Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1184781rwi; Wed, 19 Oct 2022 07:38:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7gnC1/7//WAZmSN/k2aKWCW10GMpzPup3elczj+8OOV1m1m9xoQgj6Sat2NAEICWCnHlEC X-Received: by 2002:a17:903:183:b0:184:5b9a:24e7 with SMTP id z3-20020a170903018300b001845b9a24e7mr9098042plg.79.1666190334054; Wed, 19 Oct 2022 07:38:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666190334; cv=none; d=google.com; s=arc-20160816; b=qrTShZtA1ndaF6jtLiHJYnmPxsHWZqi8quw4B6uEOpoSM83PVUFnCf9ZZ6qGzmVAuk aWxqiu9Ed17w7gbuKYtkAURewwPMCobwlZBZ7w8c7jLrMS5WGDjQ/OnLhqUUUJ4cIq29 Z02LKjIFPE8faoy/huC1IN0LFtZest0wr+37ssICpoGsgKwj0JytjmsblcDooiGz8Vk7 uz5/yNs3blynGD2QRGxKtB4aStevPqya267JUJq6Kea/FK5lCSkPn5z3ikGuoays5nq+ KgTq3h7rahhDQe5Z4cxfteYHccJWcQ6RS2SKBuvb3fu5tvRxh1D2r6RtlI+ff+TvhvgN cPhQ== 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=v8BZDgM5Dda/4fKZbdmzfc5HidKRCAvgHoZLAyD7jO8=; b=oCSAOsNRJq8ROD7TmruSt7tOw4P+U2X6hK0hpoozEKDaOyrVOHfXM5vAtqMiqdftb9 bl7rio8Bm0RvinJbhd6WVZIDb2wNlSnfQUmgxpaJ1G3hQ6Vca29S/2ESJ/2+JDRA+ZQC ziSnxHbr7Q1MmZ0cLTIcwyCkynMdBCZ3XQ8WZJ+6MGUHyuopTuOw4XJSOcRkyCVcP6PI QQ5N0sKNbPqBMhGJKTtqgMwx/3NvgyTz6D/k+2SjR0bpqPNT01ATalmFWmWaR0mUSl2c QQA4qftiNnl1WYPjQFjaecRnDJIZ+axBTY3GjLlV8qq3psmqJkNuPDjH+C6VVj5/px/F M8ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zVrRwAcO; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r15-20020a63204f000000b0043ca1b4984fsi19168226pgm.865.2022.10.19.07.38.42; Wed, 19 Oct 2022 07:38:54 -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=zVrRwAcO; 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 S232774AbiJSNou (ORCPT + 99 others); Wed, 19 Oct 2022 09:44:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233357AbiJSNoH (ORCPT ); Wed, 19 Oct 2022 09:44:07 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E68DE190E4B; Wed, 19 Oct 2022 06:31:06 -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 sin.source.kernel.org (Postfix) with ESMTPS id 0575DCE20F3; Wed, 19 Oct 2022 08:45:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D59E8C433C1; Wed, 19 Oct 2022 08:45:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169125; bh=VsHfEoKbv7JG9yIQgzXgn8pAdXnQ/kuR9cBjswx8aXY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zVrRwAcOmI2UWTgg2JqQRCI1h6mH5jaRiG5IW3ZOwYExq6pstzaFW5oGdWlHMg2/q YtewrWIhdiFo7yh770wJCYgOBWiAOJJnmZPWU+obpiaO8RIHeHsjkVudRujF+1NTEZ hKctpHBn7Rlto5W65riqYg0QKXcVc3gl3HnKBowM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mario Limonciello , Mika Westerberg Subject: [PATCH 6.0 167/862] thunderbolt: Explicitly enable lane adapter hotplug events at startup Date: Wed, 19 Oct 2022 10:24:14 +0200 Message-Id: <20221019083257.351031624@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 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 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 @@ -2822,6 +2822,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 @@ -2891,6 +2911,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 @@ -1174,6 +1174,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 @@ -308,6 +308,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 @@ -1046,6 +1046,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;