From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70084.outbound.protection.outlook.com [40.107.7.84]) by dpdk.org (Postfix) with ESMTP id F2A5E10BD for ; Mon, 10 Sep 2018 07:48:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Hq+xJUlaJNmiq5e+JOuHqI9xDSuYOO1RCgWHC1sNJEw=; b=jP0SFRw3EA8nEof1GTjW4MvsJ+ILHCEdtTDGv95cE1o97nh4so3taJ/c1ojV/p1wsy9l4qbqVd//Z4GggHHc8pq2mLfZ4yPR0Z/6mTTOYD8E7QklO0aDh/d3XtnDlsZYWxjylvt1VOnXNI0CfuwYN7yUjyXvbaci5xGg2yfOZ9E= Received: from VI1PR08MB3167.eurprd08.prod.outlook.com (52.133.15.142) by VI1PR08MB1117.eurprd08.prod.outlook.com (10.166.45.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.16; Mon, 10 Sep 2018 05:48:03 +0000 Received: from VI1PR08MB3167.eurprd08.prod.outlook.com ([fe80::b91d:e285:4647:f3e8]) by VI1PR08MB3167.eurprd08.prod.outlook.com ([fe80::b91d:e285:4647:f3e8%2]) with mapi id 15.20.1122.019; Mon, 10 Sep 2018 05:48:03 +0000 From: "Gavin Hu (Arm Technology China)" To: Jens Freimann , "dev@dpdk.org" CC: "tiwei.bie@intel.com" , "maxime.coquelin@redhat.com" Thread-Topic: [dpdk-dev] [PATCH v5 01/11] net/virtio: vring init for packed queues Thread-Index: AQHURg49klcYl72oWUSKVBt7w8plC6TpBg/A Date: Mon, 10 Sep 2018 05:48:03 +0000 Message-ID: References: <20180906181947.20646-1-jfreimann@redhat.com> <20180906181947.20646-2-jfreimann@redhat.com> In-Reply-To: <20180906181947.20646-2-jfreimann@redhat.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Gavin.Hu@arm.com; x-originating-ip: [113.29.88.7] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VI1PR08MB1117; 6:L8A/VY5U4bSTUR7c+y9HJjLP7iJ1g27nimQMUFuKb5VZ0DHbBl2W3Y1W6EHERZO7MbjqttLxll/jTAMgAHmJK+shshigrKeLx97uRIBlHk3tt37GbqeW/iIs2YderVhpgO9jQoFPFm7FQk0IN/R+svjGCKGgeEFBLOlRIbBw5XiXGeGzNjm5hahZOIQuONtdGo0kfw0G/LgNWz5rftC7EJPzBWhLBt/Rrv302LNTLbeSjMZMCI5hbsTpcDiKOW8BZZ2OTOdK5Av7MAL+v0ZpNHQSCM/8cHvGhTxpcxiyfAjwWE66eK5U43EYBliu9Dyo11gsfq9jwzXUV791tZ22X3ZgtzFHldv2k2R5hB2CZY/mH56AF2ZmRIjm1u+3gyZkOBtkFhnI/6EDPkvFMqas2dJBoSiqoSXhM3O3IhrbHtwJ9mgjfYVGgieEH2haskD1DrcjRO6gm2L+/W47sn9xoA==; 5:rNBgrgRqpW19sfbUDM974TPEt67diPtSEDs7FxkOHby9jAGB62jA1vpiEEOvMJEr+knXjK9wmky+e27sBVp4xMI5v69F+vYQWXnbPE9b6i8P6qsYKqTMjuJ6knvHG9Mvc4XoJXXDKvLIP3ex0rs+gNBRCxMm4rCphKibof05dQY=; 7:CeZ2WlhYEqCSsrbvgouznxApS7Cq6/Jp1cZQPQReDQeHc45y6YvDitRAie61AhAS5jgthfYPpwSyPaf/lUEduZMQNMuwAVgZOhhip0UsKAlEy5Laof+2ltx2Y9OYINewIca87FBCPLnmL3AC0BnGi8y2IfjRHvH1F5BLNcEX+431V76YxE8rFF/J3J8gSqjmf5Vh7VmgYanAwxZv55Az+N006uhKoIqi7Xnsi5ViwlvgOnxZHwVyJ7ZI1cy+8y1y x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 5d46deaa-1da0-42b1-2d13-08d616e0f965 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:VI1PR08MB1117; x-ms-traffictypediagnostic: VI1PR08MB1117: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(131327999870524)(103651359005742)(228905959029699); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231311)(944501410)(52105095)(3002001)(10201501046)(6055026)(149027)(150027)(6041310)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(201708071742011)(7699050); SRVR:VI1PR08MB1117; BCL:0; PCL:0; RULEID:; SRVR:VI1PR08MB1117; x-forefront-prvs: 07915F544A x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(366004)(376002)(396003)(39850400004)(346002)(189003)(199004)(13464003)(40434004)(33656002)(53546011)(11346002)(256004)(5024004)(186003)(14444005)(6246003)(476003)(99286004)(110136005)(25786009)(54906003)(102836004)(97736004)(7696005)(316002)(6506007)(4326008)(76176011)(68736007)(55236004)(2906002)(446003)(5660300001)(229853002)(66066001)(26005)(81156014)(81166006)(478600001)(14454004)(305945005)(8936002)(72206003)(486006)(106356001)(105586002)(8676002)(55016002)(86362001)(575784001)(6116002)(2900100001)(6436002)(3846002)(9686003)(74316002)(2501003)(53936002)(7736002)(5250100002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR08MB1117; H:VI1PR08MB3167.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: SECBoWa8YKNG3gq43ojyGp6MKnuTdeLuEfd6fkPulgFh8oxw0dwLfD7ra0OH+B23rm2O9szLNFe3tg1oBHpkZd207jhWGYOOy4NwvvjZ3lDJb76IMFyRIhd2p46ZEKzuk0XTt4g++JweIX7hsKng68yDYDPVhmrJQJ/D8QIyhfRUV3k9AvIDaFFkkwwLHMSISeG36Sr0VZrVEDdwkd11gtOaV/AcL/fkju98Mh+45u0uCVc+UBs6vuXEoS6WoHonDBaiUET/ENFRaLwJKK/axF2jOl6jMlobLEaADZNDo8m9poFuNGMHnTdsPmlPSnu6t0xZWbSe4MbIgE7lfhHnMzpavN7/KxTTNv5MPvKwuSE= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d46deaa-1da0-42b1-2d13-08d616e0f965 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Sep 2018 05:48:03.0375 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB1117 Subject: Re: [dpdk-dev] [PATCH v5 01/11] 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: Mon, 10 Sep 2018 05:48:05 -0000 > -----Original Message----- > From: dev On Behalf Of Jens Freimann > Sent: Friday, September 7, 2018 2:20 AM > To: dev@dpdk.org > Cc: tiwei.bie@intel.com; maxime.coquelin@redhat.com > Subject: [dpdk-dev] [PATCH v5 01/11] net/virtio: vring init for packed qu= eues > > Add and initialize descriptor data structures. > > Signed-off-by: Jens Freimann > --- > drivers/net/virtio/virtio_ethdev.c | 22 ++++++------ > drivers/net/virtio/virtio_pci.h | 8 +++++ > drivers/net/virtio/virtio_ring.h | 55 +++++++++++++++++++++++++++--- > drivers/net/virtio/virtqueue.h | 10 ++++++ > 4 files changed, 80 insertions(+), 15 deletions(-) > > diff --git a/drivers/net/virtio/virtio_ethdev.c > b/drivers/net/virtio/virtio_ethdev.c > index 614357da7..ad91f7f82 100644 > --- a/drivers/net/virtio/virtio_ethdev.c > +++ b/drivers/net/virtio/virtio_ethdev.c > @@ -299,19 +299,21 @@ virtio_init_vring(struct virtqueue *vq) > > PMD_INIT_FUNC_TRACE(); > > -/* > - * Reinitialise since virtio port might have been stopped and restarted > - */ > memset(ring_mem, 0, vq->vq_ring_size); > -vring_init(vr, size, ring_mem, VIRTIO_PCI_VRING_ALIGN); > -vq->vq_used_cons_idx =3D 0; > -vq->vq_desc_head_idx =3D 0; > -vq->vq_avail_idx =3D 0; > -vq->vq_desc_tail_idx =3D (uint16_t)(vq->vq_nentries - 1); > +vring_init(vq->hw, vr, size, ring_mem, VIRTIO_PCI_VRING_ALIGN); > + > vq->vq_free_cnt =3D vq->vq_nentries; > memset(vq->vq_descx, 0, sizeof(struct vq_desc_extra) * vq- > >vq_nentries); > +vq->vq_used_cons_idx =3D 0; > +vq->vq_avail_idx =3D 0; > +if (vtpci_packed_queue(vq->hw)) { > +vring_desc_init_packed(vr, size); > +} else { > +vq->vq_desc_head_idx =3D 0; > +vq->vq_desc_tail_idx =3D (uint16_t)(vq->vq_nentries - 1); > > -vring_desc_init(vr->desc, size); > +vring_desc_init(vr->desc, size); > +} > > /* > * Disable device(host) interrupting guest @@ -386,7 +388,7 @@ > virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) > /* > * Reserve a memzone for vring elements > */ > -size =3D vring_size(vq_size, VIRTIO_PCI_VRING_ALIGN); > +size =3D vring_size(hw, vq_size, VIRTIO_PCI_VRING_ALIGN); > vq->vq_ring_size =3D RTE_ALIGN_CEIL(size, > VIRTIO_PCI_VRING_ALIGN); > PMD_INIT_LOG(DEBUG, "vring_size: %d, rounded_vring_size: %d", > size, vq->vq_ring_size); > diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_= pci.h > index 58fdd3d45..90204d281 100644 > --- a/drivers/net/virtio/virtio_pci.h > +++ b/drivers/net/virtio/virtio_pci.h > @@ -113,6 +113,8 @@ struct virtnet_ctl; > > #define VIRTIO_F_VERSION_132 > #define VIRTIO_F_IOMMU_PLATFORM33 > +#define VIRTIO_F_RING_PACKED34 > +#define VIRTIO_F_IN_ORDER35 > > /* > * Some VirtIO feature bits (currently bits 28 through 31) are @@ -314,6 > +316,12 @@ vtpci_with_feature(struct virtio_hw *hw, uint64_t bit) > return (hw->guest_features & (1ULL << bit)) !=3D 0; } > > +static inline int > +vtpci_packed_queue(struct virtio_hw *hw) { > +return vtpci_with_feature(hw, VIRTIO_F_RING_PACKED); } > + > /* > * Function declaration from virtio_pci.c > */ > diff --git a/drivers/net/virtio/virtio_ring.h b/drivers/net/virtio/virtio= _ring.h > index 9e3c2a015..cea4d441e 100644 > --- a/drivers/net/virtio/virtio_ring.h > +++ b/drivers/net/virtio/virtio_ring.h > @@ -54,11 +54,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; Should be __le64 here, according to spec. same as follows. > +uint32_t len; > +uint16_t index; > +uint16_t flags; > +}; Should have __attribute__ ((aligned(16))) for alignment according to the sp= ec? Not sure if it automatically aligned at 16bytes boundary. > +#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 whic= h > @@ -95,10 +122,18 @@ 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 =3D num * sizeof(struct vring_desc_packed); > +size +=3D sizeof(struct vring_packed_desc_event); > +size =3D RTE_ALIGN_CEIL(size, align); > +size +=3D sizeof(struct vring_packed_desc_event); > +return size; > +} > + > size =3D num * sizeof(struct vring_desc); > size +=3D sizeof(struct vring_avail) + (num * sizeof(uint16_t)); > size =3D RTE_ALIGN_CEIL(size, align); > @@ -108,10 +143,20 @@ 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 =3D num; > +if (vtpci_packed_queue(hw)) { > +vr->desc_packed =3D (struct vring_desc_packed *)p; > +vr->driver_event =3D (struct vring_packed_desc_event *)(p + > +num * sizeof(struct vring_desc_packed)); > +vr->device_event =3D (struct vring_packed_desc_event *) > +RTE_ALIGN_CEIL((uintptr_t)(vr- > >driver_event + > +sizeof(struct vring_packed_desc_event)), > align); > +return; > +} > + > vr->desc =3D (struct vring_desc *) p; > vr->avail =3D (struct vring_avail *) (p + > num * sizeof(struct vring_desc)); > diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueu= e.h > index 26518ed98..d2a0b651a 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 =3D 0; i < n; i++) { > +struct vring_desc_packed *desc =3D &vr->desc_packed[i]; > +desc->index =3D i; > +} > +} > + > /* Chain all the descriptors in the ring with an END */ static inline v= oid > vring_desc_init(struct vring_desc *dp, uint16_t n) > -- > 2.17.1 IMPORTANT NOTICE: The contents of this email and any attachments are confid= ential and may also be privileged. If you are not the intended recipient, p= lease notify the sender immediately and do not disclose the contents to any= other person, use it for any purpose, or store or copy the information in = any medium. Thank you.