From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by dpdk.org (Postfix) with ESMTP id 033AC7CBD for ; Thu, 29 Jun 2017 20:22:44 +0200 (CEST) Received: by mail-wm0-f66.google.com with SMTP id j85so4072656wmj.0 for ; Thu, 29 Jun 2017 11:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Mscqc2N9TEZmpzNcjr/tFzYAPLYDV4E+eTagtzf6GSU=; b=r2xecpabIKB03skONzdEaJwFnaYrDabVwySLZMifGtyJ20FgD3otsi2yFW6nqQP6XS B/ObEues2R26M5tdNFd2zGOjOTAj7hVBk3UzfGSRN882l/3hJ1z1jZls5Psqw1G59VVn TyS2tmbbPKYknGztJvTP3gF5J9e573sY3rgNfPK7gG0txPngDlpcJR0Jih1ceNQ/JNhe prlHmMQrEp0M4S6/ajezXZb1oTQ8b/6SCCfZsR93eHqyfNSE0Jq1+8X3sfvs9NJRudaj Tn0wR2AXj914GT9Xb427tBkZvm5/Vm0SLTijRCLGpleqyF7A22I3f3fVJ/j1uYPX+Wsh 1Igw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Mscqc2N9TEZmpzNcjr/tFzYAPLYDV4E+eTagtzf6GSU=; b=J+XKpVPmoJQ+k7AXoVcZ/Y3VJnNTloGyuGeu/X1ydElTsRe+jZNUgmdkuIt5K3hqWN es3LeZnkuTIvIInOMij/m0Dz7eA/IgXbrcvbAgAEVdNTlFQuh3Vw6xghWR3W3lZYZ2+l nKjxcpErQnq0C+0LRx9dE5f/kAcN82BjnckzCDZ6DhgEAhThgeiA8fQNWy+44P5vKFzG qvUq86Wf4GA/3XmGKrm8TFfQf46HsuCrpQMJ9PM84yCpfcXkDNkecdK/tSr0Svk8nXdM h2lLEqGCIR5Jc3XJoUr1Eyc7HUOblfREZKTjeP32ldk4KJJOTXZF5JjheP7rhtXaeCdO dSSg== X-Gm-Message-State: AKS2vOx6vRRUCrSbn/aHpSWOHtFENnztRuKRvrjmOp5bNyjNEEFTyhfG XA3bZpg4CTsndqsG X-Received: by 10.80.185.3 with SMTP id m3mr2642691ede.41.1498760563604; Thu, 29 Jun 2017 11:22:43 -0700 (PDT) Received: from weierstrass.local ([91.200.110.13]) by smtp.gmail.com with ESMTPSA id e28sm1446366ede.14.2017.06.29.11.22.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 11:22:42 -0700 (PDT) Sender: Jan Blunck From: Jan Blunck To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, shreyansh.jain@nxp.com Date: Thu, 29 Jun 2017 20:22:05 +0200 Message-Id: <20170629182206.1072-15-jblunck@infradead.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170629182206.1072-1-jblunck@infradead.org> References: <20170629182206.1072-1-jblunck@infradead.org> Subject: [dpdk-dev] [PATCH v7 14/15] 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: Thu, 29 Jun 2017 18:22:44 -0000 Using the new generic API allows attach and detach to be backwards compatible while decoupling from the concrete bus implementations. Signed-off-by: Jan Blunck --- lib/librte_eal/common/eal_common_dev.c | 76 ++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 23 deletions(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 477b4cf..68c6b45 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,52 +46,81 @@ #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; + 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; + ret = rte_eal_hotplug_add("PCI", name, devargs); + if (ret && ret != -EINVAL) + return ret; - } else { - if (rte_vdev_init(name, devargs)) - goto err; - } + /* + * If we haven't found a bus device the user meant to "hotplug" a + * virtual device instead. + */ + ret = rte_vdev_init(name, devargs); + if (ret) + RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", + name); + return ret; +} - return 0; +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; } int rte_eal_hotplug_add(const char *busname, const char *devname, -- 2.9.4