From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7C778A0519; Mon, 22 Jun 2020 14:35:14 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4AC5F1D6B9; Mon, 22 Jun 2020 14:35:14 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by dpdk.org (Postfix) with ESMTP id AE0D31D6B5 for ; Mon, 22 Jun 2020 14:35:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592829312; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=Eda1W7jr9iMxl7K6u8XCcMKOjFKYPzqHlL8hGcg3pks=; b=RvVAd58aIsiLXZNm2uccCArXS/F4V6uMP7bfD0GQvqrzMnfh8JQBIHO8xmfX/ngpp6Aay2 TvKvtaKsHfD6RkVOAfuMku4ZOMoLQbc7uGqFkoubRk3u2KqRcHeswjArMmCWyM3XW4KrxT vKPJHWY4Gt/OXXiGxRQCkzgqbHvJVAo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-322-6nIV6XyAOLesuEGEYkc7Lw-1; Mon, 22 Jun 2020 08:35:08 -0400 X-MC-Unique: 6nIV6XyAOLesuEGEYkc7Lw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B2A05107ACCD; Mon, 22 Jun 2020 12:35:06 +0000 (UTC) Received: from [10.36.110.7] (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8058426DF5; Mon, 22 Jun 2020 12:35:00 +0000 (UTC) To: Adrian Moreno , dev@dpdk.org, matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, xiaolong.ye@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, shreyansh.jain@nxp.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com References: <20200611213748.1967029-1-maxime.coquelin@redhat.com> <20200611213748.1967029-5-maxime.coquelin@redhat.com> <94b8f54b-7114-df23-0281-ad06abcec8e5@redhat.com> <3497e21f-2ba1-cc36-2dd1-c3a335e6a519@redhat.com> From: Maxime Coquelin Autocrypt: addr=maxime.coquelin@redhat.com; keydata= mQINBFOEQQIBEADjNLYZZqghYuWv1nlLisptPJp+TSxE/KuP7x47e1Gr5/oMDJ1OKNG8rlNg kLgBQUki3voWhUbMb69ybqdMUHOl21DGCj0BTU3lXwapYXOAnsh8q6RRM+deUpasyT+Jvf3a gU35dgZcomRh5HPmKMU4KfeA38cVUebsFec1HuJAWzOb/UdtQkYyZR4rbzw8SbsOemtMtwOx YdXodneQD7KuRU9IhJKiEfipwqk2pufm2VSGl570l5ANyWMA/XADNhcEXhpkZ1Iwj3TWO7XR uH4xfvPl8nBsLo/EbEI7fbuUULcAnHfowQslPUm6/yaGv6cT5160SPXT1t8U9QDO6aTSo59N jH519JS8oeKZB1n1eLDslCfBpIpWkW8ZElGkOGWAN0vmpLfdyiqBNNyS3eGAfMkJ6b1A24un /TKc6j2QxM0QK4yZGfAxDxtvDv9LFXec8ENJYsbiR6WHRHq7wXl/n8guyh5AuBNQ3LIK44x0 KjGXP1FJkUhUuruGyZsMrDLBRHYi+hhDAgRjqHgoXi5XGETA1PAiNBNnQwMf5aubt+mE2Q5r qLNTgwSo2dpTU3+mJ3y3KlsIfoaxYI7XNsPRXGnZi4hbxmeb2NSXgdCXhX3nELUNYm4ArKBP LugO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CG3dXmKfi2H+wdUCSvEFHRpgo7GK8/Kh3vGhgKmnnxhl8ACBaGy9n fxjSxjSO6rj4/MeenmlJw1yebzkX8ZmaSi8BHe+n6jTGEFNrbiOdWpJgc5yHIZZnwXaW54QT UhhSjDL1rV2B4F28w30jYmlRmm2RdN7iCZfbyP3dvFQTzQ4ySquuPkIGcOOHrvZzxbRjzMx1 Mwqu3GQ= Message-ID: <4ce66b89-d43b-a30c-f059-c4317114a626@redhat.com> Date: Mon, 22 Jun 2020 14:34:58 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <3497e21f-2ba1-cc36-2dd1-c3a335e6a519@redhat.com> Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH 04/14] vhost: make vDPA framework bus agnostic 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" On 6/22/20 11:49 AM, Adrian Moreno wrote: > > > On 6/19/20 5:11 PM, Maxime Coquelin wrote: >> >> >> On 6/19/20 1:14 PM, Adrian Moreno wrote: >>> >>> >>> On 6/11/20 11:37 PM, Maxime Coquelin wrote: >>>> This patch makes the vDPA framework to no more >>>> support only PCI devices, but any devices by relying >>>> on the generic device name as identifier. >>>> >>>> Signed-off-by: Maxime Coquelin >>>> --- >>>> drivers/vdpa/ifc/ifcvf_vdpa.c | 6 +- >>>> drivers/vdpa/mlx5/mlx5_vdpa.c | 8 +-- >>>> drivers/vdpa/mlx5/mlx5_vdpa.h | 2 +- >>>> examples/vdpa/main.c | 49 ++++++++-------- >>>> lib/librte_vhost/rte_vdpa.h | 42 +++++++------- >>>> lib/librte_vhost/rte_vhost_version.map | 1 + >>>> lib/librte_vhost/vdpa.c | 79 +++++++++++--------------- >>>> 7 files changed, 85 insertions(+), 102 deletions(-) >>>> >>>> diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c >>>> index ec97178dcb..1fec1f1baf 100644 >>>> --- a/drivers/vdpa/ifc/ifcvf_vdpa.c >>>> +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c >>>> @@ -47,7 +47,6 @@ static const char * const ifcvf_valid_arguments[] = { >>>> static int ifcvf_vdpa_logtype; >>>> >>>> struct ifcvf_internal { >>>> - struct rte_vdpa_dev_addr dev_addr; >>>> struct rte_pci_device *pdev; >>>> struct ifcvf_hw hw; >>>> int vfio_container_fd; >>>> @@ -1176,8 +1175,6 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, >>>> (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | >>>> (1ULL << VHOST_F_LOG_ALL); >>>> >>>> - internal->dev_addr.pci_addr = pci_dev->addr; >>>> - internal->dev_addr.type = VDPA_ADDR_PCI; >>>> list->internal = internal; >>>> >>>> if (rte_kvargs_count(kvlist, IFCVF_SW_FALLBACK_LM)) { >>>> @@ -1188,8 +1185,7 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, >>>> } >>>> internal->sw_lm = sw_fallback_lm; >>>> >>>> - internal->did = rte_vdpa_register_device(&internal->dev_addr, >>>> - &ifcvf_ops); >>>> + internal->did = rte_vdpa_register_device(&pci_dev->device, &ifcvf_ops); >>>> if (internal->did < 0) { >>>> DRV_LOG(ERR, "failed to register device %s", pci_dev->name); >>>> goto error; >>>> diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c >>>> index 1113d6cef0..e8255c7d7e 100644 >>>> --- a/drivers/vdpa/mlx5/mlx5_vdpa.c >>>> +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c >>>> @@ -501,14 +501,13 @@ mlx5_vdpa_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, >>>> priv->caps = attr.vdpa; >>>> priv->log_max_rqt_size = attr.log_max_rqt_size; >>>> priv->ctx = ctx; >>>> - priv->dev_addr.pci_addr = pci_dev->addr; >>>> - priv->dev_addr.type = VDPA_ADDR_PCI; >>>> + priv->pci_dev = pci_dev; >>>> priv->var = mlx5_glue->dv_alloc_var(ctx, 0); >>>> if (!priv->var) { >>>> DRV_LOG(ERR, "Failed to allocate VAR %u.\n", errno); >>>> goto error; >>>> } >>>> - priv->id = rte_vdpa_register_device(&priv->dev_addr, &mlx5_vdpa_ops); >>>> + priv->id = rte_vdpa_register_device(&pci_dev->device, &mlx5_vdpa_ops); >>>> if (priv->id < 0) { >>>> DRV_LOG(ERR, "Failed to register vDPA device."); >>>> rte_errno = rte_errno ? rte_errno : EINVAL; >>>> @@ -550,8 +549,7 @@ mlx5_vdpa_pci_remove(struct rte_pci_device *pci_dev) >>>> >>>> pthread_mutex_lock(&priv_list_lock); >>>> TAILQ_FOREACH(priv, &priv_list, next) { >>>> - if (memcmp(&priv->dev_addr.pci_addr, &pci_dev->addr, >>>> - sizeof(pci_dev->addr)) == 0) { >>>> + if (priv->pci_dev == pci_dev) { >>>> found = 1; >>>> break; >>>> } >>>> diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h >>>> index fcc216ac78..50ee3c5870 100644 >>>> --- a/drivers/vdpa/mlx5/mlx5_vdpa.h >>>> +++ b/drivers/vdpa/mlx5/mlx5_vdpa.h >>>> @@ -104,7 +104,7 @@ struct mlx5_vdpa_priv { >>>> int id; /* vDPA device id. */ >>>> int vid; /* vhost device id. */ >>>> struct ibv_context *ctx; /* Device context. */ >>>> - struct rte_vdpa_dev_addr dev_addr; >>>> + struct rte_pci_device *pci_dev; >>>> struct mlx5_hca_vdpa_attr caps; >>>> uint32_t pdn; /* Protection Domain number. */ >>>> struct ibv_pd *pd; >>>> diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c >>>> index d9a9112b16..c12da69574 100644 >>>> --- a/examples/vdpa/main.c >>>> +++ b/examples/vdpa/main.c >>>> @@ -271,10 +271,14 @@ static void cmd_list_vdpa_devices_parsed( >>>> uint32_t queue_num; >>>> uint64_t features; >>>> struct rte_vdpa_device *vdev; >>>> - struct rte_pci_addr addr; >>>> + struct rte_device *dev; >>>> + struct rte_dev_iterator dev_iter; >>>> >>>> - cmdline_printf(cl, "device id\tdevice address\tqueue num\tsupported features\n"); >>>> - for (did = 0; did < dev_total; did++) { >>>> + cmdline_printf(cl, "device id\tdevice name\tqueue num\tsupported features\n"); >>>> + RTE_DEV_FOREACH(dev, "class=vdpa", &dev_iter) { >>>> + did = rte_vdpa_find_device_id_by_name(dev->name); >>>> + if (did < 0) >>>> + continue; >>>> vdev = rte_vdpa_get_device(did); >>>> if (!vdev) >>>> continue; >>>> @@ -290,11 +294,8 @@ static void cmd_list_vdpa_devices_parsed( >>>> "for device id %d.\n", did); >>>> continue; >>>> } >>>> - addr = vdev->addr.pci_addr; >>>> - cmdline_printf(cl, >>>> - "%d\t\t" PCI_PRI_FMT "\t%" PRIu32 "\t\t0x%" PRIx64 "\n", >>>> - did, addr.domain, addr.bus, addr.devid, >>>> - addr.function, queue_num, features); >>>> + cmdline_printf(cl, "%d\t\t%s\t\t%" PRIu32 "\t\t0x%" PRIx64 "\n", >>>> + did, dev->name, queue_num, features); >>>> } >>>> } >>>> >>>> @@ -324,17 +325,12 @@ static void cmd_create_vdpa_port_parsed(void *parsed_result, >>>> { >>>> int did; >>>> struct cmd_create_result *res = parsed_result; >>>> - struct rte_vdpa_dev_addr addr; >>>> >>>> rte_strscpy(vports[devcnt].ifname, res->socket_path, MAX_PATH_LEN); >>>> - if (rte_pci_addr_parse(res->bdf, &addr.pci_addr) != 0) { >>>> - cmdline_printf(cl, "Unable to parse the given bdf.\n"); >>>> - return; >>>> - } >>>> - addr.type = VDPA_ADDR_PCI; >>>> - did = rte_vdpa_find_device_id(&addr); >>>> + did = rte_vdpa_find_device_id_by_name(res->bdf); >>>> if (did < 0) { >>>> - cmdline_printf(cl, "Unable to find vdpa device id.\n"); >>>> + cmdline_printf(cl, "Unable to find vdpa device id for %s.\n", >>>> + res->bdf); >>>> return; >>>> } >>>> >>>> @@ -400,9 +396,11 @@ int >>>> main(int argc, char *argv[]) >>>> { >>>> char ch; >>>> - int i; >>>> + int did; >>>> int ret; >>>> struct cmdline *cl; >>>> + struct rte_device *dev; >>>> + struct rte_dev_iterator dev_iter; >>>> >>>> ret = rte_eal_init(argc, argv); >>>> if (ret < 0) >>>> @@ -428,13 +426,18 @@ main(int argc, char *argv[]) >>>> cmdline_interact(cl); >>>> cmdline_stdin_exit(cl); >>>> } else { >>>> - for (i = 0; i < RTE_MIN(MAX_VDPA_SAMPLE_PORTS, dev_total); >>>> - i++) { >>>> - vports[i].did = i; >>>> - snprintf(vports[i].ifname, MAX_PATH_LEN, "%s%d", >>>> - iface, i); >>>> + RTE_DEV_FOREACH(dev, "class=vdpa", &dev_iter) { >>>> + did = rte_vdpa_find_device_id_by_name(dev->name); >>>> + if (did < 0) { >>>> + rte_panic("Failed to find device id for %s\n", >>>> + dev->name); >>>> + } >>>> + vports[devcnt].did = did; >>>> + snprintf(vports[devcnt].ifname, MAX_PATH_LEN, "%s%d", >>>> + iface, devcnt); >>>> >>>> - start_vdpa(&vports[i]); >>>> + start_vdpa(&vports[devcnt]); >>>> + devcnt++; >>>> } >>>> >>>> printf("enter \'q\' to quit\n"); >>>> diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h >>>> index 3c400ee79b..33037d39ea 100644 >>>> --- a/lib/librte_vhost/rte_vdpa.h >>>> +++ b/lib/librte_vhost/rte_vdpa.h >>>> @@ -18,25 +18,6 @@ >>>> >>>> #define MAX_VDPA_NAME_LEN 128 >>>> >>>> -enum vdpa_addr_type { >>>> - VDPA_ADDR_PCI, >>>> - VDPA_ADDR_MAX >>>> -}; >>>> - >>>> -/** >>>> - * vdpa device address >>>> - */ >>>> -struct rte_vdpa_dev_addr { >>>> - /** vdpa address type */ >>>> - enum vdpa_addr_type type; >>>> - >>>> - /** vdpa pci address */ >>>> - union { >>>> - uint8_t __dummy[64]; >>>> - struct rte_pci_addr pci_addr; >>>> - }; >>>> -}; >>>> - >>>> /** >>>> * vdpa device operations >>>> */ >>>> @@ -81,8 +62,8 @@ struct rte_vdpa_dev_ops { >>>> * vdpa device structure includes device address and device operations. >>>> */ >>>> struct rte_vdpa_device { >>>> - /** vdpa device address */ >>>> - struct rte_vdpa_dev_addr addr; >>>> + /** Generic device information */ >>>> + struct rte_device *device; >>>> /** vdpa device operations */ >>>> struct rte_vdpa_dev_ops *ops; >>>> } __rte_cache_aligned; >>>> @@ -102,7 +83,7 @@ struct rte_vdpa_device { >>>> */ >>>> __rte_experimental >>>> int >>>> -rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr, >>>> +rte_vdpa_register_device(struct rte_device *rte_dev, >>>> struct rte_vdpa_dev_ops *ops); >>>> >>>> /** >>>> @@ -120,6 +101,21 @@ __rte_experimental >>>> int >>>> rte_vdpa_unregister_device(int did); >>>> >>>> +/** >>>> + * @warning >>>> + * @b EXPERIMENTAL: this API may change without prior notice >>>> + * >>>> + * Find the device id of a vdpa device from its name >>>> + * >>>> + * @param name >>>> + * the vdpa device name >>>> + * @return >>>> + * device id on success, -1 on failure >>>> + */ >>>> +__rte_experimental >>>> +int >>>> +rte_vdpa_find_device_id_by_name(const char *name); >>>> + >>>> /** >>>> * @warning >>>> * @b EXPERIMENTAL: this API may change without prior notice >>>> @@ -133,7 +129,7 @@ rte_vdpa_unregister_device(int did); >>>> */ >>>> __rte_experimental >>>> int >>>> -rte_vdpa_find_device_id(struct rte_vdpa_dev_addr *addr); >>>> +rte_vdpa_find_device_id(struct rte_vdpa_device *dev); >>>> >>>> /** >>>> * @warning >>>> diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map >>>> index 051d08c120..1abfff8a0c 100644 >>>> --- a/lib/librte_vhost/rte_vhost_version.map >>>> +++ b/lib/librte_vhost/rte_vhost_version.map >>>> @@ -66,4 +66,5 @@ EXPERIMENTAL { >>>> rte_vhost_get_vhost_ring_inflight; >>>> rte_vhost_get_vring_base_from_inflight; >>>> rte_vhost_slave_config_change; >>>> + rte_vdpa_find_device_id_by_name; >>>> }; >>>> diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c >>>> index 61ab9aadb4..5abc5a2a7c 100644 >>>> --- a/lib/librte_vhost/vdpa.c >>>> +++ b/lib/librte_vhost/vdpa.c >>>> @@ -18,43 +18,22 @@ >>>> static struct rte_vdpa_device vdpa_devices[MAX_VHOST_DEVICE]; >>>> static uint32_t vdpa_device_num; >>>> >>>> -static bool >>>> -is_same_vdpa_device(struct rte_vdpa_dev_addr *a, >>>> - struct rte_vdpa_dev_addr *b) >>>> -{ >>>> - bool ret = true; >>>> - >>>> - if (a->type != b->type) >>>> - return false; >>>> - >>>> - switch (a->type) { >>>> - case VDPA_ADDR_PCI: >>>> - if (a->pci_addr.domain != b->pci_addr.domain || >>>> - a->pci_addr.bus != b->pci_addr.bus || >>>> - a->pci_addr.devid != b->pci_addr.devid || >>>> - a->pci_addr.function != b->pci_addr.function) >>>> - ret = false; >>>> - break; >>>> - default: >>>> - break; >>>> - } >>>> - >>>> - return ret; >>>> -} >>>> - >>>> int >>>> -rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr, >>>> +rte_vdpa_register_device(struct rte_device *rte_dev, >>>> struct rte_vdpa_dev_ops *ops) >>>> { >>>> struct rte_vdpa_device *dev; >>>> int i; >>>> >>>> - if (vdpa_device_num >= MAX_VHOST_DEVICE || addr == NULL || ops == NULL) >>>> + if (vdpa_device_num >= MAX_VHOST_DEVICE || ops == NULL) >>>> return -1; >>>> >>>> for (i = 0; i < MAX_VHOST_DEVICE; i++) { >>>> dev = &vdpa_devices[i]; >>>> - if (dev->ops && is_same_vdpa_device(&dev->addr, addr)) >>>> + if (dev->ops == NULL) >>>> + continue; >>>> + >>>> + if (dev->device == rte_dev) >>>> return -1; >>>> } >>> >>> If we change the order of the two "if" statemets and replace "continue" with >>> "break", we can remove the for loop that follows: >>> >>> for (i = 0; i < MAX_VHOST_DEVICE; i++) { >>> if (vdpa_devices[i].ops == NULL) >>> break; >>> } >> >> Do you mean like this? >> >> for (i = 0; i < MAX_VHOST_DEVICE; i++) { >> if (dev->device == rte_dev) >> return -1; >> >> if (vdpa_devices[i].ops == NULL) >> break; >> } >> >> If so the behaviour will be different, because you can have holes in the >> array if a device is unregistered. >> > Right, did not account for the unregistered holes. Still the double iteration > could be avoided by storing a pointer/index in the stack but maybe not needed in > this patch. Yes, certainly. Now these iterations are just an intermediate step of the series. The end result gets rid of these loops, so maybe not worth the effort of optimizing it. >> With above change it would stop looking if device is already registered >> at the first hole, so could end into double registration of the same >> device. >> >>> >>>> >>>> @@ -67,7 +46,7 @@ rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr, >>>> return -1; >>>> >>>> dev = &vdpa_devices[i]; >>>> - memcpy(&dev->addr, addr, sizeof(struct rte_vdpa_dev_addr)); >>>> + dev->device = rte_dev; >>>> dev->ops = ops; >>>> vdpa_device_num++; >>>> >>>> @@ -87,12 +66,33 @@ rte_vdpa_unregister_device(int did) >>>> } >>>> >>>> int >>>> -rte_vdpa_find_device_id(struct rte_vdpa_dev_addr *addr) >>>> +rte_vdpa_find_device_id(struct rte_vdpa_device *dev) >>>> +{ >>>> + struct rte_vdpa_device *tmp_dev; >>>> + int i; >>>> + >>>> + if (dev == NULL) >>>> + return -1; >>>> + >>>> + for (i = 0; i < MAX_VHOST_DEVICE; ++i) { >>>> + tmp_dev = &vdpa_devices[i]; >>>> + if (tmp_dev->ops == NULL) >>>> + continue; >>>> + >>>> + if (tmp_dev == dev) >>>> + return i; >>>> + } >>>> + >>>> + return -1; >>>> +} >>>> + >>>> +int >>>> +rte_vdpa_find_device_id_by_name(const char *name) >>>> { >>>> struct rte_vdpa_device *dev; >>>> int i; >>>> >>>> - if (addr == NULL) >>>> + if (name == NULL) >>>> return -1; >>>> >>>> for (i = 0; i < MAX_VHOST_DEVICE; ++i) { >>>> @@ -100,7 +100,7 @@ rte_vdpa_find_device_id(struct rte_vdpa_dev_addr *addr) >>>> if (dev->ops == NULL) >>>> continue; >>>> >>>> - if (is_same_vdpa_device(&dev->addr, addr)) >>>> + if (strcmp(dev->device->name, name) == 0) >>>> return i; >>>> } >>>> >>>> @@ -236,21 +236,10 @@ static int >>>> vdpa_dev_match(struct rte_vdpa_device *dev, >>>> const struct rte_device *rte_dev) >>>> { >>>> - struct rte_vdpa_dev_addr addr; >>>> + if (dev->device == rte_dev) >>>> + return 0; >>>> >>>> - /* Only PCI bus supported for now */ >>>> - if (strcmp(rte_dev->bus->name, "pci") != 0) >>>> - return -1; >>>> - >>>> - addr.type = VDPA_ADDR_PCI; >>>> - >>>> - if (rte_pci_addr_parse(rte_dev->name, &addr.pci_addr) != 0) >>>> - return -1; >>>> - >>>> - if (!is_same_vdpa_device(&dev->addr, &addr)) >>>> - return -1; >>>> - >>>> - return 0; >>>> + return -1; >>>> } >>>> >>>> /* Generic rte_vdpa_dev comparison function. */ >>>> >>> >> >