From: Leif Lindholm <leif.lindholm@linaro.org>
To: Marcin Wojtas <mw@semihalf.com>
Cc: edk2-devel@lists.01.org, ard.biesheuvel@linaro.org,
nadavh@marvell.com, neta@marvell.com, kostap@marvell.com,
jinghua@marvell.com, jsd@semihalf.com,
David Greeson <dgreeson@cisco.com>
Subject: Re: [platforms: PATCH v2 01/10] Marvell/Drivers: MvI2cDxe: Abort transaction immediately upon fail
Date: Fri, 27 Oct 2017 15:28:54 +0100 [thread overview]
Message-ID: <20171027142854.wpcx6tcpel3nxteq@bivouac.eciton.net> (raw)
In-Reply-To: <1509066832-5285-2-git-send-email-mw@semihalf.com>
On Fri, Oct 27, 2017 at 03:13:43AM +0200, Marcin Wojtas wrote:
> From: David Greeson <dgreeson@cisco.com>
>
> Although the I2C transaction routines were prepared to
> return their status, they were never used. This could
> cause bus lock-up e.g. in case of failing to send a
> slave address, the data transfer was attempted to be
> continued anyway.
>
> This patch fixes faulty behavior by checking transaction
> status and stopping it immediately, once the fail
> is detected. On the occasion fix style around modified
> functions calls.
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: David Greeson <dgreeson@cisco.com>
> [Style adjustment and cleanup]
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
> ---
> Platform/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c | 62 +++++++++++++-------
> 1 file changed, 41 insertions(+), 21 deletions(-)
>
> diff --git a/Platform/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c b/Platform/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c
> index d85ee0b..b4599d2 100755
> --- a/Platform/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c
> +++ b/Platform/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c
> @@ -565,6 +565,7 @@ MvI2cStartRequest (
> UINTN Transmitted;
> I2C_MASTER_CONTEXT *I2cMasterContext = I2C_SC_FROM_MASTER(This);
> EFI_I2C_OPERATION *Operation;
> + EFI_STATUS Status = EFI_SUCCESS;
>
> ASSERT (RequestPacket != NULL);
> ASSERT (I2cMasterContext != NULL);
> @@ -574,33 +575,52 @@ MvI2cStartRequest (
> ReadMode = Operation->Flags & I2C_FLAG_READ;
>
> if (Count == 0) {
> - MvI2cStart ( I2cMasterContext,
> - (SlaveAddress << 1) | ReadMode,
> - I2C_TRANSFER_TIMEOUT
> - );
> + Status = MvI2cStart (I2cMasterContext,
> + (SlaveAddress << 1) | ReadMode,
> + I2C_TRANSFER_TIMEOUT);
> } else if (!(Operation->Flags & I2C_FLAG_NORESTART)) {
> - MvI2cRepeatedStart ( I2cMasterContext,
> - (SlaveAddress << 1) | ReadMode,
> - I2C_TRANSFER_TIMEOUT
> - );
> + Status = MvI2cRepeatedStart (I2cMasterContext,
> + (SlaveAddress << 1) | ReadMode,
> + I2C_TRANSFER_TIMEOUT);
> }
>
> + /* I2C transaction was aborted, so stop further transactions */
> + if (EFI_ERROR (Status)) {
> + MvI2cStop (I2cMasterContext);
> + break;
> + }
> +
> + /*
> + * If sending the slave address was successful,
> + * proceed to read or write section.
> + */
> if (ReadMode) {
> - MvI2cRead ( I2cMasterContext,
> - Operation->Buffer,
> - Operation->LengthInBytes,
> - &Transmitted,
> - Count == 1,
> - I2C_TRANSFER_TIMEOUT
> - );
> + Status = MvI2cRead (I2cMasterContext,
> + Operation->Buffer,
> + Operation->LengthInBytes,
> + &Transmitted,
> + Count == 1,
> + I2C_TRANSFER_TIMEOUT);
> + Operation->LengthInBytes = Transmitted;
> } else {
> - MvI2cWrite ( I2cMasterContext,
> - Operation->Buffer,
> - Operation->LengthInBytes,
> - &Transmitted,
> - I2C_TRANSFER_TIMEOUT
> - );
> + Status = MvI2cWrite (I2cMasterContext,
> + Operation->Buffer,
> + Operation->LengthInBytes,
> + &Transmitted,
> + I2C_TRANSFER_TIMEOUT);
> + Operation->LengthInBytes = Transmitted;
> }
> +
> + /*
> + * The I2C read or write transaction failed.
> + * Stop the I2C transaction.
> + */
> + if (EFI_ERROR (Status)) {
> + MvI2cStop (I2cMasterContext);
> + break;
> + }
> +
> + /* Check if there is any more data to be sent */
> if (Count == RequestPacket->OperationCount - 1) {
> MvI2cStop ( I2cMasterContext );
> }
> --
> 2.7.4
>
next prev parent reply other threads:[~2017-10-27 14:25 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-27 1:13 [platforms: PATCH v2 00/10] Armada 7k/8k - misc improvements pt.2 Marcin Wojtas
2017-10-27 1:13 ` [platforms: PATCH v2 01/10] Marvell/Drivers: MvI2cDxe: Abort transaction immediately upon fail Marcin Wojtas
2017-10-27 14:28 ` Leif Lindholm [this message]
2017-10-27 1:13 ` [platforms: PATCH v2 02/10] Marvell/Drivers: MvI2cDxe: Fix returning status in MvI2cStartRequest Marcin Wojtas
2017-10-27 14:29 ` Leif Lindholm
2017-10-27 1:13 ` [platforms: PATCH v2 03/10] Marvell/Drivers: MvI2cDxe: Reduce bus occupation time Marcin Wojtas
2017-10-27 1:13 ` [platforms: PATCH v2 04/10] Marvell/Library: MppLib: Prevent overwriting PCD values Marcin Wojtas
2017-10-27 1:13 ` [platforms: PATCH v2 05/10] Marvell/Library: MppLib: Disable the stack protector Marcin Wojtas
2017-10-27 1:13 ` [platforms: PATCH v2 06/10] Marvell/Library: MppLib: Take 0xFF placeholders into account Marcin Wojtas
2017-10-27 14:30 ` Leif Lindholm
2017-10-27 1:13 ` [platforms: PATCH v2 07/10] Marvell/Drivers: Pp2Dxe: Change settings for the always-up link Marcin Wojtas
2017-10-27 14:36 ` Leif Lindholm
2017-10-27 14:49 ` Marcin Wojtas
2017-10-27 1:13 ` [platforms: PATCH v2 08/10] Marvell/Drivers: XenonDxe: Fix UHS signalling mode setting Marcin Wojtas
2017-10-27 14:37 ` Leif Lindholm
2017-10-27 1:13 ` [platforms: PATCH v2 09/10] Marvell/Drivers: XenonDxe: Allow overriding base clock frequency Marcin Wojtas
2017-10-27 14:51 ` Leif Lindholm
2017-10-27 15:30 ` Marcin Wojtas
2017-10-27 1:13 ` [platforms: PATCH v2 10/10] Marvell/Drivers: XenonDxe: Do not modify FIFO default values Marcin Wojtas
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-list 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=20171027142854.wpcx6tcpel3nxteq@bivouac.eciton.net \
--to=devel@edk2.groups.io \
/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