From patchwork Fri Dec 8 03:31:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quan Nguyen X-Patchwork-Id: 1873637 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=HtVU/xeQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4SmcDf1B8Sz23mf for ; Fri, 8 Dec 2023 14:33:38 +1100 (AEDT) Authentication-Results: lists.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=HtVU/xeQ; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4SmcDd73Gfz3d8G for ; Fri, 8 Dec 2023 14:33:37 +1100 (AEDT) X-Original-To: linux-aspeed@lists.ozlabs.org Delivered-To: linux-aspeed@lists.ozlabs.org Authentication-Results: lists.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=HtVU/xeQ; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=os.amperecomputing.com (client-ip=2a01:111:f400:7e8d::710; helo=nam04-bn8-obe.outbound.protection.outlook.com; envelope-from=quan@os.amperecomputing.com; receiver=lists.ozlabs.org) Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on20710.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e8d::710]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4SmcCL5lh6z2ytN; Fri, 8 Dec 2023 14:32:30 +1100 (AEDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mz+abDYuDut4REYi/I0ZHaabkE4LOY48DilKsT/NGM+ZroVCszEwQj7Yvyuj4ZB4RButAkV+x31Zq194ax7A1pTAWMiMLLIYJK4mweW3DGkMWm1K1262ReVGkvZ8yixpi2Y0N+N+YjGcPLhsz8l2BuWWnZBkhm9iqGKfuXtz+kCMTI6pNBn69Oc1o36ulfLE8r6sDnlvSnLHe0uG+1MbsQO5CWBhF4TNNhMwieea5YQpy5K2CkJ1xhnuM427tY48YIbgz+sup71h/QqjqYUsoEb3rTZYUFi847rCRZzdFl8dwxG22ErA/IrzjP20QeutvS3f4pcQj6vDER0m3M/C3A== 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=vEQEln+Pxrd+g7XX0Erli+WSVR/HUZwZxj47st23ww4=; b=C6hKiO4C4/GbtwPNu3BHdaSGxlDxMpGpc3foMwQURPOgECAB+UXUzb9qfeTUHwtlG/ElAPOY5G4WU8UT7o5YX70TAXLZXQ3p+jruc0W6IGJacWXX2XFHpxG9YbpAXF3oUI6WAerOZDDO8j1JLKjh6ApiyRLbj6EQ4ihxypzrZ1kxxfitj1ewtEfAcB3tAKf5tLUrMV3kTk+wPXoPPALmfNlLujsF1crMi18rt9UzyGVDP7yq/GNA2AtegDESbJ9W7cwL96tWFdV71dsBalvK9SsnGnIkeiHKdNYgA6V2femouzC2WzcnqJfgnOnTG8Ss2XzLNzYpru/X8XO0qpbzmw== 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=vEQEln+Pxrd+g7XX0Erli+WSVR/HUZwZxj47st23ww4=; b=HtVU/xeQ1YtTH/424Dr6exUPOAVgEx4hZJp5NYwgNjbPr2FMdtLxuT0iv5dKL5/XAF7mY+I+ttLBoJH/btYs6Mz66f3BYcrnLz6KHmL4Q//IM6bAYw5U+nv9pJLEZw74UJcIDzbSnG7WmKM4ZqD+aQSzX3Zz6VbX1j9dA4BhZr0= 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:09 +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:09 +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 Subject: [PATCH v3 1/2] i2c: aspeed: Handle the coalesced stop conditions with the start conditions. Date: Fri, 8 Dec 2023 10:31:41 +0700 Message-Id: <20231208033142.1673232-2-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) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN4PR01MB7455:EE_|DS7PR01MB7784:EE_ X-MS-Office365-Filtering-Correlation-Id: 89633b98-bcc3-45f3-f07b-08dbf79e4240 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MzIuvqeKDZG5XaJcallXThTZ6V3wImeTXqCT/J4p/5gfECvMm4UH9QpZrH8TsU1lY87wZjXI8wpKTFxOUJNpj2+Gp/FpP2ppITJrCV/hPOjPsG8iWeDyh2e0scB0555NsMP/to0q07r0va1/XKBp/wKdyhipytZ8KWFtTIESdQwc2zTWZWsuirpYFSOXXIOj6goPRJQscIDpebp1ba33MnoYEqacGXt/KCBvrM5ouJ3TqUDkAWrMC1Nr8CCVOu29xoXWtjmlrP+SlO8+eRljjfO892Y3AYONVv6Qe/5Hr5nwvWt+e0+papRrSv8E2R25OV0efgv99iRGplnq2MW9uzSLH6IFs3TiL9N3GhPeOwQ15z1xPOeP7nU/GEv+1v8WxqTG/NGz+lT4yqqypoE1vXuSLcdmm+mHhj5RVOkVBcJP586lkxtW/2XV2YfCKmP59tO5ih0cEWA0T/SwOAvtOXvbkv5HSJbzxpMOYQ22d2H1LwpXlFbP7wtqwU0mpUWPuTJUj1eICVcqw4YSwtBQaYuJGBg8PURqX13b22dhwGNtiTw4FaZnfnTTWnIWhoJNLKRsomJZHnP6eeKCxRrw+lCjUXNNJW7BRBT8p7MbL4Iw6+9/dNek0tNAL02WyuIt 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)(66899024)(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: E7OhJtKiDhISKT4bOFMLrFCD63yiAd4gZlbsfaDMvQMHv4LbnPXjg3TqrYdRrXyh56HCZc1VKwVqJIJpDmZ67OqGl4H89zV9xNImMmlCf5WSzQ6hSvVbIBUpv8u5BlyoHr+1EDBjfn6Wqv/B5vbhlbmgEhyIbyKkpUvffMuftHtMj61jauuIGvOe1Dx0C2UQGAuAKmtodvryoPlmnFi5+oeR65d9qUDeEeQOFtrOtiYT7UxO393nE7ebQzqCFM0iFIxPkkpGJMMPSHIwj2EQi6dLwdiJOkths+VI1tMJmipp723iq9HTXUbc2ksNnn8jQ9Xl8mWHvl17zIs7t6FQl6yk9yn3QxQKw6GvtaiUS5AN1s5C1FPF8oLYzwXrkdyAccIJscRlNUMZGXAPCUWzIjni68gbReyHkQYo9j76Z1rAU6fFWO5/Z9MFBxre2PZSJ3z59JDg7x7nPQsQqZtnZ3k0Nw0tVrDsVd6r1j4GNB2G10tYQ3FojMlkgg0Ta2D8A+I8bBQLOW0abb3hyAAuq+xBIMj/H1CPzmV8aqHby2EfTZZp2BpyTSrpFGWw5p1oHuCANqR91Q4gIxYz0cxqt64px4rn3LaF+FaSZReQ1+MDppKgP2eH2j9pFcC/hikJ1C+jjMD42rhH3Kkbbezas0Tr12MlOh40pqaVRExKp9mUO5GMfEbelT7DDPsNMaw74nVcH21yU5cCNBxUIHeAFN9c7/TOjWwUcDaB0f2mJtU+IBuWodne68It1BDqzSyFf9tpJN9TtmQ4CE1W20HQDH/xnPVMC9iA32ZwBipKYFDcPrkKvEMdy58k8zqirF/9AX8G/ar3KHTg6BrL491FcZOxqFdNXy6PHqBj3u0VhVC6JZ3EE5evqBJ1+QQXizHvEem3xOocrPYlm7APLHp6LuTkA22xa77DtiIgwEqbZkEqpOAFsbTDHywR4VKWObRezqMWSdvwWCQXCd+E161p5oQHEFInzs2Vtql7BoNNo7w8G5ymWhvAL1GbtLGJxlM4X9Ik0ix0nf4mkT2U9BvWmzab/Q0sySKLlgynPGp7mtDbn09Dj/V4WAQrHFN+QliROH0Bh25VwFT6m/B560f6e94+DFW3j9S2MLfrn+g0W9NgXYaAUNO6V2UyNgKI9ZkscDa6ooQ9huR61tuxwn29lKsM8s4uz5sMwXQMqJMM9ytXyqAOhJAoTrkzbRj48+J4teYPvqLj2BnB4oScCGyFmI+UucEOIwbUA+MGbTaYlQNQ1Jypfap0kZrzW3WhylykMKNrOwk71LkDbHJBAv1y/nvmyjE6vOZpFroZrwA10HrWkCKzLElb80P++OMJFKpZQ0ciwxNauyr7/3/5rDO9H9i/eHWnkm/BFWpkTXbhOoBwuxtL+1gfUMOUn8cD/76R3L0ofaTZAo2ov8p4YULHYzRK1UUtq+0yr+xV/eoRMXBV5RwGpbAXqIzexzjdZem99TsUyS65meFmUAmjfrBd+NKDHL9W6glLHU0QQQx/WNqZ8ynoyMcIxEccvltCpXcY1rV1rv47TmjT5HauCmvtSNw/d8TgKpQoMGMIBRjlGdphjaReEkjp/JxqFX66486G3OtWqAiOz0NuKYbOAGuHJ/sEq3a6Q/mDECKOzza4pTU= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 89633b98-bcc3-45f3-f07b-08dbf79e4240 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:09.5231 (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: Z6G5GZfauDSwV1pkNdn6C7ZyKp0fstj/PFCss0K9VIKwXpQ73DIk/NDj5D9nLFM5/Qlv9Xh1nPUZvNNumCLD0f7Iu0r+SMdo+Fw8AkxcvIs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR01MB7784 X-BeenThere: linux-aspeed@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux ASPEED SoC development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cosmo Chou , Open Source Submission , "Thang Q . Nguyen" , Phong Vo , Quan Nguyen Errors-To: linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linux-aspeed" Some masters may drive the transfers with low enough latency between the nak/stop phase of the current command and the start/address phase of the following command that the interrupts are coalesced by the time we process them. Handle the stop conditions before processing SLAVE_MATCH to fix the complaints that sometimes occur below. "aspeed-i2c-bus 1e78a040.i2c-bus: irq handled != irq. Expected 0x00000086, but was 0x00000084" Fixes: f9eb91350bb2 ("i2c: aspeed: added slave support for Aspeed I2C driver") Signed-off-by: Quan Nguyen Reviewed-by: Andrew Jeffery Reviewed-by: Andi Shyti --- v3: + Change to handle the coalesced stop condition with the start conditions [Andrew] + Revised commit message [Quan] 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 | 47 ++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index 28e2a5fc4528..1c2a4f4c4e1b 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -249,18 +249,45 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) if (!slave) return 0; - command = readl(bus->base + ASPEED_I2C_CMD_REG); + /* + * Handle stop conditions early, prior to SLAVE_MATCH. Some masters may drive + * transfers with low enough latency between the nak/stop phase of the current + * command and the start/address phase of the following command that the + * interrupts are coalesced by the time we process them. + */ + if (irq_status & ASPEED_I2CD_INTR_NORMAL_STOP) { + irq_handled |= ASPEED_I2CD_INTR_NORMAL_STOP; + bus->slave_state = ASPEED_I2C_SLAVE_STOP; + } - /* Slave was requested, restart state machine. */ + 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; + } + + /* Propagate any stop conditions to the slave implementation. */ + if (bus->slave_state == ASPEED_I2C_SLAVE_STOP) { + i2c_slave_event(slave, I2C_SLAVE_STOP, &value); + bus->slave_state = ASPEED_I2C_SLAVE_INACTIVE; + } + /* + * Now that we've dealt with any potentially coalesced stop conditions, + * address any start conditions. + */ if (irq_status & ASPEED_I2CD_INTR_SLAVE_MATCH) { irq_handled |= ASPEED_I2CD_INTR_SLAVE_MATCH; bus->slave_state = ASPEED_I2C_SLAVE_START; } - /* Slave is not currently active, irq was for someone else. */ + /* + * If the slave has been stopped and not started then slave interrupt + * handling is complete. + */ if (bus->slave_state == ASPEED_I2C_SLAVE_INACTIVE) return irq_handled; + command = readl(bus->base + ASPEED_I2C_CMD_REG); dev_dbg(bus->dev, "slave irq status 0x%08x, cmd 0x%08x\n", irq_status, command); @@ -279,17 +306,6 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) irq_handled |= ASPEED_I2CD_INTR_RX_DONE; } - /* Slave was asked to stop. */ - if (irq_status & ASPEED_I2CD_INTR_NORMAL_STOP) { - irq_handled |= ASPEED_I2CD_INTR_NORMAL_STOP; - bus->slave_state = ASPEED_I2C_SLAVE_STOP; - } - 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; - } - switch (bus->slave_state) { case ASPEED_I2C_SLAVE_READ_REQUESTED: if (unlikely(irq_status & ASPEED_I2CD_INTR_TX_ACK)) @@ -324,8 +340,7 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) i2c_slave_event(slave, I2C_SLAVE_WRITE_RECEIVED, &value); break; case ASPEED_I2C_SLAVE_STOP: - i2c_slave_event(slave, I2C_SLAVE_STOP, &value); - bus->slave_state = ASPEED_I2C_SLAVE_INACTIVE; + /* Stop event handling is done early. Unreachable. */ break; case ASPEED_I2C_SLAVE_START: /* Slave was just started. Waiting for the next event. */; 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: 1873639 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=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (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 4SmcFm626cz23mf for ; Fri, 8 Dec 2023 14:34:36 +1100 (AEDT) Authentication-Results: lists.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 Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4SmcFm4vpnz3d9s for ; Fri, 8 Dec 2023 14:34:36 +1100 (AEDT) X-Original-To: linux-aspeed@lists.ozlabs.org Delivered-To: linux-aspeed@lists.ozlabs.org Authentication-Results: lists.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: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=os.amperecomputing.com (client-ip=2a01:111:f400:7e8d::710; helo=nam04-bn8-obe.outbound.protection.outlook.com; envelope-from=quan@os.amperecomputing.com; receiver=lists.ozlabs.org) Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on20710.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e8d::710]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4SmcCM2nCQz2ytN; Fri, 8 Dec 2023 14:32:31 +1100 (AEDT) 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 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) 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/f5ZF3xHA7EgG2IXy1QbbX5r8xzcbo3YEu5JR6sUlucfi6o0PErYOHgc/oOfqfq49MRQ0ruIGJM5kIoKiyhSPL2ZM3XcSzll8RG1MHFQ9Rkh1xfh9u2S8Mc3kAIcW7FrbP73idb9TtTuAu4mYRE1yjmwHwr7u8pBnzTopWVY3EgMTsAoVnQ3Y8Xq7VibrWV1glrnRshlih+/0TtnN0HDCdi5coMX97kGqyLCQaxDl39oQpyEnQjV/aQSdv32YMDiGbdd0477HNr662XZX9WdiH06TYzJi35dL+EQTTyN8YcM6aBq/qwOhUVOUNOokdbwVm31Hyhdjhw/Nn28PQWl5eE0msqe3rF7zFptcNgqjnJ7F+1/+9rsugMM2xPtE1yCQiMRuQJSCKrJxzlxUGsmaiqhKI3/hORiReqcbi3gdKlrVUeuUscYOMMk/icW6ySV1fKxGYYunixz52gDcNCecuKL3on9+Xntsc1BkSHnc9Jb6T2InHoeaF7nklCgHuPAfs4QfZi6NPEWx99+uJ2BG6vtE1GF3CXPYbVFC4kXMFS7YgyLHpfMC782aMXK5OG3S3DmmeBwdqQLOvL+GMJj//aX+m16dPzGDWB2RlK3y4yEHYLB9c/BrxaJPZCwpb0Pf0YOZhavLWlLDHzBKK+ehPoMNnnO6DBz1SydVPw0Yi19WyKN8fSPLG/ztTaxwgS727jM+dstsyqaa1J5vorWH9xvIaexx0775dbATNpbc8Zs55i6gGrOyJPWZwtyJhQAqwie6XutnoqmeXUEcRjhjOgeZ9MoFGfLBRrdaFnjB8UiPQcjOjr2xU7Lhu+KsGuL0cItVtL0GLToCEDdAevmUGsX7pnJJh1a2TcVP12Lq9uUJd4LdUctO5J/rYyr1Be62iAyH1gGxVEBBg7mDTB/FLBVL+qwHM07QqwHNZQsHh4DFLUNekj7BDURZzybma3jOxb08jlCHF9dd9ljGrpr8d4CZSfqu2wG6nKH7jn5FER1YyJvKGD8pEaHaFzctMbU5Gx/qaYC8NUks8uFeqB1qLE5Gq7GQKEG3EtGunKS/loWQqY58MzlnFW9nnGepG79sOQU= X-OriginatorOrg: 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 X-BeenThere: linux-aspeed@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux ASPEED SoC development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cosmo Chou , Open Source Submission , "Thang Q . Nguyen" , Phong Vo , Quan Nguyen Errors-To: linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linux-aspeed" 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; }