Skip to contentSkip to conversation

PCI: Do not enable extended tags on pre-dated (v1.x) systems

PATCH Superseded Sinan Kaya 2 participants 3 messages Jul 5, 2017 – Jul 7, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Sinan Kaya

author
#0 lore raw

PATCH 1/1 PCI: Do not enable extended tags on pre-dated (v1.x) systems

According to extended tags ECN document, all PCIe receivers are expected to support extended tags support. It should be safe to enable extended tags on endpoints without checking compatibility.

This assumption seems to be working fine except for the legacy systems. The ECN has been written against PCIE spec version 2.0. Therefore, we need to exclude all version 1.0 devices from this change as there is HW out there that can't handle extended tags.

Note that the default value of Extended Tags Enable bit is implementation specific. Therefore, we are clearing the bit by default when incompatible HW is found without assuming that value is zero.

---
 drivers/pci/probe.c | 52 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 45 insertions(+), 7 deletions(-)
drivers/pci/probe.c +45 -7
index 19c8950..5e39013 100644
@@ -1684,21 +1684,58 @@ static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp)
 	 */
 }
 
-static void pci_configure_extended_tags(struct pci_dev *dev)
+static bool pcie_bus_exttags_supported(struct pci_bus *bus)
+{
+	bool exttags_supported = true;
+	struct pci_dev *bridge;
+	int rc;
+	u16 flags;
+
+	bridge = bus->self;
+	while (bridge) {
+		if (pci_is_pcie(bridge)) {
+			rc = pcie_capability_read_word(bridge, PCI_EXP_FLAGS,
+						       &flags);
+			if (!rc && ((flags & PCI_EXP_FLAGS_VERS) < 2)) {
+				exttags_supported = false;
+				break;
+			}
+		}
+		if (!bridge->bus->parent)
+			break;
+		bridge = bridge->bus->parent->self;
+	}
+
+	return exttags_supported;
+}
+
+static int pcie_bus_configure_exttags(struct pci_dev *dev, void *data)
 {
 	u32 dev_cap;
 	int ret;
+	bool supported;
 
 	if (!pci_is_pcie(dev))
-		return;
+		return 0;
 
 	ret = pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &dev_cap);
 	if (ret)
-		return;
+		return 0;
 
-	if (dev_cap & PCI_EXP_DEVCAP_EXT_TAG)
-		pcie_capability_set_word(dev, PCI_EXP_DEVCTL,
-					 PCI_EXP_DEVCTL_EXT_TAG);
+	if (dev_cap & PCI_EXP_DEVCAP_EXT_TAG) {
+		supported = pcie_bus_exttags_supported(dev->bus);
+
+		if (supported) {
+			dev_dbg(&dev->dev, "setting extended tags capability\n");
+			pcie_capability_set_word(dev, PCI_EXP_DEVCTL,
+						 PCI_EXP_DEVCTL_EXT_TAG);
+		} else {
+			dev_dbg(&dev->dev, "clearing extended tags capability\n");
+			pcie_capability_clear_word(dev, PCI_EXP_DEVCTL,
+						   PCI_EXP_DEVCTL_EXT_TAG);
+		}
+	}
+	return 0;
 }
 
 static void pci_configure_device(struct pci_dev *dev)
@@ -1707,7 +1744,6 @@ static void pci_configure_device(struct pci_dev *dev)
 	int ret;
 
 	pci_configure_mps(dev);
-	pci_configure_extended_tags(dev);
 
 	memset(&hpp, 0, sizeof(hpp));
 	ret = pci_get_hp_params(dev, &hpp);
@@ -2224,6 +2260,8 @@ void pcie_bus_configure_settings(struct pci_bus *bus)
 
 	pcie_bus_configure_set(bus->self, &smpss);
 	pci_walk_bus(bus, pcie_bus_configure_set, &smpss);
+
+	pci_walk_bus(bus, pcie_bus_configure_exttags, NULL);
 }
 EXPORT_SYMBOL_GPL(pcie_bus_configure_settings);
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 68 lines · Sinan Kaya

According to extended tags ECN document, all PCIe receivers are expected to support extended tags support. It should be safe to enable extended tags on endpoints without checking compatibility.

This assumption seems to be working fine except for the legacy systems. The ECN has been written against PCIE spec version 2.0. Therefore, we need to exclude all version 1.0 devices from this change as there is HW out there that can't handle extended tags.

Note that the default value of Extended Tags Enable bit is implementation specific. Therefore, we are clearing the bit by default when incompatible HW is found without assuming that value is zero.

---
 drivers/pci/probe.c | 52 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 45 insertions(+), 7 deletions(-)
drivers/pci/probe.c +28 -2
index 19c8950..5e39013 100644
@@ -1684,21 +1684,58 @@ static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp)
         */
 }
 
-static void pci_configure_extended_tags(struct pci_dev *dev)
+static bool pcie_bus_exttags_supported(struct pci_bus *bus)
+{
+       bool exttags_supported = true;
+       struct pci_dev *bridge;
+       int rc;
+       u16 flags;
+
+       bridge = bus->self;
+       while (bridge) {
+               if (pci_is_pcie(bridge)) {
+                       rc = pcie_capability_read_word(bridge, PCI_EXP_FLAGS,
+                                                      &flags);
+                       if (!rc && ((flags & PCI_EXP_FLAGS_VERS) < 2)) {
+                               exttags_supported = false;
+                               break;
+                       }
+               }
+               if (!bridge->bus->parent)
+                       break;
+               bridge = bridge->bus->parent->self;
+       }
+
+       return exttags_supported;
+}
+
+static int pcie_bus_configure_exttags(struct pci_dev *dev, void *data)
 {
        u32 dev_cap;
        int ret;
+       bool supported;
 
        if (!pci_is_pcie(dev))
-               return;
+               return 0;
 
        ret = pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &dev_cap);

drivers/pci/probe.c static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp) · line 1727

Quoted 10 lines
drivers/pci/probe.c +4 -4
        if (ret)
-               return;
+               return 0;
 
-       if (dev_cap & PCI_EXP_DEVCAP_EXT_TAG)
-               pcie_capability_set_word(dev, PCI_EXP_DEVCTL,
-                                        PCI_EXP_DEVCTL_EXT_TAG);
+       if (dev_cap & PCI_EXP_DEVCAP_EXT_TAG) {
+               supported = pcie_bus_exttags_supported(dev->bus);
+

Maybe checking the version of this endpoint at first? Do you expect a v1 endpoint
to be working under v2+ ports?

Signature · 2 lines
Thanks,
Jike
author
#2 lore raw
Quoted 3 lines · Jike Song

Maybe checking the version of this endpoint at first? Do you expect a v1 endpoint
to be working under v2+ ports?

I see your point. I guess we need to validate both incoming and outgoing. I was only checking incoming direction.

Let me look at this one more time.

Signature · 3 lines
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.