Message ID | 20231128075236.2724038-2-quan@os.amperecomputing.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3748605vqx; Mon, 27 Nov 2023 23:53:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFS/Sy9XIr1aJCe7JHB44rtTwerx+XZp7keHrNZpxjH11xIgGkdBgmf4hFZj7ac+zrOI7aM X-Received: by 2002:a05:6358:6f8a:b0:16e:3803:9cf1 with SMTP id s10-20020a0563586f8a00b0016e38039cf1mr9453000rwn.5.1701158033572; Mon, 27 Nov 2023 23:53:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701158033; cv=pass; d=google.com; s=arc-20160816; b=fOGT/5A7o/4g8ZOMNWDvstSmELSnjddraCZVtxNKOtEkxgcDxM4p1jHR+oiIR2+LCf ya47faLoxiY2tjNaUJpghqghk0g+p8DNltcIQsirC5Pfe0yfRXyZoVoxK4OimWpA1LtB HXZd1gYl/OIqchOGgWtL3r/sD+KbjNdo4/NcZJQoO01t59hvHTVLsQsHXlgcpgF8ulec bPBllncrLw20ImtLkW6s1UuFB9CWQdJOqk04l7wHKrzCGDeUqq8kS0AVPdvHSTOf8rXl aPpxBnMAGsx4L3afUVTNl27uoGBuGgAuhbBwknFJ8uWV36w1hVbQIfr6xX0iBpjxzxz2 DkfA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=x2jqkmQeBWRe1MOsuI0Th9cPqnwGyzjyv0fBjRd58i8=; fh=+sI6aN+l4b+kIAcl3+qRSsHxxZLiE4Ou84B6CaaV0ZI=; b=rNPHWV/j8lgoLDx/IntZguuamzZoiHxt61L0eyYepfn8qGRREZC6QMXkhrZS/4s15Z R/4ag++2dSpTVVTZhrnZQ37j3tFnrGuAxxaLwXqZYiPErz8dKKuiyx/7ix6JOPNniveG nlhDiJL2eWANryhXDMU+dG9cPHAQW/vORXjmysiXP5e7QimyCvDcmuGyTAutrZuEqK5K c4PrOMxKUYZ9IGT9jAE/gzlACwgiP1FwUSoBYTHCjC30XhHBkw0IiyrbrX5DG0o8vHjS a6ChUTitbNo/49uxYjgr0lb/Q1M3rKE81XZpgXrAp2F9RiIpvdn2lvorLx0muG2pv4VV WBcw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=DXE7yREA; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id x20-20020a634854000000b0057c2f61474asi10680445pgk.290.2023.11.27.23.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 23:53:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=DXE7yREA; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 38C5C80447E4; Mon, 27 Nov 2023 23:53:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343912AbjK1HxB (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Tue, 28 Nov 2023 02:53:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343903AbjK1Hw7 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 28 Nov 2023 02:52:59 -0500 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2137.outbound.protection.outlook.com [40.107.244.137]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10E94183; Mon, 27 Nov 2023 23:53:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lkDe0qi8+3zEViVLYAUCIBabUHSGVyMCY4USRzZprnCJuCGztDNg1I5ixTM6J94WGoEHw60S5ippQPYu+tR7BUjUpzWIraOJylAzRFgEUq/1pjZqM1yIF9N2XRSqrsWT9RGwRqWmWd5egTSuvUdv+CxOw6ndFn5G+PbwTgoSDQqndfjZsJMX0a/JmIHnsPwqU5yIODXn7D6H+N5+IQXaLXe1pwByphGI5T4DLm1gljmauyrzQq8exHl7K/Xhc7IgV2N7KWPqy1XwX5kYXYGbEOxFtzi7H4nJSAQ+E0KSATRURHWt2kOwMguIey4TvWiCfjqTCIHNJNsMdTOLN1JdOQ== 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=x2jqkmQeBWRe1MOsuI0Th9cPqnwGyzjyv0fBjRd58i8=; b=HmleX7csArypFDGhO5tvZqV8Icvk09MLQ4R5voFlxx77VZJtU4eJV+hpxfP5s52HSpqnWK8hl2yrZdlYu26MsBtnKMONIqfns3Ix/aw0FUFh2eJpkvFbVsZGVywbrdN4TuTwZOU/tS9kuUxl20H/yW+hj++ny7qj8FLz/04XD1fzTePfzYVAEf7xzRnpSAo9fgcQq7Atka4+ll3DWKIfdK7oaEvXIYscE7MRzZkXpO4oEd0TG5Q8slFywft1A2jNYR3ACmoso5UIghUNK9J/cbMqXW2und0f5QMC1ws99K4AsZudNjVuBnrR9O+dTlKg2On5JflDc1NfohC5U+UiGQ== 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=x2jqkmQeBWRe1MOsuI0Th9cPqnwGyzjyv0fBjRd58i8=; b=DXE7yREA/Sivo6aDgEU/68t9SiuXqFxkKzRvzNM8fnlQH3DAd5EgFjEpF9PqLeASdkaU9hPAhj72XSRyTf7x6RmmPHW2DLJyBTx+JU46EGpXMl3tYQnsYQTslauPK3zizxSoCixvSgMj4jN2op6A6t+zqVXWpJROrziFNLIL1XA= 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 PH0PR01MB7895.prod.exchangelabs.com (2603:10b6:510:28a::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.29; Tue, 28 Nov 2023 07:53:03 +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.7025.022; Tue, 28 Nov 2023 07:53:03 +0000 From: Quan Nguyen <quan@os.amperecomputing.com> To: Brendan Higgins <brendan.higgins@linux.dev>, Benjamin Herrenschmidt <benh@kernel.crashing.org>, Joel Stanley <joel@jms.id.au>, Andi Shyti <andi.shyti@kernel.org>, Andrew Jeffery <andrew@codeconstruct.com.au>, Wolfram Sang <wsa@kernel.org>, Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>, Guenter Roeck <linux@roeck-us.net>, 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 <chou.cosmo@gmail.com>, Open Source Submission <patches@amperecomputing.com>, Phong Vo <phong@os.amperecomputing.com>, "Thang Q . Nguyen" <thang@os.amperecomputing.com> Subject: [PATCH v2 RESEND 1/2] i2c: aspeed: Fix unhandled Tx done with NAK Date: Tue, 28 Nov 2023 14:52:35 +0700 Message-Id: <20231128075236.2724038-2-quan@os.amperecomputing.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20231128075236.2724038-1-quan@os.amperecomputing.com> References: <20231128075236.2724038-1-quan@os.amperecomputing.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SI2P153CA0032.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::23) To SN4PR01MB7455.prod.exchangelabs.com (2603:10b6:806:202::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN4PR01MB7455:EE_|PH0PR01MB7895:EE_ X-MS-Office365-Filtering-Correlation-Id: 1eadd8e9-0c1a-4f35-3126-08dbefe70cad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ys36CIJi5Rxwl9e2oZ81Sx/WdByDMAYoDifWC77Y3jIu82R1pcDxutOhy8mKReGD2mRFKsXxWYK+3HbwvZT818VVhryh12CfR+Y6CzqQ9eyQPDw1xWGXdP4sAIibOrLlF4y2cG17Ok9QgN6qT+y02NORC3mcns5Hy9Hijo7fOT22WKBdEOn+k7i4hkOfB3xOrPqAf+IA9IHr3+PCvD+ywlABpEtAzy8HLhe6b6QTpH7zsZFeVEuZzlweMCDGbymhwt7loDqWe1auSOD4Ad0eiDI+NxCkUuPijNsiMVnoWyCuLhINLqS5UVHGZxku1A5zdp+ea+2+usOthNc9yy8LdciOikoq3Sygm0inmIrCFo9JzocoC9ypnFzP5Lgt3clwHFXZtWdgphC+d8wF2HbqLH15/SDBCAD23TNBy9QBk1y6KG52yu2fJl7zsE8P0B98o4TK9zIlijBK3ihC57dy2aquBN5Eqm1sIP1ozgOxezHeHc5wBBlmUi9xU5sJE7OBIHkTaHGauSlM+JyRhM36UZYCK9qDRMebsMvi2gqxAAkbN/yb9kVf5Wt1wxA/zstWpcq86N4+PSsN8djgHhepcSFPSlmlgDzw9zwYwLrYEJU+KhtE4rWISDA8/B7EFNKp 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)(396003)(376002)(346002)(136003)(366004)(39850400004)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(4326008)(41300700001)(8936002)(2906002)(8676002)(6512007)(2616005)(6506007)(52116002)(86362001)(107886003)(316002)(66556008)(66476007)(921008)(66946007)(38350700005)(7416002)(54906003)(5660300002)(1076003)(478600001)(6666004)(26005)(6486002)(110136005)(966005)(83380400001)(38100700002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?yknIA/RekVhJDR3/ns3Ay/9PRMeX?= =?utf-8?q?kWV+y01u+WRr+LjoSyI5Ue+uGhhWLauwHvZT2YRI6LROAtHnaqdCacgILwK6O3iFk?= =?utf-8?q?NCedJfWW37PXJRrExy3LwMCbTCiKN+br1IbNpu6GXyRfScSHGh8fCi6nVKtwyy6qD?= =?utf-8?q?OFUdhQPUX2R748fnBY41HuS85JBHH533nVFstYasXRVkslB2h4gX6XARO9F5bABwm?= =?utf-8?q?WN3jvbnbuF7ohXY4tuKeK0X6reD40ScCAtYVjptKr/9vihhM32LbWnXema4nr5ZQa?= =?utf-8?q?r+PY2U7CxhMc2A/Zoh/s5JwDPdFENKnYb6JzKWUiqi+BWCjQqEeEG7R9AS0VbKanM?= =?utf-8?q?epdAb+oJyWxMb141owNLZyYIB6EvoZDCXEGva5Xm2WGW/zeJLM+Ku5lI1vKz10e4R?= =?utf-8?q?Vdo0RrLgOd10RQIl3FayEjnlhjbFHmICAxGI6Jp2CmegTvNEzcHzqH6wn9gVAmN+9?= =?utf-8?q?Z/lLzs+LMr5domvWqBOByn0C38xF40Lfa758VCuUvbvyl8lv2ugIVt4/cIzOm+mQX?= =?utf-8?q?o+TBV7HsEpD8Kc+6CouJQF24V2gGfroi+mYsgmxrCNNGQHLcQVHg7q3yHOzWUWYAW?= =?utf-8?q?S+9tLNeX6SoAoNQpE+sKM/4e+d5nCtEc160we7N6HRvmCHsIR7C6oA4bkfEvJeguc?= =?utf-8?q?0R8gOOYiXomntdUgQ9LmdPUk0lvUOfBnAvMWbXBYWwBo7ZZzuWwcAm1nD2Dkcom2t?= =?utf-8?q?bNqdx9VqpLE4Wb8z7K93DZlbzEZZT2JAQMMaDBqXBVzKf46hvyzo2PwG1VP6Xg6XE?= =?utf-8?q?pUizNwIjqr0LEpzXfll6jcoBsNxoORPK2YrFMusJYH4nDsSttxpDuNpP16gP6KXTr?= =?utf-8?q?mKi03ur8KHcr0DUEqf2tqpKJ9gXXTvUOvv7EVSjlLoXYICZt7meFyQpF8dXEmNn+f?= =?utf-8?q?O7ItIL7ahD5/IfJUY9+VlIuHlrtbpGX7pyHlq/uZ6bOgTfY/YnGwOYm0b+9RldR0S?= =?utf-8?q?m3giWBRQPTjkRmuMpZBdutlL1/dYHFxM7oT1ipUk6r3986re1WdgEGCOjpOQoRwfU?= =?utf-8?q?8SXQj0pSnw91l9djG9U+PVkAsPUti0gUAp2LmnlSee1onNm862m1VNXMIZ5ZOdl6X?= =?utf-8?q?HQD4xAPiQcYJCLQRx1M4I55GY/FiJR8HJJ1pifKVU/OfbUG+owhtOn9ZdtOV01ggZ?= =?utf-8?q?NzcfsMGMEExxPIgjHLtGs7nqCns5GYrvDdmMhVZHwMQvdQc5CJ/5kYBy5BkJM05za?= =?utf-8?q?964lDEgkWUrApccWy5HVHTytYlWjZE4btsmhMmf7llpX9vt2NRaiWWC92b4HCMQ7J?= =?utf-8?q?1HseYUrtlpnUGOtieUFxJQgPdgInCTRhLzu4lTTGQDHMlsjZABkbtRN6l5aQXktKU?= =?utf-8?q?k1ylczP4+4StfnC5nRp07n6I2/uScMshbV2PDvFS21QswcRra0nEf4pD0n2dKnQJs?= =?utf-8?q?oejjlcOne0jEfzovs3AVepbMPtqbwAewWvGiefKWrMqpkkK+V6q6NcK9rqEqWUTfz?= =?utf-8?q?eIyaaTFmjLT4RHkCM5I4BSxvqZr5EFbNUvtviesI0bfltatP5CCEKthrRNBwrP4dH?= =?utf-8?q?eT4UbEb0pzIxErRlFRn7sYuZKwcE17rwI8TIMMK3KwbHsQ+WZlMS9EU=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1eadd8e9-0c1a-4f35-3126-08dbefe70cad X-MS-Exchange-CrossTenant-AuthSource: SN4PR01MB7455.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2023 07:53:03.5932 (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: CkUj1KW4UY4MD1YJegZzUY40UghVetA4cYtb5V6sna9uiXItDO1/XREnh5i+YhRfkgAeOL7ilNKIvJlKq17y0N4FJQBldZmugUirGgRLUkE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR01MB7895 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 27 Nov 2023 23:53:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783793486561954573 X-GMAIL-MSGID: 1783793486561954573 |
Series |
i2c: aspeed: Late ack Tx done irqs and fix unhandled Tx done with NAK
|
|
Commit Message
Quan Nguyen
Nov. 28, 2023, 7:52 a.m. UTC
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 <quan@os.amperecomputing.com>
---
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(+)
Comments
On Tue, 2023-11-28 at 14:52 +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 <quan@os.amperecomputing.com> > --- > 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); > + } So we're already (partially) processing this a bit later on line 287: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/i2c/busses/i2c-aspeed.c?h=v6.7-rc3#n287 From the description of the problem in the commit message it sounds like the ordering of the interrupt processing is incorrect. Prior to this patch we have the following abstract ordering of interrupt processing: 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH 2. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED With this patch we have: 1. If ASPEED_I2CD_INTR_SLAVE_MATCH then process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED 2. Process ASPEED_I2CD_INTR_SLAVE_MATCH 3. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED That feels a bit complex and redundant. What I think we can have is: 1. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH Moving back from the abstract to the concrete, implementing what I believe we need would look something like this patch: diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index 28e2a5fc4528..98dd0f35c9d3 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -251,6 +251,14 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) command = readl(bus->base + ASPEED_I2C_CMD_REG); + /* Complete any active read */ + 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); + bus->slave_state = ASPEED_I2C_SLAVE_STOP; + } + /* Slave was requested, restart state machine. */ if (irq_status & ASPEED_I2CD_INTR_SLAVE_MATCH) { irq_handled |= ASPEED_I2CD_INTR_SLAVE_MATCH; @@ -284,11 +292,6 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) 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: Thoughts? I haven't tested it, it's just something to throw darts at. Andrew
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 <quan@os.amperecomputing.com> > --- > 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? Andi > irq_handled |= ASPEED_I2CD_INTR_SLAVE_MATCH; > bus->slave_state = ASPEED_I2C_SLAVE_START; > } > -- > 2.35.1 >
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 <quan@os.amperecomputing.com> >> --- >> 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. Thanks, - Quan
On 29/11/2023 07:19, Andrew Jeffery wrote: > On Tue, 2023-11-28 at 14:52 +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 <quan@os.amperecomputing.com> >> --- >> 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); >> + } > > So we're already (partially) processing this a bit later on line 287: > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/i2c/busses/i2c-aspeed.c?h=v6.7-rc3#n287 > Thanks Andrew for the review. I think it's worth noting that the byte mode is used in this case. About the code you mentioned, it is for the general process of single Slave transmission with NAK which should be interpret as I2C_SLAVE_STOP event. In this case, there is a mix of Slave events: + I2C_SLAVE_STOP (due to INTR_TX_NAK, BIT(1) of previous transaction) + Followed by I2C_SLAVE_[READ|WRITE]_REQUESTED (due to INTR_SLAVE_MATCH and INTR_RX_DONE, BIT(7) and BIT(2), of next transaction) That is the reason we need to emit the I2C_SLAVE_STOP first for Slave backend to process. > From the description of the problem in the commit message it sounds > like the ordering of the interrupt processing is incorrect. Yes, this is correct as per my explanation above. Prior to > this patch we have the following abstract ordering of interrupt > processing: > > 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH > 2. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED > From my test, the flow is as below: 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH, slave_state is set to ASPEED_I2C_SLAVE_START 2. As there is INTR_RX_DONE and slave_state is ASPEED_I2C_SLAVE_START, depends on the data received, the slave_state moves to either ASPEED_I2C_SLAVE_[READ|WRITE]_REQUESTED. 3. When reach to the if statement to process INTR_TX_NAK, slave_state is already moves to either ASPEED_I2C_SLAVE_[READ|WRITE]_REQUESTED, not in ASPEED_I2C_SLAVE_READ_PROCESSED anymore. This eventually evaluate as false and the if statement is bypass. IOW, this INTR_TX_NAK is not process. > With this patch we have: > > 1. If ASPEED_I2CD_INTR_SLAVE_MATCH then process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED > 2. Process ASPEED_I2CD_INTR_SLAVE_MATCH > 3. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED > With this patch: 0. The I2C_SLAVE_STOP is emitted to backend Slave driver first to complete the previous transaction. And let the rest process as before this patch. 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH, slave_state is set to ASPEED_I2C_SLAVE_START 2. As there is INTR_RX_DONE and slave_state is ASPEED_I2C_SLAVE_START, depends on the data received, the slave_state moves to either ASPEED_I2C_SLAVE_[READ|WRITE]_REQUESTED. 3. When reach to the if statement to process INTR_TX_NAK, slave_state is already moves to either ASPEED_I2C_SLAVE_[READ|WRITE]_REQUESTED, not in ASPEED_I2C_SLAVE_READ_PROCESSED anymore. This eventually evaluated as false and the if statement is bypass. IOW, this INTR_TX_NAK is not process. > That feels a bit complex and redundant. What I think we can have is: > > 1. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED > 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH > > Moving back from the abstract to the concrete, implementing what I > believe we need would look something like this patch: > > diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c > index 28e2a5fc4528..98dd0f35c9d3 100644 > --- a/drivers/i2c/busses/i2c-aspeed.c > +++ b/drivers/i2c/busses/i2c-aspeed.c > @@ -251,6 +251,14 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) > > command = readl(bus->base + ASPEED_I2C_CMD_REG); > > + /* Complete any active read */ > + 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); > + bus->slave_state = ASPEED_I2C_SLAVE_STOP; > + } > + It is not confirmed through test yet but I'm afraid the switch case part will emit another I2C_SLAVE_STOP event in case there is no mix of interrupts. > /* Slave was requested, restart state machine. */ > if (irq_status & ASPEED_I2CD_INTR_SLAVE_MATCH) { > irq_handled |= ASPEED_I2CD_INTR_SLAVE_MATCH; > @@ -284,11 +292,6 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) > 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: > > Thoughts? I haven't tested it, it's just something to throw darts at. > > Andrew >
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 <quan@os.amperecomputing.com> > > > --- > > > 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
On Wed, 2023-11-29 at 16:03 +0700, Quan Nguyen wrote: > > On 29/11/2023 07:19, Andrew Jeffery wrote: > > On Tue, 2023-11-28 at 14:52 +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 <quan@os.amperecomputing.com> > > > --- > > > 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); > > > + } > > > > So we're already (partially) processing this a bit later on line 287: > > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/i2c/busses/i2c-aspeed.c?h=v6.7-rc3#n287 > > > > Thanks Andrew for the review. > > I think it's worth noting that the byte mode is used in this case. > > About the code you mentioned, it is for the general process of single > Slave transmission with NAK which should be interpret as I2C_SLAVE_STOP > event. > > In this case, there is a mix of Slave events: > > + I2C_SLAVE_STOP (due to INTR_TX_NAK, BIT(1) of previous transaction) > + Followed by I2C_SLAVE_[READ|WRITE]_REQUESTED (due to > INTR_SLAVE_MATCH and INTR_RX_DONE, BIT(7) and BIT(2), of next transaction) > > That is the reason we need to emit the I2C_SLAVE_STOP first for Slave > backend to process. > > > From the description of the problem in the commit message it sounds > > like the ordering of the interrupt processing is incorrect. > > Yes, this is correct as per my explanation above. > > Prior to > > this patch we have the following abstract ordering of interrupt > > processing: > > > > 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH > > 2. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED > > > > From my test, the flow is as below: > > 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH, slave_state is set to > ASPEED_I2C_SLAVE_START > 2. As there is INTR_RX_DONE and slave_state is > ASPEED_I2C_SLAVE_START, depends on the data received, the slave_state > moves to either ASPEED_I2C_SLAVE_[READ|WRITE]_REQUESTED. > 3. When reach to the if statement to process INTR_TX_NAK, slave_state > is already moves to either ASPEED_I2C_SLAVE_[READ|WRITE]_REQUESTED, not > in ASPEED_I2C_SLAVE_READ_PROCESSED anymore. This eventually evaluate as > false and the if statement is bypass. IOW, this INTR_TX_NAK is not process. > > > With this patch we have: > > > > 1. If ASPEED_I2CD_INTR_SLAVE_MATCH then process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED > > 2. Process ASPEED_I2CD_INTR_SLAVE_MATCH > > 3. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED > > > > With this patch: > > 0. The I2C_SLAVE_STOP is emitted to backend Slave driver first to > complete the previous transaction. And let the rest process as before > this patch. > > 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH, slave_state is set to > ASPEED_I2C_SLAVE_START > 2. As there is INTR_RX_DONE and slave_state is > ASPEED_I2C_SLAVE_START, depends on the data received, the slave_state > moves to either ASPEED_I2C_SLAVE_[READ|WRITE]_REQUESTED. > 3. When reach to the if statement to process INTR_TX_NAK, slave_state > is already moves to either ASPEED_I2C_SLAVE_[READ|WRITE]_REQUESTED, not > in ASPEED_I2C_SLAVE_READ_PROCESSED anymore. This eventually evaluated as > false and the if statement is bypass. IOW, this INTR_TX_NAK is not process. > > > That feels a bit complex and redundant. What I think we can have is: > > > > 1. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED > > 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH > > > > Moving back from the abstract to the concrete, implementing what I > > believe we need would look something like this patch: > > > > diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c > > index 28e2a5fc4528..98dd0f35c9d3 100644 > > --- a/drivers/i2c/busses/i2c-aspeed.c > > +++ b/drivers/i2c/busses/i2c-aspeed.c > > @@ -251,6 +251,14 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) > > > > command = readl(bus->base + ASPEED_I2C_CMD_REG); > > > > + /* Complete any active read */ > > + 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); > > + bus->slave_state = ASPEED_I2C_SLAVE_STOP; > > + } > > + > > It is not confirmed through test yet but I'm afraid the switch case part > will emit another I2C_SLAVE_STOP event in case there is no mix of > interrupts. Ah, good catch. I think we can rework things a bit to rationalise the logic at the expense a bigger diff. What do you think about this? I've boot tested it on an ast2600-evb and poked at some NVMe drives over MCTP to exercise the slave path. diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index aec8966bceab..3c9333a12967 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -249,18 +249,47 @@ 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 +308,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 +342,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. */;
On 30/11/2023 08:20, Andrew Jeffery wrote: > On Wed, 2023-11-29 at 16:03 +0700, Quan Nguyen wrote: >> >> On 29/11/2023 07:19, Andrew Jeffery wrote: >>> On Tue, 2023-11-28 at 14:52 +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 <quan@os.amperecomputing.com> >>>> --- >>>> 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); >>>> + } >>> >>> So we're already (partially) processing this a bit later on line 287: >>> >>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/i2c/busses/i2c-aspeed.c?h=v6.7-rc3#n287 >>> >> >> Thanks Andrew for the review. >> >> I think it's worth noting that the byte mode is used in this case. >> >> About the code you mentioned, it is for the general process of single >> Slave transmission with NAK which should be interpret as I2C_SLAVE_STOP >> event. >> >> In this case, there is a mix of Slave events: >> >> + I2C_SLAVE_STOP (due to INTR_TX_NAK, BIT(1) of previous transaction) >> + Followed by I2C_SLAVE_[READ|WRITE]_REQUESTED (due to >> INTR_SLAVE_MATCH and INTR_RX_DONE, BIT(7) and BIT(2), of next transaction) >> >> That is the reason we need to emit the I2C_SLAVE_STOP first for Slave >> backend to process. >> >>> From the description of the problem in the commit message it sounds >>> like the ordering of the interrupt processing is incorrect. >> >> Yes, this is correct as per my explanation above. >> >> Prior to >>> this patch we have the following abstract ordering of interrupt >>> processing: >>> >>> 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH >>> 2. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED >>> >> >> From my test, the flow is as below: >> >> 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH, slave_state is set to >> ASPEED_I2C_SLAVE_START >> 2. As there is INTR_RX_DONE and slave_state is >> ASPEED_I2C_SLAVE_START, depends on the data received, the slave_state >> moves to either ASPEED_I2C_SLAVE_[READ|WRITE]_REQUESTED. >> 3. When reach to the if statement to process INTR_TX_NAK, slave_state >> is already moves to either ASPEED_I2C_SLAVE_[READ|WRITE]_REQUESTED, not >> in ASPEED_I2C_SLAVE_READ_PROCESSED anymore. This eventually evaluate as >> false and the if statement is bypass. IOW, this INTR_TX_NAK is not process. >> >>> With this patch we have: >>> >>> 1. If ASPEED_I2CD_INTR_SLAVE_MATCH then process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED >>> 2. Process ASPEED_I2CD_INTR_SLAVE_MATCH >>> 3. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED >>> >> >> With this patch: >> >> 0. The I2C_SLAVE_STOP is emitted to backend Slave driver first to >> complete the previous transaction. And let the rest process as before >> this patch. >> >> 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH, slave_state is set to >> ASPEED_I2C_SLAVE_START >> 2. As there is INTR_RX_DONE and slave_state is >> ASPEED_I2C_SLAVE_START, depends on the data received, the slave_state >> moves to either ASPEED_I2C_SLAVE_[READ|WRITE]_REQUESTED. >> 3. When reach to the if statement to process INTR_TX_NAK, slave_state >> is already moves to either ASPEED_I2C_SLAVE_[READ|WRITE]_REQUESTED, not >> in ASPEED_I2C_SLAVE_READ_PROCESSED anymore. This eventually evaluated as >> false and the if statement is bypass. IOW, this INTR_TX_NAK is not process. >> >>> That feels a bit complex and redundant. What I think we can have is: >>> >>> 1. Process ASPEED_I2CD_INTR_TX_NAK when in ASPEED_I2C_SLAVE_READ_PROCESSED >>> 1. Process ASPEED_I2CD_INTR_SLAVE_MATCH >>> >>> Moving back from the abstract to the concrete, implementing what I >>> believe we need would look something like this patch: >>> >>> diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c >>> index 28e2a5fc4528..98dd0f35c9d3 100644 >>> --- a/drivers/i2c/busses/i2c-aspeed.c >>> +++ b/drivers/i2c/busses/i2c-aspeed.c >>> @@ -251,6 +251,14 @@ static u32 aspeed_i2c_slave_irq(struct aspeed_i2c_bus *bus, u32 irq_status) >>> >>> command = readl(bus->base + ASPEED_I2C_CMD_REG); >>> >>> + /* Complete any active read */ >>> + 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); >>> + bus->slave_state = ASPEED_I2C_SLAVE_STOP; >>> + } >>> + >> >> It is not confirmed through test yet but I'm afraid the switch case part >> will emit another I2C_SLAVE_STOP event in case there is no mix of >> interrupts. > > Ah, good catch. I think we can rework things a bit to rationalise the > logic at the expense a bigger diff. What do you think about this? I've > boot tested it on an ast2600-evb and poked at some NVMe drives over > MCTP to exercise the slave path. > > diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c > index aec8966bceab..3c9333a12967 100644 > --- a/drivers/i2c/busses/i2c-aspeed.c > +++ b/drivers/i2c/busses/i2c-aspeed.c > @@ -249,18 +249,47 @@ 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 +308,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 +342,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. */; Yes, this looks much better. I'll confirm these changes through test and will post the next version ASAP. Thanks a lot for the review, - Quan
On 30/11/2023 04:25, Andi Shyti wrote: > 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 <quan@os.amperecomputing.com> >>>> --- >>>> 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. > I think Andrew's idea to handle the STOP conditions prior is much better. Will test and post the next version ASAP. Thanks a lot for the review - Quan
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); + } irq_handled |= ASPEED_I2CD_INTR_SLAVE_MATCH; bus->slave_state = ASPEED_I2C_SLAVE_START; }