From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvAxP-0002CG-Km for qemu-devel@nongnu.org; Tue, 06 Oct 2009 10:24:03 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvAxK-00027i-BG for qemu-devel@nongnu.org; Tue, 06 Oct 2009 10:24:03 -0400 Received: from [199.232.76.173] (port=54979 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvAxK-00027V-6N for qemu-devel@nongnu.org; Tue, 06 Oct 2009 10:23:58 -0400 Received: from fg-out-1718.google.com ([72.14.220.156]:61893) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MvAxJ-0007p0-Jq for qemu-devel@nongnu.org; Tue, 06 Oct 2009 10:23:57 -0400 Received: by fg-out-1718.google.com with SMTP id e21so691670fga.10 for ; Tue, 06 Oct 2009 07:23:56 -0700 (PDT) Message-ID: <4ACB52F7.80803@codemonkey.ws> Date: Tue, 06 Oct 2009 09:23:51 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <20090907181436.GA8538@redhat.com> <4AA60A58.4090703@redhat.com> <20090908075831.GA9875@redhat.com> <200909212039.01126.rusty@rustcorp.com.au> <4AB7A01A.3000206@redhat.com> <4AB8992B.7070709@redhat.com> <4AB8DD53.7070806@redhat.com> <4AB8DECA.3090908@redhat.com> <4AB8E88C.4040103@redhat.com> <4AB980E6.2070203@codemonkey.ws> <4AB9AA8E.7060800@third-harmonic.com> <4AC1A4AD.10509@redhat.com> <4ACA1527.9050305@third-harmonic.com> In-Reply-To: <4ACA1527.9050305@third-harmonic.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH] fix virtio_blk serial pci config breakage, v2 List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: john cooper Cc: "Michael S. Tsirkin" , john cooper , Rusty Russell , qemu-devel@nongnu.org, Avi Kivity , jens.axboe@oracle.com, Vadim Rozenfeld john cooper wrote: > This is a re-work of the previous version where the > associated data was being funneled through a free > PCI BAR mapping. Here a request for the identify > information results in a virtqueue command utilizing > the scaffolding introduced by Rusty's recent patch. > > Signed-off-by: john cooper > --- > > > diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c > index dad4ef0..e754277 100644 > --- a/hw/virtio-blk.c > +++ b/hw/virtio-blk.c > @@ -25,6 +25,7 @@ typedef struct VirtIOBlock > BlockDriverState *bs; > VirtQueue *vq; > void *rq; > + uint16_t identify[VIRTIO_BLK_ID_LEN]; > } VirtIOBlock; > > static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev) > @@ -32,6 +33,48 @@ static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev) > return (VirtIOBlock *)vdev; > } > > +/* store identify data in little endian format > + */ > +static inline void put_le16(uint16_t *p, unsigned int v) > +{ > + *p = cpu_to_le16(v); > +} > + > +/* copy to *dst from *src, nul pad dst tail as needed to len bytes > + */ > +static inline void padstr(char *dst, const char *src, int len) > +{ > + while (len--) > + *dst++ = *src ? *src++ : '\0'; > +} > + > +/* setup simulated identify data as appropriate for virtio block device > + * > + * ref: AT Attachment 8 - ATA/ATAPI Command Set (ATA8-ACS) > + */ > +static inline void virtio_identify_template(VirtIOBlock *s) > +{ > + uint16_t *p = s->identify; > + uint64_t lba_sectors; > + > + memset(p, 0, sizeof(uint16_t) * VIRTIO_BLK_ID_LEN); > + put_le16(p + 0, 0x0); /* ATA device */ > + padstr((char *)(p + 23), QEMU_VERSION, 8); /* firmware > revision */ > + padstr((char *)(p + 27), "QEMU VIRT_BLK", 40); /* model# */ > + put_le16(p + 47, 0x80ff); /* max xfer 255 > sectors */ > + put_le16(p + 49, 0x0b00); /* support > IORDY/LBA/DMA */ > + put_le16(p + 59, 0x1ff); /* cur xfer 255 > sectors */ > + put_le16(p + 80, 0x1f0); /* support > ATA8/7/6/5/4 */ > + put_le16(p + 81, 0x16); > + put_le16(p + 82, 0x400); > + put_le16(p + 83, 0x400); > + bdrv_get_geometry(s->bs, &lba_sectors); > + put_le16(p + 100, lba_sectors); > + put_le16(p + 101, lba_sectors >> 16); > + put_le16(p + 102, lba_sectors >> 32); > + put_le16(p + 103, lba_sectors >> 48); > +} > + > typedef struct VirtIOBlockReq > { > VirtIOBlock *dev; > @@ -243,6 +286,11 @@ static void virtio_blk_handle_output(VirtIODevice > *vdev, VirtQueue *vq) > > if (req->out->type & VIRTIO_BLK_T_SCSI_CMD) { > virtio_blk_handle_scsi(req); > + } > + else if (req->out->type & VIRTIO_BLK_T_GET_ID) { CodingStyle. > + memcpy(req->elem.in_sg[0].iov_base, s->identify, > + req->elem.in_sg[0].iov_len); > + virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); Weird indentation. Regards, Anthony Liguori