Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2642478rdb; Fri, 22 Sep 2023 04:58:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3RwMX4iUCcrjtTOej1B7pOD8TRWWoofRs/rntUjvmd/jyy8BKS/nLT58q/1faV2+a2WGT X-Received: by 2002:a05:6358:618c:b0:142:efd9:1f96 with SMTP id w12-20020a056358618c00b00142efd91f96mr8492741rww.22.1695383934915; Fri, 22 Sep 2023 04:58:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695383934; cv=none; d=google.com; s=arc-20160816; b=JD6dCT1dY0VSoxD+thPzy/wOqLMsyrsCJuzoKGKiH+L9YfLiECjnFWaEAOdfOgInA3 nzmycT42vEzBvMfSkh8nG1KGSKe2cnRcG0wABUGAo4uboebImuE6q0RVflShvwJrklhk cwZ6h2Se2uSdD1dIoV4OiJUpuYBen1iDdkzRGlSeE1wXItwvwFimaeeJpjKTzzZpcRzG a73ln/YlNisQb20RgSoyyx9/HhLlXwfOrIEOALG+IUcdNEBnCT1LA2skNWFMLl2jj0Qc NutLegi86CKytfiBBAxWVvq5QkbZyeHAFUtGi8MeMkZnr8cKx0TwrMrNE1CoFU+9qpFD 9BHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=4+CrpOA3BbVW7YcDdIAr2SSQwmfCSbThy/86zuEQlAE=; fh=55cjFbGkAHeq3In4uKHUvE0ImsclnId7fcrkPAY/Kgk=; b=m3IHWWNVNCTJBs4vRazQpUDH+mtEDblwyg2sgEogALDX4hcYt9SY9ENkHbHQDBhq+t OnjfsVWwE0eLRA0ZKBqO+Ilr2/k5q/Sm8GqabgstVeDz25IuSBe5SnJeK3Gl3Pc6eeLY 9PZsx2yoU8egeP2yvhMHMXQxatllM7xCHC8wV4KIO8siRdTRHRWH9YiyFof2RAnZ+n4h lm/cg81Hq0N9nMYxccyvlgkZZY9mlCTZiieSiVgejH1COd/mtqHRZKNgUeOqLnPhQqwa wj+cvM1O9iKUdnHqNi3M5/zpxXcS1Iprp6p09YGhAZPrbE4RdyXFcC5fFQHq7Z/juPt6 yFAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@jms.id.au header.s=google header.b=cOPh1qAz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id f20-20020a637554000000b0057790a5a8e7si3760566pgn.190.2023.09.22.04.58.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 04:58:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@jms.id.au header.s=google header.b=cOPh1qAz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 2EB938387ED5; Thu, 21 Sep 2023 23:48:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229561AbjIVGsE (ORCPT + 99 others); Fri, 22 Sep 2023 02:48:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbjIVGsD (ORCPT ); Fri, 22 Sep 2023 02:48:03 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10FB4CE; Thu, 21 Sep 2023 23:47:57 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-99bdeae1d0aso216136166b.1; Thu, 21 Sep 2023 23:47:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jms.id.au; s=google; t=1695365275; x=1695970075; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=4+CrpOA3BbVW7YcDdIAr2SSQwmfCSbThy/86zuEQlAE=; b=cOPh1qAz7ooo2dQZbRpT7Dt4YUmCOmQdVAciUYbLrTKuE8beRijSV9WIRm4CoZwXxD qWhRiletBkjXTDR1y8a7ryQZsJtjr+4PBb85MRqkX/u+J70nocT/BRb11NrKbguJ1F7R 9cDTumDzxpWwdYB9zkPvVLiYLz97/GybvajBU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695365275; x=1695970075; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4+CrpOA3BbVW7YcDdIAr2SSQwmfCSbThy/86zuEQlAE=; b=WrfBCjgTyY+6/x6UqMPeFcKVzMvC5eS16vce81xNTGSU9oN6inJDXEFDZRKlzuEbHb d5VMDudbjs/fKWfnweOKRUjSBjDarm6Q8QwIAmgWuOY7KO3ELa7FQiztZE5VKvxVPTYc 8oBxsF69eP0aJWIo3/HTPTWd1ivi34tasqvv/+ruQ8jygbCh+w78FanyJjmqNx+LbvZb Z0AzcUfw6WldxpsnhU2vI/h19LnBe7z/K9Gkn6f8B5lifSoNx4RYlp885+9DqjEdUdo4 fadt1JJz4azmYm5mjiX95yo2N3gQgcOeJLQ7563D8H0yJ5mnSflV62FhhDjB2ANwcqu7 hOzQ== X-Gm-Message-State: AOJu0Yzc7cEfIBNUG0iKQRy4Ot5/6MbuzFwGmcgidAdET/6TX/Cxb34p 3lrKLZspKEoSNdIaydXNQIOeScwMdoPKANRbVkAeSoVBJYM= X-Received: by 2002:a17:907:75fc:b0:9ae:50e3:7e40 with SMTP id jz28-20020a17090775fc00b009ae50e37e40mr5278297ejc.52.1695365275252; Thu, 21 Sep 2023 23:47:55 -0700 (PDT) MIME-Version: 1.0 References: <20230810072155.3726352-1-zhangjian.3032@bytedance.com> In-Reply-To: <20230810072155.3726352-1-zhangjian.3032@bytedance.com> From: Joel Stanley Date: Fri, 22 Sep 2023 06:47:43 +0000 Message-ID: Subject: Re: [PATCH] i2c: aspeed: Fix i2c bus hang in slave read To: Jian Zhang , Tommy Huang Cc: brendan.higgins@linux.dev, benh@kernel.crashing.org, andrew@aj.id.au, zhangjian3032@gmail.com, yulei.sh@bytedance.com, xiexinnan@bytedance.com, "open list:ARM/ASPEED I2C DRIVER" , "moderated list:ARM/ASPEED I2C DRIVER" , "moderated list:ARM/ASPEED MACHINE SUPPORT" , "moderated list:ARM/ASPEED MACHINE SUPPORT" , open list Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,URIBL_CSS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 21 Sep 2023 23:48:12 -0700 (PDT) On Thu, 10 Aug 2023 at 07:22, Jian Zhang wrote: > > When the `CONFIG_I2C_SLAVE` option is enabled and the device operates > as a slave, a situation arises where the master sends a START signal > without the accompanying STOP signal. This action results in a > persistent I2C bus timeout. The core issue stems from the fact that > the i2c controller remains in a slave read state without a timeout > mechanism. As a consequence, the bus perpetually experiences timeouts. > > This proposed patch addresses this problem by introducing a status > check during i2c transmit timeouts. In the event that the controller > is in a slave read state, the i2c controller will be reset to restore > proper functionality and allow the I2C bus to resume normal operation. > > Signed-off-by: Jian Zhang Tommy has submitted a similar fix: https://lore.kernel.org/linux-i2c/20230906004910.4157305-1-tommy_huang@aspeedtech.com/ His change is very heavy handed; it reinitialises the bus including re-parsing the device tree (!). Should we have merged this fix instead? If not, are you able to confirm that his change fixes your issue? Cheers, Joel > --- > drivers/i2c/busses/i2c-aspeed.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c > index e76befe3f60f..1a95205fc946 100644 > --- a/drivers/i2c/busses/i2c-aspeed.c > +++ b/drivers/i2c/busses/i2c-aspeed.c > @@ -113,6 +113,7 @@ > ASPEED_I2CD_M_RX_CMD | \ > ASPEED_I2CD_M_TX_CMD | \ > ASPEED_I2CD_M_START_CMD) > +#define ASPEED_I2CD_SLAVE_CMDS_MASK GENMASK(31, 29) > > /* 0x18 : I2CD Slave Device Address Register */ > #define ASPEED_I2CD_DEV_ADDR_MASK GENMASK(6, 0) > @@ -706,6 +707,22 @@ static int aspeed_i2c_master_xfer(struct i2c_adapter *adap, > ASPEED_I2CD_BUS_BUSY_STS)) > aspeed_i2c_recover_bus(bus); > > +#if IS_ENABLED(CONFIG_I2C_SLAVE) > + /* > + * If master timed out and bus is in slave mode. > + * reset the slave mode. > + */ > + if (readl(bus->base + ASPEED_I2C_CMD_REG) & ASPEED_I2CD_SLAVE_CMDS_MASK) { > + spin_lock_irqsave(&bus->lock, flags); > + u32 func_ctrl_reg_val = readl(bus->base + ASPEED_I2C_FUN_CTRL_REG); > + > + writel(0, bus->base + ASPEED_I2C_FUN_CTRL_REG); > + writel(func_ctrl_reg_val, bus->base + ASPEED_I2C_FUN_CTRL_REG); > + bus->slave_state = ASPEED_I2C_SLAVE_INACTIVE; > + spin_unlock_irqrestore(&bus->lock, flags); > + } > +#endif > + > /* > * If timed out and the state is still pending, drop the pending > * master command. > -- > 2.30.2 >