From: Gavin Shan <gwshan@linux.vnet.ibm.com>
To: linux-pci@vger.kernel.org
Cc: bhelgaas@google.com, linuxppc-dev@lists.ozlabs.org,
cascardo@linux.vnet.ibm.com,
Gavin Shan <gwshan@linux.vnet.ibm.com>
Subject: [PATCH 4/4] powerpc/powernv: Register PCI dev specific reset handlers
Date: Fri, 13 Feb 2015 15:54:59 +1100 [thread overview]
Message-ID: <1423803299-22356-5-git-send-email-gwshan@linux.vnet.ibm.com> (raw)
In-Reply-To: <1423803299-22356-1-git-send-email-gwshan@linux.vnet.ibm.com>
Currently, PCI 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, which potentially brings pending
traffic over the boundary between host/guest and usually causes
memory corruption.
The patch registers PCI device specific reset handlers for those
PCI devices, pci_reset_function() doesn't work or not well, to
translate the request to EEH PE reset if possible.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
arch/powerpc/platforms/powernv/pci.c | 61 ++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c
index e69142f..c68d508 100644
--- a/arch/powerpc/platforms/powernv/pci.c
+++ b/arch/powerpc/platforms/powernv/pci.c
@@ -727,6 +727,64 @@ static void pnv_pci_dma_fallback_setup(struct pci_controller *hose,
set_iommu_table_base_and_group(&pdev->dev, pdn->iommu_table);
}
+/*
+ * VFIO infrastructure depends on pci_reset_function() to do
+ * reset on the PCI devices when their owership is changed to
+ * ensure consistent clean state on those devices when someone
+ * grabs them. However, pci_reset_function() doesn't work for
+ * some deivces that require EEH PE reset.
+ */
+static int pnv_pci_dev_specific_reset(struct pci_dev *pdev, int probe)
+{
+ struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+ struct eeh_pe *pe = edev ? edev->pe : NULL;
+
+ if (!pe)
+ return -ENOTTY;
+
+ if (probe)
+ return 0;
+
+ pci_set_pcie_reset_state(pdev, pcie_hot_reset);
+ pci_set_pcie_reset_state(pdev, pcie_deassert_reset);
+ return 0;
+}
+
+static int pnv_pci_root_bridge_prepare(struct pci_host_bridge *bridge)
+{
+ static bool pnv_pci_reset_registered = false;
+ int ret = 0;
+
+ if (pnv_pci_reset_registered)
+ return 0;
+
+ pnv_pci_reset_registered = true;
+ ret += pci_dev_add_specific_reset(PCI_VENDOR_ID_IBM,
+ PCI_ANY_ID,
+ pnv_pci_dev_specific_reset);
+ ret += pci_dev_add_specific_reset(PCI_VENDOR_ID_BROADCOM,
+ PCI_DEVICE_ID_NX2_57800,
+ pnv_pci_dev_specific_reset);
+ ret += pci_dev_add_specific_reset(PCI_VENDOR_ID_BROADCOM,
+ PCI_DEVICE_ID_NX2_57840,
+ pnv_pci_dev_specific_reset);
+ ret += pci_dev_add_specific_reset(PCI_VENDOR_ID_BROADCOM,
+ PCI_DEVICE_ID_NX2_57810,
+ pnv_pci_dev_specific_reset);
+ ret += pci_dev_add_specific_reset(PCI_VENDOR_ID_MELLANOX,
+ PCI_ANY_ID,
+ pnv_pci_dev_specific_reset);
+ ret += pci_dev_add_specific_reset(PCI_VENDOR_ID_TI,
+ PCI_ANY_ID,
+ pnv_pci_dev_specific_reset);
+ if (ret)
+ pr_warn("%s: Failure adding PCI specific reset handlers\n",
+ __func__);
+
+ /* Don't return error to keep PCI core going */
+ return 0;
+}
+
static void pnv_pci_dma_dev_setup(struct pci_dev *pdev)
{
struct pci_controller *hose = pci_bus_to_host(pdev->bus);
@@ -820,6 +878,9 @@ void __init pnv_pci_init(void)
/* Setup the linkage between OF nodes and PHBs */
pci_devs_phb_init();
+ /* Setup root bridge */
+ ppc_md.pcibios_root_bridge_prepare = pnv_pci_root_bridge_prepare;
+
/* Configure IOMMU DMA hooks */
ppc_md.pci_dma_dev_setup = pnv_pci_dma_dev_setup;
ppc_md.tce_build = pnv_tce_build_vm;
--
1.8.3.2
next prev parent reply other threads:[~2015-02-13 4:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-13 4:54 [PATCH 0/4] Support registering specific reset handler Gavin Shan
2015-02-13 4:54 ` [PATCH 1/4] PCI: Rename struct pci_dev_reset_methods Gavin Shan
2015-02-13 4:54 ` [PATCH 2/4] PCI: Introduce list for device reset methods Gavin Shan
2015-02-13 4:54 ` [PATCH 3/4] PCI: Allow registering reset method Gavin Shan
2015-02-13 4:54 ` Gavin Shan [this message]
2015-02-16 13:14 ` [PATCH 0/4] Support registering specific reset handler cascardo
2015-02-16 22:36 ` Gavin Shan
2015-02-19 18:57 ` cascardo
2015-02-20 5:53 ` Gavin Shan
2015-03-06 18:38 ` Bjorn Helgaas
2015-03-10 6:31 ` Gavin Shan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1423803299-22356-5-git-send-email-gwshan@linux.vnet.ibm.com \
--to=gwshan@linux.vnet.ibm.com \
--cc=bhelgaas@google.com \
--cc=cascardo@linux.vnet.ibm.com \
--cc=linux-pci@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).