From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f173.google.com (mail-wr0-f173.google.com [209.85.128.173]) by dpdk.org (Postfix) with ESMTP id B5A407CAE for ; Mon, 26 Jun 2017 02:22:38 +0200 (CEST) Received: by mail-wr0-f173.google.com with SMTP id c11so131616398wrc.3 for ; Sun, 25 Jun 2017 17:22:38 -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=GOYpvSIZhzX/z9ggbpe/F0KTDPgK8qjke+mD8F2kBFU=; b=kGttx0IoTKhKB7PorYpJsYDEyhJdRONJV1hj6dA+kL08ylh1p4uraFPEQKqMgMOwsO cE2ki9mnmc7JM0RqQhlLVSvB0OmG0aa80tqsubF7LeAOwkSHgPrCokhFfHpwEeB89GER gNrkplGQ2KBEzQMH6eogSBnAXrofufbuX06a+ososCgaxUqSuq8BH3kkyzaLgPMPMZ+a C6wMRoBgpNSnfZc3oJtEBCduJ9aem67ZIjnq0ZCj2hbQ8sWK8bK3lvnEl3dWgM1XPTQn 5nxV3gYIuyttfOHFKrHa7IzfjG5M9KpYGl8u08aj5shsAEMbCsedry2NjQddMoQJ+7ly M4Lg== 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=GOYpvSIZhzX/z9ggbpe/F0KTDPgK8qjke+mD8F2kBFU=; b=Fdqb3nJanufu0EYvLVYy1Deyt1PUrPhBM1LY4k8C9zilYDYrhxKg2+WhV/uY06jCUT Fu3BoWdK8769GQglEpa8dZxAbWPTuxjbEt/MAX6uiepQGzDb+euU7rjtx2ApRCbZESV6 8zo4cxcfC7HYJF3/5+FBgcV0uNbS1pqanyfGzyDEMyVQL6quY9Mh3UADySCZecErMiwG h985+kQCU8MBCKcOamDhShk0KURwRzR8BAL4sB+0vQsSvP/qAitRgqcl+QuEK557TyH7 urs1msXFw8UDKwybAHoMHr3NHXuI6DPDXcLEc3kPYQFIXdmjCNB//b5VdINjXAwMWjIl T2Mw== X-Gm-Message-State: AKS2vOzfBAun8gig/0G9JeamOgv4i5dVfkHZRzdS4M1yTjLteDMursDK xYB8FMXU9/Lcf7aX+ek= X-Received: by 10.28.135.16 with SMTP id j16mr10993444wmd.77.1498436558195; Sun, 25 Jun 2017 17:22:38 -0700 (PDT) Received: from bidouze.dev.6wind.com ([62.23.145.78]) by smtp.gmail.com with ESMTPSA id 19sm16061626wrx.26.2017.06.25.17.22.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 25 Jun 2017 17:22:37 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck , Gaetan Rivet Date: Mon, 26 Jun 2017 02:22:10 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v5 12/12] 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: Mon, 26 Jun 2017 00:22:39 -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..d83ae41 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(cmp_detached_dev_name, name, NULL); + 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(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