Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp823074pxb; Tue, 3 Nov 2020 13:33:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJweP/AtihLRQJdg/Cmh6OM/jhFmg6w/EJ/+tprOQDV7wDHJFLf9cMbu5RiZeEjcrrcSSsiS X-Received: by 2002:a17:906:e15:: with SMTP id l21mr23070852eji.509.1604439200364; Tue, 03 Nov 2020 13:33:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604439200; cv=none; d=google.com; s=arc-20160816; b=fV9M1N4qcQ1LJhLc1sdAjF3pDpgkBQ0xgEPllRAAfDk8OkkayVEbFU/0veehMU2PiT csNSihzGEpm9kyRkEb4wCuyj80HPIHM51kUO3iP8f5Cf8nUdHLZnP0xQZojiKd/415fV kF7S3bbpWKdLth/5UEAA8FiNYtCbRXqHmUjwsxSdKeitGuR3I73rn8pEZIhI57PgAhl6 jLiA5gmj/hna/lz1aTfvk697v9VpDB02jX6tt6uyFHbwm8gRor1ytDl8kJooLIxuEsTJ R3RKRAOfkqdwT4qBtYrReHUyLPutzEUdvP+cCMRP8oiVhxqKDizaZPKt11G7vchf3uoa MYdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MAS6FYTBlIuKJH4/4QEwRzm/bXkzekvKmPMmoxpSfwc=; b=nQXORWWhNvZWsf9GKYhO0Ee4OvWiiLnck36LhLWOCUtvHcBAvGOeW950vl5sffHhXp dTAy3P3KBNTe5DySjQbBMUNOdpOk1FbRklHWQyytXKB1k9/KOEsjJWVl43rMDHRb3buq ArCa9Lw84b8wV/VoZ8mchZd58p0Pf9w9C+Rtm8z/cbXtFAXSRNU2U6BHcIY0nSiZVB4g fk3LA5Ospw3vP7tkQlexsOErp7nIIudEAlupPS1PyrVj9nWCKMRmYHbhs8LGvwqgj9Zv eITxglZ2ryTpeYrSajq8geStS5NGJgJVlPYFdlpXhHwY3MGIJcV13rF7zUzd+YBl7MNw 0EGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=E8VaIc2M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si78721ejk.285.2020.11.03.13.32.57; Tue, 03 Nov 2020 13:33:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=E8VaIc2M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732649AbgKCU6R (ORCPT + 99 others); Tue, 3 Nov 2020 15:58:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:60836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731481AbgKCU6N (ORCPT ); Tue, 3 Nov 2020 15:58:13 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BC970223AC; Tue, 3 Nov 2020 20:58:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437093; bh=qhi/UtLTa2aNYfQHiw68kb15TXUKniiWSA24K2ICBik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E8VaIc2MocLgPEBqpCf/dxZpESafo6aJsIPlrcGmy7/WJqP8HKuEa5i4WdKgVo80a JCajBs1eKQQQQnlJGMklONDYFf/moXNMN/Fa1hYD+vgviyZ6GmQkuGHHF5rnM+FHsa OSa5VrH+1P4tEYfX20yBbbOjoSuachlHdRRV+4Gk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guenter Roeck , Heikki Krogerus , Li Jun , ChiYuan Huang Subject: [PATCH 5.4 142/214] usb: typec: tcpm: reset hard_reset_count for any disconnect Date: Tue, 3 Nov 2020 21:36:30 +0100 Message-Id: <20201103203304.127703625@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Li Jun commit 2d9c6442a9c81f4f8dee678d0b3c183173ab1e2d upstream. Current tcpm_detach() only reset hard_reset_count if port->attached is true, this may cause this counter clear is missed if the CC disconnect event is generated after tcpm_port_reset() is done by other events, e.g. VBUS off comes first before CC disconect for a power sink, in that case the first tcpm_detach() will only clear port->attached flag but leave hard_reset_count there because tcpm_port_is_disconnected() is still false, then later tcpm_detach() by CC disconnect will directly return due to port->attached is cleared, finally this will result tcpm will not try hard reset or error recovery for later attach. ChiYuan reported this issue on his platform with below tcpm trace: After power sink session setup after hard reset 2 times, detach from the power source and then attach: [ 4848.046358] VBUS off [ 4848.046384] state change SNK_READY -> SNK_UNATTACHED [ 4848.050908] Setting voltage/current limit 0 mV 0 mA [ 4848.050936] polarity 0 [ 4848.052593] Requesting mux state 0, usb-role 0, orientation 0 [ 4848.053222] Start toggling [ 4848.086500] state change SNK_UNATTACHED -> TOGGLING [ 4848.089983] CC1: 0 -> 0, CC2: 3 -> 3 [state TOGGLING, polarity 0, connected] [ 4848.089993] state change TOGGLING -> SNK_ATTACH_WAIT [ 4848.090031] pending state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED @200 ms [ 4848.141162] CC1: 0 -> 0, CC2: 3 -> 0 [state SNK_ATTACH_WAIT, polarity 0, disconnected] [ 4848.141170] state change SNK_ATTACH_WAIT -> SNK_ATTACH_WAIT [ 4848.141184] pending state change SNK_ATTACH_WAIT -> SNK_UNATTACHED @20 ms [ 4848.163156] state change SNK_ATTACH_WAIT -> SNK_UNATTACHED [delayed 20 ms] [ 4848.163162] Start toggling [ 4848.216918] CC1: 0 -> 0, CC2: 0 -> 3 [state TOGGLING, polarity 0, connected] [ 4848.216954] state change TOGGLING -> SNK_ATTACH_WAIT [ 4848.217080] pending state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED @200 ms [ 4848.231771] CC1: 0 -> 0, CC2: 3 -> 0 [state SNK_ATTACH_WAIT, polarity 0, disconnected] [ 4848.231800] state change SNK_ATTACH_WAIT -> SNK_ATTACH_WAIT [ 4848.231857] pending state change SNK_ATTACH_WAIT -> SNK_UNATTACHED @20 ms [ 4848.256022] state change SNK_ATTACH_WAIT -> SNK_UNATTACHED [delayed20 ms] [ 4848.256049] Start toggling [ 4848.871148] VBUS on [ 4848.885324] CC1: 0 -> 0, CC2: 0 -> 3 [state TOGGLING, polarity 0, connected] [ 4848.885372] state change TOGGLING -> SNK_ATTACH_WAIT [ 4848.885548] pending state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED @200 ms [ 4849.088240] state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED [delayed200 ms] [ 4849.088284] state change SNK_DEBOUNCED -> SNK_ATTACHED [ 4849.088291] polarity 1 [ 4849.088769] Requesting mux state 1, usb-role 2, orientation 2 [ 4849.088895] state change SNK_ATTACHED -> SNK_STARTUP [ 4849.088907] state change SNK_STARTUP -> SNK_DISCOVERY [ 4849.088915] Setting voltage/current limit 5000 mV 0 mA [ 4849.088927] vbus=0 charge:=1 [ 4849.090505] state change SNK_DISCOVERY -> SNK_WAIT_CAPABILITIES [ 4849.090828] pending state change SNK_WAIT_CAPABILITIES -> SNK_READY @240 ms [ 4849.335878] state change SNK_WAIT_CAPABILITIES -> SNK_READY [delayed240 ms] this patch fix this issue by clear hard_reset_count at any cases of cc disconnect, í.e. don't check port->attached flag. Fixes: 4b4e02c83167 ("typec: tcpm: Move out of staging") Cc: stable@vger.kernel.org Reported-and-tested-by: ChiYuan Huang Reviewed-by: Guenter Roeck Reviewed-by: Heikki Krogerus Signed-off-by: Li Jun Link: https://lore.kernel.org/r/1602500592-3817-1-git-send-email-jun.li@nxp.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/tcpm/tcpm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -2723,12 +2723,12 @@ static void tcpm_reset_port(struct tcpm_ static void tcpm_detach(struct tcpm_port *port) { - if (!port->attached) - return; - if (tcpm_port_is_disconnected(port)) port->hard_reset_count = 0; + if (!port->attached) + return; + tcpm_reset_port(port); }