* [PATCH v2] usb: typec: ucsi: Fix completion notifications
@ 2024-12-03 10:23 Łukasz Bartosik
2024-12-03 11:50 ` Dmitry Baryshkov
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Łukasz Bartosik @ 2024-12-03 10:23 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Dmitry Baryshkov
Cc: Abhishek Pandit-Subedi, Benson Leung, Jameson Thies, linux-usb,
stable
OPM PPM LPM
| 1.send cmd | |
|-------------------------->| |
| |-- |
| | | 2.set busy bit in CCI |
| |<- |
| 3.notify the OPM | |
|<--------------------------| |
| | 4.send cmd to be executed |
| |-------------------------->|
| | |
| | 5.cmd completed |
| |<--------------------------|
| | |
| |-- |
| | | 6.set cmd completed |
| |<- bit in CCI |
| | |
| 7.notify the OPM | |
|<--------------------------| |
| | |
| 8.handle notification | |
| from point 3, read CCI | |
|<--------------------------| |
| | |
When the PPM receives command from the OPM (p.1) it sets the busy bit
in the CCI (p.2), sends notification to the OPM (p.3) and forwards the
command to be executed by the LPM (p.4). When the PPM receives command
completion from the LPM (p.5) it sets command completion bit in the CCI
(p.6) and sends notification to the OPM (p.7). If command execution by
the LPM is fast enough then when the OPM starts handling the notification
from p.3 in p.8 and reads the CCI value it will see command completion bit
set and will call complete(). Then complete() might be called again when
the OPM handles notification from p.7.
This fix replaces test_bit() with test_and_clear_bit()
in ucsi_notify_common() in order to call complete() only
once per request.
This fix also reinitializes completion variable in
ucsi_sync_control_common() before a command is sent.
Fixes: 584e8df58942 ("usb: typec: ucsi: extract common code for command handling")
Cc: stable@vger.kernel.org
Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
---
Changes in v2:
- Swapped points 7 and 8 in the commit description
in order to make diagram more clear.
- Added reinitialization of completion variable
in the ucsi_sync_control_common().
---
drivers/usb/typec/ucsi/ucsi.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index c435c0835744..7a65a7672e18 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -46,11 +46,11 @@ void ucsi_notify_common(struct ucsi *ucsi, u32 cci)
ucsi_connector_change(ucsi, UCSI_CCI_CONNECTOR(cci));
if (cci & UCSI_CCI_ACK_COMPLETE &&
- test_bit(ACK_PENDING, &ucsi->flags))
+ test_and_clear_bit(ACK_PENDING, &ucsi->flags))
complete(&ucsi->complete);
if (cci & UCSI_CCI_COMMAND_COMPLETE &&
- test_bit(COMMAND_PENDING, &ucsi->flags))
+ test_and_clear_bit(COMMAND_PENDING, &ucsi->flags))
complete(&ucsi->complete);
}
EXPORT_SYMBOL_GPL(ucsi_notify_common);
@@ -65,6 +65,8 @@ int ucsi_sync_control_common(struct ucsi *ucsi, u64 command)
else
set_bit(COMMAND_PENDING, &ucsi->flags);
+ reinit_completion(&ucsi->complete);
+
ret = ucsi->ops->async_control(ucsi, command);
if (ret)
goto out_clear_bit;
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] usb: typec: ucsi: Fix completion notifications
2024-12-03 10:23 [PATCH v2] usb: typec: ucsi: Fix completion notifications Łukasz Bartosik
@ 2024-12-03 11:50 ` Dmitry Baryshkov
2024-12-03 12:48 ` Heikki Krogerus
2024-12-04 0:21 ` Benson Leung
2 siblings, 0 replies; 6+ messages in thread
From: Dmitry Baryshkov @ 2024-12-03 11:50 UTC (permalink / raw)
To: Łukasz Bartosik
Cc: Heikki Krogerus, Greg Kroah-Hartman, Abhishek Pandit-Subedi,
Benson Leung, Jameson Thies, linux-usb, stable
On Tue, 3 Dec 2024 at 12:23, Łukasz Bartosik <ukaszb@chromium.org> wrote:
>
> OPM PPM LPM
> | 1.send cmd | |
> |-------------------------->| |
> | |-- |
> | | | 2.set busy bit in CCI |
> | |<- |
> | 3.notify the OPM | |
> |<--------------------------| |
> | | 4.send cmd to be executed |
> | |-------------------------->|
> | | |
> | | 5.cmd completed |
> | |<--------------------------|
> | | |
> | |-- |
> | | | 6.set cmd completed |
> | |<- bit in CCI |
> | | |
> | 7.notify the OPM | |
> |<--------------------------| |
> | | |
> | 8.handle notification | |
> | from point 3, read CCI | |
> |<--------------------------| |
> | | |
>
> When the PPM receives command from the OPM (p.1) it sets the busy bit
> in the CCI (p.2), sends notification to the OPM (p.3) and forwards the
> command to be executed by the LPM (p.4). When the PPM receives command
> completion from the LPM (p.5) it sets command completion bit in the CCI
> (p.6) and sends notification to the OPM (p.7). If command execution by
> the LPM is fast enough then when the OPM starts handling the notification
> from p.3 in p.8 and reads the CCI value it will see command completion bit
> set and will call complete(). Then complete() might be called again when
> the OPM handles notification from p.7.
>
> This fix replaces test_bit() with test_and_clear_bit()
> in ucsi_notify_common() in order to call complete() only
> once per request.
>
> This fix also reinitializes completion variable in
> ucsi_sync_control_common() before a command is sent.
Thank you!
>
> Fixes: 584e8df58942 ("usb: typec: ucsi: extract common code for command handling")
> Cc: stable@vger.kernel.org
> Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
> ---
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] usb: typec: ucsi: Fix completion notifications
2024-12-03 10:23 [PATCH v2] usb: typec: ucsi: Fix completion notifications Łukasz Bartosik
2024-12-03 11:50 ` Dmitry Baryshkov
@ 2024-12-03 12:48 ` Heikki Krogerus
2024-12-03 12:51 ` Heikki Krogerus
2024-12-04 0:21 ` Benson Leung
2 siblings, 1 reply; 6+ messages in thread
From: Heikki Krogerus @ 2024-12-03 12:48 UTC (permalink / raw)
To: Łukasz Bartosik
Cc: Greg Kroah-Hartman, Dmitry Baryshkov, Abhishek Pandit-Subedi,
Benson Leung, Jameson Thies, linux-usb, stable
On Tue, Dec 03, 2024 at 10:23:18AM +0000, Łukasz Bartosik wrote:
> OPM PPM LPM
> | 1.send cmd | |
> |-------------------------->| |
> | |-- |
> | | | 2.set busy bit in CCI |
> | |<- |
> | 3.notify the OPM | |
> |<--------------------------| |
> | | 4.send cmd to be executed |
> | |-------------------------->|
> | | |
> | | 5.cmd completed |
> | |<--------------------------|
> | | |
> | |-- |
> | | | 6.set cmd completed |
> | |<- bit in CCI |
> | | |
> | 7.notify the OPM | |
> |<--------------------------| |
> | | |
> | 8.handle notification | |
> | from point 3, read CCI | |
> |<--------------------------| |
> | | |
>
> When the PPM receives command from the OPM (p.1) it sets the busy bit
> in the CCI (p.2), sends notification to the OPM (p.3) and forwards the
> command to be executed by the LPM (p.4). When the PPM receives command
> completion from the LPM (p.5) it sets command completion bit in the CCI
> (p.6) and sends notification to the OPM (p.7). If command execution by
> the LPM is fast enough then when the OPM starts handling the notification
> from p.3 in p.8 and reads the CCI value it will see command completion bit
> set and will call complete(). Then complete() might be called again when
> the OPM handles notification from p.7.
>
> This fix replaces test_bit() with test_and_clear_bit()
> in ucsi_notify_common() in order to call complete() only
> once per request.
>
> This fix also reinitializes completion variable in
> ucsi_sync_control_common() before a command is sent.
>
> Fixes: 584e8df58942 ("usb: typec: ucsi: extract common code for command handling")
> Cc: stable@vger.kernel.org
> Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com
> ---
>
> Changes in v2:
> - Swapped points 7 and 8 in the commit description
> in order to make diagram more clear.
> - Added reinitialization of completion variable
> in the ucsi_sync_control_common().
> ---
>
> drivers/usb/typec/ucsi/ucsi.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index c435c0835744..7a65a7672e18 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -46,11 +46,11 @@ void ucsi_notify_common(struct ucsi *ucsi, u32 cci)
> ucsi_connector_change(ucsi, UCSI_CCI_CONNECTOR(cci));
>
> if (cci & UCSI_CCI_ACK_COMPLETE &&
> - test_bit(ACK_PENDING, &ucsi->flags))
> + test_and_clear_bit(ACK_PENDING, &ucsi->flags))
> complete(&ucsi->complete);
>
> if (cci & UCSI_CCI_COMMAND_COMPLETE &&
> - test_bit(COMMAND_PENDING, &ucsi->flags))
> + test_and_clear_bit(COMMAND_PENDING, &ucsi->flags))
> complete(&ucsi->complete);
> }
> EXPORT_SYMBOL_GPL(ucsi_notify_common);
> @@ -65,6 +65,8 @@ int ucsi_sync_control_common(struct ucsi *ucsi, u64 command)
> else
> set_bit(COMMAND_PENDING, &ucsi->flags);
>
> + reinit_completion(&ucsi->complete);
> +
> ret = ucsi->ops->async_control(ucsi, command);
> if (ret)
> goto out_clear_bit;
> --
> 2.47.0.338.g60cca15819-goog
--
heikki
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] usb: typec: ucsi: Fix completion notifications
2024-12-03 12:48 ` Heikki Krogerus
@ 2024-12-03 12:51 ` Heikki Krogerus
2024-12-03 14:31 ` Łukasz Bartosik
0 siblings, 1 reply; 6+ messages in thread
From: Heikki Krogerus @ 2024-12-03 12:51 UTC (permalink / raw)
To: Łukasz Bartosik
Cc: Greg Kroah-Hartman, Dmitry Baryshkov, Abhishek Pandit-Subedi,
Benson Leung, Jameson Thies, linux-usb, stable
On Tue, Dec 03, 2024 at 02:48:59PM +0200, Heikki Krogerus wrote:
> On Tue, Dec 03, 2024 at 10:23:18AM +0000, Łukasz Bartosik wrote:
> > OPM PPM LPM
> > | 1.send cmd | |
> > |-------------------------->| |
> > | |-- |
> > | | | 2.set busy bit in CCI |
> > | |<- |
> > | 3.notify the OPM | |
> > |<--------------------------| |
> > | | 4.send cmd to be executed |
> > | |-------------------------->|
> > | | |
> > | | 5.cmd completed |
> > | |<--------------------------|
> > | | |
> > | |-- |
> > | | | 6.set cmd completed |
> > | |<- bit in CCI |
> > | | |
> > | 7.notify the OPM | |
> > |<--------------------------| |
> > | | |
> > | 8.handle notification | |
> > | from point 3, read CCI | |
> > |<--------------------------| |
> > | | |
> >
> > When the PPM receives command from the OPM (p.1) it sets the busy bit
> > in the CCI (p.2), sends notification to the OPM (p.3) and forwards the
> > command to be executed by the LPM (p.4). When the PPM receives command
> > completion from the LPM (p.5) it sets command completion bit in the CCI
> > (p.6) and sends notification to the OPM (p.7). If command execution by
> > the LPM is fast enough then when the OPM starts handling the notification
> > from p.3 in p.8 and reads the CCI value it will see command completion bit
> > set and will call complete(). Then complete() might be called again when
> > the OPM handles notification from p.7.
> >
> > This fix replaces test_bit() with test_and_clear_bit()
> > in ucsi_notify_common() in order to call complete() only
> > once per request.
> >
> > This fix also reinitializes completion variable in
> > ucsi_sync_control_common() before a command is sent.
> >
> > Fixes: 584e8df58942 ("usb: typec: ucsi: extract common code for command handling")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
>
> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Sorry about that typo.
--
heikki
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] usb: typec: ucsi: Fix completion notifications
2024-12-03 12:51 ` Heikki Krogerus
@ 2024-12-03 14:31 ` Łukasz Bartosik
0 siblings, 0 replies; 6+ messages in thread
From: Łukasz Bartosik @ 2024-12-03 14:31 UTC (permalink / raw)
To: Heikki Krogerus, Dmitry Baryshkov
Cc: Greg Kroah-Hartman, Abhishek Pandit-Subedi, Benson Leung,
Jameson Thies, linux-usb, stable
On Tue, Dec 3, 2024 at 1:51 PM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>
> On Tue, Dec 03, 2024 at 02:48:59PM +0200, Heikki Krogerus wrote:
> > On Tue, Dec 03, 2024 at 10:23:18AM +0000, Łukasz Bartosik wrote:
> > > OPM PPM LPM
> > > | 1.send cmd | |
> > > |-------------------------->| |
> > > | |-- |
> > > | | | 2.set busy bit in CCI |
> > > | |<- |
> > > | 3.notify the OPM | |
> > > |<--------------------------| |
> > > | | 4.send cmd to be executed |
> > > | |-------------------------->|
> > > | | |
> > > | | 5.cmd completed |
> > > | |<--------------------------|
> > > | | |
> > > | |-- |
> > > | | | 6.set cmd completed |
> > > | |<- bit in CCI |
> > > | | |
> > > | 7.notify the OPM | |
> > > |<--------------------------| |
> > > | | |
> > > | 8.handle notification | |
> > > | from point 3, read CCI | |
> > > |<--------------------------| |
> > > | | |
> > >
> > > When the PPM receives command from the OPM (p.1) it sets the busy bit
> > > in the CCI (p.2), sends notification to the OPM (p.3) and forwards the
> > > command to be executed by the LPM (p.4). When the PPM receives command
> > > completion from the LPM (p.5) it sets command completion bit in the CCI
> > > (p.6) and sends notification to the OPM (p.7). If command execution by
> > > the LPM is fast enough then when the OPM starts handling the notification
> > > from p.3 in p.8 and reads the CCI value it will see command completion bit
> > > set and will call complete(). Then complete() might be called again when
> > > the OPM handles notification from p.7.
> > >
> > > This fix replaces test_bit() with test_and_clear_bit()
> > > in ucsi_notify_common() in order to call complete() only
> > > once per request.
> > >
> > > This fix also reinitializes completion variable in
> > > ucsi_sync_control_common() before a command is sent.
> > >
> > > Fixes: 584e8df58942 ("usb: typec: ucsi: extract common code for command handling")
> > > Cc: stable@vger.kernel.org
> > > Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
> >
> > Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com
>
> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>
> Sorry about that typo.
>
> --
> heikki
Heikki, Dmitry,
Thank you for the review.
Regards,
Łukasz
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] usb: typec: ucsi: Fix completion notifications
2024-12-03 10:23 [PATCH v2] usb: typec: ucsi: Fix completion notifications Łukasz Bartosik
2024-12-03 11:50 ` Dmitry Baryshkov
2024-12-03 12:48 ` Heikki Krogerus
@ 2024-12-04 0:21 ` Benson Leung
2 siblings, 0 replies; 6+ messages in thread
From: Benson Leung @ 2024-12-04 0:21 UTC (permalink / raw)
To: Łukasz Bartosik
Cc: Heikki Krogerus, Greg Kroah-Hartman, Dmitry Baryshkov,
Abhishek Pandit-Subedi, Benson Leung, Jameson Thies, linux-usb,
stable
[-- Attachment #1: Type: text/plain, Size: 4155 bytes --]
On Tue, Dec 03, 2024 at 10:23:18AM +0000, Łukasz Bartosik wrote:
> OPM PPM LPM
> | 1.send cmd | |
> |-------------------------->| |
> | |-- |
> | | | 2.set busy bit in CCI |
> | |<- |
> | 3.notify the OPM | |
> |<--------------------------| |
> | | 4.send cmd to be executed |
> | |-------------------------->|
> | | |
> | | 5.cmd completed |
> | |<--------------------------|
> | | |
> | |-- |
> | | | 6.set cmd completed |
> | |<- bit in CCI |
> | | |
> | 7.notify the OPM | |
> |<--------------------------| |
> | | |
> | 8.handle notification | |
> | from point 3, read CCI | |
> |<--------------------------| |
> | | |
>
> When the PPM receives command from the OPM (p.1) it sets the busy bit
> in the CCI (p.2), sends notification to the OPM (p.3) and forwards the
> command to be executed by the LPM (p.4). When the PPM receives command
> completion from the LPM (p.5) it sets command completion bit in the CCI
> (p.6) and sends notification to the OPM (p.7). If command execution by
> the LPM is fast enough then when the OPM starts handling the notification
> from p.3 in p.8 and reads the CCI value it will see command completion bit
> set and will call complete(). Then complete() might be called again when
> the OPM handles notification from p.7.
>
> This fix replaces test_bit() with test_and_clear_bit()
> in ucsi_notify_common() in order to call complete() only
> once per request.
>
> This fix also reinitializes completion variable in
> ucsi_sync_control_common() before a command is sent.
>
> Fixes: 584e8df58942 ("usb: typec: ucsi: extract common code for command handling")
> Cc: stable@vger.kernel.org
> Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
> ---
>
> Changes in v2:
> - Swapped points 7 and 8 in the commit description
> in order to make diagram more clear.
> - Added reinitialization of completion variable
> in the ucsi_sync_control_common().
> ---
>
> drivers/usb/typec/ucsi/ucsi.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index c435c0835744..7a65a7672e18 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -46,11 +46,11 @@ void ucsi_notify_common(struct ucsi *ucsi, u32 cci)
> ucsi_connector_change(ucsi, UCSI_CCI_CONNECTOR(cci));
>
> if (cci & UCSI_CCI_ACK_COMPLETE &&
> - test_bit(ACK_PENDING, &ucsi->flags))
> + test_and_clear_bit(ACK_PENDING, &ucsi->flags))
> complete(&ucsi->complete);
>
> if (cci & UCSI_CCI_COMMAND_COMPLETE &&
> - test_bit(COMMAND_PENDING, &ucsi->flags))
> + test_and_clear_bit(COMMAND_PENDING, &ucsi->flags))
> complete(&ucsi->complete);
> }
> EXPORT_SYMBOL_GPL(ucsi_notify_common);
> @@ -65,6 +65,8 @@ int ucsi_sync_control_common(struct ucsi *ucsi, u64 command)
> else
> set_bit(COMMAND_PENDING, &ucsi->flags);
>
> + reinit_completion(&ucsi->complete);
> +
> ret = ucsi->ops->async_control(ucsi, command);
> if (ret)
> goto out_clear_bit;
> --
> 2.47.0.338.g60cca15819-goog
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-12-04 0:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-03 10:23 [PATCH v2] usb: typec: ucsi: Fix completion notifications Łukasz Bartosik
2024-12-03 11:50 ` Dmitry Baryshkov
2024-12-03 12:48 ` Heikki Krogerus
2024-12-03 12:51 ` Heikki Krogerus
2024-12-03 14:31 ` Łukasz Bartosik
2024-12-04 0:21 ` Benson Leung
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).