From patchwork Wed Apr 29 08:48:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenfan X-Patchwork-Id: 465945 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DF84314032D for ; Wed, 29 Apr 2015 18:53:56 +1000 (AEST) Received: from localhost ([::1]:37774 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnNkh-0003di-4o for incoming@patchwork.ozlabs.org; Wed, 29 Apr 2015 04:53:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35973) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnNga-0003dz-Kl for qemu-devel@nongnu.org; Wed, 29 Apr 2015 04:49:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnNgY-0002vz-AI for qemu-devel@nongnu.org; Wed, 29 Apr 2015 04:49:40 -0400 Received: from [59.151.112.132] (port=1065 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnNgX-0002jM-VK for qemu-devel@nongnu.org; Wed, 29 Apr 2015 04:49:38 -0400 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="91413643" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 29 Apr 2015 16:45:44 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t3T8mLLl007375; Wed, 29 Apr 2015 16:48:21 +0800 Received: from G08FNSTD131468.g08.fujitsu.local (10.167.226.78) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Wed, 29 Apr 2015 16:49:40 +0800 From: Chen Fan To: Date: Wed, 29 Apr 2015 16:48:36 +0800 Message-ID: <5be1bd6fd6728a6a0c7dd4d95004e5e2791068bc.1430297161.git.chen.fan.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.167.226.78] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: izumi.taku@jp.fujitsu.com, alex.williamson@redhat.com Subject: [Qemu-devel] [PATCH RFC v6 08/11] vfio: extract vfio_get_hot_reset_info as a single function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org the function is used to get affected devices by bus reset. so here extract it, and can used for aer soon. Signed-off-by: Chen Fan --- hw/vfio/pci.c | 69 ++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index c306efc..b42c2a4 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2657,6 +2657,51 @@ static void vfio_check_af_flr(VFIOPCIDevice *vdev, uint8_t pos) } } +/* + * return error with negative, return devices count with positive, + * return the ret_info fill with the affected device reset info. + * + */ +static int vfio_get_hot_reset_info(VFIOPCIDevice *vdev, + struct vfio_pci_hot_reset_info **ret_info) +{ + struct vfio_pci_hot_reset_info *info; + int ret, count; + + *ret_info = NULL; + + info = g_malloc0(sizeof(*info)); + info->argsz = sizeof(*info); + + ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, info); + if (ret && errno != ENOSPC) { + ret = -errno; + if (!vdev->has_pm_reset) { + error_report("vfio: Cannot reset device %04x:%02x:%02x.%x, " + "no available reset mechanism.", vdev->host.domain, + vdev->host.bus, vdev->host.slot, vdev->host.function); + } + return ret; + } + + count = info->count; + + info = g_realloc(info, sizeof(*info) + + (count * sizeof(struct vfio_pci_dependent_device))); + info->argsz = sizeof(*info) + + (count * sizeof(struct vfio_pci_dependent_device)); + + ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, info); + if (ret) { + ret = -errno; + error_report("vfio: hot reset info failed: %m"); + return ret; + } + + *ret_info = info; + return count; +} + static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos) { PCIDevice *pdev = &vdev->pdev; @@ -2913,32 +2958,12 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) vfio_pci_pre_reset(vdev); vdev->vbasedev.needs_reset = false; - info = g_malloc0(sizeof(*info)); - info->argsz = sizeof(*info); - - ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, info); - if (ret && errno != ENOSPC) { - ret = -errno; - if (!vdev->has_pm_reset) { - error_report("vfio: Cannot reset device %04x:%02x:%02x.%x, " - "no available reset mechanism.", vdev->host.domain, - vdev->host.bus, vdev->host.slot, vdev->host.function); - } + ret = vfio_get_hot_reset_info(vdev, &info); + if (ret < 0) { goto out_single; } - count = info->count; - info = g_realloc(info, sizeof(*info) + (count * sizeof(*devices))); - info->argsz = sizeof(*info) + (count * sizeof(*devices)); devices = &info->devices[0]; - - ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, info); - if (ret) { - ret = -errno; - error_report("vfio: hot reset info failed: %m"); - goto out_single; - } - trace_vfio_pci_hot_reset_has_dep_devices(vdev->vbasedev.name); /* Verify that we have all the groups required */