diff mbox series

[14/14] hdata: Parse extra NVLink info

Message ID 20170915054059.32109-14-oohall@gmail.com
State Accepted
Headers show
Series [01/14] core/pci-dt-slot: Represent PCIe slots in the devicetree | expand

Commit Message

Oliver O'Halloran Sept. 15, 2017, 5:40 a.m. UTC
Add parsing for the link speed information and the OCC GPU presence
flags.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 hdata/spira.c | 30 +++++++++++++++++++++++++++++-
 hdata/spira.h |  3 +++
 2 files changed, 32 insertions(+), 1 deletion(-)

Comments

Reza Arbab Sept. 15, 2017, 4:01 p.m. UTC | #1
On Fri, Sep 15, 2017 at 05:40:59AM +0000, Oliver O'Halloran wrote:
>Add parsing for the link speed information and the OCC GPU presence
>flags.

Now that we have this, should d5fa66c74a19 ("hw/npu2.c: Add ibm, 
nvlink-speed device-tree property") be reverted?
diff mbox series

Patch

diff --git a/hdata/spira.c b/hdata/spira.c
index 73a678f42b86..5e3d6ccc05d5 100644
--- a/hdata/spira.c
+++ b/hdata/spira.c
@@ -1288,9 +1288,10 @@  static void add_npu(struct dt_node *xscom, const struct HDIF_array_hdr *links,
 	int group_target[6]; /* Tracks the PCI slot targeted each link group */
 	int group_count = 0;
 	int link_count = 0;
-	uint32_t chip_id;
+	uint32_t size, chip_id;
 	int i;
 
+	size = be32_to_cpu(links->esize);
 	chip_id = dt_get_chip_id(xscom);
 
 	memset(group_target, 0, sizeof(group_target));
@@ -1307,6 +1308,7 @@  static void add_npu(struct dt_node *xscom, const struct HDIF_array_hdr *links,
 	HDIF_iarray_for_each(links, i, link) {
 		uint16_t slot_id = be16_to_cpu(link->pci_slot_idx);
 		uint32_t link_id = be32_to_cpu(link->link_id);
+		uint64_t speed = 0, nvlink_speed = 0;
 		struct dt_node *node;
 
 		/* only add a link node if this link is targeted at at device */
@@ -1403,6 +1405,32 @@  static void add_npu(struct dt_node *xscom, const struct HDIF_array_hdr *links,
 			dt_add_property_cells(node, "ibm,pcie-slot",
 					slot->phandle);
 		}
+
+		/* Newer fields which might not be populated */
+		if (size <= 0x24)
+			continue;
+
+		switch (be32_to_cpu(link->link_speed)) {
+			case 0: /* 20Gbps */
+				speed = 20000000000ul;
+				nvlink_speed = 0x3;
+				break;
+			case 1: /* 25Gbps */
+				speed = 25000000000ul;
+				nvlink_speed = 0x9;
+				break;
+			case 2: /* 25.78125 Gbps */
+				nvlink_speed =  0x8;
+				speed = 25781250000ul;
+				break;
+		}
+
+		/* ibm,link-speed is in bps and nvidia,link-speed is ~magic~ */
+		dt_add_property_u64s(node, "ibm,link-speed", speed);
+		dt_add_property_cells(node, "nvidia,link-speed", nvlink_speed);
+
+		dt_add_property_cells(node, DT_PRIVATE "occ-flag-pos",
+				PPC_BIT(link->occ_flag_bit));
 	}
 
 	dt_add_property_cells(npu, "ibm,npu-links", link_count);
diff --git a/hdata/spira.h b/hdata/spira.h
index 9b427cb7a0c2..f850c790160f 100644
--- a/hdata/spira.h
+++ b/hdata/spira.h
@@ -1178,6 +1178,9 @@  struct sppcrd_smp_link {
 	__be32 i2c_link_cable;
 	__be32 i2c_presence;
 	__be32 i2c_micro;
+	uint8_t link_speed;
+	uint8_t occ_flag_bit;
+	__be16 gpu_slca;
 } __packed;
 
 /*