From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pd0-f175.google.com (mail-pd0-f175.google.com [209.85.192.175]) by dpdk.org (Postfix) with ESMTP id AACA6374C for ; Sat, 11 Jul 2015 08:30:07 +0200 (CEST) Received: by pdrg1 with SMTP id g1so63416203pdr.2 for ; Fri, 10 Jul 2015 23:30:07 -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:cc:subject:date:message-id:in-reply-to :references; bh=McjPAupcA7yBLBjKqj4d7BBei40Lw3tGUTtJKG8JP4s=; b=CtsweXa1RpCgOcKmVMij8gnYdGnZPbkL65BG1Znnj56eQsoJC84o8x0M/YX2dtS/Ey OzHGAuknShCHVM3ZD8eA+zkWHLXwkH4jOKjpJgBDgHRlTeVhtcDj65mocAvsjyZbYWld sgPbSedDIdlM4NNc2BMSGY4M7P1kVwH14NqnTQz6xTemdgMckRQ0Jh4mqu4H9q2L1QsF d5EWrDQk3zn6dHWCmEUaXBE/5mDjvjUhjnz71EcqXpURP/f5Ja6BBfga8ihrPGOO67b3 /uzFBMXuFTp6St8QpqIjTLorxIzrayGwG4Xu0xLUwGQhNwXgsQ5Rl92XHAYuNzQaiaSR hVGA== X-Gm-Message-State: ALoCoQlXb5z+tirwweUet5L2rmjj+4PArCmPL7DGdDIfx8re4k4ahSIqlO+tAm1KfivcPX+MXayu X-Received: by 10.70.49.43 with SMTP id r11mr48382835pdn.91.1436596207000; Fri, 10 Jul 2015 23:30:07 -0700 (PDT) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id pq3sm11274146pbb.24.2015.07.10.23.30.04 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 10 Jul 2015 23:30:06 -0700 (PDT) From: Tetsuya Mukawa To: dev@dpdk.org Date: Sat, 11 Jul 2015 15:29:49 +0900 Message-Id: <1436596189-1831-1-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1436514439-4893-1-git-send-email-michael.qiu@intel.com> References: <1436514439-4893-1-git-send-email-michael.qiu@intel.com> Subject: [dpdk-dev] [PATCH] eal: fix vfio device never works. 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: Sat, 11 Jul 2015 06:30:08 -0000 The patch fixes vfio initialization issue introduced by below patch. - Commit 35b3313e322b ("pci: merge mapping functions for linux and bsd") Root cause is that VFIO_PRESENT is inaccessible in eal common level. To fix it, remove pci_map/unmap_device from common code, then implement in linux and bsd code. Reported-by: Michael Qiu Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/bsdapp/eal/eal_pci.c | 39 ++++++++++++++++++++++++ lib/librte_eal/common/eal_common_pci.c | 55 ---------------------------------- lib/librte_eal/common/eal_private.h | 18 +++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 50 +++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 55 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 12f39d9..ed31222 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -92,6 +92,45 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused) return -ENOTSUP; } +/* Map pci device */ +int +pci_map_device(struct rte_pci_device *dev) +{ + int ret = -1; + + /* try mapping the NIC resources */ + switch (dev->kdrv) { + case RTE_KDRV_NIC_UIO: + /* map resources for devices that use uio */ + ret = pci_uio_map_resource(dev); + break; + default: + RTE_LOG(DEBUG, EAL, + " Not managed by a supported kernel driver, skipped\n"); + ret = 1; + break; + } + + return ret; +} + +/* Unmap pci device */ +void +pci_unmap_device(struct rte_pci_device *dev) +{ + /* try unmapping the NIC resources */ + switch (dev->kdrv) { + case RTE_KDRV_NIC_UIO: + /* unmap resources for devices that use uio */ + pci_uio_unmap_resource(dev); + break; + default: + RTE_LOG(DEBUG, EAL, + " Not managed by a supported kernel driver, skipped\n"); + break; + } +} + void pci_uio_free_resource(struct rte_pci_device *dev, struct mapped_pci_resource *uio_res) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 3805aed..60e40e0 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -137,61 +137,6 @@ pci_unmap_resource(void *requested_addr, size_t size) requested_addr); } -/* Map pci device */ -static int -pci_map_device(struct rte_pci_device *dev) -{ - int ret = -1; - - /* try mapping the NIC resources using VFIO if it exists */ - switch (dev->kdrv) { - case RTE_KDRV_VFIO: -#ifdef VFIO_PRESENT - if (pci_vfio_is_enabled()) - ret = pci_vfio_map_resource(dev); -#endif - break; - case RTE_KDRV_IGB_UIO: - case RTE_KDRV_UIO_GENERIC: - case RTE_KDRV_NIC_UIO: - /* map resources for devices that use uio */ - ret = pci_uio_map_resource(dev); - break; - default: - RTE_LOG(DEBUG, EAL, " Not managed by a supported kernel driver," - " skipped\n"); - ret = 1; - break; - } - - return ret; -} - -/* Unmap pci device */ -static void -pci_unmap_device(struct rte_pci_device *dev) -{ - if (dev == NULL) - return; - - /* try unmapping the NIC resources using VFIO if it exists */ - switch (dev->kdrv) { - case RTE_KDRV_VFIO: - RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n"); - break; - case RTE_KDRV_IGB_UIO: - case RTE_KDRV_UIO_GENERIC: - case RTE_KDRV_NIC_UIO: - /* unmap resources for devices that use uio */ - pci_uio_unmap_resource(dev); - break; - default: - RTE_LOG(DEBUG, EAL, " Not managed by a supported kernel driver," - " skipped\n"); - break; - } -} - /* * If vendor/device ID match, call the devinit() function of the * driver. diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index e16bb68..73363f6 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -165,6 +165,24 @@ struct rte_pci_device; int pci_unbind_kernel_driver(struct rte_pci_device *dev); /** + * Map this device + * + * This function is private to EAL. + * + * @return + * 0 on success, negative on error and positive if no driver + * is found for the device. + */ +int pci_map_device(struct rte_pci_device *dev); + +/** + * Unmap this device + * + * This function is private to EAL. + */ +void pci_unmap_device(struct rte_pci_device *dev); + +/** * Map the PCI resource of a PCI device in virtual memory * * This function is private to EAL. diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index 1d5a13b..9a28ede 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -123,6 +123,56 @@ pci_get_kernel_driver_by_path(const char *filename, char *dri_name) return -1; } +/* Map pci device */ +int +pci_map_device(struct rte_pci_device *dev) +{ + int ret = -1; + + /* try mapping the NIC resources using VFIO if it exists */ + switch (dev->kdrv) { + case RTE_KDRV_VFIO: +#ifdef VFIO_PRESENT + if (pci_vfio_is_enabled()) + ret = pci_vfio_map_resource(dev); +#endif + break; + case RTE_KDRV_IGB_UIO: + case RTE_KDRV_UIO_GENERIC: + /* map resources for devices that use uio */ + ret = pci_uio_map_resource(dev); + break; + default: + RTE_LOG(DEBUG, EAL, + " Not managed by a supported kernel driver, skipped\n"); + ret = 1; + break; + } + + return ret; +} + +/* Unmap pci device */ +void +pci_unmap_device(struct rte_pci_device *dev) +{ + /* try unmapping the NIC resources using VFIO if it exists */ + switch (dev->kdrv) { + case RTE_KDRV_VFIO: + RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n"); + break; + case RTE_KDRV_IGB_UIO: + case RTE_KDRV_UIO_GENERIC: + /* unmap resources for devices that use uio */ + pci_uio_unmap_resource(dev); + break; + default: + RTE_LOG(DEBUG, EAL, + " Not managed by a supported kernel driver, skipped\n"); + break; + } +} + void * pci_find_max_end_va(void) { -- 2.1.4