From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 32561C369AB for ; Tue, 15 Apr 2025 17:38:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AsAyDVMbjjsN4PUqyCAVbanisdIFDXY47ohYY10V5Ww=; b=rqftzZncuO567tYIpZxdWvNKR1 8h/iP7YzjbaFYu85h8+7DRlY9FKASDGmB22RUy7VF4GZQSCH5ooN1MbM87GnfHEIaC3Rj/S5PajXh I74i4Z07UIN6C6iHc7W/s6JIQunq4VmkDg3x0BXjNtsoOtdJIVEw/1HWYZz1lwTlsBK+nxCkVoRMz IZDttt2sseN0Ge/LA57p6ZqbHlv/nQsA+tRJrc0sAnTf48N3wL4MGLzys285kcXVNtXnq5kJ83B1r Hm4afUF7osrbDbqeuSe+VEvKPS1aD/vBq5B0MNRWu1oYzycFekMXXrb/yuy9mg24luJllDXT6vW5v 46qfTBMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4kEp-00000006bGm-0sqa; Tue, 15 Apr 2025 17:38:23 +0000 Received: from out-183.mta0.migadu.com ([2001:41d0:1004:224b::b7]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4jpr-00000006Whr-1eeY for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2025 17:12:36 +0000 Date: Tue, 15 Apr 2025 13:12:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rosenzweig.io; s=key1; t=1744737152; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AsAyDVMbjjsN4PUqyCAVbanisdIFDXY47ohYY10V5Ww=; b=Otg4poFRNuVp6rDrDol8V3vfZfcG4CE58R04ABqAIzeFZHzkoSyq/dyRGsmsD24V/AQmsO L3ipkO9TRoB0TOIxNgJWfSM7hMMC0iNUrqiyRGKYIzTjwDaSu+N5EuW9/JvQvGyeD+2s3B nGG/AqivOuVIKh90svMU9NjMFZ6avEVkxhX4M8zplhG1nLAvM75ynlourGl6X2bFhzgP7v 3mV4n6P6Icznid3drlt1H55/vA2FZsKwhRKn3Q+s3tWUebidtLYWeBQPZEF4wxaToBUMXF nI9Qch+h19SK+diWQc4KRps0EKUysBXnthyFXH/cgEAgIKvteDmkE+8jdk3t8A== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Alyssa Rosenzweig To: sven@svenpeter.dev Cc: Janne Grunau , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Andi Shyti , Neal Gompa , Hector Martin , linuxppc-dev@lists.ozlabs.org, asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 4/6] i2c: pasemi: Improve error recovery Message-ID: References: <20250415-pasemi-fixes-v2-0-c543bf53151a@svenpeter.dev> <20250415-pasemi-fixes-v2-4-c543bf53151a@svenpeter.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20250415-pasemi-fixes-v2-4-c543bf53151a@svenpeter.dev> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250415_101235_599496_AAF47E33 X-CRM114-Status: GOOD ( 27.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Reviewed-by: Alyssa Rosenzweig Le Tue , Apr 15, 2025 at 03:36:58PM +0000, Sven Peter via B4 Relay a écrit : > From: Hector Martin > > The hardware (supposedly) has a 25ms timeout for clock stretching > and the driver uses 100ms which should be plenty. The error > reocvery itself is however lacking. > > Add handling for all the missing error condition, and better recovery in > pasemi_smb_clear(). Also move the timeout to a #define since it's used > in multiple places now. > > Signed-off-by: Hector Martin > [sven: adjusted commit message after splitting the commit into two] > Signed-off-by: Sven Peter > --- > drivers/i2c/busses/i2c-pasemi-core.c | 75 +++++++++++++++++++++++++++++++----- > 1 file changed, 65 insertions(+), 10 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-pasemi-core.c b/drivers/i2c/busses/i2c-pasemi-core.c > index 9b611dbdfef23e78a4ea75ac0311938d52b6ba96..2f31f039bedfd7f78d6572fe925125b1a6d0724b 100644 > --- a/drivers/i2c/busses/i2c-pasemi-core.c > +++ b/drivers/i2c/busses/i2c-pasemi-core.c > @@ -9,6 +9,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -52,6 +53,12 @@ > #define CTL_UJM BIT(8) > #define CTL_CLK_M GENMASK(7, 0) > > +/* > + * The hardware (supposedly) has a 25ms timeout for clock stretching, thus > + * use 100ms here which should be plenty. > + */ > +#define TRANSFER_TIMEOUT_MS 100 > + > static inline void reg_write(struct pasemi_smbus *smbus, int reg, int val) > { > dev_dbg(smbus->dev, "smbus write reg %x val %08x\n", reg, val); > @@ -80,24 +87,44 @@ static void pasemi_reset(struct pasemi_smbus *smbus) > reinit_completion(&smbus->irq_completion); > } > > -static void pasemi_smb_clear(struct pasemi_smbus *smbus) > +static int pasemi_smb_clear(struct pasemi_smbus *smbus) > { > unsigned int status; > + int ret; > > - status = reg_read(smbus, REG_SMSTA); > + /* First wait for the bus to go idle */ > + ret = readx_poll_timeout(ioread32, smbus->ioaddr + REG_SMSTA, > + status, !(status & (SMSTA_XIP | SMSTA_JAM)), > + USEC_PER_MSEC, USEC_PER_MSEC * TRANSFER_TIMEOUT_MS); > + > + if (ret < 0) { > + dev_err(smbus->dev, "Bus is still stuck (status 0x%08x)\n", status); > + return -EIO; > + } > + > + /* If any badness happened or there is data in the FIFOs, reset the FIFOs */ > + if ((status & (SMSTA_MRNE | SMSTA_JMD | SMSTA_MTO | SMSTA_TOM | SMSTA_MTN | SMSTA_MTA)) || > + !(status & SMSTA_MTE)) > + pasemi_reset(smbus); > + > + /* Clear the flags */ > reg_write(smbus, REG_SMSTA, status); > + > + return 0; > } > > static int pasemi_smb_waitready(struct pasemi_smbus *smbus) > { > - int timeout = 100; > + int timeout = TRANSFER_TIMEOUT_MS; > int ret; > unsigned int status; > > if (smbus->use_irq) { > reinit_completion(&smbus->irq_completion); > - reg_write(smbus, REG_IMASK, SMSTA_XEN | SMSTA_MTN); > - ret = wait_for_completion_timeout(&smbus->irq_completion, msecs_to_jiffies(100)); > + /* XEN should be set when a transaction terminates, whether due to error or not */ > + reg_write(smbus, REG_IMASK, SMSTA_XEN); > + ret = wait_for_completion_timeout(&smbus->irq_completion, > + msecs_to_jiffies(timeout)); > reg_write(smbus, REG_IMASK, 0); > status = reg_read(smbus, REG_SMSTA); > > @@ -123,9 +150,35 @@ static int pasemi_smb_waitready(struct pasemi_smbus *smbus) > } > } > > + /* Controller timeout? */ > + if (status & SMSTA_TOM) { > + dev_warn(smbus->dev, "Controller timeout, status 0x%08x\n", status); > + return -EIO; > + } > + > + /* Peripheral timeout? */ > + if (status & SMSTA_MTO) { > + dev_warn(smbus->dev, "Peripheral timeout, status 0x%08x\n", status); > + return -ETIME; > + } > + > + /* Still stuck in a transaction? */ > + if (status & SMSTA_XIP) { > + dev_warn(smbus->dev, "Bus stuck, status 0x%08x\n", status); > + return -EIO; > + } > + > + /* Arbitration loss? */ > + if (status & SMSTA_MTA) { > + dev_warn(smbus->dev, "Arbitration loss, status 0x%08x\n", status); > + return -EBUSY; > + } > + > /* Got NACK? */ > - if (status & SMSTA_MTN) > + if (status & SMSTA_MTN) { > + dev_warn(smbus->dev, "NACK, status 0x%08x\n", status); > return -ENXIO; > + } > > /* Clear XEN */ > reg_write(smbus, REG_SMSTA, SMSTA_XEN); > @@ -187,9 +240,9 @@ static int pasemi_i2c_xfer(struct i2c_adapter *adapter, > struct pasemi_smbus *smbus = adapter->algo_data; > int ret, i; > > - pasemi_smb_clear(smbus); > - > - ret = 0; > + ret = pasemi_smb_clear(smbus); > + if (ret) > + return ret; > > for (i = 0; i < num && !ret; i++) > ret = pasemi_i2c_xfer_msg(adapter, &msgs[i], (i == (num - 1))); > @@ -210,7 +263,9 @@ static int pasemi_smb_xfer(struct i2c_adapter *adapter, > addr <<= 1; > read_flag = read_write == I2C_SMBUS_READ; > > - pasemi_smb_clear(smbus); > + err = pasemi_smb_clear(smbus); > + if (err) > + return err; > > switch (size) { > case I2C_SMBUS_QUICK: > > -- > 2.34.1 > >