Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4878682rdh; Wed, 29 Nov 2023 13:26:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSAusN1rUH3rk9ksJ9TXnt5mksF9veXwCKSg4T5O37SSBYxYjAwqpyGElOq2UJUhKYIWq2 X-Received: by 2002:a17:902:f68e:b0:1cf:8364:ec24 with SMTP id l14-20020a170902f68e00b001cf8364ec24mr23630716plg.4.1701293164900; Wed, 29 Nov 2023 13:26:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701293164; cv=none; d=google.com; s=arc-20160816; b=NEaxpuX/eBgyxOkCiL+oqs6m/AUzpNkICQh7d2ghI/rWSq9t5Le136isJylcpgIZhS o2w1Y83wDtEQuHgfYhI0NnVpzPQYK0QI+s2FFAaz7f8cTJ77DfLTwLXYX8MPbtbWoIIj vRq8Ybf8ntE2rt4oHvESjb4EIfJua8bgXp1NYbAvOZqCwJ+S92bP+ctx/4zyN3AQTRxT xmVejEkxbpY3BMC4ZKENGTj5upJXd46XuChjg2IdVboWrItyoRbBgULKPZEQGofIKNgq LZ4KsfBe9UE8ybYhTNZPUFB2Bd/qEI2EycA67MRe31+FS8UbgZnCSuyhNktimPMUc7KO Rdag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=6CavUx0VsVHp3fQats7dvpKv5xeya+rjJ6MRgJcQlK4=; fh=ABkbQnYy7mj1U0IlDg0dsudt5Oa+PeG9h2yzCz5KuJE=; b=ahqwMutGpIbpMNIZ/AxtGZYvd3ZaAB9tqyjFZX2ps/MRbWJVBhJK3ktK06RpJYQnyo fpg8W4pf027JjO1LmK2L7Xd95HEHCTxRwUBLgtZV4plHe1NFEZSEt2ILO++gc54nb1dm HN2Bh7BREymY2G8QLd1CL3kvmIrv8zv3Xun5aCc2W1cX8NE4kiRMRuK4b3KdZRMBI5Zx 5VigTzFcy8SLV6LmVUQ06L4nmsbsYGvMoQTFA/LBwDcKX5wMn/WxcOEsFvfXSZ3GZphV U6oOnY4iRL1+/4GQ8g+vuSC2j10HHq0KaIM+APWZ3HShtVK1y5tlZmtHQR+YvLuzfjvn 7neQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mshk4Wxw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id c12-20020a170902c1cc00b001cfb7ef2badsi9595004plc.155.2023.11.29.13.26.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 13:26:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mshk4Wxw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 23721802DAAD; Wed, 29 Nov 2023 13:26:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233878AbjK2VZx (ORCPT + 99 others); Wed, 29 Nov 2023 16:25:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229658AbjK2VZw (ORCPT ); Wed, 29 Nov 2023 16:25:52 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25F2FD7D for ; Wed, 29 Nov 2023 13:25:58 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2B7FC433C9; Wed, 29 Nov 2023 21:25:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701293157; bh=ROdIinNcMbpv2zZ2WaGDF27TbBat2/HH4ZUHKaYavi8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mshk4Wxw0C1PuUEdL/SVD29XR2CpunRcEl044qrZlvwrelLuUEoLjXeN6ti/tyo/9 Ky+KTExJRiau+jLK89jsO6WBTmbXzwQgbSRj6S1CK6+QYZ0EeE73VQlaSrAt3bCo1f ORXWcVaZDQYQiHKjd8iTCMrVsS5Ig4nwpLiEoQSMDTq+f1aiN19H+/Ecq/QU9pQC9q zuroMJSqsObhFl5qqBNsD1tS/1aA6Rykyf+huvAqqgJLoO4eyNfK4MDrq3BqfzO7cO wrY/9U9Te1p8F/MfxFpKSpqzRyQ4ND7qSWKb4t3arWQk7kNbnXOQ2guOdBMm5HSo9f XvyTCYszIFwog== Date: Wed, 29 Nov 2023 22:25:52 +0100 From: Andi Shyti To: Quan Nguyen Cc: Brendan Higgins , Benjamin Herrenschmidt , Joel Stanley , Andrew Jeffery , 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, Cosmo Chou , Open Source Submission , Phong Vo , "Thang Q . Nguyen" Subject: Re: [PATCH v2 RESEND 1/2] i2c: aspeed: Fix unhandled Tx done with NAK Message-ID: <20231129212552.3uy7oqm5fz5h2m6b@zenone.zhora.eu> References: <20231128075236.2724038-1-quan@os.amperecomputing.com> <20231128075236.2724038-2-quan@os.amperecomputing.com> <20231129003542.jfhhotebweb3uwyb@zenone.zhora.eu> <3f37c359-1c71-421f-b7d9-054696735adc@os.amperecomputing.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3f37c359-1c71-421f-b7d9-054696735adc@os.amperecomputing.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 29 Nov 2023 13:26:03 -0800 (PST) Hi Quan, > On 29/11/2023 07:35, Andi Shyti wrote: > > Hi Quan, > > > > On Tue, Nov 28, 2023 at 02:52:35PM +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’ed. > > > 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 != irq. Expected > > > 0x00000086, but was 0x00000084" > > > > > > 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. > > > > > > Fixes: f9eb91350bb2 ("i2c: aspeed: added slave support for Aspeed I2C driver") > > > Signed-off-by: Quan Nguyen > > > --- > > > v2: > > > + Split to separate series [Joel] > > > + Added the Fixes line [Joel] > > > + Revised commit message [Quan] > > > > > > v1: > > > + First introduced in > > > https://lore.kernel.org/all/20210519074934.20712-1-quan@os.amperecomputing.com/ > > > --- > > > drivers/i2c/busses/i2c-aspeed.c | 5 +++++ > > > 1 file changed, 5 insertions(+) > > > > > > diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.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_bus *bus, u32 irq_status) > > > /* 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 == ASPEED_I2C_SLAVE_READ_PROCESSED) { > > > + irq_handled |= ASPEED_I2CD_INTR_TX_NAK; > > > + i2c_slave_event(slave, I2C_SLAVE_STOP, &value); > > > + } > > > > this is a duplicate of a later "if (...)" satement. What is the > > need for having them both? > > > Thanks Andi for the review. > > I assumed the if statement you mentioned is here in [1]. If so, then that is > not duplicate. > > [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/i2c/busses/i2c-aspeed.c?h=v6.7-rc3#n287 > > > The if statement is to process the case when Slave sending data to Master > but being NAK, the I2C_SLAVE_STOP event will emit later in switch-case > statement. But it is only for the case INTR_TX_NAK without INTR_SLAVE_MATCH. > > The new code is for the case of INTR_TX_NAK with INTR_SLAVE_MATCH. What it > does is to detect if there is a mix of INTR_TX_NAK of previous i2c > transaction and the start of new i2c transaction, indicate by > INTR_SLAVE_MATCH which is only raised when Slave found its address matched > on the first byte it received. If so, the new code will try to emit the > I2C_SLAVE_STOP first to complete the previous transaction and process the > rest as a new request. > > So if this was the case (with INTR_SLAVE_MATCH), the INTR_RX_DONE should > always raise with INTR_SLAVE_MATCH because Slave did receive the data which > matched with its Slave address. And this will be translated into either > I2C_SLAVE_[READ|WRITE]_REQUESTED and that make the if statement you > mentioned [1] evaluate to false and skip. > > So, in short, the new code is trying to handle the case of INTR_TX_NAK with > INTR_SLAVE_MATCH first before let the rest process as normal. yes, I saw that, but wasn't it easier to do something like this: if (irq_status & ASPEED_I2CD_INTR_TX_NAK && bus->slave_state == ASPEED_I2C_SLAVE_READ_PROCESSED) { irq_handled |= ASPEED_I2CD_INTR_TX_NAK; bus->slave_state = ASPEED_I2C_SLAVE_STOP; if (irq_status & ASPEED_I2CD_INTR_SLAVE_MATCH) i2c_slave_event(slave, I2C_SLAVE_STOP, &value); } But I see that Andrew has done some similar comment, also for patch 2. You can answer both in the same mail, not to duplicate the answer :-) We can wait for him to reply. Andi