2020-11-19 06:35:41

by Patel, Utkarsh H

[permalink] [raw]
Subject: [PATCH v3 0/4] Thunderbolt3/USB4 cable rounded and active cable plug link training support

This patch series adds the support for Thunderbolt3/USB4 rounded and
non-rounded frequencies cables and fixes the active cable plug link
training support.

Changes in v3:
- First four patches of this series have been queued by Greg to usb-testing
branch. https://www.spinics.net/lists/linux-usb/msg204880.html
- Changed commit message and description in header file in patch 1/4.
- Added a check for Cable's TBT support in patch 2/4
- Moved TBT_CABLE_ROUNDED_SUPPORT assignment to same line in patch 3/4.
- Rebased and added Reviewed-by tag in patch 4/4.

Changes in v2:
- Removed the fixes tag as there is no functional implication from patches
1/8, 2/8 and 4/8.

Utkarsh Patel (4):
usb: typec: Use Thunderbolt 3 cable discover mode VDO in Enter_USB
message
platform/chrome: cros_ec_typec: Use Thunderbolt 3 cable discover mode
VDO in USB4 mode
usb: typec: intel_pmc_mux: Configure active cable properties for USB4
usb: typec: Remove active_link_training variable from Enter_USB
message

drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
drivers/usb/typec/mux/intel_pmc_mux.c | 17 ++++++++++++++---
include/linux/usb/typec.h | 11 +++++------
3 files changed, 31 insertions(+), 11 deletions(-)

--
2.17.1


2020-11-19 06:36:24

by Patel, Utkarsh H

[permalink] [raw]
Subject: [PATCH v3 4/4] usb: typec: Remove active_link_training variable from Enter_USB message

Thunderbolt 3 cable discover mode VDO support has been added as part of
Enter_USB message to fill details of active cable plug link training.
Hence, removing unused variable active_link_training from Enter_USB
message data structure.

Signed-off-by: Utkarsh Patel <[email protected]>
Reviewed-by: Heikki Krogerus <[email protected]>

--
Changes in v3:
- Rebased and Added Reviewed-by tag.

Changes in v2:
- No change.
--
---
include/linux/usb/typec.h | 6 ------
1 file changed, 6 deletions(-)

diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index 25731ed863fa..d26824a30ff9 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -79,16 +79,10 @@ enum typec_orientation {
* @tbt_cable_vdo needs to be filled with details of active cable plug link
* training and cable rounded support when thunderbolt 3 cable is being used to
* create USB4 connection. Do not fill this in case of USB4 cable.
- * @active_link_training: Active Cable Plug Link Training
- *
- * @active_link_training is a flag that should be set with uni-directional SBRX
- * communication, and left 0 with passive cables and with bi-directional SBRX
- * communication.
*/
struct enter_usb_data {
u32 eudo;
u32 tbt_cable_vdo;
- unsigned char active_link_training:1;
};

/*
--
2.17.1

2020-11-19 06:36:50

by Patel, Utkarsh H

[permalink] [raw]
Subject: [PATCH v3 1/4] usb: typec: Use Thunderbolt 3 cable discover mode VDO in Enter_USB message

When Thunderbolt 3 cable is being used to create USB4 connection, use
Thunderbolt 3 discover mode VDO to fill details such as active cable plug
link training and cable rounded support.
With USB4 cables, these VDO members need not be filled.

Suggested-by: Heikki Krogerus <[email protected]>
Signed-off-by: Utkarsh Patel <[email protected]>

--
Changes in v3:
- Changed the commit mesage to reflect why TBT3 VDO is being used.
- Added more details in the header file about the usage of TBT3 VDO.

Changes in v2:
- No change.
--
---
include/linux/usb/typec.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index 6be558045942..25731ed863fa 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -75,6 +75,10 @@ enum typec_orientation {
/*
* struct enter_usb_data - Enter_USB Message details
* @eudo: Enter_USB Data Object
+ * @tbt_cable_vdo: TBT3 Cable Discover Mode Response
+ * @tbt_cable_vdo needs to be filled with details of active cable plug link
+ * training and cable rounded support when thunderbolt 3 cable is being used to
+ * create USB4 connection. Do not fill this in case of USB4 cable.
* @active_link_training: Active Cable Plug Link Training
*
* @active_link_training is a flag that should be set with uni-directional SBRX
@@ -83,6 +87,7 @@ enum typec_orientation {
*/
struct enter_usb_data {
u32 eudo;
+ u32 tbt_cable_vdo;
unsigned char active_link_training:1;
};

--
2.17.1

2020-11-19 06:36:54

by Patel, Utkarsh H

[permalink] [raw]
Subject: [PATCH v3 2/4] platform/chrome: cros_ec_typec: Use Thunderbolt 3 cable discover mode VDO in USB4 mode

Configure Thunderbolt 3 cable generation value by filling Thunderbolt 3
cable discover mode VDO to support rounded Thunderbolt 3 cables.
While we are here use Thunderbolt 3 cable discover mode VDO to fill active
cable plug link training value.

Suggested-by: Heikki Krogerus <[email protected]>
Signed-off-by: Utkarsh Patel <[email protected]>

--
Changes in v3:
- Added a check for cable's TBT support before filling TBT3 discover mode
VDO.

Changes in v2:
- No change.
--
---
drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 8111ed1fc574..68b17ee1d1ae 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -514,8 +514,18 @@ static int cros_typec_enable_usb4(struct cros_typec_data *typec,
else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE)
data.eudo |= EUDO_CABLE_TYPE_RE_TIMER << EUDO_CABLE_TYPE_SHIFT;

- data.active_link_training = !!(pd_ctrl->control_flags &
- USB_PD_CTRL_ACTIVE_LINK_UNIDIR);
+ /*
+ * Filling TBT3 Cable VDO when TBT3 cable is being used to establish
+ * USB4 connection.
+ */
+ if (pd_ctrl->cable_gen) {
+ data.tbt_cable_vdo = TBT_MODE;
+
+ if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
+ data.tbt_cable_vdo |= TBT_CABLE_LINK_TRAINING;
+
+ data.tbt_cable_vdo |= TBT_SET_CABLE_ROUNDED(pd_ctrl->cable_gen);
+ }

port->state.alt = NULL;
port->state.data = &data;
--
2.17.1

2020-11-19 06:38:04

by Patel, Utkarsh H

[permalink] [raw]
Subject: [PATCH v3 3/4] usb: typec: intel_pmc_mux: Configure active cable properties for USB4

Value received as a part of Thunderbolt 3 cable discover mode VDO needs
to be configured in the USB4 mode for the cable rounded support and
active cable plug link training.

Suggested-by: Heikki Krogerus <[email protected]>
Signed-off-by: Utkarsh Patel <[email protected]>

--
Changes in v3:
- Moved TBT_CABLE_ROUNDED_SUPPORT assignment to the same line.

Changes in v2:
- No change.
--
---
drivers/usb/typec/mux/intel_pmc_mux.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/intel_pmc_mux.c
index aa3211f1c4c3..baf343b14682 100644
--- a/drivers/usb/typec/mux/intel_pmc_mux.c
+++ b/drivers/usb/typec/mux/intel_pmc_mux.c
@@ -295,6 +295,7 @@ pmc_usb_mux_usb4(struct pmc_usb_port *port, struct typec_mux_state *state)
{
struct enter_usb_data *data = state->data;
struct altmode_req req = { };
+ u8 cable_rounded;
u8 cable_speed;

if (IOM_PORT_ACTIVITY_IS(port->iom_status, TBT) ||
@@ -308,9 +309,6 @@ pmc_usb_mux_usb4(struct pmc_usb_port *port, struct typec_mux_state *state)
/* USB4 Mode */
req.mode_data = PMC_USB_ALTMODE_FORCE_LSR;

- if (data->active_link_training)
- req.mode_data |= PMC_USB_ALTMODE_ACTIVE_LINK;
-
req.mode_data |= (port->orientation - 1) << PMC_USB_ALTMODE_ORI_SHIFT;
req.mode_data |= (port->role - 1) << PMC_USB_ALTMODE_UFP_SHIFT;

@@ -322,6 +320,19 @@ pmc_usb_mux_usb4(struct pmc_usb_port *port, struct typec_mux_state *state)
fallthrough;
default:
req.mode_data |= PMC_USB_ALTMODE_ACTIVE_CABLE;
+
+ if (data->tbt_cable_vdo) {
+ /* Active Thunderbolt 3 cable */
+ if (data->tbt_cable_vdo & TBT_CABLE_LINK_TRAINING)
+ req.mode_data |= PMC_USB_ALTMODE_ACTIVE_LINK;
+
+ cable_rounded = TBT_CABLE_ROUNDED_SUPPORT(data->tbt_cable_vdo);
+ req.mode_data |= PMC_USB_ALTMODE_TBT_GEN(cable_rounded);
+ } else {
+ /* Active USB4 cable */
+ req.mode_data |= PMC_USB_ALTMODE_ACTIVE_LINK |
+ PMC_USB_ALTMODE_TBT_GEN(1);
+ }
break;
}

--
2.17.1

2020-11-19 08:13:07

by Prashant Malani

[permalink] [raw]
Subject: Re: [PATCH v3 2/4] platform/chrome: cros_ec_typec: Use Thunderbolt 3 cable discover mode VDO in USB4 mode

Hi Utkarsh,

On Wed, Nov 18, 2020 at 10:32:09PM -0800, Utkarsh Patel wrote:
> Configure Thunderbolt 3 cable generation value by filling Thunderbolt 3
> cable discover mode VDO to support rounded Thunderbolt 3 cables.
> While we are here use Thunderbolt 3 cable discover mode VDO to fill active
> cable plug link training value.
>
> Suggested-by: Heikki Krogerus <[email protected]>
> Signed-off-by: Utkarsh Patel <[email protected]>
>
> --
> Changes in v3:
> - Added a check for cable's TBT support before filling TBT3 discover mode
> VDO.
>
> Changes in v2:
> - No change.
> --
> ---
> drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 8111ed1fc574..68b17ee1d1ae 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -514,8 +514,18 @@ static int cros_typec_enable_usb4(struct cros_typec_data *typec,
> else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE)
> data.eudo |= EUDO_CABLE_TYPE_RE_TIMER << EUDO_CABLE_TYPE_SHIFT;
>
> - data.active_link_training = !!(pd_ctrl->control_flags &
> - USB_PD_CTRL_ACTIVE_LINK_UNIDIR);
> + /*
> + * Filling TBT3 Cable VDO when TBT3 cable is being used to establish
> + * USB4 connection.
> + */
> + if (pd_ctrl->cable_gen) {
> + data.tbt_cable_vdo = TBT_MODE;
> +
> + if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
> + data.tbt_cable_vdo |= TBT_CABLE_LINK_TRAINING;
> +
> + data.tbt_cable_vdo |= TBT_SET_CABLE_ROUNDED(pd_ctrl->cable_gen);
> + }

I think the following would decouple Rounded Support and Active Cable Link
Training?:

struct typec_thunderbolt_data data = {};
...
if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
data.tbt_cable_vdo |= TBT_CABLE_LINK_TRAINING;

data.tbt_cable_vdo |= TBT_SET_CABLE_ROUNDED(pd_ctrl->cable_gen);

if (data.tbt_cable_vdo)
data.tbt_cable_vdo |= TBT_MODE;


Best regards,

-Prashant

2020-11-20 02:34:58

by Patel, Utkarsh H

[permalink] [raw]
Subject: RE: [PATCH v3 2/4] platform/chrome: cros_ec_typec: Use Thunderbolt 3 cable discover mode VDO in USB4 mode

Hi Prashant,

> -----Original Message-----
> From: Prashant Malani <[email protected]>
> Sent: Thursday, November 19, 2020 12:09 AM
> To: Patel, Utkarsh H <[email protected]>
> Cc: [email protected]; [email protected];
> [email protected]; [email protected]; Mani,
> Rajmohan <[email protected]>; Shaikh, Azhar
> <[email protected]>
> Subject: Re: [PATCH v3 2/4] platform/chrome: cros_ec_typec: Use Thunderbolt
> 3 cable discover mode VDO in USB4 mode
>
> Hi Utkarsh,
>
> On Wed, Nov 18, 2020 at 10:32:09PM -0800, Utkarsh Patel wrote:
> > Configure Thunderbolt 3 cable generation value by filling Thunderbolt
> > 3 cable discover mode VDO to support rounded Thunderbolt 3 cables.
> > While we are here use Thunderbolt 3 cable discover mode VDO to fill
> > active cable plug link training value.
> >
> > Suggested-by: Heikki Krogerus <[email protected]>
> > Signed-off-by: Utkarsh Patel <[email protected]>
> >
> > --
> > Changes in v3:
> > - Added a check for cable's TBT support before filling TBT3 discover mode
> > VDO.
> >
> > Changes in v2:
> > - No change.
> > --
> > ---
> > drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
> > 1 file changed, 12 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/platform/chrome/cros_ec_typec.c
> > b/drivers/platform/chrome/cros_ec_typec.c
> > index 8111ed1fc574..68b17ee1d1ae 100644
> > --- a/drivers/platform/chrome/cros_ec_typec.c
> > +++ b/drivers/platform/chrome/cros_ec_typec.c
> > @@ -514,8 +514,18 @@ static int cros_typec_enable_usb4(struct
> cros_typec_data *typec,
> > else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE)
> > data.eudo |= EUDO_CABLE_TYPE_RE_TIMER <<
> EUDO_CABLE_TYPE_SHIFT;
> >
> > - data.active_link_training = !!(pd_ctrl->control_flags &
> > - USB_PD_CTRL_ACTIVE_LINK_UNIDIR);
> > + /*
> > + * Filling TBT3 Cable VDO when TBT3 cable is being used to establish
> > + * USB4 connection.
> > + */
> > + if (pd_ctrl->cable_gen) {
> > + data.tbt_cable_vdo = TBT_MODE;
> > +
> > + if (pd_ctrl->control_flags &
> USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
> > + data.tbt_cable_vdo |= TBT_CABLE_LINK_TRAINING;
> > +
> > + data.tbt_cable_vdo |= TBT_SET_CABLE_ROUNDED(pd_ctrl-
> >cable_gen);
> > + }
>
> I think the following would decouple Rounded Support and Active Cable Link
> Training?:

Any reason you would want to decouple them?
As for the TBT3 active cable to create USB4 connection, it needs have rounded data rates.

>
> struct typec_thunderbolt_data data = {}; ...
> if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
> data.tbt_cable_vdo |= TBT_CABLE_LINK_TRAINING;
>
> data.tbt_cable_vdo |= TBT_SET_CABLE_ROUNDED(pd_ctrl-
> >cable_gen);
>
> if (data.tbt_cable_vdo)
> data.tbt_cable_vdo |= TBT_MODE;
>
>
> Best regards,
>
> -Prashant

Sincerely,
Utkarsh Patel.

2020-11-20 03:17:55

by Prashant Malani

[permalink] [raw]
Subject: Re: [PATCH v3 2/4] platform/chrome: cros_ec_typec: Use Thunderbolt 3 cable discover mode VDO in USB4 mode

Hi Utkarsh,

On Thu, Nov 19, 2020 at 6:32 PM Patel, Utkarsh H
<[email protected]> wrote:
>
> Hi Prashant,
>
> > -----Original Message-----
> > From: Prashant Malani <[email protected]>
> > Sent: Thursday, November 19, 2020 12:09 AM
> > To: Patel, Utkarsh H <[email protected]>
> > Cc: [email protected]; [email protected];
> > [email protected]; [email protected]; Mani,
> > Rajmohan <[email protected]>; Shaikh, Azhar
> > <[email protected]>
> > Subject: Re: [PATCH v3 2/4] platform/chrome: cros_ec_typec: Use Thunderbolt
> > 3 cable discover mode VDO in USB4 mode
> >
> > Hi Utkarsh,
> >
> > On Wed, Nov 18, 2020 at 10:32:09PM -0800, Utkarsh Patel wrote:
> > > Configure Thunderbolt 3 cable generation value by filling Thunderbolt
> > > 3 cable discover mode VDO to support rounded Thunderbolt 3 cables.
> > > While we are here use Thunderbolt 3 cable discover mode VDO to fill
> > > active cable plug link training value.
> > >
> > > Suggested-by: Heikki Krogerus <[email protected]>
> > > Signed-off-by: Utkarsh Patel <[email protected]>
> > >
> > > --
> > > Changes in v3:
> > > - Added a check for cable's TBT support before filling TBT3 discover mode
> > > VDO.
> > >
> > > Changes in v2:
> > > - No change.
> > > --
> > > ---
> > > drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
> > > 1 file changed, 12 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/platform/chrome/cros_ec_typec.c
> > > b/drivers/platform/chrome/cros_ec_typec.c
> > > index 8111ed1fc574..68b17ee1d1ae 100644
> > > --- a/drivers/platform/chrome/cros_ec_typec.c
> > > +++ b/drivers/platform/chrome/cros_ec_typec.c
> > > @@ -514,8 +514,18 @@ static int cros_typec_enable_usb4(struct
> > cros_typec_data *typec,
> > > else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE)
> > > data.eudo |= EUDO_CABLE_TYPE_RE_TIMER <<
> > EUDO_CABLE_TYPE_SHIFT;
> > >
> > > - data.active_link_training = !!(pd_ctrl->control_flags &
> > > - USB_PD_CTRL_ACTIVE_LINK_UNIDIR);
> > > + /*
> > > + * Filling TBT3 Cable VDO when TBT3 cable is being used to establish
> > > + * USB4 connection.
> > > + */
> > > + if (pd_ctrl->cable_gen) {
> > > + data.tbt_cable_vdo = TBT_MODE;
> > > +
> > > + if (pd_ctrl->control_flags &
> > USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
> > > + data.tbt_cable_vdo |= TBT_CABLE_LINK_TRAINING;
> > > +
> > > + data.tbt_cable_vdo |= TBT_SET_CABLE_ROUNDED(pd_ctrl-
> > >cable_gen);
> > > + }
> >
> > I think the following would decouple Rounded Support and Active Cable Link
> > Training?:
>
> Any reason you would want to decouple them?

Is there anything in the spec that says Active Cable Link Training
needs Rounded Cable support (or vice versa)?
If yes, could you kindly point me to the relevant portion in the spec
that states this?

If no, then the two should be set independently based on the response
from the Chrome EC.

FWIW, Table F-11 ( TBT3 Cable Discover Mode VDO Responses) from the
USB Type-C Cable & Connector Spec (Rel 2.0) suggests
the two are independent bits although I don't have access to the TBT3
spec to confirm.

BR,

-Prashant

2020-11-20 08:07:54

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH v3 1/4] usb: typec: Use Thunderbolt 3 cable discover mode VDO in Enter_USB message

On Wed, Nov 18, 2020 at 10:32:08PM -0800, Utkarsh Patel wrote:
> When Thunderbolt 3 cable is being used to create USB4 connection, use
> Thunderbolt 3 discover mode VDO to fill details such as active cable plug
> link training and cable rounded support.
> With USB4 cables, these VDO members need not be filled.
>
> Suggested-by: Heikki Krogerus <[email protected]>
> Signed-off-by: Utkarsh Patel <[email protected]>
>
> --
> Changes in v3:
> - Changed the commit mesage to reflect why TBT3 VDO is being used.
> - Added more details in the header file about the usage of TBT3 VDO.
>
> Changes in v2:
> - No change.
> --
> ---
> include/linux/usb/typec.h | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> index 6be558045942..25731ed863fa 100644
> --- a/include/linux/usb/typec.h
> +++ b/include/linux/usb/typec.h
> @@ -75,6 +75,10 @@ enum typec_orientation {
> /*
> * struct enter_usb_data - Enter_USB Message details
> * @eudo: Enter_USB Data Object
> + * @tbt_cable_vdo: TBT3 Cable Discover Mode Response

This is fine..

> + * @tbt_cable_vdo needs to be filled with details of active cable plug link
> + * training and cable rounded support when thunderbolt 3 cable is being used to
> + * create USB4 connection. Do not fill this in case of USB4 cable.

But this is not. The description of the member tells what the member
contains, but it does not make sense to explain also how to use the
member in the same place. Instead you should explain how to use the
member in the description of the structure. So..

> * @active_link_training: Active Cable Plug Link Training
> *
> * @active_link_training is a flag that should be set with uni-directional SBRX

Put it here. That will make this much more readable.


thanks,

--
heikki

2020-11-20 08:40:09

by Prashant Malani

[permalink] [raw]
Subject: Re: [PATCH v3 1/4] usb: typec: Use Thunderbolt 3 cable discover mode VDO in Enter_USB message

On Fri, Nov 20, 2020 at 10:05:14AM +0200, Heikki Krogerus wrote:
> On Wed, Nov 18, 2020 at 10:32:08PM -0800, Utkarsh Patel wrote:
> > When Thunderbolt 3 cable is being used to create USB4 connection, use
> > Thunderbolt 3 discover mode VDO to fill details such as active cable plug
> > link training and cable rounded support.
> > With USB4 cables, these VDO members need not be filled.
> >
> > Suggested-by: Heikki Krogerus <[email protected]>
> > Signed-off-by: Utkarsh Patel <[email protected]>
> >
> > --
> > Changes in v3:
> > - Changed the commit mesage to reflect why TBT3 VDO is being used.
> > - Added more details in the header file about the usage of TBT3 VDO.
> >
> > Changes in v2:
> > - No change.
> > --
> > ---
> > include/linux/usb/typec.h | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> > index 6be558045942..25731ed863fa 100644
> > --- a/include/linux/usb/typec.h
> > +++ b/include/linux/usb/typec.h
> > @@ -75,6 +75,10 @@ enum typec_orientation {
> > /*
> > * struct enter_usb_data - Enter_USB Message details
> > * @eudo: Enter_USB Data Object
> > + * @tbt_cable_vdo: TBT3 Cable Discover Mode Response
>
> This is fine..
>
> > + * @tbt_cable_vdo needs to be filled with details of active cable plug link
> > + * training and cable rounded support when thunderbolt 3 cable is being used to
> > + * create USB4 connection. Do not fill this in case of USB4 cable.
>
> But this is not. The description of the member tells what the member
> contains, but it does not make sense to explain also how to use the
> member in the same place.

Slightly tangential question here:

Is there a need to mention "active cable plug link training" and "cable
rounded support" at all? Wouldn't it be sufficient to omit those in the
description (in case some mux implementation wants to use the other fields
of the VDO) ?

> Instead you should explain how to use the
> member in the description of the structure. So..
>
> > * @active_link_training: Active Cable Plug Link Training
> > *
> > * @active_link_training is a flag that should be set with uni-directional SBRX
>
> Put it here. That will make this much more readable.
>
>
> thanks,
>
> --
> heikki

2020-11-20 08:55:06

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH v3 1/4] usb: typec: Use Thunderbolt 3 cable discover mode VDO in Enter_USB message

On Fri, Nov 20, 2020 at 12:36:25AM -0800, Prashant Malani wrote:
> On Fri, Nov 20, 2020 at 10:05:14AM +0200, Heikki Krogerus wrote:
> > On Wed, Nov 18, 2020 at 10:32:08PM -0800, Utkarsh Patel wrote:
> > > When Thunderbolt 3 cable is being used to create USB4 connection, use
> > > Thunderbolt 3 discover mode VDO to fill details such as active cable plug
> > > link training and cable rounded support.
> > > With USB4 cables, these VDO members need not be filled.
> > >
> > > Suggested-by: Heikki Krogerus <[email protected]>
> > > Signed-off-by: Utkarsh Patel <[email protected]>
> > >
> > > --
> > > Changes in v3:
> > > - Changed the commit mesage to reflect why TBT3 VDO is being used.
> > > - Added more details in the header file about the usage of TBT3 VDO.
> > >
> > > Changes in v2:
> > > - No change.
> > > --
> > > ---
> > > include/linux/usb/typec.h | 5 +++++
> > > 1 file changed, 5 insertions(+)
> > >
> > > diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> > > index 6be558045942..25731ed863fa 100644
> > > --- a/include/linux/usb/typec.h
> > > +++ b/include/linux/usb/typec.h
> > > @@ -75,6 +75,10 @@ enum typec_orientation {
> > > /*
> > > * struct enter_usb_data - Enter_USB Message details
> > > * @eudo: Enter_USB Data Object
> > > + * @tbt_cable_vdo: TBT3 Cable Discover Mode Response
> >
> > This is fine..
> >
> > > + * @tbt_cable_vdo needs to be filled with details of active cable plug link
> > > + * training and cable rounded support when thunderbolt 3 cable is being used to
> > > + * create USB4 connection. Do not fill this in case of USB4 cable.
> >
> > But this is not. The description of the member tells what the member
> > contains, but it does not make sense to explain also how to use the
> > member in the same place.
>
> Slightly tangential question here:
>
> Is there a need to mention "active cable plug link training" and "cable
> rounded support" at all? Wouldn't it be sufficient to omit those in the
> description (in case some mux implementation wants to use the other fields
> of the VDO) ?

No, I don't think so. I think it would be enough to just mention that
we need the TBT3 Cable VDO only when the USB4 connection is created
using TBT3 cables. And that's it.


Br,

--
heikki

2020-11-20 11:24:26

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH v3 2/4] platform/chrome: cros_ec_typec: Use Thunderbolt 3 cable discover mode VDO in USB4 mode

On Thu, Nov 19, 2020 at 12:09:06AM -0800, Prashant Malani wrote:
> Hi Utkarsh,
>
> On Wed, Nov 18, 2020 at 10:32:09PM -0800, Utkarsh Patel wrote:
> > Configure Thunderbolt 3 cable generation value by filling Thunderbolt 3
> > cable discover mode VDO to support rounded Thunderbolt 3 cables.
> > While we are here use Thunderbolt 3 cable discover mode VDO to fill active
> > cable plug link training value.
> >
> > Suggested-by: Heikki Krogerus <[email protected]>
> > Signed-off-by: Utkarsh Patel <[email protected]>
> >
> > --
> > Changes in v3:
> > - Added a check for cable's TBT support before filling TBT3 discover mode
> > VDO.
> >
> > Changes in v2:
> > - No change.
> > --
> > ---
> > drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
> > 1 file changed, 12 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> > index 8111ed1fc574..68b17ee1d1ae 100644
> > --- a/drivers/platform/chrome/cros_ec_typec.c
> > +++ b/drivers/platform/chrome/cros_ec_typec.c
> > @@ -514,8 +514,18 @@ static int cros_typec_enable_usb4(struct cros_typec_data *typec,
> > else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE)
> > data.eudo |= EUDO_CABLE_TYPE_RE_TIMER << EUDO_CABLE_TYPE_SHIFT;
> >
> > - data.active_link_training = !!(pd_ctrl->control_flags &
> > - USB_PD_CTRL_ACTIVE_LINK_UNIDIR);
> > + /*
> > + * Filling TBT3 Cable VDO when TBT3 cable is being used to establish
> > + * USB4 connection.
> > + */
> > + if (pd_ctrl->cable_gen) {
> > + data.tbt_cable_vdo = TBT_MODE;
> > +
> > + if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
> > + data.tbt_cable_vdo |= TBT_CABLE_LINK_TRAINING;
> > +
> > + data.tbt_cable_vdo |= TBT_SET_CABLE_ROUNDED(pd_ctrl->cable_gen);
> > + }
>
> I think the following would decouple Rounded Support and Active Cable Link
> Training?:
>
> struct typec_thunderbolt_data data = {};
> ...
> if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
> data.tbt_cable_vdo |= TBT_CABLE_LINK_TRAINING;
>
> data.tbt_cable_vdo |= TBT_SET_CABLE_ROUNDED(pd_ctrl->cable_gen);

I agree with this. We should not modify the data that we actually
have access to.

> if (data.tbt_cable_vdo)
> data.tbt_cable_vdo |= TBT_MODE;

That is wrong. If the LSRX communication is bi-directional, and/or the
data rates are non-rounded, the cable has to be TBT3 cable. So I think
what you would want is:

if (!data.tbt_cable_vdo)
data.tbt_cable_vdo = TBT_MODE;

But of course we can not do that either, because we have to set the
TBT_MODE bit if there is any other data in tbt_cable_vdo (USB Type-C
spec does not define any other valid values except 0x0001 = TBT_MODE
for that field). Otherwise the mux driver should consider the data
corrupted. So we would have to do this:

if (pd_ctrl->cable_gen &&
pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
data.tbt_cable_vdo = 0; /* We assume USB4 cable */
else
data.tbt_cable_vdo |= TBT_MODE; /* It is for sure TBT3 cable */

But I would not do that. TBT3 cable can also support unidirectional
SBU communication and rounded data rates.

IMO safer bet for now would be to just claim that the cable is always
TBT3 cable until we have access to information that can really tell us
is the cable USB4 or TBT3.

But it's up to you guys.


Br,

--
heikki

2020-11-20 12:09:37

by Prashant Malani

[permalink] [raw]
Subject: Re: [PATCH v3 2/4] platform/chrome: cros_ec_typec: Use Thunderbolt 3 cable discover mode VDO in USB4 mode

On Fri, Nov 20, 2020 at 01:22:18PM +0200, Heikki Krogerus wrote:
> On Thu, Nov 19, 2020 at 12:09:06AM -0800, Prashant Malani wrote:
> > Hi Utkarsh,
> >
> > On Wed, Nov 18, 2020 at 10:32:09PM -0800, Utkarsh Patel wrote:
> > > Configure Thunderbolt 3 cable generation value by filling Thunderbolt 3
> > > cable discover mode VDO to support rounded Thunderbolt 3 cables.
> > > While we are here use Thunderbolt 3 cable discover mode VDO to fill active
> > > cable plug link training value.
> > >
> > > Suggested-by: Heikki Krogerus <[email protected]>
> > > Signed-off-by: Utkarsh Patel <[email protected]>
> > >
> > > --
> > > Changes in v3:
> > > - Added a check for cable's TBT support before filling TBT3 discover mode
> > > VDO.
> > >
> > > Changes in v2:
> > > - No change.
> > > --
> > > ---
> > > drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
> > > 1 file changed, 12 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> > > index 8111ed1fc574..68b17ee1d1ae 100644
> > > --- a/drivers/platform/chrome/cros_ec_typec.c
> > > +++ b/drivers/platform/chrome/cros_ec_typec.c
> > > @@ -514,8 +514,18 @@ static int cros_typec_enable_usb4(struct cros_typec_data *typec,
> > > else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE)
> > > data.eudo |= EUDO_CABLE_TYPE_RE_TIMER << EUDO_CABLE_TYPE_SHIFT;
> > >
> > > - data.active_link_training = !!(pd_ctrl->control_flags &
> > > - USB_PD_CTRL_ACTIVE_LINK_UNIDIR);
> > > + /*
> > > + * Filling TBT3 Cable VDO when TBT3 cable is being used to establish
> > > + * USB4 connection.
> > > + */
> > > + if (pd_ctrl->cable_gen) {
> > > + data.tbt_cable_vdo = TBT_MODE;
> > > +
> > > + if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
> > > + data.tbt_cable_vdo |= TBT_CABLE_LINK_TRAINING;
> > > +
> > > + data.tbt_cable_vdo |= TBT_SET_CABLE_ROUNDED(pd_ctrl->cable_gen);
> > > + }
> >
> > I think the following would decouple Rounded Support and Active Cable Link
> > Training?:
> >
> > struct typec_thunderbolt_data data = {};
> > ...
> > if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
> > data.tbt_cable_vdo |= TBT_CABLE_LINK_TRAINING;
> >
> > data.tbt_cable_vdo |= TBT_SET_CABLE_ROUNDED(pd_ctrl->cable_gen);
>
> I agree with this. We should not modify the data that we actually
> have access to.
>
> > if (data.tbt_cable_vdo)
> > data.tbt_cable_vdo |= TBT_MODE;
>
> That is wrong. If the LSRX communication is bi-directional, and/or the
> data rates are non-rounded, the cable has to be TBT3 cable. So I think
> what you would want is:

Thanks for pointing this out, I didn't consider this case.

>
> if (!data.tbt_cable_vdo)
> data.tbt_cable_vdo = TBT_MODE;
>
> But of course we can not do that either, because we have to set the
> TBT_MODE bit if there is any other data in tbt_cable_vdo (USB Type-C
> spec does not define any other valid values except 0x0001 = TBT_MODE
> for that field). Otherwise the mux driver should consider the data
> corrupted. So we would have to do this:
>
> if (pd_ctrl->cable_gen &&
> pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
> data.tbt_cable_vdo = 0; /* We assume USB4 cable */
> else
> data.tbt_cable_vdo |= TBT_MODE; /* It is for sure TBT3 cable */
>
> But I would not do that. TBT3 cable can also support unidirectional
> SBU communication and rounded data rates.
>
> IMO safer bet for now would be to just claim that the cable is always
> TBT3 cable until we have access to information that can really tell us
> is the cable USB4 or TBT3.

Which brings us back to v1 of the patch :S

That still leaves my underlying concern that we'll be telling the Mux
implementation that a TBT3 cable is connected when in fact it's a USB4
active cable.

How about we don't set the TBT_MODE bit at all ? IMO it's equally bad as setting it
always, but with the additional advantage:

- USB4 active cable case : you are covered (since if we unilaterally set
TBT_MODE then the Active USB4 cable case never gets executed in
pmc_usb_mux_usb4() in drivers/usb/typec/mux/intel_pmc_mux.c Patch 3/4)

- Bidirectional LSRX non-rounded TBT: Still supported since
the code path in the Intel Mux agent is the same.

I understand neither of the options are ideal, but WDYT?

BR,

-Prashant

2020-11-20 13:38:30

by Prashant Malani

[permalink] [raw]
Subject: Re: [PATCH v3 2/4] platform/chrome: cros_ec_typec: Use Thunderbolt 3 cable discover mode VDO in USB4 mode

On Fri, Nov 20, 2020 at 4:07 AM Prashant Malani <[email protected]> wrote:
>
> On Fri, Nov 20, 2020 at 01:22:18PM +0200, Heikki Krogerus wrote:
> > On Thu, Nov 19, 2020 at 12:09:06AM -0800, Prashant Malani wrote:
> > > Hi Utkarsh,
> > >
> > > On Wed, Nov 18, 2020 at 10:32:09PM -0800, Utkarsh Patel wrote:
> > > > Configure Thunderbolt 3 cable generation value by filling Thunderbolt 3
> > > > cable discover mode VDO to support rounded Thunderbolt 3 cables.
> > > > While we are here use Thunderbolt 3 cable discover mode VDO to fill active
> > > > cable plug link training value.
> > > >
> > > > Suggested-by: Heikki Krogerus <[email protected]>
> > > > Signed-off-by: Utkarsh Patel <[email protected]>
> > > >
> > > > --
> > > > Changes in v3:
> > > > - Added a check for cable's TBT support before filling TBT3 discover mode
> > > > VDO.
> > > >
> > > > Changes in v2:
> > > > - No change.
> > > > --
> > > > ---
> > > > drivers/platform/chrome/cros_ec_typec.c | 14 ++++++++++++--
> > > > 1 file changed, 12 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> > > > index 8111ed1fc574..68b17ee1d1ae 100644
> > > > --- a/drivers/platform/chrome/cros_ec_typec.c
> > > > +++ b/drivers/platform/chrome/cros_ec_typec.c
> > > > @@ -514,8 +514,18 @@ static int cros_typec_enable_usb4(struct cros_typec_data *typec,
> > > > else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE)
> > > > data.eudo |= EUDO_CABLE_TYPE_RE_TIMER << EUDO_CABLE_TYPE_SHIFT;
> > > >
> > > > - data.active_link_training = !!(pd_ctrl->control_flags &
> > > > - USB_PD_CTRL_ACTIVE_LINK_UNIDIR);
> > > > + /*
> > > > + * Filling TBT3 Cable VDO when TBT3 cable is being used to establish
> > > > + * USB4 connection.
> > > > + */
> > > > + if (pd_ctrl->cable_gen) {
> > > > + data.tbt_cable_vdo = TBT_MODE;
> > > > +
> > > > + if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
> > > > + data.tbt_cable_vdo |= TBT_CABLE_LINK_TRAINING;
> > > > +
> > > > + data.tbt_cable_vdo |= TBT_SET_CABLE_ROUNDED(pd_ctrl->cable_gen);
> > > > + }
> > >
> > > I think the following would decouple Rounded Support and Active Cable Link
> > > Training?:
> > >
> > > struct typec_thunderbolt_data data = {};
> > > ...
> > > if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
> > > data.tbt_cable_vdo |= TBT_CABLE_LINK_TRAINING;
> > >
> > > data.tbt_cable_vdo |= TBT_SET_CABLE_ROUNDED(pd_ctrl->cable_gen);
> >
> > I agree with this. We should not modify the data that we actually
> > have access to.
> >
> > > if (data.tbt_cable_vdo)
> > > data.tbt_cable_vdo |= TBT_MODE;
> >
> > That is wrong. If the LSRX communication is bi-directional, and/or the
> > data rates are non-rounded, the cable has to be TBT3 cable. So I think
> > what you would want is:
>
> Thanks for pointing this out, I didn't consider this case.
>
> >
> > if (!data.tbt_cable_vdo)
> > data.tbt_cable_vdo = TBT_MODE;
> >
> > But of course we can not do that either, because we have to set the
> > TBT_MODE bit if there is any other data in tbt_cable_vdo (USB Type-C
> > spec does not define any other valid values except 0x0001 = TBT_MODE
> > for that field). Otherwise the mux driver should consider the data
> > corrupted. So we would have to do this:
> >
> > if (pd_ctrl->cable_gen &&
> > pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_LINK_UNIDIR)
> > data.tbt_cable_vdo = 0; /* We assume USB4 cable */
> > else
> > data.tbt_cable_vdo |= TBT_MODE; /* It is for sure TBT3 cable */
> >
> > But I would not do that. TBT3 cable can also support unidirectional
> > SBU communication and rounded data rates.
> >
> > IMO safer bet for now would be to just claim that the cable is always
> > TBT3 cable until we have access to information that can really tell us
> > is the cable USB4 or TBT3.
>
> Which brings us back to v1 of the patch :S
>
> That still leaves my underlying concern that we'll be telling the Mux
> implementation that a TBT3 cable is connected when in fact it's a USB4
> active cable.
>
> How about we don't set the TBT_MODE bit at all ? IMO it's equally bad as setting it
> always, but with the additional advantage:
>
> - USB4 active cable case : you are covered (since if we unilaterally set
> TBT_MODE then the Active USB4 cable case never gets executed in
> pmc_usb_mux_usb4() in drivers/usb/typec/mux/intel_pmc_mux.c Patch 3/4)
>
> - Bidirectional LSRX non-rounded TBT: Still supported since
> the code path in the Intel Mux agent is the same.

Thinking about this a bit more, never setting TBT_MODE would mean that
bidrectional LSRX non-rounded TBT would be treated the same as USB4
active cable in the mux agent
code, which is also incorrect (I think)

I need to think about this a bit more, but currently I don't have any
solutions to offer.

2020-11-20 13:46:46

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH v3 2/4] platform/chrome: cros_ec_typec: Use Thunderbolt 3 cable discover mode VDO in USB4 mode

Hi Prashant,

On Fri, Nov 20, 2020 at 04:07:00AM -0800, Prashant Malani wrote:
> On Fri, Nov 20, 2020 at 01:22:18PM +0200, Heikki Krogerus wrote:
> > IMO safer bet for now would be to just claim that the cable is always
> > TBT3 cable until we have access to information that can really tell us
> > is the cable USB4 or TBT3.
>
> Which brings us back to v1 of the patch :S
>
> That still leaves my underlying concern that we'll be telling the Mux
> implementation that a TBT3 cable is connected when in fact it's a USB4
> active cable.

No matter what we do with these values, it does not change the fact
that we do not know is the cable USB4 or TBT3 at the moment. What ever
we do, we are guessing things.

Can you please explain your concern again? What can happen if we use
USB4 cable but claim that it is TBT3 to the mux?

> How about we don't set the TBT_MODE bit at all ?

Let's not come up with values that are not defined in the spec for
this field (or any other). Even though it is unlikely, we can not rule
out the possibility that one day value of 0x0000 is defined for that
field.

I'm strongly against this kind of "modifications". It would mean that
the member tbt_cable_vdo does not actually contain TBT3 Cable VDO, but
instead it has to be considered as driver or subsystem specific data.

> IMO it's equally bad as setting it always, but with the additional
> advantage:
>
> - USB4 active cable case : you are covered (since if we unilaterally set
> TBT_MODE then the Active USB4 cable case never gets executed in
> pmc_usb_mux_usb4() in drivers/usb/typec/mux/intel_pmc_mux.c Patch 3/4)
>
> - Bidirectional LSRX non-rounded TBT: Still supported since
> the code path in the Intel Mux agent is the same.

This case will not work. The tbt_cable_vdo member is now 0, which to
the mux driver means that the cable is USB4 cable (and that is what it
really must mean to the mux driver - any mux driver). The mux driver
will therefore enable unidirectional SBU communication even though it
is actually bidirectional, and also rounded data rates even though the
cable supports only non-rounded data rates.

> I understand neither of the options are ideal, but WDYT?

I may be missing something, but I'm still going to say that let's just
claim that the cable is always TBT3 for now in this driver. That is
the only safe bet that we have.


thanks,

--
heikki

2020-11-20 17:06:49

by Patel, Utkarsh H

[permalink] [raw]
Subject: RE: [PATCH v3 1/4] usb: typec: Use Thunderbolt 3 cable discover mode VDO in Enter_USB message

Hi Heikki and Prashant,

Thank you for the feedback.

> > > > include/linux/usb/typec.h | 5 +++++
> > > > 1 file changed, 5 insertions(+)
> > > >
> > > > diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> > > > index 6be558045942..25731ed863fa 100644
> > > > --- a/include/linux/usb/typec.h
> > > > +++ b/include/linux/usb/typec.h
> > > > @@ -75,6 +75,10 @@ enum typec_orientation {
> > > > /*
> > > > * struct enter_usb_data - Enter_USB Message details
> > > > * @eudo: Enter_USB Data Object
> > > > + * @tbt_cable_vdo: TBT3 Cable Discover Mode Response
> > >
> > > This is fine..
> > >
> > > > + * @tbt_cable_vdo needs to be filled with details of active cable
> > > > + plug link
> > > > + * training and cable rounded support when thunderbolt 3 cable is
> > > > + being used to
> > > > + * create USB4 connection. Do not fill this in case of USB4 cable.
> > >
> > > But this is not. The description of the member tells what the member
> > > contains, but it does not make sense to explain also how to use the
> > > member in the same place.
> >
> > Slightly tangential question here:
> >
> > Is there a need to mention "active cable plug link training" and
> > "cable rounded support" at all? Wouldn't it be sufficient to omit
> > those in the description (in case some mux implementation wants to use
> > the other fields of the VDO) ?
>
> No, I don't think so. I think it would be enough to just mention that we need
> the TBT3 Cable VDO only when the USB4 connection is created using TBT3
> cables. And that's it.

Ack.

>
>
> Br,
>
> --
> Heikki

Sincerely,
Utkarsh Patel.