Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp109550rdb; Thu, 5 Oct 2023 19:23:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGo+xmUXlzfor/wv0FVW2Hy0Z8/Gy7wdoew6iP3xShD6tyh/0lp06PyuAo9YgIxbJ4tVDG/ X-Received: by 2002:a05:6808:4ce:b0:3af:794c:df98 with SMTP id a14-20020a05680804ce00b003af794cdf98mr6497605oie.49.1696559001023; Thu, 05 Oct 2023 19:23:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696559000; cv=none; d=google.com; s=arc-20160816; b=zRz+15afF5kAmZphuVFyp6bVqu64YZU8VrTuyJcX7pkZ0Jp7nKulC2NV//mFzN8WWy Y1uILOYmLMWQffttMu5QKXpf8aw7iBMCsAWIgE2SxHMbBn2jHbtwjTFGr62fO6oLVE2B 1qEW5OkRH+m6+xpys9un72eAY6qTRhLcNJWgRAxMU4hXxiTvQ+d4sgrysbtZuyRUm9mN ZZFLxwWKPoaszbF40QMJOGsxwyKqU3naoyrzrWo2dk1cdmjnUMY+RzTeKk3qm309tvFH 7i7b7foPS2GmPSwlOY3MgYG1Rrl09cnctfnXOdFzKI+ab5DVirtCU/9o8ICcS16JbESE tTrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=MgD2XlWyO1IkxKrZZ4NotDzi7FafWvmObFFGZh4fKtk=; fh=VD5KyU2G6WjkeAP7S66f8b5Q3gHkRzoDwD9IKqf2FDU=; b=Skcrv5Ime+lBsbcGRMA2AoDUA24siLTJahef2wF599Wezs23cx/3lftiiLfriQLZwP zagvqk5i+583QyvZFwCtkZptKJdrytkca9D8NADjXyAsZOTolIk2zSKUCFhYDJvPcqgS bq5jrTkof9X+EDalPFb0EUbkaWZVwCqYyliXgAWuCI1+22ajonxceA+NJ/Hjrz4TPli4 jkAkGeVtidi0R1ATtJ3JPI+M4+936PzQz4j1keweL2Eyy6EU5MJDvlkZQp3G36LxICLn kfwzGMfF9nRkBwvdIoBnI9T83l7OZbsX7lCw4AibYEQVbrCkfgcTQT7XSswkCoajkagj hXJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Im7qPefs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id k198-20020a636fcf000000b005855424fc2dsi2623633pgc.611.2023.10.05.19.23.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 19:23:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Im7qPefs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id E34468087CB5; Thu, 5 Oct 2023 19:23:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbjJFCXD (ORCPT + 99 others); Thu, 5 Oct 2023 22:23:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229774AbjJFCXC (ORCPT ); Thu, 5 Oct 2023 22:23:02 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18E50106 for ; Thu, 5 Oct 2023 19:22:39 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c87e55a6baso12418495ad.3 for ; Thu, 05 Oct 2023 19:22:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1696558958; x=1697163758; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=MgD2XlWyO1IkxKrZZ4NotDzi7FafWvmObFFGZh4fKtk=; b=Im7qPefsjDS9nbLox8rqJoVIvjqksZW2nFDzD7g83S4eQToetBFtf7KowlaD+pp27H 6kZvdBYd/9vvoMkMs2kaTp8k6gcKzeblf+HoT+n82oxQ+F5l8vPLv06AMKG/MXietmI6 lJEA6n7n3YxV1sr1FM1Pe5nljZhDep/nqDao31U9bR+93nyFlB8pQH4EkNeU3OxdmR/+ qtnLQ2A2G5OLcKxmVZiJQE4I7KPloDN7vae6K4IndRPoEBzolxawGmVLkmFYA3uK+uLh BT//2uZyX9/un0E40hNwzW2FZXvks3pPG8/e1aV1ynC9eGo6+KdJAIO3U6RdUttv78Gu G09w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696558958; x=1697163758; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MgD2XlWyO1IkxKrZZ4NotDzi7FafWvmObFFGZh4fKtk=; b=AhSBBfWeOreXzNfP/VyvGZB6Mc0gkTuRnwq9xBm7+ty1bbt9y0U3TIwoK+r1P+ECKt +F5cYDMjtSsl+MPAJbhAskGiw46YyvZc/s/EpPdjTqfVPiuQx64b/Wn+Iyka+JrPQVAL xG3IdH/gSmA3IVdZzFTs07nubVsXTwBV2KVqLiY2nVpk2UM/i/O1pMwJLUAqcbS5G2nB x2N4WgBQ6AGtzIgJ3aEUr4c30xoZGu8xzAI4hsd7CPsU4c5LlTynT0LIRog7NiGoWhrO AuwuIKgxHJcSq1udn/GDf1WUznK7wLqYLlpiGguVwW156rftRsN4TenP3q2iq18gNMLa XSyw== X-Gm-Message-State: AOJu0Yx1J9o7ZTIGe1fiEBg8diVKgBJDDkWCs96KL4s2YAs2KBJpwfBH GqpGQ6JyqPuQSAuuNcRzgyVFRA== X-Received: by 2002:a17:902:e542:b0:1c3:d07f:39f7 with SMTP id n2-20020a170902e54200b001c3d07f39f7mr7233603plf.62.1696558958573; Thu, 05 Oct 2023 19:22:38 -0700 (PDT) Received: from localhost ([49.7.199.22]) by smtp.gmail.com with ESMTPSA id 10-20020a170902c20a00b001ae0152d280sm2487893pll.193.2023.10.05.19.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 19:22:38 -0700 (PDT) From: Jian Zhang To: brendan.higgins@linux.dev, benh@kernel.crashing.org, joel@jms.id.au, andrew@aj.id.au Cc: zhangjian3032@gmail.com, yulei.sh@bytedance.com, xiexinnan@bytedance.com, Andi Shyti , Andrew Jeffery , Tommy Huang , Wolfram Sang , linux-i2c@vger.kernel.org (open list:ARM/ASPEED I2C DRIVER), openbmc@lists.ozlabs.org (moderated list:ARM/ASPEED I2C DRIVER), linux-arm-kernel@lists.infradead.org (moderated list:ARM/ASPEED MACHINE SUPPORT), linux-aspeed@lists.ozlabs.org (moderated list:ARM/ASPEED MACHINE SUPPORT), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3] i2c: aspeed: Fix i2c bus hang in slave read Date: Fri, 6 Oct 2023 10:22:33 +0800 Message-Id: <20231006022233.3963590-1-zhangjian.3032@bytedance.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Thu, 05 Oct 2023 19:23:19 -0700 (PDT) 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. In this case, the i2c bus will be reset, but the slave_state reset is missing. Fixes: fee465150b45 ("i2c: aspeed: Reset the i2c controller when timeout occurs") Signed-off-by: Jian Zhang Acked-by: Andi Shyti Tested-by: Andrew Jeffery Reviewed-by: Andrew Jeffery --- Changelog: v3 - move to __aspeed_i2c_reg_slave. v2 - remove the i2c slave reset and only move the `bus->slave_state = ASPEED_I2C_SLAVE_INACTIVE` to the aspeed_i2c_init. --- drivers/i2c/busses/i2c-aspeed.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index 5a416b39b818..28e2a5fc4528 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -749,6 +749,8 @@ static void __aspeed_i2c_reg_slave(struct aspeed_i2c_bus *bus, u16 slave_addr) func_ctrl_reg_val = readl(bus->base + ASPEED_I2C_FUN_CTRL_REG); func_ctrl_reg_val |= ASPEED_I2CD_SLAVE_EN; writel(func_ctrl_reg_val, bus->base + ASPEED_I2C_FUN_CTRL_REG); + + bus->slave_state = ASPEED_I2C_SLAVE_INACTIVE; } static int aspeed_i2c_reg_slave(struct i2c_client *client) @@ -765,7 +767,6 @@ static int aspeed_i2c_reg_slave(struct i2c_client *client) __aspeed_i2c_reg_slave(bus, client->addr); bus->slave = client; - bus->slave_state = ASPEED_I2C_SLAVE_INACTIVE; spin_unlock_irqrestore(&bus->lock, flags); return 0; -- 2.30.2