From patchwork Thu Nov 20 09:06:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuya Mukawa X-Patchwork-Id: 1386 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 8B0A6805D; Thu, 20 Nov 2014 09:57:51 +0100 (CET) Received: from mail-pd0-f170.google.com (mail-pd0-f170.google.com [209.85.192.170]) by dpdk.org (Postfix) with ESMTP id D0E69804C for ; Thu, 20 Nov 2014 09:57:46 +0100 (CET) Received: by mail-pd0-f170.google.com with SMTP id fp1so2691786pdb.15 for ; Thu, 20 Nov 2014 01:08:15 -0800 (PST) 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=2qQyPYOXdWSNgqA2XYgczClyRV2U3WS91ILml0M9JCc=; b=DbSq2NDVWih6ZDyk0r9nEDOoxtlEJl0a3aKP4J/+xhtgcCPj+yQpGy5n+virgku6Oi AaUjwkL/mNqWsxsc39VuzzTHJZAL4Uixg+9zBok4Gg95dd3DFYM3qquz2gZEuY23P1Zu XsB6GKUmV/vh+R/bAGgKxJsIC989n64F35luZH7aTM3fpawV72ghOuNy/98eSWycLHNL ulqk9pnoVsPIB/e3MS63FMHcsXA3y6WQY2lGJ8L3zJL537zhTjdmFo4+lYTyNyWEA99x QbIWQ9vweFhEGOeLD2GpRx695601whQT50pE7cmb2NR2hXIeGPf8qfMxkqXaUWfeRunS g5EA== X-Gm-Message-State: ALoCoQmAILQQHJ4f80rykH9nHwM0qCxQL+I9RMiKxc/fPnTNkCy7K+xfkXWkHjOEFKz/5kByMKr6 X-Received: by 10.68.234.202 with SMTP id ug10mr28494509pbc.134.1416474495640; Thu, 20 Nov 2014 01:08:15 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id a6sm1432407pbu.64.2014.11.20.01.08.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Nov 2014 01:08:15 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Thu, 20 Nov 2014 18:06:37 +0900 Message-Id: <1416474399-16851-24-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416474399-16851-1-git-send-email-mukawa@igel.co.jp> References: <1414572576-21371-1-git-send-email-mukawa@igel.co.jp> <1416474399-16851-1-git-send-email-mukawa@igel.co.jp> Cc: nakajima.yoshihiro@lab.ntt.co.jp, menrigh@brocade.com, masutani.hitoshi@lab.ntt.co.jp Subject: [dpdk-dev] [PATCH 23/25] eal/pci: Add rte_eal_pci_probe_one and rte_eal_pci_close_one 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The functions are used for probe and close a device. First the function tries to find a device that has the specfied PCI address. Then, probe or close the device. Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/common/eal_common_pci.c | 58 +++++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_pci.h | 26 +++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index b404ee0..5ff7b49 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -152,6 +152,64 @@ pci_close_all_drivers(struct rte_pci_device *dev) { return pci_invoke_all_drivers(dev, INVOKE_CLOSE); } + +static int +rte_eal_pci_invoke_one(struct rte_pci_addr *addr, int type) +{ + struct rte_pci_device *dev = NULL; + int ret = 0; + + TAILQ_FOREACH(dev, &pci_device_list, next) { + if (eal_compare_pci_addr(&dev->addr, addr)) + continue; + + switch (type) { + case INVOKE_PROBE: + ret = pci_probe_all_drivers(dev); + break; + case INVOKE_CLOSE: + ret = pci_close_all_drivers(dev); + break; + } + if (ret < 0) + goto invoke_err_return; + if (type == INVOKE_CLOSE) + goto remove_dev; + return 0; + } + + return -1; + +invoke_err_return: + RTE_LOG(WARNING, EAL, "Requested device " PCI_PRI_FMT + " cannot be used\n", dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); + return -1; + +remove_dev: + TAILQ_REMOVE(&pci_device_list, dev, next); + return 0; +} + +/* + * Find the pci device specified by pci address, then invoke probe function of + * the driver of the devive. + */ +int +rte_eal_pci_probe_one(struct rte_pci_addr *addr) +{ + return rte_eal_pci_invoke_one(addr, INVOKE_PROBE); +} + +/* + * Find the pci device specified by pci address, then invoke close function of + * the driver of the devive. + */ +int +rte_eal_pci_close_one(struct rte_pci_addr *addr) +{ + return rte_eal_pci_invoke_one(addr, INVOKE_CLOSE); +} #endif /* RTE_LIBRTE_EAL_HOTPLUG & RTE_LIBRTE_EAL_LINUXAPP */ /* diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 74720d1..33300be 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -311,6 +311,32 @@ eal_compare_pci_addr(struct rte_pci_addr *addr, struct rte_pci_addr *addr2) int rte_eal_pci_probe(void); /** + * Probe the single PCI device. + * + * Scan the content of the PCI bus, and find the pci device specified by pci + * addrrss, then call the probe() function for registered driver that has a + * matching entry in its id_table for discovered device. + * + * @return + * - 0 on success. + * - Negative on error. + */ +int rte_eal_pci_probe_one(struct rte_pci_addr *addr); + +/** + * Close the single PCI device. + * + * Scan the content of the PCI bus, and find the pci device specified by pci + * addrrss, then call the close() function for registered driver that has a + * matching entry in its id_table for discovered device. + * + * @return + * - 0 on success. + * - Negative on error. + */ +int rte_eal_pci_close_one(struct rte_pci_addr *addr); + +/** * Dump the content of the PCI bus. * * @param f