From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by dpdk.org (Postfix) with ESMTP id 70C47C6E8 for ; Fri, 29 Jan 2016 15:49:27 +0100 (CET) Received: by mail-wm0-f51.google.com with SMTP id 128so55990473wmz.1 for ; Fri, 29 Jan 2016 06:49:27 -0800 (PST) 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; bh=FKGPYp8SXjVj+CGTDpbmFzxg7KTW74xVFQVMK9QGSDg=; b=syf0B31ofwSd+p55Gzd8tL13m30eqOU3IuFhV4kQVEngNL5Yr/rkvkbykpGicU/XJ3 Y8sfbErnn8Ngzd+y1L2e2540NAnrogumYXppFLzzKNPQwJYe6nkq9/fVMxCT22u8kqDE rhmaL+5WYVII+xRSgIqzL6pISiXKFjR51n/pFVcgWsWwvJ1Ngbcxjacm8NQABNaZIzjF 8ACiULQCz9MeshNeqc4jKerUyOKm74iS9w7d0G3GBGsnOTsseUQw4SiJDFuxIUIA5Maz R1yCWuu5ZXpJfJXBsqBaqVp6YMhQNabY9lRrrndZCqWpw6AXe9BMvd8hlwE2zx6L3C4e ydeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FKGPYp8SXjVj+CGTDpbmFzxg7KTW74xVFQVMK9QGSDg=; b=dY7ExJBjAF7ZQjLhIhrx19hdl61LGCqz37/4tGwfflSQ3jsqpn0sPMxKPNRHFwVoxa 2ZzGUgV9xghGlqzUUIrmCxSxHvkEMU0QH/DwHkLTFIPh6kio5BPU0yT7JyBuTk8phlQl Xq/xIZA6kVheBt3+1BuhXtFmZ7/vmfCzKu7stOP9xKMSsfnUDltw1gd7O9Rbkbx7hR0I +Dd3kLAtgtJiYhb3tINtEBL+3QtaceKsIRGWZbbifKNLP0ENV8CPE4ynDQoOUnWAKAPe Fw1/NuCuj/E6iH2CJQvHafesZXJkNnpkFZh5rq5abGG7X65I9q9VaYXvUKc9Y87G61tl gHTA== X-Gm-Message-State: AG10YOQO2xItwVuu5pTMk8+AhM+zCOzJh8OWYF33hY5EQnu2mThmiYAJTWGLj5mceGG3wBY/ X-Received: by 10.28.179.84 with SMTP id c81mr9526756wmf.30.1454078967334; Fri, 29 Jan 2016 06:49:27 -0800 (PST) Received: from gloops.dev.6wind.com (144.77.126.78.rev.sfr.net. [78.126.77.144]) by smtp.gmail.com with ESMTPSA id y188sm7811294wmy.11.2016.01.29.06.49.26 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 29 Jan 2016 06:49:26 -0800 (PST) From: David Marchand To: dev@dpdk.org Date: Fri, 29 Jan 2016 15:49:12 +0100 Message-Id: <1454078953-23744-9-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1454078953-23744-1-git-send-email-david.marchand@6wind.com> References: <1453476464-31767-1-git-send-email-david.marchand@6wind.com> <1454078953-23744-1-git-send-email-david.marchand@6wind.com> Cc: viktorin@rehivetech.com Subject: [dpdk-dev] [PATCH v2 8/9] pci: implement blacklist using a hook X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jan 2016 14:49:27 -0000 The idea is to prepare a generic hook system for all bus, but I am still unsure if this approach will be the right one, hence, keeping this as private for now. Here, blacklisting policy is removed from pci scan code, making it possible to override it later by the application (once the api is judged generic and good enough). With this, blacklist evaluation moves to rte_eal_pci_probe() only. This way, rte_eal_pci_probe_one() (used by hotplug when attaching) now accepts to probe devices that were blacklisted initially. A new debug trace is added when skipping a device not part of a given whitelist. Signed-off-by: David Marchand --- lib/librte_eal/common/eal_common_pci.c | 101 +++++++++++++++++++++++++-------- 1 file changed, 77 insertions(+), 24 deletions(-) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 082eab8..4a0ec73 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -87,6 +87,62 @@ struct pci_driver_list pci_driver_list = struct pci_device_list pci_device_list = TAILQ_HEAD_INITIALIZER(pci_device_list); +enum rte_eal_pci_hook { + RTE_EAL_PCI_SCAN, +}; + +enum rte_eal_pci_hook_return { + RTE_EAL_PCI_HOOK_OK, + RTE_EAL_PCI_HOOK_ERROR, + RTE_EAL_PCI_HOOK_SKIP, +}; + +typedef int (rte_eal_pci_hook_t)(enum rte_eal_pci_hook, + struct rte_pci_driver *, + struct rte_pci_device *); + +static int +blacklist_pci_hook(enum rte_eal_pci_hook h, + struct rte_pci_driver *dr __rte_unused, + struct rte_pci_device *dev) +{ + int ret; + + switch (h) { + case RTE_EAL_PCI_SCAN: + { + int whitelist = + rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI); + int blacklist = + rte_eal_devargs_type_count(RTE_DEVTYPE_BLACKLISTED_PCI); + + /* + * We want to probe this device when: + * - there is no whitelist/blacklist, + * - there is a whitelist, and device is part of it, + * - there is a blacklist, and device is not part of it. + */ + if (whitelist && !dev->devargs) { + RTE_LOG(DEBUG, EAL, " Device is not whitelisted, not initializing\n"); + ret = RTE_EAL_PCI_HOOK_SKIP; + } else if (blacklist && dev->devargs) { + RTE_LOG(DEBUG, EAL, " Device is blacklisted, not initializing\n"); + ret = RTE_EAL_PCI_HOOK_SKIP; + } else + ret = RTE_EAL_PCI_HOOK_OK; + break; + } + default: + /* nothing to do here, just say ok */ + ret = RTE_EAL_PCI_HOOK_OK; + break; + } + + return ret; +} + +static rte_eal_pci_hook_t *pci_hook = &blacklist_pci_hook; + static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev) { struct rte_devargs *devargs; @@ -209,22 +265,10 @@ static int pci_probe_device(struct rte_pci_driver *dr, struct rte_pci_device *dev) { int ret; - struct rte_pci_addr *loc = &dev->addr; - - RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", - loc->domain, loc->bus, loc->devid, loc->function, - dev->numa_node); RTE_LOG(DEBUG, EAL, " probe driver: %x:%x %s\n", dev->id.vendor_id, dev->id.device_id, dr->name); - /* no initialization when blacklisted, return without error */ - if (dev->devargs != NULL && - dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) { - RTE_LOG(DEBUG, EAL, " Device is blacklisted, not initializing\n"); - return 1; - } - if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) { #ifdef RTE_PCI_CONFIG /* @@ -310,6 +354,11 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr) if (!dev) goto err_return; + RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", + dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function, + dev->numa_node); + dr = pci_find_driver(dev); if (!dr) goto err_return; @@ -369,27 +418,31 @@ rte_eal_pci_probe(void) struct rte_pci_device *dev; struct rte_pci_driver *dr; struct rte_devargs *devargs; - int probe_all = 0; - - if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) == 0) - probe_all = 1; + int ret; TAILQ_FOREACH(dev, &pci_device_list, next) { - /* no driver available */ - dr = pci_find_driver(dev); - if (!dr) - continue; + RTE_LOG(DEBUG, EAL, + "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", + dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function, + dev->numa_node); /* set devargs in PCI structure */ devargs = pci_devargs_lookup(dev); if (devargs != NULL) dev->devargs = devargs; - /* skip if not probing all and device is not whitelisted */ - if (!probe_all && - (devargs == NULL || - devargs->type != RTE_DEVTYPE_WHITELISTED_PCI)) + ret = pci_hook(RTE_EAL_PCI_SCAN, NULL, dev); + if (ret != RTE_EAL_PCI_HOOK_OK) { + RTE_LOG(DEBUG, EAL, " scan hook refused dev, err=%d\n", + ret); + continue; + } + + /* no driver available */ + dr = pci_find_driver(dev); + if (!dr) continue; if (pci_probe_device(dr, dev) < 0) -- 1.9.1