Skip to contentSkip to conversation

sparc64: pci slots information is not populated in sysfs

RFC PATCH Superseded Eric Snowberg 3 participants 8 messages Apr 27, 2015 – Apr 28, 2015 SPARC + UltraSPARC (sparc/sparc64)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 sparc64: pci slots information is not populated in sysfs

Add PCI slot numbers within sysfs for sun4v hardware. Larger sun4v systems contain nested PCI bridges and slots further down on these bridges were not being populated within sysfs. Also add AHCI style PCI slot numbers within sysfs for sun4v hardware since the OF 'slot-names' information is not available on all sun4v platforms.

---
 arch/sparc/kernel/pci.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
arch/sparc/kernel/pci.c +37 -0
index 6f7251f..3a5c402 100644
@@ -1002,6 +1002,38 @@ static int __init pcibios_init(void)
 subsys_initcall(pcibios_init);
 
 #ifdef CONFIG_SYSFS
+
+#define SLOT_NAME_SIZE  11  /* Max decimal digits + null in u32 */
+
+static void pci_sun4v_bus_slot_names(struct pci_bus *pbus)
+{
+	struct pci_dev *pdev;
+	struct pci_bus *bus;
+
+	list_for_each_entry(pdev, &pbus->devices, bus_list) {
+		char name[SLOT_NAME_SIZE];
+		struct pci_slot *pci_slot;
+		const u32 *slot_num;
+		int len;
+
+		slot_num = of_get_property(pdev->dev.of_node,
+					   "physical-slot#", &len);
+
+		if (slot_num = NULL || len != 4)
+			continue;
+
+		snprintf(name, sizeof(name), "%u", slot_num[0]);
+		pci_slot = pci_create_slot(pbus, slot_num[0], name, NULL);
+
+		if (IS_ERR(pci_slot))
+			pr_err("PCI: pci_create_slot returned %ld.\n",
+			       PTR_ERR(pci_slot));
+	}
+
+	list_for_each_entry(bus, &pbus->children, node)
+		pci_sun4v_bus_slot_names(bus);
+}
+
 static void pci_bus_slot_names(struct device_node *node, struct pci_bus *bus)
 {
 	const struct pci_slot_names {
@@ -1054,6 +1086,11 @@ static int __init of_pci_slot_init(void)
 	while ((pbus = pci_find_next_bus(pbus)) != NULL) {
 		struct device_node *node;
 
+		if (tlb_type = hypervisor) {
+			pci_sun4v_bus_slot_names(pbus);
+			continue;
+		}
+
 		if (pbus->self) {
 			/* PCI->PCI bridge */
 			node = pbus->self->dev.of_node;
Signature · 1 line
1.7.1
#1 lore raw

Hi Eric,

Quoted 4 lines · Eric Snowberg

Add PCI slot numbers within sysfs for sun4v hardware. Larger sun4v systems contain nested PCI bridges and slots further down on these bridges were not being populated within sysfs. Also add AHCI style PCI slot numbers within sysfs for sun4v

You mean ACPI, right?

Quoted 2 lines

hardware since the OF 'slot-names' information is not available on all sun4v platforms.

That doesn't seem to match the actual code, which appears to skip to the next device if it can't find the "physical-slot#" OF property: I don't see how the code can fall back to any other method of determining the slot number.

Quoted 49 lines
---
 arch/sparc/kernel/pci.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
arch/sparc/kernel/pci.c +32 -0
index 6f7251f..3a5c402 100644
@@ -1002,6 +1002,38 @@ static int __init pcibios_init(void)
 subsys_initcall(pcibios_init);
 
 #ifdef CONFIG_SYSFS
+
+#define SLOT_NAME_SIZE  11  /* Max decimal digits + null in u32 */
+
+static void pci_sun4v_bus_slot_names(struct pci_bus *pbus)
+{
+       struct pci_dev *pdev;
+       struct pci_bus *bus;
+
+       list_for_each_entry(pdev, &pbus->devices, bus_list) {
+               char name[SLOT_NAME_SIZE];
+               struct pci_slot *pci_slot;
+               const u32 *slot_num;
+               int len;
+
+               slot_num = of_get_property(pdev->dev.of_node,
+                                          "physical-slot#", &len);
+
+               if (slot_num = NULL || len != 4)
+                       continue;
+
+               snprintf(name, sizeof(name), "%u", slot_num[0]);
+               pci_slot = pci_create_slot(pbus, slot_num[0], name, NULL);
+
+               if (IS_ERR(pci_slot))
+                       pr_err("PCI: pci_create_slot returned %ld.\n",
+                              PTR_ERR(pci_slot));
+       }
+
+       list_for_each_entry(bus, &pbus->children, node)
+               pci_sun4v_bus_slot_names(bus);
+}
+
 static void pci_bus_slot_names(struct device_node *node, struct pci_bus *bus)
 {
        const struct pci_slot_names {

arch/sparc/kernel/pci.c static int __init of_pci_slot_init(void) · line 1091

Quoted 6 lines
arch/sparc/kernel/pci.c +3 -0
@@ -1054,6 +1086,11 @@ static int __init of_pci_slot_init(void)
        while ((pbus = pci_find_next_bus(pbus)) != NULL) {
                struct device_node *node;
 
+               if (tlb_type = hypervisor) {
+                       pci_sun4v_bus_slot_names(pbus);
+                       continue;

Are you sure that unconditionally continuing to the next bus is the right thing to do here?

Where is the slot name set if we can't find the "physical-slot#" property for a device?

arch/sparc/kernel/pci.c static int __init of_pci_slot_init(void) · line 1096

Quoted 5 lines
arch/sparc/kernel/pci.c +2 -0
+               }
+
                if (pbus->self) {
                        /* PCI->PCI bridge */
                        node = pbus->self->dev.of_node;

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
#2 lore raw
In reply to Eric Snowberg

Hi Eric,

(Quoting screwed up due to Eric replying with a HTML message which was probably dropped by vger.)

Quoted 30 lines · Eric Snowberg

On Apr 27, 2015, at 5:42 PM, Julian Calaby <[email protected]> wrote:

Hi Eric,

On Tue, Apr 28, 2015 at 8:07 AM, Eric Snowberg <[email protected]> wrote:

Add PCI slot numbers within sysfs for sun4v hardware. Larger sun4v systems contain nested PCI bridges and slots further down on these bridges were not being populated within sysfs. Also add AHCI style PCI slot numbers within sysfs for sun4v

You mean ACPI, right?

You are correct, I’ll update the comment.

hardware since the OF 'slot-names' information is not available on all sun4v platforms.

That doesn't seem to match the actual code, which appears to skip to the next device if it can't find the "physical-slot#" OF property: I don't see how the code can fall back to any other method of determining the slot number.

Quoted 7 lines

Correct, with this patch on sun4v systems only the ‘physical-slot#’ field is used. All other system types use the old method. With the current code, I could not find a single sun4v system where slot numbers would ever show up. I tried this out on a T2, T5, and T7. All with latest released OBP firmware. Either the ‘slot-names’ field was buried or it was not present. Since I could not find a sun4v system where it worked, I did not create a fall back method.

Ah, I thought you meant that not all sun4v systems had the "physical-slot#" property, hence my confusion when your code assumed that they all did.

Quoted 66 lines

---
arch/sparc/kernel/pci.c | 37 +++++++++++++++++++++++++++++++++++++

1 files changed, 37 insertions(+), 0 deletions(-)
arch/sparc/kernel/pci.c +32 -0
index 6f7251f..3a5c402 100644
@@ -1002,6 +1002,38 @@ static int __init pcibios_init(void)
 subsys_initcall(pcibios_init);
 
 #ifdef CONFIG_SYSFS
+
+#define SLOT_NAME_SIZE  11  /* Max decimal digits + null in u32 */
+
+static void pci_sun4v_bus_slot_names(struct pci_bus *pbus)
+{
+       struct pci_dev *pdev;
+       struct pci_bus *bus;
+
+       list_for_each_entry(pdev, &pbus->devices, bus_list) {
+               char name[SLOT_NAME_SIZE];
+               struct pci_slot *pci_slot;
+               const u32 *slot_num;
+               int len;
+
+               slot_num = of_get_property(pdev->dev.of_node,
+                                          "physical-slot#", &len);
+
+               if (slot_num = NULL || len != 4)
+                       continue;
+
+               snprintf(name, sizeof(name), "%u", slot_num[0]);
+               pci_slot = pci_create_slot(pbus, slot_num[0], name, NULL);
+
+               if (IS_ERR(pci_slot))
+                       pr_err("PCI: pci_create_slot returned %ld.\n",
+                              PTR_ERR(pci_slot));
+       }
+
+       list_for_each_entry(bus, &pbus->children, node)
+               pci_sun4v_bus_slot_names(bus);
+}
+

static void pci_bus_slot_names(struct device_node *node, struct pci_bus *bus)

{
       const struct pci_slot_names {
arch/sparc/kernel/pci.c +3 -0
@@ -1054,6 +1086,11 @@ static int __init of_pci_slot_init(void)
       while ((pbus = pci_find_next_bus(pbus)) != NULL) {
               struct device_node *node;
 
+               if (tlb_type = hypervisor) {
+                       pci_sun4v_bus_slot_names(pbus);
+                       continue;
 
 

Are you sure that unconditionally continuing to the next bus is the right thing to do here?

I believe so, I am using the same recursive pattern in pci_sun4v_bus_slot_names found throughout this file.

Quoted 6 lines

Where is the slot name set if we can't find the "physical-slot#" property for a device?

My understanding is if a device does not have a ‘physical-slot#’ then the device is not in a physical PCI slot, so it should not have a slot name.

Ok, that makes sense.

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
maintainer
#3 lore raw
In reply to Eric Snowberg

From: Julian Calaby <[email protected]>
Date: Tue, 28 Apr 2015 12:46:15 +1000

Quoted 2 lines

(Quoting screwed up due to Eric replying with a HTML message which was probably dropped by vger.)

Eric's patch posting was plain ASCII text, made it to the list, and made it into patchwork as well.

#4 lore raw
In reply to Eric Snowberg

Hi David,

Quoted 8 lines · David Miller

From: Julian Calaby <[email protected]>
Date: Tue, 28 Apr 2015 12:46:15 +1000

Quoted 2 lines

(Quoting screwed up due to Eric replying with a HTML message which was probably dropped by vger.)

Eric's patch posting was plain ASCII text, made it to the list, and made it into patchwork as well.

I was referring to his reply to my questions.

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
maintainer
#5 lore raw
In reply to Eric Snowberg

From: Julian Calaby <[email protected]>
Date: Tue, 28 Apr 2015 13:04:55 +1000

Quoted 6 lines

Hi David,

Quoted 3 lines · David Miller

From: Julian Calaby <[email protected]>
Date: Tue, 28 Apr 2015 12:46:15 +1000

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

(Quoting screwed up due to Eric replying with a HTML message which was probably dropped by vger.)

Eric's patch posting was plain ASCII text, made it to the list, and made it into patchwork as well.

I was referring to his reply to my questions.

My bad, I see what happened now, thanks for explaining.

#6 lore raw
In reply to Eric Snowberg

Hi Eric,

Quoted 17 lines · Eric Snowberg

Add PCI slot numbers within sysfs for sun4v hardware. Larger sun4v systems contain nested PCI bridges and slots further down on these bridges were not being populated within sysfs. Also add AHCI style PCI slot numbers within sysfs for sun4v hardware since the OF 'slot-names' information is not available on all sun4v platforms.

---
 arch/sparc/kernel/pci.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
arch/sparc/kernel/pci.c +0 -0
index 6f7251f..3a5c402 100644

arch/sparc/kernel/pci.c static int __init of_pci_slot_init(void) · line 1093

Quoted 8 lines
arch/sparc/kernel/pci.c +5 -0
@@ -1054,6 +1086,11 @@ static int __init of_pci_slot_init(void)
        while ((pbus = pci_find_next_bus(pbus)) != NULL) {
                struct device_node *node;
 
+               if (tlb_type == hypervisor) {
+                       pci_sun4v_bus_slot_names(pbus);
+                       continue;
+               }
+

One last thing: would it be worth it to put the following before the while loop instead of having the test inside it? I dislike invariant tests in loops. (Incremental patch attached)

+ if (tlb_type == hypervisor) {
+ while ((pbus = pci_find_next_bus(pbus)) != NULL)
+ pci_sun4v_bus_slot_names(pbus);
+
+ return 0;
+ }

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/

From 0a9175addfde57ba6d7255a6db0bb65316fd861c Mon Sep 17 00:00:00 2001
From: Julian Calaby <[email protected]>
Date: Tue, 28 Apr 2015 20:45:49 +1000
Subject: [PATCH] sparc64: pci: Move hypervisor test out of loop

---
 arch/sparc/kernel/pci.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
arch/sparc/kernel/pci.c +7 -5
index 3a5c402..d5f06bd 100644
@@ -1083,14 +1083,16 @@ static int __init of_pci_slot_init(void)
 {
 	struct pci_bus *pbus = NULL;
 
+	if (tlb_type == hypervisor) {
+		while ((pbus = pci_find_next_bus(pbus)) != NULL)
+			pci_sun4v_bus_slot_names(pbus);
+
+		return 0;
+	}
+
 	while ((pbus = pci_find_next_bus(pbus)) != NULL) {
 		struct device_node *node;
 
-		if (tlb_type == hypervisor) {
-			pci_sun4v_bus_slot_names(pbus);
-			continue;
-		}
-
 		if (pbus->self) {
 			/* PCI->PCI bridge */
 			node = pbus->self->dev.of_node;
Signature · 1 line
2.1.4
#7 lore raw
In reply to Eric Snowberg

arch/sparc/kernel/pci.c static int __init of_pci_slot_init(void)

Quoted 13 lines · Julian Calaby

One last thing: would it be worth it to put the following before the while loop instead of having the test inside it? I dislike invariant tests in loops. (Incremental patch attached)

arch/sparc/kernel/pci.c +6 -0
+        if (tlb_type = hypervisor) {
+                while ((pbus = pci_find_next_bus(pbus)) != NULL)
+                        pci_sun4v_bus_slot_names(pbus);
+
+                return 0;
+        }

That make sense, I’ll update the patch with this change.

Thanks,
-Eric