Received: by 2002:a05:6622:f08:0:0:0:0 with SMTP id l8csp4489400ivc; Tue, 3 Nov 2020 13:24:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJySgadfGF5CiJszHMZbBOmKkVg6LM/v8gqYK6NGGwMcnpqWNeltauZRjxwojBkGsu0raiWv X-Received: by 2002:a05:6402:1d85:: with SMTP id dk5mr24677482edb.240.1604438642592; Tue, 03 Nov 2020 13:24:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604438642; cv=none; d=google.com; s=arc-20160816; b=sKNdCCu+PbhSEfz070EqTW57p+DBk8VfPq9m1vURZkaPRS6P+/Yh1k4D7Hzel6NQDq vyp06IwF8NitKyyNpqL9et5n2fGm18h410B4C1L9/iv/aWksrQiUstY159Im/TAdOIZU Y6z06EV72ZpSJ15GtTvdcLZY/u4NtVOGFm4sSWhKS2OIEIfFYGX+5ZdAgGF2y4bDJVvv HD/bg7PJDcr3EoVxJOEBKpZaW0I2DTsTSnZoZXnlPHEDIiX8J+OrOi9f6MyGYFobL4oe 2Vj3jYzh4eq/5l42PLRK66CquUHgx9Heer/TvkAN9t7BBbbcIov0UtVj2Z7HXW94eG8Y UTig== 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=dbT8fT/C6IiBtVr06C548C+fXMDQF3Q4ea9340MY6Bw=; b=tP5eyPWkkBbRIRDPjLe4uHGIevPcZ6QEfs28Du+JmrnLsVqguVMniGwCYysipbx2TS Ise0RY9ZRn8WhVCCkT+jQ37HzzvXZJgKz4SaYfkhz98Dfkq77hgdmyvepoObzMEr3ax1 BhkDjtxP8QIY78lIaJWQkLQuyZLN3cIlk3d525jCmUx9eNuV0SRC5GIU6CUuiE0cZppB jGlDbfklnxTYMEaIevJP73S5HOVzN/yBDR7LTbdm9NJVsrJPfeBoqIsXb4YZ2CMBeA/e F1E6MOBdbjt/lC1BLse561pJ+0zRXJA4fO69f341bt7JtdzjK/AXpfbTU3G8dcyXeepJ o36Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YC5DTvqx; 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 k7si40046ejp.590.2020.11.03.13.23.39; Tue, 03 Nov 2020 13:24:02 -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=YC5DTvqx; 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 S2388161AbgKCVGc (ORCPT + 99 others); Tue, 3 Nov 2020 16:06:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:45380 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388160AbgKCVG1 (ORCPT ); Tue, 3 Nov 2020 16:06:27 -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 9C005206B5; Tue, 3 Nov 2020 21:06:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437587; bh=6qP3sCd3wXRue+cgDq9k16M/M+310/PClLCMCzCApaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YC5DTvqx+oqGFi2F289aXhlOElYV/i2YculPhbRNSQHk0Xz9UspbTyQ80NFsdTmue Q5VP/rXsTf0GcGaFKwrxLwhRfW8HJvQ/mBKoKwE/I2E1IvVAX5vhEY070OqD6oWyZa JJ5zf/84ikhyN2iABcvQHcMeM9whI851USaKW6yw= 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 4.19 141/191] usb: typec: tcpm: reset hard_reset_count for any disconnect Date: Tue, 3 Nov 2020 21:37:13 +0100 Message-Id: <20201103203246.070370592@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203232.656475008@linuxfoundation.org> References: <20201103203232.656475008@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.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/usb/typec/tcpm.c +++ b/drivers/usb/typec/tcpm.c @@ -2727,12 +2727,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); }