2020-12-10 16:25:03

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 0/5] USB: typec: various patches

In digging through a large set of proposed typec patches for the Android
common kernel, I've picked out 5 "easy" patches that should all go
upstream (they all should go upstream, just will take a while to clean
them up it seems...)

Badhri Jagan Sridharan (2):
USB: typec: tcpm: Prevent log overflow by removing old entries
USB: typec: tcpci: Add Bleed discharge to POWER_CONTROL definition

Kyle Tso (2):
USB: typec: tcpm: Fix PR_SWAP error handling
USB: typec: tcpm: Add a 30ms room for tPSSourceOn in PR_SWAP

pumahsu (1):
USB: typec: tcpm: Hard Reset after not receiving a Request

drivers/usb/typec/tcpm/tcpci.h | 1 +
drivers/usb/typec/tcpm/tcpm.c | 30 +++++++++++++++---------------
include/linux/usb/pd.h | 1 +
3 files changed, 17 insertions(+), 15 deletions(-)

--
2.29.2


2020-12-10 16:27:24

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 3/5] USB: typec: tcpm: Fix PR_SWAP error handling

From: Kyle Tso <[email protected]>

PD rev3.0 8.3.3.16.3.6 PE_PRS_SRC_SNK_Wait_Source_on State
The Policy Enging Shall transition to the ErrorRecovery state when the
PSSourceOnTimer times out ...

Cc: Guenter Roeck <[email protected]>
Cc: Heikki Krogerus <[email protected]>
Cc: Badhri Jagan Sridharan <[email protected]>
Signed-off-by: Kyle Tso <[email protected]>
Signed-off-by: Will McVicker <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/usb/typec/tcpm/tcpm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 0efda59bb104..d51c45961893 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -3728,7 +3728,7 @@ static void run_state_machine(struct tcpm_port *port)
tcpm_set_state(port, ERROR_RECOVERY, 0);
break;
}
- tcpm_set_state_cond(port, SNK_UNATTACHED, PD_T_PS_SOURCE_ON);
+ tcpm_set_state(port, ERROR_RECOVERY, PD_T_PS_SOURCE_ON);
break;
case PR_SWAP_SRC_SNK_SINK_ON:
/* Set the vbus disconnect threshold for implicit contract */
--
2.29.2

2020-12-10 16:28:41

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 4/5] USB: typec: tcpm: Add a 30ms room for tPSSourceOn in PR_SWAP

From: Kyle Tso <[email protected]>

TCPM state machine needs 20-25ms to enter the ErrorRecovery state after
tPSSourceOn timer timeouts. Change the timer from max 480ms to 450ms to
ensure that the timer complies with the Spec. In order to keep the
flexibility for other usecases using tPSSourceOn, add another timer only
for PR_SWAP.

Cc: Guenter Roeck <[email protected]>
Cc: Heikki Krogerus <[email protected]>
Cc: Badhri Jagan Sridharan <[email protected]>
Signed-off-by: Kyle Tso <[email protected]>
Signed-off-by: Will McVicker <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/usb/typec/tcpm/tcpm.c | 2 +-
include/linux/usb/pd.h | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index d51c45961893..5ed78194a1bd 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -3728,7 +3728,7 @@ static void run_state_machine(struct tcpm_port *port)
tcpm_set_state(port, ERROR_RECOVERY, 0);
break;
}
- tcpm_set_state(port, ERROR_RECOVERY, PD_T_PS_SOURCE_ON);
+ tcpm_set_state(port, ERROR_RECOVERY, PD_T_PS_SOURCE_ON_PRS);
break;
case PR_SWAP_SRC_SNK_SINK_ON:
/* Set the vbus disconnect threshold for implicit contract */
diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h
index 63a66dd5d832..bb9a782e1411 100644
--- a/include/linux/usb/pd.h
+++ b/include/linux/usb/pd.h
@@ -466,6 +466,7 @@ static inline unsigned int rdo_max_power(u32 rdo)
#define PD_T_DRP_SRC 30
#define PD_T_PS_SOURCE_OFF 920
#define PD_T_PS_SOURCE_ON 480
+#define PD_T_PS_SOURCE_ON_PRS 450 /* 390 - 480ms */
#define PD_T_PS_HARD_RESET 30
#define PD_T_SRC_RECOVER 760
#define PD_T_SRC_RECOVER_MAX 1000
--
2.29.2

2020-12-10 16:31:59

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 1/5] USB: typec: tcpm: Prevent log overflow by removing old entries

From: Badhri Jagan Sridharan <[email protected]>

TCPM logs overflow once the logbuffer is full. Clear old entries and
allow logging the newer ones as the newer would be more relevant to the
issue being debugged.

Also, do not reset the logbuffer tail as end users might take back to
back bugreports which would result in an empty buffer.

Cc: Guenter Roeck <[email protected]>
Cc: Heikki Krogerus <[email protected]>
Cc: Kyle Tso <[email protected]>
Signed-off-by: Badhri Jagan Sridharan <[email protected]>
Signed-off-by: Will McVicker <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/usb/typec/tcpm/tcpm.c | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index cedc6cf82d61..0ceeab50ed64 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -470,12 +470,6 @@ static bool tcpm_port_is_disconnected(struct tcpm_port *port)

#ifdef CONFIG_DEBUG_FS

-static bool tcpm_log_full(struct tcpm_port *port)
-{
- return port->logbuffer_tail ==
- (port->logbuffer_head + 1) % LOG_BUFFER_ENTRIES;
-}
-
__printf(2, 0)
static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
{
@@ -495,11 +489,6 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)

vsnprintf(tmpbuffer, sizeof(tmpbuffer), fmt, args);

- if (tcpm_log_full(port)) {
- port->logbuffer_head = max(port->logbuffer_head - 1, 0);
- strcpy(tmpbuffer, "overflow");
- }
-
if (port->logbuffer_head < 0 ||
port->logbuffer_head >= LOG_BUFFER_ENTRIES) {
dev_warn(port->dev,
@@ -519,6 +508,9 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
(unsigned long)ts_nsec, rem_nsec / 1000,
tmpbuffer);
port->logbuffer_head = (port->logbuffer_head + 1) % LOG_BUFFER_ENTRIES;
+ if (port->logbuffer_head == port->logbuffer_tail)
+ port->logbuffer_tail =
+ (port->logbuffer_tail + 1) % LOG_BUFFER_ENTRIES;

abort:
mutex_unlock(&port->logbuffer_lock);
@@ -622,8 +614,6 @@ static int tcpm_debug_show(struct seq_file *s, void *v)
seq_printf(s, "%s\n", port->logbuffer[tail]);
tail = (tail + 1) % LOG_BUFFER_ENTRIES;
}
- if (!seq_has_overflowed(s))
- port->logbuffer_tail = tail;
mutex_unlock(&port->logbuffer_lock);

return 0;
--
2.29.2

2020-12-10 16:32:53

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 2/5] USB: typec: tcpm: Hard Reset after not receiving a Request

From: pumahsu <[email protected]>

PD 3.0 spec 8.3.3.2.3, A Get_Source_Cap message is sent
to a UUT that is in the PE_SRC_Ready state. After sending
a Source_Capabilities message, the UUT should then expect
a Request message in response. When one is not received,
the UUT should timeout to PE_SRC_Hard_Reset.

Cc: Guenter Roeck <[email protected]>
Cc: Heikki Krogerus <[email protected]>
Cc: Badhri Jagan Sridharan <[email protected]>
Signed-off-by: pumahsu <[email protected]>
Signed-off-by: Kyle Tso <[email protected]>
Signed-off-by: Will McVicker <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/usb/typec/tcpm/tcpm.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 0ceeab50ed64..0efda59bb104 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -2218,6 +2218,7 @@ static int tcpm_pd_send_control(struct tcpm_port *port,
static bool tcpm_send_queued_message(struct tcpm_port *port)
{
enum pd_msg_request queued_message;
+ int ret;

do {
queued_message = port->queued_message;
@@ -2237,7 +2238,16 @@ static bool tcpm_send_queued_message(struct tcpm_port *port)
tcpm_pd_send_sink_caps(port);
break;
case PD_MSG_DATA_SOURCE_CAP:
- tcpm_pd_send_source_caps(port);
+ ret = tcpm_pd_send_source_caps(port);
+ if (ret < 0) {
+ tcpm_log(port,
+ "Unable to send src caps, ret=%d",
+ ret);
+ tcpm_set_state(port, SOFT_RESET_SEND, 0);
+ } else if (port->pwr_role == TYPEC_SOURCE) {
+ tcpm_set_state(port, HARD_RESET_SEND,
+ PD_T_SENDER_RESPONSE);
+ }
break;
default:
break;
--
2.29.2

2020-12-10 17:47:56

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 2/5] USB: typec: tcpm: Hard Reset after not receiving a Request

On Thu, Dec 10, 2020 at 05:05:18PM +0100, Greg Kroah-Hartman wrote:
> From: pumahsu <[email protected]>
>
> PD 3.0 spec 8.3.3.2.3, A Get_Source_Cap message is sent
> to a UUT that is in the PE_SRC_Ready state. After sending
> a Source_Capabilities message, the UUT should then expect
> a Request message in response. When one is not received,
> the UUT should timeout to PE_SRC_Hard_Reset.
>
> Cc: Guenter Roeck <[email protected]>
> Cc: Heikki Krogerus <[email protected]>
> Cc: Badhri Jagan Sridharan <[email protected]>
> Signed-off-by: pumahsu <[email protected]>
> Signed-off-by: Kyle Tso <[email protected]>
> Signed-off-by: Will McVicker <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

Reviewed-by: Guenter Roeck <[email protected]>

> ---
> drivers/usb/typec/tcpm/tcpm.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 0ceeab50ed64..0efda59bb104 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -2218,6 +2218,7 @@ static int tcpm_pd_send_control(struct tcpm_port *port,
> static bool tcpm_send_queued_message(struct tcpm_port *port)
> {
> enum pd_msg_request queued_message;
> + int ret;
>
> do {
> queued_message = port->queued_message;
> @@ -2237,7 +2238,16 @@ static bool tcpm_send_queued_message(struct tcpm_port *port)
> tcpm_pd_send_sink_caps(port);
> break;
> case PD_MSG_DATA_SOURCE_CAP:
> - tcpm_pd_send_source_caps(port);
> + ret = tcpm_pd_send_source_caps(port);
> + if (ret < 0) {
> + tcpm_log(port,
> + "Unable to send src caps, ret=%d",
> + ret);
> + tcpm_set_state(port, SOFT_RESET_SEND, 0);
> + } else if (port->pwr_role == TYPEC_SOURCE) {
> + tcpm_set_state(port, HARD_RESET_SEND,
> + PD_T_SENDER_RESPONSE);
> + }
> break;
> default:
> break;
> --
> 2.29.2
>

2020-12-10 17:48:05

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 3/5] USB: typec: tcpm: Fix PR_SWAP error handling

On Thu, Dec 10, 2020 at 05:05:19PM +0100, Greg Kroah-Hartman wrote:
> From: Kyle Tso <[email protected]>
>
> PD rev3.0 8.3.3.16.3.6 PE_PRS_SRC_SNK_Wait_Source_on State
> The Policy Enging Shall transition to the ErrorRecovery state when the
> PSSourceOnTimer times out ...
>
> Cc: Guenter Roeck <[email protected]>
> Cc: Heikki Krogerus <[email protected]>
> Cc: Badhri Jagan Sridharan <[email protected]>
> Signed-off-by: Kyle Tso <[email protected]>
> Signed-off-by: Will McVicker <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

Reviewed-by: Guenter Roeck <[email protected]>

> ---
> drivers/usb/typec/tcpm/tcpm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 0efda59bb104..d51c45961893 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -3728,7 +3728,7 @@ static void run_state_machine(struct tcpm_port *port)
> tcpm_set_state(port, ERROR_RECOVERY, 0);
> break;
> }
> - tcpm_set_state_cond(port, SNK_UNATTACHED, PD_T_PS_SOURCE_ON);
> + tcpm_set_state(port, ERROR_RECOVERY, PD_T_PS_SOURCE_ON);
> break;
> case PR_SWAP_SRC_SNK_SINK_ON:
> /* Set the vbus disconnect threshold for implicit contract */
> --
> 2.29.2
>

2020-12-10 19:18:37

by Badhri Jagan Sridharan

[permalink] [raw]
Subject: Re: [PATCH 1/5] USB: typec: tcpm: Prevent log overflow by removing old entries

Hi Guenter,

While I agree with what you are saying, since the logbuffer does not
have the intelligence to drop older entries where no issues were seen,
logbuffer gets full pretty quickly with good instances and there is no
space left to log the bad instance. Should wrapping this in a config
option be a better way to go about this ? When the config optioin is
set, old entries will be dropped.
Please let me know, I can update the patch and resend.

Thanks,
Badhri



On Thu, Dec 10, 2020 at 9:53 AM Guenter Roeck <[email protected]> wrote:
>
> On Thu, Dec 10, 2020 at 05:05:17PM +0100, Greg Kroah-Hartman wrote:
> > From: Badhri Jagan Sridharan <[email protected]>
> >
> > TCPM logs overflow once the logbuffer is full. Clear old entries and
> > allow logging the newer ones as the newer would be more relevant to the
> > issue being debugged.
> >
> > Also, do not reset the logbuffer tail as end users might take back to
> > back bugreports which would result in an empty buffer.
> >
>
> Historically, the reason for not doing this was that, once a problem occurs,
> the log would fill up quickly (typically with reconnect attempts), and the
> actual reason for the problem would be overwritten. Maybe that reasoning
> no longer applies; I just wanted to point out that there _was_ a reason for
> not clearing old log entries.
>
> Guenter
>
> > Cc: Guenter Roeck <[email protected]>
> > Cc: Heikki Krogerus <[email protected]>
> > Cc: Kyle Tso <[email protected]>
> > Signed-off-by: Badhri Jagan Sridharan <[email protected]>
> > Signed-off-by: Will McVicker <[email protected]>
> > Signed-off-by: Greg Kroah-Hartman <[email protected]>
> > ---
> > drivers/usb/typec/tcpm/tcpm.c | 16 +++-------------
> > 1 file changed, 3 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> > index cedc6cf82d61..0ceeab50ed64 100644
> > --- a/drivers/usb/typec/tcpm/tcpm.c
> > +++ b/drivers/usb/typec/tcpm/tcpm.c
> > @@ -470,12 +470,6 @@ static bool tcpm_port_is_disconnected(struct tcpm_port *port)
> >
> > #ifdef CONFIG_DEBUG_FS
> >
> > -static bool tcpm_log_full(struct tcpm_port *port)
> > -{
> > - return port->logbuffer_tail ==
> > - (port->logbuffer_head + 1) % LOG_BUFFER_ENTRIES;
> > -}
> > -
> > __printf(2, 0)
> > static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
> > {
> > @@ -495,11 +489,6 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
> >
> > vsnprintf(tmpbuffer, sizeof(tmpbuffer), fmt, args);
> >
> > - if (tcpm_log_full(port)) {
> > - port->logbuffer_head = max(port->logbuffer_head - 1, 0);
> > - strcpy(tmpbuffer, "overflow");
> > - }
> > -
> > if (port->logbuffer_head < 0 ||
> > port->logbuffer_head >= LOG_BUFFER_ENTRIES) {
> > dev_warn(port->dev,
> > @@ -519,6 +508,9 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
> > (unsigned long)ts_nsec, rem_nsec / 1000,
> > tmpbuffer);
> > port->logbuffer_head = (port->logbuffer_head + 1) % LOG_BUFFER_ENTRIES;
> > + if (port->logbuffer_head == port->logbuffer_tail)
> > + port->logbuffer_tail =
> > + (port->logbuffer_tail + 1) % LOG_BUFFER_ENTRIES;
> >
> > abort:
> > mutex_unlock(&port->logbuffer_lock);
> > @@ -622,8 +614,6 @@ static int tcpm_debug_show(struct seq_file *s, void *v)
> > seq_printf(s, "%s\n", port->logbuffer[tail]);
> > tail = (tail + 1) % LOG_BUFFER_ENTRIES;
> > }
> > - if (!seq_has_overflowed(s))
> > - port->logbuffer_tail = tail;
> > mutex_unlock(&port->logbuffer_lock);
> >
> > return 0;
> > --
> > 2.29.2
> >

2020-12-11 08:19:14

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 5/5] USB: typec: tcpci: Add Bleed discharge to POWER_CONTROL definition

From: Badhri Jagan Sridharan <[email protected]>

"Table 4-19. POWER_CONTROL Register Definition" from tcpci spec
defines BIT(3) as the control bit for bleed discharge.

Cc: Guenter Roeck <[email protected]>
Cc: Heikki Krogerus <[email protected]>
Cc: Kyle Tso <[email protected]>
Signed-off-by: Badhri Jagan Sridharan <[email protected]>
Signed-off-by: Will McVicker <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/usb/typec/tcpm/tcpci.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h
index 116a69c85e38..c3c7d07d9b4e 100644
--- a/drivers/usb/typec/tcpm/tcpci.h
+++ b/drivers/usb/typec/tcpm/tcpci.h
@@ -72,6 +72,7 @@

#define TCPC_POWER_CTRL 0x1c
#define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0)
+#define TCPC_POWER_CTRL_BLEED_DISCHARGE BIT(3)
#define TCPC_POWER_CTRL_AUTO_DISCHARGE BIT(4)
#define TCPC_FAST_ROLE_SWAP_EN BIT(7)

--
2.29.2

2020-12-11 08:48:29

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 1/5] USB: typec: tcpm: Prevent log overflow by removing old entries

On Thu, Dec 10, 2020 at 05:05:17PM +0100, Greg Kroah-Hartman wrote:
> From: Badhri Jagan Sridharan <[email protected]>
>
> TCPM logs overflow once the logbuffer is full. Clear old entries and
> allow logging the newer ones as the newer would be more relevant to the
> issue being debugged.
>
> Also, do not reset the logbuffer tail as end users might take back to
> back bugreports which would result in an empty buffer.
>

Historically, the reason for not doing this was that, once a problem occurs,
the log would fill up quickly (typically with reconnect attempts), and the
actual reason for the problem would be overwritten. Maybe that reasoning
no longer applies; I just wanted to point out that there _was_ a reason for
not clearing old log entries.

Guenter

> Cc: Guenter Roeck <[email protected]>
> Cc: Heikki Krogerus <[email protected]>
> Cc: Kyle Tso <[email protected]>
> Signed-off-by: Badhri Jagan Sridharan <[email protected]>
> Signed-off-by: Will McVicker <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>
> ---
> drivers/usb/typec/tcpm/tcpm.c | 16 +++-------------
> 1 file changed, 3 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index cedc6cf82d61..0ceeab50ed64 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -470,12 +470,6 @@ static bool tcpm_port_is_disconnected(struct tcpm_port *port)
>
> #ifdef CONFIG_DEBUG_FS
>
> -static bool tcpm_log_full(struct tcpm_port *port)
> -{
> - return port->logbuffer_tail ==
> - (port->logbuffer_head + 1) % LOG_BUFFER_ENTRIES;
> -}
> -
> __printf(2, 0)
> static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
> {
> @@ -495,11 +489,6 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
>
> vsnprintf(tmpbuffer, sizeof(tmpbuffer), fmt, args);
>
> - if (tcpm_log_full(port)) {
> - port->logbuffer_head = max(port->logbuffer_head - 1, 0);
> - strcpy(tmpbuffer, "overflow");
> - }
> -
> if (port->logbuffer_head < 0 ||
> port->logbuffer_head >= LOG_BUFFER_ENTRIES) {
> dev_warn(port->dev,
> @@ -519,6 +508,9 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
> (unsigned long)ts_nsec, rem_nsec / 1000,
> tmpbuffer);
> port->logbuffer_head = (port->logbuffer_head + 1) % LOG_BUFFER_ENTRIES;
> + if (port->logbuffer_head == port->logbuffer_tail)
> + port->logbuffer_tail =
> + (port->logbuffer_tail + 1) % LOG_BUFFER_ENTRIES;
>
> abort:
> mutex_unlock(&port->logbuffer_lock);
> @@ -622,8 +614,6 @@ static int tcpm_debug_show(struct seq_file *s, void *v)
> seq_printf(s, "%s\n", port->logbuffer[tail]);
> tail = (tail + 1) % LOG_BUFFER_ENTRIES;
> }
> - if (!seq_has_overflowed(s))
> - port->logbuffer_tail = tail;
> mutex_unlock(&port->logbuffer_lock);
>
> return 0;
> --
> 2.29.2
>

2020-12-11 08:48:59

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 4/5] USB: typec: tcpm: Add a 30ms room for tPSSourceOn in PR_SWAP

On Thu, Dec 10, 2020 at 05:05:20PM +0100, Greg Kroah-Hartman wrote:
> From: Kyle Tso <[email protected]>
>
> TCPM state machine needs 20-25ms to enter the ErrorRecovery state after
> tPSSourceOn timer timeouts. Change the timer from max 480ms to 450ms to
> ensure that the timer complies with the Spec. In order to keep the
> flexibility for other usecases using tPSSourceOn, add another timer only
> for PR_SWAP.
>
> Cc: Guenter Roeck <[email protected]>
> Cc: Heikki Krogerus <[email protected]>
> Cc: Badhri Jagan Sridharan <[email protected]>
> Signed-off-by: Kyle Tso <[email protected]>
> Signed-off-by: Will McVicker <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

Reviewed-by: Guenter Roeck <[email protected]>

> ---
> drivers/usb/typec/tcpm/tcpm.c | 2 +-
> include/linux/usb/pd.h | 1 +
> 2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index d51c45961893..5ed78194a1bd 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -3728,7 +3728,7 @@ static void run_state_machine(struct tcpm_port *port)
> tcpm_set_state(port, ERROR_RECOVERY, 0);
> break;
> }
> - tcpm_set_state(port, ERROR_RECOVERY, PD_T_PS_SOURCE_ON);
> + tcpm_set_state(port, ERROR_RECOVERY, PD_T_PS_SOURCE_ON_PRS);
> break;
> case PR_SWAP_SRC_SNK_SINK_ON:
> /* Set the vbus disconnect threshold for implicit contract */
> diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h
> index 63a66dd5d832..bb9a782e1411 100644
> --- a/include/linux/usb/pd.h
> +++ b/include/linux/usb/pd.h
> @@ -466,6 +466,7 @@ static inline unsigned int rdo_max_power(u32 rdo)
> #define PD_T_DRP_SRC 30
> #define PD_T_PS_SOURCE_OFF 920
> #define PD_T_PS_SOURCE_ON 480
> +#define PD_T_PS_SOURCE_ON_PRS 450 /* 390 - 480ms */
> #define PD_T_PS_HARD_RESET 30
> #define PD_T_SRC_RECOVER 760
> #define PD_T_SRC_RECOVER_MAX 1000
> --
> 2.29.2
>

2020-12-11 08:49:00

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 5/5] USB: typec: tcpci: Add Bleed discharge to POWER_CONTROL definition

On Thu, Dec 10, 2020 at 05:05:21PM +0100, Greg Kroah-Hartman wrote:
> From: Badhri Jagan Sridharan <[email protected]>
>
> "Table 4-19. POWER_CONTROL Register Definition" from tcpci spec
> defines BIT(3) as the control bit for bleed discharge.
>
> Cc: Guenter Roeck <[email protected]>
> Cc: Heikki Krogerus <[email protected]>
> Cc: Kyle Tso <[email protected]>
> Signed-off-by: Badhri Jagan Sridharan <[email protected]>
> Signed-off-by: Will McVicker <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

Just wondering - is that going to be used in a follow-up commit ?

Reviewed-by: Guenter Roeck <[email protected]>

Guenter

> ---
> drivers/usb/typec/tcpm/tcpci.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h
> index 116a69c85e38..c3c7d07d9b4e 100644
> --- a/drivers/usb/typec/tcpm/tcpci.h
> +++ b/drivers/usb/typec/tcpm/tcpci.h
> @@ -72,6 +72,7 @@
>
> #define TCPC_POWER_CTRL 0x1c
> #define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0)
> +#define TCPC_POWER_CTRL_BLEED_DISCHARGE BIT(3)
> #define TCPC_POWER_CTRL_AUTO_DISCHARGE BIT(4)
> #define TCPC_FAST_ROLE_SWAP_EN BIT(7)
>
> --
> 2.29.2
>

2020-12-11 10:27:37

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 1/5] USB: typec: tcpm: Prevent log overflow by removing old entries

On Thu, Dec 10, 2020 at 11:10:27AM -0800, Badhri Jagan Sridharan wrote:
> Hi Guenter,
>
> While I agree with what you are saying, since the logbuffer does not
> have the intelligence to drop older entries where no issues were seen,
> logbuffer gets full pretty quickly with good instances and there is no
> space left to log the bad instance. Should wrapping this in a config

For my use case, it was typically sufficient to clear the log buffer
by reading it if needed. However, as I said, my original reason may no
longer apply. After all, the code is much more stable than it used to be,
and maybe the endless conection attempts after an initial error are no
longer seen. At this point I don't really have a strong opinion either way.

> option be a better way to go about this ? When the config optioin is
> set, old entries will be dropped.

A config option (assuming you mean Kconfig) seems bad. Maybe we could
have a writeable debugfs file which defines the approach to use (not
sure if that would be acceptable, though).

Note that I also considered changing logging to tracing, but that has
the disadvantage that it needs to be explicitly activated and doesn't
provide any kind of history in the "normal" case. On a higher level,
it would be nice to have a logging option like the one implemented here
in the infrastucture. But that is really a completely different issue.

Thanks,
Guenter

> Please let me know, I can update the patch and resend.
>
> Thanks,
> Badhri
>
>
>
> On Thu, Dec 10, 2020 at 9:53 AM Guenter Roeck <[email protected]> wrote:
> >
> > On Thu, Dec 10, 2020 at 05:05:17PM +0100, Greg Kroah-Hartman wrote:
> > > From: Badhri Jagan Sridharan <[email protected]>
> > >
> > > TCPM logs overflow once the logbuffer is full. Clear old entries and
> > > allow logging the newer ones as the newer would be more relevant to the
> > > issue being debugged.
> > >
> > > Also, do not reset the logbuffer tail as end users might take back to
> > > back bugreports which would result in an empty buffer.
> > >
> >
> > Historically, the reason for not doing this was that, once a problem occurs,
> > the log would fill up quickly (typically with reconnect attempts), and the
> > actual reason for the problem would be overwritten. Maybe that reasoning
> > no longer applies; I just wanted to point out that there _was_ a reason for
> > not clearing old log entries.
> >
> > Guenter
> >
> > > Cc: Guenter Roeck <[email protected]>
> > > Cc: Heikki Krogerus <[email protected]>
> > > Cc: Kyle Tso <[email protected]>
> > > Signed-off-by: Badhri Jagan Sridharan <[email protected]>
> > > Signed-off-by: Will McVicker <[email protected]>
> > > Signed-off-by: Greg Kroah-Hartman <[email protected]>
> > > ---
> > > drivers/usb/typec/tcpm/tcpm.c | 16 +++-------------
> > > 1 file changed, 3 insertions(+), 13 deletions(-)
> > >
> > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> > > index cedc6cf82d61..0ceeab50ed64 100644
> > > --- a/drivers/usb/typec/tcpm/tcpm.c
> > > +++ b/drivers/usb/typec/tcpm/tcpm.c
> > > @@ -470,12 +470,6 @@ static bool tcpm_port_is_disconnected(struct tcpm_port *port)
> > >
> > > #ifdef CONFIG_DEBUG_FS
> > >
> > > -static bool tcpm_log_full(struct tcpm_port *port)
> > > -{
> > > - return port->logbuffer_tail ==
> > > - (port->logbuffer_head + 1) % LOG_BUFFER_ENTRIES;
> > > -}
> > > -
> > > __printf(2, 0)
> > > static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
> > > {
> > > @@ -495,11 +489,6 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
> > >
> > > vsnprintf(tmpbuffer, sizeof(tmpbuffer), fmt, args);
> > >
> > > - if (tcpm_log_full(port)) {
> > > - port->logbuffer_head = max(port->logbuffer_head - 1, 0);
> > > - strcpy(tmpbuffer, "overflow");
> > > - }
> > > -
> > > if (port->logbuffer_head < 0 ||
> > > port->logbuffer_head >= LOG_BUFFER_ENTRIES) {
> > > dev_warn(port->dev,
> > > @@ -519,6 +508,9 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
> > > (unsigned long)ts_nsec, rem_nsec / 1000,
> > > tmpbuffer);
> > > port->logbuffer_head = (port->logbuffer_head + 1) % LOG_BUFFER_ENTRIES;
> > > + if (port->logbuffer_head == port->logbuffer_tail)
> > > + port->logbuffer_tail =
> > > + (port->logbuffer_tail + 1) % LOG_BUFFER_ENTRIES;
> > >
> > > abort:
> > > mutex_unlock(&port->logbuffer_lock);
> > > @@ -622,8 +614,6 @@ static int tcpm_debug_show(struct seq_file *s, void *v)
> > > seq_printf(s, "%s\n", port->logbuffer[tail]);
> > > tail = (tail + 1) % LOG_BUFFER_ENTRIES;
> > > }
> > > - if (!seq_has_overflowed(s))
> > > - port->logbuffer_tail = tail;
> > > mutex_unlock(&port->logbuffer_lock);
> > >
> > > return 0;
> > > --
> > > 2.29.2
> > >

2020-12-11 12:29:21

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH 0/5] USB: typec: various patches

On Thu, Dec 10, 2020 at 05:05:16PM +0100, Greg Kroah-Hartman wrote:
> In digging through a large set of proposed typec patches for the Android
> common kernel, I've picked out 5 "easy" patches that should all go
> upstream (they all should go upstream, just will take a while to clean
> them up it seems...)

Cool. Is there already support for the new Enter_USB message? Badhri,
maybe you know more about this, if somebody is working on that or not?

FWIW, for all except the first patch 1/5:

Acked-by: Heikki Krogerus <[email protected]>

> Badhri Jagan Sridharan (2):
> USB: typec: tcpm: Prevent log overflow by removing old entries
> USB: typec: tcpci: Add Bleed discharge to POWER_CONTROL definition
>
> Kyle Tso (2):
> USB: typec: tcpm: Fix PR_SWAP error handling
> USB: typec: tcpm: Add a 30ms room for tPSSourceOn in PR_SWAP
>
> pumahsu (1):
> USB: typec: tcpm: Hard Reset after not receiving a Request
>
> drivers/usb/typec/tcpm/tcpci.h | 1 +
> drivers/usb/typec/tcpm/tcpm.c | 30 +++++++++++++++---------------
> include/linux/usb/pd.h | 1 +
> 3 files changed, 17 insertions(+), 15 deletions(-)
>
> --
> 2.29.2

thanks,

--
heikki

2020-12-11 13:23:16

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 0/5] USB: typec: various patches

On Fri, Dec 11, 2020 at 10:30:10AM +0200, Heikki Krogerus wrote:
> On Thu, Dec 10, 2020 at 05:05:16PM +0100, Greg Kroah-Hartman wrote:
> > In digging through a large set of proposed typec patches for the Android
> > common kernel, I've picked out 5 "easy" patches that should all go
> > upstream (they all should go upstream, just will take a while to clean
> > them up it seems...)
>
> Cool. Is there already support for the new Enter_USB message? Badhri,
> maybe you know more about this, if somebody is working on that or not?
>
> FWIW, for all except the first patch 1/5:
>
> Acked-by: Heikki Krogerus <[email protected]>

Thanks, will drop patch 1 from the queue.

greg k-h

2020-12-11 16:39:59

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 5/5] USB: typec: tcpci: Add Bleed discharge to POWER_CONTROL definition

On Thu, Dec 10, 2020 at 08:47:04PM -0800, Badhri Jagan Sridharan wrote:
> Hi Greg,
>
> I have a patch ready to enable BLEED_DISCHARGE in tcpci code.
> I will send that in once you merge this patch to usb-next.

Feel free to send that now, no need to wait :)

thanks,

greg k-h