From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f175.google.com (mail-wr0-f175.google.com [209.85.128.175]) by dpdk.org (Postfix) with ESMTP id 8FAB337A6 for ; Wed, 21 Jun 2017 01:29:55 +0200 (CEST) Received: by mail-wr0-f175.google.com with SMTP id c11so55993667wrc.3 for ; Tue, 20 Jun 2017 16:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=jNkBOKUIdoJ9SlwQzEZqLaswsUA02fbgKJ1ki6BIAh0=; b=j4cAls4xpK2UkzeSZ8sAK4awcjNzObN9MnPRtQJB9c5IppVFeE0llgC0wiRBeRxG2/ GpSAfJpVhhi5sa7/ZDs/GEtcOGMQVFoytS9Bpa2sSHIq/GJM5j3Cqv3xh1gxEhoSJcYM PEcrblNHsuQzeTVdgD/SXDNkrNB4rz5y4Pnuz0R2WkPrim29sae0qo5qrWVx/4Ab3Gx+ AIZrSGJHIGjkPe9bL8wnz4TEpH6C6gfoYxraSDcY/gL1KmFQf9BlnFZOpnE/l7R2JWAR SqNq2jZ2eIXdEEfzUDmnY2wIcYLZP7+lf6sUlnPeAd4a7pnzhglXVTH0+Ssacok81b07 rEzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=jNkBOKUIdoJ9SlwQzEZqLaswsUA02fbgKJ1ki6BIAh0=; b=hqr7mvlPxqbBrznp0jffksbNBDcLfXzceYN2fQIeaDP9cLsK/UK5YNOSp+XrKLYwrB sikafaTxNCeayDfTXcR1XYpgYJlskwwaVzSyAS3A0vPhREqR/POf+SobqXnlXykLskmU 8kGh0bbKOxrxDmM0CLSG/ubhHfZ+uq9jfyALQ+3oUtwc2M+McasDm08H7f5G0bkavEhy aIn4EHY5KichyKQ8dz5djVqz8GhT/CLh4T58qa3HFHrgk5pn2sMQmhgSY0iCaxlMeooK TIINle21aKB/gTt9/F6ivshEInwvbfLMyl493PmcIYQg0sIXpXbivq4jcPUX3iLiKGjC mKgQ== X-Gm-Message-State: AKS2vOwvaoFnpGy+thKylAY3cfu9u8MbUTeGQUG9i8fl27qSoMLQSr9g S6wjC536TOc29zPbKcU= X-Received: by 10.223.176.253 with SMTP id j58mr20846150wra.65.1498001394982; Tue, 20 Jun 2017 16:29:54 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id l127sm8592248wml.26.2017.06.20.16.29.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Jun 2017 16:29:54 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck , Gaetan Rivet Date: Wed, 21 Jun 2017 01:29:29 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v4 8/9] eal: make virtual driver probe and remove take rte_vdev_device 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: , X-List-Received-Date: Tue, 20 Jun 2017 23:29:56 -0000 From: Jan Blunck This is a preparation to embed the generic rte_device into the rte_eth_dev also for virtual devices. Signed-off-by: Jan Blunck Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_dev.c | 93 ++++++++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 22 deletions(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index a400ddd..733da91 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -45,50 +46,98 @@ #include "eal_private.h" +static int cmp_detached_dev_name(const struct rte_device *dev, + const void *_name) +{ + const char *name = _name; + + /* skip attached devices */ + if (dev->driver) + return 0; + + return strcmp(dev->name, name); +} + int rte_eal_dev_attach(const char *name, const char *devargs) { - struct rte_pci_addr addr; + struct rte_device *dev; + int ret; if (name == NULL || devargs == NULL) { RTE_LOG(ERR, EAL, "Invalid device or arguments provided\n"); return -EINVAL; } - if (eal_parse_pci_DomBDF(name, &addr) == 0) { - if (rte_pci_probe_one(&addr) < 0) - goto err; + dev = rte_bus_find_device(NULL, cmp_detached_dev_name, name); + if (dev) { + struct rte_bus *bus; + + bus = rte_bus_find_by_device(dev); + if (!bus) { + RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n", + name); + return -EINVAL; + } - } else { - if (rte_vdev_init(name, devargs)) - goto err; + if (!bus->plug) { + RTE_LOG(ERR, EAL, "Bus function not supported\n"); + return -ENOTSUP; + } + + ret = (bus->plug(dev->devargs) == NULL); + goto out; } - return 0; + /* + * If we haven't found a bus device the user meant to "hotplug" a + * virtual device instead. + */ + ret = rte_vdev_init(name, devargs); +out: + if (ret) + RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", + name); + return ret; +} + +static int cmp_dev_name(const struct rte_device *dev, const void *_name) +{ + const char *name = _name; -err: - RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", name); - return -EINVAL; + return strcmp(dev->name, name); } int rte_eal_dev_detach(const char *name) { - struct rte_pci_addr addr; + struct rte_device *dev; + struct rte_bus *bus; + int ret; if (name == NULL) { RTE_LOG(ERR, EAL, "Invalid device provided.\n"); return -EINVAL; } - if (eal_parse_pci_DomBDF(name, &addr) == 0) { - if (rte_pci_detach(&addr) < 0) - goto err; - } else { - if (rte_vdev_uninit(name)) - goto err; + dev = rte_bus_find_device(NULL, cmp_dev_name, name); + if (!dev) { + RTE_LOG(ERR, EAL, "Cannot find device (%s)\n", name); + return -EINVAL; + } + + bus = rte_bus_find_by_device(dev); + if (!bus) { + RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n", name); + return -EINVAL; + } + + if (!bus->unplug) { + RTE_LOG(ERR, EAL, "Bus function not supported\n"); + return -ENOTSUP; } - return 0; -err: - RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", name); - return -EINVAL; + ret = bus->unplug(dev); + if (ret) + RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", + name); + return ret; } -- 2.1.4