lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [day] [month] [year] [list]
Date:   Thu, 17 Mar 2022 15:16:43 +0000
From:   "Khandelwal, Rajat" <rajat.khandelwal@...el.com>
To:     "pmalani@...omium.org" <pmalani@...omium.org>,
        "bleung@...omium.org" <bleung@...omium.org>,
        "groeck@...omium.org" <groeck@...omium.org>
CC:     "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "chrome-platform@...ts.linux.dev" <chrome-platform@...ts.linux.dev>,
        "Regupathy, Rajaram" <rajaram.regupathy@...el.com>,
        "Rao, Abhijeet" <abhijeet.rao@...el.com>
Subject: RE: [PATCH] "Active" sysfs attribute of typeC class should reflect
 the current state of active mode.

+Abhijeet

-----Original Message-----
From: Khandelwal, Rajat <rajat.khandelwal@...el.com> 
Sent: Thursday, March 17, 2022 7:58 PM
To: pmalani@...omium.org; bleung@...omium.org; groeck@...omium.org
Cc: linux-kernel@...r.kernel.org; chrome-platform@...ts.linux.dev; Khandelwal, Rajat <rajat.khandelwal@...el.com>; Regupathy, Rajaram <rajaram.regupathy@...el.com>
Subject: [PATCH] "Active" sysfs attribute of typeC class should reflect the current state of active mode.

The "active" attribute of typeC class doesn't reflect the current status of active mode. For eg., if the device is in DP alt mode, the corresponding active sysfs attribute doesn't reflect the output to be "yes". It still displays "no". Same goes for TBT alt mode.
As an eg, cat /sys/bus/typec/devices/port0-partner.1/active --> displays "no"! port0-partner.1 is the partner SVID created for TBT mode. On entering TBT mode, the active sysfs attribute should display "yes", but it displays "no". This patch fixes this.

Signed-off-by: Rajat-Khandelwal <rajat.khandelwal@...el.com>
---
 drivers/platform/chrome/cros_ec_typec.c | 41 +++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 5de0bfb0bc4d..798c58c75a7c 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -32,6 +32,12 @@ enum {
 	CROS_EC_ALTMODE_MAX,
 };
 
+/* Supported alt modes and their SVIDs. */ enum {
+	CROS_EC_ALTMODE_DP_SVID = 0xff01,
+	CROS_EC_ALTMODE_TBT_SVID = 0x8087,
+};
+
 /* Container for altmode pointer nodes. */  struct cros_typec_altmode_node {
 	struct typec_altmode *amode;
@@ -396,6 +402,7 @@ static int cros_typec_enable_tbt(struct cros_typec_data *typec,  {
 	struct cros_typec_port *port = typec->ports[port_num];
 	struct typec_thunderbolt_data data;
+	struct cros_typec_altmode_node *node, *n;
 	int ret;
 
 	if (typec->pd_ctrl_ver < 2) {
@@ -438,7 +445,14 @@ static int cros_typec_enable_tbt(struct cros_typec_data *typec,
 	port->state.data = &data;
 	port->state.mode = TYPEC_TBT_MODE;
 
-	return typec_mux_set(port->mux, &port->state);
+	ret = typec_mux_set(port->mux, &port->state);
+
+	list_for_each_entry_safe(node, n, &port->partner_mode_list, list) {
+		if (node->amode->svid == CROS_EC_ALTMODE_TBT_SVID && !ret)
+			typec_altmode_update_active(node->amode, true);
+	}
+
+	return ret;
 }
 
 /* Spoof the VDOs that were likely communicated by the partner. */ @@ -448,6 +462,7 @@ static int cros_typec_enable_dp(struct cros_typec_data *typec,  {
 	struct cros_typec_port *port = typec->ports[port_num];
 	struct typec_displayport_data dp_data;
+	struct cros_typec_altmode_node *node, *n;
 	int ret;
 
 	if (typec->pd_ctrl_ver < 2) {
@@ -480,7 +495,14 @@ static int cros_typec_enable_dp(struct cros_typec_data *typec,
 	port->state.data = &dp_data;
 	port->state.mode = TYPEC_MODAL_STATE(ffs(pd_ctrl->dp_mode));
 
-	return typec_mux_set(port->mux, &port->state);
+	ret = typec_mux_set(port->mux, &port->state);
+
+	list_for_each_entry_safe(node, n, &port->partner_mode_list, list) {
+		if (node->amode->svid == CROS_EC_ALTMODE_DP_SVID && !ret)
+			typec_altmode_update_active(node->amode, true);
+	}
+
+	return ret;
 }
 
 static int cros_typec_enable_usb4(struct cros_typec_data *typec, @@ -518,8 +540,23 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
 	struct cros_typec_port *port = typec->ports[port_num];
 	struct ec_params_usb_pd_mux_ack mux_ack;
 	enum typec_orientation orientation;
+	struct cros_typec_altmode_node *node, *n;
 	int ret;
 
+	if (mux_flags != USB_PD_MUX_DP_ENABLED && mux_flags != USB_PD_MUX_HPD_IRQ &&
+	mux_flags != USB_PD_MUX_HPD_LVL) {
+		list_for_each_entry_safe(node, n, &port->partner_mode_list, list) {
+			if (node->amode->svid == CROS_EC_ALTMODE_DP_SVID)
+				typec_altmode_update_active(node->amode, false);
+		}
+	}
+
+	if (mux_flags != USB_PD_MUX_TBT_COMPAT_ENABLED) {
+		list_for_each_entry_safe(node, n, &port->partner_mode_list, list) {
+			if (node->amode->svid == CROS_EC_ALTMODE_TBT_SVID)
+				typec_altmode_update_active(node->amode, false);
+		}
+	}
+
 	if (mux_flags == USB_PD_MUX_NONE) {
 		ret = cros_typec_usb_disconnect_state(port);
 		goto mux_ack;
--
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ