From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by dpdk.org (Postfix) with ESMTP id 27BC31CC86 for ; Thu, 5 Apr 2018 17:16:36 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 745BB402277B; Thu, 5 Apr 2018 15:16:36 +0000 (UTC) Received: from localhost (dhcp-192-241.str.redhat.com [10.33.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1B9FE2026980; Thu, 5 Apr 2018 15:16:35 +0000 (UTC) Date: Thu, 5 Apr 2018 17:16:34 +0200 From: Jens Freimann To: Tiwei Bie Cc: dev@dpdk.org, yliu@fridaylinux.org, maxime.coquelin@redhat.com, mst@redhat.com Message-ID: <20180405151634.lk3rgy23r4feebub@reserved-198-163.str.redhat.com> References: <20180405101031.26468-1-jfreimann@redhat.com> <20180405101031.26468-3-jfreimann@redhat.com> <20180405142227.66igif4hgwb3rgaq@debian> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20180405142227.66igif4hgwb3rgaq@debian> User-Agent: NeoMutt/20180223 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 05 Apr 2018 15:16:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 05 Apr 2018 15:16:36 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jfreimann@redhat.com' RCPT:'' Subject: Re: [dpdk-dev] [PATCH v3 02/21] net/virtio: vring init for packed queues X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Apr 2018 15:16:37 -0000 On Thu, Apr 05, 2018 at 10:22:28PM +0800, Tiwei Bie wrote: >On Thu, Apr 05, 2018 at 12:10:12PM +0200, Jens Freimann wrote: >> Add and initialize descriptor data structures. >> >> Signed-off-by: Jens Freimann >> --- >[...] >> diff --git a/drivers/net/virtio/virtio_ring.h b/drivers/net/virtio/virtio_ring.h >> index 9e3c2a015..1bd7ba98e 100644 >> --- a/drivers/net/virtio/virtio_ring.h >> +++ b/drivers/net/virtio/virtio_ring.h >> @@ -9,6 +9,7 @@ >> >> #include >> >> + > >There is no need to add this empty line. > >> /* 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). */ >> @@ -54,11 +55,38 @@ struct vring_used { >> struct vring_used_elem ring[0]; >> }; >> >> +/* For support of packed virtqueues in Virtio 1.1 the format of descriptors >> + * looks like this. >> + */ >> +struct vring_desc_packed { >> + uint64_t addr; >> + uint32_t len; >> + uint16_t index; >> + uint16_t flags; >> +}; >> + >> +#define RING_EVENT_FLAGS_ENABLE 0x0 >> +#define RING_EVENT_FLAGS_DISABLE 0x1 >> +#define RING_EVENT_FLAGS_DESC 0x2 >> +struct vring_packed_desc_event { >> + uint16_t desc_event_off_wrap; >> + uint16_t desc_event_flags; >> +}; >> + >> struct vring { >> unsigned int num; >> - struct vring_desc *desc; >> - struct vring_avail *avail; >> - struct vring_used *used; >> + union { >> + struct vring_desc_packed *desc_packed; >> + struct vring_desc *desc; >> + }; >> + union { >> + struct vring_avail *avail; >> + struct vring_packed_desc_event *driver_event; >> + }; >> + union { >> + struct vring_used *used; >> + struct vring_packed_desc_event *device_event; >> + }; >> }; >> >> /* The standard layout for the ring is a continuous chunk of memory which >> @@ -95,10 +123,16 @@ struct vring { >> #define vring_avail_event(vr) (*(uint16_t *)&(vr)->used->ring[(vr)->num]) >> >> static inline size_t >> -vring_size(unsigned int num, unsigned long align) >> +vring_size(struct virtio_hw *hw, unsigned int num, unsigned long align) >> { >> size_t size; >> >> + if (vtpci_packed_queue(hw)) { >> + size = num * sizeof(struct vring_desc_packed); > >I think you need to add paddings based on the alignment. > >> + size += 2 * sizeof(struct vring_packed_desc_event); >> + return size; >> + } >> + >> size = num * sizeof(struct vring_desc); >> size += sizeof(struct vring_avail) + (num * sizeof(uint16_t)); >> size = RTE_ALIGN_CEIL(size, align); >> @@ -108,10 +142,19 @@ vring_size(unsigned int num, unsigned long align) >> } >> >> static inline void >> -vring_init(struct vring *vr, unsigned int num, uint8_t *p, >> +vring_init(struct virtio_hw *hw, struct vring *vr, unsigned int num, uint8_t *p, >> unsigned long align) >> { >> vr->num = num; >> + if (vtpci_packed_queue(hw)) { >> + vr->desc_packed = (struct vring_desc_packed *)p; >> + vr->driver_event = (struct vring_packed_desc_event *) (p + >> + num * sizeof(struct vring_desc_packed)); > >I think paddings are needed here. I'll align it with RTE_ALIGN_CEIL, like it's done for the used ring address. Thanks! regards, Jens > >> + vr->device_event = (struct vring_packed_desc_event *) (vr->driver_event + >> + sizeof(struct vring_packed_desc_event)); >> + return; >> + } >> + >> vr->desc = (struct vring_desc *) p; >> vr->avail = (struct vring_avail *) (p + >> num * sizeof(struct vring_desc)); >> diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h >> index 14364f356..cc2e7c0f6 100644 >> --- a/drivers/net/virtio/virtqueue.h >> +++ b/drivers/net/virtio/virtqueue.h >> @@ -245,6 +245,16 @@ struct virtio_tx_region { >> __attribute__((__aligned__(16))); >> }; >> >> +static inline void >> +vring_desc_init_packed(struct vring *vr, int n) >> +{ >> + int i; >> + for (i = 0; i < n; i++) { >> + struct vring_desc_packed *desc = &vr->desc_packed[i]; >> + desc->index = i; >> + } >> +} >> + >> /* Chain all the descriptors in the ring with an END */ >> static inline void >> vring_desc_init(struct vring_desc *dp, uint16_t n) >> -- >> 2.14.3 >>