From patchwork Fri May 26 14:56:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Merello X-Patchwork-Id: 1786599 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=iit.it header.i=@iit.it header.a=rsa-sha256 header.s=mx header.b=Ojrmi6va; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QSThG5zBtz20QF for ; Sat, 27 May 2023 01:42:38 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 474C48615E; Fri, 26 May 2023 17:42:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=iit.it Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=iit.it header.i=@iit.it header.b="Ojrmi6va"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5F29286159; Fri, 26 May 2023 16:56:44 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from es400ra02.iit.it (mx.iit.it [90.147.26.161]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C001E8613B for ; Fri, 26 May 2023 16:56:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=iit.it Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=1510dc8794=Andrea.Merello@iit.it Received: from es400ra02.iit.it (127.0.0.1) id he34ag0171sp for ; Fri, 26 May 2023 16:56:39 +0200 (envelope-from ) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iit.it; s=mx; i=@iit.it; h=Received:Received:From:To:CC:Subject:Date: Message-ID:MIME-Version:Content-Transfer-Encoding:Content-Type; bh=T/xzw4FkqlBqNG31iY0KPz9TuU+6LnM1C8ks84Kbsg8=; b=Ojrmi6vaQCg+f 3RlZRvS7y9k6FoAValtzosMXUiVCvx/GZ4uJsLy3G3mizGCcsrwumyEkcBOFXqNs I+yqh4qQ+0wHzZFh2uJNUNu+dqBwoMh6TFEh8ERyAOjU2NL9JVMTS/HHVpx/3W8e j+XjpQLDGIxHf8msnQJwbOmhdOz5XQ= Received: from mail.iit.it ([10.255.8.186]) by es400ra02.iit.it ([172.31.0.242]) (SonicWall 10.0.19.7431) with ESMTPS (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256/256) id o202305261456390230593-8; Fri, 26 May 2023 16:56:39 +0200 Received: from NewMoon.iit.local (10.245.73.32) by iitmxwge020.iit.local (10.255.8.186) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Fri, 26 May 2023 16:56:39 +0200 From: Andrea Merello To: , , CC: , Andrea Merello Subject: [PATCH] I2C: cdns: Fix broken retry mechanism on arbitration lost. Date: Fri, 26 May 2023 16:56:16 +0200 Message-ID: <20230526145616.55719-1-andrea.merello@iit.it> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.245.73.32] X-ClientProxiedBy: iitmxwge020.iit.local (10.255.8.186) To iitmxwge020.iit.local (10.255.8.186) X-Mlf-DSE-Version: 7155 X-Mlf-Rules-Version: s20230112191048; ds20200715013501; di20230516215134; ri20160318003319; fs20230515174336 X-Mlf-Smartnet-Version: 20210917223710 X-Mlf-Envelope-From: Andrea.Merello@iit.it X-Mlf-Version: 10.0.19.7431 X-Mlf-License: BSV_C_AP_T_R X-Mlf-UniqueId: o202305261456390230593 X-Mailman-Approved-At: Fri, 26 May 2023 17:42:15 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean In the current implementation, in case of I2C arbitration lost, a retry is attempted; the message counter and pointer are reset to the original values and the I2C xfer process is restart from the beginning. However the message counter and message pointer are respectively decremented and incremented by one before attempting any transfer, causing the 1st transfer not to be actually retried (in case of a single transfer, nothing is actually retried at all). This patch fixes this: in case of retry, the 1st transfer is also retried. Tested on a ZynqMP Kria board, with upstream older u-boot, but the involved file and underlying logic seem basically the same. Signed-off-by: Andrea Merello --- drivers/i2c/i2c-cdns.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/i2c/i2c-cdns.c b/drivers/i2c/i2c-cdns.c index 1a89207206..935b2ac637 100644 --- a/drivers/i2c/i2c-cdns.c +++ b/drivers/i2c/i2c-cdns.c @@ -444,7 +444,7 @@ static int cdns_i2c_xfer(struct udevice *dev, struct i2c_msg *msg, debug("i2c_xfer: %d messages\n", nmsgs); for (u8 retry = 0; retry < CDNS_I2C_ARB_LOST_MAX_RETRIES && - nmsgs > 0; nmsgs--, msg++) { + nmsgs > 0;) { debug("i2c_xfer: chip=0x%x, len=0x%x\n", msg->addr, msg->len); if (msg->flags & I2C_M_RD) { ret = cdns_i2c_read_data(i2c_bus, msg->addr, msg->buf, @@ -461,7 +461,8 @@ static int cdns_i2c_xfer(struct udevice *dev, struct i2c_msg *msg, retry); continue; } - + nmsgs--; + msg++; if (ret) { debug("i2c_write: error sending\n"); return -EREMOTEIO;