From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id E222E1BB87 for ; Wed, 4 Apr 2018 07:25:11 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Apr 2018 22:25:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,404,1517904000"; d="scan'208";a="40532742" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga003.jf.intel.com with ESMTP; 03 Apr 2018 22:25:09 -0700 Received: from fmsmsx154.amr.corp.intel.com (10.18.116.70) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 3 Apr 2018 22:25:09 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by FMSMSX154.amr.corp.intel.com (10.18.116.70) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 3 Apr 2018 22:25:08 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.241]) by shsmsx102.ccr.corp.intel.com ([169.254.2.61]) with mapi id 14.03.0319.002; Wed, 4 Apr 2018 13:25:07 +0800 From: "Tan, Jianfeng" To: "Guo, Jia" , "stephen@networkplumber.org" , "Richardson, Bruce" , "Yigit, Ferruh" , "Ananyev, Konstantin" , "gaetan.rivet@6wind.com" , "Wu, Jingjing" , "thomas@monjalon.net" , "motih@mellanox.com" , "Van Haaren, Harry" CC: "jblunck@infradead.org" , "shreyansh.jain@nxp.com" , "dev@dpdk.org" , "Zhang, Helin" Thread-Topic: [PATCH V18 2/5] bus/pci: implement handle hot unplug operation Thread-Index: AQHTy3gz5sfJ3qhcrEiT3w/Gd81i4aPwB56Q Date: Wed, 4 Apr 2018 05:25:06 +0000 Message-ID: References: <1522779443-1932-1-git-send-email-jia.guo@intel.com> <1522779443-1932-3-git-send-email-jia.guo@intel.com> In-Reply-To: <1522779443-1932-3-git-send-email-jia.guo@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH V18 2/5] bus/pci: implement handle hot unplug operation 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: Wed, 04 Apr 2018 05:25:12 -0000 > -----Original Message----- > From: Guo, Jia > Sent: Wednesday, April 4, 2018 2:17 AM > To: stephen@networkplumber.org; Richardson, Bruce; Yigit, Ferruh; > Ananyev, Konstantin; gaetan.rivet@6wind.com; Wu, Jingjing; > thomas@monjalon.net; motih@mellanox.com; Van Haaren, Harry; Tan, > Jianfeng > Cc: jblunck@infradead.org; shreyansh.jain@nxp.com; dev@dpdk.org; Guo, > Jia; Zhang, Helin > Subject: [PATCH V18 2/5] bus/pci: implement handle hot unplug operation >=20 > When handle device hot unplug event, remap a dummy memory to avoid > bus read/write error. >=20 > Signed-off-by: Jeff Guo > --- > v16->v15; > split patch, merge some function to be simple > --- > drivers/bus/pci/pci_common.c | 42 > ++++++++++++++++++++++++++++++++++++++++ > drivers/bus/pci/pci_common_uio.c | 33 > +++++++++++++++++++++++++++++++ > drivers/bus/pci/private.h | 12 ++++++++++++ > 3 files changed, 87 insertions(+) >=20 > diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c > index 2a00f36..fa077ec 100644 > --- a/drivers/bus/pci/pci_common.c > +++ b/drivers/bus/pci/pci_common.c > @@ -474,6 +474,47 @@ pci_find_device(const struct rte_device *start, > rte_dev_cmp_t cmp, > } >=20 > static int > +pci_handle_hot_unplug(struct rte_device *dev) > +{ > + struct rte_pci_device *pdev; > + int ret; > + > + if (dev =3D=3D NULL) > + return -EINVAL; > + > + pdev =3D RTE_DEV_TO_PCI(dev); > + > + /* remap resources for devices */ > + switch (pdev->kdrv) { > + case RTE_KDRV_VFIO: > +#ifdef VFIO_PRESENT > + /* TODO */ > +#endif What's the difference between uio and vfio? We can just fall though? > + break; > + case RTE_KDRV_IGB_UIO: > + case RTE_KDRV_UIO_GENERIC: > + if (rte_eal_using_phys_addrs()) { Why do we care about if we are using physical addresses? > + /* map resources for devices that use uio */ > + ret =3D pci_uio_remap_resource(pdev); > + } > + break; > + case RTE_KDRV_NIC_UIO: > + ret =3D pci_uio_remap_resource(pdev); > + break; > + default: > + RTE_LOG(DEBUG, EAL, > + " Not managed by a supported kernel driver, skipped\n"); > + ret =3D 1; -1 for such case? > + break; > + } > + > + if (ret !=3D 0) > + RTE_LOG(ERR, EAL, "failed to handle hot unplug of %s", > + pdev->name); > + return ret; > +} > + > +static int > pci_plug(struct rte_device *dev) > { > return pci_probe_all_drivers(RTE_DEV_TO_PCI(dev)); > @@ -503,6 +544,7 @@ struct rte_pci_bus rte_pci_bus =3D { > .unplug =3D pci_unplug, > .parse =3D pci_parse, > .get_iommu_class =3D rte_pci_get_iommu_class, > + .handle_hot_unplug =3D pci_handle_hot_unplug, > }, > .device_list =3D TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), > .driver_list =3D TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list), > diff --git a/drivers/bus/pci/pci_common_uio.c > b/drivers/bus/pci/pci_common_uio.c > index 54bc20b..468ade4 100644 > --- a/drivers/bus/pci/pci_common_uio.c > +++ b/drivers/bus/pci/pci_common_uio.c > @@ -146,6 +146,39 @@ pci_uio_unmap(struct mapped_pci_resource > *uio_res) > } > } >=20 > +/* remap the PCI resource of a PCI device in private virtual memory */ > +int > +pci_uio_remap_resource(struct rte_pci_device *dev) Why's this function uio specific? I think we can move it to pci_common.c. > +{ > + int i; > + uint64_t phaddr; > + void *map_address; > + > + if (dev =3D=3D NULL) > + return -1; > + > + /* Map all BARs */ s/Map/Remap =20 > + for (i =3D 0; i !=3D PCI_MAX_RESOURCE; i++) { > + /* skip empty BAR */ > + phaddr =3D dev->mem_resource[i].phys_addr; > + if (phaddr =3D=3D 0) > + continue; How about just simple: if (dev->mem_resource[i].phys_addr =3D=3D 0) > + pci_unmap_resource(dev->mem_resource[i].addr, > + (size_t)dev->mem_resource[i].len); > + map_address =3D pci_map_resource( > + dev->mem_resource[i].addr, -1, 0, > + (size_t)dev->mem_resource[i].len, > + MAP_ANONYMOUS | MAP_FIXED); > + if (map_address =3D=3D MAP_FAILED) { > + RTE_LOG(ERR, EAL, > + "Cannot remap resource for device %s\n", > dev->name); > + return -1; > + } > + } > + > + return 0; > +} > + > static struct mapped_pci_resource * > pci_uio_find_resource(struct rte_pci_device *dev) > { > diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h > index 88fa587..7a862ef 100644 > --- a/drivers/bus/pci/private.h > +++ b/drivers/bus/pci/private.h > @@ -173,6 +173,18 @@ void pci_uio_free_resource(struct rte_pci_device > *dev, > struct mapped_pci_resource *uio_res); >=20 > /** > + * remap the pci uio resource.. > + * > + * @param dev > + * Point to the struct rte pci device. > + * @return > + * - On success, zero. > + * - On failure, a negative value. > + */ > +int > +pci_uio_remap_resource(struct rte_pci_device *dev); If we define=20 > + > +/** > * Map device memory to uio resource > * > * This function is private to EAL. > -- > 2.7.4