Skip to contentSkip to conversation

usb: typec: tcpm: Fix altmode re-registration causes sysfs create fail

PATCH RESEND In review [email protected] 2 participants 3 messages Jan 9, 2023 – Jan 13, 2023

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND v2 1/1 usb: typec: tcpm: Fix altmode re-registration causes sysfs create fail

From: ChiYuan Huang <[email protected]>

There's the altmode re-registeration issue after data role swap (DR_SWAP).

Comparing to USBPD 2.0, in USBPD 3.0, it loose the limit that only DFP can initiate the VDM command to get partner identity information.

For a USBPD 3.0 UFP device, it may already get the identity information from its port partner before DR_SWAP. If DR_SWAP send or receive at the mean time, 'send_discover' flag will be raised again. It causes discover identify action restart while entering ready state. And after all discover actions are done, the 'tcpm_register_altmodes' will be called. If old altmode is not unregistered, this sysfs create fail can be found.

In 'DR_SWAP_CHANGE_DR' state case, only DFP will unregister altmodes. For UFP, the original altmodes keep registered.

This patch fix the logic that after DR_SWAP, 'tcpm_unregister_altmodes' must be called whatever the current data role is.

Fixes ae8a2ca8a221 ("usb: typec: Group all TCPCI/TCPM code together)

---
Since v2:
- Correct the mail sent from Richtek.
- Add 'Reviewed-by' tag.

Hi, Greg:

Please check this one. I have strongly requested our MIS to remove the confidential string.

ChiYuan Huang.

---
 drivers/usb/typec/tcpm/tcpm.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +3 -4
index 904c7b4..59b366b 100644
@@ -4594,14 +4594,13 @@ static void run_state_machine(struct tcpm_port *port)
 		tcpm_set_state(port, ready_state(port), 0);
 		break;
 	case DR_SWAP_CHANGE_DR:
-		if (port->data_role == TYPEC_HOST) {
-			tcpm_unregister_altmodes(port);
+		tcpm_unregister_altmodes(port);
+		if (port->data_role == TYPEC_HOST)
 			tcpm_set_roles(port, true, port->pwr_role,
 				       TYPEC_DEVICE);
-		} else {
+		else
 			tcpm_set_roles(port, true, port->pwr_role,
 				       TYPEC_HOST);
-		}
 		tcpm_ams_finish(port);
 		tcpm_set_state(port, ready_state(port), 0);
 		break;
Signature · 1 line
2.7.4
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 18 lines · On Mon, Jan 09, 2023 at 03:19:50PM +0800, [email protected] wrote:

From: ChiYuan Huang <[email protected]>

There's the altmode re-registeration issue after data role swap (DR_SWAP).

Comparing to USBPD 2.0, in USBPD 3.0, it loose the limit that only DFP can initiate the VDM command to get partner identity information.

For a USBPD 3.0 UFP device, it may already get the identity information from its port partner before DR_SWAP. If DR_SWAP send or receive at the mean time, 'send_discover' flag will be raised again. It causes discover identify action restart while entering ready state. And after all discover actions are done, the 'tcpm_register_altmodes' will be called. If old altmode is not unregistered, this sysfs create fail can be found.

In 'DR_SWAP_CHANGE_DR' state case, only DFP will unregister altmodes. For UFP, the original altmodes keep registered.

Quoted 8 lines

This patch fix the logic that after DR_SWAP, 'tcpm_unregister_altmodes' must be called whatever the current data role is.

Fixes ae8a2ca8a221 ("usb: typec: Group all TCPCI/TCPM code together)
Quoted 38 lines

---
Since v2:
- Correct the mail sent from Richtek.
- Add 'Reviewed-by' tag.

Hi, Greg:

Please check this one. I have strongly requested our MIS to remove the confidential string.

ChiYuan Huang.

---
 drivers/usb/typec/tcpm/tcpm.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +3 -4
index 904c7b4..59b366b 100644
@@ -4594,14 +4594,13 @@ static void run_state_machine(struct tcpm_port *port)
 		tcpm_set_state(port, ready_state(port), 0);
 		break;
 	case DR_SWAP_CHANGE_DR:
-		if (port->data_role == TYPEC_HOST) {
-			tcpm_unregister_altmodes(port);
+		tcpm_unregister_altmodes(port);
+		if (port->data_role == TYPEC_HOST)
 			tcpm_set_roles(port, true, port->pwr_role,
 				       TYPEC_DEVICE);
-		} else {
+		else
 			tcpm_set_roles(port, true, port->pwr_role,
 				       TYPEC_HOST);
-		}
 		tcpm_ams_finish(port);
 		tcpm_set_state(port, ready_state(port), 0);
 		break;
Signature · 1 line
2.7.4
Signature · 1 line
heikki
#2 lore raw
In reply to [email protected]
Quoted 26 lines · On Mon, Jan 09, 2023 at 03:19:50PM +0800, [email protected] wrote:

From: ChiYuan Huang <[email protected]>

There's the altmode re-registeration issue after data role swap (DR_SWAP).

Comparing to USBPD 2.0, in USBPD 3.0, it loose the limit that only DFP can initiate the VDM command to get partner identity information.

For a USBPD 3.0 UFP device, it may already get the identity information from its port partner before DR_SWAP. If DR_SWAP send or receive at the mean time, 'send_discover' flag will be raised again. It causes discover identify action restart while entering ready state. And after all discover actions are done, the 'tcpm_register_altmodes' will be called. If old altmode is not unregistered, this sysfs create fail can be found.

In 'DR_SWAP_CHANGE_DR' state case, only DFP will unregister altmodes. For UFP, the original altmodes keep registered.

This patch fix the logic that after DR_SWAP, 'tcpm_unregister_altmodes' must be called whatever the current data role is.

Fixes ae8a2ca8a221 ("usb: typec: Group all TCPCI/TCPM code together)
Quoted 5 lines

---
Since v2:
- Correct the mail sent from Richtek.
- Add 'Reviewed-by' tag.

Sorry, it seems I focus on the email testing and forget to attach the issue log in the v2 patch appendix.

If anyone check this issue. Please refer to the v1 patch link.
https://lore.kernel.org/lkml/[email protected]/
Inside this, the issue log show how it happened.

This can help better analyze this issue.

ChiYuan Huang.

Quoted 34 lines

Hi, Greg:

Please check this one. I have strongly requested our MIS to remove the confidential string.

ChiYuan Huang.

---
 drivers/usb/typec/tcpm/tcpm.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +3 -4
index 904c7b4..59b366b 100644
@@ -4594,14 +4594,13 @@ static void run_state_machine(struct tcpm_port *port)
 		tcpm_set_state(port, ready_state(port), 0);
 		break;
 	case DR_SWAP_CHANGE_DR:
-		if (port->data_role == TYPEC_HOST) {
-			tcpm_unregister_altmodes(port);
+		tcpm_unregister_altmodes(port);
+		if (port->data_role == TYPEC_HOST)
 			tcpm_set_roles(port, true, port->pwr_role,
 				       TYPEC_DEVICE);
-		} else {
+		else
 			tcpm_set_roles(port, true, port->pwr_role,
 				       TYPEC_HOST);
-		}
 		tcpm_ams_finish(port);
 		tcpm_set_state(port, ready_state(port), 0);
 		break;
Signature · 1 line
2.7.4