From patchwork Fri Dec 8 03:31:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quan Nguyen X-Patchwork-Id: 1873634 X-Patchwork-Delegate: andi.shyti@kernel.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=os.amperecomputing.com header.i=@os.amperecomputing.com header.a=rsa-sha256 header.s=selector2 header.b=g8fz7HTK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-i2c+bounces-678-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SmcCN131Gz23mf for ; Fri, 8 Dec 2023 14:32:32 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 2ECD01F212C1 for ; Fri, 8 Dec 2023 03:32:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3BF734A29; Fri, 8 Dec 2023 03:32:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=os.amperecomputing.com header.i=@os.amperecomputing.com header.b="g8fz7HTK" X-Original-To: linux-i2c@vger.kernel.org Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2134.outbound.protection.outlook.com [40.107.100.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EA451727; Thu, 7 Dec 2023 19:32:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lbt3JChCNqavGZdEg0/bbTeXhCFjQmg4IygDkZdLCKwI78BzCwaKw523mc9bf3xVodAkWxi2r0+sePZC0VFOObefUezraMEg6WBIYwkWSSf41V7As9ITBW2HLZX9bsoZFzITbtPXk+vx79S01SFjIFQC2hlBJqC0rvDBEfDK91YCyAGSftbRFm/pUOoEWTEJkfyrmhGFsA/Uv8UmT9pcsqG/CAMYb2JQJ7v5Is9auTk6c1fSD3aBcXfx1eSW8gUJPLBZqZgaW72G3GUqV9fbLzRw8QomWv0M1J+nzJDhjvPk/UTz39XkoCg4ceZNUai/2cZzI9XCqiOtK7sqmWq90A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YlMP3M3fABHaRpRNGuvf9NO+rSFvhyPtOwBNy1e3lk4=; b=UrK9W3+7BS0mn3Me70j67aW7uL5bk901c6npHQuUevoy3I3xGjYLaY1YwPmWhseh8zwi2KrjHez5p14gz6MsFTZxA/14TvszrqSJ5mZXb9X+2w/fSOldrgBkLXmkaxi/eRrQhCdFqoPzxK2i6oJMMQ98ExAhHxd/2ejxUu8FKaMLjQe4c8dGMm2BR1nygFn4E0Ery9B5EHgpU/jIOpUdjHbkV7dzTyoMneYA6eNy9Y7M82V8VczZlJOgy1eJhbvhB8a1RncMpFO0i8ba5DIAadN+D9OTljR6xM3gNySUhOXGHtn4Ok0O8IqpBN0AYX+w+OucOa+nOUhQQ4PPykXCLQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YlMP3M3fABHaRpRNGuvf9NO+rSFvhyPtOwBNy1e3lk4=; b=g8fz7HTKarJoVFqPCz6+S6iYs6VwOXHQ1vI0wJ37tDXCdto187vLgthfHpuWfFZo3CnZpy9QpnPHDJbUh1j2+Db9VVs+Agordubk//kq0soZrkIUk9nGWQwpIPmb1ARRj2Vb5+t4IJHH1BAEZG8sVbGHDg0XNQPb9w6QX6Vmtpg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from SN4PR01MB7455.prod.exchangelabs.com (2603:10b6:806:202::11) by DS7PR01MB7784.prod.exchangelabs.com (2603:10b6:8:7f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.27; Fri, 8 Dec 2023 03:32:15 +0000 Received: from SN4PR01MB7455.prod.exchangelabs.com ([fe80::5682:1d84:171a:1d68]) by SN4PR01MB7455.prod.exchangelabs.com ([fe80::5682:1d84:171a:1d68%3]) with mapi id 15.20.7068.028; Fri, 8 Dec 2023 03:32:15 +0000 From: Quan Nguyen To: Brendan Higgins , Benjamin Herrenschmidt , Joel Stanley , Andi Shyti , 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 Cc: Cosmo Chou , Open Source Submission , Phong Vo , "Thang Q . Nguyen" , Quan Nguyen Subject: [PATCH v3 2/2] i2c: aspeed: Acknowledge Tx done with and without ACK irq late Date: Fri, 8 Dec 2023 10:31:42 +0700 Message-Id: <20231208033142.1673232-3-quan@os.amperecomputing.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20231208033142.1673232-1-quan@os.amperecomputing.com> References: <20231208033142.1673232-1-quan@os.amperecomputing.com> X-ClientProxiedBy: SGAP274CA0014.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b6::26) To SN4PR01MB7455.prod.exchangelabs.com (2603:10b6:806:202::11) Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN4PR01MB7455:EE_|DS7PR01MB7784:EE_ X-MS-Office365-Filtering-Correlation-Id: a89b4120-66dc-4f5f-b8e2-08dbf79e45b0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7VwckWnszuPjfJ1FGKoQ5sg+NEvgZhZeL5J2L3U39EwA8VtUI211Idd9wPpZyWsjM5zRCvXzVhXl9kOm8cNkl2AVBSq/9yqM2PRcfaJ8RcVFLLXbHPbN8QrSsPASdXNbFqgO2rbB9wStkZnkw56gEPJgIFwgIP5hquhiqM97olRp2x4Hc4ccnNM1JuqCPz/dowxj47sprQlJON/4R9fJk7QkQgakwEzJlmTZsAEXeIdXJd1hLMN9J6g0q0freZwl1dO8CVlshbeLQvVw0dfWJH4r47OFGeL1c5QhO0tZZ0gIQCYhu7QQZ37WqYd1ZA4ohLK1HYiNP6dNJ/UDSOia53j0FBpOYjy0FydPkDAm+BxyNChjqgoLH6pLbtlKEbAZilqvtiEjI9meocp2htbQVQjc9NwdrU/kEPf327Uwg17lLrAnRZjekDtjTzbDQpBuprJwLeUI8ccWb6FteoIfX3o6ZR0Fu3GgxxpKe8aTU3Nyp1IsW+vUPyNp6CUnJsZWaHCPaichJFvXGHWSJwbxP0ixsLP/G5kNg5tV2WZ+WSlEoyuc1xyKqORTrpcA+urtX+tJjOCK47gkdSOqHqWambgYScDPAAgTNloQYk6Dv/1dG3GzRKJ3AZ+NtcxCoYn1 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN4PR01MB7455.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(376002)(366004)(39850400004)(136003)(396003)(230922051799003)(1800799012)(64100799003)(451199024)(186009)(38100700002)(41300700001)(7416002)(5660300002)(2906002)(8676002)(38350700005)(316002)(4326008)(921008)(1076003)(110136005)(478600001)(6512007)(6666004)(6506007)(52116002)(2616005)(66476007)(86362001)(66556008)(54906003)(26005)(66946007)(107886003)(8936002)(83380400001)(966005)(6486002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yJP4exEKch3CkzPFSPfMms+t1cRdqzQsozSyuSBYjKGMlyiwOKdr7N9HOE9OBqHIZXrqGyEy6UGsvPE11Sb8O8WkZURJzpNU0HDID6ll7R3n0gFbL+RkjpN6FR58fapIFQu0oMrmxUwG5Hgh+V83x2uILmsNTRofiCPrQoCfs/zuyZY2v/pP6rmLaqFrKj99LLVP95NbmcgXceT6DD34uMheNLGPjNVq6GyhpE/3QnyriZz0zX9OVqBURkmilSPZ1tXb7AzYUncpJzujd4AYcUso27Bj5l9Gc87JGYSGcSa5SdO+7N9hoUCLFjSsOl/nrlb75tUHe7wuqTsdG0+6m30QVQeliJcYb2XH955Qz/xjRbr097IVAkH0guelYKCJMvYa82jJAsiFqVgBG4E0ifzkyrdqHQ+izzjN9iNutMydRk7HMApBa9XHCzY6wDiEbn+SM84xMB18fxyHY0PElBtiNdlAu8DmPB9e3vSp7ipI/ysJZvmfSI3MB1MpBlMd+mE+5gnG1TzSAx5BaHO/A9db2C2pHi1biIOXDs8/f5ZF3xHA7EgG2IXy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ginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: a89b4120-66dc-4f5f-b8e2-08dbf79e45b0 X-MS-Exchange-CrossTenant-AuthSource: SN4PR01MB7455.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2023 03:32:15.3008 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: uz7HCNU0kVg1jpTNGtYD8qORLzFZwnOWOWoo/LIoYqY6xFPqeQBwVLQS0ch0Ht73ZgvIJgNsolVPnv5SeTiW8m27jG+A0h7DAFeHQfLcH3o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR01MB7784 Commit 2be6b47211e1 ("i2c: aspeed: Acknowledge most interrupts early in interrupt handler") acknowledges most interrupts early before the slave irq handler is executed, except for the "Receive Done Interrupt status" which is acknowledged late in the interrupt. However, it has been observed that the early acknowledgment of "Transmit Done Interrupt Status" (with ACK or NACK) often causes the interrupt to be raised in READ REQUEST state, that shows the "Unexpected ACK on read request." complaint messages. Assuming that the "Transmit Done" interrupt should only be acknowledged once it is truly processed, this commit fixes that issue by acknowledging interrupts for both ACK and NACK cases late in the interrupt handler. Fixes: 2be6b47211e1 ("i2c: aspeed: Acknowledge most interrupts early in interrupt handler") Signed-off-by: Quan Nguyen Reviewed-by: Andrew Jeffery Reviewed-by: Andi Shyti --- v3: + Fix the unconditinal write when ack the irqs [Andrew] + Refactor the code to enhance code readability [Quan] + Fix grammar in commit message [Quan] v2: + Split to separate series [Joel] + Added the Fixes line [Joel] + Fixed multiline comment [Joel] + Refactor irq clearing code [Joel, Guenter] + Revised commit message [Joel] + Revised commit message [Quan] + About a note to remind why the readl() should immediately follow the writel() to fix the race condition when clearing irq status from commit c926c87b8e36 ("i2c: aspeed: Avoid i2c interrupt status clear race condition"), I think it looks straight forward in this patch and decided not to add that note. [Joel] v1: + First introduced in https://lore.kernel.org/all/20210519074934.20712-1-quan@os.amperecomputing.com/ --- drivers/i2c/busses/i2c-aspeed.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index 1c2a4f4c4e1b..967a26dd4ffa 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -617,13 +617,19 @@ 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_ack_last; 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); + + /* + * Early acking of INTR_RX_DONE and INTR_TX_[ACK|NAK] would indicate HW to + * start receiving or sending new data, and this may cause a race condition + * as the irq handler has not yet handled these irqs but is being acked. + * Let's ack them late at the end of the irq handler when those are truly processed. + */ + irq_ack_last = ASPEED_I2CD_INTR_RX_DONE | ASPEED_I2CD_INTR_TX_ACK | ASPEED_I2CD_INTR_TX_NAK; + writel(irq_received & ~irq_ack_last, 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; @@ -667,12 +673,11 @@ static irqreturn_t aspeed_i2c_bus_irq(int irq, void *dev_id) "irq handled != irq. expected 0x%08x, but was 0x%08x\n", irq_received, irq_handled); - /* Ack Rx done */ - if (irq_received & ASPEED_I2CD_INTR_RX_DONE) { - writel(ASPEED_I2CD_INTR_RX_DONE, - bus->base + ASPEED_I2C_INTR_STS_REG); + if (irq_received & irq_ack_last) { + writel(irq_received & irq_ack_last, bus->base + ASPEED_I2C_INTR_STS_REG); readl(bus->base + ASPEED_I2C_INTR_STS_REG); } + spin_unlock(&bus->lock); return irq_remaining ? IRQ_NONE : IRQ_HANDLED; }