Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp364851pxb; Wed, 22 Sep 2021 04:06:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIqveG3dfVgOYMTOy0JnMEC5vTmQuvw8rltktdwl9IJb1Cu8d3Dcy7xMWruiuVM5/wqBQz X-Received: by 2002:a92:7302:: with SMTP id o2mr25235895ilc.44.1632308817526; Wed, 22 Sep 2021 04:06:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632308817; cv=none; d=google.com; s=arc-20160816; b=dx2wdrXCfSUnuDvxJ2DMFTGAcOC26+3zTqhZsheBFgGCuqUxuqO8HBqwfR1ec6YrMv u9Oma2ehz8rheg0Y6fn1I0SbO4nvG3jAgC5xcyEmEcFbQVT98PgwQGq19mkuPbiGnril 6Hx+jWghfGbyxHoNp7xrFIuMJpYUNaZrONHo3FfUWxqA3oSWWAuSJ2l6Kbsa0f71klqZ 23crxQJ3MHicb1hMlGuSrO9kmyLBRu6NALX9WW7loFSWZhtYuPRm9BvNgDB1fvYlxZUL zaViTRyVkfZk34CK2l9Og6XNnH3T4IXEvafCoIynPm1RswQitHpezc2ar0yDgzcAWOuu fiWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=P0Ja7+gIwUPp3wpNJP9mL2RvNwOKxP+LmjY12s7b9iM=; b=nXMjFTw8u/JXUtB0/ym7TSfIOaImBhuRsRKb2p8yAWUXBoQam9yotx4Tm9DxHHH7SL woxk+s6PKUnPvMvz4olGz6Ig26hdb1TDWHiSsxpY0M/TZH5NmT+sk0mFomDGdMoHjfit sSM7+5lZ2qE/IKr9LxV31ClOUz5MpHNHw10qb3eOzhNupqV0QvqnyU+oNQeW3GpVZ4dh Tqie0I3fCz8pWrHd4Kxa7drICjvNDEd7+uX1GES+DDG1P3HqTEii8RaZyI1XJJHHlsk7 2SpT4wQMG7/59Zj3PKRxq8ueCEd2ZsIo03kkqvbvvghSVPB3Q4pz2k1SpM39QFZHvIl6 ckug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h46si1929402jaa.85.2021.09.22.04.06.46; Wed, 22 Sep 2021 04:06:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235387AbhIVLHY (ORCPT + 99 others); Wed, 22 Sep 2021 07:07:24 -0400 Received: from inva021.nxp.com ([92.121.34.21]:43102 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235353AbhIVLHU (ORCPT ); Wed, 22 Sep 2021 07:07:20 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 64C97202638; Wed, 22 Sep 2021 13:05:49 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 580E6202652; Wed, 22 Sep 2021 13:05:49 +0200 (CEST) Received: from fsr-ub1864-111.ea.freescale.net (fsr-ub1864-111.ea.freescale.net [10.171.82.141]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id 0546F20298; Wed, 22 Sep 2021 13:05:48 +0200 (CEST) From: Diana Craciun To: Laurentiu Tudor , linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, Alex Williamson , kvm@vger.kernel.org Cc: Li Yang , linux-arm-kernel@lists.infradead.org, Diana Craciun Subject: [PATCH v2 2/2] vfio/fsl-mc: Add per device reset support Date: Wed, 22 Sep 2021 14:05:30 +0300 Message-Id: <20210922110530.24736-2-diana.craciun@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210922110530.24736-1-diana.craciun@oss.nxp.com> References: <20210922110530.24736-1-diana.craciun@oss.nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently when a fsl-mc device is reset, the entire DPRC container is reset which is very inefficient because the devices within a container will be reset multiple times. Add support for individually resetting a device. Signed-off-by: Diana Craciun --- drivers/vfio/fsl-mc/vfio_fsl_mc.c | 45 ++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc.c b/drivers/vfio/fsl-mc/vfio_fsl_mc.c index 0ead91bfa838..6d7b2d2571a2 100644 --- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c @@ -65,6 +65,34 @@ static void vfio_fsl_mc_regions_cleanup(struct vfio_fsl_mc_device *vdev) kfree(vdev->regions); } +static int vfio_fsl_mc_reset_device(struct vfio_fsl_mc_device *vdev) +{ + struct fsl_mc_device *mc_dev = vdev->mc_dev; + int ret = 0; + + if (is_fsl_mc_bus_dprc(vdev->mc_dev)) { + return dprc_reset_container(mc_dev->mc_io, 0, + mc_dev->mc_handle, + mc_dev->obj_desc.id, + DPRC_RESET_OPTION_NON_RECURSIVE); + } else { + u16 token; + + ret = fsl_mc_obj_open(mc_dev->mc_io, 0, mc_dev->obj_desc.id, + mc_dev->obj_desc.type, + &token); + if (ret) + goto out; + ret = fsl_mc_obj_reset(mc_dev->mc_io, 0, token); + if (ret) { + fsl_mc_obj_close(mc_dev->mc_io, 0, token); + goto out; + } + ret = fsl_mc_obj_close(mc_dev->mc_io, 0, token); + } +out: + return ret; +} static void vfio_fsl_mc_close_device(struct vfio_device *core_vdev) { @@ -78,9 +106,7 @@ static void vfio_fsl_mc_close_device(struct vfio_device *core_vdev) vfio_fsl_mc_regions_cleanup(vdev); /* reset the device before cleaning up the interrupts */ - ret = dprc_reset_container(mc_cont->mc_io, 0, mc_cont->mc_handle, - mc_cont->obj_desc.id, - DPRC_RESET_OPTION_NON_RECURSIVE); + ret = vfio_fsl_mc_reset_device(vdev); if (WARN_ON(ret)) dev_warn(&mc_cont->dev, @@ -203,18 +229,7 @@ static long vfio_fsl_mc_ioctl(struct vfio_device *core_vdev, } case VFIO_DEVICE_RESET: { - int ret; - struct fsl_mc_device *mc_dev = vdev->mc_dev; - - /* reset is supported only for the DPRC */ - if (!is_fsl_mc_bus_dprc(mc_dev)) - return -ENOTTY; - - ret = dprc_reset_container(mc_dev->mc_io, 0, - mc_dev->mc_handle, - mc_dev->obj_desc.id, - DPRC_RESET_OPTION_NON_RECURSIVE); - return ret; + return vfio_fsl_mc_reset_device(vdev); } default: -- 2.17.1