From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=60.244.123.138 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796459658; b=2vUXWtMEFduRqB+qoAZ8YGSmE19dLD0a3EkSMwpzRAc00OY5BmW/a7vc73rjtPFGESMo 6C1KS2Sx0UUNVtbZiUfowsI2xguT444damCm+5v7EwG+3aFT90t8n14zpzkJvoNvP7t9n y9J5DjC94FKpF1zJY2ujzyVRgCmJ/8XSyRPVX51RyEoqC6yGht7saX5BTD1AxLFJK/Be/ T1zDY+3tc3+0xg7G39fM+GFCgf4CNAay1kKCKz1hVbB1WG4qBaDzGUew3Ga1L918IxDhv YRgbx4HRhmAA/MBBXSdyHUjgDQZa9HclQHIHkhtvyQMOUBwdfiuhcVU+Xq591ng6mOQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796459658; h=DMARC-Filter:X-UUID:DKIM-Signature:X-CID-P-RULE:X-CID-O-INFO: X-CID-META:X-CID-BVR:X-CID-BAS:X-CID-FACTOR:X-CID-RHF:X-UUID:Received: Received:Received:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: Content-Type:X-MTK; bh=e8BUMeXgwn85oTWPje1neH+HxrJDLxnCUt3ajWUUp2k=; b=Ap5Pw0LV5VXacnknCkxRlxd0cr7rLxTpn4M561vh+kvKp4/urKF7k88dNSzogi2A/jlC +pkqHAdeEQMh+Qt4KBmJ+24lYjpCg4WXGWYmUw97tRJc7wd6OLqHlQ99pQPsBPB24GhqO O2SHEzoQdZtSdw5OyFqCdImFIUVK3VUBRmMdZtYzSUdmzqOIABMjP5RQLlITmhN3mEsD/ fLMu01xDGFCqU2Jkg3VrdGiq8rWRBMVzxPLVEq5EhoXOLgCiK+h2jk5tUjRvoc+ffqoyc tW4MYoBffCD3Y75h07IKePsvSzOMN+mZe6wKvNd76AyyvlSTw6VbFJaNad/frNN6Qjg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256 header.s=dk header.b=A7dOicOK; arc=none smtp.remote-ip=60.244.123.138 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA34360A5BDE; Sat, 5 Dec 2026 08:34:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DA34360A5BDE Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256 header.s=dk header.b=A7dOicOK X-UUID: a5d5b960f08611f1b9cf3d4034dccee2-20261205 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=e8BUMeXgwn85oTWPje1neH+HxrJDLxnCUt3ajWUUp2k=; b=A7dOicOKeMo/nSHRUnxSSMZnUgEk3RF0hbbSGpPORb90Qv1NyeaNtZoUOJu7Uj/H/vr/V/wgj/FY864ftxzuuHDdadqdOsnNqplQOihBh/jeaK1aOCMigbSzVEukLf8p+yU5egzuCJtzLp2yhIczS9Nr9sG2nRkHXtJTBbYDiPY=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.22,REQID:ca0c089d-c104-4fa8-abde-54aaf3788aad,IP:0,U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:d36851b,CLOUDID:9a993767-4b51-4c95-bb1b-80ac6aad9c96,B ulkID:nil,BulkQuantity:0,SF:81|82|102|836|865|888|898,TC:-5,Content:0|15|5 0|99,EDM:-3,IP:nil,URL:0,File:130,RT:0,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0 ,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: a5d5b960f08611f1b9cf3d4034dccee2-20261205 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 758974721; Sat, 05 Dec 2026 16:34:12 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Sat, 5 Dec 2026 16:34:08 +0800 Received: from gcnsap21.gcn.mediatek.inc (10.17.81.22) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.2562.56 via Frontend Transport; Sat, 5 Dec 2026 16:34:07 +0800 From: Chunfeng Yun To: Mika Westerberg CC: Andreas Noever , Konrad Dybcio , Sven Peter , Yehezkel Bernat , Matthias Brugger , Greg Kroah-Hartman , AngeloGioacchino Del Regno , , , , , Chunfeng Yun Subject: [PATCH v4 13/14] thunderbolt: Decouple the waiting time of TB_PORT_UNPLUGGED and TB_PORT_UP Date: Sat, 5 Dec 2026 16:33:38 +0800 Message-ID: <20261205083342.4009278-14-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261205083342.4009278-1-chunfeng.yun@mediatek.com> References: <20261205083342.4009278-1-chunfeng.yun@mediatek.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-MTK: N When a USB4 router wakes up due to a device disconnect, there is no need to wait the full 2 seconds in TB_PORT_UNPLUGGED. Although the USB4 specification does not define an overall timeout for Phases 2-4 (before the port transitions from CLd/TB_PORT_UNPLUGGED to Training/TB_PORT_CONNECTING), empirical testing across various devices shows that Phases 2-4 typically take at most ~200ms after router resume. Wait at most 400ms (2x margin) for the port to leave TB_PORT_UNPLUGGED; if it remains in TB_PORT_UNPLUGGED after that, treat it as disconnected and return early. Signed-off-by: Chunfeng Yun --- v4: modify commit message v3: fix code style v2: new patch --- drivers/thunderbolt/switch.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index e0bbdc5fb2f6..f25c358181dd 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -489,8 +489,9 @@ int tb_port_state(struct tb_port *port) * Wait up to 2 seconds for a port to reach state TB_PORT_UP. If * wait_if_unplugged is set then we also wait if the port is in state * TB_PORT_UNPLUGGED (it takes a while for the device to be registered after - * switch resume). Otherwise we only wait if a device is registered but the link - * has not yet been established. + * router resume, Wait at most 400 ms for link to start connecting, + * if timeout, means the device is disconnected). Otherwise we only wait + * if a device is registered but the link has not yet been established. * * Return: * * %0 - If the port is not connected or failed to reach @@ -500,6 +501,7 @@ int tb_port_state(struct tb_port *port) */ int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged) { + int unplugged_retries = 4; int retries = 20; int state; if (!port->cap_phy) { @@ -519,7 +521,7 @@ int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged) return 0; case TB_PORT_UNPLUGGED: - if (wait_if_unplugged) { + if (wait_if_unplugged && unplugged_retries--) { /* used during resume */ tb_port_dbg(port, "is unplugged (state: 7), retrying...\n"); -- 2.45.2