mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: "Christian A. Ehrhardt" <lk@c--e.de>
Cc: linux-kernel@vger.kernel.org,
	"Dmitry Baryshkov" <dmitry.baryshkov@linaro.org>,
	"Diogo Ivo" <diogo.ivo@tecnico.ulisboa.pt>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Prashant Malani" <pmalani@chromium.org>,
	"Jameson Thies" <jthies@google.com>,
	"Abhishek Pandit-Subedi" <abhishekpandit@chromium.org>,
	"Neil Armstrong" <neil.armstrong@linaro.org>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Samuel Čavoj" <samuel@cavoj.net>,
	linux-usb@vger.kernel.org
Subject: Re: [PATCH 2/3] usb: typec: ucsi: Never send a lone connector change ack
Date: Wed, 3 Apr 2024 13:40:01 +0300	[thread overview]
Message-ID: <Zg0yAfuhoOT0XrX+@kuha.fi.intel.com> (raw)
In-Reply-To: <20240327224554.1772525-3-lk@c--e.de>

On Wed, Mar 27, 2024 at 11:45:53PM +0100, Christian A. Ehrhardt wrote:
> Some PPM implementation do not like UCSI_ACK_CONNECTOR_CHANGE
> without UCSI_ACK_COMMAND_COMPLETE. Moreover, doing this is racy
> as it requires sending two UCSI_ACK_CC_CI commands in a row and
> the second one will be started with UCSI_CCI_ACK_COMPLETE already
> set in CCI.
> 
> Bundle the UCSI_ACK_CONNECTOR_CHANGE with the UCSI_ACK_COMMAND_COMPLETE
> for the UCSI_GET_CONNECTOR_STATUS command that is sent while
> handling a connector change event.
> 
> Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/ucsi/ucsi.c | 48 +++++++++++++++--------------------
>  1 file changed, 21 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 31d8a46ae5e7..48f093a1dc09 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -49,22 +49,16 @@ static int ucsi_read_message_in(struct ucsi *ucsi, void *buf,
>  	return ucsi->ops->read(ucsi, UCSI_MESSAGE_IN, buf, buf_size);
>  }
>  
> -static int ucsi_acknowledge_command(struct ucsi *ucsi)
> +static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack)
>  {
>  	u64 ctrl;
>  
>  	ctrl = UCSI_ACK_CC_CI;
>  	ctrl |= UCSI_ACK_COMMAND_COMPLETE;
> -
> -	return ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &ctrl, sizeof(ctrl));
> -}
> -
> -static int ucsi_acknowledge_connector_change(struct ucsi *ucsi)
> -{
> -	u64 ctrl;
> -
> -	ctrl = UCSI_ACK_CC_CI;
> -	ctrl |= UCSI_ACK_CONNECTOR_CHANGE;
> +	if (conn_ack) {
> +		clear_bit(EVENT_PENDING, &ucsi->flags);
> +		ctrl |= UCSI_ACK_CONNECTOR_CHANGE;
> +	}
>  
>  	return ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &ctrl, sizeof(ctrl));
>  }
> @@ -77,7 +71,7 @@ static int ucsi_read_error(struct ucsi *ucsi)
>  	int ret;
>  
>  	/* Acknowledge the command that failed */
> -	ret = ucsi_acknowledge_command(ucsi);
> +	ret = ucsi_acknowledge(ucsi, false);
>  	if (ret)
>  		return ret;
>  
> @@ -89,7 +83,7 @@ static int ucsi_read_error(struct ucsi *ucsi)
>  	if (ret)
>  		return ret;
>  
> -	ret = ucsi_acknowledge_command(ucsi);
> +	ret = ucsi_acknowledge(ucsi, false);
>  	if (ret)
>  		return ret;
>  
> @@ -152,7 +146,7 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd)
>  		return -EIO;
>  
>  	if (cci & UCSI_CCI_NOT_SUPPORTED) {
> -		if (ucsi_acknowledge_command(ucsi) < 0)
> +		if (ucsi_acknowledge(ucsi, false) < 0)
>  			dev_err(ucsi->dev,
>  				"ACK of unsupported command failed\n");
>  		return -EOPNOTSUPP;
> @@ -165,15 +159,15 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd)
>  	}
>  
>  	if (cmd == UCSI_CANCEL && cci & UCSI_CCI_CANCEL_COMPLETE) {
> -		ret = ucsi_acknowledge_command(ucsi);
> +		ret = ucsi_acknowledge(ucsi, false);
>  		return ret ? ret : -EBUSY;
>  	}
>  
>  	return UCSI_CCI_LENGTH(cci);
>  }
>  
> -int ucsi_send_command(struct ucsi *ucsi, u64 command,
> -		      void *data, size_t size)
> +static int ucsi_send_command_common(struct ucsi *ucsi, u64 command,
> +				    void *data, size_t size, bool conn_ack)
>  {
>  	u8 length;
>  	int ret;
> @@ -192,7 +186,7 @@ int ucsi_send_command(struct ucsi *ucsi, u64 command,
>  			goto out;
>  	}
>  
> -	ret = ucsi_acknowledge_command(ucsi);
> +	ret = ucsi_acknowledge(ucsi, conn_ack);
>  	if (ret)
>  		goto out;
>  
> @@ -201,6 +195,12 @@ int ucsi_send_command(struct ucsi *ucsi, u64 command,
>  	mutex_unlock(&ucsi->ppm_lock);
>  	return ret;
>  }
> +
> +int ucsi_send_command(struct ucsi *ucsi, u64 command,
> +		      void *data, size_t size)
> +{
> +	return ucsi_send_command_common(ucsi, command, data, size, false);
> +}
>  EXPORT_SYMBOL_GPL(ucsi_send_command);
>  
>  /* -------------------------------------------------------------------------- */
> @@ -1168,7 +1168,9 @@ static void ucsi_handle_connector_change(struct work_struct *work)
>  	mutex_lock(&con->lock);
>  
>  	command = UCSI_GET_CONNECTOR_STATUS | UCSI_CONNECTOR_NUMBER(con->num);
> -	ret = ucsi_send_command(ucsi, command, &con->status, sizeof(con->status));
> +
> +	ret = ucsi_send_command_common(ucsi, command, &con->status,
> +				       sizeof(con->status), true);
>  	if (ret < 0) {
>  		dev_err(ucsi->dev, "%s: GET_CONNECTOR_STATUS failed (%d)\n",
>  			__func__, ret);
> @@ -1225,14 +1227,6 @@ static void ucsi_handle_connector_change(struct work_struct *work)
>  	if (con->status.change & UCSI_CONSTAT_CAM_CHANGE)
>  		ucsi_partner_task(con, ucsi_check_altmodes, 1, 0);
>  
> -	mutex_lock(&ucsi->ppm_lock);
> -	clear_bit(EVENT_PENDING, &con->ucsi->flags);
> -	ret = ucsi_acknowledge_connector_change(ucsi);
> -	mutex_unlock(&ucsi->ppm_lock);
> -
> -	if (ret)
> -		dev_err(ucsi->dev, "%s: ACK failed (%d)", __func__, ret);
> -
>  out_unlock:
>  	mutex_unlock(&con->lock);
>  }
> -- 
> 2.40.1

-- 
heikki

  reply	other threads:[~2024-04-03 10:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27 22:45 [PATCH 0/3] usb: typec: ucsi: Ack connector change early Christian A. Ehrhardt
2024-03-27 22:45 ` [PATCH 1/3] usb: typec: ucsi: Stop abuse of bit definitions from ucsi.h Christian A. Ehrhardt
2024-04-03 10:39   ` Heikki Krogerus
2024-03-27 22:45 ` [PATCH 2/3] usb: typec: ucsi: Never send a lone connector change ack Christian A. Ehrhardt
2024-04-03 10:40   ` Heikki Krogerus [this message]
2024-03-27 22:45 ` [PATCH 3/3] usb: typec: ucsi_acpi: Remove Dell quirk Christian A. Ehrhardt
2024-04-03 10:40   ` Heikki Krogerus
2024-03-29  5:56 ` [PATCH 0/3] usb: typec: ucsi: Ack connector change early Dmitry Baryshkov

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=Zg0yAfuhoOT0XrX+@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=abhishekpandit@chromium.org \
    --cc=diogo.ivo@tecnico.ulisboa.pt \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jthies@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lk@c--e.de \
    --cc=neil.armstrong@linaro.org \
    --cc=pmalani@chromium.org \
    --cc=samuel@cavoj.net \
    --cc=u.kleine-koenig@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®