virtio: pull headers from linux
v3 cover virtio: pull headers from linux
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.
One of comments asked about support for functionality missing from linux guests. This patchet addresses this simply by adding code in include/hw/virtio like we did before.
One example of this is VIRTIO_NET_CTRL_GUEST_OFFLOADS command in virtio-net, which is currently only used by windows guests.
The definition was therefore left in include/hw/virtio/virtio-net.h, this approach makes it easy to find functionality that linux guests are missing, which is important e.g. for testing.
Ability to synchronize headers in this way will bring long-term benefits in case bugfixes need to apply to both host and guest.
In particular, this gives us known-good virtio 1.0 headers for free, right now.
This refactoring also better separates between guest ABI and internal qemu functionality, which is a good thing as we need to be extra careful about guest ABI changes.
This might also enable better static checking with sparse, as linux tags virtio headers with correct endian-ness. For now, sparse tags are automatically stripped, for compatibility with existing code.
Some pieces are more widely applicable (outside virtio): e.g. everyone will be able to pull ETH_ALEN from the standard header.
The infrastructure also might be of use for other headers (pci_regs.h)?
s390 patches have been built and smoke-tested by Cornelia.
Tested on linux on x86 and s390 only, with windows and linux guests. Needs windows, osx host testing.
Testing (even just build-test) reports would be very much appreciated.
changes from v2:
- rename sys/ to linux/ to address comments by Peter and Paolo
- address comments by Thomas
Changes from v1:
- add s390 headers (untested)
- add code to check no unexpected linux-specific headers are pulled in by mistake
- add if_ether.h to provide ETH_ALEN for virtio net
- move headers from standard-headers/linux to standard-headers/sys and put them under include so they are on search path
- fix up __leXX
- fix up __attribute__((packed))
Michael S. Tsirkin (17):
scripts/update-linux-headers.sh: pull virtio hdrs
include: import virtio headers from linux 4.0
virtio: use standard virtio_ring.h
virtio: use standard-headers
virtio-balloon: use standard headers
virtio-9p: use standard headers
virtio-blk: switch to standard-headers virtio-net,tap: use standard-headers
virtio-rng: use standard-headers
virtio-scsi: use standard-headers
virtio-serial: switch to standard-headers
update-linux-headers: use standard-headers
linux-headers: use standard-headers
virtio-pci: use standard headers
scripts: add arch specific standard-headers
standard-headers: add s390 virtio headers
s390: use standard headers
hw/9pfs/virtio-9p.h | 18 +-
hw/s390x/s390-virtio-bus.h | 36 ++--
hw/s390x/s390-virtio.h | 7 +-
include/hw/virtio/dataplane/vring.h | 2 +-
include/hw/virtio/virtio-balloon.h | 35 +---
include/hw/virtio/virtio-blk.h | 77 +------
include/hw/virtio/virtio-net.h | 151 +------------
include/hw/virtio/virtio-rng.h | 4 +-
include/hw/virtio/virtio-scsi.h | 120 +----------
include/hw/virtio/virtio-serial.h | 40 +---
include/hw/virtio/virtio.h | 48 +----
include/net/tap.h | 24 +--
include/standard-headers/asm-s390/kvm_virtio.h | 64 ++++++
include/standard-headers/asm-s390/virtio-ccw.h | 21 ++
include/standard-headers/linux/if_ether.h | 1 +
include/standard-headers/linux/types.h | 2 +
include/standard-headers/linux/virtio_9p.h | 44 ++++
include/standard-headers/linux/virtio_balloon.h | 59 ++++++
include/standard-headers/linux/virtio_blk.h | 143 +++++++++++++
include/standard-headers/linux/virtio_config.h | 64 ++++++
include/standard-headers/linux/virtio_console.h | 78 +++++++
include/standard-headers/linux/virtio_ids.h | 43 ++++
include/standard-headers/linux/virtio_net.h | 233 +++++++++++++++++++++
include/standard-headers/linux/virtio_pci.h | 193 +++++++++++++++++
.../linux}/virtio_ring.h | 138 ++++++------
include/standard-headers/linux/virtio_rng.h | 8 +
include/standard-headers/linux/virtio_scsi.h | 164 +++++++++++++++
include/standard-headers/linux/virtio_types.h | 46 ++++
linux-headers/linux/virtio_config.h | 58 +----
linux-headers/linux/virtio_ring.h | 164 +--------------
hw/block/virtio-blk.c | 8 +-
hw/char/virtio-serial-bus.c | 1 +
hw/net/vhost_net.c | 2 +-
hw/scsi/virtio-scsi.c | 1 +
hw/virtio/virtio-pci.c | 54 +----
hw/virtio/virtio.c | 23 +-
scripts/update-linux-headers.sh | 51 ++++-
37 files changed, 1345 insertions(+), 880 deletions(-)
create mode 100644 include/standard-headers/asm-s390/kvm_virtio.h
create mode 100644 include/standard-headers/asm-s390/virtio-ccw.h
create mode 100644 include/standard-headers/linux/if_ether.h
create mode 100644 include/standard-headers/linux/types.h
create mode 100644 include/standard-headers/linux/virtio_9p.h
create mode 100644 include/standard-headers/linux/virtio_balloon.h
create mode 100644 include/standard-headers/linux/virtio_blk.h
create mode 100644 include/standard-headers/linux/virtio_config.h
create mode 100644 include/standard-headers/linux/virtio_console.h
create mode 100644 include/standard-headers/linux/virtio_ids.h
create mode 100644 include/standard-headers/linux/virtio_net.h
create mode 100644 include/standard-headers/linux/virtio_pci.h
rename include/{hw/virtio => standard-headers/linux}/virtio_ring.h (57%)
create mode 100644 include/standard-headers/linux/virtio_rng.h
create mode 100644 include/standard-headers/linux/virtio_scsi.h
create mode 100644 include/standard-headers/linux/virtio_types.hSignature · 1 line
MST
PATCH v3 1/17 scripts/update-linux-headers.sh: pull virtio hdrs
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.
--- scripts/update-linux-headers.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
scripts/update-linux-headers.sh +41 -0
@@ -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=$(basename "$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\/linux\/\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 *)
@@ -76,4 +106,15 @@ else cp "$linux/COPYING" "$output/linux-headers" fi + +cp_virtio "$tmpdir/include/linux/" "$output/include/standard-headers/linux" + +cat <<EOF >$output/include/standard-headers/linux/types.h +#include <stdint.h> +#include "qemu/compiler.h" +EOF +cat <<EOF >$output/include/standard-headers/linux/if_ether.h +#define ETH_ALEN 6 +EOF + rm -rf "$tmpdir"
Signature · 1 line
MST
PATCH v3 2/17 include: import virtio headers from linux 4.0
In reply to Michael S. TsirkinAdd files imported from linux-next (what will become linux 4.0) using scripts/update-linux-headers.sh
--- include/standard-headers/linux/if_ether.h | 1 + include/standard-headers/linux/types.h | 2 + include/standard-headers/linux/virtio_9p.h | 44 +++++ include/standard-headers/linux/virtio_balloon.h | 59 ++++++ include/standard-headers/linux/virtio_blk.h | 143 +++++++++++++++ include/standard-headers/linux/virtio_config.h | 64 +++++++ include/standard-headers/linux/virtio_console.h | 78 ++++++++ include/standard-headers/linux/virtio_ids.h | 43 +++++ include/standard-headers/linux/virtio_net.h | 233 ++++++++++++++++++++++++ include/standard-headers/linux/virtio_pci.h | 193 ++++++++++++++++++++ include/standard-headers/linux/virtio_ring.h | 171 +++++++++++++++++ include/standard-headers/linux/virtio_rng.h | 8 + include/standard-headers/linux/virtio_scsi.h | 164 +++++++++++++++++ include/standard-headers/linux/virtio_types.h | 46 +++++ 14 files changed, 1249 insertions(+) create mode 100644 include/standard-headers/linux/if_ether.h create mode 100644 include/standard-headers/linux/types.h create mode 100644 include/standard-headers/linux/virtio_9p.h create mode 100644 include/standard-headers/linux/virtio_balloon.h create mode 100644 include/standard-headers/linux/virtio_blk.h create mode 100644 include/standard-headers/linux/virtio_config.h create mode 100644 include/standard-headers/linux/virtio_console.h create mode 100644 include/standard-headers/linux/virtio_ids.h create mode 100644 include/standard-headers/linux/virtio_net.h create mode 100644 include/standard-headers/linux/virtio_pci.h create mode 100644 include/standard-headers/linux/virtio_ring.h create mode 100644 include/standard-headers/linux/virtio_rng.h create mode 100644 include/standard-headers/linux/virtio_scsi.h create mode 100644 include/standard-headers/linux/virtio_types.h
include/standard-headers/linux/if_ether.h new file +1 -0
@@ -0,0 +1 @@ +#define ETH_ALEN 6
include/standard-headers/linux/types.h new file +2 -0
@@ -0,0 +1,2 @@ +#include <inttypes.h> +#include "qemu/compiler.h"
include/standard-headers/linux/virtio_9p.h new file +44 -0
44 lines not on this page · raw message
include/standard-headers/linux/virtio_balloon.h new file +59 -0
59 lines not on this page · raw message
include/standard-headers/linux/virtio_blk.h new file +143 -0
143 lines not on this page · raw message
include/standard-headers/linux/virtio_config.h new file +64 -0
64 lines not on this page · raw message
include/standard-headers/linux/virtio_console.h new file +78 -0
78 lines not on this page · raw message
include/standard-headers/linux/virtio_ids.h new file +43 -0
43 lines not on this page · raw message
include/standard-headers/linux/virtio_net.h new file +233 -0
233 lines not on this page · raw message
include/standard-headers/linux/virtio_pci.h new file +193 -0
193 lines not on this page · raw message
include/standard-headers/linux/virtio_ring.h new file +171 -0
171 lines not on this page · raw message
include/standard-headers/linux/virtio_rng.h new file +8 -0
@@ -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/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_config.h" + +#endif /* _LINUX_VIRTIO_RNG_H */
include/standard-headers/linux/virtio_scsi.h new file +164 -0
164 lines not on this page · raw message
include/standard-headers/linux/virtio_types.h new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v3 02/17] include: import virtio headers from linux 4.0
Quoted 48 lines · On Mon, 16 Feb 2015 22:35:31 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Add files imported from linux-next (what will become linux 4.0) using
scripts/update-linux-headers.shSigned-off-by Michael S. Tsirkin <[email protected]>--- include/standard-headers/linux/if_ether.h | 1 + include/standard-headers/linux/types.h | 2 + include/standard-headers/linux/virtio_9p.h | 44 +++++ include/standard-headers/linux/virtio_balloon.h | 59 ++++++ include/standard-headers/linux/virtio_blk.h | 143 +++++++++++++++ include/standard-headers/linux/virtio_config.h | 64 +++++++ include/standard-headers/linux/virtio_console.h | 78 ++++++++ include/standard-headers/linux/virtio_ids.h | 43 +++++ include/standard-headers/linux/virtio_net.h | 233 ++++++++++++++++++++++++ include/standard-headers/linux/virtio_pci.h | 193 ++++++++++++++++++++ include/standard-headers/linux/virtio_ring.h | 171 +++++++++++++++++ include/standard-headers/linux/virtio_rng.h | 8 + include/standard-headers/linux/virtio_scsi.h | 164 +++++++++++++++++ include/standard-headers/linux/virtio_types.h | 46 +++++ 14 files changed, 1249 insertions(+) create mode 100644 include/standard-headers/linux/if_ether.h create mode 100644 include/standard-headers/linux/types.h create mode 100644 include/standard-headers/linux/virtio_9p.h create mode 100644 include/standard-headers/linux/virtio_balloon.h create mode 100644 include/standard-headers/linux/virtio_blk.h create mode 100644 include/standard-headers/linux/virtio_config.h create mode 100644 include/standard-headers/linux/virtio_console.h create mode 100644 include/standard-headers/linux/virtio_ids.h create mode 100644 include/standard-headers/linux/virtio_net.h create mode 100644 include/standard-headers/linux/virtio_pci.h create mode 100644 include/standard-headers/linux/virtio_ring.h create mode 100644 include/standard-headers/linux/virtio_rng.h create mode 100644 include/standard-headers/linux/virtio_scsi.h create mode 100644 include/standard-headers/linux/virtio_types.hinclude/standard-headers/linux/if_ether.h new file +1
-0@@ -0,0 +1 @@ +#define ETH_ALEN 6include/standard-headers/linux/types.h new file +0
-0
include/standard-headers/linux/types.h line 1
Quoted 1 line
include/standard-headers/linux/types.h new file +1
-0@@ -0,0 +1,2 @@ +#include <inttypes.h>
That should be <stdint.h> now, shouldn't it?
Thomas
Re: [Qemu-devel] [PATCH v3 02/17] include: import virtio headers from linux 4.0
Quoted 55 lines · Thomas Huth
Quoted 48 lines · On Mon, 16 Feb 2015 22:35:31 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Add files imported from linux-next (what will become linux 4.0) using
scripts/update-linux-headers.shSigned-off-by Michael S. Tsirkin <[email protected]>--- include/standard-headers/linux/if_ether.h | 1 + include/standard-headers/linux/types.h | 2 + include/standard-headers/linux/virtio_9p.h | 44 +++++ include/standard-headers/linux/virtio_balloon.h | 59 ++++++ include/standard-headers/linux/virtio_blk.h | 143 +++++++++++++++ include/standard-headers/linux/virtio_config.h | 64 +++++++ include/standard-headers/linux/virtio_console.h | 78 ++++++++ include/standard-headers/linux/virtio_ids.h | 43 +++++ include/standard-headers/linux/virtio_net.h | 233 ++++++++++++++++++++++++ include/standard-headers/linux/virtio_pci.h | 193 ++++++++++++++++++++ include/standard-headers/linux/virtio_ring.h | 171 +++++++++++++++++ include/standard-headers/linux/virtio_rng.h | 8 + include/standard-headers/linux/virtio_scsi.h | 164 +++++++++++++++++ include/standard-headers/linux/virtio_types.h | 46 +++++ 14 files changed, 1249 insertions(+) create mode 100644 include/standard-headers/linux/if_ether.h create mode 100644 include/standard-headers/linux/types.h create mode 100644 include/standard-headers/linux/virtio_9p.h create mode 100644 include/standard-headers/linux/virtio_balloon.h create mode 100644 include/standard-headers/linux/virtio_blk.h create mode 100644 include/standard-headers/linux/virtio_config.h create mode 100644 include/standard-headers/linux/virtio_console.h create mode 100644 include/standard-headers/linux/virtio_ids.h create mode 100644 include/standard-headers/linux/virtio_net.h create mode 100644 include/standard-headers/linux/virtio_pci.h create mode 100644 include/standard-headers/linux/virtio_ring.h create mode 100644 include/standard-headers/linux/virtio_rng.h create mode 100644 include/standard-headers/linux/virtio_scsi.h create mode 100644 include/standard-headers/linux/virtio_types.hinclude/standard-headers/linux/if_ether.h new file +1
-0@@ -0,0 +1 @@ +#define ETH_ALEN 6include/standard-headers/linux/types.h new file +0
-0include/standard-headers/linux/types.h line 1
Quoted 1 line
include/standard-headers/linux/types.h new file +1
-0@@ -0,0 +1,2 @@ +#include <inttypes.h> That should be <
stdint.h> now, shouldn't it?
Quoted 1 line
Thomas
Oh, right, I forgot to re-run it.
I'll fix it up with a patch on top?
Signature · 1 line
MST
PATCH v3 3/17 virtio: use standard virtio_ring.h
In reply to Michael S. TsirkinSwitch to virtio_ring.h from standard headers.
--- 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
include/hw/virtio/dataplane/vring.h +1 -1
@@ -18,7 +18,7 @@#define VRING_H #include "qemu-common.h" -#include "hw/virtio/virtio_ring.h" +#include "standard-headers/linux/virtio_ring.h" #include "hw/virtio/virtio.h" typedef struct {
include/hw/virtio/virtio_ring.h deleted +0 -167
167 lines not on this page · raw message
hw/net/vhost_net.c +1 -1
@@ -35,7 +35,7 @@#include <stdio.h> -#include "hw/virtio/virtio_ring.h" +#include "standard-headers/linux/virtio_ring.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-bus.h"
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v3 03/17] virtio: use standard virtio_ring.h
Quoted 29 lines · On Mon, 16 Feb 2015 22:35:40 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Switch to
virtio_ring.hfrom standard headers.Signed-off-by Michael S. Tsirkin <[email protected]>--- 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.hinclude/hw/virtio/dataplane/vring.h +1
-1@@ -18,7 +18,7 @@#define VRING_H #include "qemu-common.h" -#include "hw/virtio/virtio_ring.h" +#include "standard-headers/linux/virtio_ring.h" #include "hw/virtio/virtio.h" typedef struct {include/hw/virtio/virtio_ring.h deleted +0
-0
include/hw/virtio/virtio_ring.h line 6
Quoted 6 lines
include/hw/virtio/virtio_ring.h deleted +0
-6@@ -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. -* */
Hmmm, in the old header, the "__inline__" was replaced with "inline" ... in the new header from patch 2, there's now "__inline__" again. Was there a good reason for this replacement? If yes, your update-linux-headers.sh patch should maybe replace the "__inline__" into "inline", too?
Apart from that, the patch looks good to me.
Thomas
Re: [Qemu-devel] [PATCH v3 03/17] virtio: use standard virtio_ring.h
Quoted 45 lines · Thomas Huth
Quoted 29 lines · On Mon, 16 Feb 2015 22:35:40 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Switch to
virtio_ring.hfrom standard headers.Signed-off-by Michael S. Tsirkin <[email protected]>--- 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.hinclude/hw/virtio/dataplane/vring.h +1
-1@@ -18,7 +18,7 @@#define VRING_H #include "qemu-common.h" -#include "hw/virtio/virtio_ring.h" +#include "standard-headers/linux/virtio_ring.h" #include "hw/virtio/virtio.h" typedef struct {include/hw/virtio/virtio_ring.h deleted +0
-0include/hw/virtio/virtio_ring.h line 6
Quoted 6 lines
include/hw/virtio/virtio_ring.h deleted +0
-6@@ -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. -* */ Hmmm, in the old header, the "
__inline__" was replaced with "inline" ... in the new header from patch 2, there's now "__inline__" again. Was there a good reason for this replacement? If yes, yourupdate-linux-headers.shpatch should maybe replace the "__inline__" into "inline", too?
Quoted 3 lines
Apart from that, the patch looks good to me.
Thomas
Probably a good idea, will do, though I wonder why does qemu use always_inline so aggressively.
OK to do as patch on top? This series is too big already.
Signature · 1 line
MST
PATCH v3 4/17 virtio: use standard-headers
In reply to Michael S. TsirkinDrop 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.
--- hw/9pfs/virtio-9p.h | 1 + include/hw/virtio/virtio.h | 48 ++-------------------------------------------- hw/virtio/virtio.c | 23 +++++----------------- 3 files changed, 8 insertions(+), 64 deletions(-)
hw/9pfs/virtio-9p.h +1 -0
@@ -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"
include/hw/virtio/virtio.h +2 -46
58 lines not on this page · raw message
hw/virtio/virtio.c +5 -18
@@ -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)
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v3 04/17] virtio: use standard-headers
Quoted 147 lines · On Mon, 16 Feb 2015 22:35:46 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Drop a bunch of code duplicated from
virtio_config.handvirtio_ring.h. This makes us rename event index accessors which conflict, as reusing the ones fromvirtio_ring.hisn't trivial.Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/9pfs/virtio-9p.h | 1 + include/hw/virtio/virtio.h | 48 ++-------------------------------------------- hw/virtio/virtio.c | 23 +++++----------------- 3 files changed, 8 insertions(+), 64 deletions(-)hw/9pfs/virtio-9p.h +1
-0@@ -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" include/hw/virtio/virtio.h +2
-46@@ -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/linux/virtio_config.h" +#include "standard-headers/linux/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,hw/virtio/virtio.c +4
-17@@ -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;
hw/virtio/virtio.c static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq) · line 845
Quoted 8 lines
hw/virtio/virtio.c +1
-1@@ -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)
PATCH v3 5/17 virtio-balloon: use standard headers
In reply to Michael S. TsirkinDrop code duplicated from standard headers.
--- include/hw/virtio/virtio-balloon.h | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-)
include/hw/virtio/virtio-balloon.h +2 -33
@@ -15,6 +15,7 @@#ifndef _QEMU_VIRTIO_BALLOON_H#define _QEMU_VIRTIO_BALLOON_H +#include "standard-headers/linux/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;
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v3 05/17] virtio-balloon: use standard headers
Quoted 50 lines · On Mon, 16 Feb 2015 22:35:52 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Drop code duplicated from standard headers.
Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/virtio/virtio-balloon.h | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-)include/hw/virtio/virtio-balloon.h +1
-27@@ -15,6 +15,7 @@#ifndef _QEMU_VIRTIO_BALLOON_H#define _QEMU_VIRTIO_BALLOON_H +#include "standard-headers/linux/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 */
include/hw/virtio/virtio-balloon.h line 29
Quoted 10 lines
include/hw/virtio/virtio-balloon.h +1
-6-#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;
PATCH v3 6/17 virtio-9p: use standard headers
In reply to Michael S. TsirkinDrop code duplicated from standard headers.
--- hw/9pfs/virtio-9p.h | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-)
hw/9pfs/virtio-9p.h +1 -16
@@ -7,6 +7,7 @@#include <utime.h> #include <sys/resource.h> #include <glib.h> +#include "standard-headers/linux/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;
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v3 06/17] virtio-9p: use standard headers
Quoted 46 lines · On Mon, 16 Feb 2015 22:35:57 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Drop code duplicated from standard headers.
Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/9pfs/virtio-9p.h | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-)hw/9pfs/virtio-9p.h +1
-9@@ -7,6 +7,7 @@#include <utime.h> #include <sys/resource.h> #include <glib.h> +#include "standard-headers/linux/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
hw/9pfs/virtio-9p.h typedef struct V9fsWriteState { · line 276
Quoted 10 lines
hw/9pfs/virtio-9p.h +0
-7-{ -/* 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;
PATCH v3 7/17 virtio-blk: switch to standard-headers
In reply to Michael S. TsirkinDrop duplicated code. Minor codechanges were required as geometry is a sub-structure now.
--- include/hw/virtio/virtio-blk.h | 77 +----------------------------------------- hw/block/virtio-blk.c | 8 ++--- 2 files changed, 5 insertions(+), 80 deletions(-)
include/hw/virtio/virtio-blk.h +1 -76
@@ -14,6 +14,7 @@#ifndef _QEMU_VIRTIO_BLK_H#define _QEMU_VIRTIO_BLK_H +#include "standard-headers/linux/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;
hw/block/virtio-blk.c +4 -4
@@ -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);
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v3 07/17] virtio-blk: switch to standard-headers
Quoted 130 lines · On Mon, 16 Feb 2015 22:36:03 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Drop duplicated code. Minor codechanges were required as geometry is a sub-structure now.
Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/virtio/virtio-blk.h | 77 +----------------------------------------- hw/block/virtio-blk.c | 8 ++--- 2 files changed, 5 insertions(+), 80 deletions(-)include/hw/virtio/virtio-blk.h +1
-76@@ -14,6 +14,7 @@#ifndef _QEMU_VIRTIO_BLK_H#define _QEMU_VIRTIO_BLK_H +#include "standard-headers/linux/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;hw/block/virtio-blk.c +2
-2@@ -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).
hw/block/virtio-blk.c static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) · line 692
Quoted 10 lines
hw/block/virtio-blk.c +2
-2*/ 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);
PATCH v3 8/17 virtio-net, tap: use standard-headers
In reply to Michael S. TsirkinDrop duplicated code.
--- include/hw/virtio/virtio-net.h | 151 +---------------------------------------- include/net/tap.h | 24 +------ 2 files changed, 2 insertions(+), 173 deletions(-)
include/hw/virtio/virtio-net.h +1 -150
@@ -14,49 +14,15 @@#ifndef _QEMU_VIRTIO_NET_H#define _QEMU_VIRTIO_NET_H +#include "standard-headers/linux/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 *
include/net/tap.h +1 -23
@@ -28,6 +28,7 @@#include "qemu-common.h" #include "qapi-types.h" +#include "standard-headers/linux/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 */
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v3 08/17] virtio-net, tap: use standard-headers
Quoted 222 lines · On Mon, 16 Feb 2015 22:36:09 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Drop duplicated code.
Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/virtio/virtio-net.h | 151 +---------------------------------------- include/net/tap.h | 24 +------ 2 files changed, 2 insertions(+), 173 deletions(-)include/hw/virtio/virtio-net.h +1
-150@@ -14,49 +14,15 @@#ifndef _QEMU_VIRTIO_NET_H#define _QEMU_VIRTIO_NET_H +#include "standard-headers/linux/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 * include/net/tap.h +1
-14@@ -28,6 +28,7 @@#include "qemu-common.h" #include "qapi-types.h" +#include "standard-headers/linux/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;
include/net/tap.h int tap_get_fd(NetClientState *nc); · line 41
Quoted 10 lines
include/net/tap.h +0
-9- 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 */
PATCH v3 9/17 virtio-rng: use standard-headers
In reply to Michael S. TsirkinDrop duplicated code.
--- include/hw/virtio/virtio-rng.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
include/hw/virtio/virtio-rng.h +1 -3
@@ -14,6 +14,7 @@#include "sysemu/rng.h" #include "sysemu/rng-random.h" +#include "standard-headers/linux/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;
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v3 09/17] virtio-rng: use standard-headers
Quoted 20 lines · On Mon, 16 Feb 2015 22:36:15 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Drop duplicated code.
Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/virtio/virtio-rng.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)include/hw/virtio/virtio-rng.h +1
-0@@ -14,6 +14,7 @@#include "sysemu/rng.h" #include "sysemu/rng-random.h" +#include "standard-headers/linux/virtio_rng.h" #define TYPE_VIRTIO_RNG "virtio-rng-device"#define VIRTIO_RNG (obj) \
include/hw/virtio/virtio-rng.h line 27
Quoted 9 lines
include/hw/virtio/virtio-rng.h +0
-3@@ -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;
PATCH v3 10/17 virtio-scsi: use standard-headers
In reply to Michael S. TsirkinDrop duplicated code.
--- include/hw/virtio/virtio-scsi.h | 120 +++------------------------------------- hw/scsi/virtio-scsi.c | 1 + 2 files changed, 10 insertions(+), 111 deletions(-)
include/hw/virtio/virtio-scsi.h +9 -111
@@ -14,6 +14,7 @@#ifndef _QEMU_VIRTIO_SCSI_H#define _QEMU_VIRTIO_SCSI_H +#include "standard-headers/linux/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;
hw/scsi/virtio-scsi.c +1 -0
@@ -13,6 +13,7 @@* */ +#include "standard-headers/linux/virtio_ids.h" #include "hw/virtio/virtio-scsi.h" #include "qemu/error-report.h" #include "qemu/iov.h"
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v3 10/17] virtio-scsi: use standard-headers
Quoted 13 lines · Michael S. Tsirkin
Drop duplicated code.
Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/virtio/virtio-scsi.h | 120 +++------------------------------------- hw/scsi/virtio-scsi.c | 1 + 2 files changed, 10 insertions(+), 111 deletions(-)include/hw/virtio/virtio-scsi.h +0
-0
include/hw/virtio/virtio-scsi.h line 17
Quoted 4 lines
include/hw/virtio/virtio-scsi.h +1
-0@@ -14,6 +14,7 @@#ifndef _QEMU_VIRTIO_SCSI_H#define _QEMU_VIRTIO_SCSI_H +#include "standard-headers/linux/virtio_scsi.h"
Quoted 149 lines
include/hw/virtio/virtio-scsi.h +8
-111#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;hw/scsi/virtio-scsi.c +1
-0@@ -13,6 +13,7 @@* */ +#include "standard-headers/linux/virtio_ids.h" #include "hw/virtio/virtio-scsi.h" #include "qemu/error-report.h" #include "qemu/iov.h"
Re: [Qemu-devel] [PATCH v3 10/17] virtio-scsi: use standard-headers
In reply to Michael S. TsirkinHi Michael,
Quoted 3 lines · Michael S. Tsirkin
Drop duplicated code.
Signed-off-by Michael S. Tsirkin <[email protected]>
This patch is breaking SLOF. Reason below:
include/hw/virtio/virtio-scsi.h
Quoted 9 lines
--- include/hw/virtio/virtio-scsi.h | 120 +++------------------------------------- hw/scsi/virtio-scsi.c | 1 + 2 files changed, 10 insertions(+), 111 deletions(-)include/hw/virtio/virtio-scsi.h +0
-0
For instance:
include/hw/virtio/virtio-scsi.h line 96
Quoted 9 lines
include/hw/virtio/virtio-scsi.h +0
-9- -/* 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;
in include/standard-headers/linux/virtio_scsi.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;Here the structure is changed having cdb as extra member. Moreover, we have checks like below in hw/scsi/virtio-scsi.c
rc = virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size,
sizeof(VirtIOSCSICmdResp) + vs->sense_size);Now that the size of CmdReq structure is not the same as earlier. Similarly for CmdResp structure.
SLOF has these headers replicated, IMHO, we should be changing the structure size.
Quoted 77 lines
include/hw/virtio/virtio-scsi.h +8
-52- -/* 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;hw/scsi/virtio-scsi.c +1
-0@@ -13,6 +13,7 @@* */ +#include "standard-headers/linux/virtio_ids.h" #include "hw/virtio/virtio-scsi.h" #include "qemu/error-report.h" #include "qemu/iov.h" Signature · 1 line
MST
Thanks
Nikunj
Re: [Qemu-devel] [PATCH v3 10/17] virtio-scsi: use standard-headers
Quoted 9 lines · Nikunj A Dadhania
Hi Michael,
Quoted 3 lines · Michael S. Tsirkin
Drop duplicated code.
Signed-off-by Michael S. Tsirkin <[email protected]>This patch is breaking SLOF. Reason below:
Can you please try out this patch:
mid.gmane.org/[email protected]
Thanks!
Quoted 129 lines
include/hw/virtio/virtio-scsi.h
Quoted 9 lines
--- include/hw/virtio/virtio-scsi.h | 120 +++------------------------------------- hw/scsi/virtio-scsi.c | 1 + 2 files changed, 10 insertions(+), 111 deletions(-)include/hw/virtio/virtio-scsi.h +0
-0For instance:
include/hw/virtio/virtio-scsi.h line 96
Quoted 9 lines
include/hw/virtio/virtio-scsi.h +0
-9- -/* 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;in
include/standard-headers/linux/virtio_scsi.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;Here the structure is changed having cdb as extra member. Moreover, we have checks like below in
hw/scsi/virtio-scsi.crc = virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size, sizeof(VirtIOSCSICmdResp) + vs->sense_size);Now that the size of CmdReq structure is not the same as earlier. Similarly for CmdResp structure.
SLOF has these headers replicated, IMHO, we should be changing the structure size.
Quoted 77 lines
include/hw/virtio/virtio-scsi.h +8
-52- -/* 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;hw/scsi/virtio-scsi.c +1
-0@@ -13,6 +13,7 @@* */ +#include "standard-headers/linux/virtio_ids.h" #include "hw/virtio/virtio-scsi.h" #include "qemu/error-report.h" #include "qemu/iov.h" Signature · 1 line
MSTThanks
Nikunj
Re: [Qemu-devel] [PATCH v3 10/17] virtio-scsi: use standard-headers
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Nikunj A Dadhania
Hi Michael,
"Michael S. Tsirkin" <[email protected]> writes:
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Drop duplicated code.
Signed-off-by Michael S. Tsirkin <[email protected]>This patch is breaking SLOF. Reason below:
Can you please try out this patch:
mid.gmane.org/[email protected]
Yes its fixed.
Regards
Nikunj
PATCH v3 11/17 virtio-serial: switch to standard-headers
In reply to Michael S. TsirkinDrop duplicate code.
--- include/hw/virtio/virtio-serial.h | 40 +-------------------------------------- hw/char/virtio-serial-bus.c | 1 + 2 files changed, 2 insertions(+), 39 deletions(-)
include/hw/virtio/virtio-serial.h +1 -39
@@ -15,53 +15,15 @@#ifndef _QEMU_VIRTIO_SERIAL_H#define _QEMU_VIRTIO_SERIAL_H +#include "standard-headers/linux/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)
hw/char/virtio-serial-bus.c +1 -0
@@ -18,6 +18,7 @@* GNU GPL, version 2 or (at your option) any later version. */ +#include "standard-headers/linux/virtio_ids.h" #include "qemu/iov.h" #include "monitor/monitor.h" #include "qemu/queue.h"
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v3 11/17] virtio-serial: switch to standard-headers
Quoted 72 lines · On Mon, 16 Feb 2015 22:36:26 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Drop duplicate code.
Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/virtio/virtio-serial.h | 40 +-------------------------------------- hw/char/virtio-serial-bus.c | 1 + 2 files changed, 2 insertions(+), 39 deletions(-)include/hw/virtio/virtio-serial.h +1
-39@@ -15,53 +15,15 @@#ifndef _QEMU_VIRTIO_SERIAL_H#define _QEMU_VIRTIO_SERIAL_H +#include "standard-headers/linux/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)hw/char/virtio-serial-bus.c +0
-0
hw/char/virtio-serial-bus.c line 21
Quoted 4 lines
hw/char/virtio-serial-bus.c +1
-0@@ -18,6 +18,7 @@* GNU GPL, version 2 or (at your option) any later version. */ +#include "standard-headers/linux/virtio_ids.h"
Could you omit this include? Later in virtio-serial-bus.c, the code includes hw/virtio/virtio-serial.h, which in turn includes standard-headers/linux/virtio_console.h - and that one already includes the ids.h file. So I think it should work without the above change, too.
Thomas
Re: [Qemu-devel] [PATCH v3 11/17] virtio-serial: switch to standard-headers
Quoted 78 lines · Thomas Huth
Quoted 75 lines · On Mon, 16 Feb 2015 22:36:26 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Drop duplicate code.
Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/virtio/virtio-serial.h | 40 +-------------------------------------- hw/char/virtio-serial-bus.c | 1 + 2 files changed, 2 insertions(+), 39 deletions(-)include/hw/virtio/virtio-serial.h +1
-39@@ -15,53 +15,15 @@#ifndef _QEMU_VIRTIO_SERIAL_H#define _QEMU_VIRTIO_SERIAL_H +#include "standard-headers/linux/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)hw/char/virtio-serial-bus.c +0
-0@@ -18,6 +18,7 @@* GNU GPL, version 2 or (at your option) any later version. */
Quoted 8 lines
hw/char/virtio-serial-bus.c line 21
Quoted 1 line
hw/char/virtio-serial-bus.c +1
-0+#include "standard-headers/linux/virtio_ids.h" Could you omit this include? Later in
virtio-serial-bus.c, the code includeshw/virtio/virtio-serial.h, which in turn includesstandard-headers/linux/virtio_console.h- and that one already includes theids.hfile. So I think it should work without the above change, too.Thomas
Yes but it's generally not a good idea to depend on headers including each other.
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v3 11/17] virtio-serial: switch to standard-headers
Quoted 3 lines · On Wed, 18 Feb 2015 15:55:54 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 2 lines · Thomas Huth
On Mon, 16 Feb 2015 22:36:26 +0100
"Michael S. Tsirkin" <[email protected]> wrote:
...
Quoted 15 lines
Quoted 15 lines
hw/char/virtio-serial-bus.c line 21
Quoted 9 lines
hw/char/virtio-serial-bus.c +1
-0@@ -18,6 +18,7 @@* GNU GPL, version 2 or (at your option) any later version. */ +#include "standard-headers/linux/virtio_ids.h" Could you omit this include? Later in
virtio-serial-bus.c, the code includeshw/virtio/virtio-serial.h, which in turn includesstandard-headers/linux/virtio_console.h- and that one already includes theids.hfile. So I think it should work without the above change, too.
Quoted 4 lines
Quoted 1 line
Thomas
Yes but it's generally not a good idea to depend on headers including each other.
But as far as I can see, you also did not do this change in your other patches of this series, so this seems a little bit inconsequent (e.g. virtio-blk.c depends on VIRTIO_ID_BLOCK, but you did not include the virtio_ids.h header there).
Thomas
Re: [Qemu-devel] [PATCH v3 11/17] virtio-serial: switch to standard-headers
Quoted 27 lines · Thomas Huth
Quoted 3 lines · On Wed, 18 Feb 2015 15:55:54 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 2 lines · Thomas Huth
On Mon, 16 Feb 2015 22:36:26 +0100
"Michael S. Tsirkin" <[email protected]> wrote:...
Quoted 15 lines
Quoted 15 lines
hw/char/virtio-serial-bus.c line 21
Quoted 9 lines
hw/char/virtio-serial-bus.c +1
-0@@ -18,6 +18,7 @@* GNU GPL, version 2 or (at your option) any later version. */ +#include "standard-headers/linux/virtio_ids.h" Could you omit this include? Later in
virtio-serial-bus.c, the code includeshw/virtio/virtio-serial.h, which in turn includesstandard-headers/linux/virtio_console.h- and that one already includes theids.hfile. So I think it should work without the above change, too.Quoted 4 lines
Quoted 1 line
Thomas
Yes but it's generally not a good idea to depend on headers including each other.
Quoted 6 lines
But as far as I can see, you also did not do this change in your other patches of this series, so this seems a little bit inconsequent (e.g.
virtio-blk.cdepends onVIRTIO_ID_BLOCK, but you did not include thevirtio_ids.hheader there).Thomas
OK - I'll do this as a patch on top?
Don't want to repost the whole series.
Signature · 1 line
MST
PATCH v3 12/17 update-linux-headers: use standard-headers
In reply to Michael S. TsirkinDrop the linux-specific virtio headers, use the copy from standard-headers instead.
--- scripts/update-linux-headers.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
scripts/update-linux-headers.sh +7 -1
@@ -91,7 +91,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
@@ -106,6 +106,12 @@ else cp "$linux/COPYING" "$output/linux-headers" fi +cat <<EOF >$output/linux-headers/linux/virtio_config.h +#include "standard-headers/linux/virtio_config.h" +EOF +cat <<EOF >$output/linux-headers/linux/virtio_ring.h +#include "standard-headers/linux/virtio_ring.h" +EOF cp_virtio "$tmpdir/include/linux/" "$output/include/standard-headers/linux"
Signature · 1 line
MST
PATCH v3 13/17 linux-headers: use standard-headers
In reply to Michael S. TsirkinDrop duplicated code.
--- linux-headers/linux/virtio_config.h | 58 +------------ linux-headers/linux/virtio_ring.h | 164 +----------------------------------- 2 files changed, 2 insertions(+), 220 deletions(-)
linux-headers/linux/virtio_config.h +1 -57
@@ -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/linux/virtio_config.h"
linux-headers/linux/virtio_ring.h +1 -163
164 lines not on this page · raw message
Signature · 1 line
MST
PATCH v3 14/17 virtio-pci: use standard headers
In reply to Michael S. TsirkinDrop duplicate code.
--- hw/virtio/virtio-pci.c | 54 +++++--------------------------------------------- 1 file changed, 5 insertions(+), 49 deletions(-)
hw/virtio/virtio-pci.c +5 -49
@@ -17,6 +17,7 @@#include <inttypes.h> +#include "standard-headers/linux/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);
Signature · 1 line
MST
PATCH v3 15/17 scripts: add arch specific standard-headers
In reply to Michael S. TsirkinCopy arch specific virtio headers.
ATM this applies to s390 only.
--- scripts/update-linux-headers.sh | 2 ++ 1 file changed, 2 insertions(+)
scripts/update-linux-headers.sh +2 -0
@@ -87,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"
Signature · 1 line
MST
PATCH v3 16/17 standard-headers: add s390 virtio headers
In reply to Michael S. Tsirkin--- 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
include/standard-headers/asm-s390/kvm_virtio.h new file +64 -0
@@ -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 <[email protected]> +*/ + +#ifndef __KVM_S390_VIRTIO_H +#define __KVM_S390_VIRTIO_H + +#include "standard-headers/linux/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
include/standard-headers/asm-s390/virtio-ccw.h new file +21 -0
@@ -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 <[email protected]> +*/ +#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
Signature · 1 line
MST
PATCH v3 17/17 s390: use standard headers
In reply to Michael S. TsirkinDrop duplicated macros in favor of values from
standard headers.
--- hw/s390x/s390-virtio-bus.h | 36 +++++++++++++++++++----------------- hw/s390x/s390-virtio.h | 7 ++----- 2 files changed, 21 insertions(+), 22 deletions(-)
hw/s390x/s390-virtio-bus.h +19 -17
@@ -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/linux/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)
hw/s390x/s390-virtio.h +2 -5
@@ -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);
Signature · 1 line
MST