From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=2a00:1450:4010:c07::242; helo=mail-lf0-x242.google.com; envelope-from=mw@semihalf.com; receiver=edk2-devel@lists.01.org Received: from mail-lf0-x242.google.com (mail-lf0-x242.google.com [IPv6:2a00:1450:4010:c07::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CF30F2034A7B8 for ; Wed, 25 Oct 2017 18:16:14 -0700 (PDT) Received: by mail-lf0-x242.google.com with SMTP id 75so1949663lfx.1 for ; Wed, 25 Oct 2017 18:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7MAtV9Y3dbCdLDNBKC5bUfr3HpBLZDupJWyLmeBN+IQ=; b=iKJodbxmF96R1uuMJF8mj5Bi/wYpfOUNKzjg/6Y4A/2cuacNFjwvWlowORARrjuCOR JRWd6pkGDoI8QlyonaIxfPKOa0WEbUMG5sSLoUWruuKZGPZi1or0Y7ar+szU+EzxAaUW POfWET0yn1+rR5seFt7OuOsKXSTaqOtyFtYHgiL1VfP1ks2K06S7n+EkJ1Y2cKEL2syi g2m3XGnwqKYEATisw7rcK+p9v3JvDPv5aSbh/jbK0NXxGmwNaDr2UcQoK67iQKF8Jx1y 683/D6bdyyQrEBP7v/zFl48vGJ4KXVzGo9EgfGZtgABL8nI34uK6nB2hDeQXdD7M9eRq Zy9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7MAtV9Y3dbCdLDNBKC5bUfr3HpBLZDupJWyLmeBN+IQ=; b=QElt4Ey/3imreU0xhGpqPVJkhmIgkLjlJJ1A9Cf2ljInB8UsPGTTBTzw8XccmmCQMS 8kx+J0ki1Qc7HjGdjGgSbzDDxqvX/UimxXGXqnRCGMkj28Xz0vY6W266aaYcXw13xRUN JHm8RTo/9T44ShLKR95dMVrKS/Lc3O9rkrCoLBEEkn33KZrf6rNbN2uPeNWIPEvGmL12 zAxbFnnoSLpu3O9Kw7p+UShvj26+VdgXZgB6sFpU5nbK6UtzcJIdJB2r3aI3OZJb6G5B gL+MHdLS8az8wpo3+hTdU7nEtBeAuu4+Fb74s9lIYOeaI6AYf16p+kY8iRC9B2Q+imvj nXXg== X-Gm-Message-State: AMCzsaXMKDbsW3i/7v09ibudlzAipMRcXo0VlT8EHE9p8+HEM8Uqh+Kf DP2wFPlwnY0MbD5GfmZGiScHmlhggXY= X-Google-Smtp-Source: ABhQp+Sri/jGznZwAhRgnHw1lgfammutO2xThYaeycaQzggMwwGgyDxalQ1sQZLtTL14rHblCBTixA== X-Received: by 10.25.228.129 with SMTP id x1mr6185110lfi.232.1508980798423; Wed, 25 Oct 2017 18:19:58 -0700 (PDT) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id h26sm1053428lja.69.2017.10.25.18.19.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Oct 2017 18:19:57 -0700 (PDT) From: Marcin Wojtas To: edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, nadavh@marvell.com, neta@marvell.com, kostap@marvell.com, jinghua@marvell.com, mw@semihalf.com, jsd@semihalf.com, David Greeson Date: Thu, 26 Oct 2017 03:19:28 +0200 Message-Id: <1508980777-29006-2-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508980777-29006-1-git-send-email-mw@semihalf.com> References: <1508980777-29006-1-git-send-email-mw@semihalf.com> Subject: [platforms: PATCH 01/10] Marvell/Drivers: MvI2cDxe: Abort transaction immediately upon fail X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Oct 2017 01:16:15 -0000 From: David Greeson 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. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: David Greeson [Style adjustment and cleanup] Signed-off-by: Marcin Wojtas --- Platform/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c | 34 +++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/Platform/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c b/Platform/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c index d85ee0b..7faf1f7 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,35 +575,58 @@ MvI2cStartRequest ( ReadMode = Operation->Flags & I2C_FLAG_READ; if (Count == 0) { - MvI2cStart ( I2cMasterContext, + Status = MvI2cStart (I2cMasterContext, (SlaveAddress << 1) | ReadMode, I2C_TRANSFER_TIMEOUT ); } else if (!(Operation->Flags & I2C_FLAG_NORESTART)) { - MvI2cRepeatedStart ( I2cMasterContext, + 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, + Status = MvI2cRead (I2cMasterContext, Operation->Buffer, Operation->LengthInBytes, &Transmitted, Count == 1, I2C_TRANSFER_TIMEOUT ); + Operation->LengthInBytes = Transmitted; } else { - MvI2cWrite ( I2cMasterContext, + 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 ); + MvI2cStop (I2cMasterContext); } } -- 2.7.4