drm/dp_mst: Fix drm RAD print
Subsystems (2)
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)
--- 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
@@ -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
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_UFPRAD[1] = (LCT_4_UFP << 4) | LCT_5_UFP ...In
drm_dp_mst_rad_to_str(), it wrongly to useBIT_MASK(4)to fetch the port number of one nibble.[How]
Adjust the code by:
- RAD array items are valuable only for LCT >= 1.
- Use0xFas the mask to replaceBIT_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]>Signed-off-by Wayne Lin <[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
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
[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 printQuoted 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_UFPRAD[1] = (LCT_4_UFP << 4) | LCT_5_UFP ...In
drm_dp_mst_rad_to_str(), it wrongly to useBIT_MASK(4)to fetch the port number of one nibble.[How]
Adjust the code by:
- RAD array items are valuable only for LCT >= 1.
- Use0xFas the mask to replaceBIT_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]>Signed-off-by Wayne Lin <[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
-0drivers/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:
Acked-by Imre Deak <[email protected]>
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