Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp2220671rdb; Sun, 21 Jan 2024 12:43:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4e/3b1kT19wZqS5aumYh6DjzttfKuHhYBXu/lnqmNPfrAXc9u+qLPtKzs95OJETgMGurt X-Received: by 2002:a05:6a20:72ac:b0:19a:5b89:9d63 with SMTP id o44-20020a056a2072ac00b0019a5b899d63mr4454944pzk.12.1705869786211; Sun, 21 Jan 2024 12:43:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705869786; cv=pass; d=google.com; s=arc-20160816; b=JGUnx89y47iR5l0iZOMG+QOOnZIoIur3UC07jWsnRpJk1ByfE8aVgnp4lYQLvTrbtF G3Zy52r5xHeqhY8+eP7jcor0hTBRooK166Doyb4Vg1dnqV7F2mitiELcthMuwKlR5K+G X8pD0QbOjqqykV2qrRAlQkSodqmh9pvNxJp3m+ukXbMhhd4p5zAwZDFmIKVjh4xUw+jp H7MYwF7EZX3iPT6mdUdUcKoBxIPuoulsFFic+uYxEprB6JKbiP4/03QKW9oFhdBp0HJb QLC50xU5b7/ail1a+AXquPnNGZSvfa7QSa8yaA8mTlyKzVvp/BD+hbXPesY/yUNA1C5Y oWIA== 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:references:in-reply-to:message-id :date:subject:cc:to:from; bh=ZDe4kT0T8F8xW4OPnFpJR2v+A5R3rXWgSSz3Zs6BlpM=; fh=PBT+T+L/Wk7fQyAuF/ivTwxWqTQzcP6BniPDJctp9Xs=; b=xqFGrcxMMYUgErTSAuNaxe6Nk3TvHiWk7NHIUa0lh64XNGwU0y6NefYr5cE9psy4hA cB4J969UY0Vd4m6GZAdSv0VghX3XCnwSADDrLueu51Y1IUbZqTobXDMPfMv7ijJAcNdk f2TT+ZrKysiVk11JtlZSaXRlNGm+6fTrpN9QtVuEeenR+E6k8z1dWsdyqKaS5YEvpSsj mSeuZWsCZKz+VFzLbVU6lfN+l0Ybq0LW4mctdYOjxwOLPCOZqmj55yR8uIESehMdsSGC 63/vA6z5KpoDFTlly7WqD1Bc7zmr2VtFbCmYD5rWKih3Xc2ZbypyiFw39/p+tc3IxJWw YUzQ== 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-32186-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32186-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id be3-20020a056a001f0300b006dab31aaa24si9511282pfb.138.2024.01.21.12.43.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 12:43:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32186-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=c--e.de); spf=pass (google.com: domain of linux-kernel+bounces-32186-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32186-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A1EB4B216D9 for ; Sun, 21 Jan 2024 20:42:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3CA2D38FB2; Sun, 21 Jan 2024 20:41:48 +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 A483A38FA1; Sun, 21 Jan 2024 20:41:45 +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=1705869707; cv=none; b=e662Hui0FwNxfKjHRcrpfvy8Mn2iv3WrNw6i4Dfue/XsWu6gZqJUxPVh0QN8sQ+3LyBq6VSk9Y27Mrv8o4eiUVRSE+94TwPKVj+iK6jlygZbLuHHgS8v/yeP6aWMYJnLUI1GNhLx0k4+1VWgnLcVeGh4EYpgeFJod9lHQJFPZ3M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705869707; c=relaxed/simple; bh=YPimAc9/op1FgIOJZ7Xs+meT1zX8exfGnSTp7c1KsRE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ji00rhKEhw0dlbS9xniSL2cy6u0tgJs8KGzsp4A7OwI0yd39bWxjDwxvxIHQwKqNTYlPWGdZ1ErfenFV6MRCjg/mG6+uFyKHrWl8GWg/JmZHblWztgrbGPZSav58ixrARUGuQfmrjv0y0uMESI7H3JpkYmoOFWGZd977OtxNpVI= 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 E29B11402D8; Sun, 21 Jan 2024 21:41:44 +0100 (CET) From: "Christian A. Ehrhardt" To: Heikki Krogerus , linux-usb@vger.kernel.org Cc: "Christian A. Ehrhardt" , Dell.Client.Kernel@dell.com, Greg Kroah-Hartman , Neil Armstrong , Hans de Goede , Jack Pham , Fabrice Gasnier , =?UTF-8?q?Samuel=20=C4=8Cavoj?= , linux-kernel@vger.kernel.org Subject: [PATCH v3 2/3] usb: ucsi_acpi: Fix command completion handling Date: Sun, 21 Jan 2024 21:41:22 +0100 Message-Id: <20240121204123.275441-3-lk@c--e.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240121204123.275441-1-lk@c--e.de> References: <20240121204123.275441-1-lk@c--e.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In case of a spurious or otherwise delayed notification it is possible that CCI still reports the previous completion. The UCSI spec is aware of this and provides two completion bits in CCI, one for normal commands and one for acks. As acks and commands alternate the notification handler can determine if the completion bit is from the current command. The initial UCSI code correctly handled this but the distinction between the two completion bits was lost with the introduction of the new API. To fix this revive the ACK_PENDING bit for ucsi_acpi and only complete commands if the completion bit matches. Fixes: f56de278e8ec ("usb: typec: ucsi: acpi: Move to the new API") Cc: stable@vger.kernel.org Signed-off-by: Christian A. Ehrhardt --- drivers/usb/typec/ucsi/ucsi_acpi.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c index 6bbf490ac401..fa222080887d 100644 --- a/drivers/usb/typec/ucsi/ucsi_acpi.c +++ b/drivers/usb/typec/ucsi/ucsi_acpi.c @@ -73,9 +73,13 @@ static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset, const void *val, size_t val_len) { struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); + bool ack = UCSI_COMMAND(*(u64 *)val) == UCSI_ACK_CC_CI; int ret; - set_bit(COMMAND_PENDING, &ua->flags); + if (ack) + set_bit(ACK_PENDING, &ua->flags); + else + set_bit(COMMAND_PENDING, &ua->flags); ret = ucsi_acpi_async_write(ucsi, offset, val, val_len); if (ret) @@ -85,7 +89,10 @@ static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset, ret = -ETIMEDOUT; out_clear_bit: - clear_bit(COMMAND_PENDING, &ua->flags); + if (ack) + clear_bit(ACK_PENDING, &ua->flags); + else + clear_bit(COMMAND_PENDING, &ua->flags); return ret; } @@ -142,8 +149,10 @@ static void ucsi_acpi_notify(acpi_handle handle, u32 event, void *data) if (UCSI_CCI_CONNECTOR(cci)) ucsi_connector_change(ua->ucsi, UCSI_CCI_CONNECTOR(cci)); - if (test_bit(COMMAND_PENDING, &ua->flags) && - cci & (UCSI_CCI_ACK_COMPLETE | UCSI_CCI_COMMAND_COMPLETE)) + if (cci & UCSI_CCI_ACK_COMPLETE && test_bit(ACK_PENDING, &ua->flags)) + complete(&ua->complete); + if (cci & UCSI_CCI_COMMAND_COMPLETE && + test_bit(COMMAND_PENDING, &ua->flags)) complete(&ua->complete); } -- 2.40.1