From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8762541C32; Tue, 7 Feb 2023 19:02:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 15F744021F; Tue, 7 Feb 2023 19:02:44 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id C2A8040151 for ; Tue, 7 Feb 2023 19:02:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675792962; 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=W0cRiYfwPr36ebJnVUs8qi2Ev4HeFgEWInGJbMSeL7s=; b=ZtVf0ujBayZXN+KrmkXrMrLkHIkTQsuBCMI8iNacZ1L5N7I3DEL0+B8/w6gHY07CLTKxlK lzzKdGxQAQ26nEOyBRPHmjCYR2zCDmOWahASkvFWseMVSde7CNu9B6mqtb5yQJzjXNwsWO p3L01yYTy2HTox+m+a5HQhw2zffFmtY= Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-539-vPwb_7d4PZi95RcAuZnRHQ-1; Tue, 07 Feb 2023 13:02:40 -0500 X-MC-Unique: vPwb_7d4PZi95RcAuZnRHQ-1 Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-52bc032fda3so18014827b3.0 for ; Tue, 07 Feb 2023 10:02:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W0cRiYfwPr36ebJnVUs8qi2Ev4HeFgEWInGJbMSeL7s=; b=qd7EtRHD6pHA9980bCxYgt3hgS5Bb/poxT/118qhE825Ab7YnIU2EfWwylJnrS+h7h SCc7RZ9eOZy36TL2EK2uOH92i6skB5y2n6E6/rJmdFIkiB8qNKxjSb8jIAEdNrlt+Jhk QwgKWXjxOOy4UUk0v2LhppEbvPU7rpT13lva9a/WTh5/gq7Dqp2E/rBn8g/zPzXfgg+w 6qrw22n6IgCifLMgB6JqUVvDGOzdzKNTCaO7oYojdpnEAmhQB6qbxJYeacxnL4R+cV92 BMfLOStczzshjGWwA6gPAd6MQVcoW5EJDVppypqA1mXC0CM9x6N5mBYXzIosTCbFE2El YsQg== X-Gm-Message-State: AO0yUKUDXUaGevS/9gs6lKQFmjZ0tYghf2EGdxh20IdQU5Uf2R8P45ij zxDp00PcVDLMc8pfvucCvTvQcaF71RX2RKtUGGuXrzgOQYzZOfabf6PJQPp065sXaQLoJi7d3dr J29JDkzDkuzuaJlBtCdc= X-Received: by 2002:a25:c712:0:b0:85a:abeb:786 with SMTP id w18-20020a25c712000000b0085aabeb0786mr367802ybe.583.1675792959100; Tue, 07 Feb 2023 10:02:39 -0800 (PST) X-Google-Smtp-Source: AK7set/AR8AX8BUF1cZtEL248NMMPDqCbXROuDkhZ8hzJAc3zncekiE3QE8eGBJXEjHxj14R3qi7HMu92GLLSVC304A= X-Received: by 2002:a25:c712:0:b0:85a:abeb:786 with SMTP id w18-20020a25c712000000b0085aabeb0786mr367797ybe.583.1675792958817; Tue, 07 Feb 2023 10:02:38 -0800 (PST) MIME-Version: 1.0 References: <20230207151747.245808-1-maxime.coquelin@redhat.com> <20230207151747.245808-16-maxime.coquelin@redhat.com> In-Reply-To: <20230207151747.245808-16-maxime.coquelin@redhat.com> From: Eugenio Perez Martin Date: Tue, 7 Feb 2023 19:02:02 +0100 Message-ID: Subject: Re: [PATCH v2 15/21] net/virtio-user: get max number of queue pairs from device To: Maxime Coquelin Cc: dev@dpdk.org, chenbo.xia@intel.com, david.marchand@redhat.com, stephen@networkplumber.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Tue, Feb 7, 2023 at 4:18 PM Maxime Coquelin wrote: > > When supported by the backend (only vDPA for now), this > patch gets the maximum number of queue pairs supported by > the device by querying it in its config space. > > This is required for adding backend control queue support, > as is index equals the maximum number of queues supported > by the device as described by the Virtio specification. > > Signed-off-by: Maxime Coquelin > Reviewed-by: Chenbo Xia Acked-by: Eugenio P=C3=A9rez > --- > .../net/virtio/virtio_user/virtio_user_dev.c | 93 ++++++++++++++----- > drivers/net/virtio/virtio_user_ethdev.c | 7 -- > 2 files changed, 71 insertions(+), 29 deletions(-) > > diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/n= et/virtio/virtio_user/virtio_user_dev.c > index 809c9ef442..a3584e7735 100644 > --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c > +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c > @@ -253,6 +253,50 @@ int virtio_user_stop_device(struct virtio_user_dev *= dev) > return -1; > } > > +static int > +virtio_user_dev_init_max_queue_pairs(struct virtio_user_dev *dev, uint32= _t user_max_qp) > +{ > + int ret; > + > + if (!(dev->device_features & (1ULL << VIRTIO_NET_F_MQ))) { > + dev->max_queue_pairs =3D 1; > + return 0; > + } > + > + if (!dev->ops->get_config) { > + dev->max_queue_pairs =3D user_max_qp; > + return 0; > + } > + > + ret =3D dev->ops->get_config(dev, (uint8_t *)&dev->max_queue_pair= s, > + offsetof(struct virtio_net_config, max_virtqueue_= pairs), > + sizeof(uint16_t)); > + if (ret) { > + /* > + * We need to know the max queue pair from the device so = that > + * the control queue gets the right index. > + */ > + dev->max_queue_pairs =3D 1; > + PMD_DRV_LOG(ERR, "(%s) Failed to get max queue pairs from= device", dev->path); > + > + return ret; > + } > + > + if (dev->max_queue_pairs > VIRTIO_MAX_VIRTQUEUE_PAIRS) { > + /* > + * If the device supports control queue, the control queu= e > + * index is max_virtqueue_pairs * 2. Disable MQ if it hap= pens. > + */ > + PMD_DRV_LOG(ERR, "(%s) Device advertises too many queues = (%u, max supported %u)", > + dev->path, dev->max_queue_pairs, VIRTIO_M= AX_VIRTQUEUE_PAIRS); > + dev->max_queue_pairs =3D 1; > + > + return -1; > + } > + > + return 0; > +} > + > int > virtio_user_dev_set_mac(struct virtio_user_dev *dev) > { > @@ -511,24 +555,7 @@ virtio_user_dev_setup(struct virtio_user_dev *dev) > return -1; > } > > - if (virtio_user_dev_init_notify(dev) < 0) { > - PMD_INIT_LOG(ERR, "(%s) Failed to init notifiers", dev->p= ath); > - goto destroy; > - } > - > - if (virtio_user_fill_intr_handle(dev) < 0) { > - PMD_INIT_LOG(ERR, "(%s) Failed to init interrupt handler"= , dev->path); > - goto uninit; > - } > - > return 0; > - > -uninit: > - virtio_user_dev_uninit_notify(dev); > -destroy: > - dev->ops->destroy(dev); > - > - return -1; > } > > /* Use below macro to filter features from vhost backend */ > @@ -570,7 +597,6 @@ virtio_user_dev_init(struct virtio_user_dev *dev, cha= r *path, uint16_t queues, > } > > dev->started =3D 0; > - dev->max_queue_pairs =3D queues; > dev->queue_pairs =3D 1; /* mq disabled by default */ > dev->queue_size =3D queue_size; > dev->is_server =3D server; > @@ -591,23 +617,39 @@ virtio_user_dev_init(struct virtio_user_dev *dev, c= har *path, uint16_t queues, > > if (dev->ops->set_owner(dev) < 0) { > PMD_INIT_LOG(ERR, "(%s) Failed to set backend owner", dev= ->path); > - return -1; > + goto destroy; > } > > if (dev->ops->get_backend_features(&backend_features) < 0) { > PMD_INIT_LOG(ERR, "(%s) Failed to get backend features", = dev->path); > - return -1; > + goto destroy; > } > > dev->unsupported_features =3D ~(VIRTIO_USER_SUPPORTED_FEATURES | = backend_features); > > if (dev->ops->get_features(dev, &dev->device_features) < 0) { > PMD_INIT_LOG(ERR, "(%s) Failed to get device features", d= ev->path); > - return -1; > + goto destroy; > } > > virtio_user_dev_init_mac(dev, mac); > > + if (virtio_user_dev_init_max_queue_pairs(dev, queues)) > + dev->unsupported_features |=3D (1ull << VIRTIO_NET_F_MQ); > + > + if (dev->max_queue_pairs > 1) > + cq =3D 1; > + > + if (virtio_user_dev_init_notify(dev) < 0) { > + PMD_INIT_LOG(ERR, "(%s) Failed to init notifiers", dev->p= ath); > + goto destroy; > + } > + > + if (virtio_user_fill_intr_handle(dev) < 0) { > + PMD_INIT_LOG(ERR, "(%s) Failed to init interrupt handler"= , dev->path); > + goto notify_uninit; > + } > + > if (!mrg_rxbuf) > dev->unsupported_features |=3D (1ull << VIRTIO_NET_F_MRG_= RXBUF); > > @@ -651,11 +693,18 @@ virtio_user_dev_init(struct virtio_user_dev *dev, c= har *path, uint16_t queues, > if (rte_errno !=3D ENOTSUP) { > PMD_INIT_LOG(ERR, "(%s) Failed to register mem ev= ent callback", > dev->path); > - return -1; > + goto notify_uninit; > } > } > > return 0; > + > +notify_uninit: > + virtio_user_dev_uninit_notify(dev); > +destroy: > + dev->ops->destroy(dev); > + > + return -1; > } > > void > diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio= /virtio_user_ethdev.c > index 6ad5896378..6c3e875793 100644 > --- a/drivers/net/virtio/virtio_user_ethdev.c > +++ b/drivers/net/virtio/virtio_user_ethdev.c > @@ -595,8 +595,6 @@ virtio_user_pmd_probe(struct rte_vdev_device *vdev) > VIRTIO_USER_ARG_CQ_NUM); > goto end; > } > - } else if (queues > 1) { > - cq =3D 1; > } > > if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_PACKED_VQ) =3D=3D 1)= { > @@ -617,11 +615,6 @@ virtio_user_pmd_probe(struct rte_vdev_device *vdev) > } > } > > - if (queues > 1 && cq =3D=3D 0) { > - PMD_INIT_LOG(ERR, "multi-q requires ctrl-q"); > - goto end; > - } > - > if (queues > VIRTIO_MAX_VIRTQUEUE_PAIRS) { > PMD_INIT_LOG(ERR, "arg %s %" PRIu64 " exceeds the limit %= u", > VIRTIO_USER_ARG_QUEUES_NUM, queues, > -- > 2.39.1 >