Commit Graph

16 Commits

Author SHA1 Message Date
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 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 69a2f9ae1a virtio: 1.0 guest features negotiation
With virtio 1.0, there feature negotiation step needs to be completed
before starting to notify the device.

This includes following steps:
* Read host supported features
* Check if virtio 1.0 is supported
* Set guest supported features
* Read host features and compare with the guest features.
* Write FEATURES_OK and check it back to confirm.

Add virtio_get_status supporting 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 940ac04abe virtio: update features set/get register accessor
The new specification has a 64-bit feature register, change the
signature and update the routine to handle them.

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 e3a281624b virtio: make all virtio apis 1.0 aware
Convert the following routines:
    virtio_get_qsize
    virtio_vring_desc
    virtio_get_vring_avail
    virtio_get_vring_used
    virtio_set_status: also use it in device reset.
    virtio_queue_notify
    virtio_set_qaddr
    virtio_{get,read}_config
    virtio_fill_desc

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 66c156d0de virtio: add 64-bit virtio helpers for 1.0
64-bit fields are to be treated as two 32-bit fields, with low 32 bit
part followed by the high 32 bit part.

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 ff9b0bd159 virtio: add virtio 1.0 related struct and defines
Traditionally, struct virtio_device is shared between SLOF and C code.
This still remains shared with the addition of virtio_cap structure as
well. Now both virtio_device and virtio_cap structures are shared.

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 fdb62149dc virtio-blk: add helpers for filling descriptors
Enable virtio_fill_desc/fill_blk_hdr with legacy and modern mode for
further use

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
Alexey Kardashevskiy 750aec6ff6 virtio: Fix vring allocation
The value returned by virtio_vring_size() is used to allocate memory
for vring. The used descriptor list (array of vring_used_elem) is
counted by the header - vring_used struct - is not.

This fixes virtio_vring_size() to return the correct size.
At the moment rings are quite small (256) and allocated with
4096 alignment, this is why we have not been having issues with
this so far.

Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Reviewed-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
Changes:
v2:
* remove magic numbers
2015-03-13 22:31:11 +11:00
Nikunj A Dadhania c365fe0393 virtio-blk: support variable block size
Current code only works with 512 bytes read.

Moreover, Qemu ignores the guest set features request. In the set
features request SLOF indicates to qemu that it is not support
VIRTIO_BLK_F_BLK_SIZE feature. Code in qemu suggests that virtio-blk
is not implementing set_guest_feature.

Tested-by: Bharata B Rao <bharata@linux.ibm.com>
Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
2014-04-25 15:40:13 +05:30
Nikunj A. Dadhania a35e44f0e6 virtio: Add a virtio-set-qaddr helper
A simple function that can be used from forth code for setting
virtqueue address. virito-scsi has multiple virtqueues(atleast 3) and
need to use set queue address for all the 3 queues.

Signed-off-by: Nikunj A. Dadhania <nikunj@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-05-21 15:13:45 +10:00
Benjamin Herrenschmidt 44e8d9a57d Add virtfs support
Code originally written by Timothy Rule and reworked &
bug fixed by myself

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2012-01-19 17:17:50 +11:00
Benjamin Herrenschmidt ca610c931e Move virtio to a separate library
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2012-01-19 17:17:50 +11:00