From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f172.google.com (mail-wr0-f172.google.com [209.85.128.172]) by dpdk.org (Postfix) with ESMTP id 68ECD58CB for ; Tue, 27 Jun 2017 18:11:46 +0200 (CEST) Received: by mail-wr0-f172.google.com with SMTP id c11so161762541wrc.3 for ; Tue, 27 Jun 2017 09:11:46 -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=KTy355P0EHGU9M1BOti684NSHlbfUHLK/gNm1OzKRM0=; b=H91n5FatoKtjJzhAZNTIb+XTyMILCzbWEGKKg1zamHbNIEHLD9i0VhI8jKjdQLBYHj 8feFrAajqNTa94HzW49KcrAPbruuXbOyIurzkNPE2ZG2lkM8v7m4nRy/ID/jg7H7+/pc NoC/cWHu3EmiXJ1WIUJg0+eKSn7cNBmk8sVrfXmfzHv4iZx5Ks1SagBwbSupFS93e/ll 3DWjORSIA1qRIq2kgAgxuC+nq2NZ/mv+otORmTALYYct4u2xH3xoFkeLCU76zGINGQQC t9DQollajZ/J5QzKwkMFduiN9TNvgOO1YBadAVCSQWiVvoAT40eetF+Jdw2eoHVCAdMD 7J+A== 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=KTy355P0EHGU9M1BOti684NSHlbfUHLK/gNm1OzKRM0=; b=FZ8JfzL73Dkmd//GSlhaguSZGQ9TFv07cf1gV3rddHRvdbsarrIqV+9cCOJNJ4rvS4 tXCsHuUHIPPOt70xmZgAGF/8mmPHN4vNkpYke1v5hu20Z7XXTg2KgrBhqm3U0qALhF6C EbdhBuMuq98GUS3lYJ4fcaQc+HE9T2mdtBj9p38gcNjKyRC+vs6IsxdZjaXDw1buD/xS qMoZqeGK8ic+iBSfdws32An4T2uG5vhTMF8LNvCx5krf/zrvOkHTYsIMJ8Hx7S5cc4tQ vewKzLucTpSzfKQ1OapfNF3jJbhcA4Z3Y3lFVwzNRed237nOTsVjdUj3uzQJIOvaz5Ux HtVQ== X-Gm-Message-State: AKS2vOyhTNvo1VxScB645g88krMGh6T8gNSZ7iNSObElQ3w7zkCRHTrA BncOPDR5DRdUvJOufk4= X-Received: by 10.223.169.145 with SMTP id b17mr3899006wrd.179.1498579905760; Tue, 27 Jun 2017 09:11:45 -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 v13sm4080465wmd.5.2017.06.27.09.11.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Jun 2017 09:11:45 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck , Gaetan Rivet Date: Tue, 27 Jun 2017 18:11:18 +0200 Message-Id: <31642876d2825d666c5722b05b531150516f8212.1498577192.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v6 11/11] dev: use new hotplug API in attach / detach 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, 27 Jun 2017 16:11:47 -0000 From: Jan Blunck This new generic API allows attach and detach to be compatible with all buses supporting hotplug. Signed-off-by: Jan Blunck Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_dev.c | 92 ++++++++++++++++++++++++++-------- 1 file changed, 70 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..19508e6 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,97 @@ #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 1; + 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(cmp_detached_dev_name, name, NULL); + if (dev) { + struct rte_bus *bus; - } else { - if (rte_vdev_init(name, devargs)) - goto err; + 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->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; +} -err: - RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", name); - return -EINVAL; +static int cmp_dev_name(const struct rte_device *dev, const void *_name) +{ + const char *name = _name; + + 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(cmp_dev_name, name, NULL); + 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