Skip to contentSkip to conversation

drm/dp_mst: Fix drm RAD print

PATCH Superseded Wayne Lin 2 participants 3 messages Nov 27, 2024 – Dec 2, 2024

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Wayne Lin

author
#0 lore raw

PATCH 1/1 drm/dp_mst: Fix drm RAD print

[Why]
The RAD of sideband message printed today is incorrect.
For RAD stored within MST branch
- If MST branch LCT is 1, it's RAD array is untouched and remained as 0.
- If MST branch LCT is larger than 1, usd nibble to store the up facing port number in cascaded sequence as illustrated below:

u8 RAD[0] = (LCT_2_UFP << 4) | LCT_3_UFP

     RAD[1] = (LCT_4_UFP << 4) | LCT_5_UFP
     ...

In drm_dp_mst_rad_to_str(), it wrongly to use BIT_MASK(4) to fetch the port number of one nibble.

[How]
Adjust the code by:
- RAD array items are valuable only for LCT >= 1.
- Use 0xF as the mask to replace BIT_MASK(4)

Fixes 2f015ec6eab6 ("drm/dp_mst: Add sideband down request tracing + selftests")
Cc Imre Deak <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Lyude Paul <[email protected]>
---
 drivers/gpu/drm/display/drm_dp_mst_topology.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/display/drm_dp_mst_topology.c +4 -4
index f7c6b60629c2..152c60f1e80f 100644
@@ -179,13 +179,13 @@ static int
 drm_dp_mst_rad_to_str(const u8 rad[8], u8 lct, char *out, size_t len)
 {
 	int i;
-	u8 unpacked_rad[16];
+	u8 unpacked_rad[16] = {0};
 
-	for (i = 0; i < lct; i++) {
+	for (i = 1; i < lct; i++) {
 		if (i % 2)
-			unpacked_rad[i] = rad[i / 2] >> 4;
+			unpacked_rad[i] = rad[(i - 1) / 2] >> 4;
 		else
-			unpacked_rad[i] = rad[i / 2] & BIT_MASK(4);
+			unpacked_rad[i] = rad[(i - 1) / 2] & 0xF;
 	}
 
 	/* TODO: Eventually add something to printk so we can format the rad
Signature · 1 line
2.37.3
Acked-by on v1 1/1
#1 lore raw
Quoted 34 lines · Wayne Lin

[Why]
The RAD of sideband message printed today is incorrect.
For RAD stored within MST branch
- If MST branch LCT is 1, it's RAD array is untouched and remained as 0.
- If MST branch LCT is larger than 1, usd nibble to store the up facing port number in cascaded sequence as illustrated below:

u8 RAD[0] = (LCT_2_UFP << 4) | LCT_3_UFP

     RAD[1] = (LCT_4_UFP << 4) | LCT_5_UFP
     ...

In drm_dp_mst_rad_to_str(), it wrongly to use BIT_MASK(4) to fetch the port number of one nibble.

[How]
Adjust the code by:
- RAD array items are valuable only for LCT >= 1.
- Use 0xF as the mask to replace BIT_MASK(4)

Fixes 2f015ec6eab6 ("drm/dp_mst: Add sideband down request tracing + selftests")
Cc Imre Deak <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Lyude Paul <[email protected]>
---
 drivers/gpu/drm/display/drm_dp_mst_topology.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/display/drm_dp_mst_topology.c +0 -0
index f7c6b60629c2..152c60f1e80f 100644

drivers/gpu/drm/display/drm_dp_mst_topology.c static int · line 182

Quoted 5 lines
drivers/gpu/drm/display/drm_dp_mst_topology.c +1 -1
@@ -179,13 +179,13 @@ static int
 drm_dp_mst_rad_to_str(const u8 rad[8], u8 lct, char *out, size_t len)
 {
 	int i;
-	u8 unpacked_rad[16];
+	u8 unpacked_rad[16] = {0};

The usual way is arr[16] = {};

drivers/gpu/drm/display/drm_dp_mst_topology.c static int · line 189

Quoted 10 lines
drivers/gpu/drm/display/drm_dp_mst_topology.c +3 -3
-	for (i = 0; i < lct; i++) {
+	for (i = 1; i < lct; i++) {
 		if (i % 2)
-			unpacked_rad[i] = rad[i / 2] >> 4;
+			unpacked_rad[i] = rad[(i - 1) / 2] >> 4;
 		else
-			unpacked_rad[i] = rad[i / 2] & BIT_MASK(4);
+			unpacked_rad[i] = rad[(i - 1) / 2] & 0xF;
 	}

So unpacked_rad[0] will be always zero, which represents drm_dp_mst_topology_mgr::mst_primary, but not actually stored in drm_dp_mst_branch::rad[]. In each element of rad[] the nibbles are ordered the most signifcant 4 bits first and the least significant 4 bits second. This could be documented at drm_dp_mst_branch::rad[] imo.

The fix looks ok to me:

drm_dp_get_mst_branch_device() needs the same logic as above extracting one element of RAD at a given index, so a helper for this could be added and used in both places.

Quoted 5 lines
drivers/gpu/drm/display/drm_dp_mst_topology.c +0 -0
 	/* TODO: Eventually add something to printk so we can format the rad
Signature · 1 line
2.37.3
author
#2 lore raw

[Public]

Hi Imre,

Thanks for your time and suggestions!
I'll adjust it and send out v2 later.

Thanks,
Wayne

Quoted 82 lines

-----Original Message-----
From: Imre Deak <[email protected]>
Sent: Saturday, November 30, 2024 4:24 AM
To: Lin, Wayne <[email protected]>
Cc: [email protected]; [email protected]; Ville Syrjälä <[email protected]>; Wentland, Harry <[email protected]>
Subject: Re: [PATCH] drm/dp_mst: Fix drm RAD print

Quoted 36 lines · Wayne Lin

[Why]
The RAD of sideband message printed today is incorrect.
For RAD stored within MST branch
- If MST branch LCT is 1, it's RAD array is untouched and remained as 0.
- If MST branch LCT is larger than 1, usd nibble to store the up facing port number in cascaded sequence as illustrated below:

u8 RAD[0] = (LCT_2_UFP << 4) | LCT_3_UFP

     RAD[1] = (LCT_4_UFP << 4) | LCT_5_UFP
     ...

In drm_dp_mst_rad_to_str(), it wrongly to use BIT_MASK(4) to fetch the port number of one nibble.

[How]
Adjust the code by:
- RAD array items are valuable only for LCT >= 1.
- Use 0xF as the mask to replace BIT_MASK(4)

Fixes 2f015ec6eab6 ("drm/dp_mst: Add sideband down request tracing +

selftests")

Cc Imre Deak <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Lyude Paul <[email protected]>
---
 drivers/gpu/drm/display/drm_dp_mst_topology.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/display/drm_dp_mst_topology.c +0 -0
index f7c6b60629c2..152c60f1e80f 100644

drivers/gpu/drm/display/drm_dp_mst_topology.c static int · line 182

Quoted 5 lines
drivers/gpu/drm/display/drm_dp_mst_topology.c +1 -1
@@ -179,13 +179,13 @@ static int
 drm_dp_mst_rad_to_str(const u8 rad[8], u8 lct, char *out, size_t len)
 {
    int i;
-   u8 unpacked_rad[16];
+   u8 unpacked_rad[16] = {0};

The usual way is arr[16] = {};

drivers/gpu/drm/display/drm_dp_mst_topology.c static int · line 189

Quoted 10 lines
drivers/gpu/drm/display/drm_dp_mst_topology.c +3 -3
-   for (i = 0; i < lct; i++) {
+   for (i = 1; i < lct; i++) {
            if (i % 2)
-                   unpacked_rad[i] = rad[i / 2] >> 4;
+                   unpacked_rad[i] = rad[(i - 1) / 2] >> 4;
            else
-                   unpacked_rad[i] = rad[i / 2] & BIT_MASK(4);
+                   unpacked_rad[i] = rad[(i - 1) / 2] & 0xF;
    }

So unpacked_rad[0] will be always zero, which represents drm_dp_mst_topology_mgr::mst_primary, but not actually stored in drm_dp_mst_branch::rad[]. In each element of rad[] the nibbles are ordered the most signifcant 4 bits first and the least significant 4 bits second. This could be documented at drm_dp_mst_branch::rad[] imo.

The fix looks ok to me:

drm_dp_get_mst_branch_device() needs the same logic as above extracting one element of RAD at a given index, so a helper for this could be added and used in both places.

Quoted 5 lines
drivers/gpu/drm/display/drm_dp_mst_topology.c +0 -1
    /* TODO: Eventually add something to printk so we can format the rad
--

2.37.3