path: root/drivers/net/virtio/virtio_pci.c
AgeCommit message (Collapse)Author
2019-03-12build/linux: rename macro from LINUXAPP to LINUXBruce Richardson
Rename the macro to make things shorter and more comprehensible. For both meson and make builds, keep the old macro around for backward compatibility. Signed-off-by: Bruce Richardson <>
2018-11-14net/virtio: fix unchecked return valueTiwei Bie
Coverity issue: 302861 Fixes: 6ba1f63b5ab0 ("virtio: support specification 1.0") Cc: Signed-off-by: Tiwei Bie <> Reviewed-by: Maxime Coquelin <>
2018-11-05net/virtio: drop duplicated reset methodTiwei Bie
Drop the duplicated reset() method in virtio_pci_ops. Currently vtpci_reset() is implemented on set_status() and get_status() directly. The reset() method in virtio_pci_ops isn't used and its implementation in the legacy device isn't right. Signed-off-by: Tiwei Bie <> Reviewed-by: Maxime Coquelin <>
2018-10-29net/virtio: fix PCI config error handlingBrian Russell
In virtio_read_caps and vtpci_msix_detect, rte_pci_read_config returns the number of bytes read from PCI config or < 0 on error. If less than the expected number of bytes are read then log the failure and return rather than carrying on with garbage. Fixes: 6ba1f63b5ab0 ("virtio: support specification 1.0") Cc: Signed-off-by: Brian Russell <> Signed-off-by: Luca Boccassi <> Reviewed-by: Tiwei Bie <>
2018-01-04drivers: use SPDX tag for Intel copyright filesBruce Richardson
Replace the BSD license header with the SPDX tag for files with only an Intel copyright on them. Signed-off-by: Bruce Richardson <>
2017-11-11net/virtio: fix Rx interrupt with VFIOZhiyong Yang
When running l3fwd-power to test virtio rxq interrupt using vfio pci noiommu mode, startup fails. In the function virtio_read_caps, the code if (flags & PCI_MSIX_ENABLE) intends to double check if vfio msix is enabled or not. However, it is not enable at that time. So use_msix is assigned to "0", not "1", which causes the failure of configuring rxq intr in l3fwd-power. This patch adds the function "vtpci_msix_detect" to detect the status of msix when interrupt changes happen. In the meanwhile, virtio_intr_enable/disable are introduced to wrap rte_intr_enable/disable to enhance the ability to detect msix. use_msix can indicate three different msix status by: VIRTIO_MSIX_NONE (0) VIRTIO_MSIX_DISABLED (1) VIRTIO_MSIX_ENABLED (2) Fixes: cb482cb3a305 ("net/virtio: fix MAC address read") Cc: Signed-off-by: Zhiyong Yang <> Acked-by: Jianfeng Tan <> Acked-by: Maxime Coquelin <>
2017-10-10net/virtio: replace magic number with PCI constantZhiyong Yang
To use macro instead of magic number in order to enhance code readability. Signed-off-by: Zhiyong Yang <> Reviewed-by: Maxime Coquelin <> Acked-by: Yuanhan Liu <>
2017-07-31net/virtio: fix MAC address readJianfeng Tan
When virtio-net devices are bound to uio_pci_generic, we get the wrong mac addr by virtio PMD. The wrong mac addr is a addr that is 4-byte left shift of the correct addr. It's a regression bug introduced by the cleanup patch below. The condition of if we set use_msix should be if msix is actually enabled. Only to check if there is a capability list is not enough. For example, binding a transitional device to uio_pci_device would trigger the wrong assignment of use_msix. To correct that, we also check the flags of msix capability to make sure it's enabled. Fixes: ee1843bd8907 ("net/virtio: remove redundant MSI-X detection") Cc: Reported-by: Vipin Varghese <> Signed-off-by: Jianfeng Tan <> Acked-by: Yuanhan Liu <>
2017-07-09net/virtio: remove device type referenceGaetan Rivet
Signed-off-by: Gaetan Rivet <>
2017-05-05pci: remove eal prefixThomas Monjalon
The PCI code will move to the bus drivers directory. Rename functions from rte_eal_pci_ to rte_pci_ to prepare the move of the driver out of EAL. Signed-off-by: Thomas Monjalon <> Acked-by: Stephen Hemminger <>
2017-04-28net/virtio: remove redundant MSI-X detectionJianfeng Tan
As we already change to use capability list to detect MSI-X, remove the redundant MSI-X detection in legacy devices. Signed-off-by: Jianfeng Tan <> Acked-by: Yuanhan Liu <>
2017-04-28net/virtio: fix LSC settingJianfeng Tan
LSC flag is set in several places, but only the last one takes effect; so we remove the redundant ones and just keep the last one. This also fixes the bug that dev_flags being overwritten by rte_eth_copy_pci_info(), which resets it to 0 unconditionally. Cc: Signed-off-by: Jianfeng Tan <> Acked-by: Yuanhan Liu <>
2017-04-28net/virtio: fix MSI-X for modern devicesJianfeng Tan
The field, use_msix, in struct virtio_hw is not updated for modern device, and is always zero. And now we depend on the status feature and MSI-X to report LSC support (which is also not a correct behavior). As a result, LSC is always disabled for modern devices. To fix this, we just recognize MSI-X capability when going through capability list, and update the info in virtio. Fixes: 6ba1f63b5ab0 ("virtio: support specification 1.0") Cc: Signed-off-by: Jianfeng Tan <> Acked-by: Yuanhan Liu <>
2017-04-19net/virtio: fix queue notifyXiao Wang
According to spec, we should write virtqueue index into the notify address, rather than 1. Besides, some HW backend may rely on the data written to identify which queue need to serve. Fixes: 6ba1f63b5ab0 ("virtio: support specification 1.0") Cc: Signed-off-by: Xiao Wang <> Reviewed-by: Stephen Hemminger <> Acked-by: Yuanhan Liu <>
2017-01-18net/virtio: use I/O device memory read/write APISantosh Shukla
Replace the raw I/O device memory read/write access with eal abstraction for I/O device memory read/write access to fix portability issues across different architectures. Signed-off-by: Santosh Shukla <> Signed-off-by: Jerin Jacob <> Acked-by: Yuanhan Liu <>
2017-01-17net/virtio: add PCI operation for queue/irq bindingJianfeng Tan
Add handler in virtio_pci_ops to set queue/irq bind. Signed-off-by: Jianfeng Tan <> Tested-by: Lei Yao <> Acked-by: Yuanhan Liu <>
2017-01-17net/virtio: invoke method directly for setting IRQ configJianfeng Tan
We need to define a prototype for such wrapper, which makes thing too complicated. Remove wrapper and call set_config_irq directly. Suggested-by: Yuanhan Liu <> Signed-off-by: Jianfeng Tan <> Tested-by: Lei Yao <> Acked-by: Yuanhan Liu <>
2017-01-17net/virtio: do not store PCI device pointer at shared memoryYuanhan Liu
hw->dev, a pointer to pci_dev, was actually not used, until the refactor of decouping from PCI device. This would somehow break the multiple process again, since "hw" is stored at shared memory, while "pci_dev" is not: the primary and secondary process could have different address for it, while just one value is allowed. Thus we should not store it to "hw", instead, we could retrieve it from the "eth_dev->device" field. Fixes: ae34410a8a8a ("ethdev: move info filling of PCI into drivers") Fixes: eac901ce29be ("ethdev: decouple from PCI device") Signed-off-by: Yuanhan Liu <>
2017-01-17net/virtio: fix multiple process supportYuanhan Liu
The introduce of virtio 1.0 support brings yet another set of ops, badly, it's not handled correctly, that it breaks the multiple process support. The issue is the data/function pointer may vary from different processes, and the old used to do one time set (for primary process only). That said, the function pointer the secondary process saw is actually from the primary process space. Accessing it could likely result to a crash. Kudos to the last patches, we now be able to maintain those info that may vary among different process locally, meaning every process could have its own copy for each of them, with the correct value set. And this is what this patch does: - remap the PCI (IO port for legacy device and memory map for modern device) - set vtpci_ops correctly After that, multiple process would work like a charm. (At least, it passed my fuzzy test) Fixes: b8f04520ad71 ("virtio: use PCI ioport API") Fixes: d5bbeefca826 ("virtio: introduce PCI implementation structure") Fixes: 6ba1f63b5ab0 ("virtio: support specification 1.0") Cc: Reported-by: Juho Snellman <> Reported-by: Yaron Illouz <> Signed-off-by: Yuanhan Liu <>
2017-01-17net/virtio: store IO port info locallyYuanhan Liu
Like vtpci_ops, the rte_pci_ioport has to store in local memory. This is basically for the rte_pci_device field is allocated from process local memory, but not from shared memory. Signed-off-by: Yuanhan Liu <>
2017-01-17net/virtio: store PCI operators pointer locallyYuanhan Liu
We used to store the vtpci_ops at virtio_hw structure. The struct, however, is stored in shared memory. That means only one value is allowed. For the multiple process model, however, the address of vtpci_ops should be different among different processes. Take virtio PMD as example, the vtpci_ops is set by the primary process, based on its own process space. If we access that address from the secondary process, that would be an illegal memory access, A crash then might happen. To make the multiple process model work, we need store the vtpci_ops in local memory but not in a shared memory. This is what the patch does: a local virtio_hw_internal array of size RTE_MAX_ETHPORTS is allocated. This new structure is used to store all these kind of info in a non-shared memory. Current, we have: - vtpci_ops - rte_pci_ioport - virtio pci mapped memory, such as common_cfg. The later two will be done in coming patches. Later patches would also set them correctly for secondary process, so that the multiple process model could work. Signed-off-by: Yuanhan Liu <>
2016-10-03pci: create device list and fallback on its membersJan Viktorin
Now that rte_device is available, drivers can start using its members (numa, name) as well as link themselves into another rte_device list. As of now no one is using this list, but can be used for moving over all devices (pdev/vdev/Xdev) and perform bulk actions (like cleanup). Signed-off-by: Jan Viktorin <> [Shreyansh: Reword commit log for extra rte_device list] Signed-off-by: Shreyansh Jain <> Acked-by: David Marchand <>
2016-06-22net/virtio: hide vring address check inside PCI opsJianfeng Tan
This patch moves phys addr check from virtio_dev_queue_setup to pci ops. To make that happen, make sure virtio_ops.setup_queue return the result if we pass through the check. Signed-off-by: Jianfeng Tan <> Signed-off-by: Huawei Xie <> Acked-by: Yuanhan Liu <>
2016-06-22net/virtio: fix crash when no devargsHuawei Xie
We skip kernel managed virtio devices, if it isn't whitelisted. Before checking if the virtio device is whitelisted, check if devargs is specified. Fixes: ac5e1d838dc1 ("virtio: skip error when probing kernel managed device") Reported-by: Vincent Li <> Signed-off-by: Huawei Xie <> Acked-by: Yuanhan Liu <>
2016-06-22net/virtio: split Rx/Tx queueHuawei Xie
We keep a common vq structure, containing only vq related fields, and then split others into RX, TX and control queue respectively. Signed-off-by: Huawei Xie <> [Jianfeng Tan: found and fixed 2 bugs] Acked-by: Yuanhan Liu <>
2016-06-15virtio: fix PCI accesses for ppc64 in legacy modeDavid Marchand
Although ppc supports both endianesses, qemu supposes that the cpu is big endian and enforces this for the virtio-net stuff. Fix PCI accesses in legacy mode. Only ppc64le is supported at the moment. Signed-off-by: David Marchand <> Signed-off-by: Olivier Matz <>
2016-06-13pci: allow to override sysfs pathJan Viktorin
The SYSFS_PCI_DEVICES is a constant that makes the PCI testing difficult as it points to an absolute path. We remove using this constant and introducing a function pci_get_sysfs_path that gives the same value. However, the user can pass a SYSFS_PCI_DEVICES env variable to override the path. It is now possible to create a fake sysfs hierarchy for testing. Signed-off-by: Jan Viktorin <>
2016-05-10virtio: fix overwritten driver flagsJianfeng Tan
The "drv_flags" is set with device as the input, which means different device (say, modern vs legacy) could end up with a different value. And the fact that "drv_flags" is shared by all devices means that every time we add a new device, it simply overwrites the value configured from the last device. Therefore, when two virtio devices have different flags, it may lead to wrong result, such as virtio would set irq config when it's not supported. Making the flag per device (using "dev->data->dev_flags") could let us have different value for each device, which would avoid the above issue. Fixes: da978dfdc43 ("virtio: use port IO to get PCI resource") Reported-by: David Marchand <> Suggested-by: David Marchand <> Signed-off-by: Jianfeng Tan <> Acked-by: David Marchand <> Acked-by: Yuanhan Liu <>
2016-03-14virtio: fix query of legacy featuresYuanhan Liu
Declare dst as type uint32_t instead of uint64_t, otherwise, we will get a random upper 32 bit feature bits, as the following io port read reads lower 32 bit only. It could lead a feature bits that include VIRTIO_F_VERSION_1 (the 32th bit) for legacy virtio, which is obviously wrong. Fixes: b8f04520ad71 ("virtio: use PCI ioport API") Signed-off-by: Yuanhan Liu <> Acked-by: Jianfeng Tan <> Reviewed-by: David Marchand <>
2016-03-10virtio: skip error when probing kernel managed deviceHuawei Xie
virtio PMD could use IO port to configure the virtio device without using UIO/VFIO driver in legacy mode. There are two issues with previous implementation: 1) virtio PMD will take over the virtio device(s) blindly even if not intended for DPDK. 2) driver conflict between virtio PMD and virtio-net kernel driver. This patch checks if there is kernel driver other than UIO/VFIO managing the virtio device before using port IO. If legacy_virtio_resource_init fails and kernel driver other than VFIO/UIO is managing the device, return 1 to tell the upper layer we don't take over this device. For all other IO port mapping errors, return -1. Note than if VFIO/UIO fails, now we don't fall back to port IO. Fixes: da978dfdc43b ("virtio: use port IO to get PCI resource") Signed-off-by: Huawei Xie <> Acked-by: Yuanhan Liu <> Acked-by: David Marchand <>
2016-02-16virtio: use PCI ioport APIDavid Marchand
Move all os / arch specifics to eal. Signed-off-by: David Marchand <> Reviewed-by: Santosh Shukla <> Tested-by: Santosh Shukla <> Acked-by: Yuanhan Liu <>
2016-02-16virtio: fix check when mapping PCI resourcesDavid Marchand
According to the api, rte_eal_pci_map_device is only successful when returning 0. Fixes: 6ba1f63b5ab0 ("virtio: support specification 1.0") Signed-off-by: David Marchand <> Acked-by: Yuanhan Liu <>
2016-02-16virtio: fix FreeBSD buildDavid Marchand
Fixes: c52afa68d763 ("virtio: move left PCI stuff in the right file") Signed-off-by: David Marchand <> Acked-by: Yuanhan Liu <>
2016-02-10remove extra parentheses in return statementHuawei Xie
fix the error reported by checkpatch: "ERROR: return is not a function, parentheses are not required" remove parentheses in return like: "return (logical expressions)" remove parentheses in return a function like: "return (rte_mempool_lookup(...))" Fixes: 6307b909b8e0 ("lib: remove extra parenthesis after return") Signed-off-by: Huawei Xie <>
2016-02-03virtio: move ioport macrosYuanhan Liu
virtio_pci.c is the only file references macros VIRTIO_READ/WRITE_REG_X. Move them there. Signed-off-by: Yuanhan Liu <> Tested-by: Qian Xu <> Reviewed-by: Tetsuya Mukawa <> Tested-by: Tetsuya Mukawa <> Acked-by: Huawei Xie <>
2016-02-03virtio: support specification 1.0Yuanhan Liu
Modern (v1.0) virtio pci device defines several pci capabilities. Each cap has a configure structure corresponding to it, and the 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[].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. Signed-off-by: Yuanhan Liu <> Tested-by: Qian Xu <> Reviewed-by: Tetsuya Mukawa <> Tested-by: Tetsuya Mukawa <> Acked-by: Huawei Xie <>
2016-02-03virtio: switch to 64 bit featuresYuanhan Liu
Switch 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. Signed-off-by: Yuanhan Liu <> Tested-by: Qian Xu <> Reviewed-by: Tetsuya Mukawa <> Tested-by: Tetsuya Mukawa <> Acked-by: Huawei Xie <>
2016-02-03virtio: move left PCI stuff in the right fileYuanhan Liu
virtio_pci.c is a more proper place for pci stuff; virtio_ethdev is not. Signed-off-by: Yuanhan Liu <> Tested-by: Qian Xu <> Reviewed-by: Tetsuya Mukawa <> Tested-by: Tetsuya Mukawa <> Acked-by: Huawei Xie <>
2016-02-03virtio: introduce PCI implementation structureYuanhan Liu
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. Signed-off-by: Yuanhan Liu <> Tested-by: Qian Xu <> Reviewed-by: Tetsuya Mukawa <> Tested-by: Tetsuya Mukawa <> Acked-by: Huawei Xie <>
2016-02-03virtio: define offset as size_t typeYuanhan Liu
offset 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. Signed-off-by: Yuanhan Liu <> Tested-by: Qian Xu <> Reviewed-by: Tetsuya Mukawa <> Tested-by: Tetsuya Mukawa <> Acked-by: Huawei Xie <>
2015-05-22virtio: move to drivers/net/Bruce Richardson
Move virtio PMD to drivers/net directory Signed-off-by: Bruce Richardson <> Acked-by: John McNamara <> Acked-by: Thomas Monjalon <>