Commit Graph

18 Commits

Author SHA1 Message Date
Thomas Huth 9604efb183 Fix typos in the remaining lib folders
Found with the "codespell" utility.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2023-02-28 16:12:57 +11:00
Alexey Kardashevskiy 7477a174ab virtio: Enable IOMMU
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-05 15:18:54 +11:00
Alexey Kardashevskiy 1aeb125770 virtio-net: Init queues after features negotiation
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-05 14:41:07 +11:00
Alexey Kardashevskiy 300384f3dc virtio: Store queue descriptors in virtio_device
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
2019-12-05 14:41:07 +11:00
Nikunj A Dadhania 685af54d8a virtio-net: rework the driver to support multiple open
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>
2017-08-07 18:24:58 +10:00
Nikunj A Dadhania 070886b669 virtio-net: fix ring handling in receive
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-06-27 12:32:58 +10:00
Nikunj A Dadhania 6e4d62c2eb virtio-net: enable virtio 1.0
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-08 16:40:39 +11:00
Nikunj A Dadhania f83299621c virtio: add and enable 1.0 device setup
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-08 16:40:39 +11:00
Nikunj A Dadhania 5ed17500f0 virtio: get rid of type variable in virtio_device
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-08 16:40:39 +11:00
Nikunj A Dadhania aa9566d2ed virtio-net: move setup-mac to the open routine
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-08 16:40:39 +11:00
Nikunj A Dadhania 31312dcf44 virtio-net: make net_hdr_size a variable
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-08 16:40:39 +11:00
Nikunj A Dadhania d20eb434fe virtio-net: replace vq array with vq_{tx,rx}
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-08 16:40:39 +11:00
Nikunj A Dadhania edc7a480d8 virtio-net: use virtio_fill_desc
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-08 16:40:38 +11:00
Nikunj A Dadhania a936ccce6e virtio-{net,blk,scsi,9p}: use status variable
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-08 16:40:38 +11:00
Nikunj A Dadhania bcdf942b91 virtio: introduce helper for initializing virt queue
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-08 16:40:38 +11:00
Nikunj A Dadhania 805cc24afa virtio: fix code style/design issues.
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>
2016-02-08 16:40:38 +11:00
Nikunj A Dadhania 7bc3d6b7d7 Fix dprintf macros at various points
Signed-off-by: Avik Sil <aviksil@linux.vnet.ibm.com>
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
2013-11-16 13:59:30 +05:30
Avik Sil 46a32aa9c7 Add virtio-net driver in libvirtio
Signed-off-by: Avik Sil <aviksil@linux.vnet.ibm.com>
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
2013-10-04 12:00:13 +05:30