* [PATCH v2 0/1] usb: typec: ucsi: Check capabilities before discovery
@ 2024-03-15 17:18 Jameson Thies
2024-03-15 17:18 ` [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery Jameson Thies
0 siblings, 1 reply; 8+ messages in thread
From: Jameson Thies @ 2024-03-15 17:18 UTC (permalink / raw)
To: heikki.krogerus, linux-usb
Cc: jthies, pmalani, bleung, abhishekpandit, andersson,
dmitry.baryshkov, fabrice.gasnier, gregkh, hdegoede,
neil.armstrong, rajaram.regupathy, saranya.gopal, linux-kernel
Hi Heikki,
This patch updates the UCSI driver to better check the appropriate
capability bit before sending a UCSI command to discovery cable and
identity information.
These have been tested on a the usb-testing branch merged with a
chromeOS 6.8-rc2 kernel. Let me know if you have any questions.
Thanks,
Jameson
Jameson Thies (1):
usb: typec: ucsi: Check capabilities before cable and identity
discovery
drivers/usb/typec/ucsi/ucsi.c | 34 +++++++++++++++++++++-------------
drivers/usb/typec/ucsi/ucsi.h | 5 +++--
2 files changed, 24 insertions(+), 15 deletions(-)
base-commit: d99e42ce6b8341d3f09e22c6706461ec900fe172
--
2.44.0.291.gc1ea87d7ee-goog
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery
2024-03-15 17:18 [PATCH v2 0/1] usb: typec: ucsi: Check capabilities before discovery Jameson Thies
@ 2024-03-15 17:18 ` Jameson Thies
2024-03-15 17:22 ` neil.armstrong
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: Jameson Thies @ 2024-03-15 17:18 UTC (permalink / raw)
To: heikki.krogerus, linux-usb
Cc: jthies, pmalani, bleung, abhishekpandit, andersson,
dmitry.baryshkov, fabrice.gasnier, gregkh, hdegoede,
neil.armstrong, rajaram.regupathy, saranya.gopal, linux-kernel
Check the UCSI_CAP_GET_PD_MESSAGE bit before sending GET_PD_MESSAGE to
discover partner and cable identity, check UCSI_CAP_CABLE_DETAILS before
sending GET_CABLE_PROPERTY to discover the cable and check
UCSI_CAP_ALT_MODE_DETAILS before registering the a cable plug. Additionally,
move 8 bits from reserved_1 to features in the ucsi_capability struct. This
makes the field 16 bits, still 8 short of the 24 bits allocated for it in
UCSI v3.0, but it will not overflow because UCSI only defines 14 bits in
bmOptionalFeatures.
Fixes: 38ca416597b0 ("usb: typec: ucsi: Register cables based on GET_CABLE_PROPERTY")
Link: https://lore.kernel.org/linux-usb/44e8142f-d9b3-487b-83fe-39deadddb492@linaro.org
Suggested-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Jameson Thies <jthies@google.com>
---
Confirmed a device which supports GET_PD_MESSAGE, GET_CABLE_PROPERTY and
GET_ALTERNATE_MODES still requested identity and cable information.
drivers/usb/typec/ucsi/ucsi.c | 34 +++++++++++++++++++++-------------
drivers/usb/typec/ucsi/ucsi.h | 5 +++--
2 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index cf52cb34d2859..958dc82989b60 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1133,17 +1133,21 @@ static int ucsi_check_cable(struct ucsi_connector *con)
if (ret < 0)
return ret;
- ret = ucsi_get_cable_identity(con);
- if (ret < 0)
- return ret;
+ if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) {
+ ret = ucsi_get_cable_identity(con);
+ if (ret < 0)
+ return ret;
+ }
- ret = ucsi_register_plug(con);
- if (ret < 0)
- return ret;
+ if (con->ucsi->cap.features & UCSI_CAP_ALT_MODE_DETAILS) {
+ ret = ucsi_register_plug(con);
+ if (ret < 0)
+ return ret;
- ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
- if (ret < 0)
- return ret;
+ ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
+ if (ret < 0)
+ return ret;
+ }
return 0;
}
@@ -1189,8 +1193,10 @@ static void ucsi_handle_connector_change(struct work_struct *work)
ucsi_register_partner(con);
ucsi_partner_task(con, ucsi_check_connection, 1, HZ);
ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ);
- ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
- ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
+ if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
+ ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
+ if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
+ ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) ==
UCSI_CONSTAT_PWR_OPMODE_PD)
@@ -1589,8 +1595,10 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
ucsi_register_partner(con);
ucsi_pwr_opmode_change(con);
ucsi_port_psy_changed(con);
- ucsi_get_partner_identity(con);
- ucsi_check_cable(con);
+ if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
+ ucsi_get_partner_identity(con);
+ if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
+ ucsi_check_cable(con);
}
/* Only notify USB controller if partner supports USB data */
diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
index 32daf5f586505..0e7c92eb1b227 100644
--- a/drivers/usb/typec/ucsi/ucsi.h
+++ b/drivers/usb/typec/ucsi/ucsi.h
@@ -206,7 +206,7 @@ struct ucsi_capability {
#define UCSI_CAP_ATTR_POWER_OTHER BIT(10)
#define UCSI_CAP_ATTR_POWER_VBUS BIT(14)
u8 num_connectors;
- u8 features;
+ u16 features;
#define UCSI_CAP_SET_UOM BIT(0)
#define UCSI_CAP_SET_PDM BIT(1)
#define UCSI_CAP_ALT_MODE_DETAILS BIT(2)
@@ -215,7 +215,8 @@ struct ucsi_capability {
#define UCSI_CAP_CABLE_DETAILS BIT(5)
#define UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS BIT(6)
#define UCSI_CAP_PD_RESET BIT(7)
- u16 reserved_1;
+#define UCSI_CAP_GET_PD_MESSAGE BIT(8)
+ u8 reserved_1;
u8 num_alt_modes;
u8 reserved_2;
u16 bc_version;
--
2.44.0.291.gc1ea87d7ee-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery
2024-03-15 17:18 ` [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery Jameson Thies
@ 2024-03-15 17:22 ` neil.armstrong
2024-03-15 18:43 ` Benson Leung
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: neil.armstrong @ 2024-03-15 17:22 UTC (permalink / raw)
To: Jameson Thies, heikki.krogerus, linux-usb
Cc: pmalani, bleung, abhishekpandit, andersson, dmitry.baryshkov,
fabrice.gasnier, gregkh, hdegoede, rajaram.regupathy,
saranya.gopal, linux-kernel
Hi,
On 15/03/2024 18:18, Jameson Thies wrote:
> Check the UCSI_CAP_GET_PD_MESSAGE bit before sending GET_PD_MESSAGE to
> discover partner and cable identity, check UCSI_CAP_CABLE_DETAILS before
> sending GET_CABLE_PROPERTY to discover the cable and check
> UCSI_CAP_ALT_MODE_DETAILS before registering the a cable plug. Additionally,
> move 8 bits from reserved_1 to features in the ucsi_capability struct. This
> makes the field 16 bits, still 8 short of the 24 bits allocated for it in
> UCSI v3.0, but it will not overflow because UCSI only defines 14 bits in
> bmOptionalFeatures.
>
> Fixes: 38ca416597b0 ("usb: typec: ucsi: Register cables based on GET_CABLE_PROPERTY")
> Link: https://lore.kernel.org/linux-usb/44e8142f-d9b3-487b-83fe-39deadddb492@linaro.org
> Suggested-by: Neil Armstrong <neil.armstrong@linaro.org>
> Signed-off-by: Jameson Thies <jthies@google.com>
> ---
> Confirmed a device which supports GET_PD_MESSAGE, GET_CABLE_PROPERTY and
> GET_ALTERNATE_MODES still requested identity and cable information.
>
> drivers/usb/typec/ucsi/ucsi.c | 34 +++++++++++++++++++++-------------
> drivers/usb/typec/ucsi/ucsi.h | 5 +++--
> 2 files changed, 24 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index cf52cb34d2859..958dc82989b60 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1133,17 +1133,21 @@ static int ucsi_check_cable(struct ucsi_connector *con)
> if (ret < 0)
> return ret;
>
> - ret = ucsi_get_cable_identity(con);
> - if (ret < 0)
> - return ret;
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) {
> + ret = ucsi_get_cable_identity(con);
> + if (ret < 0)
> + return ret;
> + }
>
> - ret = ucsi_register_plug(con);
> - if (ret < 0)
> - return ret;
> + if (con->ucsi->cap.features & UCSI_CAP_ALT_MODE_DETAILS) {
> + ret = ucsi_register_plug(con);
> + if (ret < 0)
> + return ret;
>
> - ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
> - if (ret < 0)
> - return ret;
> + ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
> + if (ret < 0)
> + return ret;
> + }
>
> return 0;
> }
> @@ -1189,8 +1193,10 @@ static void ucsi_handle_connector_change(struct work_struct *work)
> ucsi_register_partner(con);
> ucsi_partner_task(con, ucsi_check_connection, 1, HZ);
> ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ);
> - ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
> - ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
> + ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
> + if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
> + ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
>
> if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) ==
> UCSI_CONSTAT_PWR_OPMODE_PD)
> @@ -1589,8 +1595,10 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
> ucsi_register_partner(con);
> ucsi_pwr_opmode_change(con);
> ucsi_port_psy_changed(con);
> - ucsi_get_partner_identity(con);
> - ucsi_check_cable(con);
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
> + ucsi_get_partner_identity(con);
> + if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
> + ucsi_check_cable(con);
> }
>
> /* Only notify USB controller if partner supports USB data */
> diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
> index 32daf5f586505..0e7c92eb1b227 100644
> --- a/drivers/usb/typec/ucsi/ucsi.h
> +++ b/drivers/usb/typec/ucsi/ucsi.h
> @@ -206,7 +206,7 @@ struct ucsi_capability {
> #define UCSI_CAP_ATTR_POWER_OTHER BIT(10)
> #define UCSI_CAP_ATTR_POWER_VBUS BIT(14)
> u8 num_connectors;
> - u8 features;
> + u16 features;
> #define UCSI_CAP_SET_UOM BIT(0)
> #define UCSI_CAP_SET_PDM BIT(1)
> #define UCSI_CAP_ALT_MODE_DETAILS BIT(2)
> @@ -215,7 +215,8 @@ struct ucsi_capability {
> #define UCSI_CAP_CABLE_DETAILS BIT(5)
> #define UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS BIT(6)
> #define UCSI_CAP_PD_RESET BIT(7)
> - u16 reserved_1;
> +#define UCSI_CAP_GET_PD_MESSAGE BIT(8)
> + u8 reserved_1;
> u8 num_alt_modes;
> u8 reserved_2;
> u16 bc_version;
It looks fine:
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
I'll run a test on the affected platforms in the next days and
report if it fixes the regression.
Thanks,
Neil
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery
2024-03-15 17:18 ` [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery Jameson Thies
2024-03-15 17:22 ` neil.armstrong
@ 2024-03-15 18:43 ` Benson Leung
2024-03-18 9:13 ` neil.armstrong
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Benson Leung @ 2024-03-15 18:43 UTC (permalink / raw)
To: Jameson Thies
Cc: heikki.krogerus, linux-usb, pmalani, abhishekpandit, andersson,
dmitry.baryshkov, fabrice.gasnier, gregkh, hdegoede,
neil.armstrong, rajaram.regupathy, saranya.gopal, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 4496 bytes --]
Hi Jameson,
On Fri, Mar 15, 2024 at 05:18:35PM +0000, Jameson Thies wrote:
> Check the UCSI_CAP_GET_PD_MESSAGE bit before sending GET_PD_MESSAGE to
> discover partner and cable identity, check UCSI_CAP_CABLE_DETAILS before
> sending GET_CABLE_PROPERTY to discover the cable and check
> UCSI_CAP_ALT_MODE_DETAILS before registering the a cable plug. Additionally,
> move 8 bits from reserved_1 to features in the ucsi_capability struct. This
> makes the field 16 bits, still 8 short of the 24 bits allocated for it in
> UCSI v3.0, but it will not overflow because UCSI only defines 14 bits in
> bmOptionalFeatures.
>
> Fixes: 38ca416597b0 ("usb: typec: ucsi: Register cables based on GET_CABLE_PROPERTY")
> Link: https://lore.kernel.org/linux-usb/44e8142f-d9b3-487b-83fe-39deadddb492@linaro.org
> Suggested-by: Neil Armstrong <neil.armstrong@linaro.org>
> Signed-off-by: Jameson Thies <jthies@google.com>
Reviewed-by: Benson Leung <bleung@chromium.org>
Thanks!
> ---
> Confirmed a device which supports GET_PD_MESSAGE, GET_CABLE_PROPERTY and
> GET_ALTERNATE_MODES still requested identity and cable information.
>
> drivers/usb/typec/ucsi/ucsi.c | 34 +++++++++++++++++++++-------------
> drivers/usb/typec/ucsi/ucsi.h | 5 +++--
> 2 files changed, 24 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index cf52cb34d2859..958dc82989b60 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1133,17 +1133,21 @@ static int ucsi_check_cable(struct ucsi_connector *con)
> if (ret < 0)
> return ret;
>
> - ret = ucsi_get_cable_identity(con);
> - if (ret < 0)
> - return ret;
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) {
> + ret = ucsi_get_cable_identity(con);
> + if (ret < 0)
> + return ret;
> + }
>
> - ret = ucsi_register_plug(con);
> - if (ret < 0)
> - return ret;
> + if (con->ucsi->cap.features & UCSI_CAP_ALT_MODE_DETAILS) {
> + ret = ucsi_register_plug(con);
> + if (ret < 0)
> + return ret;
>
> - ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
> - if (ret < 0)
> - return ret;
> + ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
> + if (ret < 0)
> + return ret;
> + }
>
> return 0;
> }
> @@ -1189,8 +1193,10 @@ static void ucsi_handle_connector_change(struct work_struct *work)
> ucsi_register_partner(con);
> ucsi_partner_task(con, ucsi_check_connection, 1, HZ);
> ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ);
> - ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
> - ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
> + ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
> + if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
> + ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
>
> if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) ==
> UCSI_CONSTAT_PWR_OPMODE_PD)
> @@ -1589,8 +1595,10 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
> ucsi_register_partner(con);
> ucsi_pwr_opmode_change(con);
> ucsi_port_psy_changed(con);
> - ucsi_get_partner_identity(con);
> - ucsi_check_cable(con);
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
> + ucsi_get_partner_identity(con);
> + if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
> + ucsi_check_cable(con);
> }
>
> /* Only notify USB controller if partner supports USB data */
> diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
> index 32daf5f586505..0e7c92eb1b227 100644
> --- a/drivers/usb/typec/ucsi/ucsi.h
> +++ b/drivers/usb/typec/ucsi/ucsi.h
> @@ -206,7 +206,7 @@ struct ucsi_capability {
> #define UCSI_CAP_ATTR_POWER_OTHER BIT(10)
> #define UCSI_CAP_ATTR_POWER_VBUS BIT(14)
> u8 num_connectors;
> - u8 features;
> + u16 features;
> #define UCSI_CAP_SET_UOM BIT(0)
> #define UCSI_CAP_SET_PDM BIT(1)
> #define UCSI_CAP_ALT_MODE_DETAILS BIT(2)
> @@ -215,7 +215,8 @@ struct ucsi_capability {
> #define UCSI_CAP_CABLE_DETAILS BIT(5)
> #define UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS BIT(6)
> #define UCSI_CAP_PD_RESET BIT(7)
> - u16 reserved_1;
> +#define UCSI_CAP_GET_PD_MESSAGE BIT(8)
> + u8 reserved_1;
> u8 num_alt_modes;
> u8 reserved_2;
> u16 bc_version;
> --
> 2.44.0.291.gc1ea87d7ee-goog
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery
2024-03-15 17:18 ` [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery Jameson Thies
2024-03-15 17:22 ` neil.armstrong
2024-03-15 18:43 ` Benson Leung
@ 2024-03-18 9:13 ` neil.armstrong
2024-03-18 11:11 ` Heikki Krogerus
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: neil.armstrong @ 2024-03-18 9:13 UTC (permalink / raw)
To: Jameson Thies, heikki.krogerus, linux-usb
Cc: pmalani, bleung, abhishekpandit, andersson, dmitry.baryshkov,
fabrice.gasnier, gregkh, hdegoede, rajaram.regupathy,
saranya.gopal, linux-kernel
On 15/03/2024 18:18, Jameson Thies wrote:
> Check the UCSI_CAP_GET_PD_MESSAGE bit before sending GET_PD_MESSAGE to
> discover partner and cable identity, check UCSI_CAP_CABLE_DETAILS before
> sending GET_CABLE_PROPERTY to discover the cable and check
> UCSI_CAP_ALT_MODE_DETAILS before registering the a cable plug. Additionally,
> move 8 bits from reserved_1 to features in the ucsi_capability struct. This
> makes the field 16 bits, still 8 short of the 24 bits allocated for it in
> UCSI v3.0, but it will not overflow because UCSI only defines 14 bits in
> bmOptionalFeatures.
>
> Fixes: 38ca416597b0 ("usb: typec: ucsi: Register cables based on GET_CABLE_PROPERTY")
> Link: https://lore.kernel.org/linux-usb/44e8142f-d9b3-487b-83fe-39deadddb492@linaro.org
> Suggested-by: Neil Armstrong <neil.armstrong@linaro.org>
> Signed-off-by: Jameson Thies <jthies@google.com>
> ---
> Confirmed a device which supports GET_PD_MESSAGE, GET_CABLE_PROPERTY and
> GET_ALTERNATE_MODES still requested identity and cable information.
>
> drivers/usb/typec/ucsi/ucsi.c | 34 +++++++++++++++++++++-------------
> drivers/usb/typec/ucsi/ucsi.h | 5 +++--
> 2 files changed, 24 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index cf52cb34d2859..958dc82989b60 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1133,17 +1133,21 @@ static int ucsi_check_cable(struct ucsi_connector *con)
> if (ret < 0)
> return ret;
>
> - ret = ucsi_get_cable_identity(con);
> - if (ret < 0)
> - return ret;
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) {
> + ret = ucsi_get_cable_identity(con);
> + if (ret < 0)
> + return ret;
> + }
>
> - ret = ucsi_register_plug(con);
> - if (ret < 0)
> - return ret;
> + if (con->ucsi->cap.features & UCSI_CAP_ALT_MODE_DETAILS) {
> + ret = ucsi_register_plug(con);
> + if (ret < 0)
> + return ret;
>
> - ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
> - if (ret < 0)
> - return ret;
> + ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
> + if (ret < 0)
> + return ret;
> + }
>
> return 0;
> }
> @@ -1189,8 +1193,10 @@ static void ucsi_handle_connector_change(struct work_struct *work)
> ucsi_register_partner(con);
> ucsi_partner_task(con, ucsi_check_connection, 1, HZ);
> ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ);
> - ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
> - ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
> + ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
> + if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
> + ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
>
> if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) ==
> UCSI_CONSTAT_PWR_OPMODE_PD)
> @@ -1589,8 +1595,10 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
> ucsi_register_partner(con);
> ucsi_pwr_opmode_change(con);
> ucsi_port_psy_changed(con);
> - ucsi_get_partner_identity(con);
> - ucsi_check_cable(con);
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
> + ucsi_get_partner_identity(con);
> + if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
> + ucsi_check_cable(con);
> }
>
> /* Only notify USB controller if partner supports USB data */
> diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
> index 32daf5f586505..0e7c92eb1b227 100644
> --- a/drivers/usb/typec/ucsi/ucsi.h
> +++ b/drivers/usb/typec/ucsi/ucsi.h
> @@ -206,7 +206,7 @@ struct ucsi_capability {
> #define UCSI_CAP_ATTR_POWER_OTHER BIT(10)
> #define UCSI_CAP_ATTR_POWER_VBUS BIT(14)
> u8 num_connectors;
> - u8 features;
> + u16 features;
> #define UCSI_CAP_SET_UOM BIT(0)
> #define UCSI_CAP_SET_PDM BIT(1)
> #define UCSI_CAP_ALT_MODE_DETAILS BIT(2)
> @@ -215,7 +215,8 @@ struct ucsi_capability {
> #define UCSI_CAP_CABLE_DETAILS BIT(5)
> #define UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS BIT(6)
> #define UCSI_CAP_PD_RESET BIT(7)
> - u16 reserved_1;
> +#define UCSI_CAP_GET_PD_MESSAGE BIT(8)
> + u8 reserved_1;
> u8 num_alt_modes;
> u8 reserved_2;
> u16 bc_version;
LGTM
Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8550-QRD
Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8650-QRD
Thanks,
Neil
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery
2024-03-15 17:18 ` [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery Jameson Thies
` (2 preceding siblings ...)
2024-03-18 9:13 ` neil.armstrong
@ 2024-03-18 11:11 ` Heikki Krogerus
2024-03-25 14:14 ` neil.armstrong
2024-03-27 1:46 ` Bjorn Andersson
5 siblings, 0 replies; 8+ messages in thread
From: Heikki Krogerus @ 2024-03-18 11:11 UTC (permalink / raw)
To: Jameson Thies
Cc: linux-usb, pmalani, bleung, abhishekpandit, andersson,
dmitry.baryshkov, fabrice.gasnier, gregkh, hdegoede,
neil.armstrong, rajaram.regupathy, saranya.gopal, linux-kernel
On Fri, Mar 15, 2024 at 05:18:35PM +0000, Jameson Thies wrote:
> Check the UCSI_CAP_GET_PD_MESSAGE bit before sending GET_PD_MESSAGE to
> discover partner and cable identity, check UCSI_CAP_CABLE_DETAILS before
> sending GET_CABLE_PROPERTY to discover the cable and check
> UCSI_CAP_ALT_MODE_DETAILS before registering the a cable plug. Additionally,
> move 8 bits from reserved_1 to features in the ucsi_capability struct. This
> makes the field 16 bits, still 8 short of the 24 bits allocated for it in
> UCSI v3.0, but it will not overflow because UCSI only defines 14 bits in
> bmOptionalFeatures.
>
> Fixes: 38ca416597b0 ("usb: typec: ucsi: Register cables based on GET_CABLE_PROPERTY")
> Link: https://lore.kernel.org/linux-usb/44e8142f-d9b3-487b-83fe-39deadddb492@linaro.org
> Suggested-by: Neil Armstrong <neil.armstrong@linaro.org>
> Signed-off-by: Jameson Thies <jthies@google.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> Confirmed a device which supports GET_PD_MESSAGE, GET_CABLE_PROPERTY and
> GET_ALTERNATE_MODES still requested identity and cable information.
>
> drivers/usb/typec/ucsi/ucsi.c | 34 +++++++++++++++++++++-------------
> drivers/usb/typec/ucsi/ucsi.h | 5 +++--
> 2 files changed, 24 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index cf52cb34d2859..958dc82989b60 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1133,17 +1133,21 @@ static int ucsi_check_cable(struct ucsi_connector *con)
> if (ret < 0)
> return ret;
>
> - ret = ucsi_get_cable_identity(con);
> - if (ret < 0)
> - return ret;
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) {
> + ret = ucsi_get_cable_identity(con);
> + if (ret < 0)
> + return ret;
> + }
>
> - ret = ucsi_register_plug(con);
> - if (ret < 0)
> - return ret;
> + if (con->ucsi->cap.features & UCSI_CAP_ALT_MODE_DETAILS) {
> + ret = ucsi_register_plug(con);
> + if (ret < 0)
> + return ret;
>
> - ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
> - if (ret < 0)
> - return ret;
> + ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
> + if (ret < 0)
> + return ret;
> + }
>
> return 0;
> }
> @@ -1189,8 +1193,10 @@ static void ucsi_handle_connector_change(struct work_struct *work)
> ucsi_register_partner(con);
> ucsi_partner_task(con, ucsi_check_connection, 1, HZ);
> ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ);
> - ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
> - ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
> + ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
> + if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
> + ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
>
> if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) ==
> UCSI_CONSTAT_PWR_OPMODE_PD)
> @@ -1589,8 +1595,10 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
> ucsi_register_partner(con);
> ucsi_pwr_opmode_change(con);
> ucsi_port_psy_changed(con);
> - ucsi_get_partner_identity(con);
> - ucsi_check_cable(con);
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
> + ucsi_get_partner_identity(con);
> + if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
> + ucsi_check_cable(con);
> }
>
> /* Only notify USB controller if partner supports USB data */
> diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
> index 32daf5f586505..0e7c92eb1b227 100644
> --- a/drivers/usb/typec/ucsi/ucsi.h
> +++ b/drivers/usb/typec/ucsi/ucsi.h
> @@ -206,7 +206,7 @@ struct ucsi_capability {
> #define UCSI_CAP_ATTR_POWER_OTHER BIT(10)
> #define UCSI_CAP_ATTR_POWER_VBUS BIT(14)
> u8 num_connectors;
> - u8 features;
> + u16 features;
> #define UCSI_CAP_SET_UOM BIT(0)
> #define UCSI_CAP_SET_PDM BIT(1)
> #define UCSI_CAP_ALT_MODE_DETAILS BIT(2)
> @@ -215,7 +215,8 @@ struct ucsi_capability {
> #define UCSI_CAP_CABLE_DETAILS BIT(5)
> #define UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS BIT(6)
> #define UCSI_CAP_PD_RESET BIT(7)
> - u16 reserved_1;
> +#define UCSI_CAP_GET_PD_MESSAGE BIT(8)
> + u8 reserved_1;
> u8 num_alt_modes;
> u8 reserved_2;
> u16 bc_version;
> --
> 2.44.0.291.gc1ea87d7ee-goog
--
heikki
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery
2024-03-15 17:18 ` [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery Jameson Thies
` (3 preceding siblings ...)
2024-03-18 11:11 ` Heikki Krogerus
@ 2024-03-25 14:14 ` neil.armstrong
2024-03-27 1:46 ` Bjorn Andersson
5 siblings, 0 replies; 8+ messages in thread
From: neil.armstrong @ 2024-03-25 14:14 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: linux-usb, heikki.krogerus, Jameson Thies, pmalani, bleung,
abhishekpandit, andersson, dmitry.baryshkov, fabrice.gasnier,
hdegoede, rajaram.regupathy, saranya.gopal, linux-kernel,
linux-arm-msm
Hi Greg,
On 15/03/2024 18:18, Jameson Thies wrote:
> Check the UCSI_CAP_GET_PD_MESSAGE bit before sending GET_PD_MESSAGE to
> discover partner and cable identity, check UCSI_CAP_CABLE_DETAILS before
> sending GET_CABLE_PROPERTY to discover the cable and check
> UCSI_CAP_ALT_MODE_DETAILS before registering the a cable plug. Additionally,
> move 8 bits from reserved_1 to features in the ucsi_capability struct. This
> makes the field 16 bits, still 8 short of the 24 bits allocated for it in
> UCSI v3.0, but it will not overflow because UCSI only defines 14 bits in
> bmOptionalFeatures.
>
> Fixes: 38ca416597b0 ("usb: typec: ucsi: Register cables based on GET_CABLE_PROPERTY")
> Link: https://lore.kernel.org/linux-usb/44e8142f-d9b3-487b-83fe-39deadddb492@linaro.org
> Suggested-by: Neil Armstrong <neil.armstrong@linaro.org>
> Signed-off-by: Jameson Thies <jthies@google.com>
Could you queue this for v6.9-rc2 ? So far most of the recent Qualcomm boards are waiting
this fix to be unbroken.
Thanks,
Neil
> ---
> Confirmed a device which supports GET_PD_MESSAGE, GET_CABLE_PROPERTY and
> GET_ALTERNATE_MODES still requested identity and cable information.
>
> drivers/usb/typec/ucsi/ucsi.c | 34 +++++++++++++++++++++-------------
> drivers/usb/typec/ucsi/ucsi.h | 5 +++--
> 2 files changed, 24 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index cf52cb34d2859..958dc82989b60 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1133,17 +1133,21 @@ static int ucsi_check_cable(struct ucsi_connector *con)
> if (ret < 0)
> return ret;
>
> - ret = ucsi_get_cable_identity(con);
> - if (ret < 0)
> - return ret;
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) {
> + ret = ucsi_get_cable_identity(con);
> + if (ret < 0)
> + return ret;
> + }
>
> - ret = ucsi_register_plug(con);
> - if (ret < 0)
> - return ret;
> + if (con->ucsi->cap.features & UCSI_CAP_ALT_MODE_DETAILS) {
> + ret = ucsi_register_plug(con);
> + if (ret < 0)
> + return ret;
>
> - ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
> - if (ret < 0)
> - return ret;
> + ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
> + if (ret < 0)
> + return ret;
> + }
>
> return 0;
> }
> @@ -1189,8 +1193,10 @@ static void ucsi_handle_connector_change(struct work_struct *work)
> ucsi_register_partner(con);
> ucsi_partner_task(con, ucsi_check_connection, 1, HZ);
> ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ);
> - ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
> - ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
> + ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
> + if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
> + ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
>
> if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) ==
> UCSI_CONSTAT_PWR_OPMODE_PD)
> @@ -1589,8 +1595,10 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
> ucsi_register_partner(con);
> ucsi_pwr_opmode_change(con);
> ucsi_port_psy_changed(con);
> - ucsi_get_partner_identity(con);
> - ucsi_check_cable(con);
> + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
> + ucsi_get_partner_identity(con);
> + if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
> + ucsi_check_cable(con);
> }
>
> /* Only notify USB controller if partner supports USB data */
> diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
> index 32daf5f586505..0e7c92eb1b227 100644
> --- a/drivers/usb/typec/ucsi/ucsi.h
> +++ b/drivers/usb/typec/ucsi/ucsi.h
> @@ -206,7 +206,7 @@ struct ucsi_capability {
> #define UCSI_CAP_ATTR_POWER_OTHER BIT(10)
> #define UCSI_CAP_ATTR_POWER_VBUS BIT(14)
> u8 num_connectors;
> - u8 features;
> + u16 features;
> #define UCSI_CAP_SET_UOM BIT(0)
> #define UCSI_CAP_SET_PDM BIT(1)
> #define UCSI_CAP_ALT_MODE_DETAILS BIT(2)
> @@ -215,7 +215,8 @@ struct ucsi_capability {
> #define UCSI_CAP_CABLE_DETAILS BIT(5)
> #define UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS BIT(6)
> #define UCSI_CAP_PD_RESET BIT(7)
> - u16 reserved_1;
> +#define UCSI_CAP_GET_PD_MESSAGE BIT(8)
> + u8 reserved_1;
> u8 num_alt_modes;
> u8 reserved_2;
> u16 bc_version;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery
2024-03-15 17:18 ` [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery Jameson Thies
` (4 preceding siblings ...)
2024-03-25 14:14 ` neil.armstrong
@ 2024-03-27 1:46 ` Bjorn Andersson
5 siblings, 0 replies; 8+ messages in thread
From: Bjorn Andersson @ 2024-03-27 1:46 UTC (permalink / raw)
To: Jameson Thies
Cc: heikki.krogerus, linux-usb, pmalani, bleung, abhishekpandit,
andersson, dmitry.baryshkov, fabrice.gasnier, gregkh, hdegoede,
neil.armstrong, rajaram.regupathy, saranya.gopal, linux-kernel
On Fri, Mar 15, 2024 at 05:18:35PM +0000, Jameson Thies wrote:
> Check the UCSI_CAP_GET_PD_MESSAGE bit before sending GET_PD_MESSAGE to
> discover partner and cable identity, check UCSI_CAP_CABLE_DETAILS before
> sending GET_CABLE_PROPERTY to discover the cable and check
> UCSI_CAP_ALT_MODE_DETAILS before registering the a cable plug. Additionally,
> move 8 bits from reserved_1 to features in the ucsi_capability struct. This
> makes the field 16 bits, still 8 short of the 24 bits allocated for it in
> UCSI v3.0, but it will not overflow because UCSI only defines 14 bits in
> bmOptionalFeatures.
>
> Fixes: 38ca416597b0 ("usb: typec: ucsi: Register cables based on GET_CABLE_PROPERTY")
> Link: https://lore.kernel.org/linux-usb/44e8142f-d9b3-487b-83fe-39deadddb492@linaro.org
> Suggested-by: Neil Armstrong <neil.armstrong@linaro.org>
> Signed-off-by: Jameson Thies <jthies@google.com>
Thanks you, Jameson, this resolve the regression I ran into on
qcs6490-rb3gen2 as well.
Tested-by: Bjorn Andersson <quic_bjorande@quicinc.com> # QCS6490 Rb3Gen2
Regards,
Bjorn
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-03-27 1:46 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-15 17:18 [PATCH v2 0/1] usb: typec: ucsi: Check capabilities before discovery Jameson Thies
2024-03-15 17:18 ` [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery Jameson Thies
2024-03-15 17:22 ` neil.armstrong
2024-03-15 18:43 ` Benson Leung
2024-03-18 9:13 ` neil.armstrong
2024-03-18 11:11 ` Heikki Krogerus
2024-03-25 14:14 ` neil.armstrong
2024-03-27 1:46 ` Bjorn Andersson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).