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 52720A0350; Fri, 26 Jun 2020 12:34:47 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 23D101BE95; Fri, 26 Jun 2020 12:34:46 +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 20BDC1BE90 for ; Fri, 26 Jun 2020 12:34:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593167683; 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=h6SONdH1fMOmolq3EGobICZURsnjJH1zLVzDlRAzamY=; b=GyucNOA/KNDbBsPzB+a0lgaESX/4zCbOLGZOTnfE9iDzn2AXowEGs4zUivKRu32SbT3cqx vj4Y7H/aHNlpLDecbRLn5QysaMiLXjaKpuiwv1R72KF5tcwx3qimjM6nc06zhrRQ1fAslx 0mGeiE9h0Xjo0wIZxy0TgGG1+LdHuck= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-266-5y97RS-iMKeZpbUUvT74qQ-1; Fri, 26 Jun 2020 06:34:42 -0400 X-MC-Unique: 5y97RS-iMKeZpbUUvT74qQ-1 Received: by mail-wm1-f69.google.com with SMTP id v6so8313742wmg.1 for ; Fri, 26 Jun 2020 03:34:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:autocrypt:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=h6SONdH1fMOmolq3EGobICZURsnjJH1zLVzDlRAzamY=; b=EHPzhyjf/WBbRsRKOdANFrWO715xnzfZtSJXOCaWMsZuHsX/Ji/lZHjAjFzGjn/MrD oZJqiRHKyHfxsi/1KbZZrQMLUVNOnLegzVa1OUL2+AWUZpMi9GOzCFl2sD3H4XFEwYO9 P986Qpe1InrkoABOpIWBZcqfkyM2DYXgGYr+KlBln5qnvJiJwTEmDZWBJke1+uOD3d6E PMNskhSZsj2Zr9gU5I+smU7W6pRY2+RHMywxPWDinCAZltONHTBIN+ly4ITCqFN7+7KY T8d+V+UseAo/2YjSgyjN9T7Nk6PeQInYPABSOxMFT98FGofMMJNvSgQ11Zg4V3ZRjGLL j6aA== X-Gm-Message-State: AOAM531Gxqa6maavSnKGF+XMF43tFdDxAzhmNhFSK6iSoDU3DVPmy00W 1pEdTW7ZLMyfayX9EIWEO7nioiIKVHEVVvSoKEww2ajGUd6mY2NGHOa4HIc8z7nY1mza3ubXVB/ MLIM= X-Received: by 2002:a5d:4591:: with SMTP id p17mr2997706wrq.343.1593167680231; Fri, 26 Jun 2020 03:34:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8YbhpvoWZZD+i/if8ft+ar9n61mVsORbxqq2GVcRWv4X40059JKIJSadLzgIRsennWAI5jQ== X-Received: by 2002:a5d:4591:: with SMTP id p17mr2997660wrq.343.1593167679685; Fri, 26 Jun 2020 03:34:39 -0700 (PDT) Received: from amorenoz.users.ipa.redhat.com ([92.176.159.3]) by smtp.gmail.com with ESMTPSA id q1sm21878473wro.82.2020.06.26.03.34.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Jun 2020 03:34:38 -0700 (PDT) To: Maxime Coquelin , matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> <20200624122701.1369327-6-maxime.coquelin@redhat.com> From: Adrian Moreno Autocrypt: addr=amorenoz@redhat.com; prefer-encrypt=mutual; keydata= mQENBF1syNUBCADQ9dk3fDMxOZ/+OQpmbanpodYxEv8IRtDz8PXw8YX7UyGfozOpLjQ8Fftj ZxuubYNbt2QVbSgviFilFdNWu2eTnN/JaGtfhmTOLPVoakkPHZF8lbgImMoch7L0fH8wN2IM KPxQyPNlX+K9FD5brHsV1lfe1TwAxmhcvLW8yNrVq+9eDIDykxc7tH4exIqXgZroahGxMHKy c8Ti2kJka/t6pDfRaY0J+6J7I1nrn6GXXSMNA45EH8+0N/QlcXhP3rfftnoPeVmpjswzvJqY FNjf/Q5VPLx7RX0Qx+y8mMB2JcChV5Bl7D7x5EUbItj6+Sy7QfOgCtPegk9HSrBCNYaLABEB AAG0I0FkcmlhbiBNb3Jlbm8gPGFtb3Jlbm96QHJlZGhhdC5jb20+iQFUBBMBCAA+FiEEogUD gihhmbOPHy26d5C5fbYeFsUFAl1syNUCGwMFCQHhM4AFCwkIBwIGFQoJCAsCBBYCAwECHgEC F4AACgkQd5C5fbYeFsX7qwgArGHSkX+ILNcujkVzjTG4OtkpJMPFlkn/1PxSEKD0jLuzx14B COzpg/Mqj3Re/QBuOas+ci9bsUA0/2nORtmmEBvzDOJpR5FH1jaGCx8USlY4WM6QqEDNZgTw hsy9KhjFzFjMk+oo3HyItXA+Uq9yrRBTjNBGTXxezMRcMuUZ4MIAfY0IRBglL2BufiuL43jD BvTENNFLoQ/wFV7qkFWSkv+8IjTsxr7M6XUo1QLd29Hn0dvwssN579HL1+BP46i2REpzeBEG L75iVChi+YnIQQNMJ9NYarVabZx4Y1Gn8+7B/1SNArDV+IDgnYgt7E58otoV2Ap310dmtuvE VbxGpbkBDQRdbMjVAQgAqyp9oA7WDu7/Y9T4Ommt69iZx8os7shUIfdgPEy5xrcPn6qGwN1/ HQ4j8nWfBG9uuX1X0RXUZIUEtYTxtED4yaCQMTqDUf9cBAwAA2mYxBfoiNYx8YqxM+sT0/J4 2qmDd+y+20UR4yzHE8AmIbspTzDFIJDAi+jKSR8F355z0sfW7CIMDC4ZWrPsskjEy1YN/U10 r6tRRH1kNyrCSbTG0d9MtcQO58h7DLXuzUhErB+BtG52A04t5cweIJTJC+koV5XPeilzlHnm RFoj0ncruGa9Odns21BNt3cy9wLfK+aUnWuAB1uc6bJGQPiAwjkilz7g7MBRUuIQ2Zt7HGLc SwARAQABiQE8BBgBCAAmFiEEogUDgihhmbOPHy26d5C5fbYeFsUFAl1syNUCGwwFCQHhM4AA CgkQd5C5fbYeFsUlSwf8CH+u/IXaE7WeWxwFkMaORfW8cM4q0xrL3M6yRGuQNW+kMjnrvK9U J9G+L1/5uTRbDQ/4LdoKqize8LjehA+iF6ba4t9Npikh8fLKWgaJfQ/hPhH4C3O5gWPOLTW6 ylGxiuER4CdFwQIoAMMslhFA7G+teeOKBq36E+1+zrybI6Xy1UBSlpDK9j4CtTnMQejjuSQb Qhle+l8VroaUHq869wjAhRHHhqmtJKggI+OvzgQpDIwfHIDypb1BuKydi2W6cVYEALUYyCLS dTBDhzj8zR5tPCsga8J7+TclQzkWOiI2C6ZtiWrMsL/Uym3uXk5nsoc7lSj7yLd/MrBRhYfP JQ== Message-ID: Date: Fri, 26 Jun 2020 12:34:37 +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: <20200624122701.1369327-6-maxime.coquelin@redhat.com> Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [dpdk-dev] [PATCH v2 05/14] vhost: replace device ID in vDPA ops 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/24/20 2:26 PM, Maxime Coquelin wrote: > This patch is a preliminary step to get rid of the > vDPA device ID. It makes vDPA callbacks to use the > vDPA device struct as a reference instead of the ID. > > Signed-off-by: Maxime Coquelin > --- > drivers/vdpa/ifc/ifcvf_vdpa.c | 79 ++++++++++---------- > drivers/vdpa/mlx5/mlx5_vdpa.c | 134 ++++++++++++++++++++-------------- > drivers/vdpa/mlx5/mlx5_vdpa.h | 2 +- > examples/vdpa/main.c | 4 +- > lib/librte_vhost/rte_vdpa.h | 28 ++++--- > lib/librte_vhost/socket.c | 6 +- > lib/librte_vhost/vdpa.c | 101 ++++++++++++------------- > 7 files changed, 195 insertions(+), 159 deletions(-) > > diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c > index ac9e218c23..0418f9a07f 100644 > --- a/drivers/vdpa/ifc/ifcvf_vdpa.c > +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c > @@ -55,7 +55,7 @@ struct ifcvf_internal { > pthread_t tid; /* thread for notify relay */ > int epfd; > int vid; > - int did; > + struct rte_vdpa_device *vdev; > uint16_t max_queues; > uint64_t features; > rte_atomic32_t started; > @@ -84,7 +84,7 @@ static pthread_mutex_t internal_list_lock = PTHREAD_MUTEX_INITIALIZER; > static void update_used_ring(struct ifcvf_internal *internal, uint16_t qid); > > static struct internal_list * > -find_internal_resource_by_did(int did) > +find_internal_resource_by_vdev(struct rte_vdpa_device *vdev) > { > int found = 0; > struct internal_list *list; > @@ -92,7 +92,7 @@ find_internal_resource_by_did(int did) > pthread_mutex_lock(&internal_list_lock); > > TAILQ_FOREACH(list, &internal_list, next) { > - if (did == list->internal->did) { > + if (vdev == list->internal->vdev) { > found = 1; > break; > } > @@ -877,14 +877,14 @@ ifcvf_sw_fallback_switchover(struct ifcvf_internal *internal) > static int > ifcvf_dev_config(int vid) > { > - int did; > + struct rte_vdpa_device *vdev; > struct internal_list *list; > struct ifcvf_internal *internal; > > - did = rte_vhost_get_vdpa_device_id(vid); > - list = find_internal_resource_by_did(did); > + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); > + list = find_internal_resource_by_vdev(vdev); > if (list == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d", did); > + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); > return -1; > } > > @@ -894,7 +894,8 @@ ifcvf_dev_config(int vid) > update_datapath(internal); > > if (rte_vhost_host_notifier_ctrl(vid, true) != 0) > - DRV_LOG(NOTICE, "vDPA (%d): software relay is used.", did); > + DRV_LOG(NOTICE, "vDPA (%s): software relay is used.", > + vdev->device->name); > > return 0; > } > @@ -902,14 +903,14 @@ ifcvf_dev_config(int vid) > static int > ifcvf_dev_close(int vid) > { > - int did; > + struct rte_vdpa_device *vdev; > struct internal_list *list; > struct ifcvf_internal *internal; > > - did = rte_vhost_get_vdpa_device_id(vid); > - list = find_internal_resource_by_did(did); > + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); > + list = find_internal_resource_by_vdev(vdev); > if (list == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d", did); > + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); > return -1; > } > > @@ -941,15 +942,15 @@ static int > ifcvf_set_features(int vid) > { > uint64_t features = 0; > - int did; > + struct rte_vdpa_device *vdev; > struct internal_list *list; > struct ifcvf_internal *internal; > uint64_t log_base = 0, log_size = 0; > > - did = rte_vhost_get_vdpa_device_id(vid); > - list = find_internal_resource_by_did(did); > + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); > + list = find_internal_resource_by_vdev(vdev); > if (list == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d", did); > + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); > return -1; > } > > @@ -974,13 +975,13 @@ ifcvf_set_features(int vid) > static int > ifcvf_get_vfio_group_fd(int vid) > { > - int did; > + struct rte_vdpa_device *vdev; > struct internal_list *list; > > - did = rte_vhost_get_vdpa_device_id(vid); > - list = find_internal_resource_by_did(did); > + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); > + list = find_internal_resource_by_vdev(vdev); > if (list == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d", did); > + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); > return -1; > } > > @@ -990,13 +991,13 @@ ifcvf_get_vfio_group_fd(int vid) > static int > ifcvf_get_vfio_device_fd(int vid) > { > - int did; > + struct rte_vdpa_device *vdev; > struct internal_list *list; > > - did = rte_vhost_get_vdpa_device_id(vid); > - list = find_internal_resource_by_did(did); > + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); > + list = find_internal_resource_by_vdev(vdev); > if (list == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d", did); > + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); > return -1; > } > > @@ -1006,16 +1007,16 @@ ifcvf_get_vfio_device_fd(int vid) > static int > ifcvf_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) > { > - int did; > + struct rte_vdpa_device *vdev; > struct internal_list *list; > struct ifcvf_internal *internal; > struct vfio_region_info reg = { .argsz = sizeof(reg) }; > int ret; > > - did = rte_vhost_get_vdpa_device_id(vid); > - list = find_internal_resource_by_did(did); > + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); > + list = find_internal_resource_by_vdev(vdev); > if (list == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d", did); > + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); > return -1; > } > > @@ -1036,13 +1037,13 @@ ifcvf_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) > } > > static int > -ifcvf_get_queue_num(int did, uint32_t *queue_num) > +ifcvf_get_queue_num(struct rte_vdpa_device *vdev, uint32_t *queue_num) > { > struct internal_list *list; > > - list = find_internal_resource_by_did(did); > + list = find_internal_resource_by_vdev(vdev); > if (list == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d", did); > + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); > return -1; > } > > @@ -1052,13 +1053,13 @@ ifcvf_get_queue_num(int did, uint32_t *queue_num) > } > > static int > -ifcvf_get_vdpa_features(int did, uint64_t *features) > +ifcvf_get_vdpa_features(struct rte_vdpa_device *vdev, uint64_t *features) > { > struct internal_list *list; > > - list = find_internal_resource_by_did(did); > + list = find_internal_resource_by_vdev(vdev); > if (list == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d", did); > + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); > return -1; > } > > @@ -1074,8 +1075,10 @@ ifcvf_get_vdpa_features(int did, uint64_t *features) > 1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER | \ > 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) > static int > -ifcvf_get_protocol_features(int did __rte_unused, uint64_t *features) > +ifcvf_get_protocol_features(struct rte_vdpa_device *vdev, uint64_t *features) > { > + RTE_SET_USED(vdev); > + > *features = VDPA_SUPPORTED_PROTOCOL_FEATURES; > return 0; > } > @@ -1186,8 +1189,8 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, > } > internal->sw_lm = sw_fallback_lm; > > - internal->did = rte_vdpa_register_device(&pci_dev->device, &ifcvf_ops); > - if (internal->did < 0) { > + internal->vdev = rte_vdpa_register_device(&pci_dev->device, &ifcvf_ops); > + if (internal->vdev == NULL) { > DRV_LOG(ERR, "failed to register device %s", pci_dev->name); > goto error; > } > @@ -1230,7 +1233,7 @@ ifcvf_pci_remove(struct rte_pci_device *pci_dev) > > rte_pci_unmap_device(internal->pdev); > rte_vfio_container_destroy(internal->vfio_container_fd); > - rte_vdpa_unregister_device(internal->did); > + rte_vdpa_unregister_device(internal->vdev); > > pthread_mutex_lock(&internal_list_lock); > TAILQ_REMOVE(&internal_list, list, next); > diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c > index 7b5ae62bdc..9ea032d57b 100644 > --- a/drivers/vdpa/mlx5/mlx5_vdpa.c > +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c > @@ -50,21 +50,21 @@ static pthread_mutex_t priv_list_lock = PTHREAD_MUTEX_INITIALIZER; > int mlx5_vdpa_logtype; > > static struct mlx5_vdpa_priv * > -mlx5_vdpa_find_priv_resource_by_did(int did) > +mlx5_vdpa_find_priv_resource_by_vdev(struct rte_vdpa_device *vdev) > { > struct mlx5_vdpa_priv *priv; > int found = 0; > > pthread_mutex_lock(&priv_list_lock); > TAILQ_FOREACH(priv, &priv_list, next) { > - if (did == priv->id) { > + if (vdev == priv->vdev) { > found = 1; > break; > } > } > pthread_mutex_unlock(&priv_list_lock); > if (!found) { > - DRV_LOG(ERR, "Invalid device id: %d.", did); > + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); > rte_errno = EINVAL; > return NULL; > } > @@ -72,12 +72,13 @@ mlx5_vdpa_find_priv_resource_by_did(int did) > } > > static int > -mlx5_vdpa_get_queue_num(int did, uint32_t *queue_num) > +mlx5_vdpa_get_queue_num(struct rte_vdpa_device *vdev, uint32_t *queue_num) > { > - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); > + struct mlx5_vdpa_priv *priv = > + mlx5_vdpa_find_priv_resource_by_vdev(vdev); > > if (priv == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d.", did); > + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); > return -1; > } > *queue_num = priv->caps.max_num_virtio_queues; > @@ -85,12 +86,13 @@ mlx5_vdpa_get_queue_num(int did, uint32_t *queue_num) > } > > static int > -mlx5_vdpa_get_vdpa_features(int did, uint64_t *features) > +mlx5_vdpa_get_vdpa_features(struct rte_vdpa_device *vdev, uint64_t *features) > { > - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); > + struct mlx5_vdpa_priv *priv = > + mlx5_vdpa_find_priv_resource_by_vdev(vdev); > > if (priv == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d.", did); > + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); > return -1; > } > *features = MLX5_VDPA_DEFAULT_FEATURES; > @@ -110,12 +112,14 @@ mlx5_vdpa_get_vdpa_features(int did, uint64_t *features) > } > > static int > -mlx5_vdpa_get_protocol_features(int did, uint64_t *features) > +mlx5_vdpa_get_protocol_features(struct rte_vdpa_device *vdev, > + uint64_t *features) > { > - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); > + struct mlx5_vdpa_priv *priv = > + mlx5_vdpa_find_priv_resource_by_vdev(vdev); > > if (priv == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d.", did); > + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); > return -1; > } > *features = MLX5_VDPA_PROTOCOL_FEATURES; > @@ -125,11 +129,13 @@ mlx5_vdpa_get_protocol_features(int did, uint64_t *features) > static int > mlx5_vdpa_set_vring_state(int vid, int vring, int state) > { > - int did = rte_vhost_get_vdpa_device_id(vid); > - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); > + struct rte_vdpa_device *vdev = rte_vdpa_get_device( > + rte_vhost_get_vdpa_device_id(vid)); > + struct mlx5_vdpa_priv *priv = > + mlx5_vdpa_find_priv_resource_by_vdev(vdev); > > if (priv == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d.", did); > + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); > return -EINVAL; > } > if (vring >= (int)priv->caps.max_num_virtio_queues * 2) { > @@ -165,14 +171,16 @@ mlx5_vdpa_direct_db_prepare(struct mlx5_vdpa_priv *priv) > static int > mlx5_vdpa_features_set(int vid) > { > - int did = rte_vhost_get_vdpa_device_id(vid); > - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); > + struct rte_vdpa_device *vdev = rte_vdpa_get_device( > + rte_vhost_get_vdpa_device_id(vid)); > + struct mlx5_vdpa_priv *priv = > + mlx5_vdpa_find_priv_resource_by_vdev(vdev); > uint64_t log_base, log_size; > uint64_t features; > int ret; > > if (priv == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d.", did); > + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); > return -EINVAL; > } > ret = rte_vhost_get_negotiated_features(vid, &features); > @@ -284,12 +292,14 @@ mlx5_vdpa_mtu_set(struct mlx5_vdpa_priv *priv) > static int > mlx5_vdpa_dev_close(int vid) > { > - int did = rte_vhost_get_vdpa_device_id(vid); > - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); > + struct rte_vdpa_device *vdev = rte_vdpa_get_device( > + rte_vhost_get_vdpa_device_id(vid)); > + struct mlx5_vdpa_priv *priv = > + mlx5_vdpa_find_priv_resource_by_vdev(vdev); > int ret = 0; > > if (priv == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d.", did); > + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); > return -1; > } > if (priv->configured) > @@ -312,11 +322,13 @@ mlx5_vdpa_dev_close(int vid) > static int > mlx5_vdpa_dev_config(int vid) > { > - int did = rte_vhost_get_vdpa_device_id(vid); > - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); > + struct rte_vdpa_device *vdev = rte_vdpa_get_device( > + rte_vhost_get_vdpa_device_id(vid)); > + struct mlx5_vdpa_priv *priv = > + mlx5_vdpa_find_priv_resource_by_vdev(vdev); > > if (priv == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d.", did); > + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); > return -EINVAL; > } > if (priv->configured && mlx5_vdpa_dev_close(vid)) { > @@ -325,7 +337,8 @@ mlx5_vdpa_dev_config(int vid) > } > priv->vid = vid; > if (mlx5_vdpa_mtu_set(priv)) > - DRV_LOG(WARNING, "MTU cannot be set on device %d.", did); > + DRV_LOG(WARNING, "MTU cannot be set on device %s.", > + vdev->device->name); > if (mlx5_vdpa_pd_create(priv) || mlx5_vdpa_mem_register(priv) || > mlx5_vdpa_direct_db_prepare(priv) || > mlx5_vdpa_virtqs_prepare(priv) || mlx5_vdpa_steer_setup(priv) || > @@ -341,11 +354,13 @@ mlx5_vdpa_dev_config(int vid) > static int > mlx5_vdpa_get_device_fd(int vid) > { > - int did = rte_vhost_get_vdpa_device_id(vid); > - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); > + struct rte_vdpa_device *vdev = rte_vdpa_get_device( > + rte_vhost_get_vdpa_device_id(vid)); > + struct mlx5_vdpa_priv *priv = > + mlx5_vdpa_find_priv_resource_by_vdev(vdev); > > if (priv == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d.", did); > + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); > return -EINVAL; > } > return priv->ctx->cmd_fd; > @@ -354,17 +369,19 @@ mlx5_vdpa_get_device_fd(int vid) > static int > mlx5_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) > { > - int did = rte_vhost_get_vdpa_device_id(vid); > - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); > + struct rte_vdpa_device *vdev = rte_vdpa_get_device( > + rte_vhost_get_vdpa_device_id(vid)); > + struct mlx5_vdpa_priv *priv = > + mlx5_vdpa_find_priv_resource_by_vdev(vdev); > > RTE_SET_USED(qid); > if (priv == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d.", did); > + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); > return -EINVAL; > } > if (!priv->var) { > - DRV_LOG(ERR, "VAR was not created for device %d, is the device" > - " configured?.", did); > + DRV_LOG(ERR, "VAR was not created for device %s, is the device" > + " configured?.", vdev->device->name); > return -EINVAL; > } > *offset = priv->var->mmap_off; > @@ -373,8 +390,9 @@ mlx5_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) > } > > static int > -mlx5_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, > - unsigned int size) > +mlx5_vdpa_get_stats_names(struct rte_vdpa_device *vdev, > + struct rte_vdpa_stat_name *stats_names, > + unsigned int size) > { > static const char *mlx5_vdpa_stats_names[MLX5_VDPA_STATS_MAX] = { > "received_descriptors", > @@ -384,11 +402,12 @@ mlx5_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, > "invalid buffer", > "completion errors", > }; > - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); > + struct mlx5_vdpa_priv *priv = > + mlx5_vdpa_find_priv_resource_by_vdev(vdev); > unsigned int i; > > if (priv == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d.", did); > + DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name); > return -ENODEV; > } > if (!stats_names) > @@ -401,51 +420,57 @@ mlx5_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, > } > > static int > -mlx5_vdpa_get_stats(int did, int qid, struct rte_vdpa_stat *stats, > - unsigned int n) > +mlx5_vdpa_get_stats(struct rte_vdpa_device *vdev, int qid, > + struct rte_vdpa_stat *stats, unsigned int n) > { > - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); > + struct mlx5_vdpa_priv *priv = > + mlx5_vdpa_find_priv_resource_by_vdev(vdev); > > if (priv == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d.", did); > + DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name); > return -ENODEV; > } > if (!priv->configured) { > - DRV_LOG(ERR, "Device %d was not configured.", did); > + DRV_LOG(ERR, "Device %s was not configured.", > + vdev->device->name); > return -ENODATA; > } > if (qid >= (int)priv->nr_virtqs) { > - DRV_LOG(ERR, "Too big vring id: %d.", qid); > + DRV_LOG(ERR, "Too big vring id: %d for device %s.", qid, > + vdev->device->name); > return -E2BIG; > } > if (!priv->caps.queue_counters_valid) { > - DRV_LOG(ERR, "Virtq statistics is not supported for device %d.", > - did); > + DRV_LOG(ERR, "Virtq statistics is not supported for device %s.", > + vdev->device->name); > return -ENOTSUP; > } > return mlx5_vdpa_virtq_stats_get(priv, qid, stats, n); > } > > static int > -mlx5_vdpa_reset_stats(int did, int qid) > +mlx5_vdpa_reset_stats(struct rte_vdpa_device *vdev, int qid) > { > - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); > + struct mlx5_vdpa_priv *priv = > + mlx5_vdpa_find_priv_resource_by_vdev(vdev); > > if (priv == NULL) { > - DRV_LOG(ERR, "Invalid device id: %d.", did); > + DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name); > return -ENODEV; > } > if (!priv->configured) { > - DRV_LOG(ERR, "Device %d was not configured.", did); > + DRV_LOG(ERR, "Device %s was not configured.", > + vdev->device->name); > return -ENODATA; > } > if (qid >= (int)priv->nr_virtqs) { > - DRV_LOG(ERR, "Too big vring id: %d.", qid); > + DRV_LOG(ERR, "Too big vring id: %d for device %s.", qid, > + vdev->device->name); > return -E2BIG; > } > if (!priv->caps.queue_counters_valid) { > - DRV_LOG(ERR, "Virtq statistics is not supported for device %d.", > - did); > + DRV_LOG(ERR, "Virtq statistics is not supported for device %s.", > + vdev->device->name); > return -ENOTSUP; > } > return mlx5_vdpa_virtq_stats_reset(priv, qid); > @@ -687,8 +712,9 @@ mlx5_vdpa_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, > DRV_LOG(ERR, "Failed to allocate VAR %u.\n", errno); > goto error; > } > - priv->id = rte_vdpa_register_device(&pci_dev->device, &mlx5_vdpa_ops); > - if (priv->id < 0) { > + priv->vdev = rte_vdpa_register_device(&pci_dev->device, > + &mlx5_vdpa_ops); > + if (priv->vdev == NULL) { > DRV_LOG(ERR, "Failed to register vDPA device."); > rte_errno = rte_errno ? rte_errno : EINVAL; > goto error; > diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h > index 5fc801eff3..ea09576c5a 100644 > --- a/drivers/vdpa/mlx5/mlx5_vdpa.h > +++ b/drivers/vdpa/mlx5/mlx5_vdpa.h > @@ -103,7 +103,7 @@ struct mlx5_vdpa_priv { > TAILQ_ENTRY(mlx5_vdpa_priv) next; > uint8_t configured; > uint8_t direct_notifier; /* Whether direct notifier is on or off. */ > - int id; /* vDPA device id. */ > + struct rte_vdpa_device *vdev; /* vDPA device. */ > int vid; /* vhost device id. */ > struct ibv_context *ctx; /* Device context. */ > struct rte_pci_device *pci_dev; > diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c > index e72f6646e7..bdb00603cc 100644 > --- a/examples/vdpa/main.c > +++ b/examples/vdpa/main.c > @@ -291,13 +291,13 @@ static void cmd_list_vdpa_devices_parsed( > vdev = rte_vdpa_get_device(did); > if (!vdev) > continue; > - if (vdev->ops->get_queue_num(did, &queue_num) < 0) { > + if (vdev->ops->get_queue_num(vdev, &queue_num) < 0) { > RTE_LOG(ERR, VDPA, > "failed to get vdpa queue number " > "for device id %d.\n", did); > continue; > } > - if (vdev->ops->get_features(did, &features) < 0) { > + if (vdev->ops->get_features(vdev, &features) < 0) { > RTE_LOG(ERR, VDPA, > "failed to get vdpa features " > "for device id %d.\n", did); > diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h > index b752dfeb96..109cf83b8f 100644 > --- a/lib/librte_vhost/rte_vdpa.h > +++ b/lib/librte_vhost/rte_vdpa.h > @@ -21,6 +21,8 @@ > /** Maximum name length for statistics counters */ > #define RTE_VDPA_STATS_NAME_SIZE 64 > > +struct rte_vdpa_device; > + > /** > * A vDPA device statistic structure > * > @@ -51,13 +53,14 @@ struct rte_vdpa_stat_name { > */ > struct rte_vdpa_dev_ops { > /** Get capabilities of this device */ > - int (*get_queue_num)(int did, uint32_t *queue_num); > + int (*get_queue_num)(struct rte_vdpa_device *dev, uint32_t *queue_num); > > /** Get supported features of this device */ > - int (*get_features)(int did, uint64_t *features); > + int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features); > > /** Get supported protocol features of this device */ > - int (*get_protocol_features)(int did, uint64_t *protocol_features); > + int (*get_protocol_features)(struct rte_vdpa_device *dev, > + uint64_t *protocol_features); > > /** Driver configure/close the device */ > int (*dev_conf)(int vid); > @@ -83,15 +86,16 @@ struct rte_vdpa_dev_ops { > uint64_t *offset, uint64_t *size); > > /** Get statistics name */ > - int (*get_stats_names)(int did, struct rte_vdpa_stat_name *stats_names, > - unsigned int size); > + int (*get_stats_names)(struct rte_vdpa_device *dev, > + struct rte_vdpa_stat_name *stats_names, > + unsigned int size); > > /** Get statistics of the queue */ > - int (*get_stats)(int did, int qid, struct rte_vdpa_stat *stats, > - unsigned int n); > + int (*get_stats)(struct rte_vdpa_device *dev, int qid, > + struct rte_vdpa_stat *stats, unsigned int n); > > /** Reset statistics of the queue */ > - int (*reset_stats)(int did, int qid); > + int (*reset_stats)(struct rte_vdpa_device *dev, int qid); > > /** Reserved for future extension */ > void *reserved[2]; > @@ -118,10 +122,10 @@ struct rte_vdpa_device { > * @param ops > * the vdpa device operations > * @return > - * device id on success, -1 on failure > + * vDPA device pointer on success, NULL on failure > */ > __rte_experimental > -int > +struct rte_vdpa_device * > rte_vdpa_register_device(struct rte_device *rte_dev, > struct rte_vdpa_dev_ops *ops); > > @@ -132,13 +136,13 @@ rte_vdpa_register_device(struct rte_device *rte_dev, > * Unregister a vdpa device > * > * @param did > - * vdpa device id > + * vDPA device pointer > * @return > * device id on success, -1 on failure > */ > __rte_experimental > int > -rte_vdpa_unregister_device(int did); > +rte_vdpa_unregister_device(struct rte_vdpa_device *); > > /** > * @warning > diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c > index 0a66ef9767..da575b608c 100644 > --- a/lib/librte_vhost/socket.c > +++ b/lib/librte_vhost/socket.c > @@ -712,7 +712,7 @@ rte_vhost_driver_get_features(const char *path, uint64_t *features) > goto unlock_exit; > } > > - if (vdpa_dev->ops->get_features(did, &vdpa_features) < 0) { > + if (vdpa_dev->ops->get_features(vdpa_dev, &vdpa_features) < 0) { > VHOST_LOG_CONFIG(ERR, > "failed to get vdpa features " > "for socket file %s.\n", path); > @@ -767,7 +767,7 @@ rte_vhost_driver_get_protocol_features(const char *path, > goto unlock_exit; > } > > - if (vdpa_dev->ops->get_protocol_features(did, > + if (vdpa_dev->ops->get_protocol_features(vdpa_dev, > &vdpa_protocol_features) < 0) { > VHOST_LOG_CONFIG(ERR, > "failed to get vdpa protocol features " > @@ -809,7 +809,7 @@ rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num) > goto unlock_exit; > } > > - if (vdpa_dev->ops->get_queue_num(did, &vdpa_queue_num) < 0) { > + if (vdpa_dev->ops->get_queue_num(vdpa_dev, &vdpa_queue_num) < 0) { > VHOST_LOG_CONFIG(ERR, > "failed to get vdpa queue number " > "for socket file %s.\n", path); > diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c > index 07db5b9e46..ed20082f0f 100644 > --- a/lib/librte_vhost/vdpa.c > +++ b/lib/librte_vhost/vdpa.c > @@ -18,52 +18,6 @@ > static struct rte_vdpa_device vdpa_devices[MAX_VHOST_DEVICE]; > static uint32_t vdpa_device_num; > > -int > -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 || ops == NULL) > - return -1; > - > - for (i = 0; i < MAX_VHOST_DEVICE; i++) { > - dev = &vdpa_devices[i]; > - if (dev->ops == NULL) > - continue; > - > - if (dev->device == rte_dev) > - return -1; > - } > - > - for (i = 0; i < MAX_VHOST_DEVICE; i++) { > - if (vdpa_devices[i].ops == NULL) > - break; > - } > - > - if (i == MAX_VHOST_DEVICE) > - return -1; > - > - dev = &vdpa_devices[i]; > - dev->device = rte_dev; > - dev->ops = ops; > - vdpa_device_num++; > - > - return i; > -} > - > -int > -rte_vdpa_unregister_device(int did) > -{ > - if (did < 0 || did >= MAX_VHOST_DEVICE || vdpa_devices[did].ops == NULL) > - return -1; > - > - memset(&vdpa_devices[did], 0, sizeof(struct rte_vdpa_device)); > - vdpa_device_num--; > - > - return did; > -} > > int > rte_vdpa_find_device_id(struct rte_vdpa_device *dev) > @@ -116,6 +70,55 @@ rte_vdpa_get_device(int did) > return &vdpa_devices[did]; > } > > +struct rte_vdpa_device * > +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 || ops == NULL) > + return NULL; > + > + for (i = 0; i < MAX_VHOST_DEVICE; i++) { > + dev = &vdpa_devices[i]; > + if (dev->ops == NULL) > + continue; > + > + if (dev->device == rte_dev) > + return NULL; > + } > + > + for (i = 0; i < MAX_VHOST_DEVICE; i++) { > + if (vdpa_devices[i].ops == NULL) > + break; > + } > + > + if (i == MAX_VHOST_DEVICE) > + return NULL; > + > + dev = &vdpa_devices[i]; > + dev->device = rte_dev; > + dev->ops = ops; > + vdpa_device_num++; > + > + return dev; > +} > + > +int > +rte_vdpa_unregister_device(struct rte_vdpa_device *vdev) > +{ > + int did = rte_vdpa_find_device_id(vdev); > + > + if (did < 0 || vdpa_devices[did].ops == NULL) > + return -1; > + > + memset(&vdpa_devices[did], 0, sizeof(struct rte_vdpa_device)); > + vdpa_device_num--; > + > + return 0; > +} > + > int > rte_vdpa_get_device_num(void) > { > @@ -236,7 +239,7 @@ rte_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, > > RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_stats_names, -ENOTSUP); > > - return vdpa_dev->ops->get_stats_names(did, stats_names, size); > + return vdpa_dev->ops->get_stats_names(vdpa_dev, stats_names, size); > } > > int > @@ -254,7 +257,7 @@ rte_vdpa_get_stats(int did, uint16_t qid, struct rte_vdpa_stat *stats, > > RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_stats, -ENOTSUP); > > - return vdpa_dev->ops->get_stats(did, qid, stats, n); > + return vdpa_dev->ops->get_stats(vdpa_dev, qid, stats, n); > } > > int > @@ -268,7 +271,7 @@ rte_vdpa_reset_stats(int did, uint16_t qid) > > RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->reset_stats, -ENOTSUP); > > - return vdpa_dev->ops->reset_stats(did, qid); > + return vdpa_dev->ops->reset_stats(vdpa_dev, qid); > } > > static uint16_t > Acked-by: Adrián Moreno -- Adrián Moreno