Skip to contentSkip to conversation

drm/amd/display: fix return value of dm_dp_aux_transfer() (V2)

PATCH In review Shirish S 3 participants 6 messages Apr 18, 2018 – Apr 27, 2018 5 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Shirish S

author
#0 lore raw

PATCH 1/1 drm/amd/display: fix return value of dm_dp_aux_transfer() (V2)

Currently the dm_dp_aux_transfer() does not parse
the return value of dal_ddc_service_read_dpcd_data(), which also has a failure case.
This patch captures the same and ensures the i2c operation status is sent appropriately to the drm framework.

V2: Updated commit message.

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +5 -1
index 782491e..7ac124d 100644
@@ -115,7 +115,11 @@ static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux,
 				msg->address,
 				msg->buffer,
 				msg->size);
-		return read_bytes;
+		if (read_bytes != msg->size &&
+		    read_bytes >= DDC_RESULT_FAILED_OPERATION)
+			return -EIO;
+		else
+			return read_bytes;
 	case DP_AUX_I2C_WRITE:
 		res = dal_ddc_service_write_dpcd_data(
 				TO_DM_AUX(aux)->ddc_service,
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1524020209-8481-1-git-send-email-shirish.s-5C7GfCeVMHo@public.gmane.org

#2 lore raw
Quoted 18 lines · Shirish S

Currently the dm_dp_aux_transfer() does not parse
the return value of dal_ddc_service_read_dpcd_data(), which also has a failure case.
This patch captures the same and ensures the i2c operation status is sent appropriately to the drm framework.

V2: Updated commit message.

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +0 -0
index 782491e..7ac124d 100644

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux, · line 119

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +2 -1
@@ -115,7 +115,11 @@ static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux,
 				msg->address,
 				msg->buffer,
 				msg->size);
-		return read_bytes;
+		if (read_bytes != msg->size &&
+		    read_bytes >= DDC_RESULT_FAILED_OPERATION)

This doesn't look right. We shouldn't be returning the size or error code from the same function. This will not work if we submit a read 7 or 8 bytes and get an error.

Harry

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux, · line 125

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +3 -0
+			return -EIO;
+		else
+			return read_bytes;
 	case DP_AUX_I2C_WRITE:
 		res = dal_ddc_service_write_dpcd_data(
 				TO_DM_AUX(aux)->ddc_service,

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 3fa10009-7ef6-666f-a9ba-9888200be8ff-5C7GfCeVMHo@public.gmane.org

#4 lore raw
Quoted 14 lines · Harry Wentland
Quoted 13 lines · Shirish S

Currently the dm_dp_aux_transfer() does not parse
the return value of dal_ddc_service_read_dpcd_data(), which also has a failure case.
This patch captures the same and ensures the i2c operation status is sent appropriately to the drm framework.

V2: Updated commit message.

---
  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
Quoted 12 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux, · line 119

Quoted 11 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +2 -1
index 782491e..7ac124d 100644
@@ -115,7 +115,11 @@ static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux,
  				msg->address,
  				msg->buffer,
  				msg->size);
-		return read_bytes;
+		if (read_bytes != msg->size &&
+		    read_bytes >= DDC_RESULT_FAILED_OPERATION)

This doesn't look right. We shouldn't be returning the size or error code from the same function. This will not work if we submit a read 7 or 8 bytes and get an error.

Agree,  but hope you understood the issue, to re-iterate, in case of failure we reuturn a +ve number(7 or 8) back from dm_dp_aux_transfer() leading to edid read failures later. I have 2 suggestions:
1. change the "enum ddc_result {" to #defines of -ve error codes? or
2. make enum start with 129 (> than the max read_bytes possible)?
let me know which one would be better?
Thanks,
Regards,
Shirish S

Quoted 10 lines

Harry

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux, · line 125

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +3 -0
+			return -EIO;
+		else
+			return read_bytes;
  	case DP_AUX_I2C_WRITE:
  		res = dal_ddc_service_write_dpcd_data(
  				TO_DM_AUX(aux)->ddc_service,

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): f1a2e63b-db81-d24e-9535-1d22af84efb1-5C7GfCeVMHo@public.gmane.org

#6 lore raw
Quoted 31 lines · Shirish
Quoted 15 lines · Harry Wentland
Quoted 14 lines · Shirish S

Currently the dm_dp_aux_transfer() does not parse
the return value of dal_ddc_service_read_dpcd_data(), which also has a failure case.
This patch captures the same and ensures the i2c operation status is sent appropriately to the drm framework.

V2: Updated commit message.

---
  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c | 6
+++++-

  1 file changed, 5 insertions(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c static ssize_t dm_dp_aux_transfer(struct · line 120

Quoted 12 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +2 -1
index 782491e..7ac124d 100644
@@ -115,7 +115,11 @@ static ssize_t dm_dp_aux_transfer(struct 
 drm_dp_aux *aux,
                   msg->address,
                   msg->buffer,
                   msg->size);
-        return read_bytes;
+        if (read_bytes != msg->size &&
+            read_bytes >= DDC_RESULT_FAILED_OPERATION)

This doesn't look right. We shouldn't be returning the size or error code from the same function. This will not work if we submit a read 7 or 8 bytes and get an error.

Quoted 5 lines

Agree,  but hope you understood the issue, to re-iterate, in case of failure we reuturn a +ve number(7 or 8) back from dm_dp_aux_transfer() leading to edid read failures later. I have 2 suggestions:
1. change the "enum ddc_result {" to #defines of -ve error codes? or
2. make enum start with 129 (> than the max read_bytes possible)?
let me know which one would be better?

Any suggestions?

Quoted 14 lines

Thanks,
Regards,
Shirish S

Quoted 10 lines

Harry

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +3 -0
+            return -EIO;
+        else
+            return read_bytes;

      case DP_AUX_I2C_WRITE:
          res = dal_ddc_service_write_dpcd_data(
                  TO_DM_AUX(aux)->ddc_service,

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): f4520258-7efc-d19e-49b1-81ff6becc269-5C7GfCeVMHo@public.gmane.org

#8 lore raw

PATCH 1/1 drm/amd/display: Don't return ddc result and read_bytes in same return value

The two ranges overlap.

---

Thinking of something like this if this works for you.

Harry

 .../display/amdgpu_dm/amdgpu_dm_mst_types.c   | 20 +++++++++++--------
 .../gpu/drm/amd/display/dc/core/dc_link_ddc.c | 10 +++++++---
 .../gpu/drm/amd/display/dc/inc/dc_link_ddc.h  |  5 +++--
 3 files changed, 22 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +12 -8
index c3f3028253c3..b8dd7496b7bc 100644
@@ -83,21 +83,22 @@ static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux,
 	enum i2c_mot_mode mot = (msg->request & DP_AUX_I2C_MOT) ?
 		I2C_MOT_TRUE : I2C_MOT_FALSE;
 	enum ddc_result res;
-	ssize_t read_bytes;
+	uint32_t read_bytes = msg->size;
 
 	if (WARN_ON(msg->size > 16))
 		return -E2BIG;
 
 	switch (msg->request & ~DP_AUX_I2C_MOT) {
 	case DP_AUX_NATIVE_READ:
-		read_bytes = dal_ddc_service_read_dpcd_data(
+		res = dal_ddc_service_read_dpcd_data(
 				TO_DM_AUX(aux)->ddc_service,
 				false,
 				I2C_MOT_UNDEF,
 				msg->address,
 				msg->buffer,
-				msg->size);
-		return read_bytes;
+				msg->size,
+				&read_bytes);
+		break;
 	case DP_AUX_NATIVE_WRITE:
 		res = dal_ddc_service_write_dpcd_data(
 				TO_DM_AUX(aux)->ddc_service,
@@ -108,14 +109,15 @@ static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux,
 				msg->size);
 		break;
 	case DP_AUX_I2C_READ:
-		read_bytes = dal_ddc_service_read_dpcd_data(
+		res = dal_ddc_service_read_dpcd_data(
 				TO_DM_AUX(aux)->ddc_service,
 				true,
 				mot,
 				msg->address,
 				msg->buffer,
-				msg->size);
-		return read_bytes;
+				msg->size,
+				&read_bytes);
+		break;
 	case DP_AUX_I2C_WRITE:
 		res = dal_ddc_service_write_dpcd_data(
 				TO_DM_AUX(aux)->ddc_service,
@@ -137,7 +139,9 @@ static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux,
 		 r == DDC_RESULT_SUCESSFULL);
 #endif
 
-	return msg->size;
+	if (res != DDC_RESULT_SUCESSFULL)
+		return -EIO;
+	return read_bytes;
 }
 
 static enum drm_connector_status
drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c +7 -3
index 49c2face1e7a..ae48d603ebd6 100644
@@ -629,13 +629,14 @@ bool dal_ddc_service_query_ddc_data(
 	return ret;
 }
 
-ssize_t dal_ddc_service_read_dpcd_data(
+enum ddc_result dal_ddc_service_read_dpcd_data(
 	struct ddc_service *ddc,
 	bool i2c,
 	enum i2c_mot_mode mot,
 	uint32_t address,
 	uint8_t *data,
-	uint32_t len)
+	uint32_t len,
+	uint32_t *read)
 {
 	struct aux_payload read_payload = {
 		.i2c_over_aux = i2c,
@@ -652,6 +653,8 @@ ssize_t dal_ddc_service_read_dpcd_data(
 		.mot = mot
 	};
 
+	*read = 0;
+
 	if (len > DEFAULT_AUX_MAX_DATA_SIZE) {
 		BREAK_TO_DEBUGGER();
 		return DDC_RESULT_FAILED_INVALID_OPERATION;
@@ -661,7 +664,8 @@ ssize_t dal_ddc_service_read_dpcd_data(
 		ddc->ctx->i2caux,
 		ddc->ddc_pin,
 		&command)) {
-		return (ssize_t)command.payloads->length;
+		*read = command.payloads->length;
+		return DDC_RESULT_SUCESSFULL;
 	}
 
 	return DDC_RESULT_FAILED_OPERATION;
drivers/gpu/drm/amd/display/dc/inc/dc_link_ddc.h +3 -2
index 090b7a8dd67b..30b3a08b91be 100644
@@ -102,13 +102,14 @@ bool dal_ddc_service_query_ddc_data(
 		uint8_t *read_buf,
 		uint32_t read_size);
 
-ssize_t dal_ddc_service_read_dpcd_data(
+enum ddc_result dal_ddc_service_read_dpcd_data(
 		struct ddc_service *ddc,
 		bool i2c,
 		enum i2c_mot_mode mot,
 		uint32_t address,
 		uint8_t *data,
-		uint32_t len);
+		uint32_t len,
+		uint32_t *read);
 
 enum ddc_result dal_ddc_service_write_dpcd_data(
 		struct ddc_service *ddc,
Signature · 6 lines
2.17.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20180424152710.7810-1-harry.wentland-5C7GfCeVMHo@public.gmane.org

author
#10 lore raw

RE: [PATCH] drm/amd/display: Don't return ddc result and read_bytes in same return value

Thanks Harry, it works.

Patch is Reviewed-by: Shirish S <[email protected]>

Regards,
Shirish S

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Harry Wentland
Sent: Tuesday, April 24, 2018 8:57 PM
To: [email protected]; S, Shirish <[email protected]>; Deucher, Alexander <[email protected]>; S, Shirish <[email protected]>
Cc: Wentland, Harry <[email protected]>
Subject: [PATCH] drm/amd/display: Don't return ddc result and read_bytes in same return value

The two ranges overlap.

---

Thinking of something like this if this works for you.

Harry

 .../display/amdgpu_dm/amdgpu_dm_mst_types.c   | 20 +++++++++++--------
 .../gpu/drm/amd/display/dc/core/dc_link_ddc.c | 10 +++++++---
 .../gpu/drm/amd/display/dc/inc/dc_link_ddc.h  |  5 +++--
 3 files changed, 22 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +12 -8
index c3f3028253c3..b8dd7496b7bc 100644
@@ -83,21 +83,22 @@ static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux,
 	enum i2c_mot_mode mot = (msg->request & DP_AUX_I2C_MOT) ?
 		I2C_MOT_TRUE : I2C_MOT_FALSE;
 	enum ddc_result res;
-	ssize_t read_bytes;
+	uint32_t read_bytes = msg->size;
 
 	if (WARN_ON(msg->size > 16))
 		return -E2BIG;
 
 	switch (msg->request & ~DP_AUX_I2C_MOT) {
 	case DP_AUX_NATIVE_READ:
-		read_bytes = dal_ddc_service_read_dpcd_data(
+		res = dal_ddc_service_read_dpcd_data(
 				TO_DM_AUX(aux)->ddc_service,
 				false,
 				I2C_MOT_UNDEF,
 				msg->address,
 				msg->buffer,
-				msg->size);
-		return read_bytes;
+				msg->size,
+				&read_bytes);
+		break;
 	case DP_AUX_NATIVE_WRITE:
 		res = dal_ddc_service_write_dpcd_data(
 				TO_DM_AUX(aux)->ddc_service,
@@ -108,14 +109,15 @@ static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux,
 				msg->size);
 		break;
 	case DP_AUX_I2C_READ:
-		read_bytes = dal_ddc_service_read_dpcd_data(
+		res = dal_ddc_service_read_dpcd_data(
 				TO_DM_AUX(aux)->ddc_service,
 				true,
 				mot,
 				msg->address,
 				msg->buffer,
-				msg->size);
-		return read_bytes;
+				msg->size,
+				&read_bytes);
+		break;
 	case DP_AUX_I2C_WRITE:
 		res = dal_ddc_service_write_dpcd_data(
 				TO_DM_AUX(aux)->ddc_service,
@@ -137,7 +139,9 @@ static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux,
 		 r == DDC_RESULT_SUCESSFULL);
 #endif
 
-	return msg->size;
+	if (res != DDC_RESULT_SUCESSFULL)
+		return -EIO;
+	return read_bytes;
 }
 
 static enum drm_connector_status
drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c +7 -3
index 49c2face1e7a..ae48d603ebd6 100644
@@ -629,13 +629,14 @@ bool dal_ddc_service_query_ddc_data(
 	return ret;
 }
 
-ssize_t dal_ddc_service_read_dpcd_data(
+enum ddc_result dal_ddc_service_read_dpcd_data(
 	struct ddc_service *ddc,
 	bool i2c,
 	enum i2c_mot_mode mot,
 	uint32_t address,
 	uint8_t *data,
-	uint32_t len)
+	uint32_t len,
+	uint32_t *read)
 {
 	struct aux_payload read_payload = {
 		.i2c_over_aux = i2c,
@@ -652,6 +653,8 @@ ssize_t dal_ddc_service_read_dpcd_data(
 		.mot = mot
 	};
 
+	*read = 0;
+
 	if (len > DEFAULT_AUX_MAX_DATA_SIZE) {
 		BREAK_TO_DEBUGGER();
 		return DDC_RESULT_FAILED_INVALID_OPERATION;
@@ -661,7 +664,8 @@ ssize_t dal_ddc_service_read_dpcd_data(
 		ddc->ctx->i2caux,
 		ddc->ddc_pin,
 		&command)) {
-		return (ssize_t)command.payloads->length;
+		*read = command.payloads->length;
+		return DDC_RESULT_SUCESSFULL;
 	}
 
 	return DDC_RESULT_FAILED_OPERATION;
drivers/gpu/drm/amd/display/dc/inc/dc_link_ddc.h +3 -2
index 090b7a8dd67b..30b3a08b91be 100644
@@ -102,13 +102,14 @@ bool dal_ddc_service_query_ddc_data(
 		uint8_t *read_buf,
 		uint32_t read_size);
 
-ssize_t dal_ddc_service_read_dpcd_data(
+enum ddc_result dal_ddc_service_read_dpcd_data(
 		struct ddc_service *ddc,
 		bool i2c,
 		enum i2c_mot_mode mot,
 		uint32_t address,
 		uint8_t *data,
-		uint32_t len);
+		uint32_t len,
+		uint32_t *read);
 
 enum ddc_result dal_ddc_service_write_dpcd_data(
 		struct ddc_service *ddc,
Signature · 10 lines
2.17.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx