From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id E03342C7A for ; Mon, 9 Feb 2015 14:44:49 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP; 09 Feb 2015 05:44:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,544,1418112000"; d="scan'208";a="683088124" Received: from irsmsx101.ger.corp.intel.com ([163.33.3.153]) by orsmga002.jf.intel.com with ESMTP; 09 Feb 2015 05:44:47 -0800 Received: from irsmsx108.ger.corp.intel.com ([169.254.11.64]) by IRSMSX101.ger.corp.intel.com ([169.254.1.244]) with mapi id 14.03.0195.001; Mon, 9 Feb 2015 13:44:46 +0000 From: "Iremonger, Bernard" To: Tetsuya Mukawa , "dev@dpdk.org" Thread-Topic: [PATCH v7 08/14] eal/linux/pci: Add functions for unmapping igb_uio resources Thread-Index: AQHQRELY3PnmoIGInEqW3tiLCRSgiZzoU7pQ Date: Mon, 9 Feb 2015 13:44:45 +0000 Message-ID: <8CEF83825BEC744B83065625E567D7C2049DF07A@IRSMSX108.ger.corp.intel.com> References: <1422763322-13742-4-git-send-email-mukawa@igel.co.jp> <1423470639-15744-1-git-send-email-mukawa@igel.co.jp> <1423470639-15744-9-git-send-email-mukawa@igel.co.jp> In-Reply-To: <1423470639-15744-9-git-send-email-mukawa@igel.co.jp> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.180] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v7 08/14] eal/linux/pci: Add functions for unmapping igb_uio resources 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, 09 Feb 2015 13:44:50 -0000 > -----Original Message----- > From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp] > Sent: Monday, February 9, 2015 8:31 AM > To: dev@dpdk.org > Cc: Iremonger, Bernard; Qiu, Michael; Tetsuya Mukawa > Subject: [PATCH v7 08/14] eal/linux/pci: Add functions for unmapping igb_= uio resources >=20 > The patch adds functions for unmapping igb_uio resources. The patch is on= ly for Linux and igb_uio > environment. VFIO and BSD are not supported. >=20 > v5: > - Fix pci_unmap_device() to check pt_driver. > v4: > - Add parameter checking. > - Add header file to determine if hotplug can be enabled. >=20 > Signed-off-by: Tetsuya Mukawa > --- > lib/librte_eal/common/Makefile | 1 + > lib/librte_eal/common/include/rte_dev_hotplug.h | 44 +++++++++++++++++ > lib/librte_eal/linuxapp/eal/eal_pci.c | 44 +++++++++++++++++ > lib/librte_eal/linuxapp/eal/eal_pci_init.h | 8 +++ > lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 65 +++++++++++++++++++= ++++++ > 5 files changed, 162 insertions(+) > create mode 100644 lib/librte_eal/common/include/rte_dev_hotplug.h >=20 > diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makef= ile index 52c1a5f..db7cc93 > 100644 > --- a/lib/librte_eal/common/Makefile > +++ b/lib/librte_eal/common/Makefile > @@ -41,6 +41,7 @@ INC +=3D rte_eal_memconfig.h rte_malloc_heap.h INC += =3D rte_hexdump.h > rte_devargs.h rte_dev.h INC +=3D rte_common_vect.h INC +=3D rte_pci_dev= _feature_defs.h > rte_pci_dev_features.h > +INC +=3D rte_dev_hotplug.h >=20 > ifeq ($(CONFIG_RTE_INSECURE_FUNCTION_WARNING),y) > INC +=3D rte_warnings.h > diff --git a/lib/librte_eal/common/include/rte_dev_hotplug.h > b/lib/librte_eal/common/include/rte_dev_hotplug.h > new file mode 100644 > index 0000000..b333e0f > --- /dev/null > +++ b/lib/librte_eal/common/include/rte_dev_hotplug.h > @@ -0,0 +1,44 @@ > +/*- > + * BSD LICENSE > + * > + * Copyright(c) 2015 IGEL Co.,LTd. > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > + * the documentation and/or other materials provided with the > + * distribution. > + * * Neither the name of IGEL Co.,Ltd. nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS F= OR > + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGH= T > + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTA= L, > + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF US= E, > + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON A= NY > + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE U= SE > + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE= . > + */ > + > +#ifndef _RTE_DEV_HOTPLUG_H_ > +#define _RTE_DEV_HOTPLUG_H_ > + > +/* > + * determine if hotplug can be enabled on the system */ #if > +defined(RTE_LIBRTE_EAL_HOTPLUG) && defined(RTE_LIBRTE_EAL_LINUXAPP) > +#define ENABLE_HOTPLUG #endif /* RTE_LIBRTE_EAL_HOTPLUG & > +RTE_LIBRTE_EAL_LINUXAPP */ > + > +#endif /* _RTE_DEV_HOTPLUG_H_ */ > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linux= app/eal/eal_pci.c > index d847102..c3b7917 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_pci.c > +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c > @@ -166,6 +166,25 @@ pci_map_resource(void *requested_addr, int fd, off_t= offset, size_t size) > return mapaddr; > } >=20 > +#ifdef ENABLE_HOTPLUG > +/* unmap a particular resource */ > +void > +pci_unmap_resource(void *requested_addr, size_t size) { > + if (requested_addr =3D=3D NULL) > + return; > + > + /* Unmap the PCI memory resource of device */ > + if (munmap(requested_addr, size)) { > + RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n", > + __func__, requested_addr, (unsigned long)size, > + strerror(errno)); > + } else > + RTE_LOG(DEBUG, EAL, " PCI memory mapped at %p\n", Hi Tetsuya, " PCI memory mapped" should be "PCI memory unmapped" Regards, Bernard > + requested_addr); > +} > +#endif /* ENABLE_HOTPLUG */ > + > /* parse the "resource" sysfs file */ > #define IORESOURCE_MEM 0x00000200 >=20 > @@ -567,6 +586,31 @@ pci_map_device(struct rte_pci_device *dev) > return ret; > } >=20 > +#ifdef ENABLE_HOTPLUG > +static void > +pci_unmap_device(struct rte_pci_device *dev) { > + if (dev =3D=3D NULL) > + return; > + > + /* try unmapping the NIC resources using VFIO if it exists */ > + switch (dev->pt_driver) { > + case RTE_PT_VFIO: > + RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n"); > + break; > + case RTE_PT_IGB_UIO: > + case RTE_PT_UIO_GENERIC: > + /* unmap resources for devices that use uio */ > + pci_uio_unmap_resource(dev); > + break; > + default: > + RTE_LOG(DEBUG, EAL, " Not managed by known pt driver," > + " skipped\n"); > + break; > + } > +} > +#endif /* ENABLE_HOTPLUG */ > + > /* > * If vendor/device ID match, call the devinit() function of the > * driver. > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/= linuxapp/eal/eal_pci_init.h > index 1070eb8..5152a0b 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h > +++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h > @@ -34,6 +34,7 @@ > #ifndef EAL_PCI_INIT_H_ > #define EAL_PCI_INIT_H_ >=20 > +#include > #include "eal_vfio.h" >=20 > struct pci_map { > @@ -71,6 +72,13 @@ void *pci_map_resource(void *requested_addr, int fd, o= ff_t offset, > /* map IGB_UIO resource prototype */ > int pci_uio_map_resource(struct rte_pci_device *dev); >=20 > +#ifdef ENABLE_HOTPLUG > +void pci_unmap_resource(void *requested_addr, size_t size); > + > +/* unmap IGB_UIO resource prototype */ > +void pci_uio_unmap_resource(struct rte_pci_device *dev); #endif /* > +ENABLE_HOTPLUG */ > + > #ifdef VFIO_PRESENT >=20 > #define VFIO_MAX_GROUPS 64 > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/l= inuxapp/eal/eal_pci_uio.c > index 1da3507..81830d1 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > @@ -404,6 +404,71 @@ pci_uio_map_resource(struct rte_pci_device *dev) > return 0; > } >=20 > +#ifdef ENABLE_HOTPLUG > +static void > +pci_uio_unmap(struct mapped_pci_resource *uio_res) { > + int i; > + > + if (uio_res =3D=3D NULL) > + return; > + > + for (i =3D 0; i !=3D uio_res->nb_maps; i++) > + pci_unmap_resource(uio_res->maps[i].addr, > + (size_t)uio_res->maps[i].size); > +} > + > +static struct mapped_pci_resource * > +pci_uio_find_resource(struct rte_pci_device *dev) { > + struct mapped_pci_resource *uio_res; > + > + if (dev =3D=3D NULL) > + return NULL; > + > + TAILQ_FOREACH(uio_res, pci_res_list, next) { > + > + /* skip this element if it doesn't match our PCI address */ > + if (!eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr)) > + return uio_res; > + } > + return NULL; > +} > + > +/* unmap the PCI resource of a PCI device in virtual memory */ void > +pci_uio_unmap_resource(struct rte_pci_device *dev) { > + struct mapped_pci_resource *uio_res; > + > + if (dev =3D=3D NULL) > + return; > + > + /* find an entry for the device */ > + uio_res =3D pci_uio_find_resource(dev); > + if (uio_res =3D=3D NULL) > + return; > + > + /* secondary processes - just free maps */ > + if (rte_eal_process_type() !=3D RTE_PROC_PRIMARY) > + return pci_uio_unmap(uio_res); > + > + TAILQ_REMOVE(pci_res_list, uio_res, next); > + > + /* unmap all resources */ > + pci_uio_unmap(uio_res); > + > + /* free uio resource */ > + rte_free(uio_res); > + > + /* close fd if in primary process */ > + close(dev->intr_handle.fd); > + > + dev->intr_handle.fd =3D -1; > + dev->intr_handle.type =3D RTE_INTR_HANDLE_UNKNOWN; } #endif /* > +ENABLE_HOTPLUG */ > + > /* > * parse a sysfs file containing one integer value > * different to the eal version, as it needs to work with 64-bit values > -- > 1.9.1