From patchwork Mon Oct 24 11:27:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9302 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp464516wru; Mon, 24 Oct 2022 06:50:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM63Sblp9lhf256uiZeb7YcctYjC+iQV8PHyZjVmmslwR5ZfK8jmo9PrBRtl6hL8VbOWJwnu X-Received: by 2002:a05:6402:e9b:b0:454:351c:c222 with SMTP id h27-20020a0564020e9b00b00454351cc222mr31111107eda.216.1666619435557; Mon, 24 Oct 2022 06:50:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666619435; cv=none; d=google.com; s=arc-20160816; b=KOKSzM27uum63kBJbTCOBrV0Xa1lUlj+d+0bizD0Wqxthpo4+oHg1HeQWew+g3yZQJ GI0c60NOEBXSvXflWJZ+9BhgxI3u5GogdOSiPOlM3aMHgXGsIm0IJq2RzF55o0z9fD/D DC5ryc/4akU3YZ3ywIUH/Ks60M7hTrQenV7lkvrMw7crIwVqmtweLnLSQsobnygB13sF Fgvv2g67ifWX8uY9iIScztgWRbBy2PpBKzrvwpNojQPn9hZNOJnoRLQil+6y7BT7efDY 3arZ8lUMA2lu0x/D2XlgSwsv6OpWQL8Jhcq4LPKt+11rnGQWCUKdhB88ol1/wl7hoz31 nXMw== 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=TLeP5sgCPcK+ZmoWMpKd/ZQGaijfe4irCTEPPQ9Z89E=; b=lNOLGCY8t6N34ueArNy6tEITFQBdD2DBHjsw82Rzg+Ue+JpufiOhZt7S53+Pym0SGt yEDJZpn2muVlQpzqkCVoJo0V1nfg/0LbBYeqSpsdeZFsGzg/XeIq0BzfHEN+qY1cXzZt e3DfOyWr24X//wBMkf6V5PnyOZXdyLEaGICylvHJmmeYSsHWp6x0BFh9n2RW4kG64fKj zr/usrtGy/7KNFdYZVHz8L4+ijl5VEM9OlhUWAgs6p6nPDV4QLuSTh08PoYII4yMyD1V fvmxAqW14ML5yi/lyq0U/8yfVPC0DeSFcu+geZtDVr9WMOgbqhctp8lnBcA1WwmvV2gm PCaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="UCqgb//h"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd17-20020a1709069b9100b00730bc62507csi28494582ejc.125.2022.10.24.06.50.07; Mon, 24 Oct 2022 06:50:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="UCqgb//h"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236362AbiJXNqN (ORCPT + 99 others); Mon, 24 Oct 2022 09:46:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236499AbiJXNoT (ORCPT ); Mon, 24 Oct 2022 09:44:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC79329C99; Mon, 24 Oct 2022 05:40:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9A66161328; Mon, 24 Oct 2022 12:38:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD304C433D6; Mon, 24 Oct 2022 12:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666615091; bh=zWdJyAQ0UOjtuAePa70o5bEUnFcKPi9EhvQ88yL2+Qw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UCqgb//hswW4bGXpxfQvNw0bq7R0oKnJciV+5yidSlwqy0dsdTVJlRiKX0zUmdpFk H9Y+dkCxJuitA73zpI7zGWo8ewILfnWVXA42+6MhB7wqV90QICwtmOxxwOw0n+uQ1n EOHvFzLh6I6txx0ELlS7l5nSdEbFtG/Xp6MLH2Js= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mario Limonciello , Mika Westerberg Subject: [PATCH 5.15 118/530] thunderbolt: Explicitly enable lane adapter hotplug events at startup Date: Mon, 24 Oct 2022 13:27:42 +0200 Message-Id: <20221024113050.380730907@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747577141232705699?= X-GMAIL-MSGID: =?utf-8?q?1747577141232705699?= From: Mario Limonciello commit 5d2569cb4a65c373896ec0217febdf88739ed295 upstream. Software that has run before the USB4 CM in Linux runs may have disabled hotplug events for a given lane adapter. Other CMs such as that one distributed with Windows 11 will enable hotplug events. Do the same thing in the Linux CM which fixes hotplug events on "AMD Pink Sardine". Cc: stable@vger.kernel.org Signed-off-by: Mario Limonciello Signed-off-by: Mika Westerberg Signed-off-by: Greg Kroah-Hartman --- drivers/thunderbolt/switch.c | 24 ++++++++++++++++++++++++ drivers/thunderbolt/tb.h | 1 + drivers/thunderbolt/tb_regs.h | 1 + drivers/thunderbolt/usb4.c | 20 ++++++++++++++++++++ 4 files changed, 46 insertions(+) --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -2690,6 +2690,26 @@ static void tb_switch_credits_init(struc tb_sw_info(sw, "failed to determine preferred buffer allocation, using defaults\n"); } +static int tb_switch_port_hotplug_enable(struct tb_switch *sw) +{ + struct tb_port *port; + + if (tb_switch_is_icm(sw)) + return 0; + + tb_switch_for_each_port(sw, port) { + int res; + + if (!port->cap_usb4) + continue; + + res = usb4_port_hotplug_enable(port); + if (res) + return res; + } + return 0; +} + /** * tb_switch_add() - Add a switch to the domain * @sw: Switch to add @@ -2761,6 +2781,10 @@ int tb_switch_add(struct tb_switch *sw) return ret; } + ret = tb_switch_port_hotplug_enable(sw); + if (ret) + return ret; + ret = device_add(&sw->dev); if (ret) { dev_err(&sw->dev, "failed to add device: %d\n", ret); --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -1067,6 +1067,7 @@ int usb4_switch_add_ports(struct tb_swit void usb4_switch_remove_ports(struct tb_switch *sw); int usb4_port_unlock(struct tb_port *port); +int usb4_port_hotplug_enable(struct tb_port *port); int usb4_port_configure(struct tb_port *port); void usb4_port_unconfigure(struct tb_port *port); int usb4_port_configure_xdomain(struct tb_port *port); --- a/drivers/thunderbolt/tb_regs.h +++ b/drivers/thunderbolt/tb_regs.h @@ -301,6 +301,7 @@ struct tb_regs_port_header { #define ADP_CS_5 0x05 #define ADP_CS_5_LCA_MASK GENMASK(28, 22) #define ADP_CS_5_LCA_SHIFT 22 +#define ADP_CS_5_DHP BIT(31) /* TMU adapter registers */ #define TMU_ADP_CS_3 0x03 --- a/drivers/thunderbolt/usb4.c +++ b/drivers/thunderbolt/usb4.c @@ -1068,6 +1068,26 @@ int usb4_port_unlock(struct tb_port *por return tb_port_write(port, &val, TB_CFG_PORT, ADP_CS_4, 1); } +/** + * usb4_port_hotplug_enable() - Enables hotplug for a port + * @port: USB4 port to operate on + * + * Enables hot plug events on a given port. This is only intended + * to be used on lane, DP-IN, and DP-OUT adapters. + */ +int usb4_port_hotplug_enable(struct tb_port *port) +{ + int ret; + u32 val; + + ret = tb_port_read(port, &val, TB_CFG_PORT, ADP_CS_5, 1); + if (ret) + return ret; + + val &= ~ADP_CS_5_DHP; + return tb_port_write(port, &val, TB_CFG_PORT, ADP_CS_5, 1); +} + static int usb4_port_set_configured(struct tb_port *port, bool configured) { int ret;