From ca33590b6af032bff57d9cc70455660466a654b2 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Mon, 19 Feb 2018 11:16:57 +0000 Subject: New upstream version 18.02 Change-Id: I89ed24cb2a49b78fe5be6970b99dd46c1499fcc3 Signed-off-by: Luca Boccassi --- lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 43 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'lib/librte_eal/linuxapp/igb_uio/igb_uio.c') diff --git a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c index a3a98c17..4cae4dd2 100644 --- a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c +++ b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c @@ -1,25 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /*- - * GPL LICENSE SUMMARY - * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. - * The full GNU General Public License is included in this distribution - * in the file called LICENSE.GPL. - * - * Contact Information: - * Intel Corporation + * Copyright(c) 2010-2017 Intel Corporation. All rights reserved. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt @@ -45,6 +26,8 @@ struct rte_uio_pci_dev { struct uio_info info; struct pci_dev *pdev; enum rte_intr_mode mode; + struct mutex lock; + int refcnt; }; static char *intr_mode; @@ -299,7 +282,7 @@ igbuio_pci_enable_interrupts(struct rte_uio_pci_dev *udev) err = request_irq(udev->info.irq, igbuio_pci_irqhandler, udev->info.irq_flags, udev->info.name, udev); - dev_info(&udev->pdev->dev, "uio device registered with irq %lx\n", + dev_info(&udev->pdev->dev, "uio device registered with irq %ld\n", udev->info.irq); return err; @@ -336,11 +319,18 @@ igbuio_pci_open(struct uio_info *info, struct inode *inode) struct pci_dev *dev = udev->pdev; int err; + mutex_lock(&udev->lock); + if (++udev->refcnt > 1) { + mutex_unlock(&udev->lock); + return 0; + } + /* set bus master, which was cleared by the reset function */ pci_set_master(dev); /* enable interrupts */ err = igbuio_pci_enable_interrupts(udev); + mutex_unlock(&udev->lock); if (err) { dev_err(&dev->dev, "Enable interrupt fails\n"); return err; @@ -354,12 +344,19 @@ igbuio_pci_release(struct uio_info *info, struct inode *inode) struct rte_uio_pci_dev *udev = info->priv; struct pci_dev *dev = udev->pdev; + mutex_lock(&udev->lock); + if (--udev->refcnt > 0) { + mutex_unlock(&udev->lock); + return 0; + } + /* disable interrupts */ igbuio_pci_disable_interrupts(udev); /* stop the device from further DMA */ pci_clear_master(dev); + mutex_unlock(&udev->lock); return 0; } @@ -480,6 +477,7 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) if (!udev) return -ENOMEM; + mutex_init(&udev->lock); /* * enable device: ask low-level code to enable I/O and * memory @@ -570,6 +568,7 @@ igbuio_pci_remove(struct pci_dev *dev) { struct rte_uio_pci_dev *udev = pci_get_drvdata(dev); + mutex_destroy(&udev->lock); sysfs_remove_group(&dev->dev.kobj, &dev_attr_grp); uio_unregister_device(&udev->info); igbuio_pci_release_iomem(&udev->info); -- cgit 1.2.3-korg