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 40F6CA0350; Fri, 26 Jun 2020 12:18:18 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5A7241BEA3; Fri, 26 Jun 2020 12:18:17 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id EE46B1BE9E for ; Fri, 26 Jun 2020 12:18:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593166695; 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=hjs1fA8Y2qb7cpDjIndk9owHTgmTfBpsovl7+I1/rXw=; b=eAq20okNB22LtzKt6yHsrxRfXRmcTnLemFnDAeXKAY+r7PdQhdDTCUWEpG9potADJTzSvt CK26BGBc+3nJqFWaETXb5JEauskwEiSE6dgTjuGIw0v46e9AVJ4oGoyAA+5XFXjPWhm4lF CqhCG/1kPsF8it6hjPpwAANyw0zihLk= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-25-EL6M-qjtPBmQvY6RZQAzvA-1; Fri, 26 Jun 2020 06:18:14 -0400 X-MC-Unique: EL6M-qjtPBmQvY6RZQAzvA-1 Received: by mail-wr1-f69.google.com with SMTP id i5so8985173wra.9 for ; Fri, 26 Jun 2020 03:18:13 -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=hjs1fA8Y2qb7cpDjIndk9owHTgmTfBpsovl7+I1/rXw=; b=XVVoLhBEt8rUQsH+2kFo1hqQRmTf9Y5Kci5yqoiBRtCjXk3KL3L/IPZu2lyOvHNVuB DSr+TiNms13Y1oCvWKVMilg+T1+c2Dnbnf+UF+hIKEZyx2ZrTZzQPZO93d6VOWHeobV9 U9zDgVSwfgZC+1ctBH/bEJl4yQQCFIEpy00EhoItUafnc2JYpMzZYb1cGZDUQvOStnG7 HdbRi8CI/SvLNrltbUm3wI9Vw/oK6ShpWA0mo3L1TPw0rAL2ampvIuMuol4+Nsw/vzdY 4hyd4OcB3/s07OWr/FwjijvzRDNrcHBihB02OhvGNixHqt7cbOeQqMm0hfelLSZ0YyMQ GgAw== X-Gm-Message-State: AOAM533VxlAMmsxNJ0D6+7gG9Xq0kAXVKZvjJs5jNQ232/PkRdZR0T95 LzTxK5wmCLooh0VobvMJ/6dvbAM6BpuwP734MG2moVYYNuwVD4ik04N6SvetMgXfSDW7YFAtU6w lEVI= X-Received: by 2002:a7b:ca59:: with SMTP id m25mr2750304wml.151.1593166692199; Fri, 26 Jun 2020 03:18:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3MYf/ybhX/rkf8DpoLcaKileHXcduL1BgIN93WvkUsWmL3zadEGQBiNIybwkjFlSjwkT4Vw== X-Received: by 2002:a7b:ca59:: with SMTP id m25mr2750286wml.151.1593166691920; Fri, 26 Jun 2020 03:18:11 -0700 (PDT) Received: from amorenoz.users.ipa.redhat.com ([92.176.159.3]) by smtp.gmail.com with ESMTPSA id d24sm16220344wmb.45.2020.06.26.03.18.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Jun 2020 03:18:11 -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-4-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: <32c2fbff-7e84-9101-4178-dfc10dde4572@redhat.com> Date: Fri, 26 Jun 2020 12:18:09 +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-4-maxime.coquelin@redhat.com> Content-Language: en-US Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com 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 03/14] vhost: introduce vDPA devices class 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 introduces vDPA device class. It will enable > application to iterate over the vDPA devices. > > Signed-off-by: Maxime Coquelin > --- > lib/librte_vhost/vdpa.c | 115 +++++++++++++++++++++++++++++++++------- > 1 file changed, 97 insertions(+), 18 deletions(-) > > diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c > index 1f5cdcd64b..a429841691 100644 > --- a/lib/librte_vhost/vdpa.c > +++ b/lib/librte_vhost/vdpa.c > @@ -10,11 +10,12 @@ > > #include > > +#include > #include > #include "rte_vdpa.h" > #include "vhost.h" > > -static struct rte_vdpa_device *vdpa_devices[MAX_VHOST_DEVICE]; > +static struct rte_vdpa_device vdpa_devices[MAX_VHOST_DEVICE]; > static uint32_t vdpa_device_num; > > static bool > @@ -46,35 +47,28 @@ rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr, > struct rte_vdpa_dev_ops *ops) > { > struct rte_vdpa_device *dev; > - char device_name[MAX_VDPA_NAME_LEN]; > int i; > > if (vdpa_device_num >= MAX_VHOST_DEVICE || addr == NULL || ops == NULL) > return -1; > > for (i = 0; i < MAX_VHOST_DEVICE; i++) { > - dev = vdpa_devices[i]; > - if (dev && is_same_vdpa_device(&dev->addr, addr)) > + dev = &vdpa_devices[i]; > + if (dev->ops && is_same_vdpa_device(&dev->addr, addr)) > return -1; > } > > for (i = 0; i < MAX_VHOST_DEVICE; i++) { > - if (vdpa_devices[i] == NULL) > + if (vdpa_devices[i].ops == NULL) > break; > } > > if (i == MAX_VHOST_DEVICE) > return -1; > > - snprintf(device_name, sizeof(device_name), "vdpa-dev-%d", i); > - dev = rte_zmalloc(device_name, sizeof(struct rte_vdpa_device), > - RTE_CACHE_LINE_SIZE); > - if (!dev) > - return -1; > - > + dev = &vdpa_devices[i]; > memcpy(&dev->addr, addr, sizeof(struct rte_vdpa_dev_addr)); > dev->ops = ops; > - vdpa_devices[i] = dev; > vdpa_device_num++; > > return i; > @@ -83,11 +77,10 @@ rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr, > int > rte_vdpa_unregister_device(int did) > { > - if (did < 0 || did >= MAX_VHOST_DEVICE || vdpa_devices[did] == NULL) > + if (did < 0 || did >= MAX_VHOST_DEVICE || vdpa_devices[did].ops == NULL) > return -1; > > - rte_free(vdpa_devices[did]); > - vdpa_devices[did] = NULL; > + memset(&vdpa_devices[did], 0, sizeof(struct rte_vdpa_device)); > vdpa_device_num--; > > return did; > @@ -103,8 +96,11 @@ rte_vdpa_find_device_id(struct rte_vdpa_dev_addr *addr) > return -1; > > for (i = 0; i < MAX_VHOST_DEVICE; ++i) { > - dev = vdpa_devices[i]; > - if (dev && is_same_vdpa_device(&dev->addr, addr)) > + dev = &vdpa_devices[i]; > + if (dev->ops == NULL) > + continue; > + > + if (is_same_vdpa_device(&dev->addr, addr)) > return i; > } > > @@ -117,7 +113,7 @@ rte_vdpa_get_device(int did) > if (did < 0 || did >= MAX_VHOST_DEVICE) > return NULL; > > - return vdpa_devices[did]; > + return &vdpa_devices[did]; > } > > int > @@ -274,3 +270,86 @@ rte_vdpa_reset_stats(int did, uint16_t qid) > > return vdpa_dev->ops->reset_stats(did, qid); > } > + > +static uint16_t > +vdpa_dev_to_id(const struct rte_vdpa_device *dev) > +{ > + if (dev == NULL) > + return MAX_VHOST_DEVICE; > + > + if (dev < &vdpa_devices[0] || > + dev >= &vdpa_devices[MAX_VHOST_DEVICE]) > + return MAX_VHOST_DEVICE; > + > + return (uint16_t)(dev - vdpa_devices); > +} > + > +static int > +vdpa_dev_match(struct rte_vdpa_device *dev, > + const struct rte_device *rte_dev) > +{ > + struct rte_vdpa_dev_addr addr; > + > + /* 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; > +} > + > +/* Generic rte_vdpa_dev comparison function. */ > +typedef int (*rte_vdpa_cmp_t)(struct rte_vdpa_device *, > + const struct rte_device *rte_dev); > + > +static struct rte_vdpa_device * > +vdpa_find_device(const struct rte_vdpa_device *start, rte_vdpa_cmp_t cmp, > + struct rte_device *rte_dev) > +{ > + struct rte_vdpa_device *dev; > + uint16_t idx; > + > + if (start != NULL) > + idx = vdpa_dev_to_id(start) + 1; > + else > + idx = 0; > + for (; idx < MAX_VHOST_DEVICE; idx++) { > + dev = &vdpa_devices[idx]; > + /* > + * ToDo: Certainly better to introduce a state field, > + * but rely on ops being set for now. > + */ > + if (dev->ops == NULL) > + continue; > + if (cmp(dev, rte_dev) == 0) > + return dev; > + } > + return NULL; > +} > + > +static void * > +vdpa_dev_iterate(const void *start, > + const char *str, > + const struct rte_dev_iterator *it) > +{ > + struct rte_vdpa_device *vdpa_dev = NULL; > + > + RTE_SET_USED(str); > + > + vdpa_dev = vdpa_find_device(start, vdpa_dev_match, it->device); > + > + return vdpa_dev; > +} > + > +static struct rte_class rte_class_vdpa = { > + .dev_iterate = vdpa_dev_iterate, > +}; > + > +RTE_REGISTER_CLASS(vdpa, rte_class_vdpa); > Acked-by: Adrián Moreno -- Adrián Moreno