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 3F171C6E2 for ; Fri, 29 Jan 2016 15:49:25 +0100 (CET) Received: by mail-wm0-f51.google.com with SMTP id p63so71752814wmp.1 for ; Fri, 29 Jan 2016 06:49:25 -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=fL1MwXZ5ygczITvwex6IaXJRKQ8LyAvl8/9OFW9I4Ns=; b=RmgzC9R57MNibqrywSO64RvwoKg+aaXqmnyj8IY1Q9Vgrz4sJvfQ5jqErqXvTyraaX UNTLzi50rc3DyUXV5UUwD1pPc453T4BPdLE6ONIogIxWg6Z1AJSFBsxJrWfkNexrygXT TJ9mh+WdKE94YZo6GoErV1d+mAyh1NXXFRCbsIfHn//sH5b9HfwCOFzsFOghpfSXvkO4 Qpl7QwNTlrSKnA2c3aMm1ORcgTVREz3lZL1I3eC6Xo+/auINVHBRB7qSj1/zQUOYuI+6 UjPaL7ztxa9R/wU6PXZofx/FNUsMxzFh+6D57zy8x9aMCcp8sbgDQSLl78CCA9P/Wo0+ zjMA== 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=fL1MwXZ5ygczITvwex6IaXJRKQ8LyAvl8/9OFW9I4Ns=; b=fdu27dAmTVx4gjhxx9hGI/VqzG2va0nsN6k6uELlsOo7Hx1zyAjC0f4bY+Doxxf1mR kt9bEQsb81KrEd5dODxIY+r1oEn0Tqg4460oWrjH3LzEHQwFN3U9dcbiBJxGwZh8K5v6 iGgIhKZQIFGHB0DwW3yS5ccfKXRDN68AzNk08Ax8FyyHv6XUVZpCwFoIXx8tKmkpyj6F CwR0uCkUxKkxsrI9rDi5eh+VVnx0XJ6AY1HkJp/QKYudC3pCHHCmTO5qqlLSZ81HNruJ SFkvQICqUN87sztQNwj49/JZDf5iuSOqXjbvh4IBCCUZWuCxWo+83hUtcmYdMpYKGQ0R h1qA== X-Gm-Message-State: AG10YORddiUHvDOpl0x7JTtPf9vQKaqwrtJ4w0ny8b1ImMU4Z8svugE8hChY7cScFVUVWe67 X-Received: by 10.194.242.2 with SMTP id wm2mr9279579wjc.155.1454078965073; Fri, 29 Jan 2016 06:49:25 -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.24 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 29 Jan 2016 06:49:24 -0800 (PST) From: David Marchand To: dev@dpdk.org Date: Fri, 29 Jan 2016 15:49:10 +0100 Message-Id: <1454078953-23744-7-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 6/9] pci: factorize driver search 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:25 -0000 Same idea as a few commits before, no need to implement the same logic in probe and detach functions. Here, the driver matching is done by a helper, then probe / detach functions are called respectively. Signed-off-by: David Marchand --- lib/librte_eal/common/eal_common_pci.c | 96 ++++++++++++---------------------- 1 file changed, 34 insertions(+), 62 deletions(-) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index fd88305..768421a 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -280,55 +280,16 @@ pci_detach_device(struct rte_pci_driver *dr, struct rte_pci_device *dev) return 0; } -/* - * If vendor/device ID match, call the devinit() function of all - * registered driver for the given device. Return -1 if initialization - * failed, return 1 if no driver is found for this device. - */ -static int -pci_probe_all_drivers(struct rte_pci_device *dev) -{ - struct rte_pci_driver *dr = NULL; - int rc = 0; - - TAILQ_FOREACH(dr, &pci_driver_list, next) { - if (!pci_driver_supports_device(dr, dev)) - continue; - - rc = pci_probe_device(dr, dev); - if (rc < 0) - /* negative value is an error */ - return -1; - if (rc > 0) - /* positive value means device is blacklisted */ - continue; - return 0; - } - return 1; -} - -/* - * If vendor/device ID match, call the devuninit() function of all - * registered driver for the given device. Return -1 if initialization - * failed, return 1 if no driver is found for this device. - */ -static int -pci_detach_all_drivers(struct rte_pci_device *dev) +static struct rte_pci_driver * +pci_find_driver(struct rte_pci_device *dev) { - struct rte_pci_driver *dr = NULL; - int rc = 0; + struct rte_pci_driver *dr; TAILQ_FOREACH(dr, &pci_driver_list, next) { - if (!pci_driver_supports_device(dr, dev)) - continue; - - rc = pci_detach_device(dr, dev); - if (rc < 0) - /* negative value is an error */ - return -1; - return 0; + if (pci_driver_supports_device(dr, dev)) + break; } - return 1; + return dr; } /* @@ -338,8 +299,8 @@ pci_detach_all_drivers(struct rte_pci_device *dev) int rte_eal_pci_probe_one(const struct rte_pci_addr *addr) { - struct rte_pci_device *dev = NULL; - int ret = 0; + struct rte_pci_device *dev; + struct rte_pci_driver *dr; if (addr == NULL) return -1; @@ -353,8 +314,11 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr) if (!dev) goto err_return; - ret = pci_probe_all_drivers(dev); - if (ret < 0) + dr = pci_find_driver(dev); + if (!dr) + goto err_return; + + if (pci_probe_device(dr, dev) < 0) goto err_return; return 0; @@ -372,8 +336,8 @@ err_return: int rte_eal_pci_detach(const struct rte_pci_addr *addr) { - struct rte_pci_device *dev = NULL; - int ret = 0; + struct rte_pci_device *dev; + struct rte_pci_driver *dr; if (addr == NULL) return -1; @@ -382,8 +346,11 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr) if (!dev) goto err_return; - ret = pci_detach_all_drivers(dev); - if (ret < 0) + dr = pci_find_driver(dev); + if (!dr) + goto err_return; + + if (pci_detach_device(dr, dev) < 0) goto err_return; TAILQ_REMOVE(&pci_device_list, dev, next); @@ -404,28 +371,33 @@ err_return: int rte_eal_pci_probe(void) { - struct rte_pci_device *dev = NULL; + struct rte_pci_device *dev; + struct rte_pci_driver *dr; struct rte_devargs *devargs; int probe_all = 0; - int ret = 0; if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) == 0) probe_all = 1; TAILQ_FOREACH(dev, &pci_device_list, next) { + /* no driver available */ + dr = pci_find_driver(dev); + if (!dr) + continue; + /* set devargs in PCI structure */ devargs = pci_devargs_lookup(dev); if (devargs != NULL) dev->devargs = devargs; - /* probe all or only whitelisted devices */ - if (probe_all) - ret = pci_probe_all_drivers(dev); - else if (devargs != NULL && - devargs->type == RTE_DEVTYPE_WHITELISTED_PCI) - ret = pci_probe_all_drivers(dev); - if (ret < 0) + /* skip if not probing all and device is not whitelisted */ + if (!probe_all && + (devargs == NULL || + devargs->type != RTE_DEVTYPE_WHITELISTED_PCI)) + continue; + + if (pci_probe_device(dr, dev) < 0) rte_exit(EXIT_FAILURE, "Requested device " PCI_PRI_FMT " cannot be used\n", dev->addr.domain, dev->addr.bus, dev->addr.devid, dev->addr.function); -- 1.9.1