Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4238445rdh; Tue, 28 Nov 2023 16:20:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzML4sh7ierRcFnsLrS2/RmiMSOdbROvTP024KFOB9De5B1nMjTq5LPzVBU1sHqwIbKwZU X-Received: by 2002:a05:6808:1188:b0:3b5:a58c:cca6 with SMTP id j8-20020a056808118800b003b5a58ccca6mr20442674oil.3.1701217214942; Tue, 28 Nov 2023 16:20:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701217214; cv=none; d=google.com; s=arc-20160816; b=OxUOuvlihlmoqSkCls1822dGYiN4gxJOv040Rrqcmt2MmNkdz04sGJK7FAhJs0d2vs dI418uM1IHUi6aqzZ5w5t3b57+2vxd7aUu0yNnOtAnntM3OUvQjL96nuiJ8Cec6VACmX AFcLCJMgU4Z+ZYrlHIx+EBDtgXQJ7BFWzkphn9ErIZTvGVjDNDRtif9XEB24N3+gnEKH 7dewDpiWuvpsHcbDwrYiEI8KtTL+dUGMf9B45kNbLTvActE5/AqsUoisG88HGbEhQqsA 2E4TRXtTwkH9Jz8AVXaepWqXAhgVoEMF3kMc224YTfaH9JJV4U+PA0D9aAWN2z/aauLR hwRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=dk/ur1RQW3iSmbO2wQE4io8VUkp6+K+uoymueMamZHg=; fh=yDkQzEl6IxZLQSJVtYl4ZVgHjrQZ2Js7dKd11NaUo5c=; b=GA4PxPp+4DR6b6KWt+1NJLWtP6mu2znWMCFLt5ewU4yGV3nNIX2TCq76WyeXr1uEEi 41xj7+pgFJhAiEh+leAy90SmkCDCElwNHycaflt9gm/AVqnDGfFUUmMheqRxjFIlvcTk pY/d92UnVm3VmxnL+MA5LDM7knFHyFra4K45PfUNR6oo9vftuAPS9HK60X8Ukum65HEE rQ2opQnQgC6yRVpnWJsy4lhRIWrCCKQPBWtstExQ10hjXbT/q4euh60AETLZfXei3pt3 dY5G1tOhTmTclsqkaMlalcfAVFwjulZhAdFzzI4ZXn6KjADZ1P6FPtStZa+Lj+9CWNNt Judw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeconstruct.com.au header.s=2022a header.b=GIAkYfOy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeconstruct.com.au Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id b8-20020a6541c8000000b005c201eb7e85si13100569pgq.541.2023.11.28.16.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 16:20:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@codeconstruct.com.au header.s=2022a header.b=GIAkYfOy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeconstruct.com.au Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 7FBFF81C57E9; Tue, 28 Nov 2023 16:20:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229922AbjK2ATQ (ORCPT + 99 others); Tue, 28 Nov 2023 19:19:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbjK2ATP (ORCPT ); Tue, 28 Nov 2023 19:19:15 -0500 Received: from codeconstruct.com.au (pi.codeconstruct.com.au [203.29.241.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E1F78E; Tue, 28 Nov 2023 16:19:20 -0800 (PST) Received: from [192.168.68.112] (ppp118-210-131-38.adl-adc-lon-bras33.tpg.internode.on.net [118.210.131.38]) by mail.codeconstruct.com.au (Postfix) with ESMTPSA id C8EB620173; Wed, 29 Nov 2023 08:19:09 +0800 (AWST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codeconstruct.com.au; s=2022a; t=1701217154; bh=dk/ur1RQW3iSmbO2wQE4io8VUkp6+K+uoymueMamZHg=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=GIAkYfOyibSsdEqnXCDSdp7D18aGaGAUgQIZUt1T7ELSgV6ttYVwpLxqwnWClUCvb V39xOaFy/s73LGvRAH3gSpAMiN2NVy5ivuP8FZEk3nRunQZUVagLBhTINw/2oW9Upr p1DhJ8skCfCFIJmAY+yeUFxDZwog8b+gvtu+DBOwsbuObxSFPy/6vng10+31GZGrV/ LP5KlDGcC88/0tBcYb7Xd2EoNW6VNSZc8xV4F0gs/UMbSiNriwAmX9pBDrCMSCa0id 3NAQPHgVxH8EQ+RqLsoqIJuYKpCNzXdZ0QijrjDRNABl6Hfy3TkqIOZ+12He4YsvD+ bqgDHgnoJZOgw== Message-ID: <4a9fe86f0349106adaa4e0c04c5839bab631f26c.camel@codeconstruct.com.au> Subject: Re: [PATCH v2 RESEND 1/2] i2c: aspeed: Fix unhandled Tx done with NAK From: Andrew Jeffery To: Quan Nguyen , Brendan Higgins , Benjamin Herrenschmidt , Joel Stanley , Andi Shyti , Wolfram Sang , Jae Hyun Yoo , Guenter Roeck , linux-i2c@vger.kernel.org, openbmc@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: Cosmo Chou , Open Source Submission , Phong Vo , "Thang Q . Nguyen" Date: Wed, 29 Nov 2023 10:49:08 +1030 In-Reply-To: <20231128075236.2724038-2-quan@os.amperecomputing.com> References: <20231128075236.2724038-1-quan@os.amperecomputing.com> <20231128075236.2724038-2-quan@os.amperecomputing.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Tue, 28 Nov 2023 16:20:04 -0800 (PST) On Tue, 2023-11-28 at 14:52 +0700, Quan Nguyen wrote: > Under normal conditions, after the last byte is sent by the Slave, the > TX_NAK interrupt is raised. However, it is also observed that > sometimes the Master issues the next transaction too quickly while the > Slave IRQ handler is not yet invoked and the TX_NAK interrupt for the > last byte of the previous READ_PROCESSED state has not been ack=E2=80=99e= d. > This TX_NAK interrupt is then raised together with SLAVE_MATCH interrupt > and RX_DONE interrupt of the next coming transaction from Master. The > Slave IRQ handler currently handles the SLAVE_MATCH and RX_DONE, but > ignores the TX_NAK, causing complaints such as > "aspeed-i2c-bus 1e78a040.i2c-bus: irq handled !=3D irq. Expected > 0x00000086, but was 0x00000084" >=20 > This commit adds code to handle this case by emitting a SLAVE_STOP event > for the TX_NAK before processing the RX_DONE for the coming transaction > from the Master. >=20 > Fixes: f9eb91350bb2 ("i2c: aspeed: added slave support for Aspeed I2C dri= ver") > Signed-off-by: Quan Nguyen > --- > v2: > + Split to separate series [Joel] > + Added the Fixes line [Joel] > + Revised commit message [Quan] >=20 > v1: > + First introduced in > https://lore.kernel.org/all/20210519074934.20712-1-quan@os.amperecomputin= g.com/ > --- > drivers/i2c/busses/i2c-aspeed.c | 5 +++++ > 1 file changed, 5 insertions(+) >=20 > diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-asp= eed.c > index 28e2a5fc4528..79476b46285b 100644 > --- a/drivers/i2c/busses/i2c-aspeed.c > +++ b/drivers/i2c/busses/i2c-aspeed.c > @@ -253,6 +253,11 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bu= s *bus, u32 irq_status) > =20 > /* Slave was requested, restart state machine. */ > if (irq_status & ASPEED_I2CD_INTR_SLAVE_MATCH) { > + if (irq_status & ASPEED_I2CD_INTR_TX_NAK && > + bus->slave_state =3D=3D ASPEED_I2C_SLAVE_READ_PROCESSED) { > + irq_handled |=3D ASPEED_I2CD_INTR_TX_NAK; > + i2c_slave_event(slave, I2C_SLAVE_STOP, &value); > + } So we're already (partially) processing this a bit later on line 287: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/dri= vers/i2c/busses/i2c-aspeed.c?h=3Dv6.7-rc3#n287 From the description of the problem in the commit message it sounds like the ordering of the interrupt processing is incorrect. Prior to this patch we have the following abstract ordering of interrupt processing: 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH 2. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED With this patch we have: 1. If ASPEED_I2CD_INTR_SLAVE_MATCH then process ASPEED_I2CD_INTR_TX_NAK whe= n in ASPEED_I2C_SLAVE_READ_PROCESSED 2. Process ASPEED_I2CD_INTR_SLAVE_MATCH 3. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED That feels a bit complex and redundant. What I think we can have is: 1. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH Moving back from the abstract to the concrete, implementing what I believe we need would look something like this patch: diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspee= d.c index 28e2a5fc4528..98dd0f35c9d3 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -251,6 +251,14 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus = *bus, u32 irq_status) =20 command =3D readl(bus->base + ASPEED_I2C_CMD_REG); =20 + /* Complete any active read */ + if (irq_status & ASPEED_I2CD_INTR_TX_NAK && + bus->slave_state =3D=3D ASPEED_I2C_SLAVE_READ_PROCESSED) { + irq_handled |=3D ASPEED_I2CD_INTR_TX_NAK; + i2c_slave_event(slave, I2C_SLAVE_STOP, &value); + bus->slave_state =3D ASPEED_I2C_SLAVE_STOP; + } + /* Slave was requested, restart state machine. */ if (irq_status & ASPEED_I2CD_INTR_SLAVE_MATCH) { irq_handled |=3D ASPEED_I2CD_INTR_SLAVE_MATCH; @@ -284,11 +292,6 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus = *bus, u32 irq_status) irq_handled |=3D ASPEED_I2CD_INTR_NORMAL_STOP; bus->slave_state =3D ASPEED_I2C_SLAVE_STOP; } - if (irq_status & ASPEED_I2CD_INTR_TX_NAK && - bus->slave_state =3D=3D ASPEED_I2C_SLAVE_READ_PROCESSED) { - irq_handled |=3D ASPEED_I2CD_INTR_TX_NAK; - bus->slave_state =3D ASPEED_I2C_SLAVE_STOP; - } =20 switch (bus->slave_state) { case ASPEED_I2C_SLAVE_READ_REQUESTED: Thoughts? I haven't tested it, it's just something to throw darts at. Andrew