All of lore.kernel.org
 help / color / mirror / Atom feed
From: Diogo Ivo <diogo.ivo@tecnico.ulisboa.pt>
To: heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org,
	 neil.armstrong@linaro.org, quic_prashk@quicinc.com,
	dmitry.baryshkov@linaro.org,  fabrice.gasnier@foss.st.com,
	saranya.gopal@intel.com, lk@c--e.de, linux-usb@vger.kernel.org
Cc: diogo.ivo@tecnico.ulisboa.pt
Subject: [RFC PATCH] usb: typec: ucsi: ack connector change after all tasks finish
Date: Wed, 27 Mar 2024 12:39:04 +0000	[thread overview]
Message-ID: <vuh25ueep3rwcmthlkvhb2avpkqzc6lsbee3qdmerolijq7azq@rwmakgznqvmq> (raw)

The UCSI specification mentions that when the OPM is notified by the
PPM of an asynchronous event it should first send all the commands it
needs to get the details of the event and only after acknowledge it by
sending ACK_CC_CI with the Connector Change bit set, while the current
code sends this ack immediately after scheduling all the partner_tasks.
Move this ACK_CC_CI command to the end of all partner_tasks.

This fixes a problem with some LG Gram laptops where the PPM sometimes
notifies the OPM with the Connector Change Indicator field set in the
CCI after an ACK_CC_CI command is sent, causing the UCSI stack to check
the connector status indefinitely since the EVENT_PENDING bit is already
cleared. This causes an interrupt storm and an artificial high load on
these platforms.

It would also be interesting to see if we could take this approach and
implement the discussion in [1] regarding sending an ACK_CC_CI command
that acks both the command completion and the connector change.

Signed-off-by: Diogo Ivo <diogo.ivo@tecnico.ulisboa.pt>

[1]: https://lore.kernel.org/all/20240320073927.1641788-1-lk@c--e.de/
---
 drivers/usb/typec/ucsi/ucsi.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 0c8f3b3a99d6..b8b39e43aba8 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -69,6 +69,23 @@ static int ucsi_acknowledge_connector_change(struct ucsi *ucsi)
 	return ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &ctrl, sizeof(ctrl));
 }
 
+static void ucsi_handle_ack_connector_change(struct ucsi_connector *con)
+{
+	struct ucsi *ucsi = con->ucsi;
+	int ret;
+
+	if (list_empty(&con->partner_tasks)) {
+		mutex_lock(&ucsi->ppm_lock);
+		ret = ucsi_acknowledge_connector_change(ucsi);
+		mutex_unlock(&ucsi->ppm_lock);
+
+		if (ret)
+			dev_err(ucsi->dev, "%s: ACK failed (%d)", __func__, ret);
+
+		clear_bit(EVENT_PENDING, &ucsi->flags);
+	}
+}
+
 static int ucsi_exec_command(struct ucsi *ucsi, u64 command);
 
 static int ucsi_read_error(struct ucsi *ucsi)
@@ -222,6 +239,7 @@ static void ucsi_poll_worker(struct work_struct *work)
 		list_del(&uwork->node);
 		mutex_unlock(&con->lock);
 		kfree(uwork);
+		ucsi_handle_ack_connector_change(con);
 		return;
 	}
 
@@ -232,6 +250,7 @@ static void ucsi_poll_worker(struct work_struct *work)
 	} else {
 		list_del(&uwork->node);
 		kfree(uwork);
+		ucsi_handle_ack_connector_change(con);
 	}
 
 	mutex_unlock(&con->lock);
@@ -1215,13 +1234,7 @@ 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);
 
-	clear_bit(EVENT_PENDING, &con->ucsi->flags);
-
-	mutex_lock(&ucsi->ppm_lock);
-	ret = ucsi_acknowledge_connector_change(ucsi);
-	mutex_unlock(&ucsi->ppm_lock);
-	if (ret)
-		dev_err(ucsi->dev, "%s: ACK failed (%d)", __func__, ret);
+	ucsi_handle_ack_connector_change(con);
 
 out_unlock:
 	mutex_unlock(&con->lock);
-- 
2.44.0


             reply	other threads:[~2024-03-27 12:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27 12:39 Diogo Ivo [this message]
2024-03-27 13:06 ` [RFC PATCH] usb: typec: ucsi: ack connector change after all tasks finish Dmitry Baryshkov
2024-03-27 14:37   ` Diogo Ivo
2024-03-27 16:06 ` Christian Ehrhardt
2024-03-28 15:42   ` Diogo Ivo
2024-03-28 22:40     ` Christian Ehrhardt
2024-04-24 11:23       ` Diogo Ivo
2024-04-25 18:05         ` Christian Ehrhardt
2024-03-27 16:42 ` Christian Ehrhardt
2024-03-28 16:04   ` Diogo Ivo

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=vuh25ueep3rwcmthlkvhb2avpkqzc6lsbee3qdmerolijq7azq@rwmakgznqvmq \
    --to=diogo.ivo@tecnico.ulisboa.pt \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=lk@c--e.de \
    --cc=neil.armstrong@linaro.org \
    --cc=quic_prashk@quicinc.com \
    --cc=saranya.gopal@intel.com \
    /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.