From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-f51.google.com (mail-wg0-f51.google.com [74.125.82.51]) by dpdk.org (Postfix) with ESMTP id EDED8AFE1 for ; Mon, 28 Apr 2014 15:19:59 +0200 (CEST) Received: by mail-wg0-f51.google.com with SMTP id z12so5196758wgg.10 for ; Mon, 28 Apr 2014 06:20:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=L3vA4R55NHVDf7RrMjiNMY8zhwKdu/GezMTkdbfm8I8=; b=C5teYYemzCU3uKpN20MJLt1KloAz7rfmPjiF9NPTPpQzPuiLiu+ohuSYeqBbHqPjvL kSM5xVuAiJ2/xe47uCqnomjLe8kufTdDCS63nNUaD/mmM63FyHeZTv2COzagm9FyeB4Y Rc1nlSrLSbytUzqVOrCA1neAm5PCMnCUNVD9NvH/Jc93gEH3WYIGfPKPU2aeh8JpNyn2 KxQw3wDHW6YH5/nZld29XvpTEWVTJc21SXLMfXvyU7v9wRq1xW6+CcpcZ/ks8imNTgQx fPPvpQXkAw77T5EIRxVvoSFust4jSfDmQ0Igwdbu3VFu22gmMSdv2B5skVukQtvdpoSb d4ig== X-Gm-Message-State: ALoCoQk9n9jmMmJOSaOaAzIBt+7vqK6KRLkFIAyPUJnyguZz1E2ZtMVLpxd2DISpRNw14vHxsEUq X-Received: by 10.194.63.46 with SMTP id d14mr2484923wjs.24.1398691203564; Mon, 28 Apr 2014 06:20:03 -0700 (PDT) Received: from alcyon.dev.6wind.com (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id ej7sm17746555wib.9.2014.04.28.06.20.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Apr 2014 06:20:02 -0700 (PDT) From: David Marchand To: dev@dpdk.org Date: Mon, 28 Apr 2014 15:19:46 +0200 Message-Id: <1398691187-4918-7-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1398691187-4918-1-git-send-email-david.marchand@6wind.com> References: <1398691187-4918-1-git-send-email-david.marchand@6wind.com> Subject: [dpdk-dev] [PATCH 6/7] pci: move RTE_PCI_DRV_FORCE_UNBIND handling out of #ifdef 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: Mon, 28 Apr 2014 13:20:00 -0000 Move RTE_PCI_DRV_FORCE_UNBIND flag handling out of RTE_EAL_UNBIND_PORTS section. This had nothing to do with RTE_EAL_UNBIND_PORTS anyway. Signed-off-by: David Marchand --- lib/librte_eal/linuxapp/eal/eal_pci.c | 89 ++++++++++++++++----------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index db1fb3f..c21b270 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -107,6 +107,45 @@ TAILQ_HEAD(uio_res_list, uio_resource); static struct uio_res_list *uio_res_list = NULL; static int pci_parse_sysfs_value(const char *filename, uint64_t *val); +/* unbind kernel driver for this device */ +static int +pci_unbind_kernel_driver(struct rte_pci_device *dev) +{ + int n; + FILE *f; + char filename[PATH_MAX]; + char buf[BUFSIZ]; + struct rte_pci_addr *loc = &dev->addr; + + /* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */ + rte_snprintf(filename, sizeof(filename), + SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/driver/unbind", + loc->domain, loc->bus, loc->devid, loc->function); + + f = fopen(filename, "w"); + if (f == NULL) /* device was not bound */ + return 0; + + n = rte_snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n", + loc->domain, loc->bus, loc->devid, loc->function); + if ((n < 0) || (n >= (int)sizeof(buf))) { + RTE_LOG(ERR, EAL, "%s(): rte_snprintf failed\n", __func__); + goto error; + } + if (fwrite(buf, n, 1, f) == 0) { + RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__, + filename); + goto error; + } + + fclose(f); + return 0; + +error: + fclose(f); + return -1; +} + #ifdef RTE_EAL_UNBIND_PORTS #define PROC_MODULES "/proc/modules" @@ -234,46 +273,6 @@ pci_uio_bind_device(struct rte_pci_device *dev, const char *module_name) return 0; } -/* unbind kernel driver for this device */ -static int -pci_unbind_kernel_driver(struct rte_pci_device *dev) -{ - int n; - FILE *f; - char filename[PATH_MAX]; - char buf[BUFSIZ]; - struct rte_pci_addr *loc = &dev->addr; - - /* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */ - rte_snprintf(filename, sizeof(filename), - SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/driver/unbind", - loc->domain, loc->bus, loc->devid, loc->function); - - f = fopen(filename, "w"); - if (f == NULL) /* device was not bound */ - return 0; - - n = rte_snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n", - loc->domain, loc->bus, loc->devid, loc->function); - if ((n < 0) || (n >= (int)sizeof(buf))) { - RTE_LOG(ERR, EAL, "%s(): rte_snprintf failed\n", __func__); - goto error; - } - if (fwrite(buf, n, 1, f) == 0) { - RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__, - filename); - goto error; - } - - fclose(f); - return 0; - -error: - fclose(f); - return -1; -} - - static int pci_switch_module(struct rte_pci_driver *dr, struct rte_pci_device *dev, const char *module_name) @@ -1006,11 +1005,6 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d /* unbind current driver and bind on igb_uio */ if (pci_switch_module(dr, dev, IGB_UIO_NAME) < 0) return -1; - } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND && - rte_eal_process_type() == RTE_PROC_PRIMARY) { - /* unbind current driver */ - if (pci_unbind_kernel_driver(dev) < 0) - return -1; } #endif @@ -1018,6 +1012,11 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d /* map resources for devices that use igb_uio */ if (pci_uio_map_resource(dev) < 0) return -1; + } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND && + rte_eal_process_type() == RTE_PROC_PRIMARY) { + /* unbind current driver */ + if (pci_unbind_kernel_driver(dev) < 0) + return -1; } /* reference driver structure */ -- 1.7.10.4