All of lore.kernel.org
 help / color / mirror / Atom feed
From: Keith Busch <keith.busch@intel.com>
To: Linux PCI <linux-pci@vger.kernel.org>,
	Bjorn Helgaas <bhelgaas@google.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Sinan Kaya <okaya@kernel.org>, Thomas Tai <thomas.tai@oracle.com>,
	poza@codeaurora.org, Lukas Wunner <lukas@wunner.de>,
	Keith Busch <keith.busch@intel.com>
Subject: [PATCH 13/16] PCI/pciehp: Implement error handling callbacks
Date: Fri, 31 Aug 2018 15:26:36 -0600	[thread overview]
Message-ID: <20180831212639.10196-14-keith.busch@intel.com> (raw)
In-Reply-To: <20180831212639.10196-1-keith.busch@intel.com>

Error handling may trigger spurious link events, which may trigger
hotplug handling to re-enumerate the topology. This patch temporarily
disables notification during such error handling and checks the topology
for changes after reset.

Signed-off-by: Keith Busch <keith.busch@intel.com>
---
 drivers/pci/hotplug/pciehp.h      |  1 +
 drivers/pci/hotplug/pciehp_core.c | 51 +++++++++++++++++++++++++++++++++++++++
 drivers/pci/hotplug/pciehp_hpc.c  |  9 +++++++
 3 files changed, 61 insertions(+)

diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h
index 811cf83f956d..27abfb504b35 100644
--- a/drivers/pci/hotplug/pciehp.h
+++ b/drivers/pci/hotplug/pciehp.h
@@ -195,6 +195,7 @@ void pciehp_get_attention_status(struct slot *slot, u8 *status);
 void pciehp_set_attention_status(struct slot *slot, u8 status);
 void pciehp_get_latch_status(struct slot *slot, u8 *status);
 void pciehp_get_adapter_status(struct slot *slot, u8 *status);
+void pciehp_get_adapter_changed(struct slot *slot, u8 *changed);
 int pciehp_query_power_fault(struct slot *slot);
 void pciehp_green_led_on(struct slot *slot);
 void pciehp_green_led_off(struct slot *slot);
diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
index ec48c9433ae5..acb4d864b4e7 100644
--- a/drivers/pci/hotplug/pciehp_core.c
+++ b/drivers/pci/hotplug/pciehp_core.c
@@ -301,6 +301,55 @@ static void pciehp_remove(struct pcie_device *dev)
 	pciehp_release_ctrl(ctrl);
 }
 
+static void pciehp_error_detected(struct pci_dev *dev)
+{
+	struct controller *ctrl;
+	struct pcie_device *pcie_dev;
+	struct device *device = pcie_port_find_device(dev, PCIE_PORT_SERVICE_HP);
+
+	if (!device)
+		return;
+
+	pcie_dev = to_pcie_device(device);
+	ctrl = get_service_data(pcie_dev);
+
+	/*
+	 * Shutdown notification to ignore hotplug events during error
+	 * handling. We'll recheck the status when error handling completes.
+	 *
+	 * It is possible link event related to this error handling may have
+	 * triggered a the hotplug interrupt ahead of this notification, but we
+	 * can't do anything about that race.
+	 */
+	pcie_shutdown_notification(ctrl);
+}
+
+static void pciehp_slot_reset(struct pci_dev *dev)
+{
+	u8 changed;
+	struct controller *ctrl;
+	struct pcie_device *pcie_dev;
+	struct device *device = pcie_port_find_device(dev, PCIE_PORT_SERVICE_HP);
+
+	if (!device)
+		return;
+
+	pcie_dev = to_pcie_device(device);
+	ctrl = get_service_data(pcie_dev);
+
+	/*
+	 * Cache presence detect change, but ignore other hotplug events that
+	 * may occur during error handling. Ports that implement only in-band
+	 * presence detection may inadvertently believe the device has changed,
+	 * so those devices will have to be re-enumerated.
+	 */
+	pciehp_get_adapter_changed(ctrl->slot, &changed);
+	pcie_clear_hotplug_events(ctrl);
+	if (changed)
+		pciehp_request(ctrl, PCI_EXP_SLTSTA_PDC);
+	pcie_init_notification(ctrl);
+}
+
 #ifdef CONFIG_PM
 static int pciehp_suspend(struct pcie_device *dev)
 {
@@ -340,6 +389,8 @@ static struct pcie_port_service_driver hpdriver_portdrv = {
 
 	.probe		= pciehp_probe,
 	.remove		= pciehp_remove,
+	.error_detected	= pciehp_error_detected,
+	.slot_reset	= pciehp_slot_reset,
 
 #ifdef	CONFIG_PM
 	.suspend	= pciehp_suspend,
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index c6116e516e1e..7c43336e08ba 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -398,6 +398,15 @@ void pciehp_get_adapter_status(struct slot *slot, u8 *status)
 	*status = !!(slot_status & PCI_EXP_SLTSTA_PDS);
 }
 
+void pciehp_get_adapter_changed(struct slot *slot, u8 *changed)
+{
+	struct pci_dev *pdev = ctrl_dev(slot->ctrl);
+	u16 slot_status;
+
+	pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
+	*changed = !!(slot_status & PCI_EXP_SLTSTA_PDC);
+}
+
 int pciehp_query_power_fault(struct slot *slot)
 {
 	struct pci_dev *pdev = ctrl_dev(slot->ctrl);
-- 
2.14.4

  parent reply	other threads:[~2018-09-01  1:34 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-31 21:26 [PATCH 00/16] PCI, error handling and hot plug Keith Busch
2018-08-31 21:26 ` [PATCH 01/16] PCI: Simplify disconnected marking Keith Busch
2018-08-31 21:26 ` [PATCH 02/16] PCI: Fix pci_reset_bus Keith Busch
2018-08-31 21:52   ` Sinan Kaya
2018-08-31 22:08     ` Keith Busch
2018-08-31 21:26 ` [PATCH 03/16] PCI/AER: Remove dead code Keith Busch
2018-08-31 21:26 ` [PATCH 04/16] PCI/ERR: Use slot reset if available Keith Busch
2018-09-01 17:20   ` Lukas Wunner
2018-09-04 14:53     ` Keith Busch
2018-08-31 21:26 ` [PATCH 05/16] PCI/ERR: Handle fatal error recovery Keith Busch
2018-09-01  8:31   ` Christoph Hellwig
2018-09-05  5:56   ` poza
2018-08-31 21:26 ` [PATCH 06/16] PCI/ERR: Remove devices on recovery failure Keith Busch
2018-08-31 22:26   ` Sinan Kaya
2018-08-31 21:26 ` [PATCH 07/16] PCI/ERR: Always use the first downstream port Keith Busch
2018-08-31 21:26 ` [PATCH 08/16] PCI/ERR: Simplify broadcast callouts Keith Busch
2018-09-01  8:33   ` Christoph Hellwig
2018-08-31 21:26 ` [PATCH 09/16] PCI/ERR: Report current recovery status for udev Keith Busch
2018-09-01  8:36   ` Christoph Hellwig
2018-08-31 21:26 ` [PATCH 10/16] PCI/portdrv: Provide pci error callbacks Keith Busch
2018-09-02 10:16   ` Lukas Wunner
2018-09-04 21:38     ` Keith Busch
2018-08-31 21:26 ` [PATCH 11/16] PCI/portdrv: Restore pci state on slot reset Keith Busch
2018-09-02  9:34   ` Lukas Wunner
2018-09-04 14:36     ` Keith Busch
2018-08-31 21:26 ` [PATCH 12/16] PCI/pciehp: Fix powerfault detection order Keith Busch
2018-09-01 15:18   ` Lukas Wunner
2018-09-04 14:27     ` Keith Busch
2018-08-31 21:26 ` Keith Busch [this message]
2018-09-02 10:39   ` [PATCH 13/16] PCI/pciehp: Implement error handling callbacks Lukas Wunner
2018-09-04 14:19     ` Keith Busch
2018-08-31 21:26 ` [PATCH 14/16] pciehp: Ignore link events during DPC event Keith Busch
2018-08-31 22:18   ` Sinan Kaya
2018-08-31 22:33     ` Keith Busch
2018-08-31 22:55       ` Sinan Kaya
2018-08-31 22:59         ` Keith Busch
2018-08-31 23:07           ` Sinan Kaya
2018-09-02 14:27   ` Lukas Wunner
2018-09-04 14:16     ` Keith Busch
2018-09-04 14:40       ` Lukas Wunner
2018-09-04 15:31         ` Keith Busch
2018-08-31 21:26 ` [PATCH 15/16] PCI/DPC: Wait for reset complete Keith Busch
2018-08-31 22:15   ` Sinan Kaya
2018-08-31 21:26 ` [PATCH 16/16] PCI: Unify device inaccessible Keith Busch
2018-09-02 14:39   ` Lukas Wunner
2018-09-03  0:38     ` Benjamin Herrenschmidt

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=20180831212639.10196-14-keith.busch@intel.com \
    --to=keith.busch@intel.com \
    --cc=benh@kernel.crashing.org \
    --cc=bhelgaas@google.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=okaya@kernel.org \
    --cc=poza@codeaurora.org \
    --cc=thomas.tai@oracle.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.