Message ID | 20240215101024.764444-1-lk@c--e.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-66617-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp296783dyb; Thu, 15 Feb 2024 02:21:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX4TSGOb/dMtiGUIAI8yM4CVNdwu9GD5iqJA9Cnj8giu3TtLQeZ/MWsl1VAwJOmbIVPrUbl7VEBOdvN0e809teC20nTWw== X-Google-Smtp-Source: AGHT+IHkNN4RNJ/It+27CjyfSVW4mNTHWKvCc8dQ8hWXYSjtHAjJpimqkbOVgeF02wdFEhMLvkP0 X-Received: by 2002:a17:907:940f:b0:a3c:c13f:a1d9 with SMTP id dk15-20020a170907940f00b00a3cc13fa1d9mr4829298ejc.38.1707992464847; Thu, 15 Feb 2024 02:21:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707992464; cv=pass; d=google.com; s=arc-20160816; b=LFMSDlQbokiRUzDBh9K4YUGrLP5Eg3fmLsPZQhE/AgFoKdkPID4e83bRF16j9gVpE1 HWjJ2T+Krz/PBKlVg+pTwZDDfnQKc3hGjyFQ0Di0JK3IwHmvVf0glY8urAVNrxg3zN3i P0hutp9ttYSo7rLQBzmtKEHJ8s1plbnsRfGD3Oj0QbQqh5m0EPdjGo9Hp459kBSTtUJ+ 18EHe0mjfasubFi+2Eecjm8sHBg+5UCuwMtH4rSy+0CryYoltlTPP3SRtCSlqNrJ70c/ IypzK6VbWGL9OYwgC4enZaqRnlUREeDMlOsE1sT+yZS8QRYaHuqEoYtAmcgPxDRNrnsd WW2w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=ZCmPvMMiRL9TElpGnnBLo1GUthfCiDQl1g0yx5fZ0Xw=; fh=8pZ8PJyvQWCvNtM/zO9VFPtXOG46kzJdft20at4jgjE=; b=aQ/CzjH7p6jhRi2bMNi9ufOTr2AuLWfWLNBtGblvIz5lvWxfrOemgRWy6jvj8CbU/d K+T7O5sg2XIOjMoE9olfoE6nGOsMmvmFu6ymJdkxxy+XIozYX+WC2/oZDlOUdZS9YR+m CtWu/5teyisxx8I+EAr+IalkSvoXqQYqLLde+Bgbe3sduZy8xFkkgDgiIXLb3R+FK0cS VUXW5YZ2qfixColizArWn8pWb+5qw7GdPDd8xLUCYHhJ1lHVay6ro4/xv1XRVgB927Fq glwvvMg3/7TjgeK4ADLUoP+6EdoUZOTRezg8b374a8CnZRS54LV99GIwaXVIfqkuUi9j FSmw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=c--e.de); spf=pass (google.com: domain of linux-kernel+bounces-66617-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66617-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e9-20020a170906248900b00a3d67d6786csi537451ejb.183.2024.02.15.02.21.04 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 02:21:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66617-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=c--e.de); spf=pass (google.com: domain of linux-kernel+bounces-66617-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66617-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 599251F2180E for <ouuuleilei@gmail.com>; Thu, 15 Feb 2024 10:21:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0014A69D18; Thu, 15 Feb 2024 10:20:42 +0000 (UTC) Received: from cae.in-ulm.de (cae.in-ulm.de [217.10.14.231]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1609A69D01; Thu, 15 Feb 2024 10:20:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.10.14.231 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707992441; cv=none; b=l72mBWus2NGu0JRJzPvhDlwOGbXnlQnlx40wd0umcUUBDsvlntEfzAzs3JP5MKAubJlBQynrxLZ7wZOTrKnbz1WNZexL3RArArZwlCUfHA+cXw8jElwIKUYDEetPDU11sDOHNbaXxc2wXHi+AKzsogJPHrAjc+lz+siRTC4tT6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707992441; c=relaxed/simple; bh=MNzjTQVy8i+SjCyYirVZZm1jgkX/BUR/FaONBXox8oA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=dk/YR2Bj/CD+KLZ0FMVdpGEiYYxpljC7KUcpVSB4doMsD6s4aYDK6uSgUsvNYkqL2wagRTiJDZlYhhqHam27tJ25AJ4ZXFfcV+X282rJTc4rtG2GvpRGTPuHFppkNBhfOM0O6dxjj5zCSre2aZe/cifjQsoGZpu2s6gEp8rhi2s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=c--e.de; spf=pass smtp.mailfrom=c--e.de; arc=none smtp.client-ip=217.10.14.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=c--e.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=c--e.de Received: by cae.in-ulm.de (Postfix, from userid 1000) id 1F8F61402E9; Thu, 15 Feb 2024 11:10:41 +0100 (CET) From: "Christian A. Ehrhardt" <lk@c--e.de> To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Christian A. Ehrhardt" <lk@c--e.de>, Heikki Krogerus <heikki.krogerus@linux.intel.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Andy Shevchenko <andriy.shevchenko@linux.intel.com>, =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= <u.kleine-koenig@pengutronix.de>, Sing-Han Chen <singhanc@nvidia.com>, Haotien Hsu <haotienh@nvidia.com>, Utkarsh Patel <utkarsh.h.patel@intel.com>, "Jonathan Hunter" <jonathanh@nvidia.com>, "Wayne Chang" <waynec@nvidia.com>, "WK Tsai" <wtsai@nvidia.com> Subject: [PATCH CFT] usb: ucsi_ccg: Fix command completion handling Date: Thu, 15 Feb 2024 11:10:24 +0100 Message-Id: <20240215101024.764444-1-lk@c--e.de> X-Mailer: git-send-email 2.30.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790959906435749655 X-GMAIL-MSGID: 1790959906435749655 |
Series |
[CFT] usb: ucsi_ccg: Fix command completion handling
|
|
Commit Message
Christian A. Ehrhardt
Feb. 15, 2024, 10:10 a.m. UTC
In case of a spurious or otherwise delayed interrupt
it is possible that CCI still reports the previous completion.
For this reason the UCSI spec provides different completion
bits for normal commands and for UCSI_ACK_CC_CI.
Only complete a sync command if the correct completion bit
is set.
This should avoid the need to clear out CCI before starting
a command. Thus remove this code.
Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
Fixes: e32fd989ac1c ("usb: typec: ucsi: ccg: Move to the new API")
---
Additional information:
A similar change for ucsi_acpi.c is here:
https://lore.kernel.org/all/20240121204123.275441-3-lk@c--e.de/
This restores behaviour that ucsi.c had before moving to the new API.
I've seen timeouts with ucsi_acpi.c without that fix, often if there
were many port events (plug/unplug).
I do _not_ have CCG hardware to test this. So someone else will have to
provide a Tested-By tag or similar (hence the CFT in the subject).
But from looking at the code I think this change is needed for CCG,
too. Additionally, the recent change to CCG here
https://lore.kernel.org/all/20240126030115.3791554-1-haotienh@nvidia.com/
seems to work around the same problem.
Clearing the cached CCI value should not be necessary with this
anymore and I suspect that it can potentially cause other problems.
However, I can send an update patch without this hunk if desired.
drivers/usb/typec/ucsi/ucsi_ccg.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
Comments
On Thu, Feb 15, 2024 at 11:10:24AM +0100, Christian A. Ehrhardt wrote: > In case of a spurious or otherwise delayed interrupt > it is possible that CCI still reports the previous completion. > For this reason the UCSI spec provides different completion > bits for normal commands and for UCSI_ACK_CC_CI. > > Only complete a sync command if the correct completion bit > is set. > > This should avoid the need to clear out CCI before starting > a command. Thus remove this code. > > Signed-off-by: Christian A. Ehrhardt <lk@c--e.de> > Fixes: e32fd989ac1c ("usb: typec: ucsi: ccg: Move to the new API") What does "CFT" in your subject line mean? thanks, greg k-h
Hi Greg, On Thu, Feb 15, 2024 at 12:07:20PM +0100, Greg Kroah-Hartman wrote: > On Thu, Feb 15, 2024 at 11:10:24AM +0100, Christian A. Ehrhardt wrote: > > In case of a spurious or otherwise delayed interrupt > > it is possible that CCI still reports the previous completion. > > For this reason the UCSI spec provides different completion > > bits for normal commands and for UCSI_ACK_CC_CI. > > > > Only complete a sync command if the correct completion bit > > is set. > > > > This should avoid the need to clear out CCI before starting > > a command. Thus remove this code. > > > > Signed-off-by: Christian A. Ehrhardt <lk@c--e.de> > > Fixes: e32fd989ac1c ("usb: typec: ucsi: ccg: Move to the new API") > > What does "CFT" in your subject line mean? It's supposed to mean "Call For Testers". More info in the "Additional Information" section of the original mail. I think the change is necessary and good but I do not have the HW to test it. I did test a similar change for ucsi_acpi.c that got merged and this is the ping for ucsi_ccg.c people that they probably need this, too. regards Christian
On 2/15/24 20:03, Christian A. Ehrhardt wrote: > External email: Use caution opening links or attachments > > > Hi Greg, > > On Thu, Feb 15, 2024 at 12:07:20PM +0100, Greg Kroah-Hartman wrote: >> On Thu, Feb 15, 2024 at 11:10:24AM +0100, Christian A. Ehrhardt wrote: >>> In case of a spurious or otherwise delayed interrupt >>> it is possible that CCI still reports the previous completion. >>> For this reason the UCSI spec provides different completion >>> bits for normal commands and for UCSI_ACK_CC_CI. >>> >>> Only complete a sync command if the correct completion bit >>> is set. >>> >>> This should avoid the need to clear out CCI before starting >>> a command. Thus remove this code. >>> >>> Signed-off-by: Christian A. Ehrhardt <lk@c--e.de> >>> Fixes: e32fd989ac1c ("usb: typec: ucsi: ccg: Move to the new API") >> >> What does "CFT" in your subject line mean? > > It's supposed to mean "Call For Testers". More info in the > "Additional Information" section of the original mail. > > I think the change is necessary and good but I do not have the HW > to test it. > > I did test a similar change for ucsi_acpi.c that got merged and this > is the ping for ucsi_ccg.c people that they probably need this, too. > > regards Christian > > Hi Christian, If we don't clean the CCI cache in ucsi_ccg_async_write(), there might be a potential problem when the driver is polling the results. In ucsi_init(), we may get EPROBE_DEFER from ucsi_register_port(). Then it does ucsi_reset_ppm() before returning the error code, and we will get UCSI_CCI_RESET_COMPLETE and store it in the CCI cache. If we don't clean the cache, when the UCSI driver calls ucsi_init() again, then in ucsi_reset_ppm(), it will get UCSI_CCI_RESET_COMPLETE from the CCI cache instantly. Then the driver will run the next UCSI commands when the HW is not completely reset. Regards, Haotien
Hi Haotien, On Thu, Feb 29, 2024 at 07:18:44AM +0000, HaoTien Hsu wrote: > On 2/15/24 20:03, Christian A. Ehrhardt wrote: > > External email: Use caution opening links or attachments > > > > > > Hi Greg, > > > > On Thu, Feb 15, 2024 at 12:07:20PM +0100, Greg Kroah-Hartman wrote: > >> On Thu, Feb 15, 2024 at 11:10:24AM +0100, Christian A. Ehrhardt wrote: > >>> In case of a spurious or otherwise delayed interrupt > >>> it is possible that CCI still reports the previous completion. > >>> For this reason the UCSI spec provides different completion > >>> bits for normal commands and for UCSI_ACK_CC_CI. > >>> > >>> Only complete a sync command if the correct completion bit > >>> is set. > >>> > >>> This should avoid the need to clear out CCI before starting > >>> a command. Thus remove this code. > >>> > >>> Signed-off-by: Christian A. Ehrhardt <lk@c--e.de> > >>> Fixes: e32fd989ac1c ("usb: typec: ucsi: ccg: Move to the new API") > >> > >> What does "CFT" in your subject line mean? > > > > It's supposed to mean "Call For Testers". More info in the > > "Additional Information" section of the original mail. > > > > I think the change is necessary and good but I do not have the HW > > to test it. > > > > I did test a similar change for ucsi_acpi.c that got merged and this > > is the ping for ucsi_ccg.c people that they probably need this, too. > > > > regards Christian > > > > > > Hi Christian, > > If we don't clean the CCI cache in ucsi_ccg_async_write(), there might > be a potential problem when the driver is polling the results. > > In ucsi_init(), we may get EPROBE_DEFER from ucsi_register_port(). > Then it does ucsi_reset_ppm() before returning the error code, and we > will get UCSI_CCI_RESET_COMPLETE and store it in the CCI cache. > If we don't clean the cache, when the UCSI driver calls ucsi_init() > again, then in ucsi_reset_ppm(), it will get UCSI_CCI_RESET_COMPLETE > from the CCI cache instantly. > Then the driver will run the next UCSI commands when the HW is not > completely reset. Thanks, I indeed did not think the reset case completely through. However, the real bugfix is in the other hunk of the diff and this is a genuine bugfix on its own. I found that the corresponding diff was neccessary for ucsi_acpi.c. Should I resend without the CCI cleaning? Thanks Christian
diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index dda7c7c94e08..9442307e0abd 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -616,14 +616,6 @@ static int ucsi_ccg_async_write(struct ucsi *ucsi, unsigned int offset, struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(offset); - /* - * UCSI may read CCI instantly after async_write, - * clear CCI to avoid caller getting wrong data before we get CCI from ISR - */ - spin_lock(&uc->op_lock); - uc->op_data.cci = 0; - spin_unlock(&uc->op_lock); - return ccg_write(uc, reg, val, val_len); } @@ -708,9 +700,14 @@ static irqreturn_t ccg_irq_handler(int irq, void *data) err_clear_irq: ccg_write(uc, CCGX_RAB_INTR_REG, &intr_reg, sizeof(intr_reg)); - if (!ret && test_bit(DEV_CMD_PENDING, &uc->flags) && - cci & (UCSI_CCI_ACK_COMPLETE | UCSI_CCI_COMMAND_COMPLETE)) - complete(&uc->complete); + if (!ret && test_bit(DEV_CMD_PENDING, &uc->flags)) { + bool ack = UCSI_COMMAND(uc->last_cmd_sent) == UCSI_ACK_CC_CI; + + if (ack && (cci & UCSI_CCI_ACK_COMPLETE)) + complete(&uc->complete); + if (!ack && (cci & UCSI_CCI_COMMAND_COMPLETE)) + complete(&uc->complete); + } return IRQ_HANDLED; }