From patchwork Wed Oct 19 08:24:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5496 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp335836wrs; Wed, 19 Oct 2022 06:45:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4dkvyufilQlkrLP8RP31Aak3qzK9d8E4eEQc8bufbQgbDTyvn5ETUtCD6z/+qo2nAsOfCe X-Received: by 2002:a17:90a:5996:b0:203:1640:2dbf with SMTP id l22-20020a17090a599600b0020316402dbfmr10145225pji.150.1666187152085; Wed, 19 Oct 2022 06:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666187152; cv=none; d=google.com; s=arc-20160816; b=iN/b6D8kXAnrgubL5mzobzBxHIDOLCQXHH46Pamgikdzw68P6YBNKCo6sCULbed0yT ntDsSmwCqR9Uv/vnIOTXPG7/7tXyiPuhrewu6zw6TTuQozgBRbjSoM1rzjcetY3upoa6 c37z14x6eTCyqvhsY3eCokpPDjAevaqdzZOX7oJM/19zx3QRfwx8gSyaXxzEH3oWTKwU CAOwjtrpWOoWzL/etd9farZr+IdmDLWSlqvV+1ulMuP4Guc0aeOHXPuKGnafjPpIpYRL UIcH9NlUa2YMWWSJ5pLjbwLHj9gJrmmxbtJgXTeEJyGmQcVeTEEIoGK8b+Ey5WLeXqMe 4s6g== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cm9-20020a056a00338900b0056771c032f4si2390920pfb.28.2022.10.19.06.45.38; Wed, 19 Oct 2022 06:45:52 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747123859316232604?= X-GMAIL-MSGID: =?utf-8?q?1747123859316232604?= 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;