aboutsummaryrefslogtreecommitdiff
path: root/lib/libvirtio/virtio-net.c
AgeCommit message (Collapse)AuthorFilesLines
2019-12-05virtio: Enable IOMMUAlexey Kardashevskiy1-1/+4
When QEMU is started with iommu_platform=on, the guest driver must accept it or the device will fail. This enables IOMMU support for virtio-net, -scsi, -block, -serial, -9p devices. -serial and -9p are only compile tested though. For virtio-net we map all RX buffers once and TX when xmit() is called and unmap older pages when we are about to reuse the VQ descriptor. As all other devices are synchronous, we unmap IOMMU pages right after completion of a transaction. This depends on QEMU's: https://patchwork.ozlabs.org/patch/1194067/ Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Tested-by: Michael Roth <mdroth@linux.vnet.ibm.com> --- Changes: v5: * fixed queue size calculation * reworked virtio_free_desc() to only unmap what is has mapped v4: * ditched vqs->id in virtio_queue_init_vq v2: * added Mike's fs/dma-instance-function.fs * total rework
2019-12-05virtio-net: Init queues after features negotiationAlexey Kardashevskiy1-13/+14
Every virtio device negotiates virtio protocol features before setting up internal queue descriptors with one exception which is virtio-net. This moves virtio_queue_init_vq() later to have feature negotiation happened sooner. This is going to be used for IOMMU setup later. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
2019-12-05virtio: Store queue descriptors in virtio_deviceAlexey Kardashevskiy1-14/+13
At the moment desc/avail/used pointers are read from the device every time we need them. This works for now unless iommu_platform=on is used, desc/avail/used stored in the config space are bus addresses while SLOF should keep using the guest physical addresses. virtio-net stores queue descriptors already, virtio-serial does it in global statics, move them into virtio_device. The next patch will use this to allow IOMMU. While at this, move repeating avail->flags/idx setup into virtio_queue_init_vq() except virtio-serial which vq_rx->avail->idx is setup differently. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> --- Changes: v4: * removed vqs::id as it is not really used * replaced vq_size with vq->size in virtio-serial.c
2017-08-07virtio-net: rework the driver to support multiple openNikunj A Dadhania1-77/+95
Found that virtio-net is using a around 200K receive buffer per device, if we connect more than 40 virtio-net devices the heap(8MB) gets over. Because of which allocation starts failing and the VM does not boot. Moreover, the driver did not support opening multiple device, which is possible using the OF client interface. As it was using globals to store the state information of the driver. Now the driver allocates a virtio_net structure during device open stage and fills in the state information. This details are used during various device functions and finally for cleaning up on close operation. Now as the buffer memory is allocated during open and freed during the close operations the heap usage is contained. Reported-by: Satheesh Rajendran <sathnaga@linux.vnet.ibm.com> Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-06-27virtio-net: fix ring handling in receiveNikunj A Dadhania1-2/+4
A bug crept in while doing the virtio 1.0 enablement in commit 6e4d62c2 (virtio-net: enable virtio 1.0) + idx = virtio_modern16_to_cpu(&virtiodev, vq_rx.used->idx); [...] - vq_rx.avail->ring[vq_rx.avail->idx % vq_rx.size] = id - 1; + vq_rx.avail->ring[idx % vq_rx.size] = virtio_cpu_to_modern16(&virtiodev, id - 1); sync(); - vq_rx.avail->idx += 1; + vq_rx.avail->idx = virtio_cpu_to_modern16(&virtiodev, idx + 1); Should be using avail->idx in place of used->idx. Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08virtio-net: enable virtio 1.0Nikunj A Dadhania1-33/+61
Also add a device file for non-transitional pci device id: 0x1041 Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08virtio: add and enable 1.0 device setupNikunj A Dadhania1-1/+2
Introduce parsing routines for virtio capabilities. This would also determine whether we need to function in legacy mode or virtio 1.0. Update routine to start using the base address from the updated legacy structure. With the removal for base address setting in the Forth code and most of the device setup happening in C code, code in virtio.fs is redundant. Remove virtio.fs and move the allocation of the virtio_device structure to the C code instead of the Forth code in individual files. Also, drop the packed attribute for the virtio_{device,cap} structure. The structure is not shared anymore. Drivers need to negotiate the 1.0 feature capability before starting to use 1.0. Disable it in all the drivers until 1.0 is enabled. Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08virtio: get rid of type variable in virtio_deviceNikunj A Dadhania1-1/+0
virtio device structure carries a type variable indicating whether virtio is over PCI or VIO. While VIO is not there and no plan to introduce other transport, there is no purpose of having this variable around and checking for PCI. Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08virtio-net: move setup-mac to the open routineNikunj A Dadhania1-3/+4
MAC reading should be done after the initialization of the device after the features negotiation. Adjust the open routine accordingly. There is no point in sending the mac address to the virtionet_open. Change the signature. Also read the mac address directly from the config space to remove the dependency of getting the mac address from the open routine. Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08virtio-net: make net_hdr_size a variableNikunj A Dadhania1-9/+12
Size of the net_hdr_size is different in legacy and modern devices. This helps in conversion of the driver to 1.0. Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08virtio-net: replace vq array with vq_{tx,rx}Nikunj A Dadhania1-29/+30
Using an array here is not necassary, simplifies the code for readability. Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08virtio-net: use virtio_fill_descNikunj A Dadhania1-24/+11
Simplifies the driver code and is helpful for migration to virtio 1.0 enablement. Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08virtio-{net,blk,scsi,9p}: use status variableNikunj A Dadhania1-6/+10
The virtio_set_status lines were getting too long because of OR'ing the status on the same line of the call. Moreover, going forward we need to add FEATURES_OK status as well. The state progress is quite straight forward, so use status variable instead. Code looks cleaner and can easily make out the change in the state. Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08virtio: introduce helper for initializing virt queueNikunj A Dadhania1-37/+5
The routine takes care to allocate and set the queue address in the device. Add these calls in virtio-net, virtio-blk and virtio-9p. With the lack of this routine, devices like virtio-blk and virtio-9p did not do a device reset in the driver initialization code. This helper will fix that problem Change the signature of virtio_set_qaddr, accepting queue address as unsigned long argument. Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08virtio: fix code style/design issues.Nikunj A Dadhania1-1/+1
The patch does not make any functional changes. Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2013-11-16Fix dprintf macros at various pointsNikunj A Dadhania1-1/+1
Signed-off-by: Avik Sil <aviksil@linux.vnet.ibm.com> Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
2013-10-04Add virtio-net driver in libvirtioAvik Sil1-0/+369
Signed-off-by: Avik Sil <aviksil@linux.vnet.ibm.com> Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>