Simplify PCIe native ownership
Subsystems (3)
v13 cover Simplify PCIe native ownership
Currently, PCIe capabilities ownership status is detected by verifying the status of pcie_ports_native, and _OSC negotiated results (cached in struct pci_host_bridge->native_* members). But this logic can be simplified, and we can use only struct pci_host_bridge ->native_* members to detect it.
This patchset removes the distributed checks for pcie_ports_native, parameter.
Changes since v12:
* Rebased on top of v5.11-rc1
Changes since v11 (Bjorns update):
* Add bugfix for DPC with no AER Capability
* Split OSC_OWNER trivial changes from pcie_ports_native changes
* Temporarily drop pcie_ports_dpc_native changes (revisit it later).
Changes since v10:
* Addressed format issue reported by lkp test.
Changes since v9:
* Rebased on top of v5.10-rc1
Changes since v8:
* Simplified setting _OSC ownwership logic
* Moved bridge->native_ltr out of #ifdef CONFIG_PCIEPORTBUS.
Changes since v7:
* Fixed "fix array_size.cocci warnings".
Changes since v6:
* Created new patch for CONFIG_PCIEPORTBUS check in pci_init_host_bridge().
* Added warning message for a case when pcie_ports_native overrides _OSC negotiation result.
Changes since v5:
* Rebased on top of v5.8-rc1
Changes since v4:
* Changed the patch set title (Original link: https://lkml.org/lkml/2020/5/26/1710)
* Added AER/DPC dependency logic cleanup fixes.
Bjorn Helgaas (2):
PCI/DPC: Ignore devices with no AER Capability PCI/ACPI: Centralize pci_aer_available() checking
Kuppuswamy Sathyanarayanan (3):
PCI: Assume control of portdrv-related features only when portdrv
enabled
PCI/ACPI: Tidy _OSC control bit checking
PCI/ACPI: Centralize pcie_ports_native checking
drivers/acpi/pci_root.c | 49 ++++++++++++++++++++++++------- drivers/pci/hotplug/pciehp_core.c | 2 +- drivers/pci/pci-acpi.c | 3 -- drivers/pci/pcie/aer.c | 2 +- drivers/pci/pcie/dpc.c | 3 ++ drivers/pci/pcie/portdrv_core.c | 11 +++---- drivers/pci/probe.c | 6 ++-- 7 files changed, 51 insertions(+), 25 deletions(-)
Signature · 1 line
2.25.1
PATCH v13 1/5 PCI/DPC: Ignore devices with no AER Capability
From: Bjorn Helgaas <[email protected]>
Downstream Ports may support DPC regardless of whether they support AER (see PCIe r5.0, sec 6.2.10.2). Previously, if the user booted with "pcie_ports=dpc-native", it was possible for dpc_probe() to succeed even if the device had no AER Capability, but dpc_get_aer_uncorrect_severity() depends on the AER Capability.
dpc_probe() previously failed if:
!pcie_aer_is_native(pdev) && !pcie_ports_dpc_native !(pcie_aer_is_native() || pcie_ports_dpc_native) # by De Morgan's law
so it succeeded if:
pcie_aer_is_native() || pcie_ports_dpc_native
Fail dpc_probe() if the device has no AER Capability.
--- drivers/pci/pcie/dpc.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pci/pcie/dpc.c +3 -0
@@ -287,6 +287,9 @@ static int dpc_probe(struct pcie_device *dev)int status;u16 ctl, cap; +if (!pdev->aer_cap) +return -ENOTSUPP ; +if (!pcie_aer_is_native (pdev) && !pcie_ports_dpc_native)return -ENOTSUPP ;
Signature · 1 line
2.25.1
PATCH v13 2/5 PCI: Assume control of portdrv-related features only when portdrv enabled
In reply to Kuppuswamy SathyanarayananNative control of PME, AER, DPC, and PCIe hotplug depends on the portdrv, so default to native handling of them only when CONFIG_PCIEPORTBUS is enabled.
Native control LTR and SHPC hotplug does not depend on portdrv, so we can always take control of them unless some platform interface, e.g., _OSC, tells us otherwise.
--- drivers/pci/probe.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/pci/probe.c +4 -2
@@ -588,12 +588,14 @@ static void pci_init_host_bridge(struct pci_host_bridge *bridge)* may implement its own AER handling and use _OSC to prevent the * OS from interfering. */ +#ifdef CONFIG_PCIEPORTBUS bridge->native_aer =1 ; bridge->native_pcie_hotplug =1 ; - bridge->native_shpc_hotplug =1 ; bridge->native_pme =1 ; - bridge->native_ltr =1 ; bridge->native_dpc =1 ; +#endif + bridge->native_ltr =1 ; + bridge->native_shpc_hotplug =1 ;device_initialize (&bridge->dev); }
Signature · 1 line
2.25.1
PATCH v13 3/5 PCI/ACPI: Tidy _OSC control bit checking
In reply to Kuppuswamy SathyanarayananAdd OSC_OWNER() helper to prettify checking the _OSC control bits to learn whether the platform has granted us control of PCI features. No functional change intended.
--- drivers/acpi/pci_root.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/acpi/pci_root.c +17 -12
@@ -874,6 +874,12 @@ static void acpi_pci_root_release_info(struct pci_host_bridge *bridge)__acpi_pci_root_release_info (bridge->release_data); } +#define OSC_OWNER (ctrl, bit, flag) \ + do { \ + if (!(ctrl & bit)) \ + flag = 0; \ + } while (0) + struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root, struct acpi_pci_root_ops *ops, struct acpi_pci_root_info *info,
@@ -885,6 +891,7 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root,struct pci_bus *bus;struct pci_host_bridge *host_bridge;union acpi_object *obj; +u32 ctrl; info->root = root; info->bridge = device;
@@ -910,18 +917,16 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root, goto out_release_info; host_bridge =to_pci_host_bridge (bus->bridge); -if (!(root->osc_control_set &OSC_PCI_EXPRESS_NATIVE_HP_CONTROL )) - host_bridge->native_pcie_hotplug =0 ; -if (!(root->osc_control_set &OSC_PCI_SHPC_NATIVE_HP_CONTROL )) - host_bridge->native_shpc_hotplug =0 ; -if (!(root->osc_control_set &OSC_PCI_EXPRESS_AER_CONTROL )) - host_bridge->native_aer =0 ; -if (!(root->osc_control_set &OSC_PCI_EXPRESS_PME_CONTROL )) - host_bridge->native_pme =0 ; -if (!(root->osc_control_set &OSC_PCI_EXPRESS_LTR_CONTROL )) - host_bridge->native_ltr =0 ; -if (!(root->osc_control_set &OSC_PCI_EXPRESS_DPC_CONTROL )) - host_bridge->native_dpc =0 ; + + ctrl = root->osc_control_set; +OSC_OWNER (ctrl,OSC_PCI_EXPRESS_NATIVE_HP_CONTROL , + host_bridge->native_pcie_hotplug); +OSC_OWNER (ctrl,OSC_PCI_SHPC_NATIVE_HP_CONTROL , + host_bridge->native_shpc_hotplug); +OSC_OWNER (ctrl,OSC_PCI_EXPRESS_AER_CONTROL , host_bridge->native_aer); +OSC_OWNER (ctrl,OSC_PCI_EXPRESS_PME_CONTROL , host_bridge->native_pme); +OSC_OWNER (ctrl,OSC_PCI_EXPRESS_LTR_CONTROL , host_bridge->native_ltr); +OSC_OWNER (ctrl,OSC_PCI_EXPRESS_DPC_CONTROL , host_bridge->native_dpc);/* * Evaluate the "PCI Boot Configuration" _DSM Function. If it
Signature · 1 line
2.25.1
PATCH v13 4/5 PCI/ACPI: Centralize pcie_ports_native checking
In reply to Kuppuswamy SathyanarayananIf the user booted with "pcie_ports=native", we take control of the PCIe features unconditionally, regardless of what _OSC says.
Centralize the testing of pcie_ports_native in acpi_pci_root_create(), where we interpret the _OSC results, so other places only have to check host_bridge->native_X and we don't have to sprinkle tests of pcie_ports_native everywhere.
--- drivers/acpi/pci_root.c | 19 +++++++++++++++++++ drivers/pci/hotplug/pciehp_core.c | 2 +- drivers/pci/pci-acpi.c | 3 --- drivers/pci/pcie/aer.c | 2 +- drivers/pci/pcie/portdrv_core.c | 11 ++++------- 5 files changed, 25 insertions(+), 12 deletions(-)
drivers/acpi/pci_root.c +19 -0
@@ -880,6 +880,8 @@ static void acpi_pci_root_release_info(struct pci_host_bridge *bridge) flag =0 ; \ } while (0) +#define FLAG (x) ((x) ? '+' : '-') + struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root, struct acpi_pci_root_ops *ops, struct acpi_pci_root_info *info,
@@ -928,6 +930,23 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root,OSC_OWNER (ctrl,OSC_PCI_EXPRESS_LTR_CONTROL , host_bridge->native_ltr);OSC_OWNER (ctrl,OSC_PCI_EXPRESS_DPC_CONTROL , host_bridge->native_dpc); +if (pcie_ports_native) { +dev_info (&root->device->dev,"Taking control of PCIe-related features because \"pcie_ports=native\" specified; may conflict with firmware\n" ); + host_bridge->native_pcie_hotplug =1 ; + host_bridge->native_aer =1 ; + host_bridge->native_pme =1 ; + host_bridge->native_ltr =1 ; + host_bridge->native_dpc =1 ; + } + +dev_info (&root->device->dev,"OS native features: SHPCHotplug%c PCIeHotplug%c PME%c AER%c DPC%c LTR%c\n" , +FLAG (host_bridge->native_shpc_hotplug), +FLAG (host_bridge->native_pcie_hotplug), +FLAG (host_bridge->native_pme), +FLAG (host_bridge->native_aer), +FLAG (host_bridge->native_dpc), +FLAG (host_bridge->native_ltr)); +/* * Evaluate the "PCI Boot Configuration" _DSM Function. If it * exists and returns 0, we must preserve any PCI resource
drivers/pci/hotplug/pciehp_core.c +1 -1
@@ -256,7 +256,7 @@ static bool pme_is_native(struct pcie_device *dev)const struct pci_host_bridge *host; host =pci_find_host_bridge (dev->port->bus); -return pcie_ports_native || host->native_pme; +return host->native_pme; }static void pciehp_disable_interrupt (struct pcie_device *dev)
drivers/pci/pci-acpi.c +0 -3
@@ -800,9 +800,6 @@ bool pciehp_is_native(struct pci_dev *bridge)if (!(slot_cap &PCI_EXP_SLTCAP_HPC ))return false; -if (pcie_ports_native) -return true; - host =pci_find_host_bridge (bridge->bus);return host->native_pcie_hotplug; }
drivers/pci/pcie/aer.c +1 -1
@@ -219,7 +219,7 @@ int pcie_aer_is_native(struct pci_dev *dev)if (!dev->aer_cap)return 0 ; -return pcie_ports_native || host->native_aer; +return host->native_aer; }int pci_enable_pcie_error_reporting (struct pci_dev *dev)
drivers/pci/pcie/portdrv_core.c +4 -7
@@ -208,8 +208,7 @@ static int get_port_device_capability(struct pci_dev *dev)struct pci_host_bridge *host =pci_find_host_bridge (dev->bus);int services =0 ; -if (dev->is_hotplug_bridge && - (pcie_ports_native || host->native_pcie_hotplug)) { +if (host->native_pcie_hotplug && dev->is_hotplug_bridge) { services |=PCIE_PORT_SERVICE_HP ;/*
@@ -221,8 +220,7 @@ static int get_port_device_capability(struct pci_dev *dev) }#ifdef CONFIG_PCIEAER -if (dev->aer_cap &&pci_aer_available () && - (pcie_ports_native || host->native_aer)) { +if (host->native_aer && dev->aer_cap &&pci_aer_available ()) { services |=PCIE_PORT_SERVICE_AER ;/*
@@ -234,9 +232,8 @@ static int get_port_device_capability(struct pci_dev *dev)#endif /* Root Ports and Root Complex Event Collectors may generate PMEs */ -if ((pci_pcie_type (dev) ==PCI_EXP_TYPE_ROOT_PORT || -pci_pcie_type (dev) ==PCI_EXP_TYPE_RC_EC ) && - (pcie_ports_native || host->native_pme)) { +if (host->native_pme && (pci_pcie_type (dev) ==PCI_EXP_TYPE_ROOT_PORT || +pci_pcie_type (dev) ==PCI_EXP_TYPE_RC_EC )) { services |=PCIE_PORT_SERVICE_PME ;/*
Signature · 1 line
2.25.1
PATCH v13 5/5 PCI/ACPI: Centralize pci_aer_available() checking
In reply to Kuppuswamy SathyanarayananFrom: Bjorn Helgaas <[email protected]>
Check pci_aer_available() in acpi_pci_root_create() when we're interpreting _OSC results so host_bridge->native_aer becomes the single way to determine whether we control AER capabilities.
--- drivers/acpi/pci_root.c | 3 +++ drivers/pci/pcie/portdrv_core.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/acpi/pci_root.c +3 -0
@@ -939,6 +939,9 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root, host_bridge->native_dpc =1 ; } +if (!pci_aer_available ()) + host_bridge->native_aer =0 ; + dev_info(&root->device->dev, "OS native features: SHPCHotplug%c PCIeHotplug%c PME%c AER%c DPC%c LTR%c\n", FLAG(host_bridge->native_shpc_hotplug), FLAG(host_bridge->native_pcie_hotplug),
drivers/pci/pcie/portdrv_core.c +1 -1
@@ -220,7 +220,7 @@ static int get_port_device_capability(struct pci_dev *dev) }#ifdef CONFIG_PCIEAER -if (host->native_aer && dev->aer_cap &&pci_aer_available ()) { +if (host->native_aer && dev->aer_cap) { services |=PCIE_PORT_SERVICE_AER ;/*
Signature · 1 line
2.25.1
Hi Bjorn,
Quoted 8 lines · Kuppuswamy Sathyanarayanan
Currently, PCIe capabilities ownership status is detected by verifying the status of
pcie_ports_native, and_OSCnegotiated results (cached in struct pci_host_bridge->native_* members). But this logic can be simplified, and we can use only structpci_host_bridge->native_* members to detect it.This patchset removes the distributed checks for
pcie_ports_native, parameter.
Any comments on this patch set?
Quoted 54 lines
Changes since v12:
* Rebased on top of v5.11-rc1Changes since v11 (Bjorns update):
* Add bugfix for DPC with no AER Capability
* SplitOSC_OWNERtrivial changes frompcie_ports_nativechanges
* Temporarily droppcie_ports_dpc_nativechanges (revisit it later).Changes since v10:
* Addressed format issue reported by lkp test.Changes since v9:
* Rebased on top of v5.10-rc1Changes since v8:
* Simplified setting_OSCownwership logic
* Movedbridge->native_ltrout of #ifdefCONFIG_PCIEPORTBUS.Changes since v7:
* Fixed "fixarray_size.cocciwarnings".Changes since v6:
* Created new patch forCONFIG_PCIEPORTBUScheck inpci_init_host_bridge().* Added warning message for a case when
pcie_ports_nativeoverrides_OSCnegotiation result.Changes since v5:
* Rebased on top of v5.8-rc1Changes since v4:
* Changed the patch set title (Original link: https://lkml.org/lkml/2020/5/26/1710)
* Added AER/DPC dependency logic cleanup fixes.Bjorn Helgaas (2):
PCI/DPC: Ignore devices with no AER Capability PCI/ACPI: Centralizepci_aer_available()checkingKuppuswamy Sathyanarayanan (3):
PCI: Assume control of portdrv-related features only when portdrv
enabled
PCI/ACPI: Tidy_OSCcontrol bit checking
PCI/ACPI: Centralizepcie_ports_nativecheckingdrivers/acpi/pci_root.c | 49 ++++++++++++++++++++++++------- drivers/pci/hotplug/pciehp_core.c | 2 +- drivers/pci/pci-acpi.c | 3 -- drivers/pci/pcie/aer.c | 2 +- drivers/pci/pcie/dpc.c | 3 ++ drivers/pci/pcie/portdrv_core.c | 11 +++---- drivers/pci/probe.c | 6 ++-- 7 files changed, 51 insertions(+), 25 deletions(-)
Signature · 2 lines
Sathyanarayanan Kuppuswamy Linux Kernel Developer