initial virtio 1.0 enabling
cover initial virtio 1.0 enabling
Hi,
Here is an initial virtio 1.0 pmd driver enabling.
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 6.
To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a virtio_pci_ops structure, to add another layer so that we could keep those vtpci_foo_bar "APIs". With that, we could do the minimum change to add virtio 1.0 support.
Note that the enabling is still in rough state, and it's likely I may miss something. So, comments are huge welcome!
--yliu
---
Yuanhan Liu (6):
virtio: don't set vring address again at queue startup
virtio: introduce struct virtio_pci_ops
virtio: move left pci stuff to virtio_pci.c
viritio: switch to 64 bit features
virtio: set RTE_PCI_DRV_NEED_MAPPING flag
virtio: add virtio v1.0 support
drivers/net/virtio/virtio_ethdev.c | 297 +-------------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 752 +++++++++++++++++++++++++++++++++++-- drivers/net/virtio/virtio_pci.h | 100 ++++- drivers/net/virtio/virtio_rxtx.c | 15 - drivers/net/virtio/virtqueue.h | 4 +- 6 files changed, 843 insertions(+), 328 deletions(-)
Signature · 1 line
1.9.0
PATCH 1/6 virtio: don't set vring address again at queue startup
As we have already set up it at virtio_dev_queue_setup(), and a vq restart will not reset the settings.
--- drivers/net/virtio/virtio_rxtx.c | 15 --------------- 1 file changed, 15 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -15
@@ -339,11 +339,6 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)vq_update_avail_idx (vq);PMD_INIT_LOG (DEBUG ,"Allocated %d bufs" , nbufs); - -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); }else if (queue_type ==VTNET_TQ ) {if (use_simple_rxtx) {int mid_idx = vq->vq_nentries >>1 ;
@@ -362,16 +357,6 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)for (i = mid_idx; i < vq->vq_nentries; i++) vq->vq_ring.avail->ring[i] = i; } - -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); - }else { -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); } }
Signature · 1 line
1.9.0
PATCH 2/6 virtio: introduce struct virtio_pci_ops
In reply to Yuanhan LiuIntroduce struct virtio_pci_ops, to let legacy virtio (v0.95) and modern virtio (1.0) have different implementation regarding to a specific pci action, such as read host status.
With that, this patch reimplements all exported pci functions, in a way like:
vtpci_foo_bar(struct virtio_hw *hw)
{
hw->vtpci_ops->foo_bar(hw);
}So that we need pay attention to those pci related functions only while adding virtio 1.0 support.
This patch introduced a new vtpci function, vtpci_init(), to do proper virtio pci settings. It's pretty simple so far: just sets hw->vtpci_ops to legacy_ops as we don't support 1.0 yet.
--- drivers/net/virtio/virtio_ethdev.c | 22 ++--- drivers/net/virtio/virtio_pci.c | 162 ++++++++++++++++++++++++++++++------- drivers/net/virtio/virtio_pci.h | 27 +++++++ drivers/net/virtio/virtqueue.h | 2 +- 4 files changed, 171 insertions(+), 42 deletions(-)
drivers/net/virtio/virtio_ethdev.c +8 -14
@@ -272,9 +272,7 @@ virtio_dev_queue_release(struct virtqueue *vq) {if (vq) { hw = vq->hw; -/* Select and deactivate the queue */ -VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN ,0 ); + hw->vtpci_ops->del_queue (hw, vq);rte_free (vq->sw_ring);rte_free (vq);
@@ -295,15 +293,13 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,struct virtio_hw *hw = dev->data->dev_private;struct virtqueue *vq =NULL ; -/* Write the virtqueue index to the Queue Select Field */ -VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vtpci_queue_idx); -PMD_INIT_LOG (DEBUG ,"selecting queue: %u" , vtpci_queue_idx); +PMD_INIT_LOG (DEBUG ,"setting up queue: %u" , vtpci_queue_idx);/* * Read the virtqueue size from the Queue Size field * Always power of 2 and if 0 virtqueue does not exist */ - vq_size =VIRTIO_READ_REG_2 (hw,VIRTIO_PCI_QUEUE_NUM ); + vq_size = hw->vtpci_ops->get_queue_num (hw, vtpci_queue_idx);PMD_INIT_LOG (DEBUG ,"vq_size: %u nb_desc:%u" , vq_size, nb_desc);if (vq_size ==0 ) {PMD_INIT_LOG (ERR ,"%s: virtqueue does not exist" , __func__);
@@ -436,12 +432,8 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,memset (vq->virtio_net_hdr_mz->addr,0 ,PAGE_SIZE ); } -/* -* Set guest physical address of the virtqueue -* in VIRTIO_PCI_QUEUE_PFN config register of device -*/ -VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN , - mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); + hw->vtpci_ops->setup_queue (hw, vq); + *pvq = vq;return 0 ; }
@@ -950,7 +942,7 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features);/* Read device(host) feature bits */ - host_features =VIRTIO_READ_REG_4 (hw,VIRTIO_PCI_HOST_FEATURES ); + host_features = hw->vtpci_ops->get_features (hw);PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %x" , host_features);
@@ -1287,6 +1279,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; +vtpci_init (pci_dev, hw); +if (virtio_resource_init (pci_dev) <0 )return -1 ;
drivers/net/virtio/virtio_pci.c +135 -27
217 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +27 -0
@@ -163,6 +163,31 @@ struct virtqueue;*/ #define VIRTIO_MAX_VIRTQUEUES 8 +struct virtio_hw ; + +struct virtio_pci_ops { +void (*read_dev_cfg)(struct virtio_hw *hw,uint64_t offset, +void *dst,int len); +void (*write_dev_cfg)(struct virtio_hw *hw,uint64_t offset, +void *src,int len); +void (*reset)(struct virtio_hw *hw); + +uint8_t (*get_status)(struct virtio_hw *hw); +void (*set_status)(struct virtio_hw *hw,uint8_t status); + +uint32_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint32_t features); + +uint8_t (*get_isr)(struct virtio_hw *hw); + +uint16_t (*set_irq)(struct virtio_hw *hw,uint16_t vec); + +uint16_t (*get_queue_num)(struct virtio_hw *hw,uint16_t queue_id); +void (*setup_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*del_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*notify_queue)(struct virtio_hw *hw,struct virtqueue *vq); +}; +struct virtio_hw {struct virtqueue *cvq;uint32_t io_base;
@@ -174,6 +199,7 @@ struct virtio_hw {uint8_t use_msix;uint8_t started;uint8_t mac_addr[ETHER_ADDR_LEN ]; +const struct virtio_pci_ops *vtpci_ops; };/*
@@ -253,6 +279,7 @@ vtpci_with_feature(struct virtio_hw *hw, uint32_t bit)/* * Function declaration from virtio_pci.c */ +int vtpci_init (struct rte_pci_device *,struct virtio_hw *);void vtpci_reset (struct virtio_hw *);void vtpci_reinit_complete (struct virtio_hw *);
drivers/net/virtio/virtqueue.h +1 -1
@@ -302,7 +302,7 @@ virtqueue_notify(struct virtqueue *vq)* For virtio on IA, the notificaiton is through io port operation * which is a serialization instruction itself. */ -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_NOTIFY , vq->vq_queue_index); + vq->hw->vtpci_ops->notify_queue (vq->hw, vq); }#ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP
Signature · 1 line
1.9.0
PATCH 3/6 virtio: move left pci stuff to virtio_pci.c
In reply to Yuanhan Liuvirtio_pci.c is a more proper place for pci stuff; virtio_ethdev is not.
--- drivers/net/virtio/virtio_ethdev.c | 265 +----------------------------------- drivers/net/virtio/virtio_pci.c | 270 ++++++++++++++++++++++++++++++++++++- 2 files changed, 270 insertions(+), 265 deletions(-)
drivers/net/virtio/virtio_ethdev.c +1 -264
@@ -36,10 +36,6 @@#include <stdio.h> #include <errno.h> #include <unistd.h> -#ifdef RTE_EXEC_ENV_LINUXAPP -#include <dirent.h> -#include <fcntl.h> -#endif #include <rte_ethdev.h> #include <rte_memcpy.h>
@@ -955,260 +951,6 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features); } -#ifdef RTE_EXEC_ENV_LINUXAPP -static int -parse_sysfs_value (const char *filename,unsigned long *val) -{ -FILE *f; -char buf[BUFSIZ ]; -char *end =NULL ; - - f =fopen (filename,"r" ); -if (f ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): cannot open sysfs value %s" , - __func__, filename); -return -1 ; - } - -if (fgets (buf,sizeof (buf), f) ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): cannot read sysfs value %s" , - __func__, filename); -fclose (f); -return -1 ; - } - *val =strtoul (buf, &end,0 ); -if ((buf[0 ] =='\0' ) || (end ==NULL ) || (*end !='\n' )) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse sysfs value %s" , - __func__, filename); -fclose (f); -return -1 ; - } -fclose (f); -return 0 ; -} - -static int get_uio_dev (struct rte_pci_addr *loc,char *buf,unsigned int buflen, -unsigned int *uio_num) -{ -struct dirent *e; -DIR *dir; -char dirname[PATH_MAX ]; - -/* depending on kernel version, uio can be located in uio/uioX -* or uio:uioX */ -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio" , - loc->domain, loc->bus, loc->devid, loc->function); - dir =opendir (dirname); -if (dir ==NULL ) { -/* retry with the parent directory */ -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT , - loc->domain, loc->bus, loc->devid, loc->function); - dir =opendir (dirname); - -if (dir ==NULL ) { -PMD_INIT_LOG (ERR ,"Cannot opendir %s" , dirname); -return -1 ; - } - } - -/* take the first file starting with "uio" */ -while ((e =readdir (dir)) !=NULL ) { -/* format could be uio%d ...*/ -int shortprefix_len =sizeof ("uio" ) -1 ; -/* ... or uio:uio%d */ -int longprefix_len =sizeof ("uio:uio" ) -1 ; -char *endptr; - -if (strncmp (e->d_name,"uio" ,3 ) !=0 ) -continue ; - -/* first try uio%d */ - errno =0 ; - *uio_num =strtoull (e->d_name + shortprefix_len, &endptr,10 ); -if (errno ==0 && endptr != (e->d_name + shortprefix_len)) { -snprintf (buf, buflen,"%s/uio%u" , dirname, *uio_num); -break ; - } - -/* then try uio:uio%d */ - errno =0 ; - *uio_num =strtoull (e->d_name + longprefix_len, &endptr,10 ); -if (errno ==0 && endptr != (e->d_name + longprefix_len)) { -snprintf (buf, buflen,"%s/uio:uio%u" , dirname, - *uio_num); -break ; - } - } -closedir (dir); - -/* No uio resource found */ -if (e ==NULL ) { -PMD_INIT_LOG (ERR ,"Could not find uio resource" ); -return -1 ; - } - -return 0 ; -} - -static int -virtio_has_msix (const struct rte_pci_addr *loc) -{ -DIR *d; -char dirname[PATH_MAX ]; - -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/msi_irqs" , - loc->domain, loc->bus, loc->devid, loc->function); - - d =opendir (dirname); -if (d) -closedir (d); - -return (d !=NULL ); -} - -/* Extract I/O port numbers from sysfs */ -static int virtio_resource_init_by_uio (struct rte_pci_device *pci_dev) -{ -char dirname[PATH_MAX ]; -char filename[PATH_MAX ]; -unsigned long start, size; -unsigned int uio_num; - -if (get_uio_dev (&pci_dev->addr, dirname,sizeof (dirname), &uio_num) <0 ) -return -1 ; - -/* get portio size */ -snprintf (filename,sizeof (filename), -"%s/portio/port0/size" , dirname); -if (parse_sysfs_value (filename, &size) <0 ) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse size" , - __func__); -return -1 ; - } - -/* get portio start */ -snprintf (filename,sizeof (filename), -"%s/portio/port0/start" , dirname); -if (parse_sysfs_value (filename, &start) <0 ) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse portio start" , - __func__); -return -1 ; - } - pci_dev->mem_resource[0 ].addr = (void *)(uintptr_t )start; - pci_dev->mem_resource[0 ].len = (uint64_t )size; -PMD_INIT_LOG (DEBUG , -"PCI Port IO found start=0x%lx with size=0x%lx" , - start, size); - -/* save fd */ -memset (dirname,0 ,sizeof (dirname)); -snprintf (dirname,sizeof (dirname),"/dev/uio%u" , uio_num); - pci_dev->intr_handle.fd =open (dirname,O_RDWR ); -if (pci_dev->intr_handle.fd <0 ) { -PMD_INIT_LOG (ERR ,"Cannot open %s: %s\n" , - dirname,strerror (errno)); -return -1 ; - } - - pci_dev->intr_handle.type =RTE_INTR_HANDLE_UIO ; - pci_dev->driver->drv_flags |=RTE_PCI_DRV_INTR_LSC ; - -return 0 ; -} - -/* Extract port I/O numbers from proc/ioports */ -static int virtio_resource_init_by_ioports (struct rte_pci_device *pci_dev) -{ -uint16_t start, end; -int size; -FILE *fp; -char *line =NULL ; -char pci_id[16 ]; -int found =0 ; -size_t linesz; - -snprintf (pci_id,sizeof (pci_id),PCI_PRI_FMT , - pci_dev->addr.domain, - pci_dev->addr.bus, - pci_dev->addr.devid, - pci_dev->addr.function); - - fp =fopen ("/proc/ioports" ,"r" ); -if (fp ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): can't open ioports" , __func__); -return -1 ; - } - -while (getdelim (&line, &linesz,'\n' , fp) >0 ) { -char *ptr = line; -char *left; -int n; - - n =strcspn (ptr,":" ); - ptr[n] =0 ; - left = &ptr[n+1 ]; - -while (*left &&isspace (*left)) - left++; - -if (!strncmp (left, pci_id,strlen (pci_id))) { - found =1 ; - -while (*ptr &&isspace (*ptr)) - ptr++; - -sscanf (ptr,"%04hx-%04hx" , &start, &end); - size = end - start +1 ; - -break ; - } - } - -free (line); -fclose (fp); - -if (!found) -return -1 ; - - pci_dev->mem_resource[0 ].addr = (void *)(uintptr_t )(uint32_t )start; - pci_dev->mem_resource[0 ].len = (uint64_t )size; -PMD_INIT_LOG (DEBUG , -"PCI Port IO found start=0x%x with size=0x%x" , - start, size); - -/* can't support lsc interrupt without uio */ - pci_dev->driver->drv_flags &= ~RTE_PCI_DRV_INTR_LSC ; - -return 0 ; -} - -/* Extract I/O port numbers from sysfs */ -static int virtio_resource_init (struct rte_pci_device *pci_dev) -{ -if (virtio_resource_init_by_uio (pci_dev) ==0 ) -return 0 ; -else -return virtio_resource_init_by_ioports (pci_dev); -} - -#else -static int -virtio_has_msix(const struct rte_pci_addr *loc __rte_unused) -{ -/* nic_uio does not enable interrupts, return 0 (false). */ -return 0 ; -} - -static int virtio_resource_init(struct rte_pci_device *pci_dev __rte_unused) -{ -/* no setup required */ -return 0 ; -} -#endif -/* * Process Virtio Config changed interrupt and call the callback * if link state changed.
@@ -1279,14 +1021,9 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; -vtpci_init (pci_dev, hw); - -if (virtio_resource_init (pci_dev) <0 ) +if (vtpci_init (pci_dev, hw) <0 )return -1 ; - hw->use_msix =virtio_has_msix (&pci_dev->addr); - hw->io_base = (uint32_t )(uintptr_t )pci_dev->mem_resource[0 ].addr; -/* Reset the device although not necessary at startup */ vtpci_reset (hw);
drivers/net/virtio/virtio_pci.c +269 -1
290 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH 4/6 viritio: switch to 64 bit features
In reply to Yuanhan LiuSwitch to 64 bit features, which virtio 1.0 supports.
While legacy virtio only supports 32 bit features, it complains aloud and quit when trying to setting > 32 bit features.
--- drivers/net/virtio/virtio_ethdev.c | 8 ++++---- drivers/net/virtio/virtio_pci.c | 15 ++++++++++----- drivers/net/virtio/virtio_pci.h | 12 ++++++------ 3 files changed, 20 insertions(+), 15 deletions(-)
drivers/net/virtio/virtio_ethdev.c +4 -4
@@ -930,16 +930,16 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)static void virtio_negotiate_features (struct virtio_hw *hw) { -uint32_t host_features; +uint64_t host_features;/* Prepare guest_features: feature that driver wants to support */ hw->guest_features =VIRTIO_PMD_GUEST_FEATURES ; -PMD_INIT_LOG (DEBUG ,"guest_features before negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"guest_features before negotiate = %" PRIx64, hw->guest_features);/* Read device(host) feature bits */ host_features = hw->vtpci_ops->get_features (hw); -PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %" PRIx64, host_features);/*
@@ -947,7 +947,7 @@ virtio_negotiate_features(struct virtio_hw *hw)* guest feature bits. */ hw->guest_features =vtpci_negotiate_features (hw, host_features); -PMD_INIT_LOG (DEBUG ,"features after negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); }
drivers/net/virtio/virtio_pci.c +10 -5
@@ -87,15 +87,20 @@ legacy_write_dev_config(struct virtio_hw *hw, uint64_t offset, } } -static uint32_t +static uint64_t legacy_get_features (struct virtio_hw *hw) {return VIRTIO_READ_REG_4 (hw,VIRTIO_PCI_HOST_FEATURES ); }static void -legacy_set_features (struct virtio_hw *hw,uint32_t features) +legacy_set_features (struct virtio_hw *hw,uint64_t features) { +if ((features >>32 ) !=0 ) { +PMD_DRV_LOG (ERR , +"only 32 bit features are allowed for legacy virtio!" ); +return ; + }VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_GUEST_FEATURES , features); }
@@ -457,10 +462,10 @@ vtpci_write_dev_config(struct virtio_hw *hw, uint64_t offset, hw->vtpci_ops->write_dev_cfg (hw, offset, src, length); } -uint32_t -vtpci_negotiate_features (struct virtio_hw *hw,uint32_t host_features) +uint64_t +vtpci_negotiate_features (struct virtio_hw *hw,uint64_t host_features) { -uint32_t features; +uint64_t features;/* * Limit negotiated features to what the driver, virtqueue, and
drivers/net/virtio/virtio_pci.h +6 -6
@@ -175,8 +175,8 @@ struct virtio_pci_ops {uint8_t (*get_status)(struct virtio_hw *hw);void (*set_status)(struct virtio_hw *hw,uint8_t status); -uint32_t (*get_features)(struct virtio_hw *hw); -void (*set_features)(struct virtio_hw *hw,uint32_t features); +uint64_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint64_t features);uint8_t (*get_isr)(struct virtio_hw *hw);
@@ -191,7 +191,7 @@ struct virtio_pci_ops {struct virtio_hw {struct virtqueue *cvq;uint32_t io_base; -uint32_t guest_features; +uint64_t guest_features;uint32_t max_tx_queues;uint32_t max_rx_queues;uint16_t vtnet_hdr_size;
@@ -271,9 +271,9 @@ outl_p(unsigned int data, unsigned int port) outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg))))static inline int -vtpci_with_feature (struct virtio_hw *hw,uint32_t bit) +vtpci_with_feature (struct virtio_hw *hw,uint64_t bit) { -return (hw->guest_features & (1u << bit)) !=0 ; +return (hw->guest_features & (1ULL << bit)) !=0 ; }/*
@@ -286,7 +286,7 @@ void vtpci_reinit_complete(struct virtio_hw *);void vtpci_set_status (struct virtio_hw *,uint8_t ); -uint32_t vtpci_negotiate_features (struct virtio_hw *,uint32_t ); +uint64_t vtpci_negotiate_features (struct virtio_hw *,uint64_t );void vtpci_write_dev_config (struct virtio_hw *,uint64_t ,void *,int );
Signature · 1 line
1.9.0
PATCH 5/6 virtio: set RTE_PCI_DRV_NEED_MAPPING flag
In reply to Yuanhan LiuWe need to to map pci bar space for enabling modern virtio pci device, as all modern configs are stored at pci bar space.
Setting RTE_PCI_DRV_NEED_MAPPING flag will let eal do that for us.
--- drivers/net/virtio/virtio_ethdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio/virtio_ethdev.c +1 -1
@@ -1169,7 +1169,7 @@ static struct eth_driver rte_virtio_pmd = { .pci_drv = { .name = "rte_virtio_pmd", .id_table = pci_id_virtio_map, - .drv_flags = RTE_PCI_DRV_DETACHABLE, + .drv_flags = RTE_PCI_DRV_DETACHABLE | RTE_PCI_DRV_NEED_MAPPING, }, .eth_dev_init = eth_virtio_dev_init, .eth_dev_uninit = eth_virtio_dev_uninit,
Signature · 1 line
1.9.0
PATCH 6/6 virtio: add virtio v1.0 support
In reply to Yuanhan LiuModern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
And thanks to the RTE_PCI_DRV_NEED_MAPPING, which already maps all the bar space for us, we could easily locate to a cfg structure by:
cfg_addr = dev->mem_resources[cap.bar].addr + cap.offset;
Therefore, the entrance of enabling modern (v1.0) pci device support is to iterate the pci capability lists, and to locate some configs we care; and they are:
- common cfg
For generic virtio and virtuqueu configuration, such as setting/getting features, enabling a specific queue, and so on.
- nofity cfg
Combining with `queue_notify_off' from common cfg, we could use it to notify a specific virt queue.
- device cfg
Where virtio_net_config structure locates.
If any of above cap is not found, we fallback to the legacy virtio handling.
If succeed, hw->vtpci_ops is assigned to modern_ops, where all operations are implemented by reading/writing a (or few) specific configuration space from above 3 cfg structures. And that's basically how this patch works.
Besides those changes, virtio 1.0 introduces a new status field:FEATURES_OK, which is set after features negotiation is done.
Last, set the VIRTIO_F_VERSION_1 feature flag.
--- drivers/net/virtio/virtio_ethdev.c | 16 +- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 313 ++++++++++++++++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 65 ++++++++ drivers/net/virtio/virtqueue.h | 2 + 5 files changed, 395 insertions(+), 4 deletions(-)
drivers/net/virtio/virtio_ethdev.c +14 -2
@@ -927,7 +927,7 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)return virtio_send_command (hw->cvq, &ctrl, &len,1 ); } -static void +static int virtio_negotiate_features (struct virtio_hw *hw) {uint64_t host_features;
@@ -949,6 +949,17 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features =vtpci_negotiate_features (hw, host_features);PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); + +if (hw->modern) { +if (!vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) { +PMD_INIT_LOG (ERR , +"VIRTIO_F_VERSION_1 features is not enabled" ); +return -1 ; + } +vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_FEATURES_OK ); + } + +return 0 ; }/*
@@ -1032,7 +1043,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)/* Tell the host we've known how to drive the device. */ vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_DRIVER ); -virtio_negotiate_features (hw); +if (virtio_negotiate_features (hw) <0 ) +return -1 ;/* If host does not support status then disable LSC */ if (!vtpci_with_feature (hw,VIRTIO_NET_F_STATUS ))
drivers/net/virtio/virtio_ethdev.h +2 -1
@@ -64,7 +64,8 @@1u <<VIRTIO_NET_F_CTRL_VQ | \1u <<VIRTIO_NET_F_CTRL_RX | \1u <<VIRTIO_NET_F_CTRL_VLAN | \ - 1u << VIRTIO_NET_F_MRG_RXBUF) +1u <<VIRTIO_NET_F_MRG_RXBUF | \ + 1ULL << VIRTIO_F_VERSION_1)/* * CQ function prototype
drivers/net/virtio/virtio_pci.c +312 -1
339 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +65 -0
96 lines not on this page · raw message
drivers/net/virtio/virtqueue.h +2 -0
@@ -202,6 +202,8 @@ struct virtqueue {/* Size bins in array as RFC 2819, undersized [0], 64 [1], etc */ uint64_t size_bins[8 ]; +uint16_t *notify_addr; +struct vq_desc_extra {void *cookie;uint16_t ndescs;
Signature · 1 line
1.9.0
Michael,
Sorry that I forgot to CC you. (In fact, I intended to, but there is a tiny bug at my send-email script :(
It'd be great if you could take some time to review it.
Thanks.
--yliu
Quoted 38 lines · Yuanhan Liu
Hi,
Here is an initial virtio 1.0 pmd driver enabling.
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 6.To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a
virtio_pci_opsstructure, to add another layer so that we could keep thosevtpci_foo_bar"APIs". With that, we could do the minimum change to add virtio 1.0 support.Note that the enabling is still in rough state, and it's likely I may miss something. So, comments are huge welcome!
--yliu---
Yuanhan Liu (6):
virtio: don't set vring address again at queue startup
virtio: introduce structvirtio_pci_ops
virtio: move left pci stuff tovirtio_pci.c
viritio: switch to 64 bit features
virtio: setRTE_PCI_DRV_NEED_MAPPINGflag
virtio: add virtio v1.0 supportdrivers/net/virtio/virtio_ethdev.c | 297 +-------------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 752 +++++++++++++++++++++++++++++++++++-- drivers/net/virtio/virtio_pci.h | 100 ++++- drivers/net/virtio/virtio_rxtx.c | 15 - drivers/net/virtio/virtqueue.h | 4 +- 6 files changed, 843 insertions(+), 328 deletions(-)Signature · 1 line
1.9.0
Quoted 17 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Yuanhan Liu
Sent: Thursday, December 10, 2015 11:54 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH 0/6 for 2.3] initial virtio 1.0 enablingHi,
Here is an initial virtio 1.0 pmd driver enabling.
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 6.
Quoted 4 lines
To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a
virtio_pci_opsstructure, to add another layer so that we could keep thosevtpci_foo_bar"APIs". With that, we could do the minimum change to add virtio 1.0 support.
Please point out from which version, qemu starts to support virtio 1.0 net devices.
Thanks,
Jianfeng
Quoted 26 lines
Note that the enabling is still in rough state, and it's likely I may miss something. So, comments are huge welcome!
--yliu---
Yuanhan Liu (6):
virtio: don't set vring address again at queue startup
virtio: introduce structvirtio_pci_ops
virtio: move left pci stuff tovirtio_pci.c
viritio: switch to 64 bit features
virtio: setRTE_PCI_DRV_NEED_MAPPINGflag
virtio: add virtio v1.0 supportdrivers/net/virtio/virtio_ethdev.c | 297 +-------------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 752 +++++++++++++++++++++++++++++++++++-- drivers/net/virtio/virtio_pci.h | 100 ++++- drivers/net/virtio/virtio_rxtx.c | 15 - drivers/net/virtio/virtqueue.h | 4 +- 6 files changed, 843 insertions(+), 328 deletions(-)--
1.9.0
Re: [PATCH 2/6] virtio: introduce struct virtio_pci_ops
In reply to Yuanhan LiuQuoted 12 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Yuanhan Liu
Sent: Thursday, December 10, 2015 11:54 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH 2/6] virtio: introduce structvirtio_pci_opsIntroduce struct
virtio_pci_ops, to let legacy virtio (v0.95) and modern virtio (1.0) have different implementation regarding to a specific pci action, such as read host status.
...
drivers/net/virtio/virtio_pci.c vtpci_write_dev_config(struct virtio_hw *hw, uint64_t offset, · line 117
Quoted 9 lines
drivers/net/virtio/virtio_pci.c +9
-0+static void +legacy_reset (struct virtio_hw *hw) +{ +/* +* Setting the status to RESET sets the host device to +* the original, uninitialized state. +*/ +legacy_set_status (hw,VIRTIO_CONFIG_STATUS_RESET ); +legacy_get_status (hw);
May need a comment to explain why here we need to get_status().
drivers/net/virtio/virtio_pci.c vtpci_write_dev_config(struct virtio_hw *hw, uint64_t offset, · line 122
Quoted 5 lines
drivers/net/virtio/virtio_pci.c +5
-0+} + +static uint8_t +legacy_get_isr (struct virtio_hw *hw) +{
Please delete the following blank line.
Quoted 12 lines
drivers/net/virtio/virtio_pci.c +12
-0+ +return VIRTIO_READ_REG_1 (hw,VIRTIO_PCI_ISR ); +} + +/* Enable one vector (0) for Link State Intrerrupt */ +static uint16_t +legacy_set_irq (struct virtio_hw *hw,uint16_t vec) +{ +VIRTIO_WRITE_REG_2 (hw,VIRTIO_MSI_CONFIG_VECTOR , vec); +return VIRTIO_READ_REG_2 (hw,VIRTIO_MSI_CONFIG_VECTOR ); +} +
...
Quoted 19 lines
drivers/net/virtio/virtio_pci.h +19
-0+ +struct virtio_pci_ops { +void (*read_dev_cfg)(struct virtio_hw *hw,uint64_t offset, +void *dst,int len); +void (*write_dev_cfg)(struct virtio_hw *hw,uint64_t offset, +void *src,int len); +void (*reset)(struct virtio_hw *hw); + +uint8_t (*get_status)(struct virtio_hw *hw); +void (*set_status)(struct virtio_hw *hw,uint8_t status); + +uint32_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint32_t features); + +uint8_t (*get_isr)(struct virtio_hw *hw); + +uint16_t (*set_irq)(struct virtio_hw *hw,uint16_t vec); + + uint16_t (*get_queue_num)(struct virtio_hw *hw, uint16_t
Quoted 1 line
queue_id);
How about changing the name into get_queue_size? From my side, queue_num is very confusing.
Thanks,
Jianfeng
Quoted 5 lines
drivers/net/virtio/virtio_pci.h +5
-0+void (*setup_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*del_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*notify_queue)(struct virtio_hw *hw,struct virtqueue *vq); +}; +
...
Quoted 3 lines
#ifdef
RTE_LIBRTE_VIRTIO_DEBUG_DUMP
--
1.9.0
Re: [PATCH 6/6] virtio: add virtio v1.0 support
In reply to Yuanhan LiuQuoted 8 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Yuanhan Liu
Sent: Thursday, December 10, 2015 11:54 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH 6/6] virtio: add virtio v1.0 support
...
Quoted 10 lines
Signed-off-by Yuanhan Liu <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 16 +- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 313 ++++++++++++++++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 65 ++++++++ drivers/net/virtio/virtqueue.h | 2 + 5 files changed, 395 insertions(+), 4 deletions(-)
As legacy VIRTIO_WRITE_REG_XXXs are only used in virtio_pci.c, move these definitions into virtio_pci.c?
Quoted 19 lines
drivers/net/virtio/virtio_ethdev.c +1
-1@@ -927,7 +927,7 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)return virtio_send_command (hw->cvq, &ctrl, &len,1 ); } -static void +static int virtio_negotiate_features (struct virtio_hw *hw) {drivers/net/virtio/virtio_ethdev.c +0
-0uint64_t host_features;@@ -949,6 +949,17 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features =vtpci_negotiate_features (hw, host_features);PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features);
drivers/net/virtio/virtio_ethdev.c virtio_negotiate_features(struct virtio_hw *hw) · line 961
Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +8
-0+ +if (hw->modern) { +if (!vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) { +PMD_INIT_LOG (ERR , +"VIRTIO_F_VERSION_1 features is not enabled"); +return -1 ; + } +vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_FEATURES_OK );
As per Linux code drivers/virtio/virtio.c:virtio_finalize_features(), vtpci_set_status() may fail, and there's a double check. Is it necessary here?
Quoted 37 lines
drivers/net/virtio/virtio_ethdev.c +3
-0+ } + +return 0 ; }/*
drivers/net/virtio/virtio_ethdev.c +2
-1@@ -1032,7 +1043,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)/* Tell the host we've known how to drive the device. */ vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_DRIVER ); -virtio_negotiate_features (hw); +if (virtio_negotiate_features (hw) <0 ) +return -1 ;/* If host does not support status then disable LSC */ if (!vtpci_with_feature (hw,VIRTIO_NET_F_STATUS ))drivers/net/virtio/virtio_ethdev.h +2
-1@@ -64,7 +64,8 @@1u <<VIRTIO_NET_F_CTRL_VQ | \1u <<VIRTIO_NET_F_CTRL_RX | \1u <<VIRTIO_NET_F_CTRL_VLAN | \ - 1u << VIRTIO_NET_F_MRG_RXBUF) +1u <<VIRTIO_NET_F_MRG_RXBUF | \ + 1ULL << VIRTIO_F_VERSION_1)/* * CQ function prototype drivers/net/virtio/virtio_pci.c +0
-0@@ -31,6 +31,7 @@* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
Quoted 4 lines
DAMAGE.
*/
#include <stdint.h>
+#include <linux/pci_regs.h>
Put this "include" into macro RTE_EXEC_ENV_LINUXAPP followed?
Quoted 7 lines
#ifdef
RTE_EXEC_ENV_LINUXAPP
#include <dirent.h>drivers/net/virtio/virtio_pci.c +0
-0@@ -448,6 +449,205 @@ static const struct virtio_pci_ops legacy_ops = { };
...
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 562
Quoted 8 lines
drivers/net/virtio/virtio_pci.c +3
-0+ +static uint16_t +modern_set_irq(struct virtio_hw *hw __rte_unused, uint16_t vec
__rte_unused)drivers/net/virtio/virtio_pci.c +4
-0+{ +/* FIXME: xxx */ +return 0 ; +}
If not going to support LSC, please give clear indication at related doc. My concern is: this will affect some users, who are using LSC in legacy virtio. (If LSC works well on legacy virtio?).
Quoted 8 lines
drivers/net/virtio/virtio_pci.c +8
-0+ +static uint16_t +modern_get_queue_num (struct virtio_hw *hw,uint16_t queue_id) +{ +modern_write16 (queue_id, &hw->common_cfg->queue_select); +return modern_read16 (&hw->common_cfg->queue_size); +} +
...
drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 724
Quoted 9 lines
drivers/net/virtio/virtio_pci.c +8
-0+static inline void * +get_cfg_addr (struct rte_pci_device *dev,struct virtio_pci_cap *cap) +{ +uint8_t bar = cap->bar; +uint32_t length = cap->length; +uint32_t offset = cap->offset; +uint8_t *base; +
Use a macro to substitute hardcoded "5"?
Quoted 5 lines
drivers/net/virtio/virtio_pci.c +5
-0+if (unlikely (bar >5 )) { +PMD_INIT_LOG (ERR ,"invalid bar: %u" , bar); +return NULL ; + } +
...
drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 820
Quoted 10 lines
int
vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw){drivers/net/virtio/virtio_pci.c +5
-1- hw->vtpci_ops = &legacy_ops; + hw->dev = dev; +/* +* Try if we can succeed reading virtio pci caps, which exists +* only on modern pci device. If failed, we fallback to legacy +* virtio hanlding.
hanlding -> handling
Thanks,
Jianfeng
Quoted 1 line
drivers/net/virtio/virtio_pci.c +1
-0+*/
...
Quoted 6 lines
drivers/net/virtio/virtio_pci.c +1
-1+struct vq_desc_extra {void *cookie;uint16_t ndescs; --1.9.0
Re: [PATCH 6/6] virtio: add virtio v1.0 support
Quoted 20 lines · Jianfeng
Quoted 8 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Yuanhan Liu
Sent: Thursday, December 10, 2015 11:54 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH 6/6] virtio: add virtio v1.0 support...
Quoted 10 lines
Signed-off-by Yuanhan Liu <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 16 +- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 313 ++++++++++++++++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 65 ++++++++ drivers/net/virtio/virtqueue.h | 2 + 5 files changed, 395 insertions(+), 4 deletions(-)
Quoted 1 line
As legacy
VIRTIO_WRITE_REG_XXXsare only used invirtio_pci.c, move these definitions intovirtio_pci.c?
Yes, and I planned to do it in another series, where I will do more virtio cleanups. (hmm..., maybe I could stack them on top of this series).
Quoted 26 lines
Quoted 26 lines
drivers/net/virtio/virtio_ethdev.c +1
-1@@ -927,7 +927,7 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)return virtio_send_command (hw->cvq, &ctrl, &len,1 ); } -static void +static int virtio_negotiate_features (struct virtio_hw *hw) {drivers/net/virtio/virtio_ethdev.c +5
-0uint64_t host_features;@@ -949,6 +949,17 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features =vtpci_negotiate_features (hw, host_features);PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); + +if (hw->modern) { +if (!vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) { +PMD_INIT_LOG (ERR , +"VIRTIO_F_VERSION_1 features is not enabled");
Quoted 8 lines
drivers/net/virtio/virtio_ethdev.c virtio_negotiate_features(struct virtio_hw *hw)
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.c +3
-0+return -1 ; + } +vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_FEATURES_OK );As per Linux code drivers/virtio/virtio.c:virtio_finalize_features(),
vtpci_set_status()may fail, and there's a double check. Is it necessary here?
Yes, it's necessary: see the spec (3.1.1 Driver Requirements: Device Initialization):
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not support our subset of features and the device is unusable.
Quoted 31 lines
Quoted 31 lines
drivers/net/virtio/virtio_ethdev.c +3
-0+ } + +return 0 ; }/*
drivers/net/virtio/virtio_ethdev.c +2
-1@@ -1032,7 +1043,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)/* Tell the host we've known how to drive the device. */ vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_DRIVER ); -virtio_negotiate_features (hw); +if (virtio_negotiate_features (hw) <0 ) +return -1 ;/* If host does not support status then disable LSC */ if (!vtpci_with_feature (hw,VIRTIO_NET_F_STATUS ))drivers/net/virtio/virtio_ethdev.h +2
-1@@ -64,7 +64,8 @@1u <<VIRTIO_NET_F_CTRL_VQ | \1u <<VIRTIO_NET_F_CTRL_RX | \1u <<VIRTIO_NET_F_CTRL_VLAN | \ - 1u << VIRTIO_NET_F_MRG_RXBUF) +1u <<VIRTIO_NET_F_MRG_RXBUF | \ + 1ULL << VIRTIO_F_VERSION_1)
Quoted 14 lines
Quoted 8 lines
drivers/net/virtio/virtio_ethdev.h +0
-0/* * CQ function prototype drivers/net/virtio/virtio_pci.c +0
-0@@ -31,6 +31,7 @@* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH Quoted 4 lines
DAMAGE.
*/
#include <stdint.h>
+#include <linux/pci_regs.h>Put this "include" into macro
RTE_EXEC_ENV_LINUXAPPfollowed?
We can't simply do that, as we need reference some macros from it in common code path, virtio_read_caps(). But yes, you just remind me that there should be no such header in non-linux platform. We can't include it blindly here. Good catch, btw!
What's lucky here is that we just need reference quite few macros, maybe we could just define them by ourself, to get rid of the depency.
Quoted 9 lines
Quoted 8 lines
#ifdef
RTE_EXEC_ENV_LINUXAPP
#include <dirent.h>drivers/net/virtio/virtio_pci.c +0
-0@@ -448,6 +449,205 @@ static const struct virtio_pci_ops legacy_ops = { };...
Quoted 11 lines
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 562
Quoted 8 lines
drivers/net/virtio/virtio_pci.c +3
-0+ +static uint16_t +modern_set_irq(struct virtio_hw *hw __rte_unused, uint16_t vec
__rte_unused)drivers/net/virtio/virtio_pci.c +4
-0+{ +/* FIXME: xxx */ +return 0 ; +}If not going to support LSC, please give clear indication at related doc. My concern is: this will affect some users, who are using LSC in legacy virtio. (If LSC works well on legacy virtio?).
TBH, I don't spent too much time on that, therefore, I marked it as FIXME here, with the hope that I will revisit it with more cares in future version.
Quoted 10 lines
Quoted 8 lines
drivers/net/virtio/virtio_pci.c +8
-0+ +static uint16_t +modern_get_queue_num (struct virtio_hw *hw,uint16_t queue_id) +{ +modern_write16 (queue_id, &hw->common_cfg->queue_select); +return modern_read16 (&hw->common_cfg->queue_size); +} +...
Quoted 1 line
Quoted 10 lines
drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 724
Quoted 8 lines
drivers/net/virtio/virtio_pci.c +8
-0+static inline void * +get_cfg_addr (struct rte_pci_device *dev,struct virtio_pci_cap *cap) +{ +uint8_t bar = cap->bar; +uint32_t length = cap->length; +uint32_t offset = cap->offset; +uint8_t *base; +Use a macro to substitute hardcoded "5"?
The fact that 5 is the max bar number is so well known, that I don't think it's necessary to add a macro here.
Quoted 12 lines
Quoted 5 lines
drivers/net/virtio/virtio_pci.c +5
-0+if (unlikely (bar >5 )) { +PMD_INIT_LOG (ERR ,"invalid bar: %u" , bar); +return NULL ; + } +...
Quoted 6 lines
int
vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw){drivers/net/virtio/virtio_pci.c +1
-1- hw->vtpci_ops = &legacy_ops; + hw->dev = dev;
Quoted 6 lines
drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 820
Quoted 4 lines
drivers/net/virtio/virtio_pci.c +4
-0+/* +* Try if we can succeed reading virtio pci caps, which exists +* only on modern pci device. If failed, we fallback to legacy +* virtio hanlding. hanlding -> handling
Oops, and thanks.
--yliu
Re: [PATCH 2/6] virtio: introduce struct virtio_pci_ops
In reply to Tan, JianfengQuoted 13 lines · Jianfeng
Quoted 12 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Yuanhan Liu
Sent: Thursday, December 10, 2015 11:54 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH 2/6] virtio: introduce structvirtio_pci_opsIntroduce struct
virtio_pci_ops, to let legacy virtio (v0.95) and modern virtio (1.0) have different implementation regarding to a specific pci action, such as read host status....
Quoted 12 lines
drivers/net/virtio/virtio_pci.c vtpci_write_dev_config(struct virtio_hw *hw, uint64_t offset, · line 117
Quoted 9 lines
drivers/net/virtio/virtio_pci.c +9
-0+static void +legacy_reset (struct virtio_hw *hw) +{ +/* +* Setting the status to RESET sets the host device to +* the original, uninitialized state. +*/ +legacy_set_status (hw,VIRTIO_CONFIG_STATUS_RESET ); +legacy_get_status (hw);May need a comment to explain why here we need to
get_status().
I don't know, those are old code; I just moved them into a new function. Maybe I need look into the spec for answer.
Quoted 9 lines
drivers/net/virtio/virtio_pci.c vtpci_write_dev_config(struct virtio_hw *hw, uint64_t offset, · line 122
Quoted 7 lines
drivers/net/virtio/virtio_pci.c +5
-0+} + +static uint8_t +legacy_get_isr (struct virtio_hw *hw) +{Please delete the following blank line.
oops ...
Quoted 27 lines
Quoted 12 lines
drivers/net/virtio/virtio_pci.c +12
-0+ +return VIRTIO_READ_REG_1 (hw,VIRTIO_PCI_ISR ); +} + +/* Enable one vector (0) for Link State Intrerrupt */ +static uint16_t +legacy_set_irq (struct virtio_hw *hw,uint16_t vec) +{ +VIRTIO_WRITE_REG_2 (hw,VIRTIO_MSI_CONFIG_VECTOR , vec); +return VIRTIO_READ_REG_2 (hw,VIRTIO_MSI_CONFIG_VECTOR ); +} +...
Quoted 14 lines
drivers/net/virtio/virtio_pci.h +14
-0+ +struct virtio_pci_ops { +void (*read_dev_cfg)(struct virtio_hw *hw,uint64_t offset, +void *dst,int len); +void (*write_dev_cfg)(struct virtio_hw *hw,uint64_t offset, +void *src,int len); +void (*reset)(struct virtio_hw *hw); + +uint8_t (*get_status)(struct virtio_hw *hw); +void (*set_status)(struct virtio_hw *hw,uint8_t status); + +uint32_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint32_t features); +
Quoted 8 lines
Quoted 6 lines
drivers/net/virtio/virtio_pci.h +5
-0+uint8_t (*get_isr)(struct virtio_hw *hw); + +uint16_t (*set_irq)(struct virtio_hw *hw,uint16_t vec); + + uint16_t (*get_queue_num)(struct virtio_hw *hw, uint16_t
queue_id);How about changing the name into
get_queue_size? From my side,queue_numis very confusing.
I agree with you that queue_size is better here, however, queue_num is taken for being consistent with the virtio spec naming:
static uint16_t
legacy_get_queue_num(struct virtio_hw *hw, uint16_t queue_id)
{
VIRTIO_WRITE_REG_2(hw, VIRTIO_PCI_QUEUE_SEL, queue_id);
return VIRTIO_READ_REG_2(hw, VIRTIO_PCI_QUEUE_NUM);
}
--yliuQuoted 17 lines · Jianfeng
Quoted 17 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Yuanhan Liu
Sent: Thursday, December 10, 2015 11:54 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH 0/6 for 2.3] initial virtio 1.0 enablingHi,
Here is an initial virtio 1.0 pmd driver enabling.
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 6.
Quoted 7 lines
Quoted 4 lines
To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a
virtio_pci_opsstructure, to add another layer so that we could keep thosevtpci_foo_bar"APIs". With that, we could do the minimum change to add virtio 1.0 support.Please point out from which version, qemu starts to support virtio 1.0 net devices.
I didn't bother to check: I always use the latest qemu, the one build from git.
To test it, you need to add 'disable-modern=false' option to the virtio-net-pci device. I have added a simple test guide on internal jira. And I should have done so here; will add the test guide in next version.
--yliu
Does dpdk vhost-switch sample support virtio1.0? I tried it but seems not working.
Thanks
Qian
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Tan, Jianfeng
Sent: Tuesday, December 29, 2015 7:19 PM
To: Yuanhan Liu; [email protected]
Subject: Re: [dpdk-dev] [PATCH 0/6 for 2.3] initial virtio 1.0 enabling
Quoted 15 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Yuanhan Liu
Sent: Thursday, December 10, 2015 11:54 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH 0/6 for 2.3] initial virtio 1.0 enablingHi,
Here is an initial virtio 1.0 pmd driver enabling.
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 6.
Quoted 4 lines
To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a
virtio_pci_opsstructure, to add another layer so that we could keep thosevtpci_foo_bar"APIs". With that, we could do the minimum change to add virtio 1.0 support.
Please point out from which version, qemu starts to support virtio 1.0 net devices.
Thanks,
Jianfeng
Quoted 26 lines
Note that the enabling is still in rough state, and it's likely I may miss something. So, comments are huge welcome!
--yliu---
Yuanhan Liu (6):
virtio: don't set vring address again at queue startup
virtio: introduce structvirtio_pci_ops
virtio: move left pci stuff tovirtio_pci.c
viritio: switch to 64 bit features
virtio: setRTE_PCI_DRV_NEED_MAPPINGflag
virtio: add virtio v1.0 supportdrivers/net/virtio/virtio_ethdev.c | 297 +-------------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 752 +++++++++++++++++++++++++++++++++++-- drivers/net/virtio/virtio_pci.h | 100 ++++- drivers/net/virtio/virtio_rxtx.c | 15 - drivers/net/virtio/virtqueue.h | 4 +- 6 files changed, 843 insertions(+), 328 deletions(-)--
1.9.0
Quoted 1 line · Qian Q
Does dpdk vhost-switch sample support virtio1.0? I tried it but seems not working.
It has nothing to do with vhost-switch sample. It worked from my test; you may come to find me offline to see what might be wrong on your side.
--yliu
Quoted 65 lines
Thanks
Qian-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Tan, Jianfeng
Sent: Tuesday, December 29, 2015 7:19 PM
To: Yuanhan Liu; [email protected]
Subject: Re: [dpdk-dev] [PATCH 0/6 for 2.3] initial virtio 1.0 enablingQuoted 15 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Yuanhan Liu
Sent: Thursday, December 10, 2015 11:54 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH 0/6 for 2.3] initial virtio 1.0 enablingHi,
Here is an initial virtio 1.0 pmd driver enabling.
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 6.Quoted 4 lines
To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a
virtio_pci_opsstructure, to add another layer so that we could keep thosevtpci_foo_bar"APIs". With that, we could do the minimum change to add virtio 1.0 support.Please point out from which version, qemu starts to support virtio 1.0 net devices.
Thanks,
JianfengQuoted 26 lines
Note that the enabling is still in rough state, and it's likely I may miss something. So, comments are huge welcome!
--yliu---
Yuanhan Liu (6):
virtio: don't set vring address again at queue startup
virtio: introduce structvirtio_pci_ops
virtio: move left pci stuff tovirtio_pci.c
viritio: switch to 64 bit features
virtio: setRTE_PCI_DRV_NEED_MAPPINGflag
virtio: add virtio v1.0 supportdrivers/net/virtio/virtio_ethdev.c | 297 +-------------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 752 +++++++++++++++++++++++++++++++++++-- drivers/net/virtio/virtio_pci.h | 100 ++++- drivers/net/virtio/virtio_rxtx.c | 15 - drivers/net/virtio/virtqueue.h | 4 +- 6 files changed, 843 insertions(+), 328 deletions(-)--
1.9.0
v2 cover virtio 1.0 enabling for virtio pmd driver
In reply to Yuanhan Liuv2: - fix a data corruption reported by Qian, due to hdr size mismatch.
check detailes at ptach 5.
- Add missing config_irq and isr reading support from v1.
- fix comments from v1.
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 7.
To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a virtio_pci_ops structure, to add another layer so that we could keep those vtpci_foo_bar "APIs". With that, we could do the minimum change to add virtio 1.0 support.
---
Yuanhan Liu (7):
virtio: don't set vring address again at queue startup
virtio: introduce struct virtio_pci_ops
virtio: move left pci stuff to virtio_pci.c
viritio: switch to 64 bit features
virtio: retrieve hdr_size from hw->vtnet_hdr_size
eal: pci: export pci_map_device
virtio: add 1.0 support
doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 301 +--------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 768 +++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 102 +++- drivers/net/virtio/virtio_rxtx.c | 21 +- drivers/net/virtio/virtqueue.h | 4 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 2 +- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 6 + lib/librte_eal/common/eal_common_pci.c | 2 +- lib/librte_eal/common/eal_private.h | 11 - lib/librte_eal/common/include/rte_pci.h | 11 + lib/librte_eal/linuxapp/eal/eal_pci.c | 2 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 6 + 14 files changed, 899 insertions(+), 343 deletions(-)
Signature · 1 line
1.9.0
PATCH v2 1/7 virtio: don't set vring address again at queue startup
As we have already set up it at virtio_dev_queue_setup(), and a vq restart will not reset the settings.
--- drivers/net/virtio/virtio_rxtx.c | 15 --------------- 1 file changed, 15 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -15
@@ -339,11 +339,6 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)vq_update_avail_idx (vq);PMD_INIT_LOG (DEBUG ,"Allocated %d bufs" , nbufs); - -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); }else if (queue_type ==VTNET_TQ ) {if (use_simple_rxtx) {int mid_idx = vq->vq_nentries >>1 ;
@@ -362,16 +357,6 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)for (i = mid_idx; i < vq->vq_nentries; i++) vq->vq_ring.avail->ring[i] = i; } - -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); - }else { -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); } }
Signature · 1 line
1.9.0
PATCH v2 2/7 virtio: introduce struct virtio_pci_ops
In reply to Yuanhan LiuIntroduce struct virtio_pci_ops, to let legacy virtio (v0.95) and modern virtio (1.0) have different implementation regarding to a specific pci action, such as read host status.
With that, this patch reimplements all exported pci functions, in a way like:
vtpci_foo_bar(struct virtio_hw *hw)
{
hw->vtpci_ops->foo_bar(hw);
}So that we need pay attention to those pci related functions only while adding virtio 1.0 support.
This patch introduced a new vtpci function, vtpci_init(), to do proper virtio pci settings. It's pretty simple so far: just sets hw->vtpci_ops to legacy_ops as we don't support 1.0 yet.
---
v2: extra whitespace line removing, and comment on "reading status
after reset".
rename the badly taken op name "set_irq" to "set_config_irq".
--- drivers/net/virtio/virtio_ethdev.c | 22 ++---- drivers/net/virtio/virtio_pci.c | 158 ++++++++++++++++++++++++++++++------- drivers/net/virtio/virtio_pci.h | 27 +++++++ drivers/net/virtio/virtqueue.h | 2 +- 4 files changed, 166 insertions(+), 43 deletions(-)
drivers/net/virtio/virtio_ethdev.c +8 -14
@@ -272,9 +272,7 @@ virtio_dev_queue_release(struct virtqueue *vq) {if (vq) { hw = vq->hw; -/* Select and deactivate the queue */ -VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN ,0 ); + hw->vtpci_ops->del_queue (hw, vq);rte_free (vq->sw_ring);rte_free (vq);
@@ -295,15 +293,13 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,struct virtio_hw *hw = dev->data->dev_private;struct virtqueue *vq =NULL ; -/* Write the virtqueue index to the Queue Select Field */ -VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vtpci_queue_idx); -PMD_INIT_LOG (DEBUG ,"selecting queue: %u" , vtpci_queue_idx); +PMD_INIT_LOG (DEBUG ,"setting up queue: %u" , vtpci_queue_idx);/* * Read the virtqueue size from the Queue Size field * Always power of 2 and if 0 virtqueue does not exist */ - vq_size =VIRTIO_READ_REG_2 (hw,VIRTIO_PCI_QUEUE_NUM ); + vq_size = hw->vtpci_ops->get_queue_num (hw, vtpci_queue_idx);PMD_INIT_LOG (DEBUG ,"vq_size: %u nb_desc:%u" , vq_size, nb_desc);if (vq_size ==0 ) {PMD_INIT_LOG (ERR ,"%s: virtqueue does not exist" , __func__);
@@ -436,12 +432,8 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,memset (vq->virtio_net_hdr_mz->addr,0 ,PAGE_SIZE ); } -/* -* Set guest physical address of the virtqueue -* in VIRTIO_PCI_QUEUE_PFN config register of device -*/ -VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN , - mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); + hw->vtpci_ops->setup_queue (hw, vq); + *pvq = vq;return 0 ; }
@@ -950,7 +942,7 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features);/* Read device(host) feature bits */ - host_features =VIRTIO_READ_REG_4 (hw,VIRTIO_PCI_HOST_FEATURES ); + host_features = hw->vtpci_ops->get_features (hw);PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %x" , host_features);
@@ -1287,6 +1279,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; +vtpci_init (pci_dev, hw); +if (virtio_resource_init (pci_dev) <0 )return -1 ;
drivers/net/virtio/virtio_pci.c +130 -28
213 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +27 -0
@@ -163,6 +163,31 @@ struct virtqueue;*/ #define VIRTIO_MAX_VIRTQUEUES 8 +struct virtio_hw ; + +struct virtio_pci_ops { +void (*read_dev_cfg)(struct virtio_hw *hw,uint64_t offset, +void *dst,int len); +void (*write_dev_cfg)(struct virtio_hw *hw,uint64_t offset, +void *src,int len); +void (*reset)(struct virtio_hw *hw); + +uint8_t (*get_status)(struct virtio_hw *hw); +void (*set_status)(struct virtio_hw *hw,uint8_t status); + +uint32_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint32_t features); + +uint8_t (*get_isr)(struct virtio_hw *hw); + +uint16_t (*set_config_irq)(struct virtio_hw *hw,uint16_t vec); + +uint16_t (*get_queue_num)(struct virtio_hw *hw,uint16_t queue_id); +void (*setup_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*del_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*notify_queue)(struct virtio_hw *hw,struct virtqueue *vq); +}; +struct virtio_hw {struct virtqueue *cvq;uint32_t io_base;
@@ -174,6 +199,7 @@ struct virtio_hw {uint8_t use_msix;uint8_t started;uint8_t mac_addr[ETHER_ADDR_LEN ]; +const struct virtio_pci_ops *vtpci_ops; };/*
@@ -253,6 +279,7 @@ vtpci_with_feature(struct virtio_hw *hw, uint32_t bit)/* * Function declaration from virtio_pci.c */ +int vtpci_init (struct rte_pci_device *,struct virtio_hw *);void vtpci_reset (struct virtio_hw *);void vtpci_reinit_complete (struct virtio_hw *);
drivers/net/virtio/virtqueue.h +1 -1
@@ -302,7 +302,7 @@ virtqueue_notify(struct virtqueue *vq)* For virtio on IA, the notificaiton is through io port operation * which is a serialization instruction itself. */ -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_NOTIFY , vq->vq_queue_index); + vq->hw->vtpci_ops->notify_queue (vq->hw, vq); }#ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP
Signature · 1 line
1.9.0
PATCH v2 3/7 virtio: move left pci stuff to virtio_pci.c
In reply to Yuanhan Liuvirtio_pci.c is a more proper place for pci stuff; virtio_ethdev is not.
--- drivers/net/virtio/virtio_ethdev.c | 265 +----------------------------------- drivers/net/virtio/virtio_pci.c | 270 ++++++++++++++++++++++++++++++++++++- 2 files changed, 270 insertions(+), 265 deletions(-)
drivers/net/virtio/virtio_ethdev.c +1 -264
@@ -36,10 +36,6 @@#include <stdio.h> #include <errno.h> #include <unistd.h> -#ifdef RTE_EXEC_ENV_LINUXAPP -#include <dirent.h> -#include <fcntl.h> -#endif #include <rte_ethdev.h> #include <rte_memcpy.h>
@@ -955,260 +951,6 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features); } -#ifdef RTE_EXEC_ENV_LINUXAPP -static int -parse_sysfs_value (const char *filename,unsigned long *val) -{ -FILE *f; -char buf[BUFSIZ ]; -char *end =NULL ; - - f =fopen (filename,"r" ); -if (f ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): cannot open sysfs value %s" , - __func__, filename); -return -1 ; - } - -if (fgets (buf,sizeof (buf), f) ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): cannot read sysfs value %s" , - __func__, filename); -fclose (f); -return -1 ; - } - *val =strtoul (buf, &end,0 ); -if ((buf[0 ] =='\0' ) || (end ==NULL ) || (*end !='\n' )) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse sysfs value %s" , - __func__, filename); -fclose (f); -return -1 ; - } -fclose (f); -return 0 ; -} - -static int get_uio_dev (struct rte_pci_addr *loc,char *buf,unsigned int buflen, -unsigned int *uio_num) -{ -struct dirent *e; -DIR *dir; -char dirname[PATH_MAX ]; - -/* depending on kernel version, uio can be located in uio/uioX -* or uio:uioX */ -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio" , - loc->domain, loc->bus, loc->devid, loc->function); - dir =opendir (dirname); -if (dir ==NULL ) { -/* retry with the parent directory */ -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT , - loc->domain, loc->bus, loc->devid, loc->function); - dir =opendir (dirname); - -if (dir ==NULL ) { -PMD_INIT_LOG (ERR ,"Cannot opendir %s" , dirname); -return -1 ; - } - } - -/* take the first file starting with "uio" */ -while ((e =readdir (dir)) !=NULL ) { -/* format could be uio%d ...*/ -int shortprefix_len =sizeof ("uio" ) -1 ; -/* ... or uio:uio%d */ -int longprefix_len =sizeof ("uio:uio" ) -1 ; -char *endptr; - -if (strncmp (e->d_name,"uio" ,3 ) !=0 ) -continue ; - -/* first try uio%d */ - errno =0 ; - *uio_num =strtoull (e->d_name + shortprefix_len, &endptr,10 ); -if (errno ==0 && endptr != (e->d_name + shortprefix_len)) { -snprintf (buf, buflen,"%s/uio%u" , dirname, *uio_num); -break ; - } - -/* then try uio:uio%d */ - errno =0 ; - *uio_num =strtoull (e->d_name + longprefix_len, &endptr,10 ); -if (errno ==0 && endptr != (e->d_name + longprefix_len)) { -snprintf (buf, buflen,"%s/uio:uio%u" , dirname, - *uio_num); -break ; - } - } -closedir (dir); - -/* No uio resource found */ -if (e ==NULL ) { -PMD_INIT_LOG (ERR ,"Could not find uio resource" ); -return -1 ; - } - -return 0 ; -} - -static int -virtio_has_msix (const struct rte_pci_addr *loc) -{ -DIR *d; -char dirname[PATH_MAX ]; - -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/msi_irqs" , - loc->domain, loc->bus, loc->devid, loc->function); - - d =opendir (dirname); -if (d) -closedir (d); - -return (d !=NULL ); -} - -/* Extract I/O port numbers from sysfs */ -static int virtio_resource_init_by_uio (struct rte_pci_device *pci_dev) -{ -char dirname[PATH_MAX ]; -char filename[PATH_MAX ]; -unsigned long start, size; -unsigned int uio_num; - -if (get_uio_dev (&pci_dev->addr, dirname,sizeof (dirname), &uio_num) <0 ) -return -1 ; - -/* get portio size */ -snprintf (filename,sizeof (filename), -"%s/portio/port0/size" , dirname); -if (parse_sysfs_value (filename, &size) <0 ) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse size" , - __func__); -return -1 ; - } - -/* get portio start */ -snprintf (filename,sizeof (filename), -"%s/portio/port0/start" , dirname); -if (parse_sysfs_value (filename, &start) <0 ) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse portio start" , - __func__); -return -1 ; - } - pci_dev->mem_resource[0 ].addr = (void *)(uintptr_t )start; - pci_dev->mem_resource[0 ].len = (uint64_t )size; -PMD_INIT_LOG (DEBUG , -"PCI Port IO found start=0x%lx with size=0x%lx" , - start, size); - -/* save fd */ -memset (dirname,0 ,sizeof (dirname)); -snprintf (dirname,sizeof (dirname),"/dev/uio%u" , uio_num); - pci_dev->intr_handle.fd =open (dirname,O_RDWR ); -if (pci_dev->intr_handle.fd <0 ) { -PMD_INIT_LOG (ERR ,"Cannot open %s: %s\n" , - dirname,strerror (errno)); -return -1 ; - } - - pci_dev->intr_handle.type =RTE_INTR_HANDLE_UIO ; - pci_dev->driver->drv_flags |=RTE_PCI_DRV_INTR_LSC ; - -return 0 ; -} - -/* Extract port I/O numbers from proc/ioports */ -static int virtio_resource_init_by_ioports (struct rte_pci_device *pci_dev) -{ -uint16_t start, end; -int size; -FILE *fp; -char *line =NULL ; -char pci_id[16 ]; -int found =0 ; -size_t linesz; - -snprintf (pci_id,sizeof (pci_id),PCI_PRI_FMT , - pci_dev->addr.domain, - pci_dev->addr.bus, - pci_dev->addr.devid, - pci_dev->addr.function); - - fp =fopen ("/proc/ioports" ,"r" ); -if (fp ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): can't open ioports" , __func__); -return -1 ; - } - -while (getdelim (&line, &linesz,'\n' , fp) >0 ) { -char *ptr = line; -char *left; -int n; - - n =strcspn (ptr,":" ); - ptr[n] =0 ; - left = &ptr[n+1 ]; - -while (*left &&isspace (*left)) - left++; - -if (!strncmp (left, pci_id,strlen (pci_id))) { - found =1 ; - -while (*ptr &&isspace (*ptr)) - ptr++; - -sscanf (ptr,"%04hx-%04hx" , &start, &end); - size = end - start +1 ; - -break ; - } - } - -free (line); -fclose (fp); - -if (!found) -return -1 ; - - pci_dev->mem_resource[0 ].addr = (void *)(uintptr_t )(uint32_t )start; - pci_dev->mem_resource[0 ].len = (uint64_t )size; -PMD_INIT_LOG (DEBUG , -"PCI Port IO found start=0x%x with size=0x%x" , - start, size); - -/* can't support lsc interrupt without uio */ - pci_dev->driver->drv_flags &= ~RTE_PCI_DRV_INTR_LSC ; - -return 0 ; -} - -/* Extract I/O port numbers from sysfs */ -static int virtio_resource_init (struct rte_pci_device *pci_dev) -{ -if (virtio_resource_init_by_uio (pci_dev) ==0 ) -return 0 ; -else -return virtio_resource_init_by_ioports (pci_dev); -} - -#else -static int -virtio_has_msix(const struct rte_pci_addr *loc __rte_unused) -{ -/* nic_uio does not enable interrupts, return 0 (false). */ -return 0 ; -} - -static int virtio_resource_init(struct rte_pci_device *pci_dev __rte_unused) -{ -/* no setup required */ -return 0 ; -} -#endif -/* * Process Virtio Config changed interrupt and call the callback * if link state changed.
@@ -1279,14 +1021,9 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; -vtpci_init (pci_dev, hw); - -if (virtio_resource_init (pci_dev) <0 ) +if (vtpci_init (pci_dev, hw) <0 )return -1 ; - hw->use_msix =virtio_has_msix (&pci_dev->addr); - hw->io_base = (uint32_t )(uintptr_t )pci_dev->mem_resource[0 ].addr; -/* Reset the device although not necessary at startup */ vtpci_reset (hw);
drivers/net/virtio/virtio_pci.c +269 -1
290 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH v2 4/7 viritio: switch to 64 bit features
In reply to Yuanhan LiuSwitch to 64 bit features, which virtio 1.0 supports.
While legacy virtio only supports 32 bit features, it complains aloud and quit when trying to setting > 32 bit features.
--- drivers/net/virtio/virtio_ethdev.c | 8 ++++---- drivers/net/virtio/virtio_pci.c | 15 ++++++++++----- drivers/net/virtio/virtio_pci.h | 12 ++++++------ 3 files changed, 20 insertions(+), 15 deletions(-)
drivers/net/virtio/virtio_ethdev.c +4 -4
@@ -930,16 +930,16 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)static void virtio_negotiate_features (struct virtio_hw *hw) { -uint32_t host_features; +uint64_t host_features;/* Prepare guest_features: feature that driver wants to support */ hw->guest_features =VIRTIO_PMD_GUEST_FEATURES ; -PMD_INIT_LOG (DEBUG ,"guest_features before negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"guest_features before negotiate = %" PRIx64, hw->guest_features);/* Read device(host) feature bits */ host_features = hw->vtpci_ops->get_features (hw); -PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %" PRIx64, host_features);/*
@@ -947,7 +947,7 @@ virtio_negotiate_features(struct virtio_hw *hw)* guest feature bits. */ hw->guest_features =vtpci_negotiate_features (hw, host_features); -PMD_INIT_LOG (DEBUG ,"features after negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); }
drivers/net/virtio/virtio_pci.c +10 -5
@@ -87,15 +87,20 @@ legacy_write_dev_config(struct virtio_hw *hw, uint64_t offset, } } -static uint32_t +static uint64_t legacy_get_features (struct virtio_hw *hw) {return VIRTIO_READ_REG_4 (hw,VIRTIO_PCI_HOST_FEATURES ); }static void -legacy_set_features (struct virtio_hw *hw,uint32_t features) +legacy_set_features (struct virtio_hw *hw,uint64_t features) { +if ((features >>32 ) !=0 ) { +PMD_DRV_LOG (ERR , +"only 32 bit features are allowed for legacy virtio!" ); +return ; + }VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_GUEST_FEATURES , features); }
@@ -451,10 +456,10 @@ vtpci_write_dev_config(struct virtio_hw *hw, uint64_t offset, hw->vtpci_ops->write_dev_cfg (hw, offset, src, length); } -uint32_t -vtpci_negotiate_features (struct virtio_hw *hw,uint32_t host_features) +uint64_t +vtpci_negotiate_features (struct virtio_hw *hw,uint64_t host_features) { -uint32_t features; +uint64_t features;/* * Limit negotiated features to what the driver, virtqueue, and
drivers/net/virtio/virtio_pci.h +6 -6
@@ -175,8 +175,8 @@ struct virtio_pci_ops {uint8_t (*get_status)(struct virtio_hw *hw);void (*set_status)(struct virtio_hw *hw,uint8_t status); -uint32_t (*get_features)(struct virtio_hw *hw); -void (*set_features)(struct virtio_hw *hw,uint32_t features); +uint64_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint64_t features);uint8_t (*get_isr)(struct virtio_hw *hw);
@@ -191,7 +191,7 @@ struct virtio_pci_ops {struct virtio_hw {struct virtqueue *cvq;uint32_t io_base; -uint32_t guest_features; +uint64_t guest_features;uint32_t max_tx_queues;uint32_t max_rx_queues;uint16_t vtnet_hdr_size;
@@ -271,9 +271,9 @@ outl_p(unsigned int data, unsigned int port) outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg))))static inline int -vtpci_with_feature (struct virtio_hw *hw,uint32_t bit) +vtpci_with_feature (struct virtio_hw *hw,uint64_t bit) { -return (hw->guest_features & (1u << bit)) !=0 ; +return (hw->guest_features & (1ULL << bit)) !=0 ; }/*
@@ -286,7 +286,7 @@ void vtpci_reinit_complete(struct virtio_hw *);void vtpci_set_status (struct virtio_hw *,uint8_t ); -uint32_t vtpci_negotiate_features (struct virtio_hw *,uint32_t ); +uint64_t vtpci_negotiate_features (struct virtio_hw *,uint64_t );void vtpci_write_dev_config (struct virtio_hw *,uint64_t ,void *,int );
Signature · 1 line
1.9.0
PATCH v2 5/7 virtio: retrieve hdr_size from hw->vtnet_hdr_size
In reply to Yuanhan LiuThe mergeable virtio net hdr format has been the standard and the only virtio net hdr format since virtio 1.0. Therefore, we could not hardcode hdr_size to "sizeof(struct virtio_net_hdr)" any more at virtio_recv_pkts(), otherwise, there would be a mismatch of hdr size from rte_vhost_enqueue_burst() and virtio_recv_pkts(), leading a packet corruption.
Instead, we should retrieve it from hw->vtnet_hdr_size; we will do proper settings at eth_virtio_dev_init().
--- drivers/net/virtio/virtio_rxtx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_rxtx.c +4 -2
@@ -560,7 +560,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)struct rte_mbuf *rcv_pkts[VIRTIO_MBUF_BURST_SZ ];int error;uint32_t i, nb_enqueued; -const uint32_t hdr_size =sizeof (struct virtio_net_hdr ); +uint32_t hdr_size; nb_used =VIRTQUEUE_NUSED (rxvq);
@@ -580,6 +580,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) hw = rxvq->hw; nb_rx =0 ; nb_enqueued =0 ; + hdr_size = hw->vtnet_hdr_size;for (i =0 ; i < num ; i++) { rxm = rcv_pkts[i];
@@ -664,7 +665,7 @@ virtio_recv_mergeable_pkts(void *rx_queue,uint32_t seg_num;uint16_t extra_idx;uint32_t seg_res; -const uint32_t hdr_size =sizeof (struct virtio_net_hdr_mrg_rxbuf ); +uint32_t hdr_size; nb_used =VIRTQUEUE_NUSED (rxvq);
@@ -682,6 +683,7 @@ virtio_recv_mergeable_pkts(void *rx_queue, seg_num =0 ; extra_idx =0 ; seg_res =0 ; + hdr_size = hw->vtnet_hdr_size;while (i < nb_used) {struct virtio_net_hdr_mrg_rxbuf *header;
Signature · 1 line
1.9.0
PATCH v2 6/7 eal: pci: export pci_map_device
In reply to Yuanhan LiuNormally we could set RTE_PCI_DRV_NEED_MAPPING flag so that eal will invoke pci_map_device internally for us. From that point view, there is no need to export pci_map_device.
However, for virtio pmd driver, which is designed to work without binding UIO (or something similar first), pci_map_device() will fail, which ends up with virtio pmd driver being skipped. Therefore, we can not set RTE_PCI_DRV_NEED_MAPPING blindly at virtio pmd driver.
Therefore, this patch exports pci_map_device, and let virtio pmd call it when necessary.
--- lib/librte_eal/bsdapp/eal/eal_pci.c | 2 +- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 6 ++++++ lib/librte_eal/common/eal_common_pci.c | 2 +- lib/librte_eal/common/eal_private.h | 11 ----------- lib/librte_eal/common/include/rte_pci.h | 11 +++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 2 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 6 ++++++ 7 files changed, 26 insertions(+), 14 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +1 -1
@@ -93,7 +93,7 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)/* Map pci device */ int -pci_map_device (struct rte_pci_device *dev) +rte_eal_pci_map_device (struct rte_pci_device *dev) {int ret =-1 ;
lib/librte_eal/bsdapp/eal/rte_eal_version.map +6 -0
@@ -135,3 +135,9 @@ DPDK_2.2 { rte_xen_dom0_supported; } DPDK_2.1; + +DPDK_2.3 { + global: + + rte_eal_pci_map_device; +} DPDK_2.2;
lib/librte_eal/common/eal_common_pci.c +1 -1
@@ -188,7 +188,7 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dpci_config_space_set (dev);#endif /* map resources for devices that use igb_uio */ - ret =pci_map_device (dev); + ret =rte_eal_pci_map_device (dev);if (ret !=0 )return ret; } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
lib/librte_eal/common/eal_private.h +0 -11
@@ -165,17 +165,6 @@ struct rte_pci_device;int pci_unbind_kernel_driver (struct rte_pci_device *dev);/** -* Map this device -* -* This function is private to EAL. -* -* @return -* 0 on success, negative on error and positive if no driver -* is found for the device. -*/ -int pci_map_device (struct rte_pci_device *dev); - -/** * Unmap this device * * This function is private to EAL.
lib/librte_eal/common/include/rte_pci.h +11 -0
@@ -485,6 +485,17 @@ int rte_eal_pci_read_config(const struct rte_pci_device *device,*/ int rte_eal_pci_write_config (const struct rte_pci_device *device,const void *buf,size_t len,off_t offset); +/** +* Map this device +* +* This function is private to EAL. +* +* @return +* 0 on success, negative on error and positive if no driver +* is found for the device. +*/ +int rte_eal_pci_map_device (struct rte_pci_device *dev); +#ifdef RTE_PCI_CONFIG /**
lib/librte_eal/linuxapp/eal/eal_pci.c +1 -1
@@ -124,7 +124,7 @@ pci_get_kernel_driver_by_path(const char *filename, char *dri_name)/* Map pci device */ int -pci_map_device (struct rte_pci_device *dev) +rte_eal_pci_map_device (struct rte_pci_device *dev) {int ret =-1 ;
lib/librte_eal/linuxapp/eal/rte_eal_version.map +6 -0
@@ -138,3 +138,9 @@ DPDK_2.2 { rte_xen_dom0_supported; } DPDK_2.1; + +DPDK_2.3 { + global: + + rte_eal_pci_map_device; +} DPDK_2.2;
Signature · 1 line
1.9.0
PATCH v2 7/7 virtio: add 1.0 support
In reply to Yuanhan LiuModern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
Firstly, we map the pci resources by rte_eal_pci_map_device(). We then could easily locate to a cfg structure by:
cfg_addr = dev->mem_resources[cap.bar].addr + cap.offset;
Therefore, the entrance of enabling modern (v1.0) pci device support is to iterate the pci capability lists, and to locate some configs we care; and they are:
- common cfg
For generic virtio and virtuqueu configuration, such as setting/getting features, enabling a specific queue, and so on.
- nofity cfg
Combining with `queue_notify_off' from common cfg, we could use it to notify a specific virt queue.
- device cfg
Where virtio_net_config structure locates.
- isr cfg
Where to read isr (interrupt status).
If any of above cap is not found, we fallback to the legacy virtio handling.
If succeed, hw->vtpci_ops is assigned to modern_ops, where all operations are implemented by reading/writing a (or few) specific configuration space from above 4 cfg structures. And that's basically how this patch works.
Besides those changes, virtio 1.0 introduces a new status field:FEATURES_OK, which is set after features negotiation is done.
Last, set the VIRTIO_F_VERSION_1 feature flag.
---
v2: - re-read status after setting FEATURES_OK to make sure status is
set correctly.
- Add isr reading and config irq setting support.
- Define some pci macro on our own to not get the dependency of linux/pci_regs.h, as there should be no such file at non-Linux platform
--- doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 24 ++- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 335 ++++++++++++++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 67 +++++++ drivers/net/virtio/virtqueue.h | 2 + 6 files changed, 429 insertions(+), 5 deletions(-)
doc/guides/rel_notes/release_2_3.rst +3 -0
@@ -4,6 +4,9 @@ DPDK Release 2.3 New Features ------------ +* **Virtio 1.0 support.** + + Enabled virtio 1.0 support for virtio pmd driver. Resolved Issues ---------------
drivers/net/virtio/virtio_ethdev.c +21 -3
@@ -927,7 +927,7 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)return virtio_send_command (hw->cvq, &ctrl, &len,1 ); } -static void +static int virtio_negotiate_features (struct virtio_hw *hw) {uint64_t host_features;
@@ -949,6 +949,22 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features =vtpci_negotiate_features (hw, host_features);PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); + +if (hw->modern) { +if (!vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) { +PMD_INIT_LOG (ERR , +"VIRTIO_F_VERSION_1 features is not enabled." ); +return -1 ; + } +vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_FEATURES_OK ); +if (!(vtpci_get_status (hw) &VIRTIO_CONFIG_STATUS_FEATURES_OK )) { +PMD_INIT_LOG (ERR , +"failed to set FEATURES_OK status!" ); +return -1 ; + } + } + +return 0 ; }/*
@@ -1032,7 +1048,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)/* Tell the host we've known how to drive the device. */ vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_DRIVER ); -virtio_negotiate_features (hw); +if (virtio_negotiate_features (hw) <0 ) +return -1 ;/* If host does not support status then disable LSC */ if (!vtpci_with_feature (hw,VIRTIO_NET_F_STATUS ))
@@ -1043,7 +1060,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)rx_func_get (eth_dev);/* Setting up rx_header size for the device */ -if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF ) || +vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) hw->vtnet_hdr_size =sizeof (struct virtio_net_hdr_mrg_rxbuf );else hw->vtnet_hdr_size =sizeof (struct virtio_net_hdr );
drivers/net/virtio/virtio_ethdev.h +2 -1
@@ -64,7 +64,8 @@1u <<VIRTIO_NET_F_CTRL_VQ | \1u <<VIRTIO_NET_F_CTRL_RX | \1u <<VIRTIO_NET_F_CTRL_VLAN | \ - 1u << VIRTIO_NET_F_MRG_RXBUF) +1u <<VIRTIO_NET_F_MRG_RXBUF | \ + 1ULL << VIRTIO_F_VERSION_1)/* * CQ function prototype
drivers/net/virtio/virtio_pci.c +334 -1
367 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +67 -0
104 lines not on this page · raw message
drivers/net/virtio/virtqueue.h +2 -0
@@ -202,6 +202,8 @@ struct virtqueue {/* Size bins in array as RFC 2819, undersized [0], 64 [1], etc */ uint64_t size_bins[8 ]; +uint16_t *notify_addr; +struct vq_desc_extra {void *cookie;uint16_t ndescs;
Signature · 1 line
1.9.0
Re: [PATCH v2 0/7] virtio 1.0 enabling for virtio pmd driver
In reply to Yuanhan LiuQuoted 12 lines · Yuanhan Liu
v2: - fix a data corruption reported by Qian, due to hdr size mismatch.
check detailes at ptach 5.- Add missing
config_irqand isr reading support from v1.- fix comments from v1.
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 7.
Quoted 4 lines
To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a
virtio_pci_opsstructure, to add another layer so that we could keep thosevtpci_foo_bar"APIs". With that, we could do the minimum change to add virtio 1.0 support.
Oops, I just found that I missed a simple test guide here, as promised before. And here it is:
Firstly, you need get a virtio 1.0 supported QEMU (say, v2.5), then add option "disable-modern=false" to qemu virtio-net-pci device to enable virtio 1.0 (which is disabled by default).
And if you see something like following from 'lspci -v', it means virtio 1.0 is indeed enabled:
00:04.0 Ethernet controller: Red Hat, Inc Virtio network device
Subsystem: Red Hat, Inc Device 0001
Physical Slot: 4
Flags: bus master, fast devsel, latency 0, IRQ 11 I/O ports at c040 [size=64]
Memory at febf1000 (32-bit, non-prefetchable) [size=4K] Memory at fe000000 (64-bit, prefetchable) [size=8M] Expansion ROM at feb80000 [disabled] [size=256K]
Capabilities: [98] MSI-X: Enable+ Count=6 Masked-
==> Capabilities: [84] Vendor Specific Information: Len=14 <?> ==> Capabilities: [70] Vendor Specific Information: Len=14 <?> ==> Capabilities: [60] Vendor Specific Information: Len=10 <?> ==> Capabilities: [50] Vendor Specific Information: Len=10 <?> ==> Capabilities: [40] Vendor Specific Information: Len=10 <?>
Kernel driver in use: virtio-pci
Kernel modules: virtio_pci
After that, there wasn't anything speical comparing to the old virtio 0.95 pmd driver.
--yliu
Quoted 29 lines
---
Yuanhan Liu (7):
virtio: don't set vring address again at queue startup
virtio: introduce structvirtio_pci_ops
virtio: move left pci stuff tovirtio_pci.c
viritio: switch to 64 bit features
virtio: retrievehdr_sizefromhw->vtnet_hdr_size
eal: pci: exportpci_map_device
virtio: add 1.0 supportdoc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 301 +--------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 768 +++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 102 +++- drivers/net/virtio/virtio_rxtx.c | 21 +- drivers/net/virtio/virtqueue.h | 4 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 2 +- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 6 + lib/librte_eal/common/eal_common_pci.c | 2 +- lib/librte_eal/common/eal_private.h | 11 - lib/librte_eal/common/include/rte_pci.h | 11 + lib/librte_eal/linuxapp/eal/eal_pci.c | 2 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 6 + 14 files changed, 899 insertions(+), 343 deletions(-)Signature · 1 line
1.9.0
Re: [PATCH v2 6/7] eal: pci: export pci_map_device
In reply to Yuanhan LiuQuoted 4 lines · Yuanhan Liu
Normally we could set
RTE_PCI_DRV_NEED_MAPPINGflag so that eal will invokepci_map_deviceinternally for us. From that point view, there is no need to exportpci_map_device.
Quoted 8 lines
However, for virtio pmd driver, which is designed to work without binding UIO (or something similar first),
pci_map_device()will fail, which ends up with virtio pmd driver being skipped. Therefore, we can not setRTE_PCI_DRV_NEED_MAPPINGblindly at virtio pmd driver.Therefore, this patch exports
pci_map_device, and let virtio pmd call it when necessary.
Well, if you introduce map function, I suppose, for hotplug, you would need unmap.
[snip]
(quoted diff) +0 -0
Quoted 11 lines
b/lib/librte_eal/common/include/rte_pci.h
index 334c12e..e9e1725 100644lib/librte_eal/common/include/rte_pci.h +2
-0@@ -485,6 +485,17 @@ int rte_eal_pci_read_config(const structrte_pci_device *device, */ int rte_eal_pci_write_config (const struct rte_pci_device *device,const void *buf,size_t len,off_t offset); +/** +* Map this device
lib/librte_eal/common/include/rte_pci.h int rte_eal_pci_read_config(const struct · line 500
Quoted 10 lines
lib/librte_eal/common/include/rte_pci.h +9
-0+* +* This function is private to EAL. +* +* @return +* 0 on success, negative on error and positive if no driver +* is found for the device. +*/ +int rte_eal_pci_map_device (struct rte_pci_device *dev); +
If you export it, then this can not be marked as private anymore. Description could be better (I agree it was not that great before). And a little comment on when to call: driver should not set RTE_PCI_DRV_NEED_MAPPING flag if it wants to use it.
The rest looks good to me.
Signature · 1 line
David Marchand
Re: [PATCH v2 6/7] eal: pci: export pci_map_device
Quoted 12 lines · David Marchand
On Tue, Jan 12, 2016 at 7:59 AM, Yuanhan Liu <[email protected]> wrote:
Normally we could set
RTE_PCI_DRV_NEED_MAPPINGflag so that eal will invokepci_map_deviceinternally for us. From that point view, there is no need to exportpci_map_device.However, for virtio pmd driver, which is designed to work without binding UIO (or something similar first),
pci_map_device()will fail, which ends up with virtio pmd driver being skipped. Therefore, we can not setRTE_PCI_DRV_NEED_MAPPINGblindly at virtio pmd driver.
Quoted 6 lines
Therefore, this patch exports
pci_map_device, and let virtio pmd call it when necessary.Well, if you introduce map function, I suppose, for hotplug, you would need unmap.
Good remind. Thanks. I will export pci_unmap_device as well.
Quoted 26 lines
[snip]
diff --git
a/lib/librte_eal/common/include/rte_pci.hb/lib/librte_eal/common/include/rte_pci.h
index 334c12e..e9e1725 100644
---a/lib/librte_eal/common/include/rte_pci.h
+++b/lib/librte_eal/common/include/rte_pci.h
@@ -485,6 +485,17 @@ int rte_eal_pci_read_config(const structrte_pci_device*device,
*/
intrte_eal_pci_write_config(const struct rte_pci_device *device, const void *buf, size_t len, off_t offset); +/**
+ * Map this device
+ *
+ * This function is private to EAL.
+ *
+ * @return
+ * 0 on success, negative on error and positive if no driver
+ * is found for the device.
+ */
+intrte_eal_pci_map_device(struct rte_pci_device *dev);
+
Quoted 1 line
If you export it, then this can not be marked as private anymore.
Oops, a silly C&P error. Will fix it.
Quoted 3 lines
Description could be better (I agree it was not that great before). And a little comment on when to call: driver should not set
RTE_PCI_DRV_NEED_MAPPINGflag if it wants to use it.
Good suggestion.
Quoted 1 line
The rest looks good to me.
Thanks.
--yliu
Re: [PATCH v2 6/7] eal: pci: export pci_map_device
Quoted 13 lines · Yuanhan Liu
Quoted 12 lines · David Marchand
On Tue, Jan 12, 2016 at 7:59 AM, Yuanhan Liu <[email protected]> wrote:
Normally we could set
RTE_PCI_DRV_NEED_MAPPINGflag so that eal will invokepci_map_deviceinternally for us. From that point view, there is no need to exportpci_map_device.However, for virtio pmd driver, which is designed to work without binding UIO (or something similar first),
pci_map_device()will fail, which ends up with virtio pmd driver being skipped. Therefore, we can not setRTE_PCI_DRV_NEED_MAPPINGblindly at virtio pmd driver.
Quoted 8 lines
Quoted 6 lines
Therefore, this patch exports
pci_map_device, and let virtio pmd call it when necessary.Well, if you introduce map function, I suppose, for hotplug, you would need unmap.
Good remind. Thanks. I will export
pci_unmap_deviceas well.
And here you go.
--yliu
-- >8 --
Quoted 1 line
From
aa3d9d0fa827781d1563fd4c06ba04a8fafdc41cMon Sep 17 00:00:00 2001
From: Yuanhan Liu <[email protected]>
Date: Mon, 11 Jan 2016 16:51:35 +0800
Subject: [PATCH] eal: pci: export pci_[un]map_device
Normally we could set RTE_PCI_DRV_NEED_MAPPING flag so that eal will invoke pci_map_device internally for us. From that point view, there is no need to export pci_map_device.
However, for virtio pmd driver, which is designed to work without binding UIO (or something similar first), pci_map_device() will fail, which ends up with virtio pmd driver being skipped. Therefore, we can not set RTE_PCI_DRV_NEED_MAPPING blindly at virtio pmd driver.
Therefore, this patch exports pci_map_device, and let virtio pmd call it when necessary.
---
v2: - export pci_unmap_device as well
- Add few more comments about rte_eal_pci_map_device().
--- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 ++-- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 7 +++++++ lib/librte_eal/common/eal_common_pci.c | 4 ++-- lib/librte_eal/common/eal_private.h | 18 ----------------- lib/librte_eal/common/include/rte_pci.h | 27 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 4 ++-- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 7 +++++++ 7 files changed, 47 insertions(+), 24 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -2
@@ -93,7 +93,7 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)/* Map pci device */ int -pci_map_device (struct rte_pci_device *dev) +rte_eal_pci_map_device (struct rte_pci_device *dev) {int ret =-1 ;
@@ -115,7 +115,7 @@ pci_map_device(struct rte_pci_device *dev)/* Unmap pci device */ void -pci_unmap_device (struct rte_pci_device *dev) +rte_eal_pci_unmap_device (struct rte_pci_device *dev) {/* try unmapping the NIC resources */ switch (dev->kdrv) {
lib/librte_eal/bsdapp/eal/rte_eal_version.map +7 -0
@@ -135,3 +135,10 @@ DPDK_2.2 { rte_xen_dom0_supported; } DPDK_2.1; + +DPDK_2.3 { + global: + + rte_eal_pci_map_device; + rte_eal_pci_unmap_device; +} DPDK_2.2;
lib/librte_eal/common/eal_common_pci.c +2 -2
@@ -188,7 +188,7 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dpci_config_space_set (dev);#endif /* map resources for devices that use igb_uio */ - ret =pci_map_device (dev); + ret =rte_eal_pci_map_device (dev);if (ret !=0 )return ret; } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
@@ -254,7 +254,7 @@ rte_eal_pci_detach_dev(struct rte_pci_driver *dr,if (dr->drv_flags &RTE_PCI_DRV_NEED_MAPPING )/* unmap resources for devices that use igb_uio */ -pci_unmap_device (dev); +rte_eal_pci_unmap_device (dev);return 0 ; }
lib/librte_eal/common/eal_private.h +0 -18
@@ -165,24 +165,6 @@ struct rte_pci_device;int pci_unbind_kernel_driver (struct rte_pci_device *dev);/** -* Map this device -* -* This function is private to EAL. -* -* @return -* 0 on success, negative on error and positive if no driver -* is found for the device. -*/ -int pci_map_device (struct rte_pci_device *dev); - -/** -* Unmap this device -* -* This function is private to EAL. -*/ -void pci_unmap_device (struct rte_pci_device *dev); - -/** * Map the PCI resource of a PCI device in virtual memory * * This function is private to EAL.
lib/librte_eal/common/include/rte_pci.h +27 -0
@@ -485,6 +485,33 @@ int rte_eal_pci_read_config(const struct rte_pci_device *device,*/ int rte_eal_pci_write_config (const struct rte_pci_device *device,const void *buf,size_t len,off_t offset); +/** +* Map the PCI device resources in user space virtual memory address +* +* Note that driver should not call this function when flag +* RTE_PCI_DRV_NEED_MAPPING is set, as EAL will do that for +* you when it's on. +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +* +* @return +* 0 on success, negative on error and positive if no driver +* is found for the device. +*/ +int rte_eal_pci_map_device (struct rte_pci_device *dev); + +/** +* Unmap this device +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +*/ +void rte_eal_pci_unmap_device (struct rte_pci_device *dev); + +#ifdef RTE_PCI_CONFIG /**
lib/librte_eal/linuxapp/eal/eal_pci.c +2 -2
@@ -124,7 +124,7 @@ pci_get_kernel_driver_by_path(const char *filename, char *dri_name)/* Map pci device */ int -pci_map_device (struct rte_pci_device *dev) +rte_eal_pci_map_device (struct rte_pci_device *dev) {int ret =-1 ;
@@ -153,7 +153,7 @@ pci_map_device(struct rte_pci_device *dev)/* Unmap pci device */ void -pci_unmap_device (struct rte_pci_device *dev) +rte_eal_pci_unmap_device (struct rte_pci_device *dev) {/* try unmapping the NIC resources using VFIO if it exists */ switch (dev->kdrv) {
lib/librte_eal/linuxapp/eal/rte_eal_version.map +7 -0
@@ -138,3 +138,10 @@ DPDK_2.2 { rte_xen_dom0_supported; } DPDK_2.1; + +DPDK_2.3 { + global: + + rte_eal_pci_map_device; + rte_eal_pci_unmap_device; +} DPDK_2.2;
Signature · 1 line
1.9.0
Re: [PATCH v2 7/7] virtio: add 1.0 support
In reply to Yuanhan Liudrivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 763
Quoted 12 lines · Yuanhan Liu
drivers/net/virtio/virtio_pci.c +12
-0+static int +virtio_read_caps (struct rte_pci_device *dev,struct virtio_hw *hw) +{ +uint8_t pos; +struct virtio_pci_cap cap; +int ret; + +if (rte_eal_pci_map_device (dev) <0 ) { +PMD_INIT_LOG (DEBUG ,"failed to map pci device!" ); +return -1 ; + } +
Do you need to call rte_eal_pci_unmap_device() in somewhere in this file?
Anyway, I've reviewed and tested your all patches. And it seems except for it, I guess your patches are good.
Thanks,
Tetsuya
Re: [PATCH v2 7/7] virtio: add 1.0 support
Quoted 15 lines · Tetsuya Mukawa
drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 763
Quoted 12 lines · Yuanhan Liu
drivers/net/virtio/virtio_pci.c +12
-0+static int +virtio_read_caps (struct rte_pci_device *dev,struct virtio_hw *hw) +{ +uint8_t pos; +struct virtio_pci_cap cap; +int ret; + +if (rte_eal_pci_map_device (dev) <0 ) { +PMD_INIT_LOG (DEBUG ,"failed to map pci device!" ); +return -1 ; + } +Do you need to call
rte_eal_pci_unmap_device()in somewhere in this file?
Yes, we should. I will see where I can find a proper place for it in next version; eth_virtio_dev_uninit sounds like a good option.
Quoted 2 lines
Anyway, I've reviewed and tested your all patches. And it seems except for it, I guess your patches are good.
Thank you for reviewing and testing it!
--yliu
Santosh Shukla
Tested-byRe: [PATCH v2 6/7] eal: pci: export pci_map_device
In reply to Yuanhan LiuQuoted 42 lines · Yuanhan Liu
Quoted 13 lines · Yuanhan Liu
Quoted 12 lines · David Marchand
On Tue, Jan 12, 2016 at 7:59 AM, Yuanhan Liu <[email protected]> wrote:
Normally we could set
RTE_PCI_DRV_NEED_MAPPINGflag so that eal will invokepci_map_deviceinternally for us. From that point view, there is no need to exportpci_map_device.However, for virtio pmd driver, which is designed to work without binding UIO (or something similar first),
pci_map_device()will fail, which ends up with virtio pmd driver being skipped. Therefore, we can not setRTE_PCI_DRV_NEED_MAPPINGblindly at virtio pmd driver.Quoted 8 lines
Quoted 6 lines
Therefore, this patch exports
pci_map_device, and let virtio pmd call it when necessary.Well, if you introduce map function, I suppose, for hotplug, you would need unmap.
Good remind. Thanks. I will export
pci_unmap_deviceas well.And here you go.
--yliu-- >8 --
Fromaa3d9d0fa827781d1563fd4c06ba04a8fafdc41cMon Sep 17 00:00:00 2001
From: Yuanhan Liu <[email protected]>
Date: Mon, 11 Jan 2016 16:51:35 +0800
Subject: [PATCH] eal: pci: export pci_[un]map_deviceNormally we could set
RTE_PCI_DRV_NEED_MAPPINGflag so that eal will invokepci_map_deviceinternally for us. From that point view, there is no need to exportpci_map_device.However, for virtio pmd driver, which is designed to work without binding UIO (or something similar first),
pci_map_device()will fail, which ends up with virtio pmd driver being skipped. Therefore, we can not setRTE_PCI_DRV_NEED_MAPPINGblindly at virtio pmd driver.
Quoted 8 lines
Therefore, this patch exports
pci_map_device, and let virtio pmd call it when necessary.Signed-off-by Yuanhan Liu <[email protected]>---
v2: - exportpci_unmap_deviceas well- Add few more comments about
rte_eal_pci_map_device().
This patch tested for vfio-noIOMMU mode for arm64 platform.
Re: [PATCH v2 0/7] virtio 1.0 enabling for virtio pmd driver
In reply to Yuanhan LiuQuoted 28 lines · Yuanhan Liu
v2: - fix a data corruption reported by Qian, due to hdr size mismatch.
check detailes at ptach 5.- Add missing
config_irqand isr reading support from v1.- fix comments from v1.
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 7.To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a
virtio_pci_opsstructure, to add another layer so that we could keep thosevtpci_foo_bar"APIs". With that, we could do the minimum change to add virtio 1.0 support.---
Yuanhan Liu (7):
virtio: don't set vring address again at queue startup
virtio: introduce structvirtio_pci_ops
virtio: move left pci stuff tovirtio_pci.c
viritio: switch to 64 bit features
virtio: retrievehdr_sizefromhw->vtnet_hdr_size
eal: pci: exportpci_map_device
virtio: add 1.0 support
Quoted 16 lines
doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 301 +--------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 768 +++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 102 +++- drivers/net/virtio/virtio_rxtx.c | 21 +- drivers/net/virtio/virtqueue.h | 4 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 2 +- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 6 + lib/librte_eal/common/eal_common_pci.c | 2 +- lib/librte_eal/common/eal_private.h | 11 - lib/librte_eal/common/include/rte_pci.h | 11 + lib/librte_eal/linuxapp/eal/eal_pci.c | 2 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 6 + 14 files changed, 899 insertions(+), 343 deletions(-)
Hi Yuanhan and Jianfeng,
Thanks for great patches.
I want to use VIRTIO-1.0 feature for my virtio container patch, because it will solve 44 bit memory address limitation.
(So far, legacy virtio-net device only receives queue address under (1 << (32 + 12)).)
I have a few comments to rebase virtio container patches on this patches.
1. VIRTIO_READ_REG_X
So far, VIRTIO_READ_REG_1/2/4 are defined in virtio_pci.h. But these macros are only referred by virtio_pci.c. How about moving the macros to virtio_pci.c?
2. Abstraction of read/write accesses.
It may be difficult to cleanly rebase my patches on this patches, because virtio_read_caps() is not abstracted.
Let me describe it more.
So far, we need to handle below 3 virtio-net devices..
- physical virtio-net device.
- virtual virtio-net device in virtio-net PMD. (Jianfeng's patch)
- virtual virtio-net device in QEMU. (my patch)
Almost all code of the virtio-net PMD can be shared between above different cases.
Probably big difference is how to access to configuration space.
Yuanhan's patch introduces an abstraction layer to hide configuration space layout and how to access it.
Is it possible to separate?
I guess "access method" will be nice to be abstracted separately from "configuration space layout".
Probably access method will be defined by "eth_dev->dev_type" and the PMD name like "eth_cvio".
And "configuration space layout" will be defined by capability list of PCI configuration layout.
For example, if access method like below are abstracted separately and current "virtio_pci.c" is implemented on this abstraction, we can easily re-use virtio_read_caps().
- how to read/write virtio configuration space.
- how to mmap PCI configuration space.
- how to read/(write) PCI configuration space.
Thanks,
Tetsuya
Re: [PATCH v2 0/7] virtio 1.0 enabling for virtio pmd driver
Quoted 28 lines · Tetsuya Mukawa
Quoted 12 lines · Yuanhan Liu
v2: - fix a data corruption reported by Qian, due to hdr size mismatch.
check detailes at ptach 5.- Add missing
config_irqand isr reading support from v1.- fix comments from v1.
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 7.Quoted 6 lines
To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a
virtio_pci_opsstructure, to add another layer so that we could keep thosevtpci_foo_bar"APIs". With that, we could do the minimum change to add virtio 1.0 support.Hi Yuanhan and Jianfeng,
Thanks for great patches.
I want to use VIRTIO-1.0 feature for my virtio container patch, because it will solve 44 bit memory address limitation.
(So far, legacy virtio-net device only receives queue address under (1 << (32 + 12)).)
Quoted 7 lines
I have a few comments to rebase virtio container patches on this patches.
1.
VIRTIO_READ_REG_XSo far, VIRTIO_READ_REG_1/2/4 are defined in
virtio_pci.h. But these macros are only referred byvirtio_pci.c. How about moving the macros tovirtio_pci.c?
Jianfeng had same suggestion. I could do that in next version then.
Quoted 4 lines
2. Abstraction of read/write accesses.
It may be difficult to cleanly rebase my patches on this patches, because
virtio_read_caps()is not abstracted.
I don't think we can/need abstract virtio_read_caps() here. As that detects wheter it is a legacy or modern (virtio 1.0) virtio device or not.
If virtio_read_caps failes, which could either due to pci map failed, or because malformed pci layout, we fallback to legacy virtio 1.0 handling, using io port read/write to do configuration.
Quoted 6 lines
Let me describe it more.
So far, we need to handle below 3 virtio-net devices..
- physical virtio-net device.
- virtual virtio-net device in virtio-net PMD. (Jianfeng's patch)
- virtual virtio-net device in QEMU. (my patch)
Quoted 6 lines
Almost all code of the virtio-net PMD can be shared between above different cases.
Probably big difference is how to access to configuration space.Yuanhan's patch introduces an abstraction layer to hide configuration space layout and how to access it.
Actually, I didn't introduce the abstraction for pci device access. It's just a simple "if ... else ..." case here: use io port read/write, the VIRTIO_READ/WRITE_REG_X macros, to do access for legacy virtio, otherwise for modern virtio, use direct mapped memory read/write access:
modern_read/writex.
Quoted 1 line
Is it possible to separate?
As stated, there is no mix, therefore no need for seperation. But you could add another access abstraction layer, and assign it properly later, say, by checking eth_dev->dev_type as you suggested below.
Quoted 11 lines
I guess "access method" will be nice to be abstracted separately from "configuration space layout".
Probably access method will be defined by "eth_dev->dev_type" and the PMD name like "eth_cvio".
And "configuration space layout" will be defined by capability list of PCI configuration layout.For example, if access method like below are abstracted separately and current "
virtio_pci.c" is implemented on this abstraction, we can easily re-usevirtio_read_caps().
- how to read/write virtio configuration space.
It's abstracted by virtio_pci_ops.
Quoted 2 lines
- how to mmap PCI configuration space.
- how to read/(write) PCI configuration space.
For now, it's actually done by EAL, or by functions provided by EAL. I haven't read your (as well Jianfeng's) code yet, but seems that you need implement another set of functions for above needes for your virtio device.
If so, I'd suggest you (or Jianfeng) to do the abstraction based on my patchset: what I am kind of sure is that I should not add those abstraction here, simply for it has nothing to do with virtio 1.0 enabling.
--yliu
Re: [PATCH v2 0/7] virtio 1.0 enabling for virtio pmd driver
In reply to Tetsuya MukawaHi Tetsuya,
Quoted 8 lines · Tetsuya Mukawa
On 2016/01/12 15:58, Yuanhan Liu wrote:
Hi Yuanhan and Jianfeng,Thanks for great patches.
I want to use VIRTIO-1.0 feature for my virtio container patch, because it will solve 44 bit memory address limitation.
(So far, legacy virtio-net device only receives queue address under (1 << (32 + 12)).)
I suppose you are specifying the code below:
/*
* Virtio PCI device VIRTIO_PCI_QUEUE_PF register is 32bit,
* and only accepts 32 bit page frame number.
* Check if the allocated physical memory exceeds 16TB. */
if ((mz->phys_addr + vq->vq_ring_size - 1) >>
(VIRTIO_PCI_QUEUE_ADDR_SHIFT + 32)) {
PMD_INIT_LOG(ERR, "vring address shouldn't be above
16TB!");
rte_free(vq);
return -ENOMEM;
}So you don't need to add extra cmd option, right?
Quoted 8 lines
I have a few comments to rebase virtio container patches on this patches.
1.
VIRTIO_READ_REG_XSo far, VIRTIO_READ_REG_1/2/4 are defined in
virtio_pci.h. But these macros are only referred byvirtio_pci.c. How about moving the macros tovirtio_pci.c?
+1 for this.
Quoted 25 lines
2. Abstraction of read/write accesses.
It may be difficult to cleanly rebase my patches on this patches, because
virtio_read_caps()is not abstracted.
Let me describe it more.
So far, we need to handle below 3 virtio-net devices..
- physical virtio-net device.
- virtual virtio-net device in virtio-net PMD. (Jianfeng's patch)
- virtual virtio-net device in QEMU. (my patch)Almost all code of the virtio-net PMD can be shared between above different cases.
Probably big difference is how to access to configuration space.Yuanhan's patch introduces an abstraction layer to hide configuration space layout and how to access it.
Is it possible to separate?
I guess "access method" will be nice to be abstracted separately from "configuration space layout".
Probably access method will be defined by "eth_dev->dev_type" and the PMD name like "eth_cvio".
And "configuration space layout" will be defined by capability list of PCI configuration layout.
Quoted 6 lines
For example, if access method like below are abstracted separately and current "
virtio_pci.c" is implemented on this abstraction, we can easily re-usevirtio_read_caps().
- how to read/write virtio configuration space.
- how to mmap PCI configuration space.
- how to read/(write) PCI configuration space.
I basically agree with you. We have two dimensions here:
legacy modern
physical virtio device: Use virtio_read_caps_phys() to distinguish virtual virtio device (Tetsuya): Use virtio_read_caps_virt() to distinguish virtual virtio device (Jianfeng): does not need a "configuration space layout", no need to distinguish
So in vtpci_init(), we needs to test "eth_dev->dev_type" firstly
vtpci_init() {
if (eth_dev->dev_type == RTE_ETH_DEV_PCI) {
if (virtio_read_caps_phys()) {
// modern
} else {
// legacy
}
} else {
if (Tetsuya's way) {
if (virtio_read_caps_virt()) {
// modern
} else {
// legacy
}
} else {
// Jianfeng's way
}
}
}And from Yuanhan's angle, I think he does not need to address this problem. How do you think?
Thanks,
Jianfeng
Quoted 3 lines
Thanks,
Tetsuya
Re: [PATCH v2 0/7] virtio 1.0 enabling for virtio pmd driver
Quoted 22 lines · Jianfeng
Hi Tetsuya,
Quoted 8 lines · Tetsuya Mukawa
On 2016/01/12 15:58, Yuanhan Liu wrote:
Hi Yuanhan and Jianfeng,Thanks for great patches.
I want to use VIRTIO-1.0 feature for my virtio container patch, because it will solve 44 bit memory address limitation.
(So far, legacy virtio-net device only receives queue address under (1 << (32 + 12)).)I suppose you are specifying the code below:
/*
* Virtio PCI deviceVIRTIO_PCI_QUEUE_PFregister is 32bit,
* and only accepts 32 bit page frame number.
* Check if the allocated physical memory exceeds 16TB. */
if ((mz->phys_addr+vq->vq_ring_size- 1) >>
(VIRTIO_PCI_QUEUE_ADDR_SHIFT+ 32)) {
PMD_INIT_LOG(ERR, "vring address shouldn't be above
Quoted 6 lines
16TB!"); rte_free(vq); return -ENOMEM; }So you don't need to add extra cmd option, right?
Yes, this is the code.
In our case, instead of using physical address, virtual address will be used, right?
Problem is that virtual address will be over (1 << 44) without specifying some mmap options.
Probably we need to specify "MAP_FIXED" option while mmapping EAL memory to get lower address.
But if we can use VIRTIO-1.0, we can specify 64bit address, then we don't need to do something tricky mmaping.
Quoted 78 lines
Quoted 10 lines
I have a few comments to rebase virtio container patches on this patches.
1.
VIRTIO_READ_REG_XSo far, VIRTIO_READ_REG_1/2/4 are defined in
virtio_pci.h. But these macros are only referred byvirtio_pci.c. How about moving the macros tovirtio_pci.c?+1 for this.
Quoted 25 lines
2. Abstraction of read/write accesses.
It may be difficult to cleanly rebase my patches on this patches, because
virtio_read_caps()is not abstracted.
Let me describe it more.
So far, we need to handle below 3 virtio-net devices..
- physical virtio-net device.
- virtual virtio-net device in virtio-net PMD. (Jianfeng's patch)
- virtual virtio-net device in QEMU. (my patch)Almost all code of the virtio-net PMD can be shared between above different cases.
Probably big difference is how to access to configuration space.Yuanhan's patch introduces an abstraction layer to hide configuration space layout and how to access it.
Is it possible to separate?
I guess "access method" will be nice to be abstracted separately from "configuration space layout".
Probably access method will be defined by "eth_dev->dev_type" and the PMD name like "eth_cvio".
And "configuration space layout" will be defined by capability list of PCI configuration layout.Quoted 6 lines
For example, if access method like below are abstracted separately and current "
virtio_pci.c" is implemented on this abstraction, we can easily re-usevirtio_read_caps().
- how to read/write virtio configuration space.
- how to mmap PCI configuration space.
- how to read/(write) PCI configuration space.I basically agree with you. We have two dimensions here:
legacy modern
physical virtio device: Usevirtio_read_caps_phys()to distinguish
virtual virtio device (Tetsuya): Usevirtio_read_caps_virt()to
distinguish
virtual virtio device (Jianfeng): does not need a "configuration
space layout", no need to distinguishSo in
vtpci_init(), we needs to test "eth_dev->dev_type" firstlyvtpci_init() { if (eth_dev->dev_type == RTE_ETH_DEV_PCI) { if (virtio_read_caps_phys()) { // modern } else { // legacy } } else { if (Tetsuya's way) { if (virtio_read_caps_virt()) { // modern } else { // legacy } } else { // Jianfeng's way } } }
Quoted 2 lines
And from Yuanhan's angle, I think he does not need to address this problem. How do you think?
Yes, I agree he doesn't need.
Firstly, I have implemented like above, then I noticed that virtio_read_caps_phy() and virtio_read_caps_virt() are same except for access method.
Anyway, I guess abstracting access method is not so difficult. If you are OK, I want to send RFC on Yuanhan's patch. Is it OK?
Thanks,
Tetsuya
Re: [PATCH v2 0/7] virtio 1.0 enabling for virtio pmd driver
In reply to Tan, JianfengOn Thu, Jan 14, 2016 at 02:09:18PM +0800, Tan, Jianfeng wrote:
...
Quoted 9 lines
I basically agree with you. We have two dimensions here:
legacy modern
physical virtio device: Usevirtio_read_caps_phys()to
distinguish
virtual virtio device (Tetsuya): Usevirtio_read_caps_virt()to
distinguish
virtual virtio device (Jianfeng): does not need a "configuration space
layout", no need to distinguish
I guess you meant to build a form or something, but seems you failed :)
Quoted 14 lines
So in
vtpci_init(), we needs to test "eth_dev->dev_type" firstlyvtpci_init() { if (eth_dev->dev_type == RTE_ETH_DEV_PCI) { if (virtio_read_caps_phys()) { // modern } else { // legacy } } else { if (Tetsuya's way) { if (virtio_read_caps_virt()) { // modern
Quoted 8 lines
} else {
// legacy
}
} else {
// Jianfeng's way
}
}
}Normally, I'd like to hide the details inside virtio_read_caps(): I don't want similar codes to be appeared twice. And if it can be simply done by "if (eth_dev->dev_type == ...)", I'd like to do it in this way. If not, introducing another set of operation abstractions as suggested in my another email might be a better option.
Quoted 1 line
And from Yuanhan's angle, I think he does not need to address this problem.
Yep; it just has nothing to do with this patch set.
--yliu
PATCH v3 1/8 virtio: don't set vring address again at queue startup
In reply to Yuanhan LiuAs we have already set up it at virtio_dev_queue_setup(), and a vq restart will not reset the settings.
--- drivers/net/virtio/virtio_rxtx.c | 15 --------------- 1 file changed, 15 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -15
@@ -339,11 +339,6 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)vq_update_avail_idx (vq);PMD_INIT_LOG (DEBUG ,"Allocated %d bufs" , nbufs); - -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); }else if (queue_type ==VTNET_TQ ) {if (use_simple_rxtx) {int mid_idx = vq->vq_nentries >>1 ;
@@ -362,16 +357,6 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)for (i = mid_idx; i < vq->vq_nentries; i++) vq->vq_ring.avail->ring[i] = i; } - -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); - }else { -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); } }
Signature · 1 line
1.9.0
v3 cover virtio 1.0 enabling for virtio pmd driver
In reply to Yuanhan Liuv3: - export pci_unmap_device as well; and invoke it at virtio
uninit stage.
- fixed same data corruption bug reported by Qian in simple rxtx code path.
- move VIRTIO_READ/WRITE_REG_X to virtio_pci.c
v2: - fix a data corruption reported by Qian, due to hdr size mismatch.
check detailes at ptach 5.
- Add missing config_irq and isr reading support from v1.
- fix comments from v1.
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 7.
To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a virtio_pci_ops structure, to add another layer so that we could keep those vtpci_foo_bar "APIs". With that, we could do the minimum change to add virtio 1.0 support.
Rough test guide
================
Firstly, you need get a virtio 1.0 supported QEMU (say, v2.5), then add option "disable-modern=false" to qemu virtio-net-pci device to enable virtio 1.0 (which is disabled by default).
And if you see something like following from 'lspci -v', it means virtio 1.0 is indeed enabled:
00:04.0 Ethernet controller: Red Hat, Inc Virtio network device
Subsystem: Red Hat, Inc Device 0001
Physical Slot: 4
Flags: bus master, fast devsel, latency 0, IRQ 11 I/O ports at c040 [size=64]
Memory at febf1000 (32-bit, non-prefetchable) [size=4K] Memory at fe000000 (64-bit, prefetchable) [size=8M] Expansion ROM at feb80000 [disabled] [size=256K]
Capabilities: [98] MSI-X: Enable+ Count=6 Masked-
==> Capabilities: [84] Vendor Specific Information: Len=14 <?> ==> Capabilities: [70] Vendor Specific Information: Len=14 <?> ==> Capabilities: [60] Vendor Specific Information: Len=10 <?> ==> Capabilities: [50] Vendor Specific Information: Len=10 <?> ==> Capabilities: [40] Vendor Specific Information: Len=10 <?>
Kernel driver in use: virtio-pci
Kernel modules: virtio_pci
After that, there wasn't anything speical comparing to the old virtio 0.95 pmd driver.
---
Yuanhan Liu (8):
virtio: don't set vring address again at queue startup
virtio: introduce struct virtio_pci_ops
virtio: move left pci stuff to virtio_pci.c
viritio: switch to 64 bit features
virtio: retrieve hdr_size from hw->vtnet_hdr_size
eal: pci: export pci_[un]map_device
virtio: add 1.0 support
virtio: move VIRTIO_READ/WRITE_REG_X into virtio_pci.c
doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 302 +-------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 787 +++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 120 +++- drivers/net/virtio/virtio_rxtx.c | 21 +- drivers/net/virtio/virtio_rxtx_simple.c | 12 +- drivers/net/virtio/virtqueue.h | 4 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 +- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 7 + lib/librte_eal/common/eal_common_pci.c | 4 +- lib/librte_eal/common/eal_private.h | 18 - lib/librte_eal/common/include/rte_pci.h | 27 + lib/librte_eal/linuxapp/eal/eal_pci.c | 4 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 7 + 15 files changed, 946 insertions(+), 377 deletions(-)
Signature · 1 line
1.9.0
PATCH v3 2/8 virtio: introduce struct virtio_pci_ops
Introduce struct virtio_pci_ops, to let legacy virtio (v0.95) and modern virtio (1.0) have different implementation regarding to a specific pci action, such as read host status.
With that, this patch reimplements all exported pci functions, in a way like:
vtpci_foo_bar(struct virtio_hw *hw)
{
hw->vtpci_ops->foo_bar(hw);
}So that we need pay attention to those pci related functions only while adding virtio 1.0 support.
This patch introduced a new vtpci function, vtpci_init(), to do proper virtio pci settings. It's pretty simple so far: just sets hw->vtpci_ops to legacy_ops as we don't support 1.0 yet.
---
v2: extra whitespace line removing, and comment on "reading status
after reset".
rename the badly taken op name "set_irq" to "set_config_irq".
--- drivers/net/virtio/virtio_ethdev.c | 22 ++---- drivers/net/virtio/virtio_pci.c | 158 ++++++++++++++++++++++++++++++------- drivers/net/virtio/virtio_pci.h | 27 +++++++ drivers/net/virtio/virtqueue.h | 2 +- 4 files changed, 166 insertions(+), 43 deletions(-)
drivers/net/virtio/virtio_ethdev.c +8 -14
@@ -272,9 +272,7 @@ virtio_dev_queue_release(struct virtqueue *vq) {if (vq) { hw = vq->hw; -/* Select and deactivate the queue */ -VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN ,0 ); + hw->vtpci_ops->del_queue (hw, vq);rte_free (vq->sw_ring);rte_free (vq);
@@ -295,15 +293,13 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,struct virtio_hw *hw = dev->data->dev_private;struct virtqueue *vq =NULL ; -/* Write the virtqueue index to the Queue Select Field */ -VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vtpci_queue_idx); -PMD_INIT_LOG (DEBUG ,"selecting queue: %u" , vtpci_queue_idx); +PMD_INIT_LOG (DEBUG ,"setting up queue: %u" , vtpci_queue_idx);/* * Read the virtqueue size from the Queue Size field * Always power of 2 and if 0 virtqueue does not exist */ - vq_size =VIRTIO_READ_REG_2 (hw,VIRTIO_PCI_QUEUE_NUM ); + vq_size = hw->vtpci_ops->get_queue_num (hw, vtpci_queue_idx);PMD_INIT_LOG (DEBUG ,"vq_size: %u nb_desc:%u" , vq_size, nb_desc);if (vq_size ==0 ) {PMD_INIT_LOG (ERR ,"%s: virtqueue does not exist" , __func__);
@@ -436,12 +432,8 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,memset (vq->virtio_net_hdr_mz->addr,0 ,PAGE_SIZE ); } -/* -* Set guest physical address of the virtqueue -* in VIRTIO_PCI_QUEUE_PFN config register of device -*/ -VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN , - mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); + hw->vtpci_ops->setup_queue (hw, vq); + *pvq = vq;return 0 ; }
@@ -950,7 +942,7 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features);/* Read device(host) feature bits */ - host_features =VIRTIO_READ_REG_4 (hw,VIRTIO_PCI_HOST_FEATURES ); + host_features = hw->vtpci_ops->get_features (hw);PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %x" , host_features);
@@ -1287,6 +1279,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; +vtpci_init (pci_dev, hw); +if (virtio_resource_init (pci_dev) <0 )return -1 ;
drivers/net/virtio/virtio_pci.c +130 -28
213 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +27 -0
@@ -163,6 +163,31 @@ struct virtqueue;*/ #define VIRTIO_MAX_VIRTQUEUES 8 +struct virtio_hw ; + +struct virtio_pci_ops { +void (*read_dev_cfg)(struct virtio_hw *hw,uint64_t offset, +void *dst,int len); +void (*write_dev_cfg)(struct virtio_hw *hw,uint64_t offset, +void *src,int len); +void (*reset)(struct virtio_hw *hw); + +uint8_t (*get_status)(struct virtio_hw *hw); +void (*set_status)(struct virtio_hw *hw,uint8_t status); + +uint32_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint32_t features); + +uint8_t (*get_isr)(struct virtio_hw *hw); + +uint16_t (*set_config_irq)(struct virtio_hw *hw,uint16_t vec); + +uint16_t (*get_queue_num)(struct virtio_hw *hw,uint16_t queue_id); +void (*setup_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*del_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*notify_queue)(struct virtio_hw *hw,struct virtqueue *vq); +}; +struct virtio_hw {struct virtqueue *cvq;uint32_t io_base;
@@ -174,6 +199,7 @@ struct virtio_hw {uint8_t use_msix;uint8_t started;uint8_t mac_addr[ETHER_ADDR_LEN ]; +const struct virtio_pci_ops *vtpci_ops; };/*
@@ -253,6 +279,7 @@ vtpci_with_feature(struct virtio_hw *hw, uint32_t bit)/* * Function declaration from virtio_pci.c */ +int vtpci_init (struct rte_pci_device *,struct virtio_hw *);void vtpci_reset (struct virtio_hw *);void vtpci_reinit_complete (struct virtio_hw *);
drivers/net/virtio/virtqueue.h +1 -1
@@ -302,7 +302,7 @@ virtqueue_notify(struct virtqueue *vq)* For virtio on IA, the notificaiton is through io port operation * which is a serialization instruction itself. */ -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_NOTIFY , vq->vq_queue_index); + vq->hw->vtpci_ops->notify_queue (vq->hw, vq); }#ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP
Signature · 1 line
1.9.0
PATCH v3 3/8 virtio: move left pci stuff to virtio_pci.c
In reply to Yuanhan Liuvirtio_pci.c is a more proper place for pci stuff; virtio_ethdev.c is not.
--- drivers/net/virtio/virtio_ethdev.c | 265 +----------------------------------- drivers/net/virtio/virtio_pci.c | 270 ++++++++++++++++++++++++++++++++++++- 2 files changed, 270 insertions(+), 265 deletions(-)
drivers/net/virtio/virtio_ethdev.c +1 -264
@@ -36,10 +36,6 @@#include <stdio.h> #include <errno.h> #include <unistd.h> -#ifdef RTE_EXEC_ENV_LINUXAPP -#include <dirent.h> -#include <fcntl.h> -#endif #include <rte_ethdev.h> #include <rte_memcpy.h>
@@ -955,260 +951,6 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features); } -#ifdef RTE_EXEC_ENV_LINUXAPP -static int -parse_sysfs_value (const char *filename,unsigned long *val) -{ -FILE *f; -char buf[BUFSIZ ]; -char *end =NULL ; - - f =fopen (filename,"r" ); -if (f ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): cannot open sysfs value %s" , - __func__, filename); -return -1 ; - } - -if (fgets (buf,sizeof (buf), f) ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): cannot read sysfs value %s" , - __func__, filename); -fclose (f); -return -1 ; - } - *val =strtoul (buf, &end,0 ); -if ((buf[0 ] =='\0' ) || (end ==NULL ) || (*end !='\n' )) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse sysfs value %s" , - __func__, filename); -fclose (f); -return -1 ; - } -fclose (f); -return 0 ; -} - -static int get_uio_dev (struct rte_pci_addr *loc,char *buf,unsigned int buflen, -unsigned int *uio_num) -{ -struct dirent *e; -DIR *dir; -char dirname[PATH_MAX ]; - -/* depending on kernel version, uio can be located in uio/uioX -* or uio:uioX */ -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio" , - loc->domain, loc->bus, loc->devid, loc->function); - dir =opendir (dirname); -if (dir ==NULL ) { -/* retry with the parent directory */ -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT , - loc->domain, loc->bus, loc->devid, loc->function); - dir =opendir (dirname); - -if (dir ==NULL ) { -PMD_INIT_LOG (ERR ,"Cannot opendir %s" , dirname); -return -1 ; - } - } - -/* take the first file starting with "uio" */ -while ((e =readdir (dir)) !=NULL ) { -/* format could be uio%d ...*/ -int shortprefix_len =sizeof ("uio" ) -1 ; -/* ... or uio:uio%d */ -int longprefix_len =sizeof ("uio:uio" ) -1 ; -char *endptr; - -if (strncmp (e->d_name,"uio" ,3 ) !=0 ) -continue ; - -/* first try uio%d */ - errno =0 ; - *uio_num =strtoull (e->d_name + shortprefix_len, &endptr,10 ); -if (errno ==0 && endptr != (e->d_name + shortprefix_len)) { -snprintf (buf, buflen,"%s/uio%u" , dirname, *uio_num); -break ; - } - -/* then try uio:uio%d */ - errno =0 ; - *uio_num =strtoull (e->d_name + longprefix_len, &endptr,10 ); -if (errno ==0 && endptr != (e->d_name + longprefix_len)) { -snprintf (buf, buflen,"%s/uio:uio%u" , dirname, - *uio_num); -break ; - } - } -closedir (dir); - -/* No uio resource found */ -if (e ==NULL ) { -PMD_INIT_LOG (ERR ,"Could not find uio resource" ); -return -1 ; - } - -return 0 ; -} - -static int -virtio_has_msix (const struct rte_pci_addr *loc) -{ -DIR *d; -char dirname[PATH_MAX ]; - -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/msi_irqs" , - loc->domain, loc->bus, loc->devid, loc->function); - - d =opendir (dirname); -if (d) -closedir (d); - -return (d !=NULL ); -} - -/* Extract I/O port numbers from sysfs */ -static int virtio_resource_init_by_uio (struct rte_pci_device *pci_dev) -{ -char dirname[PATH_MAX ]; -char filename[PATH_MAX ]; -unsigned long start, size; -unsigned int uio_num; - -if (get_uio_dev (&pci_dev->addr, dirname,sizeof (dirname), &uio_num) <0 ) -return -1 ; - -/* get portio size */ -snprintf (filename,sizeof (filename), -"%s/portio/port0/size" , dirname); -if (parse_sysfs_value (filename, &size) <0 ) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse size" , - __func__); -return -1 ; - } - -/* get portio start */ -snprintf (filename,sizeof (filename), -"%s/portio/port0/start" , dirname); -if (parse_sysfs_value (filename, &start) <0 ) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse portio start" , - __func__); -return -1 ; - } - pci_dev->mem_resource[0 ].addr = (void *)(uintptr_t )start; - pci_dev->mem_resource[0 ].len = (uint64_t )size; -PMD_INIT_LOG (DEBUG , -"PCI Port IO found start=0x%lx with size=0x%lx" , - start, size); - -/* save fd */ -memset (dirname,0 ,sizeof (dirname)); -snprintf (dirname,sizeof (dirname),"/dev/uio%u" , uio_num); - pci_dev->intr_handle.fd =open (dirname,O_RDWR ); -if (pci_dev->intr_handle.fd <0 ) { -PMD_INIT_LOG (ERR ,"Cannot open %s: %s\n" , - dirname,strerror (errno)); -return -1 ; - } - - pci_dev->intr_handle.type =RTE_INTR_HANDLE_UIO ; - pci_dev->driver->drv_flags |=RTE_PCI_DRV_INTR_LSC ; - -return 0 ; -} - -/* Extract port I/O numbers from proc/ioports */ -static int virtio_resource_init_by_ioports (struct rte_pci_device *pci_dev) -{ -uint16_t start, end; -int size; -FILE *fp; -char *line =NULL ; -char pci_id[16 ]; -int found =0 ; -size_t linesz; - -snprintf (pci_id,sizeof (pci_id),PCI_PRI_FMT , - pci_dev->addr.domain, - pci_dev->addr.bus, - pci_dev->addr.devid, - pci_dev->addr.function); - - fp =fopen ("/proc/ioports" ,"r" ); -if (fp ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): can't open ioports" , __func__); -return -1 ; - } - -while (getdelim (&line, &linesz,'\n' , fp) >0 ) { -char *ptr = line; -char *left; -int n; - - n =strcspn (ptr,":" ); - ptr[n] =0 ; - left = &ptr[n+1 ]; - -while (*left &&isspace (*left)) - left++; - -if (!strncmp (left, pci_id,strlen (pci_id))) { - found =1 ; - -while (*ptr &&isspace (*ptr)) - ptr++; - -sscanf (ptr,"%04hx-%04hx" , &start, &end); - size = end - start +1 ; - -break ; - } - } - -free (line); -fclose (fp); - -if (!found) -return -1 ; - - pci_dev->mem_resource[0 ].addr = (void *)(uintptr_t )(uint32_t )start; - pci_dev->mem_resource[0 ].len = (uint64_t )size; -PMD_INIT_LOG (DEBUG , -"PCI Port IO found start=0x%x with size=0x%x" , - start, size); - -/* can't support lsc interrupt without uio */ - pci_dev->driver->drv_flags &= ~RTE_PCI_DRV_INTR_LSC ; - -return 0 ; -} - -/* Extract I/O port numbers from sysfs */ -static int virtio_resource_init (struct rte_pci_device *pci_dev) -{ -if (virtio_resource_init_by_uio (pci_dev) ==0 ) -return 0 ; -else -return virtio_resource_init_by_ioports (pci_dev); -} - -#else -static int -virtio_has_msix(const struct rte_pci_addr *loc __rte_unused) -{ -/* nic_uio does not enable interrupts, return 0 (false). */ -return 0 ; -} - -static int virtio_resource_init(struct rte_pci_device *pci_dev __rte_unused) -{ -/* no setup required */ -return 0 ; -} -#endif -/* * Process Virtio Config changed interrupt and call the callback * if link state changed.
@@ -1279,14 +1021,9 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; -vtpci_init (pci_dev, hw); - -if (virtio_resource_init (pci_dev) <0 ) +if (vtpci_init (pci_dev, hw) <0 )return -1 ; - hw->use_msix =virtio_has_msix (&pci_dev->addr); - hw->io_base = (uint32_t )(uintptr_t )pci_dev->mem_resource[0 ].addr; -/* Reset the device although not necessary at startup */ vtpci_reset (hw);
drivers/net/virtio/virtio_pci.c +269 -1
290 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH v3 4/8 viritio: switch to 64 bit features
In reply to Yuanhan LiuSwitch to 64 bit features, that virtio 1.0 supports.
While legacy virtio only supports 32 bit features, here we complain aloud and quit when trying to setting > 32 bit features for legacy device.
--- drivers/net/virtio/virtio_ethdev.c | 8 ++++---- drivers/net/virtio/virtio_pci.c | 15 ++++++++++----- drivers/net/virtio/virtio_pci.h | 12 ++++++------ 3 files changed, 20 insertions(+), 15 deletions(-)
drivers/net/virtio/virtio_ethdev.c +4 -4
@@ -930,16 +930,16 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)static void virtio_negotiate_features (struct virtio_hw *hw) { -uint32_t host_features; +uint64_t host_features;/* Prepare guest_features: feature that driver wants to support */ hw->guest_features =VIRTIO_PMD_GUEST_FEATURES ; -PMD_INIT_LOG (DEBUG ,"guest_features before negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"guest_features before negotiate = %" PRIx64, hw->guest_features);/* Read device(host) feature bits */ host_features = hw->vtpci_ops->get_features (hw); -PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %" PRIx64, host_features);/*
@@ -947,7 +947,7 @@ virtio_negotiate_features(struct virtio_hw *hw)* guest feature bits. */ hw->guest_features =vtpci_negotiate_features (hw, host_features); -PMD_INIT_LOG (DEBUG ,"features after negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); }
drivers/net/virtio/virtio_pci.c +10 -5
@@ -87,15 +87,20 @@ legacy_write_dev_config(struct virtio_hw *hw, uint64_t offset, } } -static uint32_t +static uint64_t legacy_get_features (struct virtio_hw *hw) {return VIRTIO_READ_REG_4 (hw,VIRTIO_PCI_HOST_FEATURES ); }static void -legacy_set_features (struct virtio_hw *hw,uint32_t features) +legacy_set_features (struct virtio_hw *hw,uint64_t features) { +if ((features >>32 ) !=0 ) { +PMD_DRV_LOG (ERR , +"only 32 bit features are allowed for legacy virtio!" ); +return ; + }VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_GUEST_FEATURES , features); }
@@ -451,10 +456,10 @@ vtpci_write_dev_config(struct virtio_hw *hw, uint64_t offset, hw->vtpci_ops->write_dev_cfg (hw, offset, src, length); } -uint32_t -vtpci_negotiate_features (struct virtio_hw *hw,uint32_t host_features) +uint64_t +vtpci_negotiate_features (struct virtio_hw *hw,uint64_t host_features) { -uint32_t features; +uint64_t features;/* * Limit negotiated features to what the driver, virtqueue, and
drivers/net/virtio/virtio_pci.h +6 -6
@@ -175,8 +175,8 @@ struct virtio_pci_ops {uint8_t (*get_status)(struct virtio_hw *hw);void (*set_status)(struct virtio_hw *hw,uint8_t status); -uint32_t (*get_features)(struct virtio_hw *hw); -void (*set_features)(struct virtio_hw *hw,uint32_t features); +uint64_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint64_t features);uint8_t (*get_isr)(struct virtio_hw *hw);
@@ -191,7 +191,7 @@ struct virtio_pci_ops {struct virtio_hw {struct virtqueue *cvq;uint32_t io_base; -uint32_t guest_features; +uint64_t guest_features;uint32_t max_tx_queues;uint32_t max_rx_queues;uint16_t vtnet_hdr_size;
@@ -271,9 +271,9 @@ outl_p(unsigned int data, unsigned int port) outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg))))static inline int -vtpci_with_feature (struct virtio_hw *hw,uint32_t bit) +vtpci_with_feature (struct virtio_hw *hw,uint64_t bit) { -return (hw->guest_features & (1u << bit)) !=0 ; +return (hw->guest_features & (1ULL << bit)) !=0 ; }/*
@@ -286,7 +286,7 @@ void vtpci_reinit_complete(struct virtio_hw *);void vtpci_set_status (struct virtio_hw *,uint8_t ); -uint32_t vtpci_negotiate_features (struct virtio_hw *,uint32_t ); +uint64_t vtpci_negotiate_features (struct virtio_hw *,uint64_t );void vtpci_write_dev_config (struct virtio_hw *,uint64_t ,void *,int );
Signature · 1 line
1.9.0
PATCH v3 5/8 virtio: retrieve hdr_size from hw->vtnet_hdr_size
In reply to Yuanhan LiuThe mergeable virtio net hdr format has been the standard and the only virtio net hdr format since virtio 1.0. Therefore, we can not hardcode hdr_size to "sizeof(struct virtio_net_hdr)" any more at virtio_recv_pkts(), otherwise, there would be a mismatch of hdr size from rte_vhost_enqueue_burst() and virtio_recv_pkts(), leading a packet corruption.
Instead, we should retrieve it from hw->vtnet_hdr_size; we will do proper settings at eth_virtio_dev_init() in later patches.
---
v3: retrieve hdr_size from hw->vtnet_hdr_size for simple rxtx
code path as well: it should not break anything, as simple rx and mergeable rx still will not co-exist.
--- drivers/net/virtio/virtio_rxtx.c | 6 ++++-- drivers/net/virtio/virtio_rxtx_simple.c | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/net/virtio/virtio_rxtx.c +4 -2
@@ -560,7 +560,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)struct rte_mbuf *rcv_pkts[VIRTIO_MBUF_BURST_SZ ];int error;uint32_t i, nb_enqueued; -const uint32_t hdr_size =sizeof (struct virtio_net_hdr ); +uint32_t hdr_size; nb_used =VIRTQUEUE_NUSED (rxvq);
@@ -580,6 +580,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) hw = rxvq->hw; nb_rx =0 ; nb_enqueued =0 ; + hdr_size = hw->vtnet_hdr_size;for (i =0 ; i < num ; i++) { rxm = rcv_pkts[i];
@@ -664,7 +665,7 @@ virtio_recv_mergeable_pkts(void *rx_queue,uint32_t seg_num;uint16_t extra_idx;uint32_t seg_res; -const uint32_t hdr_size =sizeof (struct virtio_net_hdr_mrg_rxbuf ); +uint32_t hdr_size; nb_used =VIRTQUEUE_NUSED (rxvq);
@@ -682,6 +683,7 @@ virtio_recv_mergeable_pkts(void *rx_queue, seg_num =0 ; extra_idx =0 ; seg_res =0 ; + hdr_size = hw->vtnet_hdr_size;while (i < nb_used) {struct virtio_net_hdr_mrg_rxbuf *header;
drivers/net/virtio/virtio_rxtx_simple.c +6 -6
@@ -81,9 +81,9 @@ virtqueue_enqueue_recv_refill_simple(struct virtqueue *vq, start_dp = vq->vq_ring.desc; start_dp[desc_idx].addr = (uint64_t )((uintptr_t )cookie->buf_physaddr + -RTE_PKTMBUF_HEADROOM -sizeof (struct virtio_net_hdr )); +RTE_PKTMBUF_HEADROOM - vq->hw->vtnet_hdr_size); start_dp[desc_idx].len = cookie->buf_len - -RTE_PKTMBUF_HEADROOM +sizeof (struct virtio_net_hdr ); +RTE_PKTMBUF_HEADROOM + vq->hw->vtnet_hdr_size; vq->vq_free_cnt--; vq->vq_avail_idx++;
@@ -120,9 +120,9 @@ virtio_rxq_rearm_vec(struct virtqueue *rxvq) start_dp[i].addr = (uint64_t )((uintptr_t )sw_ring[i]->buf_physaddr + -RTE_PKTMBUF_HEADROOM -sizeof (struct virtio_net_hdr )); +RTE_PKTMBUF_HEADROOM - rxvq->hw->vtnet_hdr_size); start_dp[i].len = sw_ring[i]->buf_len - -RTE_PKTMBUF_HEADROOM +sizeof (struct virtio_net_hdr ); +RTE_PKTMBUF_HEADROOM + rxvq->hw->vtnet_hdr_size; } rxvq->vq_avail_idx +=RTE_VIRTIO_VPMD_RX_REARM_THRESH ;
@@ -175,8 +175,8 @@ virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts, len_adjust =_mm_set_epi16 (0 ,0 ,0 , - (uint16_t ) -sizeof (struct virtio_net_hdr ), -0 , (uint16_t ) -sizeof (struct virtio_net_hdr ), + (uint16_t ) -rxvq->hw->vtnet_hdr_size, +0 , (uint16_t ) -rxvq->hw->vtnet_hdr_size,0 ,0 );if (unlikely (nb_pkts <RTE_VIRTIO_DESC_PER_LOOP ))
Signature · 1 line
1.9.0
PATCH v3 6/8 eal: pci: export pci_[un]map_device
In reply to Yuanhan LiuNormally we could set RTE_PCI_DRV_NEED_MAPPING flag so that eal will invoke pci_map_device internally for us. From that point view, there is no need to export pci_map_device.
However, for virtio pmd driver, which is designed to work without binding UIO (or something similar first), pci_map_device() will fail, which ends up with virtio pmd driver being skipped. Therefore, we can not set RTE_PCI_DRV_NEED_MAPPING blindly at virtio pmd driver.
Therefore, this patch exports pci_map_device, and let virtio pmd call it when necessary.
---
v3: - export pci_unmap_device as well
- Add few more comments about rte_eal_pci_map_device().
--- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 ++-- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 7 +++++++ lib/librte_eal/common/eal_common_pci.c | 4 ++-- lib/librte_eal/common/eal_private.h | 18 ----------------- lib/librte_eal/common/include/rte_pci.h | 27 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 4 ++-- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 7 +++++++ 7 files changed, 47 insertions(+), 24 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -2
@@ -93,7 +93,7 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)/* Map pci device */ int -pci_map_device (struct rte_pci_device *dev) +rte_eal_pci_map_device (struct rte_pci_device *dev) {int ret =-1 ;
@@ -115,7 +115,7 @@ pci_map_device(struct rte_pci_device *dev)/* Unmap pci device */ void -pci_unmap_device (struct rte_pci_device *dev) +rte_eal_pci_unmap_device (struct rte_pci_device *dev) {/* try unmapping the NIC resources */ switch (dev->kdrv) {
lib/librte_eal/bsdapp/eal/rte_eal_version.map +7 -0
@@ -135,3 +135,10 @@ DPDK_2.2 { rte_xen_dom0_supported; } DPDK_2.1; + +DPDK_2.3 { + global: + + rte_eal_pci_map_device; + rte_eal_pci_unmap_device; +} DPDK_2.2;
lib/librte_eal/common/eal_common_pci.c +2 -2
@@ -188,7 +188,7 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dpci_config_space_set (dev);#endif /* map resources for devices that use igb_uio */ - ret =pci_map_device (dev); + ret =rte_eal_pci_map_device (dev);if (ret !=0 )return ret; } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
@@ -254,7 +254,7 @@ rte_eal_pci_detach_dev(struct rte_pci_driver *dr,if (dr->drv_flags &RTE_PCI_DRV_NEED_MAPPING )/* unmap resources for devices that use igb_uio */ -pci_unmap_device (dev); +rte_eal_pci_unmap_device (dev);return 0 ; }
lib/librte_eal/common/eal_private.h +0 -18
@@ -165,24 +165,6 @@ struct rte_pci_device;int pci_unbind_kernel_driver (struct rte_pci_device *dev);/** -* Map this device -* -* This function is private to EAL. -* -* @return -* 0 on success, negative on error and positive if no driver -* is found for the device. -*/ -int pci_map_device (struct rte_pci_device *dev); - -/** -* Unmap this device -* -* This function is private to EAL. -*/ -void pci_unmap_device (struct rte_pci_device *dev); - -/** * Map the PCI resource of a PCI device in virtual memory * * This function is private to EAL.
lib/librte_eal/common/include/rte_pci.h +27 -0
@@ -485,6 +485,33 @@ int rte_eal_pci_read_config(const struct rte_pci_device *device,*/ int rte_eal_pci_write_config (const struct rte_pci_device *device,const void *buf,size_t len,off_t offset); +/** +* Map the PCI device resources in user space virtual memory address +* +* Note that driver should not call this function when flag +* RTE_PCI_DRV_NEED_MAPPING is set, as EAL will do that for +* you when it's on. +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +* +* @return +* 0 on success, negative on error and positive if no driver +* is found for the device. +*/ +int rte_eal_pci_map_device (struct rte_pci_device *dev); + +/** +* Unmap this device +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +*/ +void rte_eal_pci_unmap_device (struct rte_pci_device *dev); + +#ifdef RTE_PCI_CONFIG /**
lib/librte_eal/linuxapp/eal/eal_pci.c +2 -2
@@ -124,7 +124,7 @@ pci_get_kernel_driver_by_path(const char *filename, char *dri_name)/* Map pci device */ int -pci_map_device (struct rte_pci_device *dev) +rte_eal_pci_map_device (struct rte_pci_device *dev) {int ret =-1 ;
@@ -153,7 +153,7 @@ pci_map_device(struct rte_pci_device *dev)/* Unmap pci device */ void -pci_unmap_device (struct rte_pci_device *dev) +rte_eal_pci_unmap_device (struct rte_pci_device *dev) {/* try unmapping the NIC resources using VFIO if it exists */ switch (dev->kdrv) {
lib/librte_eal/linuxapp/eal/rte_eal_version.map +7 -0
@@ -138,3 +138,10 @@ DPDK_2.2 { rte_xen_dom0_supported; } DPDK_2.1; + +DPDK_2.3 { + global: + + rte_eal_pci_map_device; + rte_eal_pci_unmap_device; +} DPDK_2.2;
Signature · 1 line
1.9.0
PATCH v3 7/8 virtio: add 1.0 support
In reply to Yuanhan LiuModern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
Firstly, we map the pci resources by rte_eal_pci_map_device(). We then could easily locate to a cfg structure by:
cfg_addr = dev->mem_resources[cap.bar].addr + cap.offset;
Therefore, the entrance of enabling modern (v1.0) pci device support is to iterate the pci capability lists, and to locate some configs we care; and they are:
- common cfg
For generic virtio and virtuqueu configuration, such as setting/getting features, enabling a specific queue, and so on.
- nofity cfg
Combining with `queue_notify_off' from common cfg, we could use it to notify a specific virt queue.
- device cfg
Where virtio_net_config structure locates.
- isr cfg
Where to read isr (interrupt status).
If any of above cap is not found, we fallback to the legacy virtio handling.
If succeed, hw->vtpci_ops is assigned to modern_ops, where all operations are implemented by reading/writing a (or few) specific configuration space from above 4 cfg structures. And that's basically how this patch works.
Besides those changes, virtio 1.0 introduces a new status field:FEATURES_OK, which is set after features negotiation is done.
Last, set the VIRTIO_F_VERSION_1 feature flag.
---
v2: - re-read status after setting FEATURES_OK to make sure status is
set correctly.
- Add isr reading and config irq setting support.
- Define some pci macro on our own to not get the dependency of linux/pci_regs.h, as there should be no such file at non-Linux platform
v3: - invoke rte_eal_pci_unmap_device() at uninit stage
--- doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 25 ++- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 335 ++++++++++++++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 67 +++++++ drivers/net/virtio/virtqueue.h | 2 + 6 files changed, 430 insertions(+), 5 deletions(-)
doc/guides/rel_notes/release_2_3.rst +3 -0
@@ -4,6 +4,9 @@ DPDK Release 2.3 New Features ------------ +* **Virtio 1.0 support.** + + Enabled virtio 1.0 support for virtio pmd driver. Resolved Issues ---------------
drivers/net/virtio/virtio_ethdev.c +22 -3
@@ -927,7 +927,7 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)return virtio_send_command (hw->cvq, &ctrl, &len,1 ); } -static void +static int virtio_negotiate_features (struct virtio_hw *hw) {uint64_t host_features;
@@ -949,6 +949,22 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features =vtpci_negotiate_features (hw, host_features);PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); + +if (hw->modern) { +if (!vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) { +PMD_INIT_LOG (ERR , +"VIRTIO_F_VERSION_1 features is not enabled." ); +return -1 ; + } +vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_FEATURES_OK ); +if (!(vtpci_get_status (hw) &VIRTIO_CONFIG_STATUS_FEATURES_OK )) { +PMD_INIT_LOG (ERR , +"failed to set FEATURES_OK status!" ); +return -1 ; + } + } + +return 0 ; }/*
@@ -1032,7 +1048,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)/* Tell the host we've known how to drive the device. */ vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_DRIVER ); -virtio_negotiate_features (hw); +if (virtio_negotiate_features (hw) <0 ) +return -1 ;/* If host does not support status then disable LSC */ if (!vtpci_with_feature (hw,VIRTIO_NET_F_STATUS ))
@@ -1043,7 +1060,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)rx_func_get (eth_dev);/* Setting up rx_header size for the device */ -if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF ) || +vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) hw->vtnet_hdr_size =sizeof (struct virtio_net_hdr_mrg_rxbuf );else hw->vtnet_hdr_size =sizeof (struct virtio_net_hdr );
@@ -1159,6 +1177,7 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)rte_intr_callback_unregister (&pci_dev->intr_handle, virtio_interrupt_handler, eth_dev); +rte_eal_pci_unmap_device (pci_dev);PMD_INIT_LOG (DEBUG ,"dev_uninit completed" );
drivers/net/virtio/virtio_ethdev.h +2 -1
@@ -64,7 +64,8 @@1u <<VIRTIO_NET_F_CTRL_VQ | \1u <<VIRTIO_NET_F_CTRL_RX | \1u <<VIRTIO_NET_F_CTRL_VLAN | \ - 1u << VIRTIO_NET_F_MRG_RXBUF) +1u <<VIRTIO_NET_F_MRG_RXBUF | \ + 1ULL << VIRTIO_F_VERSION_1)/* * CQ function prototype
drivers/net/virtio/virtio_pci.c +334 -1
367 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +67 -0
104 lines not on this page · raw message
drivers/net/virtio/virtqueue.h +2 -0
@@ -202,6 +202,8 @@ struct virtqueue {/* Size bins in array as RFC 2819, undersized [0], 64 [1], etc */ uint64_t size_bins[8 ]; +uint16_t *notify_addr; +struct vq_desc_extra {void *cookie;uint16_t ndescs;
Signature · 1 line
1.9.0
PATCH v3 8/8 virtio: move VIRTIO_READ/WRITE_REG_X into virtio_pci.c
In reply to Yuanhan Liuvirtio_pci.c become the only file references those macros; move them there.
--- drivers/net/virtio/virtio_pci.c | 19 +++++++++++++++++++ drivers/net/virtio/virtio_pci.h | 18 ------------------ 2 files changed, 19 insertions(+), 18 deletions(-)
drivers/net/virtio/virtio_pci.c +19 -0
@@ -49,6 +49,25 @@#define PCI_CAPABILITY_LIST 0x34#define PCI_CAP_ID_VNDR 0x09 + +#define VIRTIO_PCI_REG_ADDR (hw, reg) \ + (unsigned short)((hw)->io_base + (reg)) + +#define VIRTIO_READ_REG_1 (hw, reg) \ + inb((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_1 (hw, reg, value) \ + outb_p((unsigned char)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) + +#define VIRTIO_READ_REG_2 (hw, reg) \ + inw((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_2 (hw, reg, value) \ + outw_p((unsigned short)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) + +#define VIRTIO_READ_REG_4 (hw, reg) \ + inl((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_4 (hw, reg, value) \ + outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) +static void legacy_read_dev_config (struct virtio_hw *hw,uint64_t offset,void *dst,int length)
drivers/net/virtio/virtio_pci.h +0 -18
@@ -318,24 +318,6 @@ outl_p(unsigned int data, unsigned int port) }#endif -#define VIRTIO_PCI_REG_ADDR (hw, reg) \ - (unsigned short)((hw)->io_base + (reg)) - -#define VIRTIO_READ_REG_1 (hw, reg) \ - inb((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_1 (hw, reg, value) \ - outb_p((unsigned char)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) - -#define VIRTIO_READ_REG_2 (hw, reg) \ - inw((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_2 (hw, reg, value) \ - outw_p((unsigned short)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) - -#define VIRTIO_READ_REG_4 (hw, reg) \ - inl((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_4 (hw, reg, value) \ - outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) -static inline int vtpci_with_feature (struct virtio_hw *hw,uint64_t bit) {
Signature · 1 line
1.9.0
Re: [PATCH v3 6/8] eal: pci: export pci_[un]map_device
In reply to Yuanhan LiuQuoted 9 lines · Yuanhan Liu
Normally we could set
RTE_PCI_DRV_NEED_MAPPINGflag so that eal will invokepci_map_deviceinternally for us. From that point view, there is no need to exportpci_map_device.However, for virtio pmd driver, which is designed to work without binding UIO (or something similar first),
pci_map_device()will fail, which ends up with virtio pmd driver being skipped. Therefore, we can not setRTE_PCI_DRV_NEED_MAPPINGblindly at virtio pmd driver.
Quoted 5 lines
Therefore, this patch exports
pci_map_device, and let virtio pmd call it when necessary.Cc David Marchand <[email protected]>Signed-off-by Yuanhan Liu <[email protected]>
Oops, forgot to carry the tested-by from Santosh.
--yliu
Re: [PATCH v2 7/7] virtio: add 1.0 support
In reply to Yuanhan LiuQuoted 1 line · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities.
[snip]
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 632
Quoted 5 lines
drivers/net/virtio/virtio_pci.c +5
-0+static void +modern_notify_queue(struct virtio_hw *hw __rte_unused, struct virtqueue *vq) +{ +modern_write16 (1 , vq->notify_addr); +}
Does virtio 1.0 only supports MMIO? MMIO has long VMEXIT latency than PORT IO.
[snip]
Re: [PATCH v2 7/7] virtio: add 1.0 support
Quoted 11 lines · Huawei
Quoted 1 line · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities.
[snip]
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 632
Quoted 5 lines
drivers/net/virtio/virtio_pci.c +5
-0+static void +modern_notify_queue(struct virtio_hw *hw __rte_unused, struct virtqueue *vq) +{ +modern_write16 (1 , vq->notify_addr); +}Does virtio 1.0 only supports MMIO? MMIO has long VMEXIT latency than PORT IO.
Virtio 1.0 supports three transport layer, including MMIO and PCI. And we use PCI only in our pmd driver.
--yliu
Re: [PATCH v2 7/7] virtio: add 1.0 support
In reply to Yuanhan LiuQuoted 6 lines · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
Firstly, we map the pci resources by
rte_eal_pci_map_device(). We then could easily locate to a cfg structure by:
s/Locate/Locate to/
Quoted 10 lines
cfg_addr = dev->mem_resources[cap.bar].addr + cap.offset;Therefore, the entrance of enabling modern (v1.0) pci device support is to iterate the pci capability lists, and to locate some configs we care; and they are:
- common cfg
For generic virtio and virtuqueu configuration, such as setting/getting
typo for virtqueue
Quoted 10 lines
features, enabling a specific queue, and so on.
- nofity cfg
Combining with `queue_notify_off' from common cfg, we could use it to notify a specific virt queue.
- device cfg
Where
virtio_net_configstructure locates.
is located
Quoted 2 lines
If any of above cap is not found, we fallback to the legacy virtio
[SNIP]
Quoted 23 lines
drivers/net/virtio/virtio_pci.c +20
-0+#define MODERN_READ_DEF (nr_bits, type) \ +static inline type \ +modern_read##nr_bits(type *addr) \ +{ \ + return *(volatile type *)addr; \ +} + +#define MODERN_WRITE_DEF (nr_bits, type) \ +static inline void \ +modern_write##nr_bits(type val, type *addr) \ +{ \ + *(volatile type *)addr = val; \ +} + +MODERN_READ_DEF (8, uint8_t) +MODERN_WRITE_DEF(8, uint8_t) + +MODERN_READ_DEF (16, uint16_t) +MODERN_WRITE_DEF (16 , uint16_t) +
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 482
Quoted 10 lines
drivers/net/virtio/virtio_pci.c +10
-0+MODERN_READ_DEF (32, uint32_t) +MODERN_WRITE_DEF(32, uint32_t) + +static inline void +modern_write64_twopart (uint64_t val,uint32_t *lo,uint32_t *hi) +{ +modern_write32 ((uint32_t )val, lo); +modern_write32 (val >>32 , hi); +} +
This is normal mmio read/write operation. ioread8/16/32/64 or just readxx is more meaningful name here.
Quoted 1 line
+static void
[SNIP]
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 504
Quoted 4 lines
drivers/net/virtio/virtio_pci.c +4
-0+ +static void +modern_write_dev_config (struct virtio_hw *hw,uint64_t offset, +void *src,int length)
define src as const
[snip]
drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 724
Quoted 3 lines
drivers/net/virtio/virtio_pci.c +2
-0+static inline void * +get_cfg_addr (struct rte_pci_device *dev,struct virtio_pci_cap *cap)
No explicit inline for non performance critical functions.
drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 731
Quoted 7 lines
drivers/net/virtio/virtio_pci.c +7
-0+{ +uint8_t bar = cap->bar; +uint32_t length = cap->length; +uint32_t offset = cap->offset; +uint8_t *base; + +if (unlikely (bar >5 )) {
Don't use constant value number whenever possible
No likely/unlikely for non performance critical functions
Quoted 19 lines
drivers/net/virtio/virtio_pci.c +19
-0+PMD_INIT_LOG (ERR ,"invalid bar: %u" , bar); +return NULL ; + } + +if (unlikely (offset + length > dev->mem_resource[bar].len)) { +PMD_INIT_LOG (ERR , +"invalid cap: overflows bar space: %u > %" PRIu64, + offset + length, dev->mem_resource[bar].len); +return NULL ; + } + + base = dev->mem_resource[bar].addr; +if (unlikely (base ==NULL )) { +PMD_INIT_LOG (ERR ,"bar %u base addr is NULL" , bar); +return NULL ; + } + +return base + offset; +}
drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 760
Quoted 10 lines
drivers/net/virtio/virtio_pci.c +10
-0+ +static int +virtio_read_caps (struct rte_pci_device *dev,struct virtio_hw *hw) +{ +uint8_t pos; +struct virtio_pci_cap cap; +int ret; + +if (rte_eal_pci_map_device (dev) <0 ) { +PMD_INIT_LOG (DEBUG ,"failed to map pci device!" );
s /DEBUG/ERR/
Quoted 5 lines
drivers/net/virtio/virtio_pci.c +5
-0+return -1 ; + } + + ret =rte_eal_pci_read_config (dev, &pos,1 ,PCI_CAPABILITY_LIST ); +
[snip]
Re: [PATCH v2 7/7] virtio: add 1.0 support
In reply to Yuanhan LiuQuoted 11 lines · Yuanhan Liu
Quoted 10 lines · Huawei
Quoted 1 line · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities.
[snip]
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 632
Quoted 5 lines
drivers/net/virtio/virtio_pci.c +5
-0+static void +modern_notify_queue(struct virtio_hw *hw __rte_unused, struct virtqueue *vq) +{ +modern_write16 (1 , vq->notify_addr); +}Does virtio 1.0 only supports MMIO? MMIO has long VMEXIT latency than PORT IO.
Quoted 2 lines
Virtio 1.0 supports three transport layer, including MMIO and PCI. And we use PCI only in our pmd driver.
I don't mean that MMIO but use memory mapped IO for configuration.
Quoted 3 lines
--yliu
Re: [PATCH v2 7/7] virtio: add 1.0 support
Quoted 12 lines · Huawei
Quoted 11 lines · Yuanhan Liu
Quoted 10 lines · Huawei
Quoted 1 line · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities.
[snip]
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 632
Quoted 5 lines
drivers/net/virtio/virtio_pci.c +5
-0+static void +modern_notify_queue(struct virtio_hw *hw __rte_unused, struct virtqueue *vq) +{ +modern_write16 (1 , vq->notify_addr); +}Does virtio 1.0 only supports MMIO? MMIO has long VMEXIT latency than PORT IO.
Quoted 4 lines
Quoted 2 lines
Virtio 1.0 supports three transport layer, including MMIO and PCI. And we use PCI only in our pmd driver.
I don't mean that MMIO but use memory mapped IO for configuration.
Then, yes.
--yliu
Re: [PATCH v2 7/7] virtio: add 1.0 support
Quoted 13 lines · Yuanhan Liu
Quoted 12 lines · Huawei
Quoted 11 lines · Yuanhan Liu
Quoted 10 lines · Huawei
Quoted 1 line · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities.
[snip]
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 632
Quoted 5 lines
drivers/net/virtio/virtio_pci.c +5
-0+static void +modern_notify_queue(struct virtio_hw *hw __rte_unused, struct virtqueue *vq) +{ +modern_write16 (1 , vq->notify_addr); +}Does virtio 1.0 only supports MMIO? MMIO has long VMEXIT latency than PORT IO.
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Virtio 1.0 supports three transport layer, including MMIO and PCI. And we use PCI only in our pmd driver.
I don't mean that MMIO but use memory mapped IO for configuration.
Then, yes.
00:03.0 Ethernet controller: Red Hat, Inc Virtio network device
Subsystem: Red Hat, Inc Device 0001
Physical Slot: 3
Flags: bus master, fast devsel, latency 0, IRQ 10 I/O ports at c100 [size=32]
Memory at febd1000 (32-bit, non-prefetchable) [size=4K] Memory at fe000000 (64-bit, prefetchable) [size=8M] Expansion ROM at feb40000 [disabled] [size=256K]
Capabilities: [98] MSI-X: Enable+ Count=3 Masked-
Capabilities: [84] Vendor Specific Information: Len=14 <?>
Capabilities: [70] Vendor Specific Information: Len=14 <?>
Capabilities: [60] Vendor Specific Information: Len=10 <?>
Capabilities: [50] Vendor Specific Information: Len=10 <?>
Capabilities: [40] Vendor Specific Information: Len=10 <?> Kernel driver in use: igb_uio
Kernel modules: virtio_pci
c100 is still there. For the notification, try PORT IO if possible.
Quoted 3 lines
--yliu
Re: [PATCH v2 7/7] virtio: add 1.0 support
Quoted 36 lines · Huawei
Quoted 13 lines · Yuanhan Liu
Quoted 12 lines · Huawei
Quoted 11 lines · Yuanhan Liu
Quoted 10 lines · Huawei
Quoted 1 line · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities.
[snip]
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 632
Quoted 5 lines
drivers/net/virtio/virtio_pci.c +5
-0+static void +modern_notify_queue(struct virtio_hw *hw __rte_unused, struct virtqueue *vq) +{ +modern_write16 (1 , vq->notify_addr); +}Does virtio 1.0 only supports MMIO? MMIO has long VMEXIT latency than PORT IO.
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Virtio 1.0 supports three transport layer, including MMIO and PCI. And we use PCI only in our pmd driver.
I don't mean that MMIO but use memory mapped IO for configuration.
Then, yes.
00:03.0 Ethernet controller: Red Hat, Inc Virtio network device
Subsystem: Red Hat, Inc Device 0001
Physical Slot: 3
Flags: bus master, fast devsel, latency 0, IRQ 10 I/O ports at c100 [size=32]
Memory atfebd1000(32-bit, non-prefetchable) [size=4K] Memory atfe000000(64-bit, prefetchable) [size=8M] Expansion ROM atfeb40000[disabled] [size=256K]
Capabilities: [98] MSI-X: Enable+ Count=3 Masked-
Capabilities: [84] Vendor Specific Information: Len=14 <?>
Capabilities: [70] Vendor Specific Information: Len=14 <?>
Capabilities: [60] Vendor Specific Information: Len=10 <?>
Capabilities: [50] Vendor Specific Information: Len=10 <?>
Capabilities: [40] Vendor Specific Information: Len=10 <?> Kernel driver in use:igb_uio
Kernel modules:virtio_pci
Quoted 1 line
c100 is still there.
Yes,
Quoted 1 line
For the notification, try PORT IO if possible.
But it doesn't seem right to me to mix legacy registers in modern pci device.
--yliu
Re: [PATCH v2 7/7] virtio: add 1.0 support
Quoted 36 lines · Yuanhan Liu
Quoted 35 lines · Huawei
Quoted 13 lines · Yuanhan Liu
Quoted 12 lines · Huawei
Quoted 11 lines · Yuanhan Liu
Quoted 10 lines · Huawei
Quoted 1 line · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities.
[snip]
Review
Quoted 5 lines
(quoted diff) +5
-0+static void +modern_notify_queue(struct virtio_hw *hw __rte_unused, struct virtqueue *vq) +{ + modern_write16(1, vq->notify_addr); +}Does virtio 1.0 only supports MMIO? MMIO has long VMEXIT latency than PORT IO.
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Virtio 1.0 supports three transport layer, including MMIO and PCI. And we use PCI only in our pmd driver.
I don't mean that MMIO but use memory mapped IO for configuration.
Then, yes.
00:03.0 Ethernet controller: Red Hat, Inc Virtio network device
Subsystem: Red Hat, Inc Device 0001
Physical Slot: 3
Flags: bus master, fast devsel, latency 0, IRQ 10 I/O ports at c100 [size=32]
Memory atfebd1000(32-bit, non-prefetchable) [size=4K] Memory atfe000000(64-bit, prefetchable) [size=8M] Expansion ROM atfeb40000[disabled] [size=256K]
Capabilities: [98] MSI-X: Enable+ Count=3 Masked-
Capabilities: [84] Vendor Specific Information: Len=14 <?>
Capabilities: [70] Vendor Specific Information: Len=14 <?>
Capabilities: [60] Vendor Specific Information: Len=10 <?>
Capabilities: [50] Vendor Specific Information: Len=10 <?>
Capabilities: [40] Vendor Specific Information: Len=10 <?> Kernel driver in use:igb_uio
Kernel modules:virtio_pci
Quoted 5 lines
Quoted 1 line
c100 is still there.
Yes,
Quoted 1 line
For the notification, try PORT IO if possible.
But it doesn't seem right to me to mix legacy registers in modern pci device.
On TLB and cache miss, this could cause plenty of cycles. Considering that our current focus is dpdkvhost which doesn't need notification, let us revisit this later.
Quoted 3 lines
--yliu
Re: [PATCH v2 7/7] virtio: add 1.0 support
In reply to Xie, HuaweiSigh... I have just send out v3 ...
Quoted 11 lines · Huawei
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 482
Quoted 7 lines · Yuanhan Liu
drivers/net/virtio/virtio_pci.c +7
-0+static inline void +modern_write64_twopart (uint64_t val,uint32_t *lo,uint32_t *hi) +{ +modern_write32 ((uint32_t )val, lo); +modern_write32 (val >>32 , hi); +} +This is normal mmio read/write operation. ioread8/16/32/64 or just readxx is more meaningful name here.
I just want to make them looks like modern device related, which they are.
Quoted 8 lines
Quoted 1 line
+static void
[SNIP]
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 504
Quoted 4 lines
drivers/net/virtio/virtio_pci.c +4
-0+ +static void +modern_write_dev_config (struct virtio_hw *hw,uint64_t offset, +void *src,int length)define src as const
okay.
Quoted 7 lines
[snip]
drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 724
Quoted 3 lines
drivers/net/virtio/virtio_pci.c +2
-0+static inline void * +get_cfg_addr (struct rte_pci_device *dev,struct virtio_pci_cap *cap)No explicit inline for non performance critical functions.
okay.
Quoted 9 lines
drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 731
Quoted 8 lines
drivers/net/virtio/virtio_pci.c +7
-0+{ +uint8_t bar = cap->bar; +uint32_t length = cap->length; +uint32_t offset = cap->offset; +uint8_t *base; + +if (unlikely (bar >5 )) {Don't use constant value number whenever possible
I normally will not bother to define a macro for used once number, espeically for some well known ones. Say, I won't define
#define UINT8_MAX_VALUE 0xff
Quoted 2 lines
No likely/unlikely for non performance critical functions
makes sense.
Quoted 4 lines
drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 760
Quoted 2 lines
drivers/net/virtio/virtio_pci.c +2
-0+if (rte_eal_pci_map_device (dev) <0 ) { +PMD_INIT_LOG (DEBUG ,"failed to map pci device!" );s /DEBUG/ERR/
It's not an error; it's expected, say, when no UIO is bond.
--yliu
v4 cover virtio 1.0 enabling for virtio pmd driver
In reply to Yuanhan Liuv4: - mark "src" arg as const for write_dev_cfg operation
- remove unnessary inline, and likely/unlikely
v3: - export pci_unmap_device as well; and invoke it at virtio
uninit stage.
- fixed same data corruption bug reported by Qian in simple rxtx code path.
- move VIRTIO_READ/WRITE_REG_X to virtio_pci.c
v2: - fix a data corruption reported by Qian, due to hdr size mismatch.
check detailes at ptach 5.
- Add missing config_irq and isr reading support from v1.
- fix comments from v1.
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 7.
To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a virtio_pci_ops structure, to add another layer so that we could keep those vtpci_foo_bar "APIs". With that, we could do the minimum change to add virtio 1.0 support.
Rough test guide
================
Firstly, you need get a virtio 1.0 supported QEMU (say, v2.5), then add option "disable-modern=false" to qemu virtio-net-pci device to enable virtio 1.0 (which is disabled by default).
And if you see something like following from 'lspci -v', it means virtio 1.0 is indeed enabled:
00:04.0 Ethernet controller: Red Hat, Inc Virtio network device
Subsystem: Red Hat, Inc Device 0001
Physical Slot: 4
Flags: bus master, fast devsel, latency 0, IRQ 11 I/O ports at c040 [size=64]
Memory at febf1000 (32-bit, non-prefetchable) [size=4K] Memory at fe000000 (64-bit, prefetchable) [size=8M] Expansion ROM at feb80000 [disabled] [size=256K]
Capabilities: [98] MSI-X: Enable+ Count=6 Masked-
==> Capabilities: [84] Vendor Specific Information: Len=14 <?> ==> Capabilities: [70] Vendor Specific Information: Len=14 <?> ==> Capabilities: [60] Vendor Specific Information: Len=10 <?> ==> Capabilities: [50] Vendor Specific Information: Len=10 <?> ==> Capabilities: [40] Vendor Specific Information: Len=10 <?>
Kernel driver in use: virtio-pci
Kernel modules: virtio_pci
After that, there wasn't anything speical comparing to the old virtio 0.95 pmd driver.
---
Yuanhan Liu (8):
virtio: don't set vring address again at queue startup
virtio: introduce struct virtio_pci_ops
virtio: move left pci stuff to virtio_pci.c
viritio: switch to 64 bit features
virtio: retrieve hdr_size from hw->vtnet_hdr_size
eal: pci: export pci_[un]map_device
virtio: add 1.0 support
virtio: move VIRTIO_READ/WRITE_REG_X into virtio_pci.c
doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 302 +-------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 793 +++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 120 +++- drivers/net/virtio/virtio_rxtx.c | 21 +- drivers/net/virtio/virtio_rxtx_simple.c | 12 +- drivers/net/virtio/virtqueue.h | 4 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 +- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 7 + lib/librte_eal/common/eal_common_pci.c | 4 +- lib/librte_eal/common/eal_private.h | 18 - lib/librte_eal/common/include/rte_pci.h | 27 + lib/librte_eal/linuxapp/eal/eal_pci.c | 4 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 7 + 15 files changed, 949 insertions(+), 380 deletions(-)
Signature · 1 line
1.9.0
PATCH v4 1/8 virtio: don't set vring address again at queue startup
As we have already set up it at virtio_dev_queue_setup(), and a vq restart will not reset the settings.
--- drivers/net/virtio/virtio_rxtx.c | 15 --------------- 1 file changed, 15 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -15
@@ -339,11 +339,6 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)vq_update_avail_idx (vq);PMD_INIT_LOG (DEBUG ,"Allocated %d bufs" , nbufs); - -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); }else if (queue_type ==VTNET_TQ ) {if (use_simple_rxtx) {int mid_idx = vq->vq_nentries >>1 ;
@@ -362,16 +357,6 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)for (i = mid_idx; i < vq->vq_nentries; i++) vq->vq_ring.avail->ring[i] = i; } - -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); - }else { -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); } }
Signature · 1 line
1.9.0
PATCH v4 2/8 virtio: introduce struct virtio_pci_ops
In reply to Yuanhan LiuIntroduce struct virtio_pci_ops, to let legacy virtio (v0.95) and modern virtio (1.0) have different implementation regarding to a specific pci action, such as read host status.
With that, this patch reimplements all exported pci functions, in a way like:
vtpci_foo_bar(struct virtio_hw *hw)
{
hw->vtpci_ops->foo_bar(hw);
}So that we need pay attention to those pci related functions only while adding virtio 1.0 support.
This patch introduced a new vtpci function, vtpci_init(), to do proper virtio pci settings. It's pretty simple so far: just sets hw->vtpci_ops to legacy_ops as we don't support 1.0 yet.
---
v2: extra whitespace line removing, and comment on "reading status
after reset".
rename the badly taken op name "set_irq" to "set_config_irq".
v4: define "src" arg of write_dev_cfg opertion as const
--- drivers/net/virtio/virtio_ethdev.c | 22 ++--- drivers/net/virtio/virtio_pci.c | 164 ++++++++++++++++++++++++++++++------- drivers/net/virtio/virtio_pci.h | 27 ++++++ drivers/net/virtio/virtqueue.h | 2 +- 4 files changed, 169 insertions(+), 46 deletions(-)
drivers/net/virtio/virtio_ethdev.c +8 -14
@@ -272,9 +272,7 @@ virtio_dev_queue_release(struct virtqueue *vq) {if (vq) { hw = vq->hw; -/* Select and deactivate the queue */ -VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN ,0 ); + hw->vtpci_ops->del_queue (hw, vq);rte_free (vq->sw_ring);rte_free (vq);
@@ -295,15 +293,13 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,struct virtio_hw *hw = dev->data->dev_private;struct virtqueue *vq =NULL ; -/* Write the virtqueue index to the Queue Select Field */ -VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vtpci_queue_idx); -PMD_INIT_LOG (DEBUG ,"selecting queue: %u" , vtpci_queue_idx); +PMD_INIT_LOG (DEBUG ,"setting up queue: %u" , vtpci_queue_idx);/* * Read the virtqueue size from the Queue Size field * Always power of 2 and if 0 virtqueue does not exist */ - vq_size =VIRTIO_READ_REG_2 (hw,VIRTIO_PCI_QUEUE_NUM ); + vq_size = hw->vtpci_ops->get_queue_num (hw, vtpci_queue_idx);PMD_INIT_LOG (DEBUG ,"vq_size: %u nb_desc:%u" , vq_size, nb_desc);if (vq_size ==0 ) {PMD_INIT_LOG (ERR ,"%s: virtqueue does not exist" , __func__);
@@ -436,12 +432,8 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,memset (vq->virtio_net_hdr_mz->addr,0 ,PAGE_SIZE ); } -/* -* Set guest physical address of the virtqueue -* in VIRTIO_PCI_QUEUE_PFN config register of device -*/ -VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN , - mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); + hw->vtpci_ops->setup_queue (hw, vq); + *pvq = vq;return 0 ; }
@@ -950,7 +942,7 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features);/* Read device(host) feature bits */ - host_features =VIRTIO_READ_REG_4 (hw,VIRTIO_PCI_HOST_FEATURES ); + host_features = hw->vtpci_ops->get_features (hw);PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %x" , host_features);
@@ -1287,6 +1279,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; +vtpci_init (pci_dev, hw); +if (virtio_resource_init (pci_dev) <0 )return -1 ;
drivers/net/virtio/virtio_pci.c +133 -31
229 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +27 -0
@@ -163,6 +163,31 @@ struct virtqueue;*/ #define VIRTIO_MAX_VIRTQUEUES 8 +struct virtio_hw ; + +struct virtio_pci_ops { +void (*read_dev_cfg)(struct virtio_hw *hw,uint64_t offset, +void *dst,int len); +void (*write_dev_cfg)(struct virtio_hw *hw,uint64_t offset, +const void *src,int len); +void (*reset)(struct virtio_hw *hw); + +uint8_t (*get_status)(struct virtio_hw *hw); +void (*set_status)(struct virtio_hw *hw,uint8_t status); + +uint32_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint32_t features); + +uint8_t (*get_isr)(struct virtio_hw *hw); + +uint16_t (*set_config_irq)(struct virtio_hw *hw,uint16_t vec); + +uint16_t (*get_queue_num)(struct virtio_hw *hw,uint16_t queue_id); +void (*setup_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*del_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*notify_queue)(struct virtio_hw *hw,struct virtqueue *vq); +}; +struct virtio_hw {struct virtqueue *cvq;uint32_t io_base;
@@ -174,6 +199,7 @@ struct virtio_hw {uint8_t use_msix;uint8_t started;uint8_t mac_addr[ETHER_ADDR_LEN ]; +const struct virtio_pci_ops *vtpci_ops; };/*
@@ -253,6 +279,7 @@ vtpci_with_feature(struct virtio_hw *hw, uint32_t bit)/* * Function declaration from virtio_pci.c */ +int vtpci_init (struct rte_pci_device *,struct virtio_hw *);void vtpci_reset (struct virtio_hw *);void vtpci_reinit_complete (struct virtio_hw *);
drivers/net/virtio/virtqueue.h +1 -1
@@ -302,7 +302,7 @@ virtqueue_notify(struct virtqueue *vq)* For virtio on IA, the notificaiton is through io port operation * which is a serialization instruction itself. */ -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_NOTIFY , vq->vq_queue_index); + vq->hw->vtpci_ops->notify_queue (vq->hw, vq); }#ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP
Signature · 1 line
1.9.0
PATCH v4 3/8 virtio: move left pci stuff to virtio_pci.c
In reply to Yuanhan Liuvirtio_pci.c is a more proper place for pci stuff; virtio_ethdev is not.
--- drivers/net/virtio/virtio_ethdev.c | 265 +----------------------------------- drivers/net/virtio/virtio_pci.c | 270 ++++++++++++++++++++++++++++++++++++- 2 files changed, 270 insertions(+), 265 deletions(-)
drivers/net/virtio/virtio_ethdev.c +1 -264
@@ -36,10 +36,6 @@#include <stdio.h> #include <errno.h> #include <unistd.h> -#ifdef RTE_EXEC_ENV_LINUXAPP -#include <dirent.h> -#include <fcntl.h> -#endif #include <rte_ethdev.h> #include <rte_memcpy.h>
@@ -955,260 +951,6 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features); } -#ifdef RTE_EXEC_ENV_LINUXAPP -static int -parse_sysfs_value (const char *filename,unsigned long *val) -{ -FILE *f; -char buf[BUFSIZ ]; -char *end =NULL ; - - f =fopen (filename,"r" ); -if (f ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): cannot open sysfs value %s" , - __func__, filename); -return -1 ; - } - -if (fgets (buf,sizeof (buf), f) ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): cannot read sysfs value %s" , - __func__, filename); -fclose (f); -return -1 ; - } - *val =strtoul (buf, &end,0 ); -if ((buf[0 ] =='\0' ) || (end ==NULL ) || (*end !='\n' )) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse sysfs value %s" , - __func__, filename); -fclose (f); -return -1 ; - } -fclose (f); -return 0 ; -} - -static int get_uio_dev (struct rte_pci_addr *loc,char *buf,unsigned int buflen, -unsigned int *uio_num) -{ -struct dirent *e; -DIR *dir; -char dirname[PATH_MAX ]; - -/* depending on kernel version, uio can be located in uio/uioX -* or uio:uioX */ -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio" , - loc->domain, loc->bus, loc->devid, loc->function); - dir =opendir (dirname); -if (dir ==NULL ) { -/* retry with the parent directory */ -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT , - loc->domain, loc->bus, loc->devid, loc->function); - dir =opendir (dirname); - -if (dir ==NULL ) { -PMD_INIT_LOG (ERR ,"Cannot opendir %s" , dirname); -return -1 ; - } - } - -/* take the first file starting with "uio" */ -while ((e =readdir (dir)) !=NULL ) { -/* format could be uio%d ...*/ -int shortprefix_len =sizeof ("uio" ) -1 ; -/* ... or uio:uio%d */ -int longprefix_len =sizeof ("uio:uio" ) -1 ; -char *endptr; - -if (strncmp (e->d_name,"uio" ,3 ) !=0 ) -continue ; - -/* first try uio%d */ - errno =0 ; - *uio_num =strtoull (e->d_name + shortprefix_len, &endptr,10 ); -if (errno ==0 && endptr != (e->d_name + shortprefix_len)) { -snprintf (buf, buflen,"%s/uio%u" , dirname, *uio_num); -break ; - } - -/* then try uio:uio%d */ - errno =0 ; - *uio_num =strtoull (e->d_name + longprefix_len, &endptr,10 ); -if (errno ==0 && endptr != (e->d_name + longprefix_len)) { -snprintf (buf, buflen,"%s/uio:uio%u" , dirname, - *uio_num); -break ; - } - } -closedir (dir); - -/* No uio resource found */ -if (e ==NULL ) { -PMD_INIT_LOG (ERR ,"Could not find uio resource" ); -return -1 ; - } - -return 0 ; -} - -static int -virtio_has_msix (const struct rte_pci_addr *loc) -{ -DIR *d; -char dirname[PATH_MAX ]; - -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/msi_irqs" , - loc->domain, loc->bus, loc->devid, loc->function); - - d =opendir (dirname); -if (d) -closedir (d); - -return (d !=NULL ); -} - -/* Extract I/O port numbers from sysfs */ -static int virtio_resource_init_by_uio (struct rte_pci_device *pci_dev) -{ -char dirname[PATH_MAX ]; -char filename[PATH_MAX ]; -unsigned long start, size; -unsigned int uio_num; - -if (get_uio_dev (&pci_dev->addr, dirname,sizeof (dirname), &uio_num) <0 ) -return -1 ; - -/* get portio size */ -snprintf (filename,sizeof (filename), -"%s/portio/port0/size" , dirname); -if (parse_sysfs_value (filename, &size) <0 ) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse size" , - __func__); -return -1 ; - } - -/* get portio start */ -snprintf (filename,sizeof (filename), -"%s/portio/port0/start" , dirname); -if (parse_sysfs_value (filename, &start) <0 ) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse portio start" , - __func__); -return -1 ; - } - pci_dev->mem_resource[0 ].addr = (void *)(uintptr_t )start; - pci_dev->mem_resource[0 ].len = (uint64_t )size; -PMD_INIT_LOG (DEBUG , -"PCI Port IO found start=0x%lx with size=0x%lx" , - start, size); - -/* save fd */ -memset (dirname,0 ,sizeof (dirname)); -snprintf (dirname,sizeof (dirname),"/dev/uio%u" , uio_num); - pci_dev->intr_handle.fd =open (dirname,O_RDWR ); -if (pci_dev->intr_handle.fd <0 ) { -PMD_INIT_LOG (ERR ,"Cannot open %s: %s\n" , - dirname,strerror (errno)); -return -1 ; - } - - pci_dev->intr_handle.type =RTE_INTR_HANDLE_UIO ; - pci_dev->driver->drv_flags |=RTE_PCI_DRV_INTR_LSC ; - -return 0 ; -} - -/* Extract port I/O numbers from proc/ioports */ -static int virtio_resource_init_by_ioports (struct rte_pci_device *pci_dev) -{ -uint16_t start, end; -int size; -FILE *fp; -char *line =NULL ; -char pci_id[16 ]; -int found =0 ; -size_t linesz; - -snprintf (pci_id,sizeof (pci_id),PCI_PRI_FMT , - pci_dev->addr.domain, - pci_dev->addr.bus, - pci_dev->addr.devid, - pci_dev->addr.function); - - fp =fopen ("/proc/ioports" ,"r" ); -if (fp ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): can't open ioports" , __func__); -return -1 ; - } - -while (getdelim (&line, &linesz,'\n' , fp) >0 ) { -char *ptr = line; -char *left; -int n; - - n =strcspn (ptr,":" ); - ptr[n] =0 ; - left = &ptr[n+1 ]; - -while (*left &&isspace (*left)) - left++; - -if (!strncmp (left, pci_id,strlen (pci_id))) { - found =1 ; - -while (*ptr &&isspace (*ptr)) - ptr++; - -sscanf (ptr,"%04hx-%04hx" , &start, &end); - size = end - start +1 ; - -break ; - } - } - -free (line); -fclose (fp); - -if (!found) -return -1 ; - - pci_dev->mem_resource[0 ].addr = (void *)(uintptr_t )(uint32_t )start; - pci_dev->mem_resource[0 ].len = (uint64_t )size; -PMD_INIT_LOG (DEBUG , -"PCI Port IO found start=0x%x with size=0x%x" , - start, size); - -/* can't support lsc interrupt without uio */ - pci_dev->driver->drv_flags &= ~RTE_PCI_DRV_INTR_LSC ; - -return 0 ; -} - -/* Extract I/O port numbers from sysfs */ -static int virtio_resource_init (struct rte_pci_device *pci_dev) -{ -if (virtio_resource_init_by_uio (pci_dev) ==0 ) -return 0 ; -else -return virtio_resource_init_by_ioports (pci_dev); -} - -#else -static int -virtio_has_msix(const struct rte_pci_addr *loc __rte_unused) -{ -/* nic_uio does not enable interrupts, return 0 (false). */ -return 0 ; -} - -static int virtio_resource_init(struct rte_pci_device *pci_dev __rte_unused) -{ -/* no setup required */ -return 0 ; -} -#endif -/* * Process Virtio Config changed interrupt and call the callback * if link state changed.
@@ -1279,14 +1021,9 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; -vtpci_init (pci_dev, hw); - -if (virtio_resource_init (pci_dev) <0 ) +if (vtpci_init (pci_dev, hw) <0 )return -1 ; - hw->use_msix =virtio_has_msix (&pci_dev->addr); - hw->io_base = (uint32_t )(uintptr_t )pci_dev->mem_resource[0 ].addr; -/* Reset the device although not necessary at startup */ vtpci_reset (hw);
drivers/net/virtio/virtio_pci.c +269 -1
290 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH v4 4/8 viritio: switch to 64 bit features
In reply to Yuanhan LiuSwitch to 64 bit features, which virtio 1.0 supports.
While legacy virtio only supports 32 bit features, it complains aloud and quit when trying to setting > 32 bit features.
--- drivers/net/virtio/virtio_ethdev.c | 8 ++++---- drivers/net/virtio/virtio_pci.c | 15 ++++++++++----- drivers/net/virtio/virtio_pci.h | 12 ++++++------ 3 files changed, 20 insertions(+), 15 deletions(-)
drivers/net/virtio/virtio_ethdev.c +4 -4
@@ -930,16 +930,16 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)static void virtio_negotiate_features (struct virtio_hw *hw) { -uint32_t host_features; +uint64_t host_features;/* Prepare guest_features: feature that driver wants to support */ hw->guest_features =VIRTIO_PMD_GUEST_FEATURES ; -PMD_INIT_LOG (DEBUG ,"guest_features before negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"guest_features before negotiate = %" PRIx64, hw->guest_features);/* Read device(host) feature bits */ host_features = hw->vtpci_ops->get_features (hw); -PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %" PRIx64, host_features);/*
@@ -947,7 +947,7 @@ virtio_negotiate_features(struct virtio_hw *hw)* guest feature bits. */ hw->guest_features =vtpci_negotiate_features (hw, host_features); -PMD_INIT_LOG (DEBUG ,"features after negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); }
drivers/net/virtio/virtio_pci.c +10 -5
@@ -87,15 +87,20 @@ legacy_write_dev_config(struct virtio_hw *hw, uint64_t offset, } } -static uint32_t +static uint64_t legacy_get_features (struct virtio_hw *hw) {return VIRTIO_READ_REG_4 (hw,VIRTIO_PCI_HOST_FEATURES ); }static void -legacy_set_features (struct virtio_hw *hw,uint32_t features) +legacy_set_features (struct virtio_hw *hw,uint64_t features) { +if ((features >>32 ) !=0 ) { +PMD_DRV_LOG (ERR , +"only 32 bit features are allowed for legacy virtio!" ); +return ; + }VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_GUEST_FEATURES , features); }
@@ -451,10 +456,10 @@ vtpci_write_dev_config(struct virtio_hw *hw, uint64_t offset, hw->vtpci_ops->write_dev_cfg (hw, offset, src, length); } -uint32_t -vtpci_negotiate_features (struct virtio_hw *hw,uint32_t host_features) +uint64_t +vtpci_negotiate_features (struct virtio_hw *hw,uint64_t host_features) { -uint32_t features; +uint64_t features;/* * Limit negotiated features to what the driver, virtqueue, and
drivers/net/virtio/virtio_pci.h +6 -6
@@ -175,8 +175,8 @@ struct virtio_pci_ops {uint8_t (*get_status)(struct virtio_hw *hw);void (*set_status)(struct virtio_hw *hw,uint8_t status); -uint32_t (*get_features)(struct virtio_hw *hw); -void (*set_features)(struct virtio_hw *hw,uint32_t features); +uint64_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint64_t features);uint8_t (*get_isr)(struct virtio_hw *hw);
@@ -191,7 +191,7 @@ struct virtio_pci_ops {struct virtio_hw {struct virtqueue *cvq;uint32_t io_base; -uint32_t guest_features; +uint64_t guest_features;uint32_t max_tx_queues;uint32_t max_rx_queues;uint16_t vtnet_hdr_size;
@@ -271,9 +271,9 @@ outl_p(unsigned int data, unsigned int port) outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg))))static inline int -vtpci_with_feature (struct virtio_hw *hw,uint32_t bit) +vtpci_with_feature (struct virtio_hw *hw,uint64_t bit) { -return (hw->guest_features & (1u << bit)) !=0 ; +return (hw->guest_features & (1ULL << bit)) !=0 ; }/*
@@ -286,7 +286,7 @@ void vtpci_reinit_complete(struct virtio_hw *);void vtpci_set_status (struct virtio_hw *,uint8_t ); -uint32_t vtpci_negotiate_features (struct virtio_hw *,uint32_t ); +uint64_t vtpci_negotiate_features (struct virtio_hw *,uint64_t );void vtpci_write_dev_config (struct virtio_hw *,uint64_t ,void *,int );
Signature · 1 line
1.9.0
PATCH v4 5/8 virtio: retrieve hdr_size from hw->vtnet_hdr_size
In reply to Yuanhan LiuThe mergeable virtio net hdr format has been the standard and the only virtio net hdr format since virtio 1.0. Therefore, we can not hardcode hdr_size to "sizeof(struct virtio_net_hdr)" any more at virtio_recv_pkts(), otherwise, there would be a mismatch of hdr size from rte_vhost_enqueue_burst() and virtio_recv_pkts(), leading a packet corruption.
Instead, we should retrieve it from hw->vtnet_hdr_size; we will do proper settings at eth_virtio_dev_init() in later patches.
---
v3: retrieve hdr_size from hw->vtnet_hdr_size for simple rxtx
code path as well: it should not break anything, as simple rx and mergeable rx still will not co-exist.
--- drivers/net/virtio/virtio_rxtx.c | 6 ++++-- drivers/net/virtio/virtio_rxtx_simple.c | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/net/virtio/virtio_rxtx.c +4 -2
@@ -560,7 +560,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)struct rte_mbuf *rcv_pkts[VIRTIO_MBUF_BURST_SZ ];int error;uint32_t i, nb_enqueued; -const uint32_t hdr_size =sizeof (struct virtio_net_hdr ); +uint32_t hdr_size; nb_used =VIRTQUEUE_NUSED (rxvq);
@@ -580,6 +580,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) hw = rxvq->hw; nb_rx =0 ; nb_enqueued =0 ; + hdr_size = hw->vtnet_hdr_size;for (i =0 ; i < num ; i++) { rxm = rcv_pkts[i];
@@ -664,7 +665,7 @@ virtio_recv_mergeable_pkts(void *rx_queue,uint32_t seg_num;uint16_t extra_idx;uint32_t seg_res; -const uint32_t hdr_size =sizeof (struct virtio_net_hdr_mrg_rxbuf ); +uint32_t hdr_size; nb_used =VIRTQUEUE_NUSED (rxvq);
@@ -682,6 +683,7 @@ virtio_recv_mergeable_pkts(void *rx_queue, seg_num =0 ; extra_idx =0 ; seg_res =0 ; + hdr_size = hw->vtnet_hdr_size;while (i < nb_used) {struct virtio_net_hdr_mrg_rxbuf *header;
drivers/net/virtio/virtio_rxtx_simple.c +6 -6
@@ -81,9 +81,9 @@ virtqueue_enqueue_recv_refill_simple(struct virtqueue *vq, start_dp = vq->vq_ring.desc; start_dp[desc_idx].addr = (uint64_t )((uintptr_t )cookie->buf_physaddr + -RTE_PKTMBUF_HEADROOM -sizeof (struct virtio_net_hdr )); +RTE_PKTMBUF_HEADROOM - vq->hw->vtnet_hdr_size); start_dp[desc_idx].len = cookie->buf_len - -RTE_PKTMBUF_HEADROOM +sizeof (struct virtio_net_hdr ); +RTE_PKTMBUF_HEADROOM + vq->hw->vtnet_hdr_size; vq->vq_free_cnt--; vq->vq_avail_idx++;
@@ -120,9 +120,9 @@ virtio_rxq_rearm_vec(struct virtqueue *rxvq) start_dp[i].addr = (uint64_t )((uintptr_t )sw_ring[i]->buf_physaddr + -RTE_PKTMBUF_HEADROOM -sizeof (struct virtio_net_hdr )); +RTE_PKTMBUF_HEADROOM - rxvq->hw->vtnet_hdr_size); start_dp[i].len = sw_ring[i]->buf_len - -RTE_PKTMBUF_HEADROOM +sizeof (struct virtio_net_hdr ); +RTE_PKTMBUF_HEADROOM + rxvq->hw->vtnet_hdr_size; } rxvq->vq_avail_idx +=RTE_VIRTIO_VPMD_RX_REARM_THRESH ;
@@ -175,8 +175,8 @@ virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts, len_adjust =_mm_set_epi16 (0 ,0 ,0 , - (uint16_t ) -sizeof (struct virtio_net_hdr ), -0 , (uint16_t ) -sizeof (struct virtio_net_hdr ), + (uint16_t ) -rxvq->hw->vtnet_hdr_size, +0 , (uint16_t ) -rxvq->hw->vtnet_hdr_size,0 ,0 );if (unlikely (nb_pkts <RTE_VIRTIO_DESC_PER_LOOP ))
Signature · 1 line
1.9.0
PATCH v4 6/8 eal: pci: export pci_[un]map_device
In reply to Yuanhan LiuNormally we could set RTE_PCI_DRV_NEED_MAPPING flag so that eal will invoke pci_map_device internally for us. From that point view, there is no need to export pci_map_device.
However, for virtio pmd driver, which is designed to work without binding UIO (or something similar first), pci_map_device() will fail, which ends up with virtio pmd driver being skipped. Therefore, we can not set RTE_PCI_DRV_NEED_MAPPING blindly at virtio pmd driver.
Therefore, this patch exports pci_map_device, and let virtio pmd call it when necessary.
---
v3: - export pci_unmap_device as well
- Add few more comments about rte_eal_pci_map_device().
--- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 ++-- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 7 +++++++ lib/librte_eal/common/eal_common_pci.c | 4 ++-- lib/librte_eal/common/eal_private.h | 18 ----------------- lib/librte_eal/common/include/rte_pci.h | 27 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 4 ++-- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 7 +++++++ 7 files changed, 47 insertions(+), 24 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -2
@@ -93,7 +93,7 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)/* Map pci device */ int -pci_map_device (struct rte_pci_device *dev) +rte_eal_pci_map_device (struct rte_pci_device *dev) {int ret =-1 ;
@@ -115,7 +115,7 @@ pci_map_device(struct rte_pci_device *dev)/* Unmap pci device */ void -pci_unmap_device (struct rte_pci_device *dev) +rte_eal_pci_unmap_device (struct rte_pci_device *dev) {/* try unmapping the NIC resources */ switch (dev->kdrv) {
lib/librte_eal/bsdapp/eal/rte_eal_version.map +7 -0
@@ -135,3 +135,10 @@ DPDK_2.2 { rte_xen_dom0_supported; } DPDK_2.1; + +DPDK_2.3 { + global: + + rte_eal_pci_map_device; + rte_eal_pci_unmap_device; +} DPDK_2.2;
lib/librte_eal/common/eal_common_pci.c +2 -2
@@ -188,7 +188,7 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dpci_config_space_set (dev);#endif /* map resources for devices that use igb_uio */ - ret =pci_map_device (dev); + ret =rte_eal_pci_map_device (dev);if (ret !=0 )return ret; } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
@@ -254,7 +254,7 @@ rte_eal_pci_detach_dev(struct rte_pci_driver *dr,if (dr->drv_flags &RTE_PCI_DRV_NEED_MAPPING )/* unmap resources for devices that use igb_uio */ -pci_unmap_device (dev); +rte_eal_pci_unmap_device (dev);return 0 ; }
lib/librte_eal/common/eal_private.h +0 -18
@@ -165,24 +165,6 @@ struct rte_pci_device;int pci_unbind_kernel_driver (struct rte_pci_device *dev);/** -* Map this device -* -* This function is private to EAL. -* -* @return -* 0 on success, negative on error and positive if no driver -* is found for the device. -*/ -int pci_map_device (struct rte_pci_device *dev); - -/** -* Unmap this device -* -* This function is private to EAL. -*/ -void pci_unmap_device (struct rte_pci_device *dev); - -/** * Map the PCI resource of a PCI device in virtual memory * * This function is private to EAL.
lib/librte_eal/common/include/rte_pci.h +27 -0
@@ -485,6 +485,33 @@ int rte_eal_pci_read_config(const struct rte_pci_device *device,*/ int rte_eal_pci_write_config (const struct rte_pci_device *device,const void *buf,size_t len,off_t offset); +/** +* Map the PCI device resources in user space virtual memory address +* +* Note that driver should not call this function when flag +* RTE_PCI_DRV_NEED_MAPPING is set, as EAL will do that for +* you when it's on. +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +* +* @return +* 0 on success, negative on error and positive if no driver +* is found for the device. +*/ +int rte_eal_pci_map_device (struct rte_pci_device *dev); + +/** +* Unmap this device +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +*/ +void rte_eal_pci_unmap_device (struct rte_pci_device *dev); + +#ifdef RTE_PCI_CONFIG /**
lib/librte_eal/linuxapp/eal/eal_pci.c +2 -2
@@ -124,7 +124,7 @@ pci_get_kernel_driver_by_path(const char *filename, char *dri_name)/* Map pci device */ int -pci_map_device (struct rte_pci_device *dev) +rte_eal_pci_map_device (struct rte_pci_device *dev) {int ret =-1 ;
@@ -153,7 +153,7 @@ pci_map_device(struct rte_pci_device *dev)/* Unmap pci device */ void -pci_unmap_device (struct rte_pci_device *dev) +rte_eal_pci_unmap_device (struct rte_pci_device *dev) {/* try unmapping the NIC resources using VFIO if it exists */ switch (dev->kdrv) {
lib/librte_eal/linuxapp/eal/rte_eal_version.map +7 -0
@@ -138,3 +138,10 @@ DPDK_2.2 { rte_xen_dom0_supported; } DPDK_2.1; + +DPDK_2.3 { + global: + + rte_eal_pci_map_device; + rte_eal_pci_unmap_device; +} DPDK_2.2;
Signature · 1 line
1.9.0
PATCH v4 7/8 virtio: add 1.0 support
In reply to Yuanhan LiuModern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
Firstly, we map the pci resources by rte_eal_pci_map_device(). We then could easily locate a cfg structure by:
cfg_addr = dev->mem_resources[cap.bar].addr + cap.offset;
Therefore, the entrance of enabling modern (v1.0) pci device support is to iterate the pci capability lists, and to locate some configs we care; and they are:
- common cfg
For generic virtio and virtqueue configuration, such as setting/getting features, enabling a specific queue, and so on.
- nofity cfg
Combining with `queue_notify_off' from common cfg, we could use it to notify a specific virt queue.
- device cfg
Where virtio_net_config structure is located.
- isr cfg
Where to read isr (interrupt status).
If any of above cap is not found, we fallback to the legacy virtio handling.
If succeed, hw->vtpci_ops is assigned to modern_ops, where all operations are implemented by reading/writing a (or few) specific configuration space from above 4 cfg structures. And that's basically how this patch works.
Besides those changes, virtio 1.0 introduces a new status field:FEATURES_OK, which is set after features negotiation is done.
Last, set the VIRTIO_F_VERSION_1 feature flag.
---
v2: - re-read status after setting FEATURES_OK to make sure status is
set correctly.
- Add isr reading and config irq setting support.
- Define some pci macro on our own to not get the dependency of linux/pci_regs.h, as there should be no such file at non-Linux platform
v3: - invoke rte_eal_pci_unmap_device() at uninit stage
v4: - remove unnessary inline, and likely/unlikely
- mark "src" arg as const for write_dev_cfg operation
--- doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 25 ++- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 335 ++++++++++++++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 67 +++++++ drivers/net/virtio/virtqueue.h | 2 + 6 files changed, 430 insertions(+), 5 deletions(-)
doc/guides/rel_notes/release_2_3.rst +3 -0
@@ -4,6 +4,9 @@ DPDK Release 2.3 New Features ------------ +* **Virtio 1.0 support.** + + Enabled virtio 1.0 support for virtio pmd driver. Resolved Issues ---------------
drivers/net/virtio/virtio_ethdev.c +22 -3
@@ -927,7 +927,7 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)return virtio_send_command (hw->cvq, &ctrl, &len,1 ); } -static void +static int virtio_negotiate_features (struct virtio_hw *hw) {uint64_t host_features;
@@ -949,6 +949,22 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features =vtpci_negotiate_features (hw, host_features);PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); + +if (hw->modern) { +if (!vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) { +PMD_INIT_LOG (ERR , +"VIRTIO_F_VERSION_1 features is not enabled." ); +return -1 ; + } +vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_FEATURES_OK ); +if (!(vtpci_get_status (hw) &VIRTIO_CONFIG_STATUS_FEATURES_OK )) { +PMD_INIT_LOG (ERR , +"failed to set FEATURES_OK status!" ); +return -1 ; + } + } + +return 0 ; }/*
@@ -1032,7 +1048,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)/* Tell the host we've known how to drive the device. */ vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_DRIVER ); -virtio_negotiate_features (hw); +if (virtio_negotiate_features (hw) <0 ) +return -1 ;/* If host does not support status then disable LSC */ if (!vtpci_with_feature (hw,VIRTIO_NET_F_STATUS ))
@@ -1043,7 +1060,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)rx_func_get (eth_dev);/* Setting up rx_header size for the device */ -if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF ) || +vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) hw->vtnet_hdr_size =sizeof (struct virtio_net_hdr_mrg_rxbuf );else hw->vtnet_hdr_size =sizeof (struct virtio_net_hdr );
@@ -1159,6 +1177,7 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)rte_intr_callback_unregister (&pci_dev->intr_handle, virtio_interrupt_handler, eth_dev); +rte_eal_pci_unmap_device (pci_dev);PMD_INIT_LOG (DEBUG ,"dev_uninit completed" );
drivers/net/virtio/virtio_ethdev.h +2 -1
@@ -64,7 +64,8 @@1u <<VIRTIO_NET_F_CTRL_VQ | \1u <<VIRTIO_NET_F_CTRL_RX | \1u <<VIRTIO_NET_F_CTRL_VLAN | \ - 1u << VIRTIO_NET_F_MRG_RXBUF) +1u <<VIRTIO_NET_F_MRG_RXBUF | \ + 1ULL << VIRTIO_F_VERSION_1)/* * CQ function prototype
drivers/net/virtio/virtio_pci.c +334 -1
367 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +67 -0
104 lines not on this page · raw message
drivers/net/virtio/virtqueue.h +2 -0
@@ -202,6 +202,8 @@ struct virtqueue {/* Size bins in array as RFC 2819, undersized [0], 64 [1], etc */ uint64_t size_bins[8 ]; +uint16_t *notify_addr; +struct vq_desc_extra {void *cookie;uint16_t ndescs;
Signature · 1 line
1.9.0
PATCH v4 8/8 virtio: move VIRTIO_READ/WRITE_REG_X into virtio_pci.c
In reply to Yuanhan Liuvirtio_pci.c is the only file references those macros; move them there.
--- drivers/net/virtio/virtio_pci.c | 19 +++++++++++++++++++ drivers/net/virtio/virtio_pci.h | 18 ------------------ 2 files changed, 19 insertions(+), 18 deletions(-)
drivers/net/virtio/virtio_pci.c +19 -0
@@ -49,6 +49,25 @@#define PCI_CAPABILITY_LIST 0x34#define PCI_CAP_ID_VNDR 0x09 + +#define VIRTIO_PCI_REG_ADDR (hw, reg) \ + (unsigned short)((hw)->io_base + (reg)) + +#define VIRTIO_READ_REG_1 (hw, reg) \ + inb((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_1 (hw, reg, value) \ + outb_p((unsigned char)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) + +#define VIRTIO_READ_REG_2 (hw, reg) \ + inw((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_2 (hw, reg, value) \ + outw_p((unsigned short)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) + +#define VIRTIO_READ_REG_4 (hw, reg) \ + inl((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_4 (hw, reg, value) \ + outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) +static void legacy_read_dev_config (struct virtio_hw *hw,uint64_t offset,void *dst,int length)
drivers/net/virtio/virtio_pci.h +0 -18
@@ -318,24 +318,6 @@ outl_p(unsigned int data, unsigned int port) }#endif -#define VIRTIO_PCI_REG_ADDR (hw, reg) \ - (unsigned short)((hw)->io_base + (reg)) - -#define VIRTIO_READ_REG_1 (hw, reg) \ - inb((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_1 (hw, reg, value) \ - outb_p((unsigned char)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) - -#define VIRTIO_READ_REG_2 (hw, reg) \ - inw((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_2 (hw, reg, value) \ - outw_p((unsigned short)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) - -#define VIRTIO_READ_REG_4 (hw, reg) \ - inl((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_4 (hw, reg, value) \ - outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) -static inline int vtpci_with_feature (struct virtio_hw *hw,uint64_t bit) {
Signature · 1 line
1.9.0
Re: [PATCH v4 8/8] virtio: move VIRTIO_READ/WRITE_REG_X into virtio_pci.c
- Test Commit: ad66a85dce9a707748cb4d9592c13022ae77c067
- OS/Kernel: Fedora 21/4.1.13
- GCC: gcc (GCC) 4.9.2 20141101 (Red Hat 4.9.2-1)
- CPU: Intel(R) Xeon(R) CPU E5-2695 v4 @ 2.10
- NIC: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
- Target: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
- Total 2 cases, 2 passed, 0 failed.
Test Case1: test_func_vhost_user_virtio1.0-pmd with different txqflags
======================================================================
Note: For virtio1.0 usage, we need use qemu version >2.4, such as 2.4.1 or 2.5.0.
1. Launch the Vhost sample by below commands, socket-mem is set for the vhost sample to use, need ensure that the PCI port located socket has the memory. In our case, the PCI BDF is 81:00.0, so we need assign memory for socket1.::
taskset -c 18-20 ./examples/vhost/build/vhost-switch -c 0x1c0000 -n 4 --huge-dir /mnt/huge --socket-mem 0,2048 -- -p 1 --mergeable 0 --zero-copy 0 --vm2vm 0
2. Start VM with 1 virtio, note: we need add "disable-modern=false" to enable virtio 1.0.
taskset -c 22-23 \
/root/qemu-versions/qemu-2.5.0/x86_64-softmmu/qemu-system-x86_64 -name us-vhost-vm1 \
-cpu host -enable-kvm -m 2048 -object memory-backend-file,id=mem,size=2048M,mem-path=/mnt/huge,share=on -numa node,memdev=mem -mem-prealloc \
-smp cores=2,sockets=1 -drive file=/home/img/vm1.img \
-chardev socket,id=char0,path=/home/qxu10/virtio-1.0/dpdk/vhost-net -netdev type=vhost-user,id=mynet1,chardev=char0,vhostforce \
-device virtio-net-pci,mac=52:54:00:00:00:01,netdev=mynet1,disable-modern=false \
-netdev tap,id=ipvm1,ifname=tap3,script=/etc/qemu-ifup -device rtl8139,netdev=ipvm1,id=net0,mac=00:00:00:00:10:01 -nographic3. In the VM, change the config file--common_linuxapp, "CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_INIT=y"; Run dpdk testpmd in VM::
./<dpdk_folder>/tools/dpdk_nic_bind.py --bind igb_uio 00:03.0
./<dpdk_folder>/x86_64-native-linuxapp-gcc/app/test-pmd/testpmd -c 0x3 -n 4 -- -i --txqflags 0x0f00 --disable-hw-vlan
$ >set fwd mac
$ >start tx_first
We expect similar output as below, and see modern virtio pci detected.
PMD: virtio_read_caps(): [98] skipping non VNDR cap id: 11
PMD: virtio_read_caps(): [84] cfg type: 5, bar: 0, offset: 0000, len: 0
PMD: virtio_read_caps(): [70] cfg type: 2, bar: 4, offset: 3000, len: 4194304
PMD: virtio_read_caps(): [60] cfg type: 4, bar: 4, offset: 2000, len: 4096
PMD: virtio_read_caps(): [50] cfg type: 3, bar: 4, offset: 1000, len: 4096
PMD: virtio_read_caps(): [40] cfg type: 1, bar: 4, offset: 0000, len: 4096
PMD: virtio_read_caps(): found modern virtio pci device.
PMD: virtio_read_caps(): common cfg mapped at: 0x7f2c61a83000
PMD: virtio_read_caps(): device cfg mapped at: 0x7f2c61a85000
PMD: virtio_read_caps(): isr cfg mapped at: 0x7f2c61a84000
PMD: virtio_read_caps(): notify base: 0x7f2c61a86000, notify off multiplier: 409 6
PMD: vtpci_init(): modern virtio pci detected.4. Send traffic to virtio1(MAC1=52:54:00:00:00:01) with VLAN ID=1000. Check if virtio packet can be RX/TX and also check the TX packet size is same as the RX packet size.
5. Also run the dpdk testpmd in VM with txqflags=0xf01 for the virtio pmd optimization usage::
./<dpdk_folder>/tools/dpdk_nic_bind.py --bind igb_uio 00:03.0
./<dpdk_folder>/x86_64-native-linuxapp-gcc/app/test-pmd/testpmd -c 0x3 -n 4 -- -i --txqflags=0x0f01 --disable-hw-vlan
$ >set fwd mac
$ >start tx_first
6. Send traffic to virtio1(MAC1=52:54:00:00:00:01) and VLAN ID=1000. Check if virtio packet can be RX/TX and also check the TX packet size is same as the RX packet size. Check the packet content is correct.
Test Case2: test_func_vhost_user_one-vm-virtio1.0-one-vm-virtio0.95
===================================================================
1. Launch the Vhost sample by below commands, socket-mem is set for the vhost sample to use, need ensure that the PCI port located socket has the memory. In our case, the PCI BDF is 81:00.0, so we need assign memory for socket1.::
taskset -c 18-20 ./examples/vhost/build/vhost-switch -c 0x1c0000 -n 4 --huge-dir /mnt/huge --socket-mem 0,2048 -- -p 1 --mergeable 0 --zero-copy 0 --vm2vm 1
2. Start VM1 with 1 virtio, note: we need add "disable-modern=false" to enable virtio 1.0.
taskset -c 22-23 \
/root/qemu-versions/qemu-2.5.0/x86_64-softmmu/qemu-system-x86_64 -name us-vhost-vm1 \
-cpu host -enable-kvm -m 2048 -object memory-backend-file,id=mem,size=2048M,mem-path=/mnt/huge,share=on -numa node,memdev=mem -mem-prealloc \
-smp cores=2,sockets=1 -drive file=/home/img/vm1.img \
-chardev socket,id=char0,path=/home/qxu10/virtio-1.0/dpdk/vhost-net -netdev type=vhost-user,id=mynet1,chardev=char0,vhostforce \
-device virtio-net-pci,mac=52:54:00:00:00:01,netdev=mynet1,disable-modern=false \
-netdev tap,id=ipvm1,ifname=tap3,script=/etc/qemu-ifup -device rtl8139,netdev=ipvm1,id=net0,mac=00:00:00:00:10:01 -nographic3. Start VM2 with 1 virtio, note:
taskset -c 24-25 \
/root/qemu-versions/qemu-2.5.0/x86_64-softmmu/qemu-system-x86_64 -name us-vhost-vm1 \
-cpu host -enable-kvm -m 2048 -object memory-backend-file,id=mem,size=2048M,mem-path=/mnt/huge,share=on -numa node,memdev=mem -mem-prealloc \
-smp cores=2,sockets=1 -drive file=/home/img/vm2.img \
-chardev socket,id=char0,path=/home/qxu10/virtio-1.0/dpdk/vhost-net -netdev type=vhost-user,id=mynet2,chardev=char0,vhostforce \
-device virtio-net-pci,mac=52:54:00:00:00:02,netdev=mynet2,disable-modern=true \
-netdev tap,id=ipvm2,ifname=tap4,script=/etc/qemu-ifup -device rtl8139,netdev=ipvm2,id=net1,mac=00:00:00:00:10:02 -nographic3. Run dpdk testpmd in VM1 and VM2::
VM1:
./<dpdk_folder>/tools/dpdk_nic_bind.py --bind igb_uio 00:03.0
./<dpdk_folder>/x86_64-native-linuxapp-gcc/app/test-pmd/testpmd -c 0x3 -n 4 -- -i --txqflags 0x0f00 --disable-hw-vlan --eth-peer=0,52:54:00:00:00:02
$ >set fwd mac
$ >start tx_first
VM2:
./<dpdk_folder>/tools/dpdk_nic_bind.py --bind igb_uio 00:03.0
./<dpdk_folder>/x86_64-native-linuxapp-gcc/app/test-pmd/testpmd -c 0x3 -n 4 -- -i --txqflags 0x0f00 --disable-hw-vlan
$ >set fwd mac
$ >start tx_first4. Send 100 packets at low rate to virtio1, and the expected flow is ixia-->NIC-->VHOST-->Virtio1-->Virtio2-->Vhost-->NIC->ixia port. Check the packet back at ixia port is content correct, no size change and payload change.
Thanks
Qian
-----Original Message-----
From: Yuanhan Liu [mailto:[email protected]]
Sent: Friday, January 15, 2016 12:36 PM
To: [email protected]
Cc: Xie, Huawei; Tetsuya Mukawa; Tan, Jianfeng; Xu, Qian Q; Yuanhan Liu
Subject: [PATCH v4 8/8] virtio: move VIRTIO_READ/WRITE_REG_X into virtio_pci.c
virtio_pci.c is the only file references those macros; move them there.
--- drivers/net/virtio/virtio_pci.c | 19 +++++++++++++++++++ drivers/net/virtio/virtio_pci.h | 18 ------------------ 2 files changed, 19 insertions(+), 18 deletions(-)
drivers/net/virtio/virtio_pci.c +19 -0
@@ -49,6 +49,25 @@#define PCI_CAPABILITY_LIST 0x34#define PCI_CAP_ID_VNDR 0x09 + +#define VIRTIO_PCI_REG_ADDR (hw, reg) \ + (unsigned short)((hw)->io_base + (reg)) + +#define VIRTIO_READ_REG_1 (hw, reg) \ + inb((VIRTIO_PCI_REG_ADDR((hw), (reg)))) #define VIRTIO_WRITE_REG_1(hw, +reg, value) \ + outb_p((unsigned char)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) + +#define VIRTIO_READ_REG_2(hw, reg) \ + inw((VIRTIO_PCI_REG_ADDR((hw), (reg)))) #define VIRTIO_WRITE_REG_2(hw, +reg, value) \ + outw_p((unsigned short)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) + +#define VIRTIO_READ_REG_4 (hw, reg) \ + inl((VIRTIO_PCI_REG_ADDR((hw), (reg)))) #define VIRTIO_WRITE_REG_4(hw, +reg, value) \ + outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) + static voidlegacy_read_dev_config (struct virtio_hw *hw,uint64_t offset,void *dst,int length)
drivers/net/virtio/virtio_pci.h +0 -19
@@ -318,24 +318,6 @@ outl_p(unsigned int data, unsigned int port) } #endif -#define VIRTIO_PCI_REG_ADDR (hw, reg) \ - (unsigned short)((hw)->io_base + (reg)) - -#define VIRTIO_READ_REG_1 (hw, reg) \ - inb((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_1 (hw, reg, value) \ - outb_p((unsigned char)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) - -#define VIRTIO_READ_REG_2 (hw, reg) \ - inw((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_2 (hw, reg, value) \ - outw_p((unsigned short)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) - -#define VIRTIO_READ_REG_4 (hw, reg) \ - inl((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_4 (hw, reg, value) \ - outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) -static inline int vtpci_with_feature (struct virtio_hw *hw,uint64_t bit) { --
1.9.0
Re: [PATCH v3 8/8] virtio: move VIRTIO_READ/WRITE_REG_X into virtio_pci.c
In reply to Yuanhan LiuQuoted 2 lines · Yuanhan Liu
virtio_pci.cbecome the only file references those macros; move them there.
My patch VFIO series need virtio_rd/wr So keeping these api in virtio_pci.h make more sense to me.
Re: [PATCH v3 8/8] virtio: move VIRTIO_READ/WRITE_REG_X into virtio_pci.c
Quoted 7 lines · Santosh Shukla
Quoted 2 lines · Yuanhan Liu
virtio_pci.cbecome the only file references those macros; move them there.My patch VFIO series need virtio_rd/wr So keeping these api in
virtio_pci.hmake more sense to me.
Ignore my comment, I just finished reading your patch series and wont see any potential issue in moving my vfio rd/wr api to vfio_pci.c.
Re: [PATCH v4 0/8] virtio 1.0 enabling for virtio pmd driver
In reply to Yuanhan LiuQuoted 72 lines · Yuanhan Liu
v4: - mark "src" arg as const for
write_dev_cfgoperation- remove unnessary inline, and likely/unlikely
v3: - export
pci_unmap_deviceas well; and invoke it at virtio
uninit stage.- fixed same data corruption bug reported by Qian in simple rxtx code path.
- move VIRTIO_READ/WRITE_REG_X to
virtio_pci.cv2: - fix a data corruption reported by Qian, due to hdr size mismatch.
check detailes at ptach 5.- Add missing
config_irqand isr reading support from v1.- fix comments from v1.
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 7.To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a
virtio_pci_opsstructure, to add another layer so that we could keep thosevtpci_foo_bar"APIs". With that, we could do the minimum change to add virtio 1.0 support.Rough test guide
================Firstly, you need get a virtio 1.0 supported QEMU (say, v2.5), then add option "disable-modern=false" to qemu virtio-net-pci device to enable virtio 1.0 (which is disabled by default).
And if you see something like following from 'lspci -v', it means virtio 1.0 is indeed enabled:
00:04.0 Ethernet controller: Red Hat, Inc Virtio network device
Subsystem: Red Hat, Inc Device 0001
Physical Slot: 4
Flags: bus master, fast devsel, latency 0, IRQ 11 I/O ports at c040 [size=64]
Memory atfebf1000(32-bit, non-prefetchable) [size=4K] Memory atfe000000(64-bit, prefetchable) [size=8M] Expansion ROM atfeb80000[disabled] [size=256K]
Capabilities: [98] MSI-X: Enable+ Count=6 Masked-
==> Capabilities: [84] Vendor Specific Information: Len=14 <?> ==> Capabilities: [70] Vendor Specific Information: Len=14 <?> ==> Capabilities: [60] Vendor Specific Information: Len=10 <?> ==> Capabilities: [50] Vendor Specific Information: Len=10 <?> ==> Capabilities: [40] Vendor Specific Information: Len=10 <?>
Kernel driver in use: virtio-pci
Kernel modules:virtio_pciAfter that, there wasn't anything speical comparing to the old virtio 0.95 pmd driver.
---
Yuanhan Liu (8):
virtio: don't set vring address again at queue startup
virtio: introduce structvirtio_pci_ops
virtio: move left pci stuff tovirtio_pci.c
viritio: switch to 64 bit features
virtio: retrievehdr_sizefromhw->vtnet_hdr_size
eal: pci: export pci_[un]map_device
virtio: add 1.0 support
virtio: move VIRTIO_READ/WRITE_REG_X intovirtio_pci.c
Quoted 17 lines
doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 302 +-------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 793 +++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 120 +++- drivers/net/virtio/virtio_rxtx.c | 21 +- drivers/net/virtio/virtio_rxtx_simple.c | 12 +- drivers/net/virtio/virtqueue.h | 4 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 +- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 7 + lib/librte_eal/common/eal_common_pci.c | 4 +- lib/librte_eal/common/eal_private.h | 18 - lib/librte_eal/common/include/rte_pci.h | 27 + lib/librte_eal/linuxapp/eal/eal_pci.c | 4 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 7 + 15 files changed, 949 insertions(+), 380 deletions(-)
Re: [PATCH v2 0/7] virtio 1.0 enabling for virtio pmd driver
In reply to Tetsuya MukawaQuoted 66 lines · Tetsuya Mukawa
Quoted 64 lines
Quoted 25 lines
2. Abstraction of read/write accesses.
It may be difficult to cleanly rebase my patches on this patches, because
virtio_read_caps()is not abstracted.
Let me describe it more.
So far, we need to handle below 3 virtio-net devices..
- physical virtio-net device.
- virtual virtio-net device in virtio-net PMD. (Jianfeng's patch)
- virtual virtio-net device in QEMU. (my patch)Almost all code of the virtio-net PMD can be shared between above different cases.
Probably big difference is how to access to configuration space.Yuanhan's patch introduces an abstraction layer to hide configuration space layout and how to access it.
Is it possible to separate?
I guess "access method" will be nice to be abstracted separately from "configuration space layout".
Probably access method will be defined by "eth_dev->dev_type" and the PMD name like "eth_cvio".
And "configuration space layout" will be defined by capability list of PCI configuration layout.Quoted 6 lines
For example, if access method like below are abstracted separately and current "
virtio_pci.c" is implemented on this abstraction, we can easily re-usevirtio_read_caps().
- how to read/write virtio configuration space.
- how to mmap PCI configuration space.
- how to read/(write) PCI configuration space.I basically agree with you. We have two dimensions here:
legacy modern
physical virtio device: Usevirtio_read_caps_phys()to distinguish
virtual virtio device (Tetsuya): Usevirtio_read_caps_virt()to
distinguish
virtual virtio device (Jianfeng): does not need a "configuration
space layout", no need to distinguishSo in
vtpci_init(), we needs to test "eth_dev->dev_type" firstlyvtpci_init() { if (eth_dev->dev_type == RTE_ETH_DEV_PCI) { if (virtio_read_caps_phys()) { // modern } else { // legacy } } else { if (Tetsuya's way) { if (virtio_read_caps_virt()) { // modern } else { // legacy } } else { // Jianfeng's way } } }Quoted 2 lines
And from Yuanhan's angle, I think he does not need to address this problem. How do you think?
Quoted 7 lines
Yes, I agree he doesn't need.
Firstly, I have implemented like above, then I noticed that
virtio_read_caps_phy()andvirtio_read_caps_virt()are same except for access method.
Anyway, I guess abstracting access method is not so difficult. If you are OK, I want to send RFC on Yuanhan's patch. Is it OK?
Hi Jianfeng,
I will submit patches to abstract pci access method. The patches will be on Yuanhan's latest virtio-1.0 patches.
I guess your container patches also can be on the patches. Could you please check it?
Thanks,
Tetsuya
Re: [PATCH v4 7/8] virtio: add 1.0 support
In reply to Yuanhan LiuQuoted 4 lines · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
[snip]
Quoted 5 lines
drivers/net/virtio/virtio_pci.c +4
-0+static void * +get_cfg_addr (struct rte_pci_device *dev,struct virtio_pci_cap *cap) +{ +uint8_t bar = cap->bar;
drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 736
Quoted 10 lines
drivers/net/virtio/virtio_pci.c +10
-0+uint32_t length = cap->length; +uint32_t offset = cap->offset; +uint8_t *base; + +if (bar >5 ) { +PMD_INIT_LOG (ERR ,"invalid bar: %u" , bar); +return NULL ; + } + +if (offset + length > dev->mem_resource[bar].len) {
offset + length could overflow 32bit limit
Quoted 7 lines
drivers/net/virtio/virtio_pci.c +7
-0+PMD_INIT_LOG (ERR , +"invalid cap: overflows bar space: %u > %" PRIu64, + offset + length, dev->mem_resource[bar].len); +return NULL ; + } + +
[snip]
Re: [PATCH v4 7/8] virtio: add 1.0 support
In reply to Yuanhan Liudrivers/net/virtio/virtio_ethdev.c virtio_negotiate_features(struct virtio_hw *hw) · line 949
Quoted 7 lines · Yuanhan Liu
drivers/net/virtio/virtio_ethdev.c +1
-1-static void +static int virtio_negotiate_features (struct virtio_hw *hw) {uint64_t host_features;@@ -949,6 +949,22 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features =vtpci_negotiate_features (hw, host_features);
Here if we are not modern device, we should remove VIRTIO_F_VERSION_1 in guest features.
Quoted 19 lines
drivers/net/virtio/virtio_ethdev.c +16
-0PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); + +if (hw->modern) { +if (!vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) { +PMD_INIT_LOG (ERR , +"VIRTIO_F_VERSION_1 features is not enabled." ); +return -1 ; + } +vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_FEATURES_OK ); +if (!(vtpci_get_status (hw) &VIRTIO_CONFIG_STATUS_FEATURES_OK )) { +PMD_INIT_LOG (ERR , +"failed to set FEATURES_OK status!" ); +return -1 ; + } + } + +return 0 ; }
Re: [PATCH v4 7/8] virtio: add 1.0 support
In reply to Yuanhan LiuQuoted 4 lines · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
[snip]
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 480
Quoted 6 lines
drivers/net/virtio/virtio_pci.c +6
-0+ +static inline void +io_write64_twopart (uint64_t val,uint32_t *lo,uint32_t *hi) +{ +io_write32 ((uint32_t )val, lo); +io_write32 (val >>32 , hi);
Firstly your second iowrite32 doesn't do the conversion. The conversion is duplicated.
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 484
Quoted 4 lines
drivers/net/virtio/virtio_pci.c +4
-0+} + +static void +modern_read_dev_config(struct virtio_hw *hw, uint64_t offset,
here and there, size_t is more accurate for offset as we get it from offsetof.
Quoted 37 lines
drivers/net/virtio/virtio_pci.c +37
-0+ void *dst, int length) +{ + int i; +uint8_t *p; +uint8_t old_gen, new_gen; + +do { + old_gen =io_read8 (&hw->common_cfg->config_generation); + + p = dst; +for (i =0 ; i < length; i++) + *p++ =io_read8 ((uint8_t *)hw->dev_cfg + offset + i); + + new_gen =io_read8 (&hw->common_cfg->config_generation); + }while (old_gen != new_gen); +} + +static void +modern_write_dev_config (struct virtio_hw *hw,uint64_t offset, +const void *src,int length) +{ +int i; +const uint8_t *p = src; + +for (i =0 ; i < length; i++) +io_write8 (*p++, (uint8_t *)hw->dev_cfg + offset + i); +} + +static uint64_t +modern_get_features (struct virtio_hw *hw) +{ +uint32_t features_lo, features_hi; + +io_write32 (0 , &hw->common_cfg->device_feature_select); + features_lo =io_read32 (&hw->common_cfg->device_feature); + +io_write32 (1 , &hw->common_cfg->device_feature_select);
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 531
Quoted 10 lines
drivers/net/virtio/virtio_pci.c +10
-0+ features_hi =io_read32 (&hw->common_cfg->device_feature); + +return ((uint64_t )(features_hi) <<32 ) | features_lo; +} + +static void +modern_set_features (struct virtio_hw *hw,uint64_t features) +{ +io_write32 (0 , &hw->common_cfg->guest_feature_select); + io_write32(features & ((1ULL << 32) - 1),
again, duplicated conversion
Quoted 3 lines
drivers/net/virtio/virtio_pci.c +3
-0+ &hw->common_cfg->guest_feature); + +io_write32 (1 , &hw->common_cfg->guest_feature_select);
[snip]
Re: [PATCH v4 2/8] virtio: introduce struct virtio_pci_ops
In reply to Yuanhan Liudrivers/net/virtio/virtio_pci.c vtpci_write_dev_config(struct virtio_hw *hw, uint64_t offset, · line 188
Quoted 5 lines · Yuanhan Liu
drivers/net/virtio/virtio_pci.c +5
-0+void +vtpci_write_dev_config (struct virtio_hw *hw,uint64_t offset, +void *src,int length) +{ + hw->vtpci_ops->write_dev_cfg (hw, offset, src, length);
missed changing src to const.
Quoted 1 line
+}
Re: [PATCH v4 7/8] virtio: add 1.0 support
In reply to Xie, HuaweiQuoted 6 lines · Huawei
Quoted 4 lines · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
[snip]
Quoted 8 lines
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 480
Quoted 6 lines
drivers/net/virtio/virtio_pci.c +6
-0+ +static inline void +io_write64_twopart (uint64_t val,uint32_t *lo,uint32_t *hi) +{ +io_write32 ((uint32_t )val, lo); +io_write32 (val >>32 , hi);Firstly your second iowrite32 doesn't do the conversion.
Because it's not necessary. The first one is for retrieving the low 32 bits.
Quoted 1 line
The conversion is duplicated.
What do you mean by "duplicated".
--yliu
Re: [PATCH v4 7/8] virtio: add 1.0 support
Quoted 14 lines · Yuanhan Liu
Quoted 5 lines · Huawei
Quoted 4 lines · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
Quoted 8 lines
[snip]
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 480
Quoted 6 lines
drivers/net/virtio/virtio_pci.c +6
-0+ +static inline void +io_write64_twopart (uint64_t val,uint32_t *lo,uint32_t *hi) +{ +io_write32 ((uint32_t )val, lo); +io_write32 (val >>32 , hi);Firstly your second iowrite32 doesn't do the conversion.
Quoted 2 lines
Because it's not necessary. The first one is for retrieving the low 32 bits.
I don't mean the shift operation, but the conversion from 64bit to 32bit. Same applied to below.
Quoted 6 lines
Quoted 2 lines
The conversion is duplicated.
What do you mean by "duplicated".
--yliu
Re: [PATCH v4 7/8] virtio: add 1.0 support
Quoted 15 lines · Huawei
Quoted 14 lines · Yuanhan Liu
Quoted 13 lines · Huawei
Quoted 4 lines · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
[snip]
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 480
Quoted 6 lines
drivers/net/virtio/virtio_pci.c +6
-0+ +static inline void +io_write64_twopart (uint64_t val,uint32_t *lo,uint32_t *hi) +{ +io_write32 ((uint32_t )val, lo); +io_write32 (val >>32 , hi);Firstly your second iowrite32 doesn't do the conversion.
Quoted 5 lines
Quoted 2 lines
Because it's not necessary. The first one is for retrieving the low 32 bits.
I don't mean the shift operation, but the conversion from 64bit to 32bit. Same applied to below.
It's more than a casting here: it's same as "val & (1<<32 - 1)", as stated above, to retrieve the low 32 bits.
I know it still could work without it, but, hey, what's wrong to make it explicit?
--yliu
Re: [PATCH v4 7/8] virtio: add 1.0 support
Quoted 18 lines · Yuanhan Liu
Quoted 17 lines · Huawei
Quoted 16 lines · Yuanhan Liu
Quoted 5 lines · Huawei
Quoted 4 lines · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
Quoted 8 lines
[snip]
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 480
Quoted 6 lines
drivers/net/virtio/virtio_pci.c +6
-0+ +static inline void +io_write64_twopart (uint64_t val,uint32_t *lo,uint32_t *hi) +{ +io_write32 ((uint32_t )val, lo); +io_write32 (val >>32 , hi);Firstly your second iowrite32 doesn't do the conversion.
Because it's not necessary. The first one is for retrieving the low 32 bits.
Quoted 7 lines
Quoted 2 lines
I don't mean the shift operation, but the conversion from 64bit to 32bit. Same applied to below.
It's more than a casting here: it's same as "val & (1<<32 - 1)", as stated above, to retrieve the low 32 bits.
I know it still could work without it, but, hey, what's wrong to make it explicit?
Say x = val, y = val >> 32, both with (uint32_t) or both not. Be consistent and simple.
Quoted 3 lines
--yliu
Re: [PATCH v4 7/8] virtio: add 1.0 support
Quoted 21 lines · Huawei
Quoted 20 lines · Yuanhan Liu
Quoted 19 lines · Huawei
Quoted 14 lines · Yuanhan Liu
Quoted 5 lines · Huawei
Quoted 4 lines · Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
Quoted 8 lines
[snip]
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 480
Quoted 6 lines
drivers/net/virtio/virtio_pci.c +6
-0+ +static inline void +io_write64_twopart (uint64_t val,uint32_t *lo,uint32_t *hi) +{ +io_write32 ((uint32_t )val, lo); +io_write32 (val >>32 , hi);Firstly your second iowrite32 doesn't do the conversion.
Quoted 2 lines
Because it's not necessary. The first one is for retrieving the low 32 bits.
I don't mean the shift operation, but the conversion from 64bit to 32bit. Same applied to below.
Quoted 8 lines
Quoted 5 lines
It's more than a casting here: it's same as "val & (1<<32 - 1)", as stated above, to retrieve the low 32 bits.
I know it still could work without it, but, hey, what's wrong to make it explicit?
Say x = val, y = val >> 32, both with (
uint32_t) or both not. Be consistent and simple.
fine.
--yliu
Re: [PATCH v4 7/8] virtio: add 1.0 support
In reply to Xie, HuaweiQuoted 11 lines · Huawei
drivers/net/virtio/virtio_ethdev.c virtio_negotiate_features(struct virtio_hw *hw) · line 949
Quoted 7 lines · Yuanhan Liu
drivers/net/virtio/virtio_ethdev.c +1
-1-static void +static int virtio_negotiate_features (struct virtio_hw *hw) {uint64_t host_features;@@ -949,6 +949,22 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features =vtpci_negotiate_features (hw, host_features);Here if we are not modern device, we should remove
VIRTIO_F_VERSION_1in guest features.
VIRTIO_F_VERSION_1 should not be set for legacy virtio device at all.
--yliu
Re: [PATCH v4 7/8] virtio: add 1.0 support
Quoted 11 lines · Yuanhan Liu
Quoted 10 lines · Huawei
drivers/net/virtio/virtio_ethdev.c virtio_negotiate_features(struct virtio_hw *hw) · line 949
Quoted 7 lines · Yuanhan Liu
drivers/net/virtio/virtio_ethdev.c +1
-1-static void +static int virtio_negotiate_features (struct virtio_hw *hw) {uint64_t host_features;@@ -949,6 +949,22 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features =vtpci_negotiate_features (hw, host_features);Here if we are not modern device, we should remove
VIRTIO_F_VERSION_1in guest features.
Quoted 1 line
VIRTIO_F_VERSION_1should not be set for legacy virtio device at all.
Yes, but here this patch sets this VIRTIO_F_VERSION_1 feature even for legacy virtio device.
It doesn't cause issues, but better remove it for legacy virtio device.
Quoted 3 lines
--yliu
Re: [PATCH v4 7/8] virtio: add 1.0 support
Quoted 12 lines · Huawei
Quoted 11 lines · Yuanhan Liu
Quoted 10 lines · Huawei
drivers/net/virtio/virtio_ethdev.c virtio_negotiate_features(struct virtio_hw *hw) · line 949
Quoted 7 lines · Yuanhan Liu
drivers/net/virtio/virtio_ethdev.c +1
-1-static void +static int virtio_negotiate_features (struct virtio_hw *hw) {uint64_t host_features;@@ -949,6 +949,22 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features =vtpci_negotiate_features (hw, host_features);Here if we are not modern device, we should remove
VIRTIO_F_VERSION_1in guest features.
Quoted 5 lines
Quoted 1 line
VIRTIO_F_VERSION_1should not be set for legacy virtio device at all.Yes, but here this patch sets this
VIRTIO_F_VERSION_1feature even for legacy virtio device.
It doesn't cause issues, but better remove it for legacy virtio device.
It's not set for legacy virtio device (at hw->guest_features), how could you remove it then???
--yliu
Re: [PATCH v4 7/8] virtio: add 1.0 support
In reply to Xie, HuaweiQuoted 12 lines · Huawei
Quoted 11 lines · Yuanhan Liu
Quoted 10 lines · Huawei
drivers/net/virtio/virtio_ethdev.c virtio_negotiate_features(struct virtio_hw *hw) · line 949
Quoted 7 lines · Yuanhan Liu
drivers/net/virtio/virtio_ethdev.c +1
-1-static void +static int virtio_negotiate_features (struct virtio_hw *hw) {uint64_t host_features;@@ -949,6 +949,22 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features =vtpci_negotiate_features (hw, host_features);Here if we are not modern device, we should remove
VIRTIO_F_VERSION_1in guest features.
Quoted 4 lines
Quoted 1 line
VIRTIO_F_VERSION_1should not be set for legacy virtio device at all.Yes, but here this patch sets this
VIRTIO_F_VERSION_1feature even for legacy virtio device.
It doesn't cause issues, but better remove it for legacy virtio device.
OK, I see the legacy_get_features return a 32bit value which masks the higher bits which contains the host VIRTIO_F_VERSION_1 feature. This is very implict.
Quoted 3 lines
Quoted 2 lines
--yliu
v5 cover virtio 1.0 enabling for virtio pmd driver
In reply to Yuanhan Liuv5: minor fixes:
- fix wrong type of arg "offset" of read/write_dev_config(): patch 2 is newly added for that.
- check "offset + length" overflow
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 8.
To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a virtio_pci_ops structure, to add another layer so that we could keep those vtpci_foo_bar "APIs". With that, we could do the minimum change to add virtio 1.0 support.
Rough test guide
================
Firstly, you need get a virtio 1.0 supported QEMU (say, v2.5), then add option "disable-modern=false" to qemu virtio-net-pci device to enable virtio 1.0 (which is disabled by default).
And if you see something like following from 'lspci -v', it means virtio 1.0 is indeed enabled:
00:04.0 Ethernet controller: Red Hat, Inc Virtio network device
Subsystem: Red Hat, Inc Device 0001
Physical Slot: 4
Flags: bus master, fast devsel, latency 0, IRQ 11 I/O ports at c040 [size=64]
Memory at febf1000 (32-bit, non-prefetchable) [size=4K] Memory at fe000000 (64-bit, prefetchable) [size=8M] Expansion ROM at feb80000 [disabled] [size=256K]
Capabilities: [98] MSI-X: Enable+ Count=6 Masked-
==> Capabilities: [84] Vendor Specific Information: Len=14 <?> ==> Capabilities: [70] Vendor Specific Information: Len=14 <?> ==> Capabilities: [60] Vendor Specific Information: Len=10 <?> ==> Capabilities: [50] Vendor Specific Information: Len=10 <?> ==> Capabilities: [40] Vendor Specific Information: Len=10 <?>
Kernel driver in use: virtio-pci
Kernel modules: virtio_pci
After that, there wasn't anything speical comparing to the old virtio 0.95 pmd driver.
---
Yuanhan Liu (9):
virtio: don't set vring address again at queue startup
virtio: define offset as size_t type
virtio: introduce struct virtio_pci_ops
virtio: move left pci stuff to virtio_pci.c
viritio: switch to 64 bit features
virtio: retrieve hdr_size from hw->vtnet_hdr_size
eal: pci: export pci_[un]map_device
virtio: add 1.0 support
virtio: move VIRTIO_READ/WRITE_REG_X into virtio_pci.c
doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 302 +-------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 799 +++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 124 +++- drivers/net/virtio/virtio_rxtx.c | 21 +- drivers/net/virtio/virtio_rxtx_simple.c | 12 +- drivers/net/virtio/virtqueue.h | 4 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 +- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 7 + lib/librte_eal/common/eal_common_pci.c | 4 +- lib/librte_eal/common/eal_private.h | 18 - lib/librte_eal/common/include/rte_pci.h | 27 + lib/librte_eal/linuxapp/eal/eal_pci.c | 4 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 7 + 15 files changed, 957 insertions(+), 382 deletions(-)
Signature · 1 line
1.9.0
PATCH v5 1/9 virtio: don't set vring address again at queue startup
As we have already set up it at virtio_dev_queue_setup(), and a vq restart will not reset the settings.
--- drivers/net/virtio/virtio_rxtx.c | 15 --------------- 1 file changed, 15 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -15
@@ -339,11 +339,6 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)vq_update_avail_idx (vq);PMD_INIT_LOG (DEBUG ,"Allocated %d bufs" , nbufs); - -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); }else if (queue_type ==VTNET_TQ ) {if (use_simple_rxtx) {int mid_idx = vq->vq_nentries >>1 ;
@@ -362,16 +357,6 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)for (i = mid_idx; i < vq->vq_nentries; i++) vq->vq_ring.avail->ring[i] = i; } - -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); - }else { -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); } }
Signature · 1 line
1.9.0
PATCH v5 2/9 virtio: define offset as size_t type
In reply to Yuanhan Liuoffset arg of vtpci_read/write_dev_config is derived from offsetof(), which is of size_t type, instead of uint64_t. So, define it as size_t type.
--- drivers/net/virtio/virtio_pci.c | 4 ++-- drivers/net/virtio/virtio_pci.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/virtio/virtio_pci.c +2 -2
@@ -38,7 +38,7 @@static uint8_t vtpci_get_status (struct virtio_hw *);void -vtpci_read_dev_config (struct virtio_hw *hw,uint64_t offset, +vtpci_read_dev_config (struct virtio_hw *hw,size_t offset,void *dst,int length) {uint64_t off;
@@ -61,7 +61,7 @@ vtpci_read_dev_config(struct virtio_hw *hw, uint64_t offset, }void -vtpci_write_dev_config (struct virtio_hw *hw,uint64_t offset, +vtpci_write_dev_config (struct virtio_hw *hw,size_t offset,void *src,int length) {uint64_t off;
drivers/net/virtio/virtio_pci.h +2 -2
@@ -261,9 +261,9 @@ void vtpci_set_status(struct virtio_hw *, uint8_t);uint32_t vtpci_negotiate_features (struct virtio_hw *,uint32_t ); -void vtpci_write_dev_config (struct virtio_hw *,uint64_t ,void *,int ); +void vtpci_write_dev_config (struct virtio_hw *,size_t ,void *,int ); -void vtpci_read_dev_config (struct virtio_hw *,uint64_t ,void *,int ); +void vtpci_read_dev_config (struct virtio_hw *,size_t ,void *,int );uint8_t vtpci_isr (struct virtio_hw *);
Signature · 1 line
1.9.0
PATCH v5 3/9 virtio: introduce struct virtio_pci_ops
In reply to Yuanhan LiuIntroduce struct virtio_pci_ops, to let legacy virtio (v0.95) and modern virtio (1.0) have different implementation regarding to a specific pci action, such as read host status.
With that, this patch reimplements all exported pci functions, in a way like:
vtpci_foo_bar(struct virtio_hw *hw)
{
hw->vtpci_ops->foo_bar(hw);
}So that we need pay attention to those pci related functions only while adding virtio 1.0 support.
This patch introduced a new vtpci function, vtpci_init(), to do proper virtio pci settings. It's pretty simple so far: just sets hw->vtpci_ops to legacy_ops as we don't support 1.0 yet.
---
v5: - define "src" arg of vtpci_write_dev_config()
--- drivers/net/virtio/virtio_ethdev.c | 22 ++--- drivers/net/virtio/virtio_pci.c | 164 ++++++++++++++++++++++++++++++------- drivers/net/virtio/virtio_pci.h | 29 ++++++- drivers/net/virtio/virtqueue.h | 2 +- 4 files changed, 170 insertions(+), 47 deletions(-)
drivers/net/virtio/virtio_ethdev.c +8 -14
@@ -272,9 +272,7 @@ virtio_dev_queue_release(struct virtqueue *vq) {if (vq) { hw = vq->hw; -/* Select and deactivate the queue */ -VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN ,0 ); + hw->vtpci_ops->del_queue (hw, vq);rte_free (vq->sw_ring);rte_free (vq);
@@ -295,15 +293,13 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,struct virtio_hw *hw = dev->data->dev_private;struct virtqueue *vq =NULL ; -/* Write the virtqueue index to the Queue Select Field */ -VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vtpci_queue_idx); -PMD_INIT_LOG (DEBUG ,"selecting queue: %u" , vtpci_queue_idx); +PMD_INIT_LOG (DEBUG ,"setting up queue: %u" , vtpci_queue_idx);/* * Read the virtqueue size from the Queue Size field * Always power of 2 and if 0 virtqueue does not exist */ - vq_size =VIRTIO_READ_REG_2 (hw,VIRTIO_PCI_QUEUE_NUM ); + vq_size = hw->vtpci_ops->get_queue_num (hw, vtpci_queue_idx);PMD_INIT_LOG (DEBUG ,"vq_size: %u nb_desc:%u" , vq_size, nb_desc);if (vq_size ==0 ) {PMD_INIT_LOG (ERR ,"%s: virtqueue does not exist" , __func__);
@@ -436,12 +432,8 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,memset (vq->virtio_net_hdr_mz->addr,0 ,PAGE_SIZE ); } -/* -* Set guest physical address of the virtqueue -* in VIRTIO_PCI_QUEUE_PFN config register of device -*/ -VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN , - mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); + hw->vtpci_ops->setup_queue (hw, vq); + *pvq = vq;return 0 ; }
@@ -950,7 +942,7 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features);/* Read device(host) feature bits */ - host_features =VIRTIO_READ_REG_4 (hw,VIRTIO_PCI_HOST_FEATURES ); + host_features = hw->vtpci_ops->get_features (hw);PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %x" , host_features);
@@ -1287,6 +1279,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; +vtpci_init (pci_dev, hw); +if (virtio_resource_init (pci_dev) <0 )return -1 ;
drivers/net/virtio/virtio_pci.c +133 -31
229 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +28 -1
@@ -163,6 +163,31 @@ struct virtqueue;*/ #define VIRTIO_MAX_VIRTQUEUES 8 +struct virtio_hw ; + +struct virtio_pci_ops { +void (*read_dev_cfg)(struct virtio_hw *hw,size_t offset, +void *dst,int len); +void (*write_dev_cfg)(struct virtio_hw *hw,size_t offset, +const void *src,int len); +void (*reset)(struct virtio_hw *hw); + +uint8_t (*get_status)(struct virtio_hw *hw); +void (*set_status)(struct virtio_hw *hw,uint8_t status); + +uint32_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint32_t features); + +uint8_t (*get_isr)(struct virtio_hw *hw); + +uint16_t (*set_config_irq)(struct virtio_hw *hw,uint16_t vec); + +uint16_t (*get_queue_num)(struct virtio_hw *hw,uint16_t queue_id); +void (*setup_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*del_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*notify_queue)(struct virtio_hw *hw,struct virtqueue *vq); +}; +struct virtio_hw {struct virtqueue *cvq;uint32_t io_base;
@@ -174,6 +199,7 @@ struct virtio_hw {uint8_t use_msix;uint8_t started;uint8_t mac_addr[ETHER_ADDR_LEN ]; +const struct virtio_pci_ops *vtpci_ops; };/*
@@ -253,6 +279,7 @@ vtpci_with_feature(struct virtio_hw *hw, uint32_t bit)/* * Function declaration from virtio_pci.c */ +int vtpci_init (struct rte_pci_device *,struct virtio_hw *);void vtpci_reset (struct virtio_hw *);void vtpci_reinit_complete (struct virtio_hw *);
@@ -261,7 +288,7 @@ void vtpci_set_status(struct virtio_hw *, uint8_t);uint32_t vtpci_negotiate_features (struct virtio_hw *,uint32_t ); -void vtpci_write_dev_config (struct virtio_hw *,size_t ,void *,int ); +void vtpci_write_dev_config (struct virtio_hw *,size_t ,const void *,int );void vtpci_read_dev_config (struct virtio_hw *,size_t ,void *,int );
drivers/net/virtio/virtqueue.h +1 -1
@@ -302,7 +302,7 @@ virtqueue_notify(struct virtqueue *vq)* For virtio on IA, the notificaiton is through io port operation * which is a serialization instruction itself. */ -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_NOTIFY , vq->vq_queue_index); + vq->hw->vtpci_ops->notify_queue (vq->hw, vq); }#ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP
Signature · 1 line
1.9.0
PATCH v5 4/9 virtio: move left pci stuff to virtio_pci.c
In reply to Yuanhan Liuvirtio_pci.c is a more proper place for pci stuff; virtio_ethdev is not.
--- drivers/net/virtio/virtio_ethdev.c | 265 +----------------------------------- drivers/net/virtio/virtio_pci.c | 270 ++++++++++++++++++++++++++++++++++++- 2 files changed, 270 insertions(+), 265 deletions(-)
drivers/net/virtio/virtio_ethdev.c +1 -264
@@ -36,10 +36,6 @@#include <stdio.h> #include <errno.h> #include <unistd.h> -#ifdef RTE_EXEC_ENV_LINUXAPP -#include <dirent.h> -#include <fcntl.h> -#endif #include <rte_ethdev.h> #include <rte_memcpy.h>
@@ -955,260 +951,6 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features); } -#ifdef RTE_EXEC_ENV_LINUXAPP -static int -parse_sysfs_value (const char *filename,unsigned long *val) -{ -FILE *f; -char buf[BUFSIZ ]; -char *end =NULL ; - - f =fopen (filename,"r" ); -if (f ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): cannot open sysfs value %s" , - __func__, filename); -return -1 ; - } - -if (fgets (buf,sizeof (buf), f) ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): cannot read sysfs value %s" , - __func__, filename); -fclose (f); -return -1 ; - } - *val =strtoul (buf, &end,0 ); -if ((buf[0 ] =='\0' ) || (end ==NULL ) || (*end !='\n' )) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse sysfs value %s" , - __func__, filename); -fclose (f); -return -1 ; - } -fclose (f); -return 0 ; -} - -static int get_uio_dev (struct rte_pci_addr *loc,char *buf,unsigned int buflen, -unsigned int *uio_num) -{ -struct dirent *e; -DIR *dir; -char dirname[PATH_MAX ]; - -/* depending on kernel version, uio can be located in uio/uioX -* or uio:uioX */ -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio" , - loc->domain, loc->bus, loc->devid, loc->function); - dir =opendir (dirname); -if (dir ==NULL ) { -/* retry with the parent directory */ -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT , - loc->domain, loc->bus, loc->devid, loc->function); - dir =opendir (dirname); - -if (dir ==NULL ) { -PMD_INIT_LOG (ERR ,"Cannot opendir %s" , dirname); -return -1 ; - } - } - -/* take the first file starting with "uio" */ -while ((e =readdir (dir)) !=NULL ) { -/* format could be uio%d ...*/ -int shortprefix_len =sizeof ("uio" ) -1 ; -/* ... or uio:uio%d */ -int longprefix_len =sizeof ("uio:uio" ) -1 ; -char *endptr; - -if (strncmp (e->d_name,"uio" ,3 ) !=0 ) -continue ; - -/* first try uio%d */ - errno =0 ; - *uio_num =strtoull (e->d_name + shortprefix_len, &endptr,10 ); -if (errno ==0 && endptr != (e->d_name + shortprefix_len)) { -snprintf (buf, buflen,"%s/uio%u" , dirname, *uio_num); -break ; - } - -/* then try uio:uio%d */ - errno =0 ; - *uio_num =strtoull (e->d_name + longprefix_len, &endptr,10 ); -if (errno ==0 && endptr != (e->d_name + longprefix_len)) { -snprintf (buf, buflen,"%s/uio:uio%u" , dirname, - *uio_num); -break ; - } - } -closedir (dir); - -/* No uio resource found */ -if (e ==NULL ) { -PMD_INIT_LOG (ERR ,"Could not find uio resource" ); -return -1 ; - } - -return 0 ; -} - -static int -virtio_has_msix (const struct rte_pci_addr *loc) -{ -DIR *d; -char dirname[PATH_MAX ]; - -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/msi_irqs" , - loc->domain, loc->bus, loc->devid, loc->function); - - d =opendir (dirname); -if (d) -closedir (d); - -return (d !=NULL ); -} - -/* Extract I/O port numbers from sysfs */ -static int virtio_resource_init_by_uio (struct rte_pci_device *pci_dev) -{ -char dirname[PATH_MAX ]; -char filename[PATH_MAX ]; -unsigned long start, size; -unsigned int uio_num; - -if (get_uio_dev (&pci_dev->addr, dirname,sizeof (dirname), &uio_num) <0 ) -return -1 ; - -/* get portio size */ -snprintf (filename,sizeof (filename), -"%s/portio/port0/size" , dirname); -if (parse_sysfs_value (filename, &size) <0 ) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse size" , - __func__); -return -1 ; - } - -/* get portio start */ -snprintf (filename,sizeof (filename), -"%s/portio/port0/start" , dirname); -if (parse_sysfs_value (filename, &start) <0 ) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse portio start" , - __func__); -return -1 ; - } - pci_dev->mem_resource[0 ].addr = (void *)(uintptr_t )start; - pci_dev->mem_resource[0 ].len = (uint64_t )size; -PMD_INIT_LOG (DEBUG , -"PCI Port IO found start=0x%lx with size=0x%lx" , - start, size); - -/* save fd */ -memset (dirname,0 ,sizeof (dirname)); -snprintf (dirname,sizeof (dirname),"/dev/uio%u" , uio_num); - pci_dev->intr_handle.fd =open (dirname,O_RDWR ); -if (pci_dev->intr_handle.fd <0 ) { -PMD_INIT_LOG (ERR ,"Cannot open %s: %s\n" , - dirname,strerror (errno)); -return -1 ; - } - - pci_dev->intr_handle.type =RTE_INTR_HANDLE_UIO ; - pci_dev->driver->drv_flags |=RTE_PCI_DRV_INTR_LSC ; - -return 0 ; -} - -/* Extract port I/O numbers from proc/ioports */ -static int virtio_resource_init_by_ioports (struct rte_pci_device *pci_dev) -{ -uint16_t start, end; -int size; -FILE *fp; -char *line =NULL ; -char pci_id[16 ]; -int found =0 ; -size_t linesz; - -snprintf (pci_id,sizeof (pci_id),PCI_PRI_FMT , - pci_dev->addr.domain, - pci_dev->addr.bus, - pci_dev->addr.devid, - pci_dev->addr.function); - - fp =fopen ("/proc/ioports" ,"r" ); -if (fp ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): can't open ioports" , __func__); -return -1 ; - } - -while (getdelim (&line, &linesz,'\n' , fp) >0 ) { -char *ptr = line; -char *left; -int n; - - n =strcspn (ptr,":" ); - ptr[n] =0 ; - left = &ptr[n+1 ]; - -while (*left &&isspace (*left)) - left++; - -if (!strncmp (left, pci_id,strlen (pci_id))) { - found =1 ; - -while (*ptr &&isspace (*ptr)) - ptr++; - -sscanf (ptr,"%04hx-%04hx" , &start, &end); - size = end - start +1 ; - -break ; - } - } - -free (line); -fclose (fp); - -if (!found) -return -1 ; - - pci_dev->mem_resource[0 ].addr = (void *)(uintptr_t )(uint32_t )start; - pci_dev->mem_resource[0 ].len = (uint64_t )size; -PMD_INIT_LOG (DEBUG , -"PCI Port IO found start=0x%x with size=0x%x" , - start, size); - -/* can't support lsc interrupt without uio */ - pci_dev->driver->drv_flags &= ~RTE_PCI_DRV_INTR_LSC ; - -return 0 ; -} - -/* Extract I/O port numbers from sysfs */ -static int virtio_resource_init (struct rte_pci_device *pci_dev) -{ -if (virtio_resource_init_by_uio (pci_dev) ==0 ) -return 0 ; -else -return virtio_resource_init_by_ioports (pci_dev); -} - -#else -static int -virtio_has_msix(const struct rte_pci_addr *loc __rte_unused) -{ -/* nic_uio does not enable interrupts, return 0 (false). */ -return 0 ; -} - -static int virtio_resource_init(struct rte_pci_device *pci_dev __rte_unused) -{ -/* no setup required */ -return 0 ; -} -#endif -/* * Process Virtio Config changed interrupt and call the callback * if link state changed.
@@ -1279,14 +1021,9 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; -vtpci_init (pci_dev, hw); - -if (virtio_resource_init (pci_dev) <0 ) +if (vtpci_init (pci_dev, hw) <0 )return -1 ; - hw->use_msix =virtio_has_msix (&pci_dev->addr); - hw->io_base = (uint32_t )(uintptr_t )pci_dev->mem_resource[0 ].addr; -/* Reset the device although not necessary at startup */ vtpci_reset (hw);
drivers/net/virtio/virtio_pci.c +269 -1
290 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH v5 5/9 viritio: switch to 64 bit features
In reply to Yuanhan LiuSwitch to 64 bit features, which virtio 1.0 supports.
While legacy virtio only supports 32 bit features, it complains aloud and quit when trying to setting > 32 bit features.
--- drivers/net/virtio/virtio_ethdev.c | 8 ++++---- drivers/net/virtio/virtio_pci.c | 15 ++++++++++----- drivers/net/virtio/virtio_pci.h | 12 ++++++------ 3 files changed, 20 insertions(+), 15 deletions(-)
drivers/net/virtio/virtio_ethdev.c +4 -4
@@ -930,16 +930,16 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)static void virtio_negotiate_features (struct virtio_hw *hw) { -uint32_t host_features; +uint64_t host_features;/* Prepare guest_features: feature that driver wants to support */ hw->guest_features =VIRTIO_PMD_GUEST_FEATURES ; -PMD_INIT_LOG (DEBUG ,"guest_features before negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"guest_features before negotiate = %" PRIx64, hw->guest_features);/* Read device(host) feature bits */ host_features = hw->vtpci_ops->get_features (hw); -PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %" PRIx64, host_features);/*
@@ -947,7 +947,7 @@ virtio_negotiate_features(struct virtio_hw *hw)* guest feature bits. */ hw->guest_features =vtpci_negotiate_features (hw, host_features); -PMD_INIT_LOG (DEBUG ,"features after negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); }
drivers/net/virtio/virtio_pci.c +10 -5
@@ -87,15 +87,20 @@ legacy_write_dev_config(struct virtio_hw *hw, size_t offset, } } -static uint32_t +static uint64_t legacy_get_features (struct virtio_hw *hw) {return VIRTIO_READ_REG_4 (hw,VIRTIO_PCI_HOST_FEATURES ); }static void -legacy_set_features (struct virtio_hw *hw,uint32_t features) +legacy_set_features (struct virtio_hw *hw,uint64_t features) { +if ((features >>32 ) !=0 ) { +PMD_DRV_LOG (ERR , +"only 32 bit features are allowed for legacy virtio!" ); +return ; + }VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_GUEST_FEATURES , features); }
@@ -451,10 +456,10 @@ vtpci_write_dev_config(struct virtio_hw *hw, size_t offset, hw->vtpci_ops->write_dev_cfg (hw, offset, src, length); } -uint32_t -vtpci_negotiate_features (struct virtio_hw *hw,uint32_t host_features) +uint64_t +vtpci_negotiate_features (struct virtio_hw *hw,uint64_t host_features) { -uint32_t features; +uint64_t features;/* * Limit negotiated features to what the driver, virtqueue, and
drivers/net/virtio/virtio_pci.h +6 -6
@@ -175,8 +175,8 @@ struct virtio_pci_ops {uint8_t (*get_status)(struct virtio_hw *hw);void (*set_status)(struct virtio_hw *hw,uint8_t status); -uint32_t (*get_features)(struct virtio_hw *hw); -void (*set_features)(struct virtio_hw *hw,uint32_t features); +uint64_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint64_t features);uint8_t (*get_isr)(struct virtio_hw *hw);
@@ -191,7 +191,7 @@ struct virtio_pci_ops {struct virtio_hw {struct virtqueue *cvq;uint32_t io_base; -uint32_t guest_features; +uint64_t guest_features;uint32_t max_tx_queues;uint32_t max_rx_queues;uint16_t vtnet_hdr_size;
@@ -271,9 +271,9 @@ outl_p(unsigned int data, unsigned int port) outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg))))static inline int -vtpci_with_feature (struct virtio_hw *hw,uint32_t bit) +vtpci_with_feature (struct virtio_hw *hw,uint64_t bit) { -return (hw->guest_features & (1u << bit)) !=0 ; +return (hw->guest_features & (1ULL << bit)) !=0 ; }/*
@@ -286,7 +286,7 @@ void vtpci_reinit_complete(struct virtio_hw *);void vtpci_set_status (struct virtio_hw *,uint8_t ); -uint32_t vtpci_negotiate_features (struct virtio_hw *,uint32_t ); +uint64_t vtpci_negotiate_features (struct virtio_hw *,uint64_t );void vtpci_write_dev_config (struct virtio_hw *,size_t ,const void *,int );
Signature · 1 line
1.9.0
PATCH v5 6/9 virtio: retrieve hdr_size from hw->vtnet_hdr_size
In reply to Yuanhan LiuThe mergeable virtio net hdr format has been the standard and the only virtio net hdr format since virtio 1.0. Therefore, we can not hardcode hdr_size to "sizeof(struct virtio_net_hdr)" any more at virtio_recv_pkts(), otherwise, there would be a mismatch of hdr size from rte_vhost_enqueue_burst() and virtio_recv_pkts(), leading a packet corruption.
Instead, we should retrieve it from hw->vtnet_hdr_size; we will do proper settings at eth_virtio_dev_init() in later patches.
---
--- drivers/net/virtio/virtio_rxtx.c | 6 ++++-- drivers/net/virtio/virtio_rxtx_simple.c | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/net/virtio/virtio_rxtx.c +4 -2
@@ -560,7 +560,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)struct rte_mbuf *rcv_pkts[VIRTIO_MBUF_BURST_SZ ];int error;uint32_t i, nb_enqueued; -const uint32_t hdr_size =sizeof (struct virtio_net_hdr ); +uint32_t hdr_size; nb_used =VIRTQUEUE_NUSED (rxvq);
@@ -580,6 +580,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) hw = rxvq->hw; nb_rx =0 ; nb_enqueued =0 ; + hdr_size = hw->vtnet_hdr_size;for (i =0 ; i < num ; i++) { rxm = rcv_pkts[i];
@@ -664,7 +665,7 @@ virtio_recv_mergeable_pkts(void *rx_queue,uint32_t seg_num;uint16_t extra_idx;uint32_t seg_res; -const uint32_t hdr_size =sizeof (struct virtio_net_hdr_mrg_rxbuf ); +uint32_t hdr_size; nb_used =VIRTQUEUE_NUSED (rxvq);
@@ -682,6 +683,7 @@ virtio_recv_mergeable_pkts(void *rx_queue, seg_num =0 ; extra_idx =0 ; seg_res =0 ; + hdr_size = hw->vtnet_hdr_size;while (i < nb_used) {struct virtio_net_hdr_mrg_rxbuf *header;
drivers/net/virtio/virtio_rxtx_simple.c +6 -6
@@ -81,9 +81,9 @@ virtqueue_enqueue_recv_refill_simple(struct virtqueue *vq, start_dp = vq->vq_ring.desc; start_dp[desc_idx].addr = (uint64_t )((uintptr_t )cookie->buf_physaddr + -RTE_PKTMBUF_HEADROOM -sizeof (struct virtio_net_hdr )); +RTE_PKTMBUF_HEADROOM - vq->hw->vtnet_hdr_size); start_dp[desc_idx].len = cookie->buf_len - -RTE_PKTMBUF_HEADROOM +sizeof (struct virtio_net_hdr ); +RTE_PKTMBUF_HEADROOM + vq->hw->vtnet_hdr_size; vq->vq_free_cnt--; vq->vq_avail_idx++;
@@ -120,9 +120,9 @@ virtio_rxq_rearm_vec(struct virtqueue *rxvq) start_dp[i].addr = (uint64_t )((uintptr_t )sw_ring[i]->buf_physaddr + -RTE_PKTMBUF_HEADROOM -sizeof (struct virtio_net_hdr )); +RTE_PKTMBUF_HEADROOM - rxvq->hw->vtnet_hdr_size); start_dp[i].len = sw_ring[i]->buf_len - -RTE_PKTMBUF_HEADROOM +sizeof (struct virtio_net_hdr ); +RTE_PKTMBUF_HEADROOM + rxvq->hw->vtnet_hdr_size; } rxvq->vq_avail_idx +=RTE_VIRTIO_VPMD_RX_REARM_THRESH ;
@@ -175,8 +175,8 @@ virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts, len_adjust =_mm_set_epi16 (0 ,0 ,0 , - (uint16_t ) -sizeof (struct virtio_net_hdr ), -0 , (uint16_t ) -sizeof (struct virtio_net_hdr ), + (uint16_t ) -rxvq->hw->vtnet_hdr_size, +0 , (uint16_t ) -rxvq->hw->vtnet_hdr_size,0 ,0 );if (unlikely (nb_pkts <RTE_VIRTIO_DESC_PER_LOOP ))
Signature · 1 line
1.9.0
PATCH v5 7/9 eal: pci: export pci_[un]map_device
In reply to Yuanhan LiuNormally we could set RTE_PCI_DRV_NEED_MAPPING flag so that eal will invoke pci_map_device internally for us. From that point view, there is no need to export pci_map_device.
However, for virtio pmd driver, which is designed to work without binding UIO (or something similar first), pci_map_device() will fail, which ends up with virtio pmd driver being skipped. Therefore, we can not set RTE_PCI_DRV_NEED_MAPPING blindly at virtio pmd driver.
Therefore, this patch exports pci_map_device, and let virtio pmd call it when necessary.
--- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 ++-- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 7 +++++++ lib/librte_eal/common/eal_common_pci.c | 4 ++-- lib/librte_eal/common/eal_private.h | 18 ----------------- lib/librte_eal/common/include/rte_pci.h | 27 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 4 ++-- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 7 +++++++ 7 files changed, 47 insertions(+), 24 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -2
@@ -93,7 +93,7 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)/* Map pci device */ int -pci_map_device (struct rte_pci_device *dev) +rte_eal_pci_map_device (struct rte_pci_device *dev) {int ret =-1 ;
@@ -115,7 +115,7 @@ pci_map_device(struct rte_pci_device *dev)/* Unmap pci device */ void -pci_unmap_device (struct rte_pci_device *dev) +rte_eal_pci_unmap_device (struct rte_pci_device *dev) {/* try unmapping the NIC resources */ switch (dev->kdrv) {
lib/librte_eal/bsdapp/eal/rte_eal_version.map +7 -0
@@ -135,3 +135,10 @@ DPDK_2.2 { rte_xen_dom0_supported; } DPDK_2.1; + +DPDK_2.3 { + global: + + rte_eal_pci_map_device; + rte_eal_pci_unmap_device; +} DPDK_2.2;
lib/librte_eal/common/eal_common_pci.c +2 -2
@@ -188,7 +188,7 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dpci_config_space_set (dev);#endif /* map resources for devices that use igb_uio */ - ret =pci_map_device (dev); + ret =rte_eal_pci_map_device (dev);if (ret !=0 )return ret; } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
@@ -254,7 +254,7 @@ rte_eal_pci_detach_dev(struct rte_pci_driver *dr,if (dr->drv_flags &RTE_PCI_DRV_NEED_MAPPING )/* unmap resources for devices that use igb_uio */ -pci_unmap_device (dev); +rte_eal_pci_unmap_device (dev);return 0 ; }
lib/librte_eal/common/eal_private.h +0 -18
@@ -165,24 +165,6 @@ struct rte_pci_device;int pci_unbind_kernel_driver (struct rte_pci_device *dev);/** -* Map this device -* -* This function is private to EAL. -* -* @return -* 0 on success, negative on error and positive if no driver -* is found for the device. -*/ -int pci_map_device (struct rte_pci_device *dev); - -/** -* Unmap this device -* -* This function is private to EAL. -*/ -void pci_unmap_device (struct rte_pci_device *dev); - -/** * Map the PCI resource of a PCI device in virtual memory * * This function is private to EAL.
lib/librte_eal/common/include/rte_pci.h +27 -0
@@ -485,6 +485,33 @@ int rte_eal_pci_read_config(const struct rte_pci_device *device,*/ int rte_eal_pci_write_config (const struct rte_pci_device *device,const void *buf,size_t len,off_t offset); +/** +* Map the PCI device resources in user space virtual memory address +* +* Note that driver should not call this function when flag +* RTE_PCI_DRV_NEED_MAPPING is set, as EAL will do that for +* you when it's on. +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +* +* @return +* 0 on success, negative on error and positive if no driver +* is found for the device. +*/ +int rte_eal_pci_map_device (struct rte_pci_device *dev); + +/** +* Unmap this device +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +*/ +void rte_eal_pci_unmap_device (struct rte_pci_device *dev); + +#ifdef RTE_PCI_CONFIG /**
lib/librte_eal/linuxapp/eal/eal_pci.c +2 -2
@@ -124,7 +124,7 @@ pci_get_kernel_driver_by_path(const char *filename, char *dri_name)/* Map pci device */ int -pci_map_device (struct rte_pci_device *dev) +rte_eal_pci_map_device (struct rte_pci_device *dev) {int ret =-1 ;
@@ -153,7 +153,7 @@ pci_map_device(struct rte_pci_device *dev)/* Unmap pci device */ void -pci_unmap_device (struct rte_pci_device *dev) +rte_eal_pci_unmap_device (struct rte_pci_device *dev) {/* try unmapping the NIC resources using VFIO if it exists */ switch (dev->kdrv) {
lib/librte_eal/linuxapp/eal/rte_eal_version.map +7 -0
@@ -138,3 +138,10 @@ DPDK_2.2 { rte_xen_dom0_supported; } DPDK_2.1; + +DPDK_2.3 { + global: + + rte_eal_pci_map_device; + rte_eal_pci_unmap_device; +} DPDK_2.2;
Signature · 1 line
1.9.0
PATCH v5 8/9 virtio: add 1.0 support
In reply to Yuanhan LiuModern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
Firstly, we map the pci resources by rte_eal_pci_map_device(). We then could easily locate a cfg structure by:
cfg_addr = dev->mem_resources[cap.bar].addr + cap.offset;
Therefore, the entrance of enabling modern (v1.0) pci device support is to iterate the pci capability lists, and to locate some configs we care; and they are:
- common cfg
For generic virtio and virtqueue configuration, such as setting/getting features, enabling a specific queue, and so on.
- nofity cfg
Combining with `queue_notify_off' from common cfg, we could use it to notify a specific virt queue.
- device cfg
Where virtio_net_config structure is located.
- isr cfg
Where to read isr (interrupt status).
If any of above cap is not found, we fallback to the legacy virtio handling.
If succeed, hw->vtpci_ops is assigned to modern_ops, where all operations are implemented by reading/writing a (or few) specific configuration space from above 4 cfg structures. And that's basically how this patch works.
Besides those changes, virtio 1.0 introduces a new status field:FEATURES_OK, which is set after features negotiation is done.
Last, set the VIRTIO_F_VERSION_1 feature flag.
---
v5: - rename MODERN_READ/WRITE_DEF macro name to IO_READ/WRITE_DEF
- check offset + length overflow
--- doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 25 ++- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 341 ++++++++++++++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 67 +++++++ drivers/net/virtio/virtqueue.h | 2 + 6 files changed, 436 insertions(+), 5 deletions(-)
doc/guides/rel_notes/release_2_3.rst +3 -0
@@ -4,6 +4,9 @@ DPDK Release 2.3 New Features ------------ +* **Virtio 1.0 support.** + + Enabled virtio 1.0 support for virtio pmd driver. Resolved Issues ---------------
drivers/net/virtio/virtio_ethdev.c +22 -3
@@ -927,7 +927,7 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)return virtio_send_command (hw->cvq, &ctrl, &len,1 ); } -static void +static int virtio_negotiate_features (struct virtio_hw *hw) {uint64_t host_features;
@@ -949,6 +949,22 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features =vtpci_negotiate_features (hw, host_features);PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); + +if (hw->modern) { +if (!vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) { +PMD_INIT_LOG (ERR , +"VIRTIO_F_VERSION_1 features is not enabled." ); +return -1 ; + } +vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_FEATURES_OK ); +if (!(vtpci_get_status (hw) &VIRTIO_CONFIG_STATUS_FEATURES_OK )) { +PMD_INIT_LOG (ERR , +"failed to set FEATURES_OK status!" ); +return -1 ; + } + } + +return 0 ; }/*
@@ -1032,7 +1048,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)/* Tell the host we've known how to drive the device. */ vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_DRIVER ); -virtio_negotiate_features (hw); +if (virtio_negotiate_features (hw) <0 ) +return -1 ;/* If host does not support status then disable LSC */ if (!vtpci_with_feature (hw,VIRTIO_NET_F_STATUS ))
@@ -1043,7 +1060,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)rx_func_get (eth_dev);/* Setting up rx_header size for the device */ -if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF ) || +vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) hw->vtnet_hdr_size =sizeof (struct virtio_net_hdr_mrg_rxbuf );else hw->vtnet_hdr_size =sizeof (struct virtio_net_hdr );
@@ -1159,6 +1177,7 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)rte_intr_callback_unregister (&pci_dev->intr_handle, virtio_interrupt_handler, eth_dev); +rte_eal_pci_unmap_device (pci_dev);PMD_INIT_LOG (DEBUG ,"dev_uninit completed" );
drivers/net/virtio/virtio_ethdev.h +2 -1
@@ -64,7 +64,8 @@1u <<VIRTIO_NET_F_CTRL_VQ | \1u <<VIRTIO_NET_F_CTRL_RX | \1u <<VIRTIO_NET_F_CTRL_VLAN | \ - 1u << VIRTIO_NET_F_MRG_RXBUF) +1u <<VIRTIO_NET_F_MRG_RXBUF | \ + 1ULL << VIRTIO_F_VERSION_1)/* * CQ function prototype
drivers/net/virtio/virtio_pci.c +340 -1
373 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +67 -0
104 lines not on this page · raw message
drivers/net/virtio/virtqueue.h +2 -0
@@ -202,6 +202,8 @@ struct virtqueue {/* Size bins in array as RFC 2819, undersized [0], 64 [1], etc */ uint64_t size_bins[8 ]; +uint16_t *notify_addr; +struct vq_desc_extra {void *cookie;uint16_t ndescs;
Signature · 1 line
1.9.0
PATCH v5 9/9 virtio: move VIRTIO_READ/WRITE_REG_X into virtio_pci.c
In reply to Yuanhan Liuvirtio_pci.c is the only file references those macros; move them there.
--- drivers/net/virtio/virtio_pci.c | 19 +++++++++++++++++++ drivers/net/virtio/virtio_pci.h | 18 ------------------ 2 files changed, 19 insertions(+), 18 deletions(-)
drivers/net/virtio/virtio_pci.c +19 -0
@@ -49,6 +49,25 @@#define PCI_CAPABILITY_LIST 0x34#define PCI_CAP_ID_VNDR 0x09 + +#define VIRTIO_PCI_REG_ADDR (hw, reg) \ + (unsigned short)((hw)->io_base + (reg)) + +#define VIRTIO_READ_REG_1 (hw, reg) \ + inb((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_1 (hw, reg, value) \ + outb_p((unsigned char)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) + +#define VIRTIO_READ_REG_2 (hw, reg) \ + inw((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_2 (hw, reg, value) \ + outw_p((unsigned short)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) + +#define VIRTIO_READ_REG_4 (hw, reg) \ + inl((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_4 (hw, reg, value) \ + outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) +static void legacy_read_dev_config (struct virtio_hw *hw,size_t offset,void *dst,int length)
drivers/net/virtio/virtio_pci.h +0 -18
@@ -318,24 +318,6 @@ outl_p(unsigned int data, unsigned int port) }#endif -#define VIRTIO_PCI_REG_ADDR (hw, reg) \ - (unsigned short)((hw)->io_base + (reg)) - -#define VIRTIO_READ_REG_1 (hw, reg) \ - inb((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_1 (hw, reg, value) \ - outb_p((unsigned char)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) - -#define VIRTIO_READ_REG_2 (hw, reg) \ - inw((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_2 (hw, reg, value) \ - outw_p((unsigned short)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) - -#define VIRTIO_READ_REG_4 (hw, reg) \ - inl((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_4 (hw, reg, value) \ - outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) -static inline int vtpci_with_feature (struct virtio_hw *hw,uint64_t bit) {
Signature · 1 line
1.9.0
Re: [PATCH v5 7/9] eal: pci: export pci_[un]map_device
In reply to Yuanhan LiuQuoted 12 lines · Yuanhan Liu
Normally we could set
RTE_PCI_DRV_NEED_MAPPINGflag so that eal will invokepci_map_deviceinternally for us. From that point view, there is no need to exportpci_map_device.However, for virtio pmd driver, which is designed to work without binding UIO (or something similar first),
pci_map_device()will fail, which ends up with virtio pmd driver being skipped. Therefore, we can not setRTE_PCI_DRV_NEED_MAPPINGblindly at virtio pmd driver.Therefore, this patch exports
pci_map_device, and let virtio pmd call it when necessary.
Quoted 6 lines
Cc David Marchand <[email protected]>Signed-off-by Yuanhan Liu <[email protected]>Tested-by Santosh Shukla <[email protected]>Tested-by Qian Xu <[email protected]>Reviewed-by Tetsuya Mukawa <[email protected]>Tested-by Tetsuya Mukawa <[email protected]>
lgtm
Signature · 1 line
David Marchand
Re: [PATCH v5 0/9] virtio 1.0 enabling for virtio pmd driver
In reply to Yuanhan LiuQuoted 62 lines · Yuanhan Liu
v5: minor fixes:
- fix wrong type of arg "offset" of read/write_dev_config(): patch 2 is newly added for that.
- check "offset + length" overflow
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 8.To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a
virtio_pci_opsstructure, to add another layer so that we could keep thosevtpci_foo_bar"APIs". With that, we could do the minimum change to add virtio 1.0 support.Rough test guide
================Firstly, you need get a virtio 1.0 supported QEMU (say, v2.5), then add option "disable-modern=false" to qemu virtio-net-pci device to enable virtio 1.0 (which is disabled by default).
And if you see something like following from 'lspci -v', it means virtio 1.0 is indeed enabled:
00:04.0 Ethernet controller: Red Hat, Inc Virtio network device
Subsystem: Red Hat, Inc Device 0001
Physical Slot: 4
Flags: bus master, fast devsel, latency 0, IRQ 11 I/O ports at c040 [size=64]
Memory atfebf1000(32-bit, non-prefetchable) [size=4K] Memory atfe000000(64-bit, prefetchable) [size=8M] Expansion ROM atfeb80000[disabled] [size=256K]
Capabilities: [98] MSI-X: Enable+ Count=6 Masked-
==> Capabilities: [84] Vendor Specific Information: Len=14 <?> ==> Capabilities: [70] Vendor Specific Information: Len=14 <?> ==> Capabilities: [60] Vendor Specific Information: Len=10 <?> ==> Capabilities: [50] Vendor Specific Information: Len=10 <?> ==> Capabilities: [40] Vendor Specific Information: Len=10 <?>
Kernel driver in use: virtio-pci
Kernel modules:virtio_pciAfter that, there wasn't anything speical comparing to the old virtio 0.95 pmd driver.
---
Yuanhan Liu (9):
virtio: don't set vring address again at queue startup
virtio: define offset assize_ttype
virtio: introduce structvirtio_pci_ops
virtio: move left pci stuff tovirtio_pci.c
viritio: switch to 64 bit features
virtio: retrievehdr_sizefromhw->vtnet_hdr_size
eal: pci: export pci_[un]map_device
virtio: add 1.0 support
virtio: move VIRTIO_READ/WRITE_REG_X intovirtio_pci.c
Quoted 17 lines
doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 302 +-------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 799 +++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 124 +++- drivers/net/virtio/virtio_rxtx.c | 21 +- drivers/net/virtio/virtio_rxtx_simple.c | 12 +- drivers/net/virtio/virtqueue.h | 4 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 +- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 7 + lib/librte_eal/common/eal_common_pci.c | 4 +- lib/librte_eal/common/eal_private.h | 18 - lib/librte_eal/common/include/rte_pci.h | 27 + lib/librte_eal/linuxapp/eal/eal_pci.c | 4 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 7 + 15 files changed, 957 insertions(+), 382 deletions(-)
Next time, please include all the changes made in the change notice.
Re: [PATCH v5 8/9] virtio: add 1.0 support
In reply to Yuanhan Liu2016-01-19 16:12, Yuanhan Liu:
Quoted 12 lines
drivers/net/virtio/virtio_pci.c +12
-0+#define IO_READ_DEF (nr_bits, type) \ +static inline type \ +io_read##nr_bits(type *addr) \ +{ \ + return *(volatile type *)addr; \ +} + +#define IO_WRITE_DEF (nr_bits, type) \ +static inline void \ +io_write##nr_bits(type val, type *addr) \ +{ \ + *(volatile type *)addr = val; \
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 474
Quoted 10 lines
drivers/net/virtio/virtio_pci.c +10
-0+} + +IO_READ_DEF (8, uint8_t) +IO_WRITE_DEF(8, uint8_t) + +IO_READ_DEF (16, uint16_t) +IO_WRITE_DEF(16, uint16_t) + +IO_READ_DEF (32, uint32_t) +IO_WRITE_DEF (32 , uint32_t)
Yes you can do this.
But not sure you should.
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 481
Quoted 6 lines
drivers/net/virtio/virtio_pci.c +6
-0+static inline void +io_write64_twopart (uint64_t val,uint32_t *lo,uint32_t *hi) +{ +io_write32 (val & ((1ULL <<32 ) -1 ), lo); +io_write32 (val >>32 , hi); +}
When debugging this code, how GDB behave?
How to find the definition of io_write32() with grep or simple editors?
Re: [PATCH v5 8/9] virtio: add 1.0 support
In reply to Yuanhan Liu2016-01-19 16:12, Yuanhan Liu:
Quoted 8 lines
int
vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw){drivers/net/virtio/virtio_pci.c +4
-1- hw->vtpci_ops = &legacy_ops; + hw->dev = dev; + +/* +* Try if we can succeed reading virtio pci caps, which exists
drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 849
Quoted 10 lines
drivers/net/virtio/virtio_pci.c +10
-0+* only on modern pci device. If failed, we fallback to legacy +* virtio handling. +*/ +if (virtio_read_caps (dev, hw) ==0 ) { +PMD_INIT_LOG (INFO ,"modern virtio pci detected." ); + hw->vtpci_ops = &modern_ops; + hw->modern =1 ; + dev->driver->drv_flags |=RTE_PCI_DRV_INTR_LSC ; +return 0 ; + }
RTE_PCI_DRV_INTR_LSC is already set by virtio_resource_init_by_uio(). Do you mean interrupt was not supported with legacy virtio?
Re: [PATCH v5 8/9] virtio: add 1.0 support
Quoted 20 lines · Thomas Monjalon
2016-01-19 16:12, Yuanhan Liu:
Quoted 8 lines
int
vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw){drivers/net/virtio/virtio_pci.c +4
-1- hw->vtpci_ops = &legacy_ops; + hw->dev = dev; + +/* +* Try if we can succeed reading virtio pci caps, which exists drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 849
Quoted 10 lines
drivers/net/virtio/virtio_pci.c +10
-0+* only on modern pci device. If failed, we fallback to legacy +* virtio handling. +*/ +if (virtio_read_caps (dev, hw) ==0 ) { +PMD_INIT_LOG (INFO ,"modern virtio pci detected." ); + hw->vtpci_ops = &modern_ops; + hw->modern =1 ; + dev->driver->drv_flags |=RTE_PCI_DRV_INTR_LSC ; +return 0 ; + }
Quoted 1 line
RTE_PCI_DRV_INTR_LSCis already set byvirtio_resource_init_by_uio().
We don't go that far here. Here we just detect if it's a modern virtio device. And if yes, we do some modern initiations, and return.
virtio_resource_init_by_uio() is invoked when virtio_read_caps() fails.
Quoted 1 line
Do you mean interrupt was not supported with legacy virtio?
Nope. this patch set changes nothing on legacy virtio support.
--yliu
Re: [PATCH v5 8/9] virtio: add 1.0 support
In reply to Thomas MonjalonQuoted 27 lines · Thomas Monjalon
2016-01-19 16:12, Yuanhan Liu:
Quoted 12 lines
drivers/net/virtio/virtio_pci.c +12
-0+#define IO_READ_DEF (nr_bits, type) \ +static inline type \ +io_read##nr_bits(type *addr) \ +{ \ + return *(volatile type *)addr; \ +} + +#define IO_WRITE_DEF (nr_bits, type) \ +static inline void \ +io_write##nr_bits(type val, type *addr) \ +{ \ + *(volatile type *)addr = val; \drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 474
Quoted 10 lines
drivers/net/virtio/virtio_pci.c +10
-0+} + +IO_READ_DEF (8, uint8_t) +IO_WRITE_DEF(8, uint8_t) + +IO_READ_DEF (16, uint16_t) +IO_WRITE_DEF(16, uint16_t) + +IO_READ_DEF (32, uint32_t) +IO_WRITE_DEF (32 , uint32_t)Yes you can do this.
But not sure you should.
Quoted 9 lines
drivers/net/virtio/virtio_pci.c static const struct virtio_pci_ops legacy_ops = { · line 481
Quoted 6 lines
drivers/net/virtio/virtio_pci.c +6
-0+static inline void +io_write64_twopart (uint64_t val,uint32_t *lo,uint32_t *hi) +{ +io_write32 (val & ((1ULL <<32 ) -1 ), lo); +io_write32 (val >>32 , hi); +}When debugging this code, how GDB behave?
How to find the definition ofio_write32()with grep or simple editors?
Okay, I will unfold them.
--yliu
Re: [PATCH v5 8/9] virtio: add 1.0 support
In reply to Yuanhan Liu2016-01-27 11:46, Yuanhan Liu:
Quoted 23 lines · Thomas Monjalon
Quoted 20 lines
2016-01-19 16:12, Yuanhan Liu:
Quoted 8 lines
int
vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw){drivers/net/virtio/virtio_pci.c +4
-1- hw->vtpci_ops = &legacy_ops; + hw->dev = dev; + +/* +* Try if we can succeed reading virtio pci caps, which exists drivers/net/virtio/virtio_pci.c vtpci_irq_config(struct virtio_hw *hw, uint16_t vec) · line 849
Quoted 10 lines
drivers/net/virtio/virtio_pci.c +10
-0+* only on modern pci device. If failed, we fallback to legacy +* virtio handling. +*/ +if (virtio_read_caps (dev, hw) ==0 ) { +PMD_INIT_LOG (INFO ,"modern virtio pci detected." ); + hw->vtpci_ops = &modern_ops; + hw->modern =1 ; + dev->driver->drv_flags |=RTE_PCI_DRV_INTR_LSC ; +return 0 ; + }Quoted 1 line
RTE_PCI_DRV_INTR_LSCis already set byvirtio_resource_init_by_uio().
Quoted 8 lines
We don't go that far here. Here we just detect if it's a modern virtio device. And if yes, we do some modern initiations, and return.
virtio_resource_init_by_uio()is invoked whenvirtio_read_caps()fails.Quoted 1 line
Do you mean interrupt was not supported with legacy virtio?
Nope. this patch set changes nothing on legacy virtio support.
Oh yes. I guess I had not seen the return.
v6 cover virtio 1.0 enabling for virtio pmd driver
In reply to Yuanhan Liuv6: unfold IO_READ/WRITE_DEF macro
v5: minor fixes:
- fix wrong type of arg "offset" of read/write_dev_config(): patch 2 is newly added for that.
- check "offset + length" overflow
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 8.
To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a virtio_pci_ops structure, to add another layer so that we could keep those vtpci_foo_bar "APIs". With that, we could do the minimum change to add virtio 1.0 support.
Rough test guide
================
Firstly, you need get a virtio 1.0 supported QEMU (say, v2.5), then add option "disable-modern=false" to qemu virtio-net-pci device to enable virtio 1.0 (which is disabled by default).
And if you see something like following from 'lspci -v', it means virtio 1.0 is indeed enabled:
00:04.0 Ethernet controller: Red Hat, Inc Virtio network device
Subsystem: Red Hat, Inc Device 0001
Physical Slot: 4
Flags: bus master, fast devsel, latency 0, IRQ 11 I/O ports at c040 [size=64]
Memory at febf1000 (32-bit, non-prefetchable) [size=4K] Memory at fe000000 (64-bit, prefetchable) [size=8M] Expansion ROM at feb80000 [disabled] [size=256K]
Capabilities: [98] MSI-X: Enable+ Count=6 Masked-
==> Capabilities: [84] Vendor Specific Information: Len=14 <?> ==> Capabilities: [70] Vendor Specific Information: Len=14 <?> ==> Capabilities: [60] Vendor Specific Information: Len=10 <?> ==> Capabilities: [50] Vendor Specific Information: Len=10 <?> ==> Capabilities: [40] Vendor Specific Information: Len=10 <?>
Kernel driver in use: virtio-pci
Kernel modules: virtio_pci
After that, there wasn't anything speical comparing to the old virtio 0.95 pmd driver.
---
Yuanhan Liu (9):
virtio: don't set vring address again at queue startup
virtio: define offset as size_t type
virtio: introduce struct virtio_pci_ops
virtio: move left pci stuff to virtio_pci.c
viritio: switch to 64 bit features
virtio: retrieve hdr_size from hw->vtnet_hdr_size
eal: pci: export pci_[un]map_device
virtio: add 1.0 support
virtio: move VIRTIO_READ/WRITE_REG_X into virtio_pci.c
doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 302 +-------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 813 +++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 124 +++- drivers/net/virtio/virtio_rxtx.c | 21 +- drivers/net/virtio/virtio_rxtx_simple.c | 12 +- drivers/net/virtio/virtqueue.h | 4 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 +- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 7 + lib/librte_eal/common/eal_common_pci.c | 4 +- lib/librte_eal/common/eal_private.h | 18 - lib/librte_eal/common/include/rte_pci.h | 27 + lib/librte_eal/linuxapp/eal/eal_pci.c | 4 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 7 + 15 files changed, 971 insertions(+), 382 deletions(-)
Signature · 1 line
1.9.0
PATCH v6 1/9 virtio: don't set vring address again at queue startup
As we have already set up it at virtio_dev_queue_setup(), and a vq restart will not reset the settings.
--- drivers/net/virtio/virtio_rxtx.c | 15 --------------- 1 file changed, 15 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -15
@@ -339,11 +339,6 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)vq_update_avail_idx (vq);PMD_INIT_LOG (DEBUG ,"Allocated %d bufs" , nbufs); - -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); }else if (queue_type ==VTNET_TQ ) {if (use_simple_rxtx) {int mid_idx = vq->vq_nentries >>1 ;
@@ -362,16 +357,6 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)for (i = mid_idx; i < vq->vq_nentries; i++) vq->vq_ring.avail->ring[i] = i; } - -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); - }else { -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); } }
Signature · 1 line
1.9.0
PATCH v6 2/9 virtio: define offset as size_t type
In reply to Yuanhan Liuoffset arg of vtpci_read/write_dev_config is derived from offsetof(), which is of size_t type, instead of uint64_t. So, define it as size_t type.
--- drivers/net/virtio/virtio_pci.c | 4 ++-- drivers/net/virtio/virtio_pci.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/virtio/virtio_pci.c +2 -2
@@ -38,7 +38,7 @@static uint8_t vtpci_get_status (struct virtio_hw *);void -vtpci_read_dev_config (struct virtio_hw *hw,uint64_t offset, +vtpci_read_dev_config (struct virtio_hw *hw,size_t offset,void *dst,int length) {uint64_t off;
@@ -61,7 +61,7 @@ vtpci_read_dev_config(struct virtio_hw *hw, uint64_t offset, }void -vtpci_write_dev_config (struct virtio_hw *hw,uint64_t offset, +vtpci_write_dev_config (struct virtio_hw *hw,size_t offset,void *src,int length) {uint64_t off;
drivers/net/virtio/virtio_pci.h +2 -2
@@ -261,9 +261,9 @@ void vtpci_set_status(struct virtio_hw *, uint8_t);uint32_t vtpci_negotiate_features (struct virtio_hw *,uint32_t ); -void vtpci_write_dev_config (struct virtio_hw *,uint64_t ,void *,int ); +void vtpci_write_dev_config (struct virtio_hw *,size_t ,void *,int ); -void vtpci_read_dev_config (struct virtio_hw *,uint64_t ,void *,int ); +void vtpci_read_dev_config (struct virtio_hw *,size_t ,void *,int );uint8_t vtpci_isr (struct virtio_hw *);
Signature · 1 line
1.9.0
PATCH v6 3/9 virtio: introduce struct virtio_pci_ops
In reply to Yuanhan LiuIntroduce struct virtio_pci_ops, to let legacy virtio (v0.95) and modern virtio (1.0) have different implementation regarding to a specific pci action, such as read host status.
With that, this patch reimplements all exported pci functions, in a way like:
vtpci_foo_bar(struct virtio_hw *hw)
{
hw->vtpci_ops->foo_bar(hw);
}So that we need pay attention to those pci related functions only while adding virtio 1.0 support.
This patch introduced a new vtpci function, vtpci_init(), to do proper virtio pci settings. It's pretty simple so far: just sets hw->vtpci_ops to legacy_ops as we don't support 1.0 yet.
---
v5: - define "src" arg of vtpci_write_dev_config()
--- drivers/net/virtio/virtio_ethdev.c | 22 ++--- drivers/net/virtio/virtio_pci.c | 164 ++++++++++++++++++++++++++++++------- drivers/net/virtio/virtio_pci.h | 29 ++++++- drivers/net/virtio/virtqueue.h | 2 +- 4 files changed, 170 insertions(+), 47 deletions(-)
drivers/net/virtio/virtio_ethdev.c +8 -14
@@ -272,9 +272,7 @@ virtio_dev_queue_release(struct virtqueue *vq) {if (vq) { hw = vq->hw; -/* Select and deactivate the queue */ -VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN ,0 ); + hw->vtpci_ops->del_queue (hw, vq);rte_free (vq->sw_ring);rte_free (vq);
@@ -295,15 +293,13 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,struct virtio_hw *hw = dev->data->dev_private;struct virtqueue *vq =NULL ; -/* Write the virtqueue index to the Queue Select Field */ -VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vtpci_queue_idx); -PMD_INIT_LOG (DEBUG ,"selecting queue: %u" , vtpci_queue_idx); +PMD_INIT_LOG (DEBUG ,"setting up queue: %u" , vtpci_queue_idx);/* * Read the virtqueue size from the Queue Size field * Always power of 2 and if 0 virtqueue does not exist */ - vq_size =VIRTIO_READ_REG_2 (hw,VIRTIO_PCI_QUEUE_NUM ); + vq_size = hw->vtpci_ops->get_queue_num (hw, vtpci_queue_idx);PMD_INIT_LOG (DEBUG ,"vq_size: %u nb_desc:%u" , vq_size, nb_desc);if (vq_size ==0 ) {PMD_INIT_LOG (ERR ,"%s: virtqueue does not exist" , __func__);
@@ -436,12 +432,8 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,memset (vq->virtio_net_hdr_mz->addr,0 ,PAGE_SIZE ); } -/* -* Set guest physical address of the virtqueue -* in VIRTIO_PCI_QUEUE_PFN config register of device -*/ -VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN , - mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); + hw->vtpci_ops->setup_queue (hw, vq); + *pvq = vq;return 0 ; }
@@ -950,7 +942,7 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features);/* Read device(host) feature bits */ - host_features =VIRTIO_READ_REG_4 (hw,VIRTIO_PCI_HOST_FEATURES ); + host_features = hw->vtpci_ops->get_features (hw);PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %x" , host_features);
@@ -1287,6 +1279,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; +vtpci_init (pci_dev, hw); +if (virtio_resource_init (pci_dev) <0 )return -1 ;
drivers/net/virtio/virtio_pci.c +133 -31
229 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +28 -1
@@ -163,6 +163,31 @@ struct virtqueue;*/ #define VIRTIO_MAX_VIRTQUEUES 8 +struct virtio_hw ; + +struct virtio_pci_ops { +void (*read_dev_cfg)(struct virtio_hw *hw,size_t offset, +void *dst,int len); +void (*write_dev_cfg)(struct virtio_hw *hw,size_t offset, +const void *src,int len); +void (*reset)(struct virtio_hw *hw); + +uint8_t (*get_status)(struct virtio_hw *hw); +void (*set_status)(struct virtio_hw *hw,uint8_t status); + +uint32_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint32_t features); + +uint8_t (*get_isr)(struct virtio_hw *hw); + +uint16_t (*set_config_irq)(struct virtio_hw *hw,uint16_t vec); + +uint16_t (*get_queue_num)(struct virtio_hw *hw,uint16_t queue_id); +void (*setup_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*del_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*notify_queue)(struct virtio_hw *hw,struct virtqueue *vq); +}; +struct virtio_hw {struct virtqueue *cvq;uint32_t io_base;
@@ -174,6 +199,7 @@ struct virtio_hw {uint8_t use_msix;uint8_t started;uint8_t mac_addr[ETHER_ADDR_LEN ]; +const struct virtio_pci_ops *vtpci_ops; };/*
@@ -253,6 +279,7 @@ vtpci_with_feature(struct virtio_hw *hw, uint32_t bit)/* * Function declaration from virtio_pci.c */ +int vtpci_init (struct rte_pci_device *,struct virtio_hw *);void vtpci_reset (struct virtio_hw *);void vtpci_reinit_complete (struct virtio_hw *);
@@ -261,7 +288,7 @@ void vtpci_set_status(struct virtio_hw *, uint8_t);uint32_t vtpci_negotiate_features (struct virtio_hw *,uint32_t ); -void vtpci_write_dev_config (struct virtio_hw *,size_t ,void *,int ); +void vtpci_write_dev_config (struct virtio_hw *,size_t ,const void *,int );void vtpci_read_dev_config (struct virtio_hw *,size_t ,void *,int );
drivers/net/virtio/virtqueue.h +1 -1
@@ -302,7 +302,7 @@ virtqueue_notify(struct virtqueue *vq)* For virtio on IA, the notificaiton is through io port operation * which is a serialization instruction itself. */ -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_NOTIFY , vq->vq_queue_index); + vq->hw->vtpci_ops->notify_queue (vq->hw, vq); }#ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP
Signature · 1 line
1.9.0
PATCH v6 4/9 virtio: move left pci stuff to virtio_pci.c
In reply to Yuanhan Liuvirtio_pci.c is a more proper place for pci stuff; virtio_ethdev is not.
--- drivers/net/virtio/virtio_ethdev.c | 265 +----------------------------------- drivers/net/virtio/virtio_pci.c | 270 ++++++++++++++++++++++++++++++++++++- 2 files changed, 270 insertions(+), 265 deletions(-)
drivers/net/virtio/virtio_ethdev.c +1 -264
@@ -36,10 +36,6 @@#include <stdio.h> #include <errno.h> #include <unistd.h> -#ifdef RTE_EXEC_ENV_LINUXAPP -#include <dirent.h> -#include <fcntl.h> -#endif #include <rte_ethdev.h> #include <rte_memcpy.h>
@@ -955,260 +951,6 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features); } -#ifdef RTE_EXEC_ENV_LINUXAPP -static int -parse_sysfs_value (const char *filename,unsigned long *val) -{ -FILE *f; -char buf[BUFSIZ ]; -char *end =NULL ; - - f =fopen (filename,"r" ); -if (f ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): cannot open sysfs value %s" , - __func__, filename); -return -1 ; - } - -if (fgets (buf,sizeof (buf), f) ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): cannot read sysfs value %s" , - __func__, filename); -fclose (f); -return -1 ; - } - *val =strtoul (buf, &end,0 ); -if ((buf[0 ] =='\0' ) || (end ==NULL ) || (*end !='\n' )) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse sysfs value %s" , - __func__, filename); -fclose (f); -return -1 ; - } -fclose (f); -return 0 ; -} - -static int get_uio_dev (struct rte_pci_addr *loc,char *buf,unsigned int buflen, -unsigned int *uio_num) -{ -struct dirent *e; -DIR *dir; -char dirname[PATH_MAX ]; - -/* depending on kernel version, uio can be located in uio/uioX -* or uio:uioX */ -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio" , - loc->domain, loc->bus, loc->devid, loc->function); - dir =opendir (dirname); -if (dir ==NULL ) { -/* retry with the parent directory */ -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT , - loc->domain, loc->bus, loc->devid, loc->function); - dir =opendir (dirname); - -if (dir ==NULL ) { -PMD_INIT_LOG (ERR ,"Cannot opendir %s" , dirname); -return -1 ; - } - } - -/* take the first file starting with "uio" */ -while ((e =readdir (dir)) !=NULL ) { -/* format could be uio%d ...*/ -int shortprefix_len =sizeof ("uio" ) -1 ; -/* ... or uio:uio%d */ -int longprefix_len =sizeof ("uio:uio" ) -1 ; -char *endptr; - -if (strncmp (e->d_name,"uio" ,3 ) !=0 ) -continue ; - -/* first try uio%d */ - errno =0 ; - *uio_num =strtoull (e->d_name + shortprefix_len, &endptr,10 ); -if (errno ==0 && endptr != (e->d_name + shortprefix_len)) { -snprintf (buf, buflen,"%s/uio%u" , dirname, *uio_num); -break ; - } - -/* then try uio:uio%d */ - errno =0 ; - *uio_num =strtoull (e->d_name + longprefix_len, &endptr,10 ); -if (errno ==0 && endptr != (e->d_name + longprefix_len)) { -snprintf (buf, buflen,"%s/uio:uio%u" , dirname, - *uio_num); -break ; - } - } -closedir (dir); - -/* No uio resource found */ -if (e ==NULL ) { -PMD_INIT_LOG (ERR ,"Could not find uio resource" ); -return -1 ; - } - -return 0 ; -} - -static int -virtio_has_msix (const struct rte_pci_addr *loc) -{ -DIR *d; -char dirname[PATH_MAX ]; - -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/msi_irqs" , - loc->domain, loc->bus, loc->devid, loc->function); - - d =opendir (dirname); -if (d) -closedir (d); - -return (d !=NULL ); -} - -/* Extract I/O port numbers from sysfs */ -static int virtio_resource_init_by_uio (struct rte_pci_device *pci_dev) -{ -char dirname[PATH_MAX ]; -char filename[PATH_MAX ]; -unsigned long start, size; -unsigned int uio_num; - -if (get_uio_dev (&pci_dev->addr, dirname,sizeof (dirname), &uio_num) <0 ) -return -1 ; - -/* get portio size */ -snprintf (filename,sizeof (filename), -"%s/portio/port0/size" , dirname); -if (parse_sysfs_value (filename, &size) <0 ) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse size" , - __func__); -return -1 ; - } - -/* get portio start */ -snprintf (filename,sizeof (filename), -"%s/portio/port0/start" , dirname); -if (parse_sysfs_value (filename, &start) <0 ) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse portio start" , - __func__); -return -1 ; - } - pci_dev->mem_resource[0 ].addr = (void *)(uintptr_t )start; - pci_dev->mem_resource[0 ].len = (uint64_t )size; -PMD_INIT_LOG (DEBUG , -"PCI Port IO found start=0x%lx with size=0x%lx" , - start, size); - -/* save fd */ -memset (dirname,0 ,sizeof (dirname)); -snprintf (dirname,sizeof (dirname),"/dev/uio%u" , uio_num); - pci_dev->intr_handle.fd =open (dirname,O_RDWR ); -if (pci_dev->intr_handle.fd <0 ) { -PMD_INIT_LOG (ERR ,"Cannot open %s: %s\n" , - dirname,strerror (errno)); -return -1 ; - } - - pci_dev->intr_handle.type =RTE_INTR_HANDLE_UIO ; - pci_dev->driver->drv_flags |=RTE_PCI_DRV_INTR_LSC ; - -return 0 ; -} - -/* Extract port I/O numbers from proc/ioports */ -static int virtio_resource_init_by_ioports (struct rte_pci_device *pci_dev) -{ -uint16_t start, end; -int size; -FILE *fp; -char *line =NULL ; -char pci_id[16 ]; -int found =0 ; -size_t linesz; - -snprintf (pci_id,sizeof (pci_id),PCI_PRI_FMT , - pci_dev->addr.domain, - pci_dev->addr.bus, - pci_dev->addr.devid, - pci_dev->addr.function); - - fp =fopen ("/proc/ioports" ,"r" ); -if (fp ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): can't open ioports" , __func__); -return -1 ; - } - -while (getdelim (&line, &linesz,'\n' , fp) >0 ) { -char *ptr = line; -char *left; -int n; - - n =strcspn (ptr,":" ); - ptr[n] =0 ; - left = &ptr[n+1 ]; - -while (*left &&isspace (*left)) - left++; - -if (!strncmp (left, pci_id,strlen (pci_id))) { - found =1 ; - -while (*ptr &&isspace (*ptr)) - ptr++; - -sscanf (ptr,"%04hx-%04hx" , &start, &end); - size = end - start +1 ; - -break ; - } - } - -free (line); -fclose (fp); - -if (!found) -return -1 ; - - pci_dev->mem_resource[0 ].addr = (void *)(uintptr_t )(uint32_t )start; - pci_dev->mem_resource[0 ].len = (uint64_t )size; -PMD_INIT_LOG (DEBUG , -"PCI Port IO found start=0x%x with size=0x%x" , - start, size); - -/* can't support lsc interrupt without uio */ - pci_dev->driver->drv_flags &= ~RTE_PCI_DRV_INTR_LSC ; - -return 0 ; -} - -/* Extract I/O port numbers from sysfs */ -static int virtio_resource_init (struct rte_pci_device *pci_dev) -{ -if (virtio_resource_init_by_uio (pci_dev) ==0 ) -return 0 ; -else -return virtio_resource_init_by_ioports (pci_dev); -} - -#else -static int -virtio_has_msix(const struct rte_pci_addr *loc __rte_unused) -{ -/* nic_uio does not enable interrupts, return 0 (false). */ -return 0 ; -} - -static int virtio_resource_init(struct rte_pci_device *pci_dev __rte_unused) -{ -/* no setup required */ -return 0 ; -} -#endif -/* * Process Virtio Config changed interrupt and call the callback * if link state changed.
@@ -1279,14 +1021,9 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; -vtpci_init (pci_dev, hw); - -if (virtio_resource_init (pci_dev) <0 ) +if (vtpci_init (pci_dev, hw) <0 )return -1 ; - hw->use_msix =virtio_has_msix (&pci_dev->addr); - hw->io_base = (uint32_t )(uintptr_t )pci_dev->mem_resource[0 ].addr; -/* Reset the device although not necessary at startup */ vtpci_reset (hw);
drivers/net/virtio/virtio_pci.c +269 -1
290 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH v6 5/9 viritio: switch to 64 bit features
In reply to Yuanhan LiuSwitch to 64 bit features, which virtio 1.0 supports.
While legacy virtio only supports 32 bit features, it complains aloud and quit when trying to setting > 32 bit features.
--- drivers/net/virtio/virtio_ethdev.c | 8 ++++---- drivers/net/virtio/virtio_pci.c | 15 ++++++++++----- drivers/net/virtio/virtio_pci.h | 12 ++++++------ 3 files changed, 20 insertions(+), 15 deletions(-)
drivers/net/virtio/virtio_ethdev.c +4 -4
@@ -930,16 +930,16 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)static void virtio_negotiate_features (struct virtio_hw *hw) { -uint32_t host_features; +uint64_t host_features;/* Prepare guest_features: feature that driver wants to support */ hw->guest_features =VIRTIO_PMD_GUEST_FEATURES ; -PMD_INIT_LOG (DEBUG ,"guest_features before negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"guest_features before negotiate = %" PRIx64, hw->guest_features);/* Read device(host) feature bits */ host_features = hw->vtpci_ops->get_features (hw); -PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %" PRIx64, host_features);/*
@@ -947,7 +947,7 @@ virtio_negotiate_features(struct virtio_hw *hw)* guest feature bits. */ hw->guest_features =vtpci_negotiate_features (hw, host_features); -PMD_INIT_LOG (DEBUG ,"features after negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); }
drivers/net/virtio/virtio_pci.c +10 -5
@@ -87,15 +87,20 @@ legacy_write_dev_config(struct virtio_hw *hw, size_t offset, } } -static uint32_t +static uint64_t legacy_get_features (struct virtio_hw *hw) {return VIRTIO_READ_REG_4 (hw,VIRTIO_PCI_HOST_FEATURES ); }static void -legacy_set_features (struct virtio_hw *hw,uint32_t features) +legacy_set_features (struct virtio_hw *hw,uint64_t features) { +if ((features >>32 ) !=0 ) { +PMD_DRV_LOG (ERR , +"only 32 bit features are allowed for legacy virtio!" ); +return ; + }VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_GUEST_FEATURES , features); }
@@ -451,10 +456,10 @@ vtpci_write_dev_config(struct virtio_hw *hw, size_t offset, hw->vtpci_ops->write_dev_cfg (hw, offset, src, length); } -uint32_t -vtpci_negotiate_features (struct virtio_hw *hw,uint32_t host_features) +uint64_t +vtpci_negotiate_features (struct virtio_hw *hw,uint64_t host_features) { -uint32_t features; +uint64_t features;/* * Limit negotiated features to what the driver, virtqueue, and
drivers/net/virtio/virtio_pci.h +6 -6
@@ -175,8 +175,8 @@ struct virtio_pci_ops {uint8_t (*get_status)(struct virtio_hw *hw);void (*set_status)(struct virtio_hw *hw,uint8_t status); -uint32_t (*get_features)(struct virtio_hw *hw); -void (*set_features)(struct virtio_hw *hw,uint32_t features); +uint64_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint64_t features);uint8_t (*get_isr)(struct virtio_hw *hw);
@@ -191,7 +191,7 @@ struct virtio_pci_ops {struct virtio_hw {struct virtqueue *cvq;uint32_t io_base; -uint32_t guest_features; +uint64_t guest_features;uint32_t max_tx_queues;uint32_t max_rx_queues;uint16_t vtnet_hdr_size;
@@ -271,9 +271,9 @@ outl_p(unsigned int data, unsigned int port) outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg))))static inline int -vtpci_with_feature (struct virtio_hw *hw,uint32_t bit) +vtpci_with_feature (struct virtio_hw *hw,uint64_t bit) { -return (hw->guest_features & (1u << bit)) !=0 ; +return (hw->guest_features & (1ULL << bit)) !=0 ; }/*
@@ -286,7 +286,7 @@ void vtpci_reinit_complete(struct virtio_hw *);void vtpci_set_status (struct virtio_hw *,uint8_t ); -uint32_t vtpci_negotiate_features (struct virtio_hw *,uint32_t ); +uint64_t vtpci_negotiate_features (struct virtio_hw *,uint64_t );void vtpci_write_dev_config (struct virtio_hw *,size_t ,const void *,int );
Signature · 1 line
1.9.0
PATCH v6 6/9 virtio: retrieve hdr_size from hw->vtnet_hdr_size
In reply to Yuanhan LiuThe mergeable virtio net hdr format has been the standard and the only virtio net hdr format since virtio 1.0. Therefore, we can not hardcode hdr_size to "sizeof(struct virtio_net_hdr)" any more at virtio_recv_pkts(), otherwise, there would be a mismatch of hdr size from rte_vhost_enqueue_burst() and virtio_recv_pkts(), leading a packet corruption.
Instead, we should retrieve it from hw->vtnet_hdr_size; we will do proper settings at eth_virtio_dev_init() in later patches.
---
--- drivers/net/virtio/virtio_rxtx.c | 6 ++++-- drivers/net/virtio/virtio_rxtx_simple.c | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/net/virtio/virtio_rxtx.c +4 -2
@@ -560,7 +560,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)struct rte_mbuf *rcv_pkts[VIRTIO_MBUF_BURST_SZ ];int error;uint32_t i, nb_enqueued; -const uint32_t hdr_size =sizeof (struct virtio_net_hdr ); +uint32_t hdr_size; nb_used =VIRTQUEUE_NUSED (rxvq);
@@ -580,6 +580,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) hw = rxvq->hw; nb_rx =0 ; nb_enqueued =0 ; + hdr_size = hw->vtnet_hdr_size;for (i =0 ; i < num ; i++) { rxm = rcv_pkts[i];
@@ -664,7 +665,7 @@ virtio_recv_mergeable_pkts(void *rx_queue,uint32_t seg_num;uint16_t extra_idx;uint32_t seg_res; -const uint32_t hdr_size =sizeof (struct virtio_net_hdr_mrg_rxbuf ); +uint32_t hdr_size; nb_used =VIRTQUEUE_NUSED (rxvq);
@@ -682,6 +683,7 @@ virtio_recv_mergeable_pkts(void *rx_queue, seg_num =0 ; extra_idx =0 ; seg_res =0 ; + hdr_size = hw->vtnet_hdr_size;while (i < nb_used) {struct virtio_net_hdr_mrg_rxbuf *header;
drivers/net/virtio/virtio_rxtx_simple.c +6 -6
@@ -81,9 +81,9 @@ virtqueue_enqueue_recv_refill_simple(struct virtqueue *vq, start_dp = vq->vq_ring.desc; start_dp[desc_idx].addr = (uint64_t )((uintptr_t )cookie->buf_physaddr + -RTE_PKTMBUF_HEADROOM -sizeof (struct virtio_net_hdr )); +RTE_PKTMBUF_HEADROOM - vq->hw->vtnet_hdr_size); start_dp[desc_idx].len = cookie->buf_len - -RTE_PKTMBUF_HEADROOM +sizeof (struct virtio_net_hdr ); +RTE_PKTMBUF_HEADROOM + vq->hw->vtnet_hdr_size; vq->vq_free_cnt--; vq->vq_avail_idx++;
@@ -120,9 +120,9 @@ virtio_rxq_rearm_vec(struct virtqueue *rxvq) start_dp[i].addr = (uint64_t )((uintptr_t )sw_ring[i]->buf_physaddr + -RTE_PKTMBUF_HEADROOM -sizeof (struct virtio_net_hdr )); +RTE_PKTMBUF_HEADROOM - rxvq->hw->vtnet_hdr_size); start_dp[i].len = sw_ring[i]->buf_len - -RTE_PKTMBUF_HEADROOM +sizeof (struct virtio_net_hdr ); +RTE_PKTMBUF_HEADROOM + rxvq->hw->vtnet_hdr_size; } rxvq->vq_avail_idx +=RTE_VIRTIO_VPMD_RX_REARM_THRESH ;
@@ -175,8 +175,8 @@ virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts, len_adjust =_mm_set_epi16 (0 ,0 ,0 , - (uint16_t ) -sizeof (struct virtio_net_hdr ), -0 , (uint16_t ) -sizeof (struct virtio_net_hdr ), + (uint16_t ) -rxvq->hw->vtnet_hdr_size, +0 , (uint16_t ) -rxvq->hw->vtnet_hdr_size,0 ,0 );if (unlikely (nb_pkts <RTE_VIRTIO_DESC_PER_LOOP ))
Signature · 1 line
1.9.0
PATCH v6 7/9 eal: pci: export pci_[un]map_device
In reply to Yuanhan LiuNormally we could set RTE_PCI_DRV_NEED_MAPPING flag so that eal will invoke pci_map_device internally for us. From that point view, there is no need to export pci_map_device.
However, for virtio pmd driver, which is designed to work without binding UIO (or something similar first), pci_map_device() will fail, which ends up with virtio pmd driver being skipped. Therefore, we can not set RTE_PCI_DRV_NEED_MAPPING blindly at virtio pmd driver.
Therefore, this patch exports pci_map_device, and let virtio pmd call it when necessary.
--- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 ++-- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 7 +++++++ lib/librte_eal/common/eal_common_pci.c | 4 ++-- lib/librte_eal/common/eal_private.h | 18 ----------------- lib/librte_eal/common/include/rte_pci.h | 27 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 4 ++-- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 7 +++++++ 7 files changed, 47 insertions(+), 24 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -2
@@ -93,7 +93,7 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)/* Map pci device */ int -pci_map_device (struct rte_pci_device *dev) +rte_eal_pci_map_device (struct rte_pci_device *dev) {int ret =-1 ;
@@ -115,7 +115,7 @@ pci_map_device(struct rte_pci_device *dev)/* Unmap pci device */ void -pci_unmap_device (struct rte_pci_device *dev) +rte_eal_pci_unmap_device (struct rte_pci_device *dev) {/* try unmapping the NIC resources */ switch (dev->kdrv) {
lib/librte_eal/bsdapp/eal/rte_eal_version.map +7 -0
@@ -135,3 +135,10 @@ DPDK_2.2 { rte_xen_dom0_supported; } DPDK_2.1; + +DPDK_2.3 { + global: + + rte_eal_pci_map_device; + rte_eal_pci_unmap_device; +} DPDK_2.2;
lib/librte_eal/common/eal_common_pci.c +2 -2
@@ -188,7 +188,7 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dpci_config_space_set (dev);#endif /* map resources for devices that use igb_uio */ - ret =pci_map_device (dev); + ret =rte_eal_pci_map_device (dev);if (ret !=0 )return ret; } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
@@ -254,7 +254,7 @@ rte_eal_pci_detach_dev(struct rte_pci_driver *dr,if (dr->drv_flags &RTE_PCI_DRV_NEED_MAPPING )/* unmap resources for devices that use igb_uio */ -pci_unmap_device (dev); +rte_eal_pci_unmap_device (dev);return 0 ; }
lib/librte_eal/common/eal_private.h +0 -18
@@ -165,24 +165,6 @@ struct rte_pci_device;int pci_unbind_kernel_driver (struct rte_pci_device *dev);/** -* Map this device -* -* This function is private to EAL. -* -* @return -* 0 on success, negative on error and positive if no driver -* is found for the device. -*/ -int pci_map_device (struct rte_pci_device *dev); - -/** -* Unmap this device -* -* This function is private to EAL. -*/ -void pci_unmap_device (struct rte_pci_device *dev); - -/** * Map the PCI resource of a PCI device in virtual memory * * This function is private to EAL.
lib/librte_eal/common/include/rte_pci.h +27 -0
@@ -485,6 +485,33 @@ int rte_eal_pci_read_config(const struct rte_pci_device *device,*/ int rte_eal_pci_write_config (const struct rte_pci_device *device,const void *buf,size_t len,off_t offset); +/** +* Map the PCI device resources in user space virtual memory address +* +* Note that driver should not call this function when flag +* RTE_PCI_DRV_NEED_MAPPING is set, as EAL will do that for +* you when it's on. +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +* +* @return +* 0 on success, negative on error and positive if no driver +* is found for the device. +*/ +int rte_eal_pci_map_device (struct rte_pci_device *dev); + +/** +* Unmap this device +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +*/ +void rte_eal_pci_unmap_device (struct rte_pci_device *dev); + +#ifdef RTE_PCI_CONFIG /**
lib/librte_eal/linuxapp/eal/eal_pci.c +2 -2
@@ -124,7 +124,7 @@ pci_get_kernel_driver_by_path(const char *filename, char *dri_name)/* Map pci device */ int -pci_map_device (struct rte_pci_device *dev) +rte_eal_pci_map_device (struct rte_pci_device *dev) {int ret =-1 ;
@@ -153,7 +153,7 @@ pci_map_device(struct rte_pci_device *dev)/* Unmap pci device */ void -pci_unmap_device (struct rte_pci_device *dev) +rte_eal_pci_unmap_device (struct rte_pci_device *dev) {/* try unmapping the NIC resources using VFIO if it exists */ switch (dev->kdrv) {
lib/librte_eal/linuxapp/eal/rte_eal_version.map +7 -0
@@ -138,3 +138,10 @@ DPDK_2.2 { rte_xen_dom0_supported; } DPDK_2.1; + +DPDK_2.3 { + global: + + rte_eal_pci_map_device; + rte_eal_pci_unmap_device; +} DPDK_2.2;
Signature · 1 line
1.9.0
PATCH v6 8/9 virtio: add 1.0 support
In reply to Yuanhan LiuModern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
Firstly, we map the pci resources by rte_eal_pci_map_device(). We then could easily locate a cfg structure by:
cfg_addr = dev->mem_resources[cap.bar].addr + cap.offset;
Therefore, the entrance of enabling modern (v1.0) pci device support is to iterate the pci capability lists, and to locate some configs we care; and they are:
- common cfg
For generic virtio and virtqueue configuration, such as setting/getting features, enabling a specific queue, and so on.
- nofity cfg
Combining with `queue_notify_off' from common cfg, we could use it to notify a specific virt queue.
- device cfg
Where virtio_net_config structure is located.
- isr cfg
Where to read isr (interrupt status).
If any of above cap is not found, we fallback to the legacy virtio handling.
If succeed, hw->vtpci_ops is assigned to modern_ops, where all operations are implemented by reading/writing a (or few) specific configuration space from above 4 cfg structures. And that's basically how this patch works.
Besides those changes, virtio 1.0 introduces a new status field:FEATURES_OK, which is set after features negotiation is done.
Last, set the VIRTIO_F_VERSION_1 feature flag.
---
v6: - unfold DEF_IO_READ/WRITE macros
v5: - rename MODERN_READ/WRITE_DEF macro name to IO_READ/WRITE_DEF
- check offset + length overflow
--- doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 25 ++- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 355 ++++++++++++++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 67 +++++++ drivers/net/virtio/virtqueue.h | 2 + 6 files changed, 450 insertions(+), 5 deletions(-)
doc/guides/rel_notes/release_2_3.rst +3 -0
@@ -4,6 +4,9 @@ DPDK Release 2.3 New Features ------------ +* **Virtio 1.0 support.** + + Enabled virtio 1.0 support for virtio pmd driver. Resolved Issues ---------------
drivers/net/virtio/virtio_ethdev.c +22 -3
@@ -927,7 +927,7 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)return virtio_send_command (hw->cvq, &ctrl, &len,1 ); } -static void +static int virtio_negotiate_features (struct virtio_hw *hw) {uint64_t host_features;
@@ -949,6 +949,22 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features =vtpci_negotiate_features (hw, host_features);PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); + +if (hw->modern) { +if (!vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) { +PMD_INIT_LOG (ERR , +"VIRTIO_F_VERSION_1 features is not enabled." ); +return -1 ; + } +vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_FEATURES_OK ); +if (!(vtpci_get_status (hw) &VIRTIO_CONFIG_STATUS_FEATURES_OK )) { +PMD_INIT_LOG (ERR , +"failed to set FEATURES_OK status!" ); +return -1 ; + } + } + +return 0 ; }/*
@@ -1032,7 +1048,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)/* Tell the host we've known how to drive the device. */ vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_DRIVER ); -virtio_negotiate_features (hw); +if (virtio_negotiate_features (hw) <0 ) +return -1 ;/* If host does not support status then disable LSC */ if (!vtpci_with_feature (hw,VIRTIO_NET_F_STATUS ))
@@ -1043,7 +1060,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)rx_func_get (eth_dev);/* Setting up rx_header size for the device */ -if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF ) || +vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) hw->vtnet_hdr_size =sizeof (struct virtio_net_hdr_mrg_rxbuf );else hw->vtnet_hdr_size =sizeof (struct virtio_net_hdr );
@@ -1159,6 +1177,7 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)rte_intr_callback_unregister (&pci_dev->intr_handle, virtio_interrupt_handler, eth_dev); +rte_eal_pci_unmap_device (pci_dev);PMD_INIT_LOG (DEBUG ,"dev_uninit completed" );
drivers/net/virtio/virtio_ethdev.h +2 -1
@@ -64,7 +64,8 @@1u <<VIRTIO_NET_F_CTRL_VQ | \1u <<VIRTIO_NET_F_CTRL_RX | \1u <<VIRTIO_NET_F_CTRL_VLAN | \ - 1u << VIRTIO_NET_F_MRG_RXBUF) +1u <<VIRTIO_NET_F_MRG_RXBUF | \ + 1ULL << VIRTIO_F_VERSION_1)/* * CQ function prototype
drivers/net/virtio/virtio_pci.c +354 -1
387 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +67 -0
104 lines not on this page · raw message
drivers/net/virtio/virtqueue.h +2 -0
@@ -202,6 +202,8 @@ struct virtqueue {/* Size bins in array as RFC 2819, undersized [0], 64 [1], etc */ uint64_t size_bins[8 ]; +uint16_t *notify_addr; +struct vq_desc_extra {void *cookie;uint16_t ndescs;
Signature · 1 line
1.9.0
PATCH v6 9/9 virtio: move VIRTIO_READ/WRITE_REG_X into virtio_pci.c
In reply to Yuanhan Liuvirtio_pci.c is the only file references those macros; move them there.
--- drivers/net/virtio/virtio_pci.c | 19 +++++++++++++++++++ drivers/net/virtio/virtio_pci.h | 18 ------------------ 2 files changed, 19 insertions(+), 18 deletions(-)
drivers/net/virtio/virtio_pci.c +19 -0
@@ -49,6 +49,25 @@#define PCI_CAPABILITY_LIST 0x34#define PCI_CAP_ID_VNDR 0x09 + +#define VIRTIO_PCI_REG_ADDR (hw, reg) \ + (unsigned short)((hw)->io_base + (reg)) + +#define VIRTIO_READ_REG_1 (hw, reg) \ + inb((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_1 (hw, reg, value) \ + outb_p((unsigned char)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) + +#define VIRTIO_READ_REG_2 (hw, reg) \ + inw((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_2 (hw, reg, value) \ + outw_p((unsigned short)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) + +#define VIRTIO_READ_REG_4 (hw, reg) \ + inl((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_4 (hw, reg, value) \ + outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) +static void legacy_read_dev_config (struct virtio_hw *hw,size_t offset,void *dst,int length)
drivers/net/virtio/virtio_pci.h +0 -18
@@ -318,24 +318,6 @@ outl_p(unsigned int data, unsigned int port) }#endif -#define VIRTIO_PCI_REG_ADDR (hw, reg) \ - (unsigned short)((hw)->io_base + (reg)) - -#define VIRTIO_READ_REG_1 (hw, reg) \ - inb((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_1 (hw, reg, value) \ - outb_p((unsigned char)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) - -#define VIRTIO_READ_REG_2 (hw, reg) \ - inw((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_2 (hw, reg, value) \ - outw_p((unsigned short)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) - -#define VIRTIO_READ_REG_4 (hw, reg) \ - inl((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_4 (hw, reg, value) \ - outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) -static inline int vtpci_with_feature (struct virtio_hw *hw,uint64_t bit) {
Signature · 1 line
1.9.0
Re: [PATCH v6 0/9] virtio 1.0 enabling for virtio pmd driver
In reply to Yuanhan LiuHi Yuanhan,
I wanted to apply these patches but I see few checkpatch warnings, inluding a typo.
Sometimes I fix them myself but I guess you would prefer checking it.
### PATCH v6 4_9
CHECK:SPACING: spaces preferred around that '+' (ctx:VxV) #571: FILE: drivers/net/virtio/virtio_pci.c:361:
+ left = &ptr[n+1];
^WARNING:NAKED_SSCANF: unchecked sscanf return value #582: FILE: drivers/net/virtio/virtio_pci.c:372:
+ sscanf(ptr, "%04hx-%04hx", &start, &end);
### PATCH v6 5_9
CHECK:CONCATENATED_STRING: Concatenated strings should use spaces between elements #79: FILE: drivers/net/virtio/virtio_ethdev.c:937:
+ PMD_INIT_LOG(DEBUG, "guest_features before negotiate = %"PRIx64,
CHECK:CONCATENATED_STRING: Concatenated strings should use spaces between elements #85: FILE: drivers/net/virtio/virtio_ethdev.c:942:
+ PMD_INIT_LOG(DEBUG, "host_features before negotiate = %"PRIx64,
CHECK:CONCATENATED_STRING: Concatenated strings should use spaces between elements #94: FILE: drivers/net/virtio/virtio_ethdev.c:950:
+ PMD_INIT_LOG(DEBUG, "features after negotiate = %"PRIx64,
### PATCH v6 7_9
WARNING:BAD_SIGN_OFF: 'Tested-by:' is the preferred signature form #63:
### PATCH v6 8_9
CHECK:CAMELCASE: Avoid CamelCase: <PRIx64>
#396: FILE: drivers/net/virtio/virtio_pci.c:620:
+ PMD_INIT_LOG(DEBUG, "\t desc_addr: %"PRIx64, desc_addr);
CHECK:CONCATENATED_STRING: Concatenated strings should use spaces between elements #396: FILE: drivers/net/virtio/virtio_pci.c:620:
+ PMD_INIT_LOG(DEBUG, "\t desc_addr: %"PRIx64, desc_addr);
CHECK:CONCATENATED_STRING: Concatenated strings should use spaces between elements #397: FILE: drivers/net/virtio/virtio_pci.c:621:
+ PMD_INIT_LOG(DEBUG, "\t aval_addr: %"PRIx64, avail_addr);
CHECK:CONCATENATED_STRING: Concatenated strings should use spaces between elements #398: FILE: drivers/net/virtio/virtio_pci.c:622:
+ PMD_INIT_LOG(DEBUG, "\t used_addr: %"PRIx64, used_addr);
WARNING:TYPO_SPELLING: 'lenght' may be misspelled - perhaps 'length'? #475: FILE: drivers/net/virtio/virtio_pci.c:751:
+ PMD_INIT_LOG(ERR, "offset(%u) + lenght(%u) overflows",
CHECK:CAMELCASE: Avoid CamelCase: <PRIu64>
#482: FILE: drivers/net/virtio/virtio_pci.c:758:
+ "invalid cap: overflows bar space: %u > %"PRIu64,
CHECK:CONCATENATED_STRING: Concatenated strings should use spaces between elements #482: FILE: drivers/net/virtio/virtio_pci.c:758:
+ "invalid cap: overflows bar space: %u > %"PRIu64,
WARNING:INDENTED_LABEL: labels should not be indented #550: FILE: drivers/net/virtio/virtio_pci.c:826:
+ next:
Re: [PATCH v6 0/9] virtio 1.0 enabling for virtio pmd driver
Quoted 5 lines · Thomas Monjalon
Hi Yuanhan,
I wanted to apply these patches but I see few checkpatch warnings, inluding a typo.
Sometimes I fix them myself but I guess you would prefer checking it.
Okay; I will fix them all.
--yliu
v7 cover virtio 1.0 enabling for virtio pmd driver
In reply to Yuanhan Liuv7: - make checkpatch a bit happier; few (false) warnings still left.
- rebase to latest code: fixed a conflict.
v6: unfold IO_READ/WRITE_DEF macro
v5: minor fixes:
- fix wrong type of arg "offset" of read/write_dev_config(): patch 2 is newly added for that.
- check "offset + length" overflow
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 8.
To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a virtio_pci_ops structure, to add another layer so that we could keep those vtpci_foo_bar "APIs". With that, we could do the minimum change to add virtio 1.0 support.
Rough test guide
================
Firstly, you need get a virtio 1.0 supported QEMU (say, v2.5), then add option "disable-modern=false" to qemu virtio-net-pci device to enable virtio 1.0 (which is disabled by default).
And if you see something like following from 'lspci -v', it means virtio 1.0 is indeed enabled:
00:04.0 Ethernet controller: Red Hat, Inc Virtio network device
Subsystem: Red Hat, Inc Device 0001
Physical Slot: 4
Flags: bus master, fast devsel, latency 0, IRQ 11 I/O ports at c040 [size=64]
Memory at febf1000 (32-bit, non-prefetchable) [size=4K] Memory at fe000000 (64-bit, prefetchable) [size=8M] Expansion ROM at feb80000 [disabled] [size=256K]
Capabilities: [98] MSI-X: Enable+ Count=6 Masked-
==> Capabilities: [84] Vendor Specific Information: Len=14 <?> ==> Capabilities: [70] Vendor Specific Information: Len=14 <?> ==> Capabilities: [60] Vendor Specific Information: Len=10 <?> ==> Capabilities: [50] Vendor Specific Information: Len=10 <?> ==> Capabilities: [40] Vendor Specific Information: Len=10 <?>
Kernel driver in use: virtio-pci
Kernel modules: virtio_pci
After that, there wasn't anything speical comparing to the old virtio 0.95 pmd driver.
---
Yuanhan Liu (9):
virtio: don't set vring address again at queue startup
virtio: define offset as size_t type
virtio: introduce struct virtio_pci_ops
virtio: move left pci stuff to virtio_pci.c
viritio: switch to 64 bit features
virtio: retrieve hdr_size from hw->vtnet_hdr_size
eal: pci: export pci_[un]map_device
virtio: add 1.0 support
virtio: move VIRTIO_READ/WRITE_REG_X into virtio_pci.c
doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 302 +-------- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 815 +++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 124 +++- drivers/net/virtio/virtio_rxtx.c | 21 +- drivers/net/virtio/virtio_rxtx_simple.c | 12 +- drivers/net/virtio/virtqueue.h | 4 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 +- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 + lib/librte_eal/common/eal_common_pci.c | 4 +- lib/librte_eal/common/eal_private.h | 18 - lib/librte_eal/common/include/rte_pci.h | 27 + lib/librte_eal/linuxapp/eal/eal_pci.c | 4 +- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 3 + 15 files changed, 964 insertions(+), 382 deletions(-)
Signature · 1 line
1.9.0
PATCH v7 1/9 virtio: don't set vring address again at queue startup
As we have already set up it at virtio_dev_queue_setup(), and a vq restart will not reset the settings.
--- drivers/net/virtio/virtio_rxtx.c | 15 --------------- 1 file changed, 15 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -15
@@ -339,11 +339,6 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)vq_update_avail_idx (vq);PMD_INIT_LOG (DEBUG ,"Allocated %d bufs" , nbufs); - -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); }else if (queue_type ==VTNET_TQ ) {if (use_simple_rxtx) {int mid_idx = vq->vq_nentries >>1 ;
@@ -362,16 +357,6 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)for (i = mid_idx; i < vq->vq_nentries; i++) vq->vq_ring.avail->ring[i] = i; } - -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); - }else { -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_SEL , - vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (vq->hw,VIRTIO_PCI_QUEUE_PFN , - vq->mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); } }
Signature · 1 line
1.9.0
PATCH v7 2/9 virtio: define offset as size_t type
In reply to Yuanhan Liuoffset arg of vtpci_read/write_dev_config is derived from offsetof(), which is of size_t type, instead of uint64_t. So, define it as size_t type.
--- drivers/net/virtio/virtio_pci.c | 4 ++-- drivers/net/virtio/virtio_pci.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/virtio/virtio_pci.c +2 -2
@@ -38,7 +38,7 @@static uint8_t vtpci_get_status (struct virtio_hw *);void -vtpci_read_dev_config (struct virtio_hw *hw,uint64_t offset, +vtpci_read_dev_config (struct virtio_hw *hw,size_t offset,void *dst,int length) {uint64_t off;
@@ -61,7 +61,7 @@ vtpci_read_dev_config(struct virtio_hw *hw, uint64_t offset, }void -vtpci_write_dev_config (struct virtio_hw *hw,uint64_t offset, +vtpci_write_dev_config (struct virtio_hw *hw,size_t offset,void *src,int length) {uint64_t off;
drivers/net/virtio/virtio_pci.h +2 -2
@@ -261,9 +261,9 @@ void vtpci_set_status(struct virtio_hw *, uint8_t);uint32_t vtpci_negotiate_features (struct virtio_hw *,uint32_t ); -void vtpci_write_dev_config (struct virtio_hw *,uint64_t ,void *,int ); +void vtpci_write_dev_config (struct virtio_hw *,size_t ,void *,int ); -void vtpci_read_dev_config (struct virtio_hw *,uint64_t ,void *,int ); +void vtpci_read_dev_config (struct virtio_hw *,size_t ,void *,int );uint8_t vtpci_isr (struct virtio_hw *);
Signature · 1 line
1.9.0
PATCH v7 3/9 virtio: introduce struct virtio_pci_ops
In reply to Yuanhan LiuIntroduce struct virtio_pci_ops, to let legacy virtio (v0.95) and modern virtio (1.0) have different implementation regarding to a specific pci action, such as read host status.
With that, this patch reimplements all exported pci functions, in a way like:
vtpci_foo_bar(struct virtio_hw *hw)
{
hw->vtpci_ops->foo_bar(hw);
}So that we need pay attention to those pci related functions only while adding virtio 1.0 support.
This patch introduced a new vtpci function, vtpci_init(), to do proper virtio pci settings. It's pretty simple so far: just sets hw->vtpci_ops to legacy_ops as we don't support 1.0 yet.
---
v5: - define "src" arg of vtpci_write_dev_config()
--- drivers/net/virtio/virtio_ethdev.c | 22 ++--- drivers/net/virtio/virtio_pci.c | 164 ++++++++++++++++++++++++++++++------- drivers/net/virtio/virtio_pci.h | 29 ++++++- drivers/net/virtio/virtqueue.h | 2 +- 4 files changed, 170 insertions(+), 47 deletions(-)
drivers/net/virtio/virtio_ethdev.c +8 -14
@@ -272,9 +272,7 @@ virtio_dev_queue_release(struct virtqueue *vq) {if (vq) { hw = vq->hw; -/* Select and deactivate the queue */ -VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vq->vq_queue_index); -VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN ,0 ); + hw->vtpci_ops->del_queue (hw, vq);rte_free (vq->sw_ring);rte_free (vq);
@@ -295,15 +293,13 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,struct virtio_hw *hw = dev->data->dev_private;struct virtqueue *vq =NULL ; -/* Write the virtqueue index to the Queue Select Field */ -VIRTIO_WRITE_REG_2 (hw,VIRTIO_PCI_QUEUE_SEL , vtpci_queue_idx); -PMD_INIT_LOG (DEBUG ,"selecting queue: %u" , vtpci_queue_idx); +PMD_INIT_LOG (DEBUG ,"setting up queue: %u" , vtpci_queue_idx);/* * Read the virtqueue size from the Queue Size field * Always power of 2 and if 0 virtqueue does not exist */ - vq_size =VIRTIO_READ_REG_2 (hw,VIRTIO_PCI_QUEUE_NUM ); + vq_size = hw->vtpci_ops->get_queue_num (hw, vtpci_queue_idx);PMD_INIT_LOG (DEBUG ,"vq_size: %u nb_desc:%u" , vq_size, nb_desc);if (vq_size ==0 ) {PMD_INIT_LOG (ERR ,"%s: virtqueue does not exist" , __func__);
@@ -436,12 +432,8 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,memset (vq->virtio_net_hdr_mz->addr,0 ,PAGE_SIZE ); } -/* -* Set guest physical address of the virtqueue -* in VIRTIO_PCI_QUEUE_PFN config register of device -*/ -VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_QUEUE_PFN , - mz->phys_addr >>VIRTIO_PCI_QUEUE_ADDR_SHIFT ); + hw->vtpci_ops->setup_queue (hw, vq); + *pvq = vq;return 0 ; }
@@ -950,7 +942,7 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features);/* Read device(host) feature bits */ - host_features =VIRTIO_READ_REG_4 (hw,VIRTIO_PCI_HOST_FEATURES ); + host_features = hw->vtpci_ops->get_features (hw);PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %x" , host_features);
@@ -1287,6 +1279,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; +vtpci_init (pci_dev, hw); +if (virtio_resource_init (pci_dev) <0 )return -1 ;
drivers/net/virtio/virtio_pci.c +133 -31
229 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +28 -1
@@ -163,6 +163,31 @@ struct virtqueue;*/ #define VIRTIO_MAX_VIRTQUEUES 8 +struct virtio_hw ; + +struct virtio_pci_ops { +void (*read_dev_cfg)(struct virtio_hw *hw,size_t offset, +void *dst,int len); +void (*write_dev_cfg)(struct virtio_hw *hw,size_t offset, +const void *src,int len); +void (*reset)(struct virtio_hw *hw); + +uint8_t (*get_status)(struct virtio_hw *hw); +void (*set_status)(struct virtio_hw *hw,uint8_t status); + +uint32_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint32_t features); + +uint8_t (*get_isr)(struct virtio_hw *hw); + +uint16_t (*set_config_irq)(struct virtio_hw *hw,uint16_t vec); + +uint16_t (*get_queue_num)(struct virtio_hw *hw,uint16_t queue_id); +void (*setup_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*del_queue)(struct virtio_hw *hw,struct virtqueue *vq); +void (*notify_queue)(struct virtio_hw *hw,struct virtqueue *vq); +}; +struct virtio_hw {struct virtqueue *cvq;uint32_t io_base;
@@ -174,6 +199,7 @@ struct virtio_hw {uint8_t use_msix;uint8_t started;uint8_t mac_addr[ETHER_ADDR_LEN ]; +const struct virtio_pci_ops *vtpci_ops; };/*
@@ -253,6 +279,7 @@ vtpci_with_feature(struct virtio_hw *hw, uint32_t bit)/* * Function declaration from virtio_pci.c */ +int vtpci_init (struct rte_pci_device *,struct virtio_hw *);void vtpci_reset (struct virtio_hw *);void vtpci_reinit_complete (struct virtio_hw *);
@@ -261,7 +288,7 @@ void vtpci_set_status(struct virtio_hw *, uint8_t);uint32_t vtpci_negotiate_features (struct virtio_hw *,uint32_t ); -void vtpci_write_dev_config (struct virtio_hw *,size_t ,void *,int ); +void vtpci_write_dev_config (struct virtio_hw *,size_t ,const void *,int );void vtpci_read_dev_config (struct virtio_hw *,size_t ,void *,int );
drivers/net/virtio/virtqueue.h +1 -1
@@ -302,7 +302,7 @@ virtqueue_notify(struct virtqueue *vq)* For virtio on IA, the notificaiton is through io port operation * which is a serialization instruction itself. */ -VIRTIO_WRITE_REG_2 (vq->hw,VIRTIO_PCI_QUEUE_NOTIFY , vq->vq_queue_index); + vq->hw->vtpci_ops->notify_queue (vq->hw, vq); }#ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP
Signature · 1 line
1.9.0
PATCH v7 4/9 virtio: move left pci stuff to virtio_pci.c
In reply to Yuanhan Liuvirtio_pci.c is a more proper place for pci stuff; virtio_ethdev is not.
--- drivers/net/virtio/virtio_ethdev.c | 265 +----------------------------------- drivers/net/virtio/virtio_pci.c | 272 ++++++++++++++++++++++++++++++++++++- 2 files changed, 272 insertions(+), 265 deletions(-)
drivers/net/virtio/virtio_ethdev.c +1 -264
@@ -36,10 +36,6 @@#include <stdio.h> #include <errno.h> #include <unistd.h> -#ifdef RTE_EXEC_ENV_LINUXAPP -#include <dirent.h> -#include <fcntl.h> -#endif #include <rte_ethdev.h> #include <rte_memcpy.h>
@@ -955,260 +951,6 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features); } -#ifdef RTE_EXEC_ENV_LINUXAPP -static int -parse_sysfs_value (const char *filename,unsigned long *val) -{ -FILE *f; -char buf[BUFSIZ ]; -char *end =NULL ; - - f =fopen (filename,"r" ); -if (f ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): cannot open sysfs value %s" , - __func__, filename); -return -1 ; - } - -if (fgets (buf,sizeof (buf), f) ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): cannot read sysfs value %s" , - __func__, filename); -fclose (f); -return -1 ; - } - *val =strtoul (buf, &end,0 ); -if ((buf[0 ] =='\0' ) || (end ==NULL ) || (*end !='\n' )) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse sysfs value %s" , - __func__, filename); -fclose (f); -return -1 ; - } -fclose (f); -return 0 ; -} - -static int get_uio_dev (struct rte_pci_addr *loc,char *buf,unsigned int buflen, -unsigned int *uio_num) -{ -struct dirent *e; -DIR *dir; -char dirname[PATH_MAX ]; - -/* depending on kernel version, uio can be located in uio/uioX -* or uio:uioX */ -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio" , - loc->domain, loc->bus, loc->devid, loc->function); - dir =opendir (dirname); -if (dir ==NULL ) { -/* retry with the parent directory */ -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT , - loc->domain, loc->bus, loc->devid, loc->function); - dir =opendir (dirname); - -if (dir ==NULL ) { -PMD_INIT_LOG (ERR ,"Cannot opendir %s" , dirname); -return -1 ; - } - } - -/* take the first file starting with "uio" */ -while ((e =readdir (dir)) !=NULL ) { -/* format could be uio%d ...*/ -int shortprefix_len =sizeof ("uio" ) -1 ; -/* ... or uio:uio%d */ -int longprefix_len =sizeof ("uio:uio" ) -1 ; -char *endptr; - -if (strncmp (e->d_name,"uio" ,3 ) !=0 ) -continue ; - -/* first try uio%d */ - errno =0 ; - *uio_num =strtoull (e->d_name + shortprefix_len, &endptr,10 ); -if (errno ==0 && endptr != (e->d_name + shortprefix_len)) { -snprintf (buf, buflen,"%s/uio%u" , dirname, *uio_num); -break ; - } - -/* then try uio:uio%d */ - errno =0 ; - *uio_num =strtoull (e->d_name + longprefix_len, &endptr,10 ); -if (errno ==0 && endptr != (e->d_name + longprefix_len)) { -snprintf (buf, buflen,"%s/uio:uio%u" , dirname, - *uio_num); -break ; - } - } -closedir (dir); - -/* No uio resource found */ -if (e ==NULL ) { -PMD_INIT_LOG (ERR ,"Could not find uio resource" ); -return -1 ; - } - -return 0 ; -} - -static int -virtio_has_msix (const struct rte_pci_addr *loc) -{ -DIR *d; -char dirname[PATH_MAX ]; - -snprintf (dirname,sizeof (dirname), -SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/msi_irqs" , - loc->domain, loc->bus, loc->devid, loc->function); - - d =opendir (dirname); -if (d) -closedir (d); - -return (d !=NULL ); -} - -/* Extract I/O port numbers from sysfs */ -static int virtio_resource_init_by_uio (struct rte_pci_device *pci_dev) -{ -char dirname[PATH_MAX ]; -char filename[PATH_MAX ]; -unsigned long start, size; -unsigned int uio_num; - -if (get_uio_dev (&pci_dev->addr, dirname,sizeof (dirname), &uio_num) <0 ) -return -1 ; - -/* get portio size */ -snprintf (filename,sizeof (filename), -"%s/portio/port0/size" , dirname); -if (parse_sysfs_value (filename, &size) <0 ) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse size" , - __func__); -return -1 ; - } - -/* get portio start */ -snprintf (filename,sizeof (filename), -"%s/portio/port0/start" , dirname); -if (parse_sysfs_value (filename, &start) <0 ) { -PMD_INIT_LOG (ERR ,"%s(): cannot parse portio start" , - __func__); -return -1 ; - } - pci_dev->mem_resource[0 ].addr = (void *)(uintptr_t )start; - pci_dev->mem_resource[0 ].len = (uint64_t )size; -PMD_INIT_LOG (DEBUG , -"PCI Port IO found start=0x%lx with size=0x%lx" , - start, size); - -/* save fd */ -memset (dirname,0 ,sizeof (dirname)); -snprintf (dirname,sizeof (dirname),"/dev/uio%u" , uio_num); - pci_dev->intr_handle.fd =open (dirname,O_RDWR ); -if (pci_dev->intr_handle.fd <0 ) { -PMD_INIT_LOG (ERR ,"Cannot open %s: %s\n" , - dirname,strerror (errno)); -return -1 ; - } - - pci_dev->intr_handle.type =RTE_INTR_HANDLE_UIO ; - pci_dev->driver->drv_flags |=RTE_PCI_DRV_INTR_LSC ; - -return 0 ; -} - -/* Extract port I/O numbers from proc/ioports */ -static int virtio_resource_init_by_ioports (struct rte_pci_device *pci_dev) -{ -uint16_t start, end; -int size; -FILE *fp; -char *line =NULL ; -char pci_id[16 ]; -int found =0 ; -size_t linesz; - -snprintf (pci_id,sizeof (pci_id),PCI_PRI_FMT , - pci_dev->addr.domain, - pci_dev->addr.bus, - pci_dev->addr.devid, - pci_dev->addr.function); - - fp =fopen ("/proc/ioports" ,"r" ); -if (fp ==NULL ) { -PMD_INIT_LOG (ERR ,"%s(): can't open ioports" , __func__); -return -1 ; - } - -while (getdelim (&line, &linesz,'\n' , fp) >0 ) { -char *ptr = line; -char *left; -int n; - - n =strcspn (ptr,":" ); - ptr[n] =0 ; - left = &ptr[n+1 ]; - -while (*left &&isspace (*left)) - left++; - -if (!strncmp (left, pci_id,strlen (pci_id))) { - found =1 ; - -while (*ptr &&isspace (*ptr)) - ptr++; - -sscanf (ptr,"%04hx-%04hx" , &start, &end); - size = end - start +1 ; - -break ; - } - } - -free (line); -fclose (fp); - -if (!found) -return -1 ; - - pci_dev->mem_resource[0 ].addr = (void *)(uintptr_t )(uint32_t )start; - pci_dev->mem_resource[0 ].len = (uint64_t )size; -PMD_INIT_LOG (DEBUG , -"PCI Port IO found start=0x%x with size=0x%x" , - start, size); - -/* can't support lsc interrupt without uio */ - pci_dev->driver->drv_flags &= ~RTE_PCI_DRV_INTR_LSC ; - -return 0 ; -} - -/* Extract I/O port numbers from sysfs */ -static int virtio_resource_init (struct rte_pci_device *pci_dev) -{ -if (virtio_resource_init_by_uio (pci_dev) ==0 ) -return 0 ; -else -return virtio_resource_init_by_ioports (pci_dev); -} - -#else -static int -virtio_has_msix(const struct rte_pci_addr *loc __rte_unused) -{ -/* nic_uio does not enable interrupts, return 0 (false). */ -return 0 ; -} - -static int virtio_resource_init(struct rte_pci_device *pci_dev __rte_unused) -{ -/* no setup required */ -return 0 ; -} -#endif -/* * Process Virtio Config changed interrupt and call the callback * if link state changed.
@@ -1279,14 +1021,9 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; -vtpci_init (pci_dev, hw); - -if (virtio_resource_init (pci_dev) <0 ) +if (vtpci_init (pci_dev, hw) <0 )return -1 ; - hw->use_msix =virtio_has_msix (&pci_dev->addr); - hw->io_base = (uint32_t )(uintptr_t )pci_dev->mem_resource[0 ].addr; -/* Reset the device although not necessary at startup */ vtpci_reset (hw);
drivers/net/virtio/virtio_pci.c +271 -1
292 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH v7 5/9 viritio: switch to 64 bit features
In reply to Yuanhan LiuSwitch to 64 bit features, which virtio 1.0 supports.
While legacy virtio only supports 32 bit features, it complains aloud and quit when trying to setting > 32 bit features.
--- drivers/net/virtio/virtio_ethdev.c | 8 ++++---- drivers/net/virtio/virtio_pci.c | 15 ++++++++++----- drivers/net/virtio/virtio_pci.h | 12 ++++++------ 3 files changed, 20 insertions(+), 15 deletions(-)
drivers/net/virtio/virtio_ethdev.c +4 -4
@@ -930,16 +930,16 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)static void virtio_negotiate_features (struct virtio_hw *hw) { -uint32_t host_features; +uint64_t host_features;/* Prepare guest_features: feature that driver wants to support */ hw->guest_features =VIRTIO_PMD_GUEST_FEATURES ; -PMD_INIT_LOG (DEBUG ,"guest_features before negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"guest_features before negotiate = %" PRIx64, hw->guest_features);/* Read device(host) feature bits */ host_features = hw->vtpci_ops->get_features (hw); -PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"host_features before negotiate = %" PRIx64, host_features);/*
@@ -947,7 +947,7 @@ virtio_negotiate_features(struct virtio_hw *hw)* guest feature bits. */ hw->guest_features =vtpci_negotiate_features (hw, host_features); -PMD_INIT_LOG (DEBUG ,"features after negotiate = %x" , +PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); }
drivers/net/virtio/virtio_pci.c +10 -5
@@ -87,15 +87,20 @@ legacy_write_dev_config(struct virtio_hw *hw, size_t offset, } } -static uint32_t +static uint64_t legacy_get_features (struct virtio_hw *hw) {return VIRTIO_READ_REG_4 (hw,VIRTIO_PCI_HOST_FEATURES ); }static void -legacy_set_features (struct virtio_hw *hw,uint32_t features) +legacy_set_features (struct virtio_hw *hw,uint64_t features) { +if ((features >>32 ) !=0 ) { +PMD_DRV_LOG (ERR , +"only 32 bit features are allowed for legacy virtio!" ); +return ; + }VIRTIO_WRITE_REG_4 (hw,VIRTIO_PCI_GUEST_FEATURES , features); }
@@ -453,10 +458,10 @@ vtpci_write_dev_config(struct virtio_hw *hw, size_t offset, hw->vtpci_ops->write_dev_cfg (hw, offset, src, length); } -uint32_t -vtpci_negotiate_features (struct virtio_hw *hw,uint32_t host_features) +uint64_t +vtpci_negotiate_features (struct virtio_hw *hw,uint64_t host_features) { -uint32_t features; +uint64_t features;/* * Limit negotiated features to what the driver, virtqueue, and
drivers/net/virtio/virtio_pci.h +6 -6
@@ -175,8 +175,8 @@ struct virtio_pci_ops {uint8_t (*get_status)(struct virtio_hw *hw);void (*set_status)(struct virtio_hw *hw,uint8_t status); -uint32_t (*get_features)(struct virtio_hw *hw); -void (*set_features)(struct virtio_hw *hw,uint32_t features); +uint64_t (*get_features)(struct virtio_hw *hw); +void (*set_features)(struct virtio_hw *hw,uint64_t features);uint8_t (*get_isr)(struct virtio_hw *hw);
@@ -191,7 +191,7 @@ struct virtio_pci_ops {struct virtio_hw {struct virtqueue *cvq;uint32_t io_base; -uint32_t guest_features; +uint64_t guest_features;uint32_t max_tx_queues;uint32_t max_rx_queues;uint16_t vtnet_hdr_size;
@@ -271,9 +271,9 @@ outl_p(unsigned int data, unsigned int port) outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg))))static inline int -vtpci_with_feature (struct virtio_hw *hw,uint32_t bit) +vtpci_with_feature (struct virtio_hw *hw,uint64_t bit) { -return (hw->guest_features & (1u << bit)) !=0 ; +return (hw->guest_features & (1ULL << bit)) !=0 ; }/*
@@ -286,7 +286,7 @@ void vtpci_reinit_complete(struct virtio_hw *);void vtpci_set_status (struct virtio_hw *,uint8_t ); -uint32_t vtpci_negotiate_features (struct virtio_hw *,uint32_t ); +uint64_t vtpci_negotiate_features (struct virtio_hw *,uint64_t );void vtpci_write_dev_config (struct virtio_hw *,size_t ,const void *,int );
Signature · 1 line
1.9.0
PATCH v7 6/9 virtio: retrieve hdr_size from hw->vtnet_hdr_size
In reply to Yuanhan LiuThe mergeable virtio net hdr format has been the standard and the only virtio net hdr format since virtio 1.0. Therefore, we can not hardcode hdr_size to "sizeof(struct virtio_net_hdr)" any more at virtio_recv_pkts(), otherwise, there would be a mismatch of hdr size from rte_vhost_enqueue_burst() and virtio_recv_pkts(), leading a packet corruption.
Instead, we should retrieve it from hw->vtnet_hdr_size; we will do proper settings at eth_virtio_dev_init() in later patches.
---
--- drivers/net/virtio/virtio_rxtx.c | 6 ++++-- drivers/net/virtio/virtio_rxtx_simple.c | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/net/virtio/virtio_rxtx.c +4 -2
@@ -560,7 +560,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)struct rte_mbuf *rcv_pkts[VIRTIO_MBUF_BURST_SZ ];int error;uint32_t i, nb_enqueued; -const uint32_t hdr_size =sizeof (struct virtio_net_hdr ); +uint32_t hdr_size; nb_used =VIRTQUEUE_NUSED (rxvq);
@@ -580,6 +580,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) hw = rxvq->hw; nb_rx =0 ; nb_enqueued =0 ; + hdr_size = hw->vtnet_hdr_size;for (i =0 ; i < num ; i++) { rxm = rcv_pkts[i];
@@ -664,7 +665,7 @@ virtio_recv_mergeable_pkts(void *rx_queue,uint32_t seg_num;uint16_t extra_idx;uint32_t seg_res; -const uint32_t hdr_size =sizeof (struct virtio_net_hdr_mrg_rxbuf ); +uint32_t hdr_size; nb_used =VIRTQUEUE_NUSED (rxvq);
@@ -682,6 +683,7 @@ virtio_recv_mergeable_pkts(void *rx_queue, seg_num =0 ; extra_idx =0 ; seg_res =0 ; + hdr_size = hw->vtnet_hdr_size;while (i < nb_used) {struct virtio_net_hdr_mrg_rxbuf *header;
drivers/net/virtio/virtio_rxtx_simple.c +6 -6
@@ -81,9 +81,9 @@ virtqueue_enqueue_recv_refill_simple(struct virtqueue *vq, start_dp = vq->vq_ring.desc; start_dp[desc_idx].addr = (uint64_t )((uintptr_t )cookie->buf_physaddr + -RTE_PKTMBUF_HEADROOM -sizeof (struct virtio_net_hdr )); +RTE_PKTMBUF_HEADROOM - vq->hw->vtnet_hdr_size); start_dp[desc_idx].len = cookie->buf_len - -RTE_PKTMBUF_HEADROOM +sizeof (struct virtio_net_hdr ); +RTE_PKTMBUF_HEADROOM + vq->hw->vtnet_hdr_size; vq->vq_free_cnt--; vq->vq_avail_idx++;
@@ -120,9 +120,9 @@ virtio_rxq_rearm_vec(struct virtqueue *rxvq) start_dp[i].addr = (uint64_t )((uintptr_t )sw_ring[i]->buf_physaddr + -RTE_PKTMBUF_HEADROOM -sizeof (struct virtio_net_hdr )); +RTE_PKTMBUF_HEADROOM - rxvq->hw->vtnet_hdr_size); start_dp[i].len = sw_ring[i]->buf_len - -RTE_PKTMBUF_HEADROOM +sizeof (struct virtio_net_hdr ); +RTE_PKTMBUF_HEADROOM + rxvq->hw->vtnet_hdr_size; } rxvq->vq_avail_idx +=RTE_VIRTIO_VPMD_RX_REARM_THRESH ;
@@ -175,8 +175,8 @@ virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts, len_adjust =_mm_set_epi16 (0 ,0 ,0 , - (uint16_t ) -sizeof (struct virtio_net_hdr ), -0 , (uint16_t ) -sizeof (struct virtio_net_hdr ), + (uint16_t )-rxvq->hw->vtnet_hdr_size, +0 , (uint16_t )-rxvq->hw->vtnet_hdr_size,0 ,0 );if (unlikely (nb_pkts <RTE_VIRTIO_DESC_PER_LOOP ))
Signature · 1 line
1.9.0
PATCH v7 7/9 eal: pci: export pci_[un]map_device
In reply to Yuanhan LiuNormally we could set RTE_PCI_DRV_NEED_MAPPING flag so that eal will invoke pci_map_device internally for us. From that point view, there is no need to export pci_map_device.
However, for virtio pmd driver, which is designed to work without binding UIO (or something similar first), pci_map_device() will fail, which ends up with virtio pmd driver being skipped. Therefore, we can not set RTE_PCI_DRV_NEED_MAPPING blindly at virtio pmd driver.
Therefore, this patch exports pci_map_device, and let virtio pmd call it when necessary.
--- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 ++-- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 ++ lib/librte_eal/common/eal_common_pci.c | 4 ++-- lib/librte_eal/common/eal_private.h | 18 ----------------- lib/librte_eal/common/include/rte_pci.h | 27 +++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 4 ++-- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 3 +++ 7 files changed, 38 insertions(+), 24 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -2
@@ -93,7 +93,7 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)/* Map pci device */ int -pci_map_device (struct rte_pci_device *dev) +rte_eal_pci_map_device (struct rte_pci_device *dev) {int ret =-1 ;
@@ -115,7 +115,7 @@ pci_map_device(struct rte_pci_device *dev)/* Unmap pci device */ void -pci_unmap_device (struct rte_pci_device *dev) +rte_eal_pci_unmap_device (struct rte_pci_device *dev) {/* try unmapping the NIC resources */ switch (dev->kdrv) {
lib/librte_eal/bsdapp/eal/rte_eal_version.map +2 -0
@@ -139,6 +139,8 @@ DPDK_2.2 { DPDK_2.3 { global: + rte_eal_pci_map_device; + rte_eal_pci_unmap_device; rte_cpu_feature_table; } DPDK_2.2;
lib/librte_eal/common/eal_common_pci.c +2 -2
@@ -188,7 +188,7 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dpci_config_space_set (dev);#endif /* map resources for devices that use igb_uio */ - ret =pci_map_device (dev); + ret =rte_eal_pci_map_device (dev);if (ret !=0 )return ret; } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
@@ -254,7 +254,7 @@ rte_eal_pci_detach_dev(struct rte_pci_driver *dr,if (dr->drv_flags &RTE_PCI_DRV_NEED_MAPPING )/* unmap resources for devices that use igb_uio */ -pci_unmap_device (dev); +rte_eal_pci_unmap_device (dev);return 0 ; }
lib/librte_eal/common/eal_private.h +0 -18
@@ -165,24 +165,6 @@ struct rte_pci_device;int pci_unbind_kernel_driver (struct rte_pci_device *dev);/** -* Map this device -* -* This function is private to EAL. -* -* @return -* 0 on success, negative on error and positive if no driver -* is found for the device. -*/ -int pci_map_device (struct rte_pci_device *dev); - -/** -* Unmap this device -* -* This function is private to EAL. -*/ -void pci_unmap_device (struct rte_pci_device *dev); - -/** * Map the PCI resource of a PCI device in virtual memory * * This function is private to EAL.
lib/librte_eal/common/include/rte_pci.h +27 -0
@@ -485,6 +485,33 @@ int rte_eal_pci_read_config(const struct rte_pci_device *device,*/ int rte_eal_pci_write_config (const struct rte_pci_device *device,const void *buf,size_t len,off_t offset); +/** +* Map the PCI device resources in user space virtual memory address +* +* Note that driver should not call this function when flag +* RTE_PCI_DRV_NEED_MAPPING is set, as EAL will do that for +* you when it's on. +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +* +* @return +* 0 on success, negative on error and positive if no driver +* is found for the device. +*/ +int rte_eal_pci_map_device (struct rte_pci_device *dev); + +/** +* Unmap this device +* +* @param dev +* A pointer to a rte_pci_device structure describing the device +* to use +*/ +void rte_eal_pci_unmap_device (struct rte_pci_device *dev); + +#ifdef RTE_PCI_CONFIG /**
lib/librte_eal/linuxapp/eal/eal_pci.c +2 -2
@@ -124,7 +124,7 @@ pci_get_kernel_driver_by_path(const char *filename, char *dri_name)/* Map pci device */ int -pci_map_device (struct rte_pci_device *dev) +rte_eal_pci_map_device (struct rte_pci_device *dev) {int ret =-1 ;
@@ -153,7 +153,7 @@ pci_map_device(struct rte_pci_device *dev)/* Unmap pci device */ void -pci_unmap_device (struct rte_pci_device *dev) +rte_eal_pci_unmap_device (struct rte_pci_device *dev) {/* try unmapping the NIC resources using VFIO if it exists */ switch (dev->kdrv) {
lib/librte_eal/linuxapp/eal/rte_eal_version.map +3 -0
@@ -142,5 +142,8 @@ DPDK_2.2 { DPDK_2.3 { global: + rte_eal_pci_map_device; + rte_eal_pci_unmap_device; rte_cpu_feature_table; + } DPDK_2.2;
Signature · 1 line
1.9.0
PATCH v7 8/9 virtio: add 1.0 support
In reply to Yuanhan LiuModern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the cap.bar and cap.offset fields tell us where to find it.
Firstly, we map the pci resources by rte_eal_pci_map_device(). We then could easily locate a cfg structure by:
cfg_addr = dev->mem_resources[cap.bar].addr + cap.offset;
Therefore, the entrance of enabling modern (v1.0) pci device support is to iterate the pci capability lists, and to locate some configs we care; and they are:
- common cfg
For generic virtio and virtqueue configuration, such as setting/getting features, enabling a specific queue, and so on.
- nofity cfg
Combining with `queue_notify_off' from common cfg, we could use it to notify a specific virt queue.
- device cfg
Where virtio_net_config structure is located.
- isr cfg
Where to read isr (interrupt status).
If any of above cap is not found, we fallback to the legacy virtio handling.
If succeed, hw->vtpci_ops is assigned to modern_ops, where all operations are implemented by reading/writing a (or few) specific configuration space from above 4 cfg structures. And that's basically how this patch works.
Besides those changes, virtio 1.0 introduces a new status field:FEATURES_OK, which is set after features negotiation is done.
Last, set the VIRTIO_F_VERSION_1 feature flag.
---
v6: - unfold DEF_IO_READ/WRITE macros
v5: - rename MODERN_READ/WRITE_DEF macro name to IO_READ/WRITE_DEF
- check offset + length overflow
--- doc/guides/rel_notes/release_2_3.rst | 3 + drivers/net/virtio/virtio_ethdev.c | 25 ++- drivers/net/virtio/virtio_ethdev.h | 3 +- drivers/net/virtio/virtio_pci.c | 355 ++++++++++++++++++++++++++++++++++- drivers/net/virtio/virtio_pci.h | 67 +++++++ drivers/net/virtio/virtqueue.h | 2 + 6 files changed, 450 insertions(+), 5 deletions(-)
doc/guides/rel_notes/release_2_3.rst +3 -0
@@ -4,6 +4,9 @@ DPDK Release 2.3 New Features ------------ +* **Virtio 1.0 support.** + + Enabled virtio 1.0 support for virtio pmd driver. Resolved Issues ---------------
drivers/net/virtio/virtio_ethdev.c +22 -3
@@ -927,7 +927,7 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)return virtio_send_command (hw->cvq, &ctrl, &len,1 ); } -static void +static int virtio_negotiate_features (struct virtio_hw *hw) {uint64_t host_features;
@@ -949,6 +949,22 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features =vtpci_negotiate_features (hw, host_features);PMD_INIT_LOG (DEBUG ,"features after negotiate = %" PRIx64, hw->guest_features); + +if (hw->modern) { +if (!vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) { +PMD_INIT_LOG (ERR , +"VIRTIO_F_VERSION_1 features is not enabled." ); +return -1 ; + } +vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_FEATURES_OK ); +if (!(vtpci_get_status (hw) &VIRTIO_CONFIG_STATUS_FEATURES_OK )) { +PMD_INIT_LOG (ERR , +"failed to set FEATURES_OK status!" ); +return -1 ; + } + } + +return 0 ; }/*
@@ -1032,7 +1048,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)/* Tell the host we've known how to drive the device. */ vtpci_set_status (hw,VIRTIO_CONFIG_STATUS_DRIVER ); -virtio_negotiate_features (hw); +if (virtio_negotiate_features (hw) <0 ) +return -1 ;/* If host does not support status then disable LSC */ if (!vtpci_with_feature (hw,VIRTIO_NET_F_STATUS ))
@@ -1043,7 +1060,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)rx_func_get (eth_dev);/* Setting up rx_header size for the device */ -if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF ) || +vtpci_with_feature (hw,VIRTIO_F_VERSION_1 )) hw->vtnet_hdr_size =sizeof (struct virtio_net_hdr_mrg_rxbuf );else hw->vtnet_hdr_size =sizeof (struct virtio_net_hdr );
@@ -1159,6 +1177,7 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)rte_intr_callback_unregister (&pci_dev->intr_handle, virtio_interrupt_handler, eth_dev); +rte_eal_pci_unmap_device (pci_dev);PMD_INIT_LOG (DEBUG ,"dev_uninit completed" );
drivers/net/virtio/virtio_ethdev.h +2 -1
@@ -64,7 +64,8 @@1u <<VIRTIO_NET_F_CTRL_VQ | \1u <<VIRTIO_NET_F_CTRL_RX | \1u <<VIRTIO_NET_F_CTRL_VLAN | \ - 1u << VIRTIO_NET_F_MRG_RXBUF) +1u <<VIRTIO_NET_F_MRG_RXBUF | \ + 1ULL << VIRTIO_F_VERSION_1)/* * CQ function prototype
drivers/net/virtio/virtio_pci.c +354 -1
387 lines not on this page · raw message
drivers/net/virtio/virtio_pci.h +67 -0
104 lines not on this page · raw message
drivers/net/virtio/virtqueue.h +2 -0
@@ -202,6 +202,8 @@ struct virtqueue {/* Size bins in array as RFC 2819, undersized [0], 64 [1], etc */ uint64_t size_bins[8 ]; +uint16_t *notify_addr; +struct vq_desc_extra {void *cookie;uint16_t ndescs;
Signature · 1 line
1.9.0
PATCH v7 9/9 virtio: move VIRTIO_READ/WRITE_REG_X into virtio_pci.c
In reply to Yuanhan Liuvirtio_pci.c is the only file references those macros; move them there.
--- drivers/net/virtio/virtio_pci.c | 19 +++++++++++++++++++ drivers/net/virtio/virtio_pci.h | 18 ------------------ 2 files changed, 19 insertions(+), 18 deletions(-)
drivers/net/virtio/virtio_pci.c +19 -0
@@ -49,6 +49,25 @@#define PCI_CAPABILITY_LIST 0x34#define PCI_CAP_ID_VNDR 0x09 + +#define VIRTIO_PCI_REG_ADDR (hw, reg) \ + (unsigned short)((hw)->io_base + (reg)) + +#define VIRTIO_READ_REG_1 (hw, reg) \ + inb((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_1 (hw, reg, value) \ + outb_p((unsigned char)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) + +#define VIRTIO_READ_REG_2 (hw, reg) \ + inw((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_2 (hw, reg, value) \ + outw_p((unsigned short)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) + +#define VIRTIO_READ_REG_4 (hw, reg) \ + inl((VIRTIO_PCI_REG_ADDR((hw), (reg)))) +#define VIRTIO_WRITE_REG_4 (hw, reg, value) \ + outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) +static void legacy_read_dev_config (struct virtio_hw *hw,size_t offset,void *dst,int length)
drivers/net/virtio/virtio_pci.h +0 -18
@@ -318,24 +318,6 @@ outl_p(unsigned int data, unsigned int port) }#endif -#define VIRTIO_PCI_REG_ADDR (hw, reg) \ - (unsigned short)((hw)->io_base + (reg)) - -#define VIRTIO_READ_REG_1 (hw, reg) \ - inb((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_1 (hw, reg, value) \ - outb_p((unsigned char)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) - -#define VIRTIO_READ_REG_2 (hw, reg) \ - inw((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_2 (hw, reg, value) \ - outw_p((unsigned short)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) - -#define VIRTIO_READ_REG_4 (hw, reg) \ - inl((VIRTIO_PCI_REG_ADDR((hw), (reg)))) -#define VIRTIO_WRITE_REG_4 (hw, reg, value) \ - outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) -static inline int vtpci_with_feature (struct virtio_hw *hw,uint64_t bit) {
Signature · 1 line
1.9.0
Thomas Monjalon
AppliedRe: [PATCH v7 0/9] virtio 1.0 enabling for virtio pmd driver
In reply to Yuanhan Liu2016-02-02 21:48, Yuanhan Liu:
Quoted 18 lines
v7: - make checkpatch a bit happier; few (false) warnings still left.
- rebase to latest code: fixed a conflict.
v6: unfold IO_READ/WRITE_DEF macro
v5: minor fixes:
- fix wrong type of arg "offset" of read/write_dev_config(): patch 2 is newly added for that.
- check "offset + length" overflow
Almost all difference comes from virtio 1.0 are the PCI layout change:
the major configuration structures are stored at bar space, and their location is stored at corresponding pci cap structure. Reading/parsing them is one of the major work of patch 8.
Quoted 4 lines
To make handling virtio v1.0 and v0.95 co-exist well, this patch set introduces a
virtio_pci_opsstructure, to add another layer so that we could keep thosevtpci_foo_bar"APIs". With that, we could do the minimum change to add virtio 1.0 support.
Applied, thanks