All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Kyle Tso <kyletso@google.com>,
	heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org
Cc: badhri@google.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] usb: typec: tcpm: Properly interrupt VDM AMS
Date: Fri, 21 May 2021 07:48:30 -0700	[thread overview]
Message-ID: <6872a037-c036-fd1c-608a-c33e4ef22923@roeck-us.net> (raw)
In-Reply-To: <20210521130121.1470334-2-kyletso@google.com>

On 5/21/21 6:01 AM, Kyle Tso wrote:
> When a VDM AMS is interrupted by Messages other than VDM, the AMS needs
> to be finished properly. Also start a VDM AMS if receiving SVDM Commands
> from the port partner to complement the functionality of tcpm_vdm_ams().
> 
> Fixes: 0908c5aca31e ("usb: typec: tcpm: AMS and Collision Avoidance")
> Signed-off-by: Kyle Tso <kyletso@google.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>   drivers/usb/typec/tcpm/tcpm.c | 30 ++++++++++++++++++++++++++++++
>   1 file changed, 30 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 64133e586c64..deb8a9d01f73 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -1550,6 +1550,8 @@ static int tcpm_pd_svdm(struct tcpm_port *port, struct typec_altmode *adev,
>   			if (PD_VDO_SVDM_VER(p[0]) < svdm_version)
>   				typec_partner_set_svdm_version(port->partner,
>   							       PD_VDO_SVDM_VER(p[0]));
> +
> +			tcpm_ams_start(port, DISCOVER_IDENTITY);
>   			/* 6.4.4.3.1: Only respond as UFP (device) */
>   			if (port->data_role == TYPEC_DEVICE &&
>   			    port->nr_snk_vdo) {
> @@ -1568,14 +1570,19 @@ static int tcpm_pd_svdm(struct tcpm_port *port, struct typec_altmode *adev,
>   			}
>   			break;
>   		case CMD_DISCOVER_SVID:
> +			tcpm_ams_start(port, DISCOVER_SVIDS);
>   			break;
>   		case CMD_DISCOVER_MODES:
> +			tcpm_ams_start(port, DISCOVER_MODES);
>   			break;
>   		case CMD_ENTER_MODE:
> +			tcpm_ams_start(port, DFP_TO_UFP_ENTER_MODE);
>   			break;
>   		case CMD_EXIT_MODE:
> +			tcpm_ams_start(port, DFP_TO_UFP_EXIT_MODE);
>   			break;
>   		case CMD_ATTENTION:
> +			tcpm_ams_start(port, ATTENTION);
>   			/* Attention command does not have response */
>   			*adev_action = ADEV_ATTENTION;
>   			return 0;
> @@ -2287,6 +2294,12 @@ static void tcpm_pd_data_request(struct tcpm_port *port,
>   	bool frs_enable;
>   	int ret;
>   
> +	if (tcpm_vdm_ams(port) && type != PD_DATA_VENDOR_DEF) {
> +		port->vdm_state == VDM_STATE_ERR_BUSY;
> +		tcpm_ams_finish(port);
> +		mod_vdm_delayed_work(port, 0);
> +	}
> +
>   	switch (type) {
>   	case PD_DATA_SOURCE_CAP:
>   		for (i = 0; i < cnt; i++)
> @@ -2459,6 +2472,16 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
>   	enum pd_ctrl_msg_type type = pd_header_type_le(msg->header);
>   	enum tcpm_state next_state;
>   
> +	/*
> +	 * Stop VDM state machine if interrupted by other Messages while NOT_SUPP is allowed in
> +	 * VDM AMS if waiting for VDM responses and will be handled later.
> +	 */
> +	if (tcpm_vdm_ams(port) && type != PD_CTRL_NOT_SUPP && type != PD_CTRL_GOOD_CRC) {
> +		port->vdm_state = VDM_STATE_ERR_BUSY;
> +		tcpm_ams_finish(port);
> +		mod_vdm_delayed_work(port, 0);
> +	}
> +
>   	switch (type) {
>   	case PD_CTRL_GOOD_CRC:
>   	case PD_CTRL_PING:
> @@ -2717,6 +2740,13 @@ static void tcpm_pd_ext_msg_request(struct tcpm_port *port,
>   	enum pd_ext_msg_type type = pd_header_type_le(msg->header);
>   	unsigned int data_size = pd_ext_header_data_size_le(msg->ext_msg.header);
>   
> +	/* stopping VDM state machine if interrupted by other Messages */
> +	if (tcpm_vdm_ams(port)) {
> +		port->vdm_state = VDM_STATE_ERR_BUSY;
> +		tcpm_ams_finish(port);
> +		mod_vdm_delayed_work(port, 0);
> +	}
> +
>   	if (!(msg->ext_msg.header & PD_EXT_HDR_CHUNKED)) {
>   		tcpm_pd_handle_msg(port, PD_MSG_CTRL_NOT_SUPP, NONE_AMS);
>   		tcpm_log(port, "Unchunked extended messages unsupported");
> 


  reply	other threads:[~2021-05-21 14:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-21 13:01 [PATCH 0/2] Fix some VDM AMS handling Kyle Tso
2021-05-21 13:01 ` [PATCH 1/2] usb: typec: tcpm: Properly interrupt VDM AMS Kyle Tso
2021-05-21 14:48   ` Guenter Roeck [this message]
2021-05-22 20:22   ` kernel test robot
2021-05-22 20:22     ` kernel test robot
2021-05-23  2:02     ` Kyle Tso
2021-05-23  2:02       ` Kyle Tso
2021-05-21 13:01 ` [PATCH 2/2] usb: typec: tcpm: Respond Not_Supported if no snk_vdo Kyle Tso
2021-05-21 14:48   ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6872a037-c036-fd1c-608a-c33e4ef22923@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=badhri@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=kyletso@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.