From patchwork Wed Mar 11 04:59:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 5982331 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6745D9FB2A for ; Wed, 11 Mar 2015 05:00:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 786332037F for ; Wed, 11 Mar 2015 05:00:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8AC012037A for ; Wed, 11 Mar 2015 05:00:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750779AbbCKFAG (ORCPT ); Wed, 11 Mar 2015 01:00:06 -0400 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:41565 "EHLO e23smtp01.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750810AbbCKFAF (ORCPT ); Wed, 11 Mar 2015 01:00:05 -0400 Received: from /spool/local by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 11 Mar 2015 15:00:02 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 11 Mar 2015 15:00:01 +1000 Received: from d23relay06.au.ibm.com (d23relay06.au.ibm.com [9.185.63.219]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 393F92CE804E for ; Wed, 11 Mar 2015 16:00:01 +1100 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t2B4xqwF52494572 for ; Wed, 11 Mar 2015 16:00:01 +1100 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t2B4xR0Y009272 for ; Wed, 11 Mar 2015 15:59:27 +1100 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t2B4xQgu008603; Wed, 11 Mar 2015 15:59:27 +1100 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.253.15]) by ozlabs.au.ibm.com (Postfix) with ESMTP id C73F5A0221; Wed, 11 Mar 2015 15:59:03 +1100 (AEDT) Received: from shangw (shangw.ozlabs.ibm.com [10.61.2.199]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id 3D46216A9C4; Wed, 11 Mar 2015 15:59:03 +1100 (AEDT) Received: by shangw (Postfix, from userid 1000) id 275D53E02AC; Wed, 11 Mar 2015 15:59:03 +1100 (EST) From: Gavin Shan To: linux-pci@vger.kernel.org Cc: cascardo@linux.vnet.ibm.com, bhelgaas@google.com, Gavin Shan Subject: [PATCH v2 2/2] PCI: Apply warm reset to specific devices Date: Wed, 11 Mar 2015 15:59:01 +1100 Message-Id: <1426049941-6727-2-git-send-email-gwshan@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1426049941-6727-1-git-send-email-gwshan@linux.vnet.ibm.com> References: <1426049941-6727-1-git-send-email-gwshan@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15031105-1618-0000-0000-000001B79B2F Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, VFIO infrastructure depends on pci_reset_function() to ensure the PCI device in clean state when passing to guest, or being returned back to host. However, the function doesn't work (or well) on some PCI devices on PowerPC platforms, which potentiallybrings pending traffic over the boundary between host/guest and usually causes memory corruption. The patch applies warm reset to those PCI devices, which is implemented based on pci_set_pcie_reset_state() to get clean state when passing device from host to guest, or returning it back to host. The reset request is routed to platform specific pcibios_set_pcie_reset_state() and processed there. Signed-off-by: Gavin Shan --- v2: Reuse pci_set_pcie_reset_state() --- drivers/pci/quirks.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 85f247e..9846d5e 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -3504,6 +3504,22 @@ static int reset_chelsio_generic_dev(struct pci_dev *dev, int probe) return 0; } +static int pci_dev_warm_reset(struct pci_dev *pdev, int probe) +{ + int ret; + + /* Check the device can take the reset or not */ + if (probe) + return pci_set_pcie_reset_state(pdev, pcie_warm_reset, probe); + + /* Issue warm reset */ + ret = pci_set_pcie_reset_state(pdev, pcie_warm_reset, 0); + if (!ret) + ret = pci_set_pcie_reset_state(pdev, pcie_deassert_reset, 0); + + return ret; +} + #define PCI_DEVICE_ID_INTEL_82599_SFP_VF 0x10ed #define PCI_DEVICE_ID_INTEL_IVB_M_VGA 0x0156 #define PCI_DEVICE_ID_INTEL_IVB_M2_VGA 0x0166 @@ -3519,6 +3535,18 @@ static const struct pci_dev_reset_methods pci_dev_reset_methods[] = { reset_intel_generic_dev }, { PCI_VENDOR_ID_CHELSIO, PCI_ANY_ID, reset_chelsio_generic_dev }, + { PCI_VENDOR_ID_IBM, PCI_ANY_ID, + pci_dev_warm_reset }, + { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57800, + pci_dev_warm_reset }, + { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57840, + pci_dev_warm_reset }, + { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57810, + pci_dev_warm_reset }, + { PCI_VENDOR_ID_MELLANOX, PCI_ANY_ID, + pci_dev_warm_reset }, + { PCI_VENDOR_ID_TI, PCI_ANY_ID, + pci_dev_warm_reset }, { 0 } };