From patchwork Fri Oct 6 02:22:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jian Zhang X-Patchwork-Id: 1844206 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=google header.b=GJFODh5M; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S1sg56lFrz1yqF for ; Fri, 6 Oct 2023 13:23:45 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=google header.b=GJFODh5M; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4S1sg54flmz3cg1 for ; Fri, 6 Oct 2023 13:23:45 +1100 (AEDT) X-Original-To: linux-aspeed@lists.ozlabs.org Delivered-To: linux-aspeed@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=google header.b=GJFODh5M; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bytedance.com (client-ip=2607:f8b0:4864:20::635; helo=mail-pl1-x635.google.com; envelope-from=zhangjian.3032@bytedance.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4S1sdw5cyyz3c7Q for ; Fri, 6 Oct 2023 13:22:43 +1100 (AEDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1c0ecb9a075so12389885ad.2 for ; Thu, 05 Oct 2023 19:22:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1696558958; x=1697163758; darn=lists.ozlabs.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=GJFODh5MsB+tapW+AsMjpVb+8FvE/RY0NA7YFJmcjg4vOwCAirzA/WPfbxf0C2r0Vt AxuqnG3LkkiOssbtnYM3FhCTToeaQgGiJ019mXqfABVYF78WiMW/nXiwsrFw0cej2wu7 EL98CE/v8ABaIii1in63KI2qap71pl4AF3yFGxbKqM/pH8WhFxu3t8+/WYd3oDFc9EJ3 oW4SG6tYNGO7i/fUiVGepKOg9YLq5KGZKXd9ylbnMXlN2XqfuMK6JFuX7mtnyoprNajE SEABuUCU4+Fm8iQgmrWsCry1uankuf6YwfdSvPUWHMM+842pdJYN5C4QRj3f63VK5RUX b8Ig== 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=GtRpy56TAl1EF3JzUdh1kHgXd+Ne0SP7NY5VJf5RNQs2a/f9DXgtiXrbIA9TdiOp14 kJ1g86ZAlGxECwWEBXwTr7J3aV7WWJcF0VG1sWjsUXz/VavM+qK/FcaH0QrTt3fZIx4u EbHx6FUxtoeSOfuPeAYwfRsnIJnAQuFIkIOkN0FFCYoXFBEh6Ay+lYxZOlLV6rwJ3KIt zv3lbqf49YsNnjFQ19Zzb//z3JQqdfgDP6BW0+I20VqCDzoJMnWrQ41QIHLZBhsTDbgM JdRLJQ7iuoqcv5ww3jHQe4xuLhmg6rfMtTP4YEV3tFLQ719ZgRTNQjoZlO2JM7cpFyrx Hxkg== X-Gm-Message-State: AOJu0YxjteJd5kQ1WGwk7qfsL3cVp0wS3PVvQ9+KKn3lmWKd4cEOF9Y9 1tI0q0i+OECpsEcjgzqiO/gBSA== X-Google-Smtp-Source: AGHT+IG+mQuSZhsZ7s1GbN7oZkzhFLn2RCUCg1Is6VpUBCVfYtfZj/tayH7KU48aIsSbMRFm9GPikA== 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 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 X-BeenThere: linux-aspeed@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux ASPEED SoC development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andi Shyti , "moderated list:ARM/ASPEED MACHINE SUPPORT" , "moderated list:ARM/ASPEED I2C DRIVER" , open list , Wolfram Sang , "open list:ARM/ASPEED I2C DRIVER" , zhangjian3032@gmail.com, Andrew Jeffery , "moderated list:ARM/ASPEED MACHINE SUPPORT" , xiexinnan@bytedance.com Errors-To: linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linux-aspeed" 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;