From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id AA6FE1CC1F for ; Thu, 5 Apr 2018 16:24:53 +0200 (CEST) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Apr 2018 07:24:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,411,1517904000"; d="scan'208";a="214182403" Received: from debian.sh.intel.com (HELO debian) ([10.67.104.164]) by orsmga005.jf.intel.com with ESMTP; 05 Apr 2018 07:24:25 -0700 Date: Thu, 5 Apr 2018 22:22:28 +0800 From: Tiwei Bie To: Jens Freimann Cc: dev@dpdk.org, yliu@fridaylinux.org, maxime.coquelin@redhat.com, mst@redhat.com Message-ID: <20180405142227.66igif4hgwb3rgaq@debian> References: <20180405101031.26468-1-jfreimann@redhat.com> <20180405101031.26468-3-jfreimann@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180405101031.26468-3-jfreimann@redhat.com> User-Agent: NeoMutt/20170113 (1.7.2) 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 14:24:54 -0000 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. > + 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 >