* [Qemu-devel] [PATCH v2 01/17] scripts/update-linux-headers.sh: pull virtio hdrs
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
@ 2015-02-15 11:38 ` Michael S. Tsirkin
2015-02-16 14:27 ` Thomas Huth
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 02/17] include: import virtio headers from linux 4.0 Michael S. Tsirkin
` (17 subsequent siblings)
18 siblings, 1 reply; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:38 UTC (permalink / raw)
To: qemu-devel
Cc: Cornelia Huck, Peter Maydell, Alexander Graf, Stefan Hajnoczi,
Chen, Tiejun
It doesn't make sense to copy values manually:
the only issue with getting headers from linux
seems to be dealing with linux/types, we
can easily fix that automatically while importing.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
| 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
--git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
index c8e026d..738e590 100755
--- a/scripts/update-linux-headers.sh
+++ b/scripts/update-linux-headers.sh
@@ -76,4 +76,37 @@ else
cp "$linux/COPYING" "$output/linux-headers"
fi
+
+rm -rf "$output/include/standard-headers/sys"
+mkdir -p "$output/include/standard-headers/sys"
+for f in $tmpdir/include/linux/virtio*h; do
+ if
+ grep '#include' "$f" | grep -v -e 'linux/virtio' \
+ -e 'linux/types' \
+ -e 'linux/if_ether' \
+ > /dev/null
+ then
+ echo "Unexpected #include in input file $f".
+ exit 2
+ fi
+
+ header=$(expr "$f" : '.*/\(.*\)');
+ sed -e 's/__u\([0-9][0-9]*\)/uint\1_t/g' \
+ -e 's/__le\([0-9][0-9]*\)/uint\1_t/g' \
+ -e 's/__be\([0-9][0-9]*\)/uint\1_t/g' \
+ -e 's/<linux\/\([^>]*\)>/"standard-headers\/sys\/\1"/' \
+ -e 's/__bitwise__//' \
+ -e 's/__attribute__((packed))/QEMU_PACKED/' \
+ "$tmpdir/include/linux/$header" > \
+ "$output/include/standard-headers/sys/$header";
+done
+
+cat <<EOF >$output/include/standard-headers/sys/types.h
+#include <inttypes.h>
+#include "qemu/compiler.h"
+EOF
+cat <<EOF >$output/include/standard-headers/sys/if_ether.h
+#define ETH_ALEN 6
+EOF
+
rm -rf "$tmpdir"
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 01/17] scripts/update-linux-headers.sh: pull virtio hdrs
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 01/17] scripts/update-linux-headers.sh: pull virtio hdrs Michael S. Tsirkin
@ 2015-02-16 14:27 ` Thomas Huth
0 siblings, 0 replies; 36+ messages in thread
From: Thomas Huth @ 2015-02-16 14:27 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Peter Maydell, qemu-devel, Alexander Graf, Stefan Hajnoczi,
Cornelia Huck, Chen, Tiejun
On Sun, 15 Feb 2015 12:38:34 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> It doesn't make sense to copy values manually:
> the only issue with getting headers from linux
> seems to be dealing with linux/types, we
> can easily fix that automatically while importing.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> scripts/update-linux-headers.sh | 33 +++++++++++++++++++++++++++++++++
> 1 file changed, 33 insertions(+)
>
> diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
> index c8e026d..738e590 100755
> --- a/scripts/update-linux-headers.sh
> +++ b/scripts/update-linux-headers.sh
> @@ -76,4 +76,37 @@ else
> cp "$linux/COPYING" "$output/linux-headers"
> fi
>
> +
> +rm -rf "$output/include/standard-headers/sys"
> +mkdir -p "$output/include/standard-headers/sys"
> +for f in $tmpdir/include/linux/virtio*h; do
> + if
> + grep '#include' "$f" | grep -v -e 'linux/virtio' \
> + -e 'linux/types' \
> + -e 'linux/if_ether' \
> + > /dev/null
> + then
> + echo "Unexpected #include in input file $f".
> + exit 2
> + fi
> +
> + header=$(expr "$f" : '.*/\(.*\)');
I think you could also use "basename $f" instead - that would be
easier to read.
> + sed -e 's/__u\([0-9][0-9]*\)/uint\1_t/g' \
> + -e 's/__le\([0-9][0-9]*\)/uint\1_t/g' \
> + -e 's/__be\([0-9][0-9]*\)/uint\1_t/g' \
> + -e 's/<linux\/\([^>]*\)>/"standard-headers\/sys\/\1"/' \
> + -e 's/__bitwise__//' \
> + -e 's/__attribute__((packed))/QEMU_PACKED/' \
> + "$tmpdir/include/linux/$header" > \
> + "$output/include/standard-headers/sys/$header";
> +done
> +
> +cat <<EOF >$output/include/standard-headers/sys/types.h
> +#include <inttypes.h>
This is just about getting the uintxx_t types, right? If so, I think it
is also sufficient to just include <stdint.h> instead.
> +#include "qemu/compiler.h"
> +EOF
> +cat <<EOF >$output/include/standard-headers/sys/if_ether.h
> +#define ETH_ALEN 6
> +EOF
> +
> rm -rf "$tmpdir"
Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
^ permalink raw reply [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 02/17] include: import virtio headers from linux 4.0
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 01/17] scripts/update-linux-headers.sh: pull virtio hdrs Michael S. Tsirkin
@ 2015-02-15 11:38 ` Michael S. Tsirkin
2015-02-16 16:03 ` Thomas Huth
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 03/17] virtio: use standard virtio_ring.h Michael S. Tsirkin
` (16 subsequent siblings)
18 siblings, 1 reply; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:38 UTC (permalink / raw)
To: qemu-devel
Cc: Cornelia Huck, Peter Maydell, Alexander Graf, Stefan Hajnoczi,
Chen, Tiejun
Add files imported from linux-next (what will become linux 4.0) using
scripts/update-linux-headers.sh
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/standard-headers/sys/if_ether.h | 1 +
include/standard-headers/sys/types.h | 2 +
include/standard-headers/sys/virtio_9p.h | 44 +++++
include/standard-headers/sys/virtio_balloon.h | 59 +++++++
include/standard-headers/sys/virtio_blk.h | 143 ++++++++++++++++
include/standard-headers/sys/virtio_config.h | 64 +++++++
include/standard-headers/sys/virtio_console.h | 78 +++++++++
include/standard-headers/sys/virtio_ids.h | 43 +++++
include/standard-headers/sys/virtio_net.h | 233 ++++++++++++++++++++++++++
include/standard-headers/sys/virtio_pci.h | 193 +++++++++++++++++++++
include/standard-headers/sys/virtio_ring.h | 171 +++++++++++++++++++
include/standard-headers/sys/virtio_rng.h | 8 +
include/standard-headers/sys/virtio_scsi.h | 164 ++++++++++++++++++
include/standard-headers/sys/virtio_types.h | 46 +++++
14 files changed, 1249 insertions(+)
create mode 100644 include/standard-headers/sys/if_ether.h
create mode 100644 include/standard-headers/sys/types.h
create mode 100644 include/standard-headers/sys/virtio_9p.h
create mode 100644 include/standard-headers/sys/virtio_balloon.h
create mode 100644 include/standard-headers/sys/virtio_blk.h
create mode 100644 include/standard-headers/sys/virtio_config.h
create mode 100644 include/standard-headers/sys/virtio_console.h
create mode 100644 include/standard-headers/sys/virtio_ids.h
create mode 100644 include/standard-headers/sys/virtio_net.h
create mode 100644 include/standard-headers/sys/virtio_pci.h
create mode 100644 include/standard-headers/sys/virtio_ring.h
create mode 100644 include/standard-headers/sys/virtio_rng.h
create mode 100644 include/standard-headers/sys/virtio_scsi.h
create mode 100644 include/standard-headers/sys/virtio_types.h
diff --git a/include/standard-headers/sys/if_ether.h b/include/standard-headers/sys/if_ether.h
new file mode 100644
index 0000000..91cf735
--- /dev/null
+++ b/include/standard-headers/sys/if_ether.h
@@ -0,0 +1 @@
+#define ETH_ALEN 6
diff --git a/include/standard-headers/sys/types.h b/include/standard-headers/sys/types.h
new file mode 100644
index 0000000..7d42ac6
--- /dev/null
+++ b/include/standard-headers/sys/types.h
@@ -0,0 +1,2 @@
+#include <inttypes.h>
+#include "qemu/compiler.h"
diff --git a/include/standard-headers/sys/virtio_9p.h b/include/standard-headers/sys/virtio_9p.h
new file mode 100644
index 0000000..19df0e4
--- /dev/null
+++ b/include/standard-headers/sys/virtio_9p.h
@@ -0,0 +1,44 @@
+#ifndef _LINUX_VIRTIO_9P_H
+#define _LINUX_VIRTIO_9P_H
+/* This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+#include "standard-headers/sys/types.h"
+#include "standard-headers/sys/virtio_ids.h"
+#include "standard-headers/sys/virtio_config.h"
+
+/* The feature bitmap for virtio 9P */
+
+/* The mount point is specified in a config variable */
+#define VIRTIO_9P_MOUNT_TAG 0
+
+struct virtio_9p_config {
+ /* length of the tag name */
+ uint16_t tag_len;
+ /* non-NULL terminated tag name */
+ uint8_t tag[0];
+} QEMU_PACKED;
+
+#endif /* _LINUX_VIRTIO_9P_H */
diff --git a/include/standard-headers/sys/virtio_balloon.h b/include/standard-headers/sys/virtio_balloon.h
new file mode 100644
index 0000000..9392a0a
--- /dev/null
+++ b/include/standard-headers/sys/virtio_balloon.h
@@ -0,0 +1,59 @@
+#ifndef _LINUX_VIRTIO_BALLOON_H
+#define _LINUX_VIRTIO_BALLOON_H
+/* This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+#include "standard-headers/sys/virtio_ids.h"
+#include "standard-headers/sys/virtio_config.h"
+
+/* The feature bitmap for virtio balloon */
+#define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */
+#define VIRTIO_BALLOON_F_STATS_VQ 1 /* Memory Stats virtqueue */
+#define VIRTIO_BALLOON_F_DEFLATE_ON_OOM 2 /* Deflate balloon on OOM */
+
+/* Size of a PFN in the balloon interface. */
+#define VIRTIO_BALLOON_PFN_SHIFT 12
+
+struct virtio_balloon_config {
+ /* Number of pages host wants Guest to give up. */
+ uint32_t num_pages;
+ /* Number of pages we've actually got in balloon. */
+ uint32_t actual;
+};
+
+#define VIRTIO_BALLOON_S_SWAP_IN 0 /* Amount of memory swapped in */
+#define VIRTIO_BALLOON_S_SWAP_OUT 1 /* Amount of memory swapped out */
+#define VIRTIO_BALLOON_S_MAJFLT 2 /* Number of major faults */
+#define VIRTIO_BALLOON_S_MINFLT 3 /* Number of minor faults */
+#define VIRTIO_BALLOON_S_MEMFREE 4 /* Total amount of free memory */
+#define VIRTIO_BALLOON_S_MEMTOT 5 /* Total amount of memory */
+#define VIRTIO_BALLOON_S_NR 6
+
+struct virtio_balloon_stat {
+ uint16_t tag;
+ uint64_t val;
+} QEMU_PACKED;
+
+#endif /* _LINUX_VIRTIO_BALLOON_H */
diff --git a/include/standard-headers/sys/virtio_blk.h b/include/standard-headers/sys/virtio_blk.h
new file mode 100644
index 0000000..80c46f0
--- /dev/null
+++ b/include/standard-headers/sys/virtio_blk.h
@@ -0,0 +1,143 @@
+#ifndef _LINUX_VIRTIO_BLK_H
+#define _LINUX_VIRTIO_BLK_H
+/* This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+#include "standard-headers/sys/types.h"
+#include "standard-headers/sys/virtio_ids.h"
+#include "standard-headers/sys/virtio_config.h"
+#include "standard-headers/sys/virtio_types.h"
+
+/* Feature bits */
+#define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
+#define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
+#define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */
+#define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
+#define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
+#define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */
+#define VIRTIO_BLK_F_MQ 12 /* support more than one vq */
+
+/* Legacy feature bits */
+#ifndef VIRTIO_BLK_NO_LEGACY
+#define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
+#define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
+#define VIRTIO_BLK_F_WCE 9 /* Writeback mode enabled after reset */
+#define VIRTIO_BLK_F_CONFIG_WCE 11 /* Writeback mode available in config */
+/* Old (deprecated) name for VIRTIO_BLK_F_WCE. */
+#define VIRTIO_BLK_F_FLUSH VIRTIO_BLK_F_WCE
+#endif /* !VIRTIO_BLK_NO_LEGACY */
+
+#define VIRTIO_BLK_ID_BYTES 20 /* ID string length */
+
+struct virtio_blk_config {
+ /* The capacity (in 512-byte sectors). */
+ uint64_t capacity;
+ /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */
+ uint32_t size_max;
+ /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
+ uint32_t seg_max;
+ /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */
+ struct virtio_blk_geometry {
+ uint16_t cylinders;
+ uint8_t heads;
+ uint8_t sectors;
+ } geometry;
+
+ /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
+ uint32_t blk_size;
+
+ /* the next 4 entries are guarded by VIRTIO_BLK_F_TOPOLOGY */
+ /* exponent for physical block per logical block. */
+ uint8_t physical_block_exp;
+ /* alignment offset in logical blocks. */
+ uint8_t alignment_offset;
+ /* minimum I/O size without performance penalty in logical blocks. */
+ uint16_t min_io_size;
+ /* optimal sustained I/O size in logical blocks. */
+ uint32_t opt_io_size;
+
+ /* writeback mode (if VIRTIO_BLK_F_CONFIG_WCE) */
+ uint8_t wce;
+ uint8_t unused;
+
+ /* number of vqs, only available when VIRTIO_BLK_F_MQ is set */
+ uint16_t num_queues;
+} QEMU_PACKED;
+
+/*
+ * Command types
+ *
+ * Usage is a bit tricky as some bits are used as flags and some are not.
+ *
+ * Rules:
+ * VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or
+ * VIRTIO_BLK_T_BARRIER. VIRTIO_BLK_T_FLUSH is a command of its own
+ * and may not be combined with any of the other flags.
+ */
+
+/* These two define direction. */
+#define VIRTIO_BLK_T_IN 0
+#define VIRTIO_BLK_T_OUT 1
+
+#ifndef VIRTIO_BLK_NO_LEGACY
+/* This bit says it's a scsi command, not an actual read or write. */
+#define VIRTIO_BLK_T_SCSI_CMD 2
+#endif /* VIRTIO_BLK_NO_LEGACY */
+
+/* Cache flush command */
+#define VIRTIO_BLK_T_FLUSH 4
+
+/* Get device ID command */
+#define VIRTIO_BLK_T_GET_ID 8
+
+#ifndef VIRTIO_BLK_NO_LEGACY
+/* Barrier before this op. */
+#define VIRTIO_BLK_T_BARRIER 0x80000000
+#endif /* !VIRTIO_BLK_NO_LEGACY */
+
+/* This is the first element of the read scatter-gather list. */
+struct virtio_blk_outhdr {
+ /* VIRTIO_BLK_T* */
+ __virtio32 type;
+ /* io priority. */
+ __virtio32 ioprio;
+ /* Sector (ie. 512 byte offset) */
+ __virtio64 sector;
+};
+
+#ifndef VIRTIO_BLK_NO_LEGACY
+struct virtio_scsi_inhdr {
+ __virtio32 errors;
+ __virtio32 data_len;
+ __virtio32 sense_len;
+ __virtio32 residual;
+};
+#endif /* !VIRTIO_BLK_NO_LEGACY */
+
+/* And this is the final byte of the write scatter-gather list. */
+#define VIRTIO_BLK_S_OK 0
+#define VIRTIO_BLK_S_IOERR 1
+#define VIRTIO_BLK_S_UNSUPP 2
+#endif /* _LINUX_VIRTIO_BLK_H */
diff --git a/include/standard-headers/sys/virtio_config.h b/include/standard-headers/sys/virtio_config.h
new file mode 100644
index 0000000..72c4a80
--- /dev/null
+++ b/include/standard-headers/sys/virtio_config.h
@@ -0,0 +1,64 @@
+#ifndef _LINUX_VIRTIO_CONFIG_H
+#define _LINUX_VIRTIO_CONFIG_H
+/* This header, excluding the #ifdef __KERNEL__ part, is BSD licensed so
+ * anyone can use the definitions to implement compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+
+/* Virtio devices use a standardized configuration space to define their
+ * features and pass configuration information, but each implementation can
+ * store and access that space differently. */
+#include "standard-headers/sys/types.h"
+
+/* Status byte for guest to report progress, and synchronize features. */
+/* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
+#define VIRTIO_CONFIG_S_ACKNOWLEDGE 1
+/* We have found a driver for the device. */
+#define VIRTIO_CONFIG_S_DRIVER 2
+/* Driver has used its parts of the config, and is happy */
+#define VIRTIO_CONFIG_S_DRIVER_OK 4
+/* Driver has finished configuring features */
+#define VIRTIO_CONFIG_S_FEATURES_OK 8
+/* We've given up on this device. */
+#define VIRTIO_CONFIG_S_FAILED 0x80
+
+/* Some virtio feature bits (currently bits 28 through 32) are reserved for the
+ * transport being used (eg. virtio_ring), the rest are per-device feature
+ * bits. */
+#define VIRTIO_TRANSPORT_F_START 28
+#define VIRTIO_TRANSPORT_F_END 33
+
+#ifndef VIRTIO_CONFIG_NO_LEGACY
+/* Do we get callbacks when the ring is completely used, even if we've
+ * suppressed them? */
+#define VIRTIO_F_NOTIFY_ON_EMPTY 24
+
+/* Can the device handle any descriptor layout? */
+#define VIRTIO_F_ANY_LAYOUT 27
+#endif /* VIRTIO_CONFIG_NO_LEGACY */
+
+/* v1.0 compliant. */
+#define VIRTIO_F_VERSION_1 32
+
+#endif /* _LINUX_VIRTIO_CONFIG_H */
diff --git a/include/standard-headers/sys/virtio_console.h b/include/standard-headers/sys/virtio_console.h
new file mode 100644
index 0000000..c23dbee
--- /dev/null
+++ b/include/standard-headers/sys/virtio_console.h
@@ -0,0 +1,78 @@
+/*
+ * This header, excluding the #ifdef __KERNEL__ part, is BSD licensed so
+ * anyone can use the definitions to implement compatible drivers/servers:
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Copyright (C) Red Hat, Inc., 2009, 2010, 2011
+ * Copyright (C) Amit Shah <amit.shah@redhat.com>, 2009, 2010, 2011
+ */
+#ifndef _LINUX_VIRTIO_CONSOLE_H
+#define _LINUX_VIRTIO_CONSOLE_H
+#include "standard-headers/sys/types.h"
+#include "standard-headers/sys/virtio_types.h"
+#include "standard-headers/sys/virtio_ids.h"
+#include "standard-headers/sys/virtio_config.h"
+
+/* Feature bits */
+#define VIRTIO_CONSOLE_F_SIZE 0 /* Does host provide console size? */
+#define VIRTIO_CONSOLE_F_MULTIPORT 1 /* Does host provide multiple ports? */
+#define VIRTIO_CONSOLE_F_EMERG_WRITE 2 /* Does host support emergency write? */
+
+#define VIRTIO_CONSOLE_BAD_ID (~(uint32_t)0)
+
+struct virtio_console_config {
+ /* colums of the screens */
+ uint16_t cols;
+ /* rows of the screens */
+ uint16_t rows;
+ /* max. number of ports this device can hold */
+ uint32_t max_nr_ports;
+ /* emergency write register */
+ uint32_t emerg_wr;
+} QEMU_PACKED;
+
+/*
+ * A message that's passed between the Host and the Guest for a
+ * particular port.
+ */
+struct virtio_console_control {
+ __virtio32 id; /* Port number */
+ __virtio16 event; /* The kind of control event (see below) */
+ __virtio16 value; /* Extra information for the key */
+};
+
+/* Some events for control messages */
+#define VIRTIO_CONSOLE_DEVICE_READY 0
+#define VIRTIO_CONSOLE_PORT_ADD 1
+#define VIRTIO_CONSOLE_PORT_REMOVE 2
+#define VIRTIO_CONSOLE_PORT_READY 3
+#define VIRTIO_CONSOLE_CONSOLE_PORT 4
+#define VIRTIO_CONSOLE_RESIZE 5
+#define VIRTIO_CONSOLE_PORT_OPEN 6
+#define VIRTIO_CONSOLE_PORT_NAME 7
+
+
+#endif /* _LINUX_VIRTIO_CONSOLE_H */
diff --git a/include/standard-headers/sys/virtio_ids.h b/include/standard-headers/sys/virtio_ids.h
new file mode 100644
index 0000000..284fc3a
--- /dev/null
+++ b/include/standard-headers/sys/virtio_ids.h
@@ -0,0 +1,43 @@
+#ifndef _LINUX_VIRTIO_IDS_H
+#define _LINUX_VIRTIO_IDS_H
+/*
+ * Virtio IDs
+ *
+ * This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+
+#define VIRTIO_ID_NET 1 /* virtio net */
+#define VIRTIO_ID_BLOCK 2 /* virtio block */
+#define VIRTIO_ID_CONSOLE 3 /* virtio console */
+#define VIRTIO_ID_RNG 4 /* virtio rng */
+#define VIRTIO_ID_BALLOON 5 /* virtio balloon */
+#define VIRTIO_ID_RPMSG 7 /* virtio remote processor messaging */
+#define VIRTIO_ID_SCSI 8 /* virtio scsi */
+#define VIRTIO_ID_9P 9 /* 9p virtio console */
+#define VIRTIO_ID_RPROC_SERIAL 11 /* virtio remoteproc serial link */
+#define VIRTIO_ID_CAIF 12 /* Virtio caif */
+
+#endif /* _LINUX_VIRTIO_IDS_H */
diff --git a/include/standard-headers/sys/virtio_net.h b/include/standard-headers/sys/virtio_net.h
new file mode 100644
index 0000000..f3d94f5
--- /dev/null
+++ b/include/standard-headers/sys/virtio_net.h
@@ -0,0 +1,233 @@
+#ifndef _LINUX_VIRTIO_NET_H
+#define _LINUX_VIRTIO_NET_H
+/* This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+#include "standard-headers/sys/types.h"
+#include "standard-headers/sys/virtio_ids.h"
+#include "standard-headers/sys/virtio_config.h"
+#include "standard-headers/sys/virtio_types.h"
+#include "standard-headers/sys/if_ether.h"
+
+/* The feature bitmap for virtio net */
+#define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */
+#define VIRTIO_NET_F_GUEST_CSUM 1 /* Guest handles pkts w/ partial csum */
+#define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */
+#define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */
+#define VIRTIO_NET_F_GUEST_TSO6 8 /* Guest can handle TSOv6 in. */
+#define VIRTIO_NET_F_GUEST_ECN 9 /* Guest can handle TSO[6] w/ ECN in. */
+#define VIRTIO_NET_F_GUEST_UFO 10 /* Guest can handle UFO in. */
+#define VIRTIO_NET_F_HOST_TSO4 11 /* Host can handle TSOv4 in. */
+#define VIRTIO_NET_F_HOST_TSO6 12 /* Host can handle TSOv6 in. */
+#define VIRTIO_NET_F_HOST_ECN 13 /* Host can handle TSO[6] w/ ECN in. */
+#define VIRTIO_NET_F_HOST_UFO 14 /* Host can handle UFO in. */
+#define VIRTIO_NET_F_MRG_RXBUF 15 /* Host can merge receive buffers. */
+#define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */
+#define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */
+#define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */
+#define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering */
+#define VIRTIO_NET_F_CTRL_RX_EXTRA 20 /* Extra RX mode control support */
+#define VIRTIO_NET_F_GUEST_ANNOUNCE 21 /* Guest can announce device on the
+ * network */
+#define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow
+ * Steering */
+#define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */
+
+#ifndef VIRTIO_NET_NO_LEGACY
+#define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */
+#endif /* VIRTIO_NET_NO_LEGACY */
+
+#define VIRTIO_NET_S_LINK_UP 1 /* Link is up */
+#define VIRTIO_NET_S_ANNOUNCE 2 /* Announcement is needed */
+
+struct virtio_net_config {
+ /* The config defining mac address (if VIRTIO_NET_F_MAC) */
+ uint8_t mac[ETH_ALEN];
+ /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */
+ uint16_t status;
+ /* Maximum number of each of transmit and receive queues;
+ * see VIRTIO_NET_F_MQ and VIRTIO_NET_CTRL_MQ.
+ * Legal values are between 1 and 0x8000
+ */
+ uint16_t max_virtqueue_pairs;
+} QEMU_PACKED;
+
+#ifndef VIRTIO_NET_NO_LEGACY
+/* This header comes first in the scatter-gather list.
+ * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, it must
+ * be the first element of the scatter-gather list. If you don't
+ * specify GSO or CSUM features, you can simply ignore the header. */
+struct virtio_net_hdr {
+#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 // Use csum_start, csum_offset
+#define VIRTIO_NET_HDR_F_DATA_VALID 2 // Csum is valid
+ uint8_t flags;
+#define VIRTIO_NET_HDR_GSO_NONE 0 // Not a GSO frame
+#define VIRTIO_NET_HDR_GSO_TCPV4 1 // GSO frame, IPv4 TCP (TSO)
+#define VIRTIO_NET_HDR_GSO_UDP 3 // GSO frame, IPv4 UDP (UFO)
+#define VIRTIO_NET_HDR_GSO_TCPV6 4 // GSO frame, IPv6 TCP
+#define VIRTIO_NET_HDR_GSO_ECN 0x80 // TCP has ECN set
+ uint8_t gso_type;
+ __virtio16 hdr_len; /* Ethernet + IP + tcp/udp hdrs */
+ __virtio16 gso_size; /* Bytes to append to hdr_len per frame */
+ __virtio16 csum_start; /* Position to start checksumming from */
+ __virtio16 csum_offset; /* Offset after that to place checksum */
+};
+
+/* This is the version of the header to use when the MRG_RXBUF
+ * feature has been negotiated. */
+struct virtio_net_hdr_mrg_rxbuf {
+ struct virtio_net_hdr hdr;
+ __virtio16 num_buffers; /* Number of merged rx buffers */
+};
+#else /* ... VIRTIO_NET_NO_LEGACY */
+/*
+ * This header comes first in the scatter-gather list. If you don't
+ * specify GSO or CSUM features, you can simply ignore the header.
+ *
+ * This is bitwise-equivalent to the legacy struct virtio_net_hdr_mrg_rxbuf.
+ */
+struct virtio_net_hdr_v1 {
+#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 /* Use csum_start, csum_offset */
+#define VIRTIO_NET_HDR_F_DATA_VALID 2 /* Csum is valid */
+ uint8_t flags;
+#define VIRTIO_NET_HDR_GSO_NONE 0 /* Not a GSO frame */
+#define VIRTIO_NET_HDR_GSO_TCPV4 1 /* GSO frame, IPv4 TCP (TSO) */
+#define VIRTIO_NET_HDR_GSO_UDP 3 /* GSO frame, IPv4 UDP (UFO) */
+#define VIRTIO_NET_HDR_GSO_TCPV6 4 /* GSO frame, IPv6 TCP */
+#define VIRTIO_NET_HDR_GSO_ECN 0x80 /* TCP has ECN set */
+ uint8_t gso_type;
+ __virtio16 hdr_len; /* Ethernet + IP + tcp/udp hdrs */
+ __virtio16 gso_size; /* Bytes to append to hdr_len per frame */
+ __virtio16 csum_start; /* Position to start checksumming from */
+ __virtio16 csum_offset; /* Offset after that to place checksum */
+ __virtio16 num_buffers; /* Number of merged rx buffers */
+};
+#endif /* ...VIRTIO_NET_NO_LEGACY */
+
+/*
+ * Control virtqueue data structures
+ *
+ * The control virtqueue expects a header in the first sg entry
+ * and an ack/status response in the last entry. Data for the
+ * command goes in between.
+ */
+struct virtio_net_ctrl_hdr {
+ uint8_t class;
+ uint8_t cmd;
+} QEMU_PACKED;
+
+typedef uint8_t virtio_net_ctrl_ack;
+
+#define VIRTIO_NET_OK 0
+#define VIRTIO_NET_ERR 1
+
+/*
+ * Control the RX mode, ie. promisucous, allmulti, etc...
+ * All commands require an "out" sg entry containing a 1 byte
+ * state value, zero = disable, non-zero = enable. Commands
+ * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature.
+ * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA.
+ */
+#define VIRTIO_NET_CTRL_RX 0
+ #define VIRTIO_NET_CTRL_RX_PROMISC 0
+ #define VIRTIO_NET_CTRL_RX_ALLMULTI 1
+ #define VIRTIO_NET_CTRL_RX_ALLUNI 2
+ #define VIRTIO_NET_CTRL_RX_NOMULTI 3
+ #define VIRTIO_NET_CTRL_RX_NOUNI 4
+ #define VIRTIO_NET_CTRL_RX_NOBCAST 5
+
+/*
+ * Control the MAC
+ *
+ * The MAC filter table is managed by the hypervisor, the guest should
+ * assume the size is infinite. Filtering should be considered
+ * non-perfect, ie. based on hypervisor resources, the guest may
+ * received packets from sources not specified in the filter list.
+ *
+ * In addition to the class/cmd header, the TABLE_SET command requires
+ * two out scatterlists. Each contains a 4 byte count of entries followed
+ * by a concatenated byte stream of the ETH_ALEN MAC addresses. The
+ * first sg list contains unicast addresses, the second is for multicast.
+ * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature
+ * is available.
+ *
+ * The ADDR_SET command requests one out scatterlist, it contains a
+ * 6 bytes MAC address. This functionality is present if the
+ * VIRTIO_NET_F_CTRL_MAC_ADDR feature is available.
+ */
+struct virtio_net_ctrl_mac {
+ __virtio32 entries;
+ uint8_t macs[][ETH_ALEN];
+} QEMU_PACKED;
+
+#define VIRTIO_NET_CTRL_MAC 1
+ #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0
+ #define VIRTIO_NET_CTRL_MAC_ADDR_SET 1
+
+/*
+ * Control VLAN filtering
+ *
+ * The VLAN filter table is controlled via a simple ADD/DEL interface.
+ * VLAN IDs not added may be filterd by the hypervisor. Del is the
+ * opposite of add. Both commands expect an out entry containing a 2
+ * byte VLAN ID. VLAN filterting is available with the
+ * VIRTIO_NET_F_CTRL_VLAN feature bit.
+ */
+#define VIRTIO_NET_CTRL_VLAN 2
+ #define VIRTIO_NET_CTRL_VLAN_ADD 0
+ #define VIRTIO_NET_CTRL_VLAN_DEL 1
+
+/*
+ * Control link announce acknowledgement
+ *
+ * The command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that
+ * driver has recevied the notification; device would clear the
+ * VIRTIO_NET_S_ANNOUNCE bit in the status field after it receives
+ * this command.
+ */
+#define VIRTIO_NET_CTRL_ANNOUNCE 3
+ #define VIRTIO_NET_CTRL_ANNOUNCE_ACK 0
+
+/*
+ * Control Receive Flow Steering
+ *
+ * The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET
+ * enables Receive Flow Steering, specifying the number of the transmit and
+ * receive queues that will be used. After the command is consumed and acked by
+ * the device, the device will not steer new packets on receive virtqueues
+ * other than specified nor read from transmit virtqueues other than specified.
+ * Accordingly, driver should not transmit new packets on virtqueues other than
+ * specified.
+ */
+struct virtio_net_ctrl_mq {
+ __virtio16 virtqueue_pairs;
+};
+
+#define VIRTIO_NET_CTRL_MQ 4
+ #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 0
+ #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1
+ #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000
+
+#endif /* _LINUX_VIRTIO_NET_H */
diff --git a/include/standard-headers/sys/virtio_pci.h b/include/standard-headers/sys/virtio_pci.h
new file mode 100644
index 0000000..dbfcc94
--- /dev/null
+++ b/include/standard-headers/sys/virtio_pci.h
@@ -0,0 +1,193 @@
+/*
+ * Virtio PCI driver
+ *
+ * This module allows virtio devices to be used over a virtual PCI device.
+ * This can be used with QEMU based VMMs like KVM or Xen.
+ *
+ * Copyright IBM Corp. 2007
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_VIRTIO_PCI_H
+#define _LINUX_VIRTIO_PCI_H
+
+#include "standard-headers/sys/types.h"
+
+#ifndef VIRTIO_PCI_NO_LEGACY
+
+/* A 32-bit r/o bitmask of the features supported by the host */
+#define VIRTIO_PCI_HOST_FEATURES 0
+
+/* A 32-bit r/w bitmask of features activated by the guest */
+#define VIRTIO_PCI_GUEST_FEATURES 4
+
+/* A 32-bit r/w PFN for the currently selected queue */
+#define VIRTIO_PCI_QUEUE_PFN 8
+
+/* A 16-bit r/o queue size for the currently selected queue */
+#define VIRTIO_PCI_QUEUE_NUM 12
+
+/* A 16-bit r/w queue selector */
+#define VIRTIO_PCI_QUEUE_SEL 14
+
+/* A 16-bit r/w queue notifier */
+#define VIRTIO_PCI_QUEUE_NOTIFY 16
+
+/* An 8-bit device status register. */
+#define VIRTIO_PCI_STATUS 18
+
+/* An 8-bit r/o interrupt status register. Reading the value will return the
+ * current contents of the ISR and will also clear it. This is effectively
+ * a read-and-acknowledge. */
+#define VIRTIO_PCI_ISR 19
+
+/* MSI-X registers: only enabled if MSI-X is enabled. */
+/* A 16-bit vector for configuration changes. */
+#define VIRTIO_MSI_CONFIG_VECTOR 20
+/* A 16-bit vector for selected queue notifications. */
+#define VIRTIO_MSI_QUEUE_VECTOR 22
+
+/* The remaining space is defined by each driver as the per-driver
+ * configuration space */
+#define VIRTIO_PCI_CONFIG_OFF(msix_enabled) ((msix_enabled) ? 24 : 20)
+/* Deprecated: please use VIRTIO_PCI_CONFIG_OFF instead */
+#define VIRTIO_PCI_CONFIG(dev) VIRTIO_PCI_CONFIG_OFF((dev)->msix_enabled)
+
+/* Virtio ABI version, this must match exactly */
+#define VIRTIO_PCI_ABI_VERSION 0
+
+/* How many bits to shift physical queue address written to QUEUE_PFN.
+ * 12 is historical, and due to x86 page size. */
+#define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12
+
+/* The alignment to use between consumer and producer parts of vring.
+ * x86 pagesize again. */
+#define VIRTIO_PCI_VRING_ALIGN 4096
+
+#endif /* VIRTIO_PCI_NO_LEGACY */
+
+/* The bit of the ISR which indicates a device configuration change. */
+#define VIRTIO_PCI_ISR_CONFIG 0x2
+/* Vector value used to disable MSI for queue */
+#define VIRTIO_MSI_NO_VECTOR 0xffff
+
+#ifndef VIRTIO_PCI_NO_MODERN
+
+/* IDs for different capabilities. Must all exist. */
+
+/* Common configuration */
+#define VIRTIO_PCI_CAP_COMMON_CFG 1
+/* Notifications */
+#define VIRTIO_PCI_CAP_NOTIFY_CFG 2
+/* ISR access */
+#define VIRTIO_PCI_CAP_ISR_CFG 3
+/* Device specific configuration */
+#define VIRTIO_PCI_CAP_DEVICE_CFG 4
+/* PCI configuration access */
+#define VIRTIO_PCI_CAP_PCI_CFG 5
+
+/* This is the PCI capability header: */
+struct virtio_pci_cap {
+ uint8_t cap_vndr; /* Generic PCI field: PCI_CAP_ID_VNDR */
+ uint8_t cap_next; /* Generic PCI field: next ptr. */
+ uint8_t cap_len; /* Generic PCI field: capability length */
+ uint8_t cfg_type; /* Identifies the structure. */
+ uint8_t bar; /* Where to find it. */
+ uint8_t padding[3]; /* Pad to full dword. */
+ uint32_t offset; /* Offset within bar. */
+ uint32_t length; /* Length of the structure, in bytes. */
+};
+
+struct virtio_pci_notify_cap {
+ struct virtio_pci_cap cap;
+ uint32_t notify_off_multiplier; /* Multiplier for queue_notify_off. */
+};
+
+/* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */
+struct virtio_pci_common_cfg {
+ /* About the whole device. */
+ uint32_t device_feature_select; /* read-write */
+ uint32_t device_feature; /* read-only */
+ uint32_t guest_feature_select; /* read-write */
+ uint32_t guest_feature; /* read-write */
+ uint16_t msix_config; /* read-write */
+ uint16_t num_queues; /* read-only */
+ uint8_t device_status; /* read-write */
+ uint8_t config_generation; /* read-only */
+
+ /* About a specific virtqueue. */
+ uint16_t queue_select; /* read-write */
+ uint16_t queue_size; /* read-write, power of 2. */
+ uint16_t queue_msix_vector; /* read-write */
+ uint16_t queue_enable; /* read-write */
+ uint16_t queue_notify_off; /* read-only */
+ uint32_t queue_desc_lo; /* read-write */
+ uint32_t queue_desc_hi; /* read-write */
+ uint32_t queue_avail_lo; /* read-write */
+ uint32_t queue_avail_hi; /* read-write */
+ uint32_t queue_used_lo; /* read-write */
+ uint32_t queue_used_hi; /* read-write */
+};
+
+/* Macro versions of offsets for the Old Timers! */
+#define VIRTIO_PCI_CAP_VNDR 0
+#define VIRTIO_PCI_CAP_NEXT 1
+#define VIRTIO_PCI_CAP_LEN 2
+#define VIRTIO_PCI_CAP_CFG_TYPE 3
+#define VIRTIO_PCI_CAP_BAR 4
+#define VIRTIO_PCI_CAP_OFFSET 8
+#define VIRTIO_PCI_CAP_LENGTH 12
+
+#define VIRTIO_PCI_NOTIFY_CAP_MULT 16
+
+#define VIRTIO_PCI_COMMON_DFSELECT 0
+#define VIRTIO_PCI_COMMON_DF 4
+#define VIRTIO_PCI_COMMON_GFSELECT 8
+#define VIRTIO_PCI_COMMON_GF 12
+#define VIRTIO_PCI_COMMON_MSIX 16
+#define VIRTIO_PCI_COMMON_NUMQ 18
+#define VIRTIO_PCI_COMMON_STATUS 20
+#define VIRTIO_PCI_COMMON_CFGGENERATION 21
+#define VIRTIO_PCI_COMMON_Q_SELECT 22
+#define VIRTIO_PCI_COMMON_Q_SIZE 24
+#define VIRTIO_PCI_COMMON_Q_MSIX 26
+#define VIRTIO_PCI_COMMON_Q_ENABLE 28
+#define VIRTIO_PCI_COMMON_Q_NOFF 30
+#define VIRTIO_PCI_COMMON_Q_DESCLO 32
+#define VIRTIO_PCI_COMMON_Q_DESCHI 36
+#define VIRTIO_PCI_COMMON_Q_AVAILLO 40
+#define VIRTIO_PCI_COMMON_Q_AVAILHI 44
+#define VIRTIO_PCI_COMMON_Q_USEDLO 48
+#define VIRTIO_PCI_COMMON_Q_USEDHI 52
+
+#endif /* VIRTIO_PCI_NO_MODERN */
+
+#endif
diff --git a/include/standard-headers/sys/virtio_ring.h b/include/standard-headers/sys/virtio_ring.h
new file mode 100644
index 0000000..a268aec
--- /dev/null
+++ b/include/standard-headers/sys/virtio_ring.h
@@ -0,0 +1,171 @@
+#ifndef _LINUX_VIRTIO_RING_H
+#define _LINUX_VIRTIO_RING_H
+/* An interface for efficient virtio implementation, currently for use by KVM
+ * and lguest, but hopefully others soon. Do NOT change this since it will
+ * break existing servers and clients.
+ *
+ * This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Copyright Rusty Russell IBM Corporation 2007. */
+#include "standard-headers/sys/types.h"
+#include "standard-headers/sys/virtio_types.h"
+
+/* This marks a buffer as continuing via the next field. */
+#define VRING_DESC_F_NEXT 1
+/* This marks a buffer as write-only (otherwise read-only). */
+#define VRING_DESC_F_WRITE 2
+/* This means the buffer contains a list of buffer descriptors. */
+#define VRING_DESC_F_INDIRECT 4
+
+/* The Host uses this in used->flags to advise the Guest: don't kick me when
+ * you add a buffer. It's unreliable, so it's simply an optimization. Guest
+ * will still kick if it's out of buffers. */
+#define VRING_USED_F_NO_NOTIFY 1
+/* The Guest uses this in avail->flags to advise the Host: don't interrupt me
+ * when you consume a buffer. It's unreliable, so it's simply an
+ * optimization. */
+#define VRING_AVAIL_F_NO_INTERRUPT 1
+
+/* We support indirect buffer descriptors */
+#define VIRTIO_RING_F_INDIRECT_DESC 28
+
+/* The Guest publishes the used index for which it expects an interrupt
+ * at the end of the avail ring. Host should ignore the avail->flags field. */
+/* The Host publishes the avail index for which it expects a kick
+ * at the end of the used ring. Guest should ignore the used->flags field. */
+#define VIRTIO_RING_F_EVENT_IDX 29
+
+/* Virtio ring descriptors: 16 bytes. These can chain together via "next". */
+struct vring_desc {
+ /* Address (guest-physical). */
+ __virtio64 addr;
+ /* Length. */
+ __virtio32 len;
+ /* The flags as indicated above. */
+ __virtio16 flags;
+ /* We chain unused descriptors via this, too */
+ __virtio16 next;
+};
+
+struct vring_avail {
+ __virtio16 flags;
+ __virtio16 idx;
+ __virtio16 ring[];
+};
+
+/* u32 is used here for ids for padding reasons. */
+struct vring_used_elem {
+ /* Index of start of used descriptor chain. */
+ __virtio32 id;
+ /* Total length of the descriptor chain which was used (written to) */
+ __virtio32 len;
+};
+
+struct vring_used {
+ __virtio16 flags;
+ __virtio16 idx;
+ struct vring_used_elem ring[];
+};
+
+struct vring {
+ unsigned int num;
+
+ struct vring_desc *desc;
+
+ struct vring_avail *avail;
+
+ struct vring_used *used;
+};
+
+/* Alignment requirements for vring elements.
+ * When using pre-virtio 1.0 layout, these fall out naturally.
+ */
+#define VRING_AVAIL_ALIGN_SIZE 2
+#define VRING_USED_ALIGN_SIZE 4
+#define VRING_DESC_ALIGN_SIZE 16
+
+/* The standard layout for the ring is a continuous chunk of memory which looks
+ * like this. We assume num is a power of 2.
+ *
+ * struct vring
+ * {
+ * // The actual descriptors (16 bytes each)
+ * struct vring_desc desc[num];
+ *
+ * // A ring of available descriptor heads with free-running index.
+ * __virtio16 avail_flags;
+ * __virtio16 avail_idx;
+ * __virtio16 available[num];
+ * __virtio16 used_event_idx;
+ *
+ * // Padding to the next align boundary.
+ * char pad[];
+ *
+ * // A ring of used descriptor heads with free-running index.
+ * __virtio16 used_flags;
+ * __virtio16 used_idx;
+ * struct vring_used_elem used[num];
+ * __virtio16 avail_event_idx;
+ * };
+ */
+/* We publish the used event index at the end of the available ring, and vice
+ * versa. They are at the end for backwards compatibility. */
+#define vring_used_event(vr) ((vr)->avail->ring[(vr)->num])
+#define vring_avail_event(vr) (*(__virtio16 *)&(vr)->used->ring[(vr)->num])
+
+static __inline__ void vring_init(struct vring *vr, unsigned int num, void *p,
+ unsigned long align)
+{
+ vr->num = num;
+ vr->desc = p;
+ vr->avail = p + num*sizeof(struct vring_desc);
+ vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(__virtio16)
+ + align-1) & ~(align - 1));
+}
+
+static __inline__ unsigned vring_size(unsigned int num, unsigned long align)
+{
+ return ((sizeof(struct vring_desc) * num + sizeof(__virtio16) * (3 + num)
+ + align - 1) & ~(align - 1))
+ + sizeof(__virtio16) * 3 + sizeof(struct vring_used_elem) * num;
+}
+
+/* The following is used with USED_EVENT_IDX and AVAIL_EVENT_IDX */
+/* Assuming a given event_idx value from the other size, if
+ * we have just incremented index from old to new_idx,
+ * should we trigger an event? */
+static __inline__ int vring_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
+{
+ /* Note: Xen has similar logic for notification hold-off
+ * in include/xen/interface/io/ring.h with req_event and req_prod
+ * corresponding to event_idx + 1 and new_idx respectively.
+ * Note also that req_event and req_prod in Xen start at 1,
+ * event indexes in virtio start at 0. */
+ return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old);
+}
+
+#endif /* _LINUX_VIRTIO_RING_H */
diff --git a/include/standard-headers/sys/virtio_rng.h b/include/standard-headers/sys/virtio_rng.h
new file mode 100644
index 0000000..cb5ecb1
--- /dev/null
+++ b/include/standard-headers/sys/virtio_rng.h
@@ -0,0 +1,8 @@
+#ifndef _LINUX_VIRTIO_RNG_H
+#define _LINUX_VIRTIO_RNG_H
+/* This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers. */
+#include "standard-headers/sys/virtio_ids.h"
+#include "standard-headers/sys/virtio_config.h"
+
+#endif /* _LINUX_VIRTIO_RNG_H */
diff --git a/include/standard-headers/sys/virtio_scsi.h b/include/standard-headers/sys/virtio_scsi.h
new file mode 100644
index 0000000..da794e4
--- /dev/null
+++ b/include/standard-headers/sys/virtio_scsi.h
@@ -0,0 +1,164 @@
+/*
+ * This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_VIRTIO_SCSI_H
+#define _LINUX_VIRTIO_SCSI_H
+
+#include "standard-headers/sys/virtio_types.h"
+
+#define VIRTIO_SCSI_CDB_SIZE 32
+#define VIRTIO_SCSI_SENSE_SIZE 96
+
+/* SCSI command request, followed by data-out */
+struct virtio_scsi_cmd_req {
+ uint8_t lun[8]; /* Logical Unit Number */
+ __virtio64 tag; /* Command identifier */
+ uint8_t task_attr; /* Task attribute */
+ uint8_t prio; /* SAM command priority field */
+ uint8_t crn;
+ uint8_t cdb[VIRTIO_SCSI_CDB_SIZE];
+} QEMU_PACKED;
+
+/* SCSI command request, followed by protection information */
+struct virtio_scsi_cmd_req_pi {
+ uint8_t lun[8]; /* Logical Unit Number */
+ __virtio64 tag; /* Command identifier */
+ uint8_t task_attr; /* Task attribute */
+ uint8_t prio; /* SAM command priority field */
+ uint8_t crn;
+ __virtio32 pi_bytesout; /* DataOUT PI Number of bytes */
+ __virtio32 pi_bytesin; /* DataIN PI Number of bytes */
+ uint8_t cdb[VIRTIO_SCSI_CDB_SIZE];
+} QEMU_PACKED;
+
+/* Response, followed by sense data and data-in */
+struct virtio_scsi_cmd_resp {
+ __virtio32 sense_len; /* Sense data length */
+ __virtio32 resid; /* Residual bytes in data buffer */
+ __virtio16 status_qualifier; /* Status qualifier */
+ uint8_t status; /* Command completion status */
+ uint8_t response; /* Response values */
+ uint8_t sense[VIRTIO_SCSI_SENSE_SIZE];
+} QEMU_PACKED;
+
+/* Task Management Request */
+struct virtio_scsi_ctrl_tmf_req {
+ __virtio32 type;
+ __virtio32 subtype;
+ uint8_t lun[8];
+ __virtio64 tag;
+} QEMU_PACKED;
+
+struct virtio_scsi_ctrl_tmf_resp {
+ uint8_t response;
+} QEMU_PACKED;
+
+/* Asynchronous notification query/subscription */
+struct virtio_scsi_ctrl_an_req {
+ __virtio32 type;
+ uint8_t lun[8];
+ __virtio32 event_requested;
+} QEMU_PACKED;
+
+struct virtio_scsi_ctrl_an_resp {
+ __virtio32 event_actual;
+ uint8_t response;
+} QEMU_PACKED;
+
+struct virtio_scsi_event {
+ __virtio32 event;
+ uint8_t lun[8];
+ __virtio32 reason;
+} QEMU_PACKED;
+
+struct virtio_scsi_config {
+ uint32_t num_queues;
+ uint32_t seg_max;
+ uint32_t max_sectors;
+ uint32_t cmd_per_lun;
+ uint32_t event_info_size;
+ uint32_t sense_size;
+ uint32_t cdb_size;
+ uint16_t max_channel;
+ uint16_t max_target;
+ uint32_t max_lun;
+} QEMU_PACKED;
+
+/* Feature Bits */
+#define VIRTIO_SCSI_F_INOUT 0
+#define VIRTIO_SCSI_F_HOTPLUG 1
+#define VIRTIO_SCSI_F_CHANGE 2
+#define VIRTIO_SCSI_F_T10_PI 3
+
+/* Response codes */
+#define VIRTIO_SCSI_S_OK 0
+#define VIRTIO_SCSI_S_OVERRUN 1
+#define VIRTIO_SCSI_S_ABORTED 2
+#define VIRTIO_SCSI_S_BAD_TARGET 3
+#define VIRTIO_SCSI_S_RESET 4
+#define VIRTIO_SCSI_S_BUSY 5
+#define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6
+#define VIRTIO_SCSI_S_TARGET_FAILURE 7
+#define VIRTIO_SCSI_S_NEXUS_FAILURE 8
+#define VIRTIO_SCSI_S_FAILURE 9
+#define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10
+#define VIRTIO_SCSI_S_FUNCTION_REJECTED 11
+#define VIRTIO_SCSI_S_INCORRECT_LUN 12
+
+/* Controlq type codes. */
+#define VIRTIO_SCSI_T_TMF 0
+#define VIRTIO_SCSI_T_AN_QUERY 1
+#define VIRTIO_SCSI_T_AN_SUBSCRIBE 2
+
+/* Valid TMF subtypes. */
+#define VIRTIO_SCSI_T_TMF_ABORT_TASK 0
+#define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1
+#define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2
+#define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3
+#define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4
+#define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5
+#define VIRTIO_SCSI_T_TMF_QUERY_TASK 6
+#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7
+
+/* Events. */
+#define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000
+#define VIRTIO_SCSI_T_NO_EVENT 0
+#define VIRTIO_SCSI_T_TRANSPORT_RESET 1
+#define VIRTIO_SCSI_T_ASYNC_NOTIFY 2
+#define VIRTIO_SCSI_T_PARAM_CHANGE 3
+
+/* Reasons of transport reset event */
+#define VIRTIO_SCSI_EVT_RESET_HARD 0
+#define VIRTIO_SCSI_EVT_RESET_RESCAN 1
+#define VIRTIO_SCSI_EVT_RESET_REMOVED 2
+
+#define VIRTIO_SCSI_S_SIMPLE 0
+#define VIRTIO_SCSI_S_ORDERED 1
+#define VIRTIO_SCSI_S_HEAD 2
+#define VIRTIO_SCSI_S_ACA 3
+
+
+#endif /* _LINUX_VIRTIO_SCSI_H */
diff --git a/include/standard-headers/sys/virtio_types.h b/include/standard-headers/sys/virtio_types.h
new file mode 100644
index 0000000..6ca03a7
--- /dev/null
+++ b/include/standard-headers/sys/virtio_types.h
@@ -0,0 +1,46 @@
+#ifndef _LINUX_VIRTIO_TYPES_H
+#define _LINUX_VIRTIO_TYPES_H
+/* Type definitions for virtio implementations.
+ *
+ * This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ * Author: Michael S. Tsirkin <mst@redhat.com>
+ */
+#include "standard-headers/sys/types.h"
+
+/*
+ * __virtio{16,32,64} have the following meaning:
+ * - __u{16,32,64} for virtio devices in legacy mode, accessed in native endian
+ * - __le{16,32,64} for standard-compliant virtio devices
+ */
+
+typedef uint16_t __virtio16;
+typedef uint32_t __virtio32;
+typedef uint64_t __virtio64;
+
+#endif /* _LINUX_VIRTIO_TYPES_H */
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 02/17] include: import virtio headers from linux 4.0
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 02/17] include: import virtio headers from linux 4.0 Michael S. Tsirkin
@ 2015-02-16 16:03 ` Thomas Huth
2015-02-16 16:13 ` Michael S. Tsirkin
0 siblings, 1 reply; 36+ messages in thread
From: Thomas Huth @ 2015-02-16 16:03 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Peter Maydell, qemu-devel, Alexander Graf, Stefan Hajnoczi,
Cornelia Huck, Chen, Tiejun
On Sun, 15 Feb 2015 12:38:37 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> Add files imported from linux-next (what will become linux 4.0) using
> scripts/update-linux-headers.sh
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> include/standard-headers/sys/if_ether.h | 1 +
> include/standard-headers/sys/types.h | 2 +
> include/standard-headers/sys/virtio_9p.h | 44 +++++
> include/standard-headers/sys/virtio_balloon.h | 59 +++++++
> include/standard-headers/sys/virtio_blk.h | 143 ++++++++++++++++
> include/standard-headers/sys/virtio_config.h | 64 +++++++
> include/standard-headers/sys/virtio_console.h | 78 +++++++++
> include/standard-headers/sys/virtio_ids.h | 43 +++++
> include/standard-headers/sys/virtio_net.h | 233 ++++++++++++++++++++++++++
> include/standard-headers/sys/virtio_pci.h | 193 +++++++++++++++++++++
> include/standard-headers/sys/virtio_ring.h | 171 +++++++++++++++++++
> include/standard-headers/sys/virtio_rng.h | 8 +
> include/standard-headers/sys/virtio_scsi.h | 164 ++++++++++++++++++
> include/standard-headers/sys/virtio_types.h | 46 +++++
> 14 files changed, 1249 insertions(+)
> create mode 100644 include/standard-headers/sys/if_ether.h
> create mode 100644 include/standard-headers/sys/types.h
> create mode 100644 include/standard-headers/sys/virtio_9p.h
> create mode 100644 include/standard-headers/sys/virtio_balloon.h
> create mode 100644 include/standard-headers/sys/virtio_blk.h
> create mode 100644 include/standard-headers/sys/virtio_config.h
> create mode 100644 include/standard-headers/sys/virtio_console.h
> create mode 100644 include/standard-headers/sys/virtio_ids.h
> create mode 100644 include/standard-headers/sys/virtio_net.h
> create mode 100644 include/standard-headers/sys/virtio_pci.h
> create mode 100644 include/standard-headers/sys/virtio_ring.h
> create mode 100644 include/standard-headers/sys/virtio_rng.h
> create mode 100644 include/standard-headers/sys/virtio_scsi.h
> create mode 100644 include/standard-headers/sys/virtio_types.h
>
> diff --git a/include/standard-headers/sys/if_ether.h b/include/standard-headers/sys/if_ether.h
> new file mode 100644
> index 0000000..91cf735
> --- /dev/null
> +++ b/include/standard-headers/sys/if_ether.h
> @@ -0,0 +1 @@
> +#define ETH_ALEN 6
> diff --git a/include/standard-headers/sys/types.h b/include/standard-headers/sys/types.h
> new file mode 100644
> index 0000000..7d42ac6
> --- /dev/null
> +++ b/include/standard-headers/sys/types.h
> @@ -0,0 +1,2 @@
> +#include <inttypes.h>
> +#include "qemu/compiler.h"
> diff --git a/include/standard-headers/sys/virtio_9p.h b/include/standard-headers/sys/virtio_9p.h
> new file mode 100644
> index 0000000..19df0e4
> --- /dev/null
> +++ b/include/standard-headers/sys/virtio_9p.h
> @@ -0,0 +1,44 @@
> +#ifndef _LINUX_VIRTIO_9P_H
> +#define _LINUX_VIRTIO_9P_H
Would it make sense to replace the _LINUX_ in the header guards with
the update-linux-headers.sh script, too (to avoid confusion with the
real Linux headers)?
Thomas
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 02/17] include: import virtio headers from linux 4.0
2015-02-16 16:03 ` Thomas Huth
@ 2015-02-16 16:13 ` Michael S. Tsirkin
0 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-16 16:13 UTC (permalink / raw)
To: Thomas Huth
Cc: Peter Maydell, qemu-devel, Alexander Graf, Stefan Hajnoczi,
Cornelia Huck, Chen, Tiejun
On Mon, Feb 16, 2015 at 05:03:16PM +0100, Thomas Huth wrote:
> On Sun, 15 Feb 2015 12:38:37 +0100
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
>
> > Add files imported from linux-next (what will become linux 4.0) using
> > scripts/update-linux-headers.sh
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> > include/standard-headers/sys/if_ether.h | 1 +
> > include/standard-headers/sys/types.h | 2 +
> > include/standard-headers/sys/virtio_9p.h | 44 +++++
> > include/standard-headers/sys/virtio_balloon.h | 59 +++++++
> > include/standard-headers/sys/virtio_blk.h | 143 ++++++++++++++++
> > include/standard-headers/sys/virtio_config.h | 64 +++++++
> > include/standard-headers/sys/virtio_console.h | 78 +++++++++
> > include/standard-headers/sys/virtio_ids.h | 43 +++++
> > include/standard-headers/sys/virtio_net.h | 233 ++++++++++++++++++++++++++
> > include/standard-headers/sys/virtio_pci.h | 193 +++++++++++++++++++++
> > include/standard-headers/sys/virtio_ring.h | 171 +++++++++++++++++++
> > include/standard-headers/sys/virtio_rng.h | 8 +
> > include/standard-headers/sys/virtio_scsi.h | 164 ++++++++++++++++++
> > include/standard-headers/sys/virtio_types.h | 46 +++++
> > 14 files changed, 1249 insertions(+)
> > create mode 100644 include/standard-headers/sys/if_ether.h
> > create mode 100644 include/standard-headers/sys/types.h
> > create mode 100644 include/standard-headers/sys/virtio_9p.h
> > create mode 100644 include/standard-headers/sys/virtio_balloon.h
> > create mode 100644 include/standard-headers/sys/virtio_blk.h
> > create mode 100644 include/standard-headers/sys/virtio_config.h
> > create mode 100644 include/standard-headers/sys/virtio_console.h
> > create mode 100644 include/standard-headers/sys/virtio_ids.h
> > create mode 100644 include/standard-headers/sys/virtio_net.h
> > create mode 100644 include/standard-headers/sys/virtio_pci.h
> > create mode 100644 include/standard-headers/sys/virtio_ring.h
> > create mode 100644 include/standard-headers/sys/virtio_rng.h
> > create mode 100644 include/standard-headers/sys/virtio_scsi.h
> > create mode 100644 include/standard-headers/sys/virtio_types.h
> >
> > diff --git a/include/standard-headers/sys/if_ether.h b/include/standard-headers/sys/if_ether.h
> > new file mode 100644
> > index 0000000..91cf735
> > --- /dev/null
> > +++ b/include/standard-headers/sys/if_ether.h
> > @@ -0,0 +1 @@
> > +#define ETH_ALEN 6
> > diff --git a/include/standard-headers/sys/types.h b/include/standard-headers/sys/types.h
> > new file mode 100644
> > index 0000000..7d42ac6
> > --- /dev/null
> > +++ b/include/standard-headers/sys/types.h
> > @@ -0,0 +1,2 @@
> > +#include <inttypes.h>
> > +#include "qemu/compiler.h"
> > diff --git a/include/standard-headers/sys/virtio_9p.h b/include/standard-headers/sys/virtio_9p.h
> > new file mode 100644
> > index 0000000..19df0e4
> > --- /dev/null
> > +++ b/include/standard-headers/sys/virtio_9p.h
> > @@ -0,0 +1,44 @@
> > +#ifndef _LINUX_VIRTIO_9P_H
> > +#define _LINUX_VIRTIO_9P_H
>
> Would it make sense to replace the _LINUX_ in the header guards with
> the update-linux-headers.sh script, too (to avoid confusion with the
> real Linux headers)?
>
> Thomas
There will be conflicts if you try to pull in both, anyway.
So just don't do it :)
--
MST
^ permalink raw reply [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 03/17] virtio: use standard virtio_ring.h
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 01/17] scripts/update-linux-headers.sh: pull virtio hdrs Michael S. Tsirkin
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 02/17] include: import virtio headers from linux 4.0 Michael S. Tsirkin
@ 2015-02-15 11:38 ` Michael S. Tsirkin
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 04/17] virtio: use standard-headers Michael S. Tsirkin
` (15 subsequent siblings)
18 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:38 UTC (permalink / raw)
To: qemu-devel
Cc: Cornelia Huck, Peter Maydell, Alexander Graf, Stefan Hajnoczi,
Chen, Tiejun
Switch to virtio_ring.h from standard headers.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/dataplane/vring.h | 2 +-
include/hw/virtio/virtio_ring.h | 167 ------------------------------------
hw/net/vhost_net.c | 2 +-
3 files changed, 2 insertions(+), 169 deletions(-)
delete mode 100644 include/hw/virtio/virtio_ring.h
diff --git a/include/hw/virtio/dataplane/vring.h b/include/hw/virtio/dataplane/vring.h
index d3e086a..6484b94 100644
--- a/include/hw/virtio/dataplane/vring.h
+++ b/include/hw/virtio/dataplane/vring.h
@@ -18,7 +18,7 @@
#define VRING_H
#include "qemu-common.h"
-#include "hw/virtio/virtio_ring.h"
+#include "standard-headers/sys/virtio_ring.h"
#include "hw/virtio/virtio.h"
typedef struct {
diff --git a/include/hw/virtio/virtio_ring.h b/include/hw/virtio/virtio_ring.h
deleted file mode 100644
index 0b42e6e..0000000
--- a/include/hw/virtio/virtio_ring.h
+++ /dev/null
@@ -1,167 +0,0 @@
-#ifndef _LINUX_VIRTIO_RING_H
-#define _LINUX_VIRTIO_RING_H
-/*
- * This file is copied from /usr/include/linux while converting __uNN types
- * to uXX_t, __inline__ to inline, and tab to spaces.
- * */
-
-/* An interface for efficient virtio implementation, currently for use by KVM
- * and lguest, but hopefully others soon. Do NOT change this since it will
- * break existing servers and clients.
- *
- * This header is BSD licensed so anyone can use the definitions to implement
- * compatible drivers/servers.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of IBM nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * Copyright Rusty Russell IBM Corporation 2007. */
-
-/* This marks a buffer as continuing via the next field. */
-#define VRING_DESC_F_NEXT 1
-/* This marks a buffer as write-only (otherwise read-only). */
-#define VRING_DESC_F_WRITE 2
-/* This means the buffer contains a list of buffer descriptors. */
-#define VRING_DESC_F_INDIRECT 4
-
-/* The Host uses this in used->flags to advise the Guest: don't kick me when
- * you add a buffer. It's unreliable, so it's simply an optimization. Guest
- * will still kick if it's out of buffers. */
-#define VRING_USED_F_NO_NOTIFY 1
-/* The Guest uses this in avail->flags to advise the Host: don't interrupt me
- * when you consume a buffer. It's unreliable, so it's simply an
- * optimization. */
-#define VRING_AVAIL_F_NO_INTERRUPT 1
-
-/* We support indirect buffer descriptors */
-#define VIRTIO_RING_F_INDIRECT_DESC 28
-
-/* The Guest publishes the used index for which it expects an interrupt
- * at the end of the avail ring. Host should ignore the avail->flags field. */
-/* The Host publishes the avail index for which it expects a kick
- * at the end of the used ring. Guest should ignore the used->flags field. */
-#define VIRTIO_RING_F_EVENT_IDX 29
-
-/* Virtio ring descriptors: 16 bytes. These can chain together via "next". */
-struct vring_desc {
- /* Address (guest-physical). */
- uint64_t addr;
- /* Length. */
- uint32_t len;
- /* The flags as indicated above. */
- uint16_t flags;
- /* We chain unused descriptors via this, too */
- uint16_t next;
-};
-
-struct vring_avail {
- uint16_t flags;
- uint16_t idx;
- uint16_t ring[];
-};
-
-/* u32 is used here for ids for padding reasons. */
-struct vring_used_elem {
- /* Index of start of used descriptor chain. */
- uint32_t id;
- /* Total length of the descriptor chain which was used (written to) */
- uint32_t len;
-};
-
-struct vring_used {
- uint16_t flags;
- uint16_t idx;
- struct vring_used_elem ring[];
-};
-
-struct vring {
- unsigned int num;
-
- struct vring_desc *desc;
-
- struct vring_avail *avail;
-
- struct vring_used *used;
-};
-
-/* The standard layout for the ring is a continuous chunk of memory which looks
- * like this. We assume num is a power of 2.
- *
- * struct vring
- * {
- * // The actual descriptors (16 bytes each)
- * struct vring_desc desc[num];
- *
- * // A ring of available descriptor heads with free-running index.
- * uint16_t avail_flags;
- * uint16_t avail_idx;
- * uint16_t available[num];
- * uint16_t used_event_idx;
- *
- * // Padding to the next align boundary.
- * char pad[];
- *
- * // A ring of used descriptor heads with free-running index.
- * uint16_t used_flags;
- * uint16_t used_idx;
- * struct vring_used_elem used[num];
- * uint16_t avail_event_idx;
- * };
- */
-/* We publish the used event index at the end of the available ring, and vice
- * versa. They are at the end for backwards compatibility. */
-#define vring_used_event(vr) ((vr)->avail->ring[(vr)->num])
-#define vring_avail_event(vr) (*(uint16_t *)&(vr)->used->ring[(vr)->num])
-
-static inline void vring_init(struct vring *vr, unsigned int num, void *p,
- unsigned long align)
-{
- vr->num = num;
- vr->desc = p;
- vr->avail = p + num*sizeof(struct vring_desc);
- vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(uint16_t)
- + align - 1) & ~(align - 1));
-}
-
-static inline unsigned vring_size(unsigned int num, unsigned long align)
-{
- return ((sizeof(struct vring_desc) * num + sizeof(uint16_t) * (3 + num)
- + align - 1) & ~(align - 1))
- + sizeof(uint16_t) * 3 + sizeof(struct vring_used_elem) * num;
-}
-
-/* The following is used with USED_EVENT_IDX and AVAIL_EVENT_IDX */
-/* Assuming a given event_idx value from the other size, if
- * we have just incremented index from old to new_idx,
- * should we trigger an event? */
-static inline int vring_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
-{
- /* Note: Xen has similar logic for notification hold-off
- * in include/xen/interface/io/ring.h with req_event and req_prod
- * corresponding to event_idx + 1 and new_idx respectively.
- * Note also that req_event and req_prod in Xen start at 1,
- * event indexes in virtio start at 0. */
- return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old);
-}
-
-#endif /* _LINUX_VIRTIO_RING_H */
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 4e3a061..75eb15c 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -35,7 +35,7 @@
#include <stdio.h>
-#include "hw/virtio/virtio_ring.h"
+#include "standard-headers/sys/virtio_ring.h"
#include "hw/virtio/vhost.h"
#include "hw/virtio/virtio-bus.h"
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 04/17] virtio: use standard-headers
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (2 preceding siblings ...)
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 03/17] virtio: use standard virtio_ring.h Michael S. Tsirkin
@ 2015-02-15 11:38 ` Michael S. Tsirkin
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 05/17] virtio-balloon: use standard headers Michael S. Tsirkin
` (14 subsequent siblings)
18 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:38 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Maydell, Stefan Hajnoczi, Alexander Graf, Aneesh Kumar K.V,
Anthony Liguori, Cornelia Huck, Chen, Tiejun
Drop a bunch of code duplicated from virtio_config.h and virtio_ring.h.
This makes us rename event index accessors which conflict,
as reusing the ones from virtio_ring.h isn't trivial.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/9pfs/virtio-9p.h | 1 +
include/hw/virtio/virtio.h | 48 ++--------------------------------------------
hw/virtio/virtio.c | 23 +++++-----------------
3 files changed, 8 insertions(+), 64 deletions(-)
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 2c3603a..0776424 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -8,6 +8,7 @@
#include <sys/resource.h>
#include <glib.h>
#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-9p.h"
#include "fsdev/file-op-9p.h"
#include "fsdev/virtio-9p-marshal.h"
#include "qemu/thread.h"
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index f24997d..88a9bc1 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -19,56 +19,12 @@
#include "hw/qdev.h"
#include "sysemu/sysemu.h"
#include "qemu/event_notifier.h"
-#ifdef CONFIG_VIRTFS
-#include "hw/virtio/virtio-9p.h"
-#endif
+#include "standard-headers/sys/virtio_config.h"
+#include "standard-headers/sys/virtio_ring.h"
-/* from Linux's linux/virtio_config.h */
-
-/* Status byte for guest to report progress, and synchronize features. */
-/* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
-#define VIRTIO_CONFIG_S_ACKNOWLEDGE 1
-/* We have found a driver for the device. */
-#define VIRTIO_CONFIG_S_DRIVER 2
-/* Driver has used its parts of the config, and is happy */
-#define VIRTIO_CONFIG_S_DRIVER_OK 4
-/* We've given up on this device. */
-#define VIRTIO_CONFIG_S_FAILED 0x80
-
-/* Some virtio feature bits (currently bits 28 through 31) are reserved for the
- * transport being used (eg. virtio_ring), the rest are per-device feature bits. */
-#define VIRTIO_TRANSPORT_F_START 28
-#define VIRTIO_TRANSPORT_F_END 32
-
-/* We notify when the ring is completely used, even if the guest is suppressing
- * callbacks */
-#define VIRTIO_F_NOTIFY_ON_EMPTY 24
-/* Can the device handle any descriptor layout? */
-#define VIRTIO_F_ANY_LAYOUT 27
-/* We support indirect buffer descriptors */
-#define VIRTIO_RING_F_INDIRECT_DESC 28
-/* The Guest publishes the used index for which it expects an interrupt
- * at the end of the avail ring. Host should ignore the avail->flags field. */
-/* The Host publishes the avail index for which it expects a kick
- * at the end of the used ring. Guest should ignore the used->flags field. */
-#define VIRTIO_RING_F_EVENT_IDX 29
/* A guest should never accept this. It implies negotiation is broken. */
#define VIRTIO_F_BAD_FEATURE 30
-/* from Linux's linux/virtio_ring.h */
-
-/* This marks a buffer as continuing via the next field. */
-#define VRING_DESC_F_NEXT 1
-/* This marks a buffer as write-only (otherwise read-only). */
-#define VRING_DESC_F_WRITE 2
-/* This means the buffer contains a list of buffer descriptors. */
-#define VRING_DESC_F_INDIRECT 4
-
-/* This means don't notify other side when buffer added. */
-#define VRING_USED_F_NO_NOTIFY 1
-/* This means don't interrupt guest when buffer consumed. */
-#define VRING_AVAIL_F_NO_INTERRUPT 1
-
struct VirtQueue;
static inline hwaddr vring_align(hwaddr addr,
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index d735343..f783f31 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -155,7 +155,7 @@ static inline uint16_t vring_avail_ring(VirtQueue *vq, int i)
return virtio_lduw_phys(vq->vdev, pa);
}
-static inline uint16_t vring_used_event(VirtQueue *vq)
+static inline uint16_t vring_get_used_event(VirtQueue *vq)
{
return vring_avail_ring(vq, vq->vring.num);
}
@@ -204,7 +204,7 @@ static inline void vring_used_flags_unset_bit(VirtQueue *vq, int mask)
virtio_stw_phys(vdev, pa, virtio_lduw_phys(vdev, pa) & ~mask);
}
-static inline void vring_avail_event(VirtQueue *vq, uint16_t val)
+static inline void vring_set_avail_event(VirtQueue *vq, uint16_t val)
{
hwaddr pa;
if (!vq->notification) {
@@ -218,7 +218,7 @@ void virtio_queue_set_notification(VirtQueue *vq, int enable)
{
vq->notification = enable;
if (vq->vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
- vring_avail_event(vq, vring_avail_idx(vq));
+ vring_set_avail_event(vq, vring_avail_idx(vq));
} else if (enable) {
vring_used_flags_unset_bit(vq, VRING_USED_F_NO_NOTIFY);
} else {
@@ -469,7 +469,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
i = head = virtqueue_get_head(vq, vq->last_avail_idx++);
if (vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
- vring_avail_event(vq, vq->last_avail_idx);
+ vring_set_avail_event(vq, vq->last_avail_idx);
}
if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_INDIRECT) {
@@ -819,19 +819,6 @@ void virtio_irq(VirtQueue *vq)
virtio_notify_vector(vq->vdev, vq->vector);
}
-/* Assuming a given event_idx value from the other size, if
- * we have just incremented index from old to new_idx,
- * should we trigger an event? */
-static inline int vring_need_event(uint16_t event, uint16_t new, uint16_t old)
-{
- /* Note: Xen has similar logic for notification hold-off
- * in include/xen/interface/io/ring.h with req_event and req_prod
- * corresponding to event_idx + 1 and new respectively.
- * Note also that req_event and req_prod in Xen start at 1,
- * event indexes in virtio start at 0. */
- return (uint16_t)(new - event - 1) < (uint16_t)(new - old);
-}
-
static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq)
{
uint16_t old, new;
@@ -852,7 +839,7 @@ static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq)
vq->signalled_used_valid = true;
old = vq->signalled_used;
new = vq->signalled_used = vring_used_idx(vq);
- return !v || vring_need_event(vring_used_event(vq), new, old);
+ return !v || vring_need_event(vring_get_used_event(vq), new, old);
}
void virtio_notify(VirtIODevice *vdev, VirtQueue *vq)
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 05/17] virtio-balloon: use standard headers
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (3 preceding siblings ...)
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 04/17] virtio: use standard-headers Michael S. Tsirkin
@ 2015-02-15 11:38 ` Michael S. Tsirkin
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 06/17] virtio-9p: " Michael S. Tsirkin
` (13 subsequent siblings)
18 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:38 UTC (permalink / raw)
To: qemu-devel
Cc: Cornelia Huck, Peter Maydell, Alexander Graf, Stefan Hajnoczi,
Chen, Tiejun
Drop code duplicated from standard headers.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/virtio-balloon.h | 35 ++---------------------------------
1 file changed, 2 insertions(+), 33 deletions(-)
diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h
index f863bfe..e69fa0b 100644
--- a/include/hw/virtio/virtio-balloon.h
+++ b/include/hw/virtio/virtio-balloon.h
@@ -15,6 +15,7 @@
#ifndef _QEMU_VIRTIO_BALLOON_H
#define _QEMU_VIRTIO_BALLOON_H
+#include "standard-headers/sys/virtio_balloon.h"
#include "hw/virtio/virtio.h"
#include "hw/pci/pci.h"
@@ -22,39 +23,7 @@
#define VIRTIO_BALLOON(obj) \
OBJECT_CHECK(VirtIOBalloon, (obj), TYPE_VIRTIO_BALLOON)
-/* from Linux's linux/virtio_balloon.h */
-
-/* The ID for virtio_balloon */
-#define VIRTIO_ID_BALLOON 5
-
-/* The feature bitmap for virtio balloon */
-#define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */
-#define VIRTIO_BALLOON_F_STATS_VQ 1 /* Memory stats virtqueue */
-
-/* Size of a PFN in the balloon interface. */
-#define VIRTIO_BALLOON_PFN_SHIFT 12
-
-struct virtio_balloon_config
-{
- /* Number of pages host wants Guest to give up. */
- uint32_t num_pages;
- /* Number of pages we've actually got in balloon. */
- uint32_t actual;
-};
-
-/* Memory Statistics */
-#define VIRTIO_BALLOON_S_SWAP_IN 0 /* Amount of memory swapped in */
-#define VIRTIO_BALLOON_S_SWAP_OUT 1 /* Amount of memory swapped out */
-#define VIRTIO_BALLOON_S_MAJFLT 2 /* Number of major faults */
-#define VIRTIO_BALLOON_S_MINFLT 3 /* Number of minor faults */
-#define VIRTIO_BALLOON_S_MEMFREE 4 /* Total amount of free memory */
-#define VIRTIO_BALLOON_S_MEMTOT 5 /* Total amount of memory */
-#define VIRTIO_BALLOON_S_NR 6
-
-typedef struct VirtIOBalloonStat {
- uint16_t tag;
- uint64_t val;
-} QEMU_PACKED VirtIOBalloonStat;
+typedef struct virtio_balloon_stat VirtIOBalloonStat;
typedef struct VirtIOBalloon {
VirtIODevice parent_obj;
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 06/17] virtio-9p: use standard headers
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (4 preceding siblings ...)
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 05/17] virtio-balloon: use standard headers Michael S. Tsirkin
@ 2015-02-15 11:38 ` Michael S. Tsirkin
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 07/17] virtio-blk: switch to standard-headers Michael S. Tsirkin
` (12 subsequent siblings)
18 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:38 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Maydell, Stefan Hajnoczi, Alexander Graf, Aneesh Kumar K.V,
Anthony Liguori, Cornelia Huck, Chen, Tiejun
Drop code duplicated from standard headers.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/9pfs/virtio-9p.h | 17 +----------------
1 file changed, 1 insertion(+), 16 deletions(-)
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 0776424..2b1fbdd 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -7,6 +7,7 @@
#include <utime.h>
#include <sys/resource.h>
#include <glib.h>
+#include "standard-headers/sys/virtio_9p.h"
#include "hw/virtio/virtio.h"
#include "hw/virtio/virtio-9p.h"
#include "fsdev/file-op-9p.h"
@@ -14,10 +15,6 @@
#include "qemu/thread.h"
#include "block/coroutine.h"
-/* The feature bitmap for virtio 9P */
-/* The mount point is specified in a config variable */
-#define VIRTIO_9P_MOUNT_TAG 0
-
enum {
P9_TLERROR = 6,
P9_RLERROR,
@@ -145,10 +142,6 @@ struct V9fsPDU
* 1) change user needs to set groups and stuff
*/
-/* from Linux's linux/virtio_9p.h */
-
-/* The ID for virtio console */
-#define VIRTIO_ID_9P 9
#define MAX_REQ 128
#define MAX_TAG_LEN 32
@@ -278,14 +271,6 @@ typedef struct V9fsWriteState {
int cnt;
} V9fsWriteState;
-struct virtio_9p_config
-{
- /* number of characters in tag */
- uint16_t tag_len;
- /* Variable size tag name */
- uint8_t tag[0];
-} QEMU_PACKED;
-
typedef struct V9fsMkState {
V9fsPDU *pdu;
size_t offset;
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 07/17] virtio-blk: switch to standard-headers
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (5 preceding siblings ...)
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 06/17] virtio-9p: " Michael S. Tsirkin
@ 2015-02-15 11:38 ` Michael S. Tsirkin
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 08/17] virtio-net, tap: use standard-headers Michael S. Tsirkin
` (11 subsequent siblings)
18 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:38 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Alexander Graf,
Stefan Hajnoczi, Cornelia Huck, Chen, Tiejun
Drop duplicated code. Minor codechanges were required
as geometry is a sub-structure now.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/virtio-blk.h | 77 +-----------------------------------------
hw/block/virtio-blk.c | 8 ++---
2 files changed, 5 insertions(+), 80 deletions(-)
diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h
index fc7d311..ea73ffe 100644
--- a/include/hw/virtio/virtio-blk.h
+++ b/include/hw/virtio/virtio-blk.h
@@ -14,6 +14,7 @@
#ifndef _QEMU_VIRTIO_BLK_H
#define _QEMU_VIRTIO_BLK_H
+#include "standard-headers/sys/virtio_blk.h"
#include "hw/virtio/virtio.h"
#include "hw/block/block.h"
#include "sysemu/iothread.h"
@@ -23,88 +24,12 @@
#define VIRTIO_BLK(obj) \
OBJECT_CHECK(VirtIOBlock, (obj), TYPE_VIRTIO_BLK)
-/* from Linux's linux/virtio_blk.h */
-
-/* The ID for virtio_block */
-#define VIRTIO_ID_BLOCK 2
-
-/* Feature bits */
-#define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
-#define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
-#define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
-#define VIRTIO_BLK_F_GEOMETRY 4 /* Indicates support of legacy geometry */
-#define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
-#define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
-#define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
-/* #define VIRTIO_BLK_F_IDENTIFY 8 ATA IDENTIFY supported, DEPRECATED */
-#define VIRTIO_BLK_F_WCE 9 /* write cache enabled */
-#define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */
-#define VIRTIO_BLK_F_CONFIG_WCE 11 /* write cache configurable */
-
-#define VIRTIO_BLK_ID_BYTES 20 /* ID string length */
-
-struct virtio_blk_config
-{
- uint64_t capacity;
- uint32_t size_max;
- uint32_t seg_max;
- uint16_t cylinders;
- uint8_t heads;
- uint8_t sectors;
- uint32_t blk_size;
- uint8_t physical_block_exp;
- uint8_t alignment_offset;
- uint16_t min_io_size;
- uint32_t opt_io_size;
- uint8_t wce;
-} QEMU_PACKED;
-
-/* These two define direction. */
-#define VIRTIO_BLK_T_IN 0
-#define VIRTIO_BLK_T_OUT 1
-
-/* This bit says it's a scsi command, not an actual read or write. */
-#define VIRTIO_BLK_T_SCSI_CMD 2
-
-/* Flush the volatile write cache */
-#define VIRTIO_BLK_T_FLUSH 4
-
-/* return the device ID string */
-#define VIRTIO_BLK_T_GET_ID 8
-
-/* Barrier before this op. */
-#define VIRTIO_BLK_T_BARRIER 0x80000000
-
-/* This is the first element of the read scatter-gather list. */
-struct virtio_blk_outhdr
-{
- /* VIRTIO_BLK_T* */
- uint32_t type;
- /* io priority. */
- uint32_t ioprio;
- /* Sector (ie. 512 byte offset) */
- uint64_t sector;
-};
-
-#define VIRTIO_BLK_S_OK 0
-#define VIRTIO_BLK_S_IOERR 1
-#define VIRTIO_BLK_S_UNSUPP 2
-
/* This is the last element of the write scatter-gather list */
struct virtio_blk_inhdr
{
unsigned char status;
};
-/* SCSI pass-through header */
-struct virtio_scsi_inhdr
-{
- uint32_t errors;
- uint32_t data_len;
- uint32_t sense_len;
- uint32_t residual;
-};
-
struct VirtIOBlkConf
{
BlockConf conf;
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 1a8a176..6828f48 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -667,11 +667,11 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
memset(&blkcfg, 0, sizeof(blkcfg));
virtio_stq_p(vdev, &blkcfg.capacity, capacity);
virtio_stl_p(vdev, &blkcfg.seg_max, 128 - 2);
- virtio_stw_p(vdev, &blkcfg.cylinders, conf->cyls);
+ virtio_stw_p(vdev, &blkcfg.geometry.cylinders, conf->cyls);
virtio_stl_p(vdev, &blkcfg.blk_size, blk_size);
virtio_stw_p(vdev, &blkcfg.min_io_size, conf->min_io_size / blk_size);
virtio_stw_p(vdev, &blkcfg.opt_io_size, conf->opt_io_size / blk_size);
- blkcfg.heads = conf->heads;
+ blkcfg.geometry.heads = conf->heads;
/*
* We must ensure that the block device capacity is a multiple of
* the logical block size. If that is not the case, let's use
@@ -684,9 +684,9 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
* per track (cylinder).
*/
if (blk_getlength(s->blk) / conf->heads / conf->secs % blk_size) {
- blkcfg.sectors = conf->secs & ~s->sector_mask;
+ blkcfg.geometry.sectors = conf->secs & ~s->sector_mask;
} else {
- blkcfg.sectors = conf->secs;
+ blkcfg.geometry.sectors = conf->secs;
}
blkcfg.size_max = 0;
blkcfg.physical_block_exp = get_physical_block_exp(conf);
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 08/17] virtio-net, tap: use standard-headers
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (6 preceding siblings ...)
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 07/17] virtio-blk: switch to standard-headers Michael S. Tsirkin
@ 2015-02-15 11:38 ` Michael S. Tsirkin
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 09/17] virtio-rng: " Michael S. Tsirkin
` (10 subsequent siblings)
18 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:38 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Maydell, Jason Wang, Alexander Graf, Vincenzo Maffione,
Michael Roth, Stefan Hajnoczi, Cornelia Huck, Chen, Tiejun,
Laszlo Ersek
Drop duplicated code.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/virtio-net.h | 151 +----------------------------------------
include/net/tap.h | 24 +------
2 files changed, 2 insertions(+), 173 deletions(-)
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index 6ceb5aa..d6fa842 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -14,49 +14,15 @@
#ifndef _QEMU_VIRTIO_NET_H
#define _QEMU_VIRTIO_NET_H
+#include "standard-headers/sys/virtio_net.h"
#include "hw/virtio/virtio.h"
-#include "hw/pci/pci.h"
#define TYPE_VIRTIO_NET "virtio-net-device"
#define VIRTIO_NET(obj) \
OBJECT_CHECK(VirtIONet, (obj), TYPE_VIRTIO_NET)
-#define ETH_ALEN 6
-
-/* from Linux's virtio_net.h */
-
-/* The ID for virtio_net */
-#define VIRTIO_ID_NET 1
-
-/* The feature bitmap for virtio net */
-#define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */
-#define VIRTIO_NET_F_GUEST_CSUM 1 /* Guest handles pkts w/ partial csum */
#define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Control channel offload
* configuration support */
-#define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */
-#define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */
-#define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */
-#define VIRTIO_NET_F_GUEST_TSO6 8 /* Guest can handle TSOv6 in. */
-#define VIRTIO_NET_F_GUEST_ECN 9 /* Guest can handle TSO[6] w/ ECN in. */
-#define VIRTIO_NET_F_GUEST_UFO 10 /* Guest can handle UFO in. */
-#define VIRTIO_NET_F_HOST_TSO4 11 /* Host can handle TSOv4 in. */
-#define VIRTIO_NET_F_HOST_TSO6 12 /* Host can handle TSOv6 in. */
-#define VIRTIO_NET_F_HOST_ECN 13 /* Host can handle TSO[6] w/ ECN in. */
-#define VIRTIO_NET_F_HOST_UFO 14 /* Host can handle UFO in. */
-#define VIRTIO_NET_F_MRG_RXBUF 15 /* Host can merge receive buffers. */
-#define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */
-#define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */
-#define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */
-#define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering */
-#define VIRTIO_NET_F_CTRL_RX_EXTRA 20 /* Extra RX mode control support */
-#define VIRTIO_NET_F_GUEST_ANNOUNCE 21 /* Guest can announce itself */
-#define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow
- * Steering */
-
-#define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */
-
-#define VIRTIO_NET_S_LINK_UP 1 /* Link is up */
-#define VIRTIO_NET_S_ANNOUNCE 2 /* Announcement is needed */
#define TX_TIMER_INTERVAL 150000 /* 150 us */
@@ -77,72 +43,6 @@ typedef struct virtio_net_conf
/* Maximum packet size we can receive from tap device: header + 64k */
#define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 << 10))
-struct virtio_net_config
-{
- /* The config defining mac address ($ETH_ALEN bytes) */
- uint8_t mac[ETH_ALEN];
- /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */
- uint16_t status;
- /* Max virtqueue pairs supported by the device */
- uint16_t max_virtqueue_pairs;
-} QEMU_PACKED;
-
-/*
- * Control virtqueue data structures
- *
- * The control virtqueue expects a header in the first sg entry
- * and an ack/status response in the last entry. Data for the
- * command goes in between.
- */
-struct virtio_net_ctrl_hdr {
- uint8_t class;
- uint8_t cmd;
-};
-
-typedef uint8_t virtio_net_ctrl_ack;
-
-#define VIRTIO_NET_OK 0
-#define VIRTIO_NET_ERR 1
-
-/*
- * Control the RX mode, ie. promisucous, allmulti, etc...
- * All commands require an "out" sg entry containing a 1 byte
- * state value, zero = disable, non-zero = enable. Commands
- * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature.
- * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA.
- */
-#define VIRTIO_NET_CTRL_RX 0
- #define VIRTIO_NET_CTRL_RX_PROMISC 0
- #define VIRTIO_NET_CTRL_RX_ALLMULTI 1
- #define VIRTIO_NET_CTRL_RX_ALLUNI 2
- #define VIRTIO_NET_CTRL_RX_NOMULTI 3
- #define VIRTIO_NET_CTRL_RX_NOUNI 4
- #define VIRTIO_NET_CTRL_RX_NOBCAST 5
-
-/*
- * Control the MAC
- *
- * The MAC filter table is managed by the hypervisor, the guest should
- * assume the size is infinite. Filtering should be considered
- * non-perfect, ie. based on hypervisor resources, the guest may
- * received packets from sources not specified in the filter list.
- *
- * In addition to the class/cmd header, the TABLE_SET command requires
- * two out scatterlists. Each contains a 4 byte count of entries followed
- * by a concatenated byte stream of the ETH_ALEN MAC addresses. The
- * first sg list contains unicast addresses, the second is for multicast.
- * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature
- * is available.
- *
- * The ADDR_SET command requests one out scatterlist, it contains a
- * 6 bytes MAC address. This functionality is present if the
- * VIRTIO_NET_F_CTRL_MAC_ADDR feature is available.
- */
-struct virtio_net_ctrl_mac {
- uint32_t entries;
- uint8_t macs[][ETH_ALEN];
-};
-
typedef struct VirtIONetQueue {
VirtQueue *rx_vq;
VirtQueue *tx_vq;
@@ -199,55 +99,6 @@ typedef struct VirtIONet {
int announce_counter;
} VirtIONet;
-#define VIRTIO_NET_CTRL_MAC 1
- #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0
- #define VIRTIO_NET_CTRL_MAC_ADDR_SET 1
-
-/*
- * Control VLAN filtering
- *
- * The VLAN filter table is controlled via a simple ADD/DEL interface.
- * VLAN IDs not added may be filterd by the hypervisor. Del is the
- * opposite of add. Both commands expect an out entry containing a 2
- * byte VLAN ID. VLAN filterting is available with the
- * VIRTIO_NET_F_CTRL_VLAN feature bit.
- */
-#define VIRTIO_NET_CTRL_VLAN 2
- #define VIRTIO_NET_CTRL_VLAN_ADD 0
- #define VIRTIO_NET_CTRL_VLAN_DEL 1
-
-/*
- * Control link announce acknowledgement
- *
- * VIRTIO_NET_S_ANNOUNCE bit in the status field requests link announcement from
- * guest driver. The driver is notified by config space change interrupt. The
- * command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that the driver has
- * received the notification. It makes the device clear the bit
- * VIRTIO_NET_S_ANNOUNCE in the status field.
- */
-#define VIRTIO_NET_CTRL_ANNOUNCE 3
- #define VIRTIO_NET_CTRL_ANNOUNCE_ACK 0
-
-/*
- * Control Multiqueue
- *
- * The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET
- * enables multiqueue, specifying the number of the transmit and
- * receive queues that will be used. After the command is consumed and acked by
- * the device, the device will not steer new packets on receive virtqueues
- * other than specified nor read from transmit virtqueues other than specified.
- * Accordingly, driver should not transmit new packets on virtqueues other than
- * specified.
- */
-struct virtio_net_ctrl_mq {
- uint16_t virtqueue_pairs;
-};
-
-#define VIRTIO_NET_CTRL_MQ 4
- #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 0
- #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1
- #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000
-
/*
* Control network offloads
*
diff --git a/include/net/tap.h b/include/net/tap.h
index 6daeb42..186387d 100644
--- a/include/net/tap.h
+++ b/include/net/tap.h
@@ -28,6 +28,7 @@
#include "qemu-common.h"
#include "qapi-types.h"
+#include "standard-headers/sys/virtio_net.h"
int tap_enable(NetClientState *nc);
int tap_disable(NetClientState *nc);
@@ -37,27 +38,4 @@ int tap_get_fd(NetClientState *nc);
struct vhost_net;
struct vhost_net *tap_get_vhost_net(NetClientState *nc);
-struct virtio_net_hdr
-{
-#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 // Use csum_start, csum_offset
-#define VIRTIO_NET_HDR_F_DATA_VALID 2 // Csum is valid
- uint8_t flags;
-#define VIRTIO_NET_HDR_GSO_NONE 0 // Not a GSO frame
-#define VIRTIO_NET_HDR_GSO_TCPV4 1 // GSO frame, IPv4 TCP (TSO)
-#define VIRTIO_NET_HDR_GSO_UDP 3 // GSO frame, IPv4 UDP (UFO)
-#define VIRTIO_NET_HDR_GSO_TCPV6 4 // GSO frame, IPv6 TCP
-#define VIRTIO_NET_HDR_GSO_ECN 0x80 // TCP has ECN set
- uint8_t gso_type;
- uint16_t hdr_len;
- uint16_t gso_size;
- uint16_t csum_start;
- uint16_t csum_offset;
-};
-
-struct virtio_net_hdr_mrg_rxbuf
-{
- struct virtio_net_hdr hdr;
- uint16_t num_buffers; /* Number of merged rx buffers */
-};
-
#endif /* QEMU_NET_TAP_H */
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 09/17] virtio-rng: use standard-headers
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (7 preceding siblings ...)
2015-02-15 11:38 ` [Qemu-devel] [PATCH v2 08/17] virtio-net, tap: use standard-headers Michael S. Tsirkin
@ 2015-02-15 11:39 ` Michael S. Tsirkin
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 10/17] virtio-scsi: " Michael S. Tsirkin
` (9 subsequent siblings)
18 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:39 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Maydell, Alexander Graf, Amit Shah, Stefan Hajnoczi,
Cornelia Huck, Chen, Tiejun
Drop duplicated code.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/virtio-rng.h | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/include/hw/virtio/virtio-rng.h b/include/hw/virtio/virtio-rng.h
index 14e85a5..b352733 100644
--- a/include/hw/virtio/virtio-rng.h
+++ b/include/hw/virtio/virtio-rng.h
@@ -14,6 +14,7 @@
#include "sysemu/rng.h"
#include "sysemu/rng-random.h"
+#include "standard-headers/sys/virtio_rng.h"
#define TYPE_VIRTIO_RNG "virtio-rng-device"
#define VIRTIO_RNG(obj) \
@@ -21,9 +22,6 @@
#define VIRTIO_RNG_GET_PARENT_CLASS(obj) \
OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_RNG)
-/* The Virtio ID for the virtio rng device */
-#define VIRTIO_ID_RNG 4
-
struct VirtIORNGConf {
RngBackend *rng;
uint64_t max_bytes;
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 10/17] virtio-scsi: use standard-headers
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (8 preceding siblings ...)
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 09/17] virtio-rng: " Michael S. Tsirkin
@ 2015-02-15 11:39 ` Michael S. Tsirkin
2015-02-16 9:30 ` Paolo Bonzini
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 11/17] virtio-serial: switch to standard-headers Michael S. Tsirkin
` (8 subsequent siblings)
18 siblings, 1 reply; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:39 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Maydell, Stefan Hajnoczi, Alexander Graf, Anthony Liguori,
Paolo Bonzini, Cornelia Huck, Chen, Tiejun
Drop duplicated code.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/virtio-scsi.h | 120 +++-------------------------------------
hw/scsi/virtio-scsi.c | 1 +
2 files changed, 10 insertions(+), 111 deletions(-)
diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
index bf17cc9..9bcda7e 100644
--- a/include/hw/virtio/virtio-scsi.h
+++ b/include/hw/virtio/virtio-scsi.h
@@ -14,6 +14,7 @@
#ifndef _QEMU_VIRTIO_SCSI_H
#define _QEMU_VIRTIO_SCSI_H
+#include "standard-headers/sys/virtio_scsi.h"
#include "hw/virtio/virtio.h"
#include "hw/pci/pci.h"
#include "hw/scsi/scsi.h"
@@ -28,15 +29,6 @@
#define VIRTIO_SCSI(obj) \
OBJECT_CHECK(VirtIOSCSI, (obj), TYPE_VIRTIO_SCSI)
-
-/* The ID for virtio_scsi */
-#define VIRTIO_ID_SCSI 8
-
-/* Feature Bits */
-#define VIRTIO_SCSI_F_INOUT 0
-#define VIRTIO_SCSI_F_HOTPLUG 1
-#define VIRTIO_SCSI_F_CHANGE 2
-
#define VIRTIO_SCSI_VQ_SIZE 128
#define VIRTIO_SCSI_CDB_SIZE 32
#define VIRTIO_SCSI_SENSE_SIZE 96
@@ -44,108 +36,14 @@
#define VIRTIO_SCSI_MAX_TARGET 255
#define VIRTIO_SCSI_MAX_LUN 16383
-/* Response codes */
-#define VIRTIO_SCSI_S_OK 0
-#define VIRTIO_SCSI_S_OVERRUN 1
-#define VIRTIO_SCSI_S_ABORTED 2
-#define VIRTIO_SCSI_S_BAD_TARGET 3
-#define VIRTIO_SCSI_S_RESET 4
-#define VIRTIO_SCSI_S_BUSY 5
-#define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6
-#define VIRTIO_SCSI_S_TARGET_FAILURE 7
-#define VIRTIO_SCSI_S_NEXUS_FAILURE 8
-#define VIRTIO_SCSI_S_FAILURE 9
-#define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10
-#define VIRTIO_SCSI_S_FUNCTION_REJECTED 11
-#define VIRTIO_SCSI_S_INCORRECT_LUN 12
-
-/* Controlq type codes. */
-#define VIRTIO_SCSI_T_TMF 0
-#define VIRTIO_SCSI_T_AN_QUERY 1
-#define VIRTIO_SCSI_T_AN_SUBSCRIBE 2
-
-/* Valid TMF subtypes. */
-#define VIRTIO_SCSI_T_TMF_ABORT_TASK 0
-#define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1
-#define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2
-#define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3
-#define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4
-#define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5
-#define VIRTIO_SCSI_T_TMF_QUERY_TASK 6
-#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7
-
-/* Events. */
-#define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000
-#define VIRTIO_SCSI_T_NO_EVENT 0
-#define VIRTIO_SCSI_T_TRANSPORT_RESET 1
-#define VIRTIO_SCSI_T_ASYNC_NOTIFY 2
-#define VIRTIO_SCSI_T_PARAM_CHANGE 3
-
-/* Reasons for transport reset event */
-#define VIRTIO_SCSI_EVT_RESET_HARD 0
-#define VIRTIO_SCSI_EVT_RESET_RESCAN 1
-#define VIRTIO_SCSI_EVT_RESET_REMOVED 2
-
-/* SCSI command request, followed by CDB and data-out */
-typedef struct {
- uint8_t lun[8]; /* Logical Unit Number */
- uint64_t tag; /* Command identifier */
- uint8_t task_attr; /* Task attribute */
- uint8_t prio;
- uint8_t crn;
-} QEMU_PACKED VirtIOSCSICmdReq;
-
-/* Response, followed by sense data and data-in */
-typedef struct {
- uint32_t sense_len; /* Sense data length */
- uint32_t resid; /* Residual bytes in data buffer */
- uint16_t status_qualifier; /* Status qualifier */
- uint8_t status; /* Command completion status */
- uint8_t response; /* Response values */
-} QEMU_PACKED VirtIOSCSICmdResp;
-
-/* Task Management Request */
-typedef struct {
- uint32_t type;
- uint32_t subtype;
- uint8_t lun[8];
- uint64_t tag;
-} QEMU_PACKED VirtIOSCSICtrlTMFReq;
-
-typedef struct {
- uint8_t response;
-} QEMU_PACKED VirtIOSCSICtrlTMFResp;
-
-/* Asynchronous notification query/subscription */
-typedef struct {
- uint32_t type;
- uint8_t lun[8];
- uint32_t event_requested;
-} QEMU_PACKED VirtIOSCSICtrlANReq;
-
-typedef struct {
- uint32_t event_actual;
- uint8_t response;
-} QEMU_PACKED VirtIOSCSICtrlANResp;
-
-typedef struct {
- uint32_t event;
- uint8_t lun[8];
- uint32_t reason;
-} QEMU_PACKED VirtIOSCSIEvent;
-
-typedef struct {
- uint32_t num_queues;
- uint32_t seg_max;
- uint32_t max_sectors;
- uint32_t cmd_per_lun;
- uint32_t event_info_size;
- uint32_t sense_size;
- uint32_t cdb_size;
- uint16_t max_channel;
- uint16_t max_target;
- uint32_t max_lun;
-} QEMU_PACKED VirtIOSCSIConfig;
+typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq;
+typedef struct virtio_scsi_cmd_resp VirtIOSCSICmdResp;
+typedef struct virtio_scsi_ctrl_tmf_req VirtIOSCSICtrlTMFReq;
+typedef struct virtio_scsi_ctrl_tmf_resp VirtIOSCSICtrlTMFResp;
+typedef struct virtio_scsi_ctrl_an_req VirtIOSCSICtrlANReq;
+typedef struct virtio_scsi_ctrl_an_resp VirtIOSCSICtrlANResp;
+typedef struct virtio_scsi_event VirtIOSCSIEvent;
+typedef struct virtio_scsi_config VirtIOSCSIConfig;
struct VirtIOSCSIConf {
uint32_t num_queues;
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 9e2c718..da4c215 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -13,6 +13,7 @@
*
*/
+#include "standard-headers/sys/virtio_ids.h"
#include "hw/virtio/virtio-scsi.h"
#include "qemu/error-report.h"
#include "qemu/iov.h"
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 10/17] virtio-scsi: use standard-headers
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 10/17] virtio-scsi: " Michael S. Tsirkin
@ 2015-02-16 9:30 ` Paolo Bonzini
2015-02-16 11:36 ` Michael S. Tsirkin
0 siblings, 1 reply; 36+ messages in thread
From: Paolo Bonzini @ 2015-02-16 9:30 UTC (permalink / raw)
To: Michael S. Tsirkin, qemu-devel
Cc: Peter Maydell, Stefan Hajnoczi, Alexander Graf, Anthony Liguori,
Cornelia Huck, Chen, Tiejun
On 15/02/2015 12:39, Michael S. Tsirkin wrote:
> Drop duplicated code.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> include/hw/virtio/virtio-scsi.h | 120 +++-------------------------------------
> hw/scsi/virtio-scsi.c | 1 +
> 2 files changed, 10 insertions(+), 111 deletions(-)
>
> diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
> index bf17cc9..9bcda7e 100644
> --- a/include/hw/virtio/virtio-scsi.h
> +++ b/include/hw/virtio/virtio-scsi.h
> @@ -14,6 +14,7 @@
> #ifndef _QEMU_VIRTIO_SCSI_H
> #define _QEMU_VIRTIO_SCSI_H
>
> +#include "standard-headers/sys/virtio_scsi.h"
Why sys/? It's linux/, let's keep it linux/.
Paolo
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 10/17] virtio-scsi: use standard-headers
2015-02-16 9:30 ` Paolo Bonzini
@ 2015-02-16 11:36 ` Michael S. Tsirkin
2015-02-16 11:45 ` Peter Maydell
2015-03-11 10:13 ` Alexey Kardashevskiy
0 siblings, 2 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-16 11:36 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Peter Maydell, Anthony Liguori, qemu-devel, Alexander Graf,
Stefan Hajnoczi, Cornelia Huck, Chen, Tiejun
On Mon, Feb 16, 2015 at 10:30:24AM +0100, Paolo Bonzini wrote:
>
>
> On 15/02/2015 12:39, Michael S. Tsirkin wrote:
> > Drop duplicated code.
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> > include/hw/virtio/virtio-scsi.h | 120 +++-------------------------------------
> > hw/scsi/virtio-scsi.c | 1 +
> > 2 files changed, 10 insertions(+), 111 deletions(-)
> >
> > diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
> > index bf17cc9..9bcda7e 100644
> > --- a/include/hw/virtio/virtio-scsi.h
> > +++ b/include/hw/virtio/virtio-scsi.h
> > @@ -14,6 +14,7 @@
> > #ifndef _QEMU_VIRTIO_SCSI_H
> > #define _QEMU_VIRTIO_SCSI_H
> >
> > +#include "standard-headers/sys/virtio_scsi.h"
>
> Why sys/? It's linux/, let's keep it linux/.
>
> Paolo
Peter requested this change: he felt having portable
headers under linux/ is confusing:
http://mid.gmane.org/CAFEAcA8QFTWbBZSPjCKzEBBwWZojJL+LDKTPL_F=eCDpDHj=Zw@mail.gmail.com
Makes sense?
--
MST
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 10/17] virtio-scsi: use standard-headers
2015-02-16 11:36 ` Michael S. Tsirkin
@ 2015-02-16 11:45 ` Peter Maydell
2015-02-16 14:27 ` Paolo Bonzini
2015-03-11 10:13 ` Alexey Kardashevskiy
1 sibling, 1 reply; 36+ messages in thread
From: Peter Maydell @ 2015-02-16 11:45 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Anthony Liguori, QEMU Developers, Alexander Graf, Stefan Hajnoczi,
Chen, Tiejun, Cornelia Huck, Paolo Bonzini
On 16 February 2015 at 11:36, Michael S. Tsirkin <mst@redhat.com> wrote:
> On Mon, Feb 16, 2015 at 10:30:24AM +0100, Paolo Bonzini wrote:
>>
>>
>> On 15/02/2015 12:39, Michael S. Tsirkin wrote:
>> > Drop duplicated code.
>> >
>> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>> > ---
>> > include/hw/virtio/virtio-scsi.h | 120 +++-------------------------------------
>> > hw/scsi/virtio-scsi.c | 1 +
>> > 2 files changed, 10 insertions(+), 111 deletions(-)
>> >
>> > diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
>> > index bf17cc9..9bcda7e 100644
>> > --- a/include/hw/virtio/virtio-scsi.h
>> > +++ b/include/hw/virtio/virtio-scsi.h
>> > @@ -14,6 +14,7 @@
>> > #ifndef _QEMU_VIRTIO_SCSI_H
>> > #define _QEMU_VIRTIO_SCSI_H
>> >
>> > +#include "standard-headers/sys/virtio_scsi.h"
>>
>> Why sys/? It's linux/, let's keep it linux/.
>>
>> Paolo
>
> Peter requested this change: he felt having portable
> headers under linux/ is confusing:
My point was that you don't want to be including
these headers via "linux/whatever.h";
#include "standard-headers/linux/whatever.h" would be
fine.
-- PMM
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 10/17] virtio-scsi: use standard-headers
2015-02-16 11:36 ` Michael S. Tsirkin
2015-02-16 11:45 ` Peter Maydell
@ 2015-03-11 10:13 ` Alexey Kardashevskiy
2015-03-11 10:57 ` Alexey Kardashevskiy
2015-03-11 12:04 ` Michael S. Tsirkin
1 sibling, 2 replies; 36+ messages in thread
From: Alexey Kardashevskiy @ 2015-03-11 10:13 UTC (permalink / raw)
To: Michael S. Tsirkin, Paolo Bonzini
Cc: Peter Maydell, Anthony Liguori, Nikunj A Dadhania, qemu-devel,
Alexander Graf, Stefan Hajnoczi, Cornelia Huck, Chen, Tiejun
Hi!
This particular patch broke virtio-scsi in SLOF (ppc64-server firmware),
QEMU just exits:
Populating /pci@800000020000000/scsi@0
SCSI: Looking for devices
qemu-system-ppc64: wrong size for virtio-scsi headers
This is how I run it:
-device virtio-scsi-pci,id=id3 \
-drive id=id4,if=none,file=virtimg/rhel7_24GB.qcow2 \
-device scsi-disk,id=id5,drive=id4
It is bigendian, kvm or tcg.
Any quick idea? Thanks :)
On 02/16/2015 10:36 PM, Michael S. Tsirkin wrote:
> On Mon, Feb 16, 2015 at 10:30:24AM +0100, Paolo Bonzini wrote:
>>
>>
>> On 15/02/2015 12:39, Michael S. Tsirkin wrote:
>>> Drop duplicated code.
>>>
>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>> ---
>>> include/hw/virtio/virtio-scsi.h | 120 +++-------------------------------------
>>> hw/scsi/virtio-scsi.c | 1 +
>>> 2 files changed, 10 insertions(+), 111 deletions(-)
>>>
>>> diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
>>> index bf17cc9..9bcda7e 100644
>>> --- a/include/hw/virtio/virtio-scsi.h
>>> +++ b/include/hw/virtio/virtio-scsi.h
>>> @@ -14,6 +14,7 @@
>>> #ifndef _QEMU_VIRTIO_SCSI_H
>>> #define _QEMU_VIRTIO_SCSI_H
>>>
>>> +#include "standard-headers/sys/virtio_scsi.h"
>>
>> Why sys/? It's linux/, let's keep it linux/.
>>
>> Paolo
>
> Peter requested this change: he felt having portable
> headers under linux/ is confusing:
>
> http://mid.gmane.org/CAFEAcA8QFTWbBZSPjCKzEBBwWZojJL+LDKTPL_F=eCDpDHj=Zw@mail.gmail.com
>
> Makes sense?
>
--
Alexey
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 10/17] virtio-scsi: use standard-headers
2015-03-11 10:13 ` Alexey Kardashevskiy
@ 2015-03-11 10:57 ` Alexey Kardashevskiy
2015-03-11 12:04 ` Michael S. Tsirkin
1 sibling, 0 replies; 36+ messages in thread
From: Alexey Kardashevskiy @ 2015-03-11 10:57 UTC (permalink / raw)
To: Michael S. Tsirkin, Paolo Bonzini
Cc: Peter Maydell, Anthony Liguori, Nikunj A Dadhania, qemu-devel,
Alexander Graf, Stefan Hajnoczi, Cornelia Huck, Chen, Tiejun
On 03/11/2015 09:13 PM, Alexey Kardashevskiy wrote:
> Hi!
>
> This particular patch broke virtio-scsi in SLOF (ppc64-server firmware),
> QEMU just exits:
Oops, there was v3 and Nikunj asked there. Ignore this.
>
> Populating /pci@800000020000000/scsi@0
> SCSI: Looking for devices
> qemu-system-ppc64: wrong size for virtio-scsi headers
>
>
> This is how I run it:
>
> -device virtio-scsi-pci,id=id3 \
> -drive id=id4,if=none,file=virtimg/rhel7_24GB.qcow2 \
> -device scsi-disk,id=id5,drive=id4
>
> It is bigendian, kvm or tcg.
>
>
> Any quick idea? Thanks :)
>
>
>
> On 02/16/2015 10:36 PM, Michael S. Tsirkin wrote:
>> On Mon, Feb 16, 2015 at 10:30:24AM +0100, Paolo Bonzini wrote:
>>>
>>>
>>> On 15/02/2015 12:39, Michael S. Tsirkin wrote:
>>>> Drop duplicated code.
>>>>
>>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>>> ---
>>>> include/hw/virtio/virtio-scsi.h | 120
>>>> +++-------------------------------------
>>>> hw/scsi/virtio-scsi.c | 1 +
>>>> 2 files changed, 10 insertions(+), 111 deletions(-)
>>>>
>>>> diff --git a/include/hw/virtio/virtio-scsi.h
>>>> b/include/hw/virtio/virtio-scsi.h
>>>> index bf17cc9..9bcda7e 100644
>>>> --- a/include/hw/virtio/virtio-scsi.h
>>>> +++ b/include/hw/virtio/virtio-scsi.h
>>>> @@ -14,6 +14,7 @@
>>>> #ifndef _QEMU_VIRTIO_SCSI_H
>>>> #define _QEMU_VIRTIO_SCSI_H
>>>>
>>>> +#include "standard-headers/sys/virtio_scsi.h"
>>>
>>> Why sys/? It's linux/, let's keep it linux/.
>>>
>>> Paolo
>>
>> Peter requested this change: he felt having portable
>> headers under linux/ is confusing:
>>
>> http://mid.gmane.org/CAFEAcA8QFTWbBZSPjCKzEBBwWZojJL+LDKTPL_F=eCDpDHj=Zw@mail.gmail.com
>>
>>
>> Makes sense?
>>
>
>
--
Alexey
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 10/17] virtio-scsi: use standard-headers
2015-03-11 10:13 ` Alexey Kardashevskiy
2015-03-11 10:57 ` Alexey Kardashevskiy
@ 2015-03-11 12:04 ` Michael S. Tsirkin
2015-03-11 12:52 ` Alexey Kardashevskiy
1 sibling, 1 reply; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-03-11 12:04 UTC (permalink / raw)
To: Alexey Kardashevskiy
Cc: Peter Maydell, Anthony Liguori, Nikunj A Dadhania, Alexander Graf,
qemu-devel, Stefan Hajnoczi, Chen, Tiejun, Cornelia Huck,
Paolo Bonzini
On Wed, Mar 11, 2015 at 09:13:18PM +1100, Alexey Kardashevskiy wrote:
> Hi!
>
> This particular patch broke virtio-scsi in SLOF (ppc64-server firmware),
> QEMU just exits:
>
> Populating /pci@800000020000000/scsi@0
> SCSI: Looking for devices
> qemu-system-ppc64: wrong size for virtio-scsi headers
>
>
> This is how I run it:
>
> -device virtio-scsi-pci,id=id3 \
> -drive id=id4,if=none,file=virtimg/rhel7_24GB.qcow2 \
> -device scsi-disk,id=id5,drive=id4
>
> It is bigendian, kvm or tcg.
>
>
> Any quick idea? Thanks :)
Can you please try this patch:
mid.gmane.org/20150311101858-mutt-send-email-mst@redhat.com
Thanks!
>
>
> On 02/16/2015 10:36 PM, Michael S. Tsirkin wrote:
> >On Mon, Feb 16, 2015 at 10:30:24AM +0100, Paolo Bonzini wrote:
> >>
> >>
> >>On 15/02/2015 12:39, Michael S. Tsirkin wrote:
> >>>Drop duplicated code.
> >>>
> >>>Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> >>>---
> >>> include/hw/virtio/virtio-scsi.h | 120 +++-------------------------------------
> >>> hw/scsi/virtio-scsi.c | 1 +
> >>> 2 files changed, 10 insertions(+), 111 deletions(-)
> >>>
> >>>diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
> >>>index bf17cc9..9bcda7e 100644
> >>>--- a/include/hw/virtio/virtio-scsi.h
> >>>+++ b/include/hw/virtio/virtio-scsi.h
> >>>@@ -14,6 +14,7 @@
> >>> #ifndef _QEMU_VIRTIO_SCSI_H
> >>> #define _QEMU_VIRTIO_SCSI_H
> >>>
> >>>+#include "standard-headers/sys/virtio_scsi.h"
> >>
> >>Why sys/? It's linux/, let's keep it linux/.
> >>
> >>Paolo
> >
> >Peter requested this change: he felt having portable
> >headers under linux/ is confusing:
> >
> >http://mid.gmane.org/CAFEAcA8QFTWbBZSPjCKzEBBwWZojJL+LDKTPL_F=eCDpDHj=Zw@mail.gmail.com
> >
> >Makes sense?
> >
>
>
> --
> Alexey
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 10/17] virtio-scsi: use standard-headers
2015-03-11 12:04 ` Michael S. Tsirkin
@ 2015-03-11 12:52 ` Alexey Kardashevskiy
0 siblings, 0 replies; 36+ messages in thread
From: Alexey Kardashevskiy @ 2015-03-11 12:52 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Peter Maydell, Anthony Liguori, Nikunj A Dadhania, Alexander Graf,
qemu-devel, Stefan Hajnoczi, Chen, Tiejun, Cornelia Huck,
Paolo Bonzini
On 03/11/2015 11:04 PM, Michael S. Tsirkin wrote:
> On Wed, Mar 11, 2015 at 09:13:18PM +1100, Alexey Kardashevskiy wrote:
>> Hi!
>>
>> This particular patch broke virtio-scsi in SLOF (ppc64-server firmware),
>> QEMU just exits:
>>
>> Populating /pci@800000020000000/scsi@0
>> SCSI: Looking for devices
>> qemu-system-ppc64: wrong size for virtio-scsi headers
>>
>>
>> This is how I run it:
>>
>> -device virtio-scsi-pci,id=id3 \
>> -drive id=id4,if=none,file=virtimg/rhel7_24GB.qcow2 \
>> -device scsi-disk,id=id5,drive=id4
>>
>> It is bigendian, kvm or tcg.
>>
>>
>> Any quick idea? Thanks :)
>
>
> Can you please try this patch:
> mid.gmane.org/20150311101858-mutt-send-email-mst@redhat.com
Tried, it helped. I also replied (the same) in the patch's mail thread.
>
> Thanks!
>
>>
>>
>> On 02/16/2015 10:36 PM, Michael S. Tsirkin wrote:
>>> On Mon, Feb 16, 2015 at 10:30:24AM +0100, Paolo Bonzini wrote:
>>>>
>>>>
>>>> On 15/02/2015 12:39, Michael S. Tsirkin wrote:
>>>>> Drop duplicated code.
>>>>>
>>>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>>>> ---
>>>>> include/hw/virtio/virtio-scsi.h | 120 +++-------------------------------------
>>>>> hw/scsi/virtio-scsi.c | 1 +
>>>>> 2 files changed, 10 insertions(+), 111 deletions(-)
>>>>>
>>>>> diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
>>>>> index bf17cc9..9bcda7e 100644
>>>>> --- a/include/hw/virtio/virtio-scsi.h
>>>>> +++ b/include/hw/virtio/virtio-scsi.h
>>>>> @@ -14,6 +14,7 @@
>>>>> #ifndef _QEMU_VIRTIO_SCSI_H
>>>>> #define _QEMU_VIRTIO_SCSI_H
>>>>>
>>>>> +#include "standard-headers/sys/virtio_scsi.h"
>>>>
>>>> Why sys/? It's linux/, let's keep it linux/.
>>>>
>>>> Paolo
>>>
>>> Peter requested this change: he felt having portable
>>> headers under linux/ is confusing:
>>>
>>> http://mid.gmane.org/CAFEAcA8QFTWbBZSPjCKzEBBwWZojJL+LDKTPL_F=eCDpDHj=Zw@mail.gmail.com
>>>
>>> Makes sense?
>>>
>>
>>
>> --
>> Alexey
--
Alexey
^ permalink raw reply [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 11/17] virtio-serial: switch to standard-headers
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (9 preceding siblings ...)
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 10/17] virtio-scsi: " Michael S. Tsirkin
@ 2015-02-15 11:39 ` Michael S. Tsirkin
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 12/17] update-linux-headers: use standard-headers Michael S. Tsirkin
` (7 subsequent siblings)
18 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:39 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Maydell, Anthony Liguori, Alexander Graf, Amit Shah,
Stefan Hajnoczi, Cornelia Huck, Chen, Tiejun
Drop duplicate code.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/virtio-serial.h | 40 +--------------------------------------
hw/char/virtio-serial-bus.c | 1 +
2 files changed, 2 insertions(+), 39 deletions(-)
diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
index 11af978..de4ac6d 100644
--- a/include/hw/virtio/virtio-serial.h
+++ b/include/hw/virtio/virtio-serial.h
@@ -15,53 +15,15 @@
#ifndef _QEMU_VIRTIO_SERIAL_H
#define _QEMU_VIRTIO_SERIAL_H
+#include "standard-headers/sys/virtio_console.h"
#include "hw/qdev.h"
#include "hw/virtio/virtio.h"
-/* == Interface shared between the guest kernel and qemu == */
-
-/* The Virtio ID for virtio console / serial ports */
-#define VIRTIO_ID_CONSOLE 3
-
-/* Features supported */
-#define VIRTIO_CONSOLE_F_MULTIPORT 1
-
-#define VIRTIO_CONSOLE_BAD_ID (~(uint32_t)0)
-
-struct virtio_console_config {
- /*
- * These two fields are used by VIRTIO_CONSOLE_F_SIZE which
- * isn't implemented here yet
- */
- uint16_t cols;
- uint16_t rows;
-
- uint32_t max_nr_ports;
-} QEMU_PACKED;
-
-struct virtio_console_control {
- uint32_t id; /* Port number */
- uint16_t event; /* The kind of control event (see below) */
- uint16_t value; /* Extra information for the key */
-};
-
struct virtio_serial_conf {
/* Max. number of ports we can have for a virtio-serial device */
uint32_t max_virtserial_ports;
};
-/* Some events for the internal messages (control packets) */
-#define VIRTIO_CONSOLE_DEVICE_READY 0
-#define VIRTIO_CONSOLE_PORT_ADD 1
-#define VIRTIO_CONSOLE_PORT_REMOVE 2
-#define VIRTIO_CONSOLE_PORT_READY 3
-#define VIRTIO_CONSOLE_CONSOLE_PORT 4
-#define VIRTIO_CONSOLE_RESIZE 5
-#define VIRTIO_CONSOLE_PORT_OPEN 6
-#define VIRTIO_CONSOLE_PORT_NAME 7
-
-/* == In-qemu interface == */
-
#define TYPE_VIRTIO_SERIAL_PORT "virtio-serial-port"
#define VIRTIO_SERIAL_PORT(obj) \
OBJECT_CHECK(VirtIOSerialPort, (obj), TYPE_VIRTIO_SERIAL_PORT)
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 47fbb34..cea298c 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -18,6 +18,7 @@
* GNU GPL, version 2 or (at your option) any later version.
*/
+#include "standard-headers/sys/virtio_ids.h"
#include "qemu/iov.h"
#include "monitor/monitor.h"
#include "qemu/queue.h"
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 12/17] update-linux-headers: use standard-headers
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (10 preceding siblings ...)
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 11/17] virtio-serial: switch to standard-headers Michael S. Tsirkin
@ 2015-02-15 11:39 ` Michael S. Tsirkin
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 13/17] linux-headers: " Michael S. Tsirkin
` (6 subsequent siblings)
18 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:39 UTC (permalink / raw)
To: qemu-devel
Cc: Cornelia Huck, Peter Maydell, Alexander Graf, Stefan Hajnoczi,
Chen, Tiejun
Drop the linux-specific virtio headers, use the copy from
standard-headers instead.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
| 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
--git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
index 738e590..9654553 100755
--- a/scripts/update-linux-headers.sh
+++ b/scripts/update-linux-headers.sh
@@ -61,7 +61,7 @@ done
rm -rf "$output/linux-headers/linux"
mkdir -p "$output/linux-headers/linux"
-for header in kvm.h kvm_para.h vfio.h vhost.h virtio_config.h virtio_ring.h \
+for header in kvm.h kvm_para.h vfio.h vhost.h \
psci.h; do
cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux"
done
@@ -76,6 +76,12 @@ else
cp "$linux/COPYING" "$output/linux-headers"
fi
+cat <<EOF >$output/linux-headers/linux/virtio_config.h
+#include "standard-headers/sys/virtio_config.h"
+EOF
+cat <<EOF >$output/linux-headers/linux/virtio_ring.h
+#include "standard-headers/sys/virtio_ring.h"
+EOF
rm -rf "$output/include/standard-headers/sys"
mkdir -p "$output/include/standard-headers/sys"
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 13/17] linux-headers: use standard-headers
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (11 preceding siblings ...)
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 12/17] update-linux-headers: use standard-headers Michael S. Tsirkin
@ 2015-02-15 11:39 ` Michael S. Tsirkin
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 14/17] virtio-pci: use standard headers Michael S. Tsirkin
` (5 subsequent siblings)
18 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:39 UTC (permalink / raw)
To: qemu-devel
Cc: Cornelia Huck, Peter Maydell, Alexander Graf, Stefan Hajnoczi,
Chen, Tiejun
Drop duplicated code.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
| 58 +------------
| 164 +-----------------------------------
2 files changed, 2 insertions(+), 220 deletions(-)
--git a/linux-headers/linux/virtio_config.h b/linux-headers/linux/virtio_config.h
index 75dc20b..6d5a220 100644
--- a/linux-headers/linux/virtio_config.h
+++ b/linux-headers/linux/virtio_config.h
@@ -1,57 +1 @@
-#ifndef _LINUX_VIRTIO_CONFIG_H
-#define _LINUX_VIRTIO_CONFIG_H
-/* This header, excluding the #ifdef __KERNEL__ part, is BSD licensed so
- * anyone can use the definitions to implement compatible drivers/servers.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of IBM nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE. */
-
-/* Virtio devices use a standardized configuration space to define their
- * features and pass configuration information, but each implementation can
- * store and access that space differently. */
-#include <linux/types.h>
-
-/* Status byte for guest to report progress, and synchronize features. */
-/* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
-#define VIRTIO_CONFIG_S_ACKNOWLEDGE 1
-/* We have found a driver for the device. */
-#define VIRTIO_CONFIG_S_DRIVER 2
-/* Driver has used its parts of the config, and is happy */
-#define VIRTIO_CONFIG_S_DRIVER_OK 4
-/* We've given up on this device. */
-#define VIRTIO_CONFIG_S_FAILED 0x80
-
-/* Some virtio feature bits (currently bits 28 through 31) are reserved for the
- * transport being used (eg. virtio_ring), the rest are per-device feature
- * bits. */
-#define VIRTIO_TRANSPORT_F_START 28
-#define VIRTIO_TRANSPORT_F_END 32
-
-/* Do we get callbacks when the ring is completely used, even if we've
- * suppressed them? */
-#define VIRTIO_F_NOTIFY_ON_EMPTY 24
-
-/* Can the device handle any descriptor layout? */
-#define VIRTIO_F_ANY_LAYOUT 27
-
-#endif /* _LINUX_VIRTIO_CONFIG_H */
+#include "standard-headers/sys/virtio_config.h"
--git a/linux-headers/linux/virtio_ring.h b/linux-headers/linux/virtio_ring.h
index 1b333e2..7d44224 100644
--- a/linux-headers/linux/virtio_ring.h
+++ b/linux-headers/linux/virtio_ring.h
@@ -1,163 +1 @@
-#ifndef _LINUX_VIRTIO_RING_H
-#define _LINUX_VIRTIO_RING_H
-/* An interface for efficient virtio implementation, currently for use by KVM
- * and lguest, but hopefully others soon. Do NOT change this since it will
- * break existing servers and clients.
- *
- * This header is BSD licensed so anyone can use the definitions to implement
- * compatible drivers/servers.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of IBM nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * Copyright Rusty Russell IBM Corporation 2007. */
-#include <linux/types.h>
-
-/* This marks a buffer as continuing via the next field. */
-#define VRING_DESC_F_NEXT 1
-/* This marks a buffer as write-only (otherwise read-only). */
-#define VRING_DESC_F_WRITE 2
-/* This means the buffer contains a list of buffer descriptors. */
-#define VRING_DESC_F_INDIRECT 4
-
-/* The Host uses this in used->flags to advise the Guest: don't kick me when
- * you add a buffer. It's unreliable, so it's simply an optimization. Guest
- * will still kick if it's out of buffers. */
-#define VRING_USED_F_NO_NOTIFY 1
-/* The Guest uses this in avail->flags to advise the Host: don't interrupt me
- * when you consume a buffer. It's unreliable, so it's simply an
- * optimization. */
-#define VRING_AVAIL_F_NO_INTERRUPT 1
-
-/* We support indirect buffer descriptors */
-#define VIRTIO_RING_F_INDIRECT_DESC 28
-
-/* The Guest publishes the used index for which it expects an interrupt
- * at the end of the avail ring. Host should ignore the avail->flags field. */
-/* The Host publishes the avail index for which it expects a kick
- * at the end of the used ring. Guest should ignore the used->flags field. */
-#define VIRTIO_RING_F_EVENT_IDX 29
-
-/* Virtio ring descriptors: 16 bytes. These can chain together via "next". */
-struct vring_desc {
- /* Address (guest-physical). */
- __u64 addr;
- /* Length. */
- __u32 len;
- /* The flags as indicated above. */
- __u16 flags;
- /* We chain unused descriptors via this, too */
- __u16 next;
-};
-
-struct vring_avail {
- __u16 flags;
- __u16 idx;
- __u16 ring[];
-};
-
-/* u32 is used here for ids for padding reasons. */
-struct vring_used_elem {
- /* Index of start of used descriptor chain. */
- __u32 id;
- /* Total length of the descriptor chain which was used (written to) */
- __u32 len;
-};
-
-struct vring_used {
- __u16 flags;
- __u16 idx;
- struct vring_used_elem ring[];
-};
-
-struct vring {
- unsigned int num;
-
- struct vring_desc *desc;
-
- struct vring_avail *avail;
-
- struct vring_used *used;
-};
-
-/* The standard layout for the ring is a continuous chunk of memory which looks
- * like this. We assume num is a power of 2.
- *
- * struct vring
- * {
- * // The actual descriptors (16 bytes each)
- * struct vring_desc desc[num];
- *
- * // A ring of available descriptor heads with free-running index.
- * __u16 avail_flags;
- * __u16 avail_idx;
- * __u16 available[num];
- * __u16 used_event_idx;
- *
- * // Padding to the next align boundary.
- * char pad[];
- *
- * // A ring of used descriptor heads with free-running index.
- * __u16 used_flags;
- * __u16 used_idx;
- * struct vring_used_elem used[num];
- * __u16 avail_event_idx;
- * };
- */
-/* We publish the used event index at the end of the available ring, and vice
- * versa. They are at the end for backwards compatibility. */
-#define vring_used_event(vr) ((vr)->avail->ring[(vr)->num])
-#define vring_avail_event(vr) (*(__u16 *)&(vr)->used->ring[(vr)->num])
-
-static __inline__ void vring_init(struct vring *vr, unsigned int num, void *p,
- unsigned long align)
-{
- vr->num = num;
- vr->desc = p;
- vr->avail = p + num*sizeof(struct vring_desc);
- vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(__u16)
- + align-1) & ~(align - 1));
-}
-
-static __inline__ unsigned vring_size(unsigned int num, unsigned long align)
-{
- return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (3 + num)
- + align - 1) & ~(align - 1))
- + sizeof(__u16) * 3 + sizeof(struct vring_used_elem) * num;
-}
-
-/* The following is used with USED_EVENT_IDX and AVAIL_EVENT_IDX */
-/* Assuming a given event_idx value from the other size, if
- * we have just incremented index from old to new_idx,
- * should we trigger an event? */
-static __inline__ int vring_need_event(__u16 event_idx, __u16 new_idx, __u16 old)
-{
- /* Note: Xen has similar logic for notification hold-off
- * in include/xen/interface/io/ring.h with req_event and req_prod
- * corresponding to event_idx + 1 and new_idx respectively.
- * Note also that req_event and req_prod in Xen start at 1,
- * event indexes in virtio start at 0. */
- return (__u16)(new_idx - event_idx - 1) < (__u16)(new_idx - old);
-}
-
-#endif /* _LINUX_VIRTIO_RING_H */
+#include "standard-headers/sys/virtio_ring.h"
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 14/17] virtio-pci: use standard headers
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (12 preceding siblings ...)
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 13/17] linux-headers: " Michael S. Tsirkin
@ 2015-02-15 11:39 ` Michael S. Tsirkin
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 15/17] scripts: add arch specific standard-headers Michael S. Tsirkin
` (4 subsequent siblings)
18 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:39 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Maydell, Stefan Hajnoczi, Alexander Graf, Anthony Liguori,
Cornelia Huck, Chen, Tiejun
Drop duplicate code.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/virtio/virtio-pci.c | 54 +++++---------------------------------------------
1 file changed, 5 insertions(+), 49 deletions(-)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index dde1d73..0466571 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -17,6 +17,7 @@
#include <inttypes.h>
+#include "standard-headers/sys/virtio_pci.h"
#include "hw/virtio/virtio.h"
#include "hw/virtio/virtio-blk.h"
#include "hw/virtio/virtio-net.h"
@@ -35,56 +36,11 @@
#include "hw/virtio/virtio-bus.h"
#include "qapi/visitor.h"
-/* from Linux's linux/virtio_pci.h */
-
-/* A 32-bit r/o bitmask of the features supported by the host */
-#define VIRTIO_PCI_HOST_FEATURES 0
-
-/* A 32-bit r/w bitmask of features activated by the guest */
-#define VIRTIO_PCI_GUEST_FEATURES 4
-
-/* A 32-bit r/w PFN for the currently selected queue */
-#define VIRTIO_PCI_QUEUE_PFN 8
-
-/* A 16-bit r/o queue size for the currently selected queue */
-#define VIRTIO_PCI_QUEUE_NUM 12
-
-/* A 16-bit r/w queue selector */
-#define VIRTIO_PCI_QUEUE_SEL 14
-
-/* A 16-bit r/w queue notifier */
-#define VIRTIO_PCI_QUEUE_NOTIFY 16
-
-/* An 8-bit device status register. */
-#define VIRTIO_PCI_STATUS 18
-
-/* An 8-bit r/o interrupt status register. Reading the value will return the
- * current contents of the ISR and will also clear it. This is effectively
- * a read-and-acknowledge. */
-#define VIRTIO_PCI_ISR 19
-
-/* MSI-X registers: only enabled if MSI-X is enabled. */
-/* A 16-bit vector for configuration changes. */
-#define VIRTIO_MSI_CONFIG_VECTOR 20
-/* A 16-bit vector for selected queue notifications. */
-#define VIRTIO_MSI_QUEUE_VECTOR 22
-
-/* Config space size */
-#define VIRTIO_PCI_CONFIG_NOMSI 20
-#define VIRTIO_PCI_CONFIG_MSI 24
-#define VIRTIO_PCI_REGION_SIZE(dev) (msix_present(dev) ? \
- VIRTIO_PCI_CONFIG_MSI : \
- VIRTIO_PCI_CONFIG_NOMSI)
+#define VIRTIO_PCI_REGION_SIZE(dev) VIRTIO_PCI_CONFIG_OFF(msix_present(dev))
/* The remaining space is defined by each driver as the per-driver
* configuration space */
-#define VIRTIO_PCI_CONFIG(dev) (msix_enabled(dev) ? \
- VIRTIO_PCI_CONFIG_MSI : \
- VIRTIO_PCI_CONFIG_NOMSI)
-
-/* How many bits to shift physical queue address written to QUEUE_PFN.
- * 12 is historical, and due to x86 page size. */
-#define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12
+#define VIRTIO_PCI_CONFIG_SIZE(dev) VIRTIO_PCI_CONFIG_OFF(msix_enabled(dev))
static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
VirtIOPCIProxy *dev);
@@ -392,7 +348,7 @@ static uint64_t virtio_pci_config_read(void *opaque, hwaddr addr,
{
VirtIOPCIProxy *proxy = opaque;
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
- uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+ uint32_t config = VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev);
uint64_t val = 0;
if (addr < config) {
return virtio_ioport_read(proxy, addr);
@@ -423,7 +379,7 @@ static void virtio_pci_config_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
VirtIOPCIProxy *proxy = opaque;
- uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+ uint32_t config = VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev);
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
if (addr < config) {
virtio_ioport_write(proxy, addr, val);
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 15/17] scripts: add arch specific standard-headers
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (13 preceding siblings ...)
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 14/17] virtio-pci: use standard headers Michael S. Tsirkin
@ 2015-02-15 11:39 ` Michael S. Tsirkin
2015-02-16 15:56 ` Thomas Huth
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 16/17] standard-headers: add s390 virtio headers Michael S. Tsirkin
` (3 subsequent siblings)
18 siblings, 1 reply; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:39 UTC (permalink / raw)
To: qemu-devel
Cc: Cornelia Huck, Peter Maydell, Alexander Graf, Stefan Hajnoczi,
Chen, Tiejun
Move virtio header copying logic to a function,
use that to copy arch specific virtio headers.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
| 56 ++++++++++++++++++++++++-----------------
1 file changed, 33 insertions(+), 23 deletions(-)
--git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
index 9654553..1be4d83 100755
--- a/scripts/update-linux-headers.sh
+++ b/scripts/update-linux-headers.sh
@@ -28,6 +28,36 @@ if [ -z "$output" ]; then
output="$PWD"
fi
+cp_virtio() {
+ from=$1
+ to=$2
+ virtio=$(find "$from" -name '*virtio*h')
+ if [ "$virtio" ]; then
+ rm -rf "$to"
+ mkdir -p "$to"
+ for f in $virtio; do
+ if
+ grep '#include' "$f" | grep -v -e 'linux/virtio' \
+ -e 'linux/types' \
+ -e 'linux/if_ether' \
+ > /dev/null
+ then
+ echo "Unexpected #include in input file $f".
+ exit 2
+ fi
+
+ header=$(expr "$f" : '.*/\(.*\)');
+ sed -e 's/__u\([0-9][0-9]*\)/uint\1_t/g' \
+ -e 's/__le\([0-9][0-9]*\)/uint\1_t/g' \
+ -e 's/__be\([0-9][0-9]*\)/uint\1_t/g' \
+ -e 's/<linux\/\([^>]*\)>/"standard-headers\/sys\/\1"/' \
+ -e 's/__bitwise__//' \
+ -e 's/__attribute__((packed))/QEMU_PACKED/' \
+ "$f" > "$to/$header";
+ done
+ fi
+}
+
# This will pick up non-directories too (eg "Kconfig") but we will
# ignore them in the next loop.
ARCHLIST=$(cd "$linux/arch" && echo *)
@@ -57,6 +87,8 @@ for arch in $ARCHLIST; do
if [ $arch = powerpc ]; then
cp "$tmpdir/include/asm/epapr_hcalls.h" "$output/linux-headers/asm-powerpc/"
fi
+
+ cp_virtio "$tmpdir/include/asm" "$output/include/standard-headers/asm-$arch"
done
rm -rf "$output/linux-headers/linux"
@@ -83,29 +115,7 @@ cat <<EOF >$output/linux-headers/linux/virtio_ring.h
#include "standard-headers/sys/virtio_ring.h"
EOF
-rm -rf "$output/include/standard-headers/sys"
-mkdir -p "$output/include/standard-headers/sys"
-for f in $tmpdir/include/linux/virtio*h; do
- if
- grep '#include' "$f" | grep -v -e 'linux/virtio' \
- -e 'linux/types' \
- -e 'linux/if_ether' \
- > /dev/null
- then
- echo "Unexpected #include in input file $f".
- exit 2
- fi
-
- header=$(expr "$f" : '.*/\(.*\)');
- sed -e 's/__u\([0-9][0-9]*\)/uint\1_t/g' \
- -e 's/__le\([0-9][0-9]*\)/uint\1_t/g' \
- -e 's/__be\([0-9][0-9]*\)/uint\1_t/g' \
- -e 's/<linux\/\([^>]*\)>/"standard-headers\/sys\/\1"/' \
- -e 's/__bitwise__//' \
- -e 's/__attribute__((packed))/QEMU_PACKED/' \
- "$tmpdir/include/linux/$header" > \
- "$output/include/standard-headers/sys/$header";
-done
+cp_virtio "$tmpdir/include/linux/" "$output/include/standard-headers/sys"
cat <<EOF >$output/include/standard-headers/sys/types.h
#include <inttypes.h>
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 15/17] scripts: add arch specific standard-headers
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 15/17] scripts: add arch specific standard-headers Michael S. Tsirkin
@ 2015-02-16 15:56 ` Thomas Huth
2015-02-16 16:15 ` Michael S. Tsirkin
0 siblings, 1 reply; 36+ messages in thread
From: Thomas Huth @ 2015-02-16 15:56 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Peter Maydell, qemu-devel, Alexander Graf, Stefan Hajnoczi,
Cornelia Huck, Chen, Tiejun
On Sun, 15 Feb 2015 12:39:25 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> Move virtio header copying logic to a function,
> use that to copy arch specific virtio headers.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> scripts/update-linux-headers.sh | 56 ++++++++++++++++++++++++-----------------
> 1 file changed, 33 insertions(+), 23 deletions(-)
>
> diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
> index 9654553..1be4d83 100755
> --- a/scripts/update-linux-headers.sh
> +++ b/scripts/update-linux-headers.sh
> @@ -28,6 +28,36 @@ if [ -z "$output" ]; then
> output="$PWD"
> fi
>
> +cp_virtio() {
> + from=$1
> + to=$2
> + virtio=$(find "$from" -name '*virtio*h')
> + if [ "$virtio" ]; then
> + rm -rf "$to"
> + mkdir -p "$to"
> + for f in $virtio; do
> + if
> + grep '#include' "$f" | grep -v -e 'linux/virtio' \
> + -e 'linux/types' \
> + -e 'linux/if_ether' \
> + > /dev/null
> + then
> + echo "Unexpected #include in input file $f".
> + exit 2
> + fi
> +
> + header=$(expr "$f" : '.*/\(.*\)');
> + sed -e 's/__u\([0-9][0-9]*\)/uint\1_t/g' \
> + -e 's/__le\([0-9][0-9]*\)/uint\1_t/g' \
> + -e 's/__be\([0-9][0-9]*\)/uint\1_t/g' \
> + -e 's/<linux\/\([^>]*\)>/"standard-headers\/sys\/\1"/' \
> + -e 's/__bitwise__//' \
> + -e 's/__attribute__((packed))/QEMU_PACKED/' \
> + "$f" > "$to/$header";
> + done
> + fi
> +}
Could you maybe introduce this function in patch 1 already? That would
avoid a bit of code churn here.
Thomas
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 15/17] scripts: add arch specific standard-headers
2015-02-16 15:56 ` Thomas Huth
@ 2015-02-16 16:15 ` Michael S. Tsirkin
0 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-16 16:15 UTC (permalink / raw)
To: Thomas Huth
Cc: Peter Maydell, qemu-devel, Alexander Graf, Stefan Hajnoczi,
Cornelia Huck, Chen, Tiejun
On Mon, Feb 16, 2015 at 04:56:39PM +0100, Thomas Huth wrote:
> On Sun, 15 Feb 2015 12:39:25 +0100
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
>
> > Move virtio header copying logic to a function,
> > use that to copy arch specific virtio headers.
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> > scripts/update-linux-headers.sh | 56 ++++++++++++++++++++++++-----------------
> > 1 file changed, 33 insertions(+), 23 deletions(-)
> >
> > diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
> > index 9654553..1be4d83 100755
> > --- a/scripts/update-linux-headers.sh
> > +++ b/scripts/update-linux-headers.sh
> > @@ -28,6 +28,36 @@ if [ -z "$output" ]; then
> > output="$PWD"
> > fi
> >
> > +cp_virtio() {
> > + from=$1
> > + to=$2
> > + virtio=$(find "$from" -name '*virtio*h')
> > + if [ "$virtio" ]; then
> > + rm -rf "$to"
> > + mkdir -p "$to"
> > + for f in $virtio; do
> > + if
> > + grep '#include' "$f" | grep -v -e 'linux/virtio' \
> > + -e 'linux/types' \
> > + -e 'linux/if_ether' \
> > + > /dev/null
> > + then
> > + echo "Unexpected #include in input file $f".
> > + exit 2
> > + fi
> > +
> > + header=$(expr "$f" : '.*/\(.*\)');
> > + sed -e 's/__u\([0-9][0-9]*\)/uint\1_t/g' \
> > + -e 's/__le\([0-9][0-9]*\)/uint\1_t/g' \
> > + -e 's/__be\([0-9][0-9]*\)/uint\1_t/g' \
> > + -e 's/<linux\/\([^>]*\)>/"standard-headers\/sys\/\1"/' \
> > + -e 's/__bitwise__//' \
> > + -e 's/__attribute__((packed))/QEMU_PACKED/' \
> > + "$f" > "$to/$header";
> > + done
> > + fi
> > +}
>
> Could you maybe introduce this function in patch 1 already? That would
> avoid a bit of code churn here.
>
> Thomas
Yes but this part needs more testing, there are advantages
to keeping code as simple as possible.
^ permalink raw reply [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 16/17] standard-headers: add s390 virtio headers
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (14 preceding siblings ...)
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 15/17] scripts: add arch specific standard-headers Michael S. Tsirkin
@ 2015-02-15 11:39 ` Michael S. Tsirkin
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 17/17] s390: use standard headers Michael S. Tsirkin
` (2 subsequent siblings)
18 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:39 UTC (permalink / raw)
To: qemu-devel
Cc: Cornelia Huck, Peter Maydell, Alexander Graf, Stefan Hajnoczi,
Chen, Tiejun
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/standard-headers/asm-s390/kvm_virtio.h | 64 ++++++++++++++++++++++++++
include/standard-headers/asm-s390/virtio-ccw.h | 21 +++++++++
2 files changed, 85 insertions(+)
create mode 100644 include/standard-headers/asm-s390/kvm_virtio.h
create mode 100644 include/standard-headers/asm-s390/virtio-ccw.h
diff --git a/include/standard-headers/asm-s390/kvm_virtio.h b/include/standard-headers/asm-s390/kvm_virtio.h
new file mode 100644
index 0000000..a7a33ff
--- /dev/null
+++ b/include/standard-headers/asm-s390/kvm_virtio.h
@@ -0,0 +1,64 @@
+/*
+ * definition for virtio for kvm on s390
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ * Author(s): Christian Borntraeger <borntraeger@de.ibm.com>
+ */
+
+#ifndef __KVM_S390_VIRTIO_H
+#define __KVM_S390_VIRTIO_H
+
+#include "standard-headers/sys/types.h"
+
+struct kvm_device_desc {
+ /* The device type: console, network, disk etc. Type 0 terminates. */
+ uint8_t type;
+ /* The number of virtqueues (first in config array) */
+ uint8_t num_vq;
+ /*
+ * The number of bytes of feature bits. Multiply by 2: one for host
+ * features and one for guest acknowledgements.
+ */
+ uint8_t feature_len;
+ /* The number of bytes of the config array after virtqueues. */
+ uint8_t config_len;
+ /* A status byte, written by the Guest. */
+ uint8_t status;
+ uint8_t config[0];
+};
+
+/*
+ * This is how we expect the device configuration field for a virtqueue
+ * to be laid out in config space.
+ */
+struct kvm_vqconfig {
+ /* The token returned with an interrupt. Set by the guest */
+ uint64_t token;
+ /* The address of the virtio ring */
+ uint64_t address;
+ /* The number of entries in the virtio_ring */
+ uint16_t num;
+
+};
+
+#define KVM_S390_VIRTIO_NOTIFY 0
+#define KVM_S390_VIRTIO_RESET 1
+#define KVM_S390_VIRTIO_SET_STATUS 2
+
+/* The alignment to use between consumer and producer parts of vring.
+ * This is pagesize for historical reasons. */
+#define KVM_S390_VIRTIO_RING_ALIGN 4096
+
+
+/* These values are supposed to be in ext_params on an interrupt */
+#define VIRTIO_PARAM_MASK 0xff
+#define VIRTIO_PARAM_VRING_INTERRUPT 0x0
+#define VIRTIO_PARAM_CONFIG_CHANGED 0x1
+#define VIRTIO_PARAM_DEV_ADD 0x2
+
+#endif
diff --git a/include/standard-headers/asm-s390/virtio-ccw.h b/include/standard-headers/asm-s390/virtio-ccw.h
new file mode 100644
index 0000000..a9a4ebf
--- /dev/null
+++ b/include/standard-headers/asm-s390/virtio-ccw.h
@@ -0,0 +1,21 @@
+/*
+ * Definitions for virtio-ccw devices.
+ *
+ * Copyright IBM Corp. 2013
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
+ */
+#ifndef __KVM_VIRTIO_CCW_H
+#define __KVM_VIRTIO_CCW_H
+
+/* Alignment of vring buffers. */
+#define KVM_VIRTIO_CCW_RING_ALIGN 4096
+
+/* Subcode for diagnose 500 (virtio hypercall). */
+#define KVM_S390_VIRTIO_CCW_NOTIFY 3
+
+#endif
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH v2 17/17] s390: use standard headers
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (15 preceding siblings ...)
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 16/17] standard-headers: add s390 virtio headers Michael S. Tsirkin
@ 2015-02-15 11:39 ` Michael S. Tsirkin
2015-02-15 11:41 ` [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Peter Maydell
2015-02-16 8:50 ` Cornelia Huck
18 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:39 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Maydell, Alexander Graf, Stefan Hajnoczi, Cornelia Huck,
Chen, Tiejun, Richard Henderson
Drop duplicated macros in favor of values from
standard headers.
Warning: untested.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/s390x/s390-virtio-bus.h | 36 +++++++++++++++++++-----------------
hw/s390x/s390-virtio.h | 7 ++-----
2 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/hw/s390x/s390-virtio-bus.h b/hw/s390x/s390-virtio-bus.h
index ffd0df7..e888104 100644
--- a/hw/s390x/s390-virtio-bus.h
+++ b/hw/s390x/s390-virtio-bus.h
@@ -19,6 +19,10 @@
#ifndef HW_S390_VIRTIO_BUS_H
#define HW_S390_VIRTIO_BUS_H 1
+#include <stddef.h>
+
+#include "standard-headers/asm-s390/kvm_virtio.h"
+#include "standard-headers/sys/virtio_ring.h"
#include "hw/virtio/virtio-blk.h"
#include "hw/virtio/virtio-net.h"
#include "hw/virtio/virtio-rng.h"
@@ -29,28 +33,26 @@
#include "hw/virtio/vhost-scsi.h"
#endif
-#define VIRTIO_DEV_OFFS_TYPE 0 /* 8 bits */
-#define VIRTIO_DEV_OFFS_NUM_VQ 1 /* 8 bits */
-#define VIRTIO_DEV_OFFS_FEATURE_LEN 2 /* 8 bits */
-#define VIRTIO_DEV_OFFS_CONFIG_LEN 3 /* 8 bits */
-#define VIRTIO_DEV_OFFS_STATUS 4 /* 8 bits */
-#define VIRTIO_DEV_OFFS_CONFIG 5 /* dynamic */
+typedef struct kvm_device_desc KvmDeviceDesc;
+
+#define VIRTIO_DEV_OFFS_TYPE offsetof(KvmDeviceDesc, type)
+#define VIRTIO_DEV_OFFS_NUM_VQ offsetof(KvmDeviceDesc, num_vq)
+#define VIRTIO_DEV_OFFS_FEATURE_LEN offsetof(KvmDeviceDesc, feature_len)
+#define VIRTIO_DEV_OFFS_CONFIG_LEN offsetof(KvmDeviceDesc, config_len)
+#define VIRTIO_DEV_OFFS_STATUS offsetof(KvmDeviceDesc, status)
+#define VIRTIO_DEV_OFFS_CONFIG offsetof(KvmDeviceDesc, config)
-#define VIRTIO_VQCONFIG_OFFS_TOKEN 0 /* 64 bits */
-#define VIRTIO_VQCONFIG_OFFS_ADDRESS 8 /* 64 bits */
-#define VIRTIO_VQCONFIG_OFFS_NUM 16 /* 16 bits */
-#define VIRTIO_VQCONFIG_LEN 24
+typedef struct kvm_vqconfig KvmVqConfig;
+#define VIRTIO_VQCONFIG_OFFS_TOKEN offsetof(KvmVqConfig,token) /* 64 bit */
+#define VIRTIO_VQCONFIG_OFFS_ADDRESS offsetof(KvmVqConfig, address) /* 64 bit */
+#define VIRTIO_VQCONFIG_OFFS_NUM offsetof(KvmVqConfig, num) /* 16 bit */
+#define VIRTIO_VQCONFIG_LEN sizeof(KvmVqConfig)
#define VIRTIO_RING_LEN (TARGET_PAGE_SIZE * 3)
-#define VIRTIO_VRING_AVAIL_IDX_OFFS 2
-#define VIRTIO_VRING_USED_IDX_OFFS 2
+#define VIRTIO_VRING_AVAIL_IDX_OFFS offsetof(struct vring_avail, idx)
+#define VIRTIO_VRING_USED_IDX_OFFS offsetof(struct vring_used, idx)
#define S390_DEVICE_PAGES 512
-#define VIRTIO_PARAM_MASK 0xff
-#define VIRTIO_PARAM_VRING_INTERRUPT 0x0
-#define VIRTIO_PARAM_CONFIG_CHANGED 0x1
-#define VIRTIO_PARAM_DEV_ADD 0x2
-
#define TYPE_VIRTIO_S390_DEVICE "virtio-s390-device"
#define VIRTIO_S390_DEVICE(obj) \
OBJECT_CHECK(VirtIOS390Device, (obj), TYPE_VIRTIO_S390_DEVICE)
diff --git a/hw/s390x/s390-virtio.h b/hw/s390x/s390-virtio.h
index 33847ae..f9d67a8 100644
--- a/hw/s390x/s390-virtio.h
+++ b/hw/s390x/s390-virtio.h
@@ -13,11 +13,8 @@
#define HW_S390_VIRTIO_H 1
#include "hw/nmi.h"
-
-#define KVM_S390_VIRTIO_NOTIFY 0
-#define KVM_S390_VIRTIO_RESET 1
-#define KVM_S390_VIRTIO_SET_STATUS 2
-#define KVM_S390_VIRTIO_CCW_NOTIFY 3
+#include "standard-headers/asm-s390/kvm_virtio.h"
+#include "standard-headers/asm-s390/virtio-ccw.h"
typedef int (*s390_virtio_fn)(const uint64_t *args);
void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn);
--
MST
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (16 preceding siblings ...)
2015-02-15 11:39 ` [Qemu-devel] [PATCH v2 17/17] s390: use standard headers Michael S. Tsirkin
@ 2015-02-15 11:41 ` Peter Maydell
2015-02-15 11:43 ` Michael S. Tsirkin
2015-02-16 8:50 ` Cornelia Huck
18 siblings, 1 reply; 36+ messages in thread
From: Peter Maydell @ 2015-02-15 11:41 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Cornelia Huck, Chen, Tiejun, QEMU Developers, Stefan Hajnoczi,
Alexander Graf
On 15 February 2015 at 11:38, Michael S. Tsirkin <mst@redhat.com> wrote:
> This reuses virtio headers from files exported by linux.
> The current situation is quite messy: for example we
> have multiple copies of the virtio net packet structure,
> and the virtio ring structure.
> We already use some of them for linux-specific code,
> reusing more widely gets rid of code duplication.
>
> One of the reasons we didn't do this previously
> was portability considerations: this patchset addresses
> this by fixing up headers in question - turns out to
> be easy to do since they are already quite portable.
> Lightly tested on x86.
Did you test on Windows and OSX, or do you need somebody
to do that?
-- PMM
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux
2015-02-15 11:41 ` [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Peter Maydell
@ 2015-02-15 11:43 ` Michael S. Tsirkin
0 siblings, 0 replies; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-15 11:43 UTC (permalink / raw)
To: Peter Maydell
Cc: Cornelia Huck, Chen, Tiejun, QEMU Developers, Stefan Hajnoczi,
Alexander Graf
On Sun, Feb 15, 2015 at 11:41:03AM +0000, Peter Maydell wrote:
> On 15 February 2015 at 11:38, Michael S. Tsirkin <mst@redhat.com> wrote:
> > This reuses virtio headers from files exported by linux.
> > The current situation is quite messy: for example we
> > have multiple copies of the virtio net packet structure,
> > and the virtio ring structure.
> > We already use some of them for linux-specific code,
> > reusing more widely gets rid of code duplication.
> >
> > One of the reasons we didn't do this previously
> > was portability considerations: this patchset addresses
> > this by fixing up headers in question - turns out to
> > be easy to do since they are already quite portable.
>
> > Lightly tested on x86.
>
> Did you test on Windows and OSX, or do you need somebody
> to do that?
>
> -- PMM
Thanks for the reminder - forgot to mention that :(
Tested on linux only, with windows and linux guests.
Needs windows, osx host testing.
--
MST
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux
2015-02-15 11:38 [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Michael S. Tsirkin
` (17 preceding siblings ...)
2015-02-15 11:41 ` [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux Peter Maydell
@ 2015-02-16 8:50 ` Cornelia Huck
2015-02-16 9:05 ` Michael S. Tsirkin
18 siblings, 1 reply; 36+ messages in thread
From: Cornelia Huck @ 2015-02-16 8:50 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Peter Maydell, Chen, Tiejun, qemu-devel, Stefan Hajnoczi,
Alexander Graf
On Sun, 15 Feb 2015 12:38:30 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> While I applied refactoring to s390 code as well, these patches
> are untested, and aren't a mandatory part of the series.
> Testing (even just build-test) reports would be very much appreciated.
Do you have a branch around for that?
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux
2015-02-16 8:50 ` Cornelia Huck
@ 2015-02-16 9:05 ` Michael S. Tsirkin
2015-02-16 9:32 ` Cornelia Huck
0 siblings, 1 reply; 36+ messages in thread
From: Michael S. Tsirkin @ 2015-02-16 9:05 UTC (permalink / raw)
To: Cornelia Huck
Cc: Peter Maydell, Chen, Tiejun, qemu-devel, Stefan Hajnoczi,
Alexander Graf
On Mon, Feb 16, 2015 at 09:50:17AM +0100, Cornelia Huck wrote:
> On Sun, 15 Feb 2015 12:38:30 +0100
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
>
> > While I applied refactoring to s390 code as well, these patches
> > are untested, and aren't a mandatory part of the series.
> > Testing (even just build-test) reports would be very much appreciated.
>
> Do you have a branch around for that?
Yes.
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git pci
Thanks,
--
MST
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] [PATCH v2 00/17] virtio: pull headers from linux
2015-02-16 9:05 ` Michael S. Tsirkin
@ 2015-02-16 9:32 ` Cornelia Huck
0 siblings, 0 replies; 36+ messages in thread
From: Cornelia Huck @ 2015-02-16 9:32 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Peter Maydell, Chen, Tiejun, qemu-devel, Stefan Hajnoczi,
Alexander Graf
On Mon, 16 Feb 2015 10:05:24 +0100
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Mon, Feb 16, 2015 at 09:50:17AM +0100, Cornelia Huck wrote:
> > On Sun, 15 Feb 2015 12:38:30 +0100
> > "Michael S. Tsirkin" <mst@redhat.com> wrote:
> >
> > > While I applied refactoring to s390 code as well, these patches
> > > are untested, and aren't a mandatory part of the series.
> > > Testing (even just build-test) reports would be very much appreciated.
> >
> > Do you have a branch around for that?
>
> Yes.
>
> git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git pci
OK, this compiles for me and passes some very basic smoke tests for
both s390-virtio and virtio-ccw.
I'll look at the actual patch series later.
^ permalink raw reply [flat|nested] 36+ messages in thread