From patchwork Thu Apr 19 07:07:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Freimann X-Patchwork-Id: 38473 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F40487D0E; Thu, 19 Apr 2018 09:08:30 +0200 (CEST) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by dpdk.org (Postfix) with ESMTP id 2586C7CFB for ; Thu, 19 Apr 2018 09:08:29 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B9A1B406803E; Thu, 19 Apr 2018 07:08:28 +0000 (UTC) Received: from localhost (ovpn-117-19.ams2.redhat.com [10.36.117.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 18EFE42226; Thu, 19 Apr 2018 07:08:21 +0000 (UTC) From: Jens Freimann To: dev@dpdk.org Cc: tiwei.bie@intel.com, yliu@fridaylinux.org, maxime.coquelin@redhat.com, mst@redhat.com, jens@freimann.org Date: Thu, 19 Apr 2018 09:07:40 +0200 Message-Id: <20180419070751.8933-10-jfreimann@redhat.com> In-Reply-To: <20180419070751.8933-1-jfreimann@redhat.com> References: <20180419070751.8933-1-jfreimann@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 19 Apr 2018 07:08:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 19 Apr 2018 07:08:28 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jfreimann@redhat.com' RCPT:'' Subject: [dpdk-dev] [PATCH v4 09/20] net/virtio: add virtio send command packed queue support 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Use packed virtqueue format when reading and writing descriptors to/from the ring. Signed-off-by: Jens Freimann --- drivers/net/virtio/virtio_ethdev.c | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index e4c039a48..b9fada638 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -140,6 +140,75 @@ static const struct rte_virtio_xstats_name_off rte_virtio_txq_stat_strings[] = { struct virtio_hw_internal virtio_hw_internal[RTE_MAX_ETHPORTS]; +static struct virtio_pmd_ctrl * +virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, + int *dlen, int pkt_num) +{ + struct virtqueue *vq = cvq->vq; + int head_idx = (vq->vq_avail_idx++) & (vq->vq_nentries -1); + struct vring_desc_packed *desc = vq->vq_ring.desc_packed; + int used_idx = vq->vq_used_cons_idx & (vq->vq_nentries - 1); + int flags = desc[head_idx].flags; + struct virtio_pmd_ctrl *result; + int wrap_counter; + int sum = 0; + int i; + + wrap_counter = vq->vq_ring.avail_wrap_counter; + if ((head_idx & (vq->vq_nentries - 1)) == 0) + toggle_wrap_counter(&vq->vq_ring); + + for (i = 0; i < pkt_num; i++) { + flags |= VRING_DESC_F_NEXT; + desc[head_idx].addr = cvq->virtio_net_hdr_mem + + sizeof(struct virtio_net_ctrl_hdr) + + sizeof(ctrl->status) + sizeof(uint8_t) * sum; + desc[head_idx].len = dlen[i]; + rte_smp_wmb(); + desc[head_idx].flags = flags; + sum += dlen[i]; + vq->vq_free_cnt--; + _set_desc_avail(&desc[head_idx], wrap_counter); + head_idx = (vq->vq_avail_idx++) & (vq->vq_nentries - 1); + if ((head_idx & (vq->vq_nentries - 1)) == 0) + toggle_wrap_counter(&vq->vq_ring); + } + + + flags = VRING_DESC_F_WRITE; + desc[head_idx].addr = cvq->virtio_net_hdr_mem + + sizeof(struct virtio_net_ctrl_hdr); + desc[head_idx].len = sizeof(ctrl->status); + vq->vq_free_cnt--; + rte_smp_wmb(); + _set_desc_avail(&desc[head_idx], wrap_counter); + desc[head_idx].flags = flags; + + virtqueue_notify(vq); + + rte_rmb(); + /* wait for used descriptors in virtqueue */ + while(!desc_is_used(&desc[head_idx])) { + rte_rmb(); + usleep(100); + } + + /* now get used descriptors */ + while(desc_is_used(&desc[used_idx])) { + used_idx = (vq->vq_used_cons_idx++) & (vq->vq_nentries - 1); + vq->vq_free_cnt++; + rte_smp_wmb(); + set_desc_avail(&vq->vq_ring, &desc[used_idx]); + if ((used_idx & (vq->vq_nentries - 1)) == 0) + toggle_wrap_counter(&vq->vq_ring); + } + + vq->vq_used_cons_idx = used_idx; + + result = cvq->virtio_net_hdr_mz->addr; + return result; +} + static int virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, int *dlen, int pkt_num) @@ -173,6 +242,11 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, memcpy(cvq->virtio_net_hdr_mz->addr, ctrl, sizeof(struct virtio_pmd_ctrl)); + if (vtpci_packed_queue(vq->hw)) { + result = virtio_pq_send_command(cvq, ctrl, dlen, pkt_num); + goto out_unlock; + } + /* * Format is enforced in qemu code: * One TX packet for header; @@ -244,6 +318,7 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, result = cvq->virtio_net_hdr_mz->addr; +out_unlock: rte_spinlock_unlock(&cvq->lock); return result->status; }