Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2089859rdb; Mon, 20 Nov 2023 01:20:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFG2KVe0YiFjavXgiojorzajTtrsVdjGSnqSZ9TZr2LFIrgSGlPaVFmkp5jzFoFhJ/fiqyk X-Received: by 2002:a17:903:494:b0:1cc:4cb0:d273 with SMTP id jj20-20020a170903049400b001cc4cb0d273mr7290104plb.56.1700472004727; Mon, 20 Nov 2023 01:20:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700472004; cv=none; d=google.com; s=arc-20160816; b=M8D6pNvQffbc1B0NxfgXreCrWR65sikMcMVHo65zNOK8/SSauEN1AJJFgELMNxdWwE OtNu/3JjdKxQ+yj5Vwq2MQsdcIT9mCARvoBbqRZyA73wSMzbRTHmR7ckPzo7JI43Eqg3 TgCP09qR9xqHRk4WmxMQxK7jzeu2r048tZy1ZWTPXF0OvBYJ6P8m8LcKip/Fdzglc56h ttYnE78N+eTtY6Qcfekt/jVPK4S5DGPQTqQz+MzJL0MxksLE4HZFSmlaWhyv7nMTnUZS QnEaimC2G7fgbspBfUn074Lk0le+Xkq0wxUY1fakptcF8nSDfDweF2lFpXE5wYPyYPkc aSyw== 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=tdiBbtmZINpiK2wrkr8560HBNxLICLlfhPzVnTah2sg=; fh=4vxbU4vRBUrzSWOlsPIP/lFTi4aHDf/vhUbt8Xz5uys=; b=XbC0efR0hS3yjh9FK0tnmQeVpCSWDDNhADIoYmSU6VNefD3+w1nOrCVkFRu8o6z8FC fs8eetpLe+phrEt983na8jV2PObNRI5eynwCGTcPHsIQ+d5dBANoMnaBpvySBpPRDiFR BsYG7NhlnCWHREodXy86OGlYnhyqm++oE2jiZwusOTB59e2D8PrFiTvRMmHu/b+L5TWi 3ujusl11ebo3YEVYl6B4Pq+Gds7lQaXoPplPmIufN22VzfkpLWqIIbzqyZbxE8Ptx6PF 0XIptta7nSg5CF/2OBGtVp95UFgRigQhSdqy1jTCVuGAs4EYAboqWGLzyY/tck9U0nGS 7lGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="QAAs3+/b"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id p4-20020a170902eac400b001cc0cd0772dsi7510424pld.86.2023.11.20.01.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 01:20: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=@gmail.com header.s=20230601 header.b="QAAs3+/b"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B36B68068972; Mon, 20 Nov 2023 01:17:59 -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 S232495AbjKTJR6 (ORCPT + 99 others); Mon, 20 Nov 2023 04:17:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232426AbjKTJR4 (ORCPT ); Mon, 20 Nov 2023 04:17:56 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78FE0B8; Mon, 20 Nov 2023 01:17:53 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6c4eb5fda3cso4292609b3a.2; Mon, 20 Nov 2023 01:17:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700471873; x=1701076673; 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=tdiBbtmZINpiK2wrkr8560HBNxLICLlfhPzVnTah2sg=; b=QAAs3+/buGiV2OByeKXZ0V808JyCUsftJJxgaVw0ZkGww/RaoMdaNtzbJW3MxSFSFb bGutLP1WLP/5oAtIc7kFD3HqWswTHMX045VYO4HIqPoO50ir1Uq1eXBqf4V6XJwh9QmZ +MZWwcWWnD7P4VGa/z+82PcAPs32hQPECYXI/V8CJnGENjVjDcAVRC58vaRqq8CpooSn 36O5KuA4luU6aj8zFA/IwsyObHB+56TuEoxVPsGkUZc6jX1M2+EfKDnRV9t3FyJBsGyp nzPz/RhgpzDTvG+teo7TvOIeIG3u7NhSzDpGpvVYF7/uF824xasKkI+CtsWitbb/XFqN mHAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700471873; x=1701076673; 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=tdiBbtmZINpiK2wrkr8560HBNxLICLlfhPzVnTah2sg=; b=i8UKolgOIoDYUAiamlbcrLVsty2ykMJPwh+BkUUvqSz+uyB0w+LFvM5H+VRsw6vIRk 455v3z2Rzroy4ci8l+b6v4Sn1I2NF35z8jBP5x+3OkV0YgX4J9YqPFTkBREV2V4lt2f6 nwMLdPRmkGKh267+Md1eji/8O2ZJ3ovn9xcaP+hcfLkU0X685ltBE4BMIptMMRqoDZRu 69YmCvnw2LTdw19vb1Uu3ccId6wdUL0jOr20rshdNulT5n/uOiN6R00ihCvWc1VqOed3 GaYkNXGaLX5woBOWdjN7tO75hP5bvbl0EmikdEztbM0GT0VdeHQx4K7QTYPaUkMyRJt+ qESQ== X-Gm-Message-State: AOJu0YwLR09NWlYB9wttzqhD03Viku54H8cLvC0K5xf0YuCvjdpJeyQW u7BzlaOEPa0qVVyn0vuoXH8= X-Received: by 2002:a05:6a20:4429:b0:188:75c:e69a with SMTP id ce41-20020a056a20442900b00188075ce69amr10006442pzb.4.1700471872866; Mon, 20 Nov 2023 01:17:52 -0800 (PST) Received: from cosmo-ubuntu-2204.dhcpserver.bu9bmc.local (1-34-21-66.hinet-ip.hinet.net. [1.34.21.66]) by smtp.gmail.com with ESMTPSA id j12-20020a056a00130c00b0068fece22469sm5582116pfu.4.2023.11.20.01.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 01:17:52 -0800 (PST) From: Cosmo Chou To: brendan.higgins@linux.dev, benh@kernel.crashing.org, joel@jms.id.au, andi.shyti@kernel.org, andrew@codeconstruct.com.au, linux@roeck-us.net, wsa@kernel.org, jae.hyun.yoo@linux.intel.com Cc: 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, chou.cosmo@gmail.com, cosmo.chou@quantatw.com Subject: [PATCH] i2c: aspeed: Acknowledge Tx ack late when in SLAVE_READ_PROCESSED Date: Mon, 20 Nov 2023 17:17:46 +0800 Message-Id: <20231120091746.2866232-1-chou.cosmo@gmail.com> X-Mailer: git-send-email 2.34.1 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,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,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]); Mon, 20 Nov 2023 01:17:59 -0800 (PST) commit 2be6b47211e1 ("i2c: aspeed: Acknowledge most interrupts early in interrupt handler") moved most interrupt acknowledgments to the start of the interrupt handler to avoid race conditions. However, slave Tx ack status shouldn't be cleared before SLAVE_READ_PROCESSED is handled. Acknowledge Tx ack status after handling SLAVE_READ_PROCESSED to fix the problem that the next byte is not sent correctly. Fixes: 2be6b47211e1 ("i2c: aspeed: Acknowledge most interrupts early in interrupt handler") Signed-off-by: Cosmo Chou --- drivers/i2c/busses/i2c-aspeed.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index 28e2a5fc4528..c2d74e4b7e50 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -337,6 +337,12 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) break; } + /* Ack Tx ack */ + if (irq_handled & ASPEED_I2CD_INTR_TX_ACK) { + writel(ASPEED_I2CD_INTR_TX_ACK, bus->base + ASPEED_I2C_INTR_STS_REG); + readl(bus->base + ASPEED_I2C_INTR_STS_REG); + } + return irq_handled; } #endif /* CONFIG_I2C_SLAVE */ @@ -602,13 +608,18 @@ static u32 aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus, u32 irq_status) static irqreturn_t aspeed_i2c_bus_irq(int irq, void *dev_id) { struct aspeed_i2c_bus *bus = dev_id; - u32 irq_received, irq_remaining, irq_handled; + u32 irq_received, irq_remaining, irq_handled, irq_acked; spin_lock(&bus->lock); irq_received = readl(bus->base + ASPEED_I2C_INTR_STS_REG); /* Ack all interrupts except for Rx done */ - writel(irq_received & ~ASPEED_I2CD_INTR_RX_DONE, - bus->base + ASPEED_I2C_INTR_STS_REG); + irq_acked = irq_received & ~ASPEED_I2CD_INTR_RX_DONE; +#if IS_ENABLED(CONFIG_I2C_SLAVE) + /* shouldn't ack Slave Tx Ack before it's handled */ + if (bus->slave_state == ASPEED_I2C_SLAVE_READ_PROCESSED) + irq_acked &= ~ASPEED_I2CD_INTR_TX_ACK; +#endif + writel(irq_acked, bus->base + ASPEED_I2C_INTR_STS_REG); readl(bus->base + ASPEED_I2C_INTR_STS_REG); irq_received &= ASPEED_I2CD_INTR_RECV_MASK; irq_remaining = irq_received; -- 2.34.1