From patchwork Mon Dec 11 10:22:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quan Nguyen X-Patchwork-Id: 13486978 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF0A0C4167B for ; Mon, 11 Dec 2023 10:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UYs3qdY+nY/odgCiz/1+fkvcaTYCOhbK3uDh54puqNk=; b=Wkk34KtvnbyAnq gYIztbX6hvi5RUF6o0W1QE+rQhGZ8vGnhx5U6rAs2t5dyxjrQqLU63NSN/kQ40Bug5Gp/F7/FIkB/ HVJKRx8xw1B0JBrmrxBgt7hp9800eEVQA6Gr2z9SekyeTB0gp+c7biNpLCaFQhVoOlcl9Ujy9d9Ev P1yr5der/5xqTxhX1LxPm5CCebZ17cfs4VrQgA8GLe4vKH5Ui7pPaewOrLdy3qv4uxJgRKp8MuWyS XeX1fWiMHLNlRCaj49e7SUHTidFliFiMI6hrPTQXNmrS4ln6GiS4jQF3lB6a9baMcdXrSkv4V7A87 szy0MnNPp2OO69YidCgg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rCdR9-004avC-2W; Mon, 11 Dec 2023 10:22:55 +0000 Received: from mail-bn8nam11on20700.outbound.protection.outlook.com ([2a01:111:f400:7eae::700] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rCdR3-004ato-04 for linux-arm-kernel@lists.infradead.org; Mon, 11 Dec 2023 10:22:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bCizyxQlmrXKHOYuAcItLqutYwGCfh87WnaOI9mg0EQBOMZQh0yGJTqfQ9YzPEhe+3CNgtXeMFJFrgffggENuOe4je7lDccuiZB8ovbGi/P0RrakvdG7QYGdZguQCs0BMLpHJTR35Tg1soLWquZBaAn8/E+YMXCADJkCEJymWgTeuTUz9CYNq/et9ew8LWoiNcd37h3Udzapy7hxruyL58ae8ToVg5LhtPyEyEDw849Ofc8NTCGWwf3TIulhbOH1yTHezaEmPcQEzx/f0Ym1O2WDcE5ysJhFKPIUTRZ5Er7QbUPIeTSLihunP+tkgYS009qZNyts477+Xl46NzpT8w== 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=9BY5s2186L/aTXEB/fsA3P5IQbtXqCy/Ek7NttGxmiA=; b=AedBbMjJvczE3DqR4bFDLGco6BmWa0kMQVa80jRhZkXj+jTll0cbW3FkOnb6JsiiwtA3HRSMaYg/OSW+9RZPUGwe/9AkBzZA++rZCnlzUJ56DGG+96PDvE8JHgy8u8p9jsrz1eRoM7/U3kaPkxYEu3KVcRNMwfbmqFmAUIOUCHchjPS2Bn+41xgBidC+5NzrPg4qZgLMochneyTtcz3o5PTnpSN9BLonOgbt5cOrel5aKCRzcfGJm404aBbfefspXOZs/gmh7n6XmAUmuyjVk2uQQK61i39UcPBlSiJcmf30wo4g0UnGl0vFMwwTKQwRfWQUXgS6HWOcjZC3h7x5IA== 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=9BY5s2186L/aTXEB/fsA3P5IQbtXqCy/Ek7NttGxmiA=; b=HBmVpxTPg/dgDZyG5iFMtfp3nJjgQmVxsntp2a8+cHCPRy8PnivKwqrQJhYka05jRouR2diA8qPTHBaAjHGwem1JpbnFki/EFz6cmh2YOD7Wsor5LOFXZZ48rOzRwPWM5rDsGCcNkJS5Tc7i8gwgC0ApD7dpynNwpuNbrMAUdrA= 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 CO1PR01MB6568.prod.exchangelabs.com (2603:10b6:303:f9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.33; Mon, 11 Dec 2023 10:22:44 +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.031; Mon, 11 Dec 2023 10:22:44 +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 v4 1/2] i2c: aspeed: Handle the coalesced stop conditions with the start conditions. Date: Mon, 11 Dec 2023 17:22:16 +0700 Message-Id: <20231211102217.2436294-2-quan@os.amperecomputing.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20231211102217.2436294-1-quan@os.amperecomputing.com> References: <20231211102217.2436294-1-quan@os.amperecomputing.com> X-ClientProxiedBy: SG2P153CA0007.APCP153.PROD.OUTLOOK.COM (2603:1096::17) To SN4PR01MB7455.prod.exchangelabs.com (2603:10b6:806:202::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN4PR01MB7455:EE_|CO1PR01MB6568:EE_ X-MS-Office365-Filtering-Correlation-Id: 191937b4-53ef-4954-1d5f-08dbfa331cd8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SjGZSCBgonBI/yfZgZ/xPX12P+U2kYsAZBqqP7PhGduVgCzfjzJmI7xkgZkCoaa0SexcniPXjBogX0doAmvMCW1+tfw/zR3mXj+PhNITq/fbYpvT8GhS37YG8VZZBXKlnhgJKzXgOmp31OIzSJo6u0mQEGCKeqyfyPe9eADbObN9yUlRYXvG6shyYnW5NBJAQm9EbjxRXsO24H9Bkv7jl4SsPkpDTyeEBEjxps2O7znGnZnyVqOpU9Qt9DNXyNoGlUNclv6HeTFCB/uASOEeLaFr+wAjheIcnYO2V4OWcEoXgHNPYF379ImiAiKIAWM7dRTMl3xRLRJqC7fBAv7w0Fs9HLk9hwNjDR4ghQ0GQLK+eIyGQZ++OPQZ0qPCdVYotYFHFnlqVqUcmIduREGWldY99JXtuAKFRPMGoX/o2CD0Jw9HnK6NX148Sf7VRJDJzYGUoQdshruQA2ky+oZWQx5M6ovIlSOii4QjoJAhqlZVIzrmOpnjz6VWUfpaqPrTKTKseG6UmGuAvWrru6onEZmVFY5lwQ0VD7wDnXMj+R4f2qNJUJEaJaghIfsCsNISP38LGP7mGZT3TuTMiKvsM5DDd5xwPw3HXEhRAtiyvURJGrbU1RfCGoVVr/xJuo6V 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)(376002)(39850400004)(136003)(396003)(346002)(366004)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(1076003)(26005)(107886003)(2616005)(6506007)(6512007)(6666004)(52116002)(83380400001)(5660300002)(7416002)(41300700001)(2906002)(4326008)(478600001)(966005)(6486002)(8676002)(8936002)(66946007)(110136005)(66556008)(316002)(66476007)(54906003)(86362001)(38100700002)(38350700005)(921008)(66899024);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: x1oTkao/5yE5qMO2xfF8BCazMJJBkD0JYbdd1Jvoc5Nv9PHAWFMJB6r4VszfF7/kdXIlKmP4HUmN5guoDlkB6734m5MRg3SAsbRLeylpKKNNv0Y3iKLsD1ohHpDeZZ7nM0XuS7Ndsk3Qi1Tvu8m9+NgzaDed2K8QEt7u2vE45xdaEa6T5KTWYWtk45zLK9YqnLq6rLnHZoiHFF8qQI4hTOY4Lu9chmRmuCN17m1mjeTqIILdu+c4JJeDOjlRPS16cuRVVJD5v/5y6bmBwuBcXgcAT9C2ciaTFfjPzp8vbsIbop9boNcDGNsJ0hqgRir0htgxy0H7h/BClp+P8LG0Urt5u3Hn/dqBvDEn19NqqpCArfQO5bQY2468bZ9O/0j9mbDw3u23lP/ybjqbemsfE6q9z9rj7JpejjeH8RmJaZ20K/EfgksmSIQ0qPREbAnwDRFgqYH6SgaYZbggumXO68CgqQJTnhKhD0MdmwYr3I5NS9CXyYOKkVseuGXcXq8ZEeZamXHKM8KIOLDjRZL0rlh5fhScZ9weHmAy0TLJXx4SEJdDBgf+iCL2rv2yHJ1MOloh3FRHu7pmd95/e1lcyQXQJb/hJ3uq7hM+++rs2PO9KhAvXQZbLwetS3L/LEE2ogfrk98xk35UT+PxVPNsFw4bWTRGxNqhUDtlTU+AUj6mBxzOc56JYIJ+HD0pEDkzoLn/6k66kHXPE3cfZnbtNwQ/eHK5iTjqxZn1yYL27kh09EKJqg27gLk8ZULEQrJP5WCPrOf4KJNiZ9lFMumI6euA/Isuy62gYjNsrJ87o0Tsi7h8u/+9/4ory1K7/7uzGIFU17dAmSB5hlgMdd+S217BAlUVb5oaN3mTw1bwq6mK86+zSWRvrCFMjGx6ycQnQt9CCixrxTKe4hioJfT72gB/l+gtgJAxwb7cepz/sbrT0zaca5SnDnSF3MpDAIS6f7imolJEH15fVyqq9Hn9TXNhu8cZPLkgd1EJy5FrJJ3tOd5Id/RR6nKJhKeARmHsAA7MSU7mFkCwLPkjPUa2zf20T8h0scJXlr+BHDVPkyJ/h9Pqnw1oTUFl2X0RmAT28xBOC3ljxIooGq+e479eTXIpsEJhUis2xG4MHdEw+3yilWQDujUsWI8Ks0Fi1J5pR2I1mBRKLteHkA4G7VDrbEpZIrAM+cqNX/cX6DCHVDDQChyv79ZigOz5ZULgWmwZt6wyC/bVw+nJET/atF3xcFs9DDVay0Iupq74A8KhIvznAGVuY6R68jj+NuDxZr0TCcLfrHHdtMKXb310SaORife7LbBkbhNVcqCEmbFK+Z1SavyofZmMTGsm7DxP/4evfLht0xSY6t/OBpBKRmQc5kBrZJyHvV1jrDyI624IpchxDeBFVHWyjmcsGISWV+9mYkbRyyMoTevGc2aG7xHlrgWhRJTzA51lCNIDKLlVz0NzjJgjIcTwGGrEapSNEYb8J3elHdK/TNOguRarA+cKVMhVR8uXn/6kdMPPBONsXjM+s+2NzYhHxyibSd93xDXJgRWe3wkYb53uNcG+NP4GrlCHM++kYwalRfNonX75Kh6zXQ/6TCrLDWTTMR4+540x5JEmYzUfCcnVEnFt+G4IYDIfvErzao+zuC5fik2w6G8= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 191937b4-53ef-4954-1d5f-08dbfa331cd8 X-MS-Exchange-CrossTenant-AuthSource: SN4PR01MB7455.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2023 10:22:43.9396 (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: IX2yGEacm58I0fwfDHy35K31N15yTecyJC47tebN7DsFXONPkrsc7w2UK7dK+WQP/qntc6g069VVNPAgjSuzsxEg5flu7gMK5Wdipkn8sYs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR01MB6568 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231211_022249_088584_BEB7B9AE X-CRM114-Status: GOOD ( 18.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- v4: + Add an extra empty line before the comment [Andrew] Note: I'd like to keep adding Reviewed-by Andrew and Andi for this patch eventhough there is an extra empty line added before the comment as mentioned above. Thanks for the review. 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 | 48 ++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index 28e2a5fc4528..5511fd46a65e 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -249,18 +249,46 @@ 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; + } + + 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; + } - /* Slave was requested, restart state machine. */ + /* + * 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 +307,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 +341,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 Mon Dec 11 10:22:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quan Nguyen X-Patchwork-Id: 13486979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7BF4AC4167B for ; Mon, 11 Dec 2023 10:23:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=23M+mFYhkE2nbLyi6EopDfjpC1HHmoCscBmSm/Woe2w=; b=3PCxqIGFgVEm5D AvYW7/YQTarhzOf16xpUX8+NnlRZKP1wHffbFM3MZxtD3pe/7ANfZSgrKtoujeb2bYnBhHup1KM7J vKiASxgMn4b+yEQdXK5m2sClfW7pB0weNCKVuSUFlUUjDI7S65o11hkpG8mZniMRlQgiSxTiKZsWT d172Epmev3SYBQ5B0aCk0uB8Tn3WqeK0ga7W4ZinuP8iqDQAXtpHBACmMrt3azgiC0bZu5lJzGJfm ldRdDNcAd/emEzpD4CoJCUTvEey2jaiAEuWUURVLcN7q4YRH6pPDS7xVBZzRH6yxD8GACBhVdEo2c OO8TxMQ3aQDXz4QOFK4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rCdRF-004awj-1g; Mon, 11 Dec 2023 10:23:01 +0000 Received: from mail-bn8nam11on20700.outbound.protection.outlook.com ([2a01:111:f400:7eae::700] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rCdR8-004ato-1P for linux-arm-kernel@lists.infradead.org; Mon, 11 Dec 2023 10:22:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WDidnJPACR/yJ0Xsc1RdAqqO7RjX8fZwHDwQMxjo7CC1xfL81Ti/61MeplPhpra0YxcA4sw/1HDzx5Y2k3Cc+X4I1F0fAlsbCMMm0IjT7mkBgeJZgS+KUQm4L8T9aVUvnZADViXIQ9/szQfAxAZReRPCezCHLe2tGP11U6srcp0/V4t5216SIP9RGJNlh/Yp9DAFXn3lODGpCAC0d4AozrWUFS9DRLiqwCnpVoVt0uJ+AsLT4VUVka21igSg5zerqgCq38BRNBomVWDtAyp3iIHbgykOOMhvSdA4EnheGGqlfWl1bgnFIXviGahR2CAXIi/U4pGRvUQ/fH0Q9kLmkw== 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=AL8ucwBp7iSZS1mOKdfvDd6/FN0LMGhmG9Mje9C0kSA=; b=S/Jgydl1F99LJwmnMpoPMMfZ23emQgjLWhYhzYfu2TqV4kADXQLRXcZVpYCIQLqiw4yNHEeEyLm23avYoST5RoqVS3US/nrEWMsHGj6xlTdhYRRLVmKEcBW/vOO6fOeisaBNMPb06t+pnD/ybh8z04Q/i5hcbeVRC+vG1spfb0GuP7SJ6i7SZxt0HPdWfAqDBZ8wStmG3Bn2qjOZnpuM9m1H6HvyQVD6pRVHlMgu8uXVOQE6TxXWF+9piejVpR3FFq6b2GWzAUf2N7CHzt+ZbdYLd5iJYCzwauSkLHuMmgPARWgwkFWBk/7IzXH/QiYw0S4rPY135fTikA/GvTtyuQ== 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=AL8ucwBp7iSZS1mOKdfvDd6/FN0LMGhmG9Mje9C0kSA=; b=n9JsUr30Xzb3j/SbO45wKRo/uEs21FVacYgyyaYA/3nGcZSFTbG3txYtveVH7BneyZRjzbsbblGzFXKGfGG8Hh8z455aPYX/uhkR08XyiDlBG+pVsfdrEtyRJxBkghpEBVWmMtc/Ap0rUrFdK2bmV68XS7qP1kEyMy6Rfbk+24E= 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 CO1PR01MB6568.prod.exchangelabs.com (2603:10b6:303:f9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.33; Mon, 11 Dec 2023 10:22:49 +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.031; Mon, 11 Dec 2023 10:22:49 +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 v4 2/2] i2c: aspeed: Acknowledge Tx done with and without ACK irq late Date: Mon, 11 Dec 2023 17:22:17 +0700 Message-Id: <20231211102217.2436294-3-quan@os.amperecomputing.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20231211102217.2436294-1-quan@os.amperecomputing.com> References: <20231211102217.2436294-1-quan@os.amperecomputing.com> X-ClientProxiedBy: SG2P153CA0007.APCP153.PROD.OUTLOOK.COM (2603:1096::17) To SN4PR01MB7455.prod.exchangelabs.com (2603:10b6:806:202::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN4PR01MB7455:EE_|CO1PR01MB6568:EE_ X-MS-Office365-Filtering-Correlation-Id: a303e0ec-eb89-417a-744d-08dbfa331fd5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U9mw8C6ILK3csf8axLoZ2t6tMXF7AO5KSaNrw6FKIUmMZSFIXwD+EtS+t2s1sLNHq21eDoFTc0xpvRdh150sWIiED5njgrQOoKCIAijWOhYS3tG1VIvT5B95goL4d1Uj1rXqBj3byYDVaySjSl2ItTjKpkwFMJDNFJFLvScISpKyEEB6FJnu+zceahim+nu/z/DBwFIaD9GfU10LzeK6VxkVPyjzcrnoYxKIBa52cu+YqhEklgoMvPSjtD/hyle3YYofk5v+AmYuPqk0aEYpugl2vzICAbJFqsoTKk662BriWxFpOiKA0A5h28fLiXsQjLPPeJ8lHdGaBMdX4NcQlP0+xSJp2Eog6PeWH+tZu2Q874jvDf2c6nBGz/Fg4oYab10yxdZBgnOO9g6EI2f1zBrSQMUQSqEzGZCfU/qflYyW3EHzQTI1bbQ9bB7KQIJU2ILwaq93RT4eiFywlTOFUJFBtZlUHiBsQL7GM0aU/1rebaS3vn6r9m7WgC890PoHPkeMm7x7VNcuiyFzPL73xJREuCM6HQd+6mnof0VRkIOJ5pOseN9Gy+Ehj7wYTwu1HOS3FZiFRec4fAdsioRLDogyLJMdO7p2oHRbbqd7LPL4PA+3MBsqWOxfnOJUMMC7 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)(376002)(39850400004)(136003)(396003)(346002)(366004)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(1076003)(26005)(107886003)(2616005)(6506007)(6512007)(6666004)(52116002)(83380400001)(5660300002)(7416002)(41300700001)(2906002)(4326008)(478600001)(966005)(6486002)(8676002)(8936002)(66946007)(110136005)(66556008)(316002)(66476007)(54906003)(86362001)(38100700002)(38350700005)(921008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lHduaNS8DVTh9rEkMjoGrFTJdjb3/AG2NOLmhLfENOAT/NMI4E0Be5DpsA3OKoLVzlQyMs9IQGzEvOrZ3qz3ukLTcOnaxvmVYzTJte9aO5Std4Fga4UIDmETRYypn+7lvkLTRZIE6d8BNvyA+UBuLNvcQ0JP+D5ntL7mcFwTfnMmdRjvmy4V9x7qQ3bvV8qyPkCMD9GTHbZpJDvuskAMzeB1l06260QX9SOkso6AyxfTFa0DamAajX/+vVDNZNZdb1euUHay8q6Ckx49grcfgTkq57oD0Z0wQLwYkab6aZwZjgZ/+/ZjGfbUXthXYqiD6GtcReOLpH1TjOxzFxsP2ZdSeks12E6ib/bpiI3EqIWgAdZ75AcVhpwI4nsbu4X2Ojh3HFAxIGHMB6xyKj3gh9Y5QjtWaTDQZsZMdKAANbL5fOlS6ZKTEQFrjYvHCoJta7vh5JQ2U9OzZJlQPiMP079LOVTlxNl4xj6BqBnpLc1t7FNHZEkqN4DQIFUjyQ9/NQ29UylTTVd/FeO8FIHP1DMkWnIeZ2XoB/cBG6uRF4J4Jq2rqImwaURLo0QPPsdyqXMhYflv3+GqcmRNJR8n459fW5e7VUM/cWugCQTHVt3SHYgBtPUw8mTemXd5kNP3/z5oLAAhSnAK3esCXk0weu9tuikIatKFlCOYl0LkMsUm2KKMqJZTIt/d9ukzOf1shW7U7H9pqpbGa1rHq2Jq2uz16qRicuqOd20sA+VrIeXrdAgAZqQE5Q0k8kptmJ/lM10PDWcRK86sAJfZxvWiWrnaHhDSNaCROWWK3OaNScD1I11DuRG9lzaiolnU2LTpuOZTGHo9U+5pwg/bPFZiYhuG6Z70M2K8mQYNBmb+xs9Rdv3irRBJh2+hzqRhDCyjFlYFpmITgi+fJt5siORHX6v4iEno/XINZENB55S3WFt48t129DHzlkH46o0BlrAk1k+1Gjirq1NSgvCqi8BUjepP/pQbfpxS+DKV35bCW4v43XBp/hB7t5Ox+Hktwrp3+MuUouVs0NRFn/GcARXGTN6xSTG5a4MHND5cORLoHnA2Pmn2IzLA8ugDv/7vWGbWHpa7dFjkTsHTDELFliOYAbnGdpuh3rLvvoJG06bGd+7EofLpk91uEBgIdBVsphStGbsJputrMdvjWSUgwiePRvDGfWvKNIpr9sOFLjSs7ecIaKq86H7pfBahPyaSckhXoBLa+kgp44hScV91kNjpX9kd4264wRFjdZghArsqvCwuLR70OXRIwU+EIZHasM/AgveGeUztzI1x1EffXAIqaGoHgT5nMsXkbkGkqaQDz/xyeRNVM5WzQ57RKRV/OON/ovPqQKVKWN0pUvPkLUquJecmjOsaEqIfeAhcoRHIj5tdfzf6hvezt/NwisMCWAmoe+bFBv806f4i/9s1kirhlxfY3iuRz4vvKZ3PUptRBuoHRunZPxD2sdtCdo8TSMGDTPrY+K4XhOL/MByV30bGnKAhowolzJBiFrCBVeotRLkKkUkItn+7eO/bEXg5BHYNZXsRr/lEKh69X9CQLfLXkow8N/G4TPd7Jt6x7UA2M6NVGEs7/hTvr+jbWsUBXG2cfJTtC2OttmH2tiBLO8+i+fE5kvhlyyDJ8dwk2sQmUDE= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: a303e0ec-eb89-417a-744d-08dbfa331fd5 X-MS-Exchange-CrossTenant-AuthSource: SN4PR01MB7455.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2023 10:22:49.1549 (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: PItBE7hQJPUk1izhwECgYdVAJft+7UDK0p7N2wmh4omF1x975WbDKas1MPK9DhOef3sW9bJsTMWYQG6MVpLVByfIORcLa6ukgJqjVLG2GmE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR01MB6568 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231211_022254_498955_68009DB3 X-CRM114-Status: GOOD ( 16.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- v4: + Switch to use define macro instead of variable [Andrew] + Make the early ack conditionally to avoid unnecessary writel()/readl() [Quan] 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 | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index 5511fd46a65e..0f67218cf04a 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -93,6 +93,10 @@ ASPEED_I2CD_INTR_RX_DONE | \ ASPEED_I2CD_INTR_TX_NAK | \ ASPEED_I2CD_INTR_TX_ACK) +#define ASPEED_I2CD_INTR_ACK_RX_TX \ + (ASPEED_I2CD_INTR_RX_DONE | \ + ASPEED_I2CD_INTR_TX_ACK | \ + ASPEED_I2CD_INTR_TX_NAK) /* 0x14 : I2CD Command/Status Register */ #define ASPEED_I2CD_SCL_LINE_STS BIT(18) @@ -622,10 +626,19 @@ static irqreturn_t aspeed_i2c_bus_irq(int irq, void *dev_id) 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); - readl(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. + */ + if (irq_received & ~ASPEED_I2CD_INTR_ACK_RX_TX) { + writel(irq_received & ~ASPEED_I2CD_INTR_ACK_RX_TX, + 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; @@ -668,12 +681,12 @@ 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, + if (irq_received & ASPEED_I2CD_INTR_ACK_RX_TX) { + writel(irq_received & ASPEED_I2CD_INTR_ACK_RX_TX, 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; }