From patchwork Wed Nov 30 15:56:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 120372 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 62C5DA00C2; Wed, 30 Nov 2022 16:58:28 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ABB9B42D6C; Wed, 30 Nov 2022 16:57:15 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 2640742D53 for ; Wed, 30 Nov 2022 16:57:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669823833; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V3KPmseeDxJ6fpegA1k/gn0f3UPqt1YANwrDgFY5PYI=; b=E9QbgjVIyz/Hsrzn7JJFNQkcFd8qSAGHzpFgrVU1po5q3q2VnvdCudsL65DTrDDx/16HqG zc8IVnrMCfjj0CnwVvkba0vlU/tP0nIfBWpESlifQfu6yGUG1z5PM35BvZ16mp5Kpfxc2w BgbMnmSB1Z/MQdCgw6c4nvwARLIu4NE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-608-Q9VQc91nOJm-EYNBk7pkgw-1; Wed, 30 Nov 2022 10:57:12 -0500 X-MC-Unique: Q9VQc91nOJm-EYNBk7pkgw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DFA6929DD99B; Wed, 30 Nov 2022 15:57:11 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDE3A40C83ED; Wed, 30 Nov 2022 15:57:10 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, david.marchand@redhat.com, eperezma@redhat.com Cc: Maxime Coquelin Subject: [PATCH v1 16/21] net/virtio-user: allocate shadow control queue Date: Wed, 30 Nov 2022 16:56:34 +0100 Message-Id: <20221130155639.150553-17-maxime.coquelin@redhat.com> In-Reply-To: <20221130155639.150553-1-maxime.coquelin@redhat.com> References: <20221130155639.150553-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org If the backends supports control virtqueue, allocate a shadow control virtqueue, and implement the notify callback that writes into the kickfd. Signed-off-by: Maxime Coquelin Reviewed-by: Chenbo Xia --- .../net/virtio/virtio_user/virtio_user_dev.c | 47 ++++++++++++++++++- .../net/virtio/virtio_user/virtio_user_dev.h | 5 ++ drivers/net/virtio/virtio_user_ethdev.c | 6 +++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index a3584e7735..16a0e07413 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -146,8 +146,9 @@ virtio_user_dev_set_features(struct virtio_user_dev *dev) /* Strip VIRTIO_NET_F_MAC, as MAC address is handled in vdev init */ features &= ~(1ull << VIRTIO_NET_F_MAC); - /* Strip VIRTIO_NET_F_CTRL_VQ, as devices do not really need to know */ - features &= ~(1ull << VIRTIO_NET_F_CTRL_VQ); + /* Strip VIRTIO_NET_F_CTRL_VQ if the devices does not really support control VQ */ + if (!dev->hw_cvq) + features &= ~(1ull << VIRTIO_NET_F_CTRL_VQ); features &= ~(1ull << VIRTIO_NET_F_STATUS); ret = dev->ops->set_features(dev, features); if (ret < 0) @@ -911,6 +912,48 @@ virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx) } } +static void +virtio_user_control_queue_notify(struct virtqueue *vq, void *cookie) +{ + struct virtio_user_dev *dev = cookie; + uint64_t buf = 1; + + if (write(dev->kickfds[vq->vq_queue_index], &buf, sizeof(buf)) < 0) + PMD_DRV_LOG(ERR, "failed to kick backend: %s", + strerror(errno)); +} + +int +virtio_user_dev_create_shadow_cvq(struct virtio_user_dev *dev, struct virtqueue *vq) +{ + char name[VIRTQUEUE_MAX_NAME_SZ]; + struct virtqueue *scvq; + + snprintf(name, sizeof(name), "port%d_shadow_cvq", vq->hw->port_id); + scvq = virtqueue_alloc(&dev->hw, vq->vq_queue_index, vq->vq_nentries, + VTNET_CQ, SOCKET_ID_ANY, name); + if (!scvq) { + PMD_INIT_LOG(ERR, "(%s) Failed to alloc shadow control vq\n", dev->path); + return -ENOMEM; + } + + scvq->cq.notify_queue = &virtio_user_control_queue_notify; + scvq->cq.notify_cookie = dev; + dev->scvq = scvq; + + return 0; +} + +void +virtio_user_dev_destroy_shadow_cvq(struct virtio_user_dev *dev) +{ + if (!dev->scvq) + return; + + virtqueue_free(dev->scvq); + dev->scvq = NULL; +} + int virtio_user_dev_set_status(struct virtio_user_dev *dev, uint8_t status) { diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h index 3c5453eac0..e0db4faf3f 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -58,6 +58,9 @@ struct virtio_user_dev { pthread_mutex_t mutex; bool started; + bool hw_cvq; + struct virtqueue *scvq; + void *backend_data; }; @@ -74,6 +77,8 @@ void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx); void virtio_user_handle_cq_packed(struct virtio_user_dev *dev, uint16_t queue_idx); uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs); +int virtio_user_dev_create_shadow_cvq(struct virtio_user_dev *dev, struct virtqueue *vq); +void virtio_user_dev_destroy_shadow_cvq(struct virtio_user_dev *dev); int virtio_user_dev_set_status(struct virtio_user_dev *dev, uint8_t status); int virtio_user_dev_update_status(struct virtio_user_dev *dev); int virtio_user_dev_update_link_state(struct virtio_user_dev *dev); diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 6c3e875793..626bd95b62 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -232,6 +232,9 @@ virtio_user_setup_queue(struct virtio_hw *hw, struct virtqueue *vq) else virtio_user_setup_queue_split(vq, dev); + if (dev->hw_cvq && hw->cvq && (virtnet_cq_to_vq(hw->cvq) == vq)) + return virtio_user_dev_create_shadow_cvq(dev, vq); + return 0; } @@ -251,6 +254,9 @@ virtio_user_del_queue(struct virtio_hw *hw, struct virtqueue *vq) close(dev->callfds[vq->vq_queue_index]); close(dev->kickfds[vq->vq_queue_index]); + + if (hw->cvq && (virtnet_cq_to_vq(hw->cvq) == vq) && dev->scvq) + virtio_user_dev_destroy_shadow_cvq(dev); } static void