From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 0B755591E for ; Fri, 2 Dec 2016 17:27:58 +0100 (CET) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP; 02 Dec 2016 08:27:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,287,1477983600"; d="scan'208";a="38243029" Received: from dpdk06.sh.intel.com ([10.239.129.195]) by fmsmga005.fm.intel.com with ESMTP; 02 Dec 2016 08:27:54 -0800 From: Jianfeng Tan To: dev@dpdk.org Cc: david.marchand@6wind.com, ferruh.yigit@intel.com, stephen@networkplumber.org, Jianfeng Tan Date: Fri, 2 Dec 2016 16:28:31 +0000 Message-Id: <1480696111-116651-1-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472696197-37614-1-git-send-email-jianfeng.tan@intel.com> References: <1472696197-37614-1-git-send-email-jianfeng.tan@intel.com> Subject: [dpdk-dev] [PATCH] igb_uio: deprecate iomem and ioport mapping X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Dec 2016 16:27:59 -0000 Previously in igb_uio, iomem is mapped, and both ioport and io mem are recorded into uio framework, which is duplicated and makes the code too complex. For iomem, DPDK user space code never opens or reads files under /sys/pci/bus/devices/xxxx:xx:xx.x/uio/uioY/maps/. Instead, /sys/pci/bus/devices/xxxx:xx:xx.x/resourceY are used to map device memory. For ioport, non-x86 platforms cannot read from files under /sys/pci/bus/devices/xxxx:xx:xx.x/uio/uioY/portio/ directly, because non-x86 platforms need to map port region for access in user space, see non-x86 version pci_uio_ioport_map(). x86 platforms can use the the same way as uio_pci_generic. This patch deprecates iomem and ioport mapping in igb_uio kernel module, and adjusts the iomem implementation in both igb_uio and uio_pci_generic: - for x86 platform, get ports info from /proc/ioports; - for non-x86 platform, map and get ports info by pci_uio_ioport_map(). Note: this will affect those applications who are using files under /sys/pci/bus/devices/xxxx:xx:xx.x/uio/uioY/maps/ and /sys/pci/bus/devices/xxxx:xx:xx.x/uio/uioY/portio/. Signed-off-by: Jianfeng Tan --- lib/librte_eal/linuxapp/eal/eal_pci.c | 4 - lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 56 +------------- lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 119 ++---------------------------- 3 files changed, 9 insertions(+), 170 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index 876ba38..2110ad8 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -645,8 +645,6 @@ rte_eal_pci_ioport_map(struct rte_pci_device *dev, int bar, break; #endif case RTE_KDRV_IGB_UIO: - ret = pci_uio_ioport_map(dev, bar, p); - break; case RTE_KDRV_UIO_GENERIC: #if defined(RTE_ARCH_X86) ret = pci_ioport_map(dev, bar, p); @@ -734,8 +732,6 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p) break; #endif case RTE_KDRV_IGB_UIO: - ret = pci_uio_ioport_unmap(p); - break; case RTE_KDRV_UIO_GENERIC: #if defined(RTE_ARCH_X86) ret = 0; diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c index 1786b75..28d09ed 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c @@ -370,53 +370,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, return -1; } -#if defined(RTE_ARCH_X86) -int -pci_uio_ioport_map(struct rte_pci_device *dev, int bar, - struct rte_pci_ioport *p) -{ - char dirname[PATH_MAX]; - char filename[PATH_MAX]; - int uio_num; - unsigned long start; - - uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname), 0); - if (uio_num < 0) - return -1; - - /* get portio start */ - snprintf(filename, sizeof(filename), - "%s/portio/port%d/start", dirname, bar); - if (eal_parse_sysfs_value(filename, &start) < 0) { - RTE_LOG(ERR, EAL, "%s(): cannot parse portio start\n", - __func__); - return -1; - } - /* ensure we don't get anything funny here, read/write will cast to - * uin16_t */ - if (start > UINT16_MAX) - return -1; - - /* FIXME only for primary process ? */ - if (dev->intr_handle.type == RTE_INTR_HANDLE_UNKNOWN) { - - snprintf(filename, sizeof(filename), "/dev/uio%u", uio_num); - dev->intr_handle.fd = open(filename, O_RDWR); - if (dev->intr_handle.fd < 0) { - RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", - filename, strerror(errno)); - return -1; - } - dev->intr_handle.type = RTE_INTR_HANDLE_UIO; - } - - RTE_LOG(DEBUG, EAL, "PCI Port IO found start=0x%lx\n", start); - - p->base = start; - p->len = 0; - return 0; -} -#else +#if !defined(RTE_ARCH_X86) int pci_uio_ioport_map(struct rte_pci_device *dev, int bar, struct rte_pci_ioport *p) @@ -553,14 +507,10 @@ pci_uio_ioport_write(struct rte_pci_ioport *p, } } +#if !defined(RTE_ARCH_X86) int pci_uio_ioport_unmap(struct rte_pci_ioport *p) { -#if defined(RTE_ARCH_X86) - RTE_SET_USED(p); - /* FIXME close intr fd ? */ - return 0; -#else return munmap((void *)(uintptr_t)p->base, p->len); -#endif } +#endif diff --git a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c index df41e45..e9d78fb 100644 --- a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c +++ b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c @@ -216,107 +216,6 @@ igbuio_dom0_pci_mmap(struct uio_info *info, struct vm_area_struct *vma) } #endif -/* Remap pci resources described by bar #pci_bar in uio resource n. */ -static int -igbuio_pci_setup_iomem(struct pci_dev *dev, struct uio_info *info, - int n, int pci_bar, const char *name) -{ - unsigned long addr, len; - void *internal_addr; - - if (n >= ARRAY_SIZE(info->mem)) - return -EINVAL; - - addr = pci_resource_start(dev, pci_bar); - len = pci_resource_len(dev, pci_bar); - if (addr == 0 || len == 0) - return -1; - internal_addr = ioremap(addr, len); - if (internal_addr == NULL) - return -1; - info->mem[n].name = name; - info->mem[n].addr = addr; - info->mem[n].internal_addr = internal_addr; - info->mem[n].size = len; - info->mem[n].memtype = UIO_MEM_PHYS; - return 0; -} - -/* Get pci port io resources described by bar #pci_bar in uio resource n. */ -static int -igbuio_pci_setup_ioport(struct pci_dev *dev, struct uio_info *info, - int n, int pci_bar, const char *name) -{ - unsigned long addr, len; - - if (n >= ARRAY_SIZE(info->port)) - return -EINVAL; - - addr = pci_resource_start(dev, pci_bar); - len = pci_resource_len(dev, pci_bar); - if (addr == 0 || len == 0) - return -EINVAL; - - info->port[n].name = name; - info->port[n].start = addr; - info->port[n].size = len; - info->port[n].porttype = UIO_PORT_X86; - - return 0; -} - -/* Unmap previously ioremap'd resources */ -static void -igbuio_pci_release_iomem(struct uio_info *info) -{ - int i; - - for (i = 0; i < MAX_UIO_MAPS; i++) { - if (info->mem[i].internal_addr) - iounmap(info->mem[i].internal_addr); - } -} - -static int -igbuio_setup_bars(struct pci_dev *dev, struct uio_info *info) -{ - int i, iom, iop, ret; - unsigned long flags; - static const char *bar_names[PCI_STD_RESOURCE_END + 1] = { - "BAR0", - "BAR1", - "BAR2", - "BAR3", - "BAR4", - "BAR5", - }; - - iom = 0; - iop = 0; - - for (i = 0; i < ARRAY_SIZE(bar_names); i++) { - if (pci_resource_len(dev, i) != 0 && - pci_resource_start(dev, i) != 0) { - flags = pci_resource_flags(dev, i); - if (flags & IORESOURCE_MEM) { - ret = igbuio_pci_setup_iomem(dev, info, iom, - i, bar_names[i]); - if (ret != 0) - return ret; - iom++; - } else if (flags & IORESOURCE_IO) { - ret = igbuio_pci_setup_ioport(dev, info, iop, - i, bar_names[i]); - if (ret != 0) - return ret; - iop++; - } - } - } - - return (iom != 0) ? ret : -ENOENT; -} - #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0) static int __devinit #else @@ -345,22 +244,17 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) /* enable bus mastering on the device */ pci_set_master(dev); - /* remap IO memory */ - err = igbuio_setup_bars(dev, &udev->info); - if (err != 0) - goto fail_release_iomem; - /* set 64-bit DMA mask */ err = pci_set_dma_mask(dev, DMA_BIT_MASK(64)); if (err != 0) { dev_err(&dev->dev, "Cannot set DMA mask\n"); - goto fail_release_iomem; + goto fail_disable_dev; } err = pci_set_consistent_dma_mask(dev, DMA_BIT_MASK(64)); if (err != 0) { dev_err(&dev->dev, "Cannot set consistent DMA mask\n"); - goto fail_release_iomem; + goto fail_disable_dev; } /* fill uio infos */ @@ -406,12 +300,12 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) dev_err(&dev->dev, "invalid IRQ mode %u", igbuio_intr_mode_preferred); err = -EINVAL; - goto fail_release_iomem; + goto fail_disable_dev; } err = sysfs_create_group(&dev->dev.kobj, &dev_attr_grp); if (err != 0) - goto fail_release_iomem; + goto fail_disable_irq; /* register uio driver */ err = uio_register_device(&dev->dev, &udev->info); @@ -427,10 +321,10 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) fail_remove_group: sysfs_remove_group(&dev->dev.kobj, &dev_attr_grp); -fail_release_iomem: - igbuio_pci_release_iomem(&udev->info); +fail_disable_irq: if (udev->mode == RTE_INTR_MODE_MSIX) pci_disable_msix(udev->pdev); +fail_disable_dev: pci_disable_device(dev); fail_free: kfree(udev); @@ -445,7 +339,6 @@ igbuio_pci_remove(struct pci_dev *dev) sysfs_remove_group(&dev->dev.kobj, &dev_attr_grp); uio_unregister_device(&udev->info); - igbuio_pci_release_iomem(&udev->info); if (udev->mode == RTE_INTR_MODE_MSIX) pci_disable_msix(dev); pci_disable_device(dev); -- 2.7.4