Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp757260rwl; Thu, 10 Aug 2023 00:42:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1ZMmTWdKj4MYPtlzogCHzE6PL6rF1kycVdLaVj/UD302dgI9HCBC2Tl4V7DVFKimdUl7X X-Received: by 2002:a05:6358:93a3:b0:134:cbff:c5a4 with SMTP id h35-20020a05635893a300b00134cbffc5a4mr2160795rwb.18.1691653346741; Thu, 10 Aug 2023 00:42:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691653346; cv=none; d=google.com; s=arc-20160816; b=GvA78FPVlT5JVyOA96AAoxIeXYGi6qTNA7e9WEhXq84NqrDm+0PJXh+nlUzkGpmyi6 TJWg7LUvQrtfffdmcC8Olwae53F0s4WcHvjB8XO5QT3QiAX0z9xzjSTIDMOFT4iWFJ63 TxHkMo9JJsc1kO1g8r42vgaAuhCJLq6mnPn7VK7owmjF2McQo7KFLhVOMu+CePlqlGmq nyI3Ga+p8Zp6v7rbfLnMOuHDRQhAqJfcZ0POjUiQWULYHKCuHOl6SikS0/Y/W41hJuEU nOW9qYgtORnC8vpe3rpT5pBUwzTjiVgzUMZoXHWFBSXgTIdGvI6fSkkUw8/3Nsn7QVeI 5ksg== 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=oCsFa++ogn7H/UBzN64O3INdySKF0/YyEIYVfwtbNi4=; fh=7qUewteqceIlMJ1m+BWJkMs9BeHowIc/ijT7LPFRPLE=; b=xXmtsuZTc2HeILIcbHAkhjhALxVzYNW8xW5DY+wVSgQL0+RdLWQs/hjzjk9zcOsjPl GBgfC+AYNV6ePMgz95q0vEPUpqVpsXXYV8Efs3bdpZWARy157llkzIAY4cn41UZViv2y OgWH6Vk8cSR5L2JfGhWfoPH79QaSxYpPeiZvFQTEY/C+9iO6C1es5MX3ZDC6sPI0Rb2M 1UshPeZum1vSFjAPCib6qNC0UWPFJTAl0nssaxTCLhoOKKSSvBu2LxGMkfZrTWZT0t+1 heuMZvY+lpyBGp2pR5PqayqFfB3hAMazy3LizZqqo84Xy0NDjw0ihDC7GILaF4fmOiSt k8xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=cCKBkQQg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t184-20020a6381c1000000b005640a32d25esi1032232pgd.517.2023.08.10.00.42.13; Thu, 10 Aug 2023 00:42:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=cCKBkQQg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233826AbjHJHW3 (ORCPT + 99 others); Thu, 10 Aug 2023 03:22:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232462AbjHJHW2 (ORCPT ); Thu, 10 Aug 2023 03:22:28 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE8491BD9 for ; Thu, 10 Aug 2023 00:22:02 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-686fc0d3c92so431081b3a.0 for ; Thu, 10 Aug 2023 00:22:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1691652122; x=1692256922; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=oCsFa++ogn7H/UBzN64O3INdySKF0/YyEIYVfwtbNi4=; b=cCKBkQQg3S66/frhBsmAlmRxovXilvClD1MVf+P/F/DowmmK8Ocu/GlQ9T4uPUxv4U u12XtTQ0rXPiTyvqbb55WTf+xmwq7qnFLIuoyT5J7YPA1SzpiRY+LCiKiTxbL73hTN3X pXOnqtky7JiPc0mU49MbYEH9OWr5oMrktoGi1Y6Fm7MQVTtLRkyRpvZB5AUYp7ILOAuu WbmmbVpIZAiQkjMdzY89weCPT3rE+mKG3NuBf2Hizx5BMKmbrYAtF6OhvTbg98urRmp4 9JwvnEHzcwNDk0FeudEeL8ALFcAtKHd7IFL6MdTqicfcckmSlIdYbKK1ItGJB8uHzoLb TEvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691652122; x=1692256922; 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=oCsFa++ogn7H/UBzN64O3INdySKF0/YyEIYVfwtbNi4=; b=B+I+IEW6dVzgNWsk0wmIaQb/42bUX7pFYf7jxC7rem/z/VO8Nel55mLUqHH9wU8C2+ oAEU2za9qT11z69c0OBsYqMwa6WJ5ZQHtcijDT6AC2M/vhEfYldX5S/IVmr7NLXlfSBc 9DgqeGIGDkGNEqnVtz4Gl+HLJMeSb/XhKtWhR+v449pqIqRo4rBR3dca0yOwEdvSgQ+a jFmdQtRdcd1mZ7avLQIAtYuLc7a9LRPVqPed8c182x9gtbaDJ7co8hqMab0cKHZu7Qqw ByT9Jcg38UermObmTc46wxhqzuHC0aqDxDrAI0tmaCahCEayV2rVSaepY7dgvw3wDwFd KMzw== X-Gm-Message-State: AOJu0Yyg6hF28/7TwDE5K/N9z68ndBDHOr/7hNbSSK4RvaRlX2RLqpJU dmrh3wY0OBcZ1F9ecHE0Igd9gw== X-Received: by 2002:a05:6a20:325a:b0:134:a8a1:3bf with SMTP id hm26-20020a056a20325a00b00134a8a103bfmr1309418pzc.30.1691652122340; Thu, 10 Aug 2023 00:22:02 -0700 (PDT) Received: from localhost ([49.7.199.210]) by smtp.gmail.com with ESMTPSA id c6-20020a170902c1c600b001b8a3a0c928sm880830plc.181.2023.08.10.00.22.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 00:22:02 -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, 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] i2c: aspeed: Fix i2c bus hang in slave read Date: Thu, 10 Aug 2023 15:21:55 +0800 Message-Id: <20230810072155.3726352-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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