aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith Busch <keith.busch@intel.com>2016-04-28 18:24:48 -0400
committerBjorn Helgaas <bhelgaas@google.com>2016-05-03 11:39:24 -0400
commit26e515713342b6f7c553aa3c66b21c6ab7cf82af (patch)
treeb1a1f3223de5c7ea6d6a379f06f5d8d687ae7490
parent10126ac14d36e74b2705802dc915b0b18463a51f (diff)
PCI: Add Downstream Port Containment driver
Add driver for the PCI Express Downstream Port Containment extended capability. DPC is an optional capability to contain uncorrectable errors below a port. For more information on DPC, please see PCI Express Base Specification Revision 4, section 7.31, or view the PCI-SIG DPC ECN here: https://pcisig.com/sites/default/files/specification_documents/ECN_DPC_2012-02-09_finalized.pdf When a DPC event is triggered, the hardware disables downstream links, so the DPC driver schedules removal for all devices below this port. This may happen concurrently with a PCIe hotplug driver if enabled. When all downstream devices are removed and the link state transitions to disabled, the DPC driver clears the DPC status and interrupt bits so the link may retrain for a newly connected device. [bhelgaas: clear (not set) DPC_CTL bits on remove, whitespace cleanup] Signed-off-by: Keith Busch <keith.busch@intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Cc: Lukas Wunner <lukas@wunner.de>
-rw-r--r--drivers/pci/pcie/Kconfig14
-rw-r--r--drivers/pci/pcie/Makefile2
-rw-r--r--drivers/pci/pcie/pcie-dpc.c163
-rw-r--r--include/uapi/linux/pci_regs.h17
4 files changed, 196 insertions, 0 deletions
diff --git a/drivers/pci/pcie/Kconfig b/drivers/pci/pcie/Kconfig
index 72db7f4209ca..22ca6412bd15 100644
--- a/drivers/pci/pcie/Kconfig
+++ b/drivers/pci/pcie/Kconfig
@@ -81,3 +81,17 @@ endchoice
81config PCIE_PME 81config PCIE_PME
82 def_bool y 82 def_bool y
83 depends on PCIEPORTBUS && PM 83 depends on PCIEPORTBUS && PM
84
85config PCIE_DPC
86 tristate "PCIe Downstream Port Containment support"
87 depends on PCIEPORTBUS
88 default n
89 help
90 This enables PCI Express Downstream Port Containment (DPC)
91 driver support. DPC events from Root and Downstream ports
92 will be handled by the DPC driver. If your system doesn't
93 have this capability or you do not want to use this feature,
94 it is safe to answer N.
95
96 To compile this driver as a module, choose M here: the module
97 will be called pcie-dpc.
diff --git a/drivers/pci/pcie/Makefile b/drivers/pci/pcie/Makefile
index 00c62df5a9fc..b24525b3dec1 100644
--- a/drivers/pci/pcie/Makefile
+++ b/drivers/pci/pcie/Makefile
@@ -14,3 +14,5 @@ obj-$(CONFIG_PCIEPORTBUS) += pcieportdrv.o
14obj-$(CONFIG_PCIEAER) += aer/ 14obj-$(CONFIG_PCIEAER) += aer/
15 15
16obj-$(CONFIG_PCIE_PME) += pme.o 16obj-$(CONFIG_PCIE_PME) += pme.o
17
18obj-$(CONFIG_PCIE_DPC) += pcie-dpc.o
diff --git a/drivers/pci/pcie/pcie-dpc.c b/drivers/pci/pcie/pcie-dpc.c
new file mode 100644
index 000000000000..ab552f1bc08f
--- /dev/null
+++ b/drivers/pci/pcie/pcie-dpc.c
@@ -0,0 +1,163 @@
1/*
2 * PCI Express Downstream Port Containment services driver
3 * Copyright (C) 2016 Intel Corp.
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 */
9
10#include <linux/delay.h>
11#include <linux/interrupt.h>
12#include <linux/module.h>
13#include <linux/pci.h>
14#include <linux/pcieport_if.h>
15
16struct dpc_dev {
17 struct pcie_device *dev;
18 struct work_struct work;
19 int cap_pos;
20};
21
22static void dpc_wait_link_inactive(struct pci_dev *pdev)
23{
24 unsigned long timeout = jiffies + HZ;
25 u16 lnk_status;
26
27 pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
28 while (lnk_status & PCI_EXP_LNKSTA_DLLLA &&
29 !time_after(jiffies, timeout)) {
30 msleep(10);
31 pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
32 }
33 if (lnk_status & PCI_EXP_LNKSTA_DLLLA)
34 dev_warn(&pdev->dev, "Link state not disabled for DPC event");
35}
36
37static void interrupt_event_handler(struct work_struct *work)
38{
39 struct dpc_dev *dpc = container_of(work, struct dpc_dev, work);
40 struct pci_dev *dev, *temp, *pdev = dpc->dev->port;
41 struct pci_bus *parent = pdev->subordinate;
42
43 pci_lock_rescan_remove();
44 list_for_each_entry_safe_reverse(dev, temp, &parent->devices,
45 bus_list) {
46 pci_dev_get(dev);
47 pci_stop_and_remove_bus_device(dev);
48 pci_dev_put(dev);
49 }
50 pci_unlock_rescan_remove();
51
52 dpc_wait_link_inactive(pdev);
53 pci_write_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_STATUS,
54 PCI_EXP_DPC_STATUS_TRIGGER | PCI_EXP_DPC_STATUS_INTERRUPT);
55}
56
57static irqreturn_t dpc_irq(int irq, void *context)
58{
59 struct dpc_dev *dpc = (struct dpc_dev *)context;
60 struct pci_dev *pdev = dpc->dev->port;
61 u16 status, source;
62
63 pci_read_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_STATUS, &status);
64 pci_read_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_SOURCE_ID,
65 &source);
66 if (!status)
67 return IRQ_NONE;
68
69 dev_info(&dpc->dev->device, "DPC containment event, status:%#06x source:%#06x\n",
70 status, source);
71
72 if (status & PCI_EXP_DPC_STATUS_TRIGGER) {
73 u16 reason = (status >> 1) & 0x3;
74
75 dev_warn(&dpc->dev->device, "DPC %s triggered, remove downstream devices\n",
76 (reason == 0) ? "unmasked uncorrectable error" :
77 (reason == 1) ? "ERR_NONFATAL" :
78 (reason == 2) ? "ERR_FATAL" : "extended error");
79 schedule_work(&dpc->work);
80 }
81 return IRQ_HANDLED;
82}
83
84#define FLAG(x, y) (((x) & (y)) ? '+' : '-')
85static int dpc_probe(struct pcie_device *dev)
86{
87 struct dpc_dev *dpc;
88 struct pci_dev *pdev = dev->port;
89 int status;
90 u16 ctl, cap;
91
92 dpc = kzalloc(sizeof(*dpc), GFP_KERNEL);
93 if (!dpc)
94 return -ENOMEM;
95
96 dpc->cap_pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DPC);
97 dpc->dev = dev;
98 INIT_WORK(&dpc->work, interrupt_event_handler);
99 set_service_data(dev, dpc);
100
101 status = request_irq(dev->irq, dpc_irq, IRQF_SHARED, "pcie-dpc", dpc);
102 if (status) {
103 dev_warn(&dev->device, "request IRQ%d failed: %d\n", dev->irq,
104 status);
105 goto out;
106 }
107
108 pci_read_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_CAP, &cap);
109 pci_read_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_CTL, &ctl);
110
111 ctl |= PCI_EXP_DPC_CTL_EN_NONFATAL | PCI_EXP_DPC_CTL_INT_EN;
112 pci_write_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_CTL, ctl);
113
114 dev_info(&dev->device, "DPC error containment capabilities: Int Msg #%d, RPExt%c PoisonedTLP%c SwTrigger%c RP PIO Log %d, DL_ActiveErr%c\n",
115 cap & 0xf, FLAG(cap, PCI_EXP_DPC_CAP_RP_EXT),
116 FLAG(cap, PCI_EXP_DPC_CAP_POISONED_TLP),
117 FLAG(cap, PCI_EXP_DPC_CAP_SW_TRIGGER), (cap >> 8) & 0xf,
118 FLAG(cap, PCI_EXP_DPC_CAP_DL_ACTIVE));
119 return status;
120 out:
121 kfree(dpc);
122 return status;
123}
124
125static void dpc_remove(struct pcie_device *dev)
126{
127 struct dpc_dev *dpc = get_service_data(dev);
128 struct pci_dev *pdev = dev->port;
129 u16 ctl;
130
131 pci_read_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_CTL, &ctl);
132 ctl &= ~(PCI_EXP_DPC_CTL_EN_NONFATAL | PCI_EXP_DPC_CTL_INT_EN);
133 pci_write_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_CTL, ctl);
134
135 free_irq(dev->irq, dpc);
136 kfree(dpc);
137}
138
139static struct pcie_port_service_driver dpcdriver = {
140 .name = "dpc",
141 .port_type = PCI_EXP_TYPE_ROOT_PORT | PCI_EXP_TYPE_DOWNSTREAM,
142 .service = PCIE_PORT_SERVICE_DPC,
143 .probe = dpc_probe,
144 .remove = dpc_remove,
145};
146
147static int __init dpc_service_init(void)
148{
149 return pcie_port_service_register(&dpcdriver);
150}
151
152static void __exit dpc_service_exit(void)
153{
154 pcie_port_service_unregister(&dpcdriver);
155}
156
157MODULE_DESCRIPTION("PCI Express Downstream Port Containment driver");
158MODULE_AUTHOR("Keith Busch <keith.busch@intel.com>");
159MODULE_LICENSE("GPL");
160MODULE_VERSION("0.1");
161
162module_init(dpc_service_init);
163module_exit(dpc_service_exit);
diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h
index 61e95c142547..404095124ae2 100644
--- a/include/uapi/linux/pci_regs.h
+++ b/include/uapi/linux/pci_regs.h
@@ -947,4 +947,21 @@
947#define PCI_TPH_CAP_ST_SHIFT 16 /* st table shift */ 947#define PCI_TPH_CAP_ST_SHIFT 16 /* st table shift */
948#define PCI_TPH_BASE_SIZEOF 12 /* size with no st table */ 948#define PCI_TPH_BASE_SIZEOF 12 /* size with no st table */
949 949
950/* Downstream Port Containment */
951#define PCI_EXP_DPC_CAP 4 /* DPC Capability */
952#define PCI_EXP_DPC_CAP_RP_EXT 0x20 /* Root Port Extensions for DPC */
953#define PCI_EXP_DPC_CAP_POISONED_TLP 0x40 /* Poisoned TLP Egress Blocking Supported */
954#define PCI_EXP_DPC_CAP_SW_TRIGGER 0x80 /* Software Triggering Supported */
955#define PCI_EXP_DPC_CAP_DL_ACTIVE 0x1000 /* ERR_COR signal on DL_Active supported */
956
957#define PCI_EXP_DPC_CTL 6 /* DPC control */
958#define PCI_EXP_DPC_CTL_EN_NONFATAL 0x02 /* Enable trigger on ERR_NONFATAL message */
959#define PCI_EXP_DPC_CTL_INT_EN 0x08 /* DPC Interrupt Enable */
960
961#define PCI_EXP_DPC_STATUS 8 /* DPC Status */
962#define PCI_EXP_DPC_STATUS_TRIGGER 0x01 /* Trigger Status */
963#define PCI_EXP_DPC_STATUS_INTERRUPT 0x08 /* Interrupt Status */
964
965#define PCI_EXP_DPC_SOURCE_ID 10 /* DPC Source Identifier */
966
950#endif /* LINUX_PCI_REGS_H */ 967#endif /* LINUX_PCI_REGS_H */