]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.1/thunderbolt-keep-the-domain-powered-when-usb4-port-i.patch
Fixes for 6.1
[thirdparty/kernel/stable-queue.git] / queue-6.1 / thunderbolt-keep-the-domain-powered-when-usb4-port-i.patch
1 From 9730608c2a1338f56e5605844c13f844ee5fea56 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Fri, 26 Jan 2024 15:55:55 +0200
4 Subject: thunderbolt: Keep the domain powered when USB4 port is in redrive
5 mode
6
7 From: Mika Westerberg <mika.westerberg@linux.intel.com>
8
9 [ Upstream commit a75e0684efe567ae5f6a8e91a8360c4c1773cf3a ]
10
11 If a DiplayPort cable is directly connected to the host routers USB4
12 port, there is no tunnel involved but the port is in "redrive" mode
13 meaning that it is re-driving the DisplayPort signals from its
14 DisplayPort source. In this case we need to keep the domain powered on
15 otherwise once the domain enters D3cold the connected monitor blanks
16 too.
17
18 Since this happens only on Intel Barlow Ridge add a quirk that takes
19 runtime PM reference if we detect that the USB4 port entered redrive
20 mode (and release it once it exits the mode).
21
22 Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
23 Signed-off-by: Sasha Levin <sashal@kernel.org>
24 ---
25 drivers/thunderbolt/quirks.c | 14 +++++++++++
26 drivers/thunderbolt/tb.c | 49 +++++++++++++++++++++++++++++++++++-
27 drivers/thunderbolt/tb.h | 4 +++
28 3 files changed, 66 insertions(+), 1 deletion(-)
29
30 diff --git a/drivers/thunderbolt/quirks.c b/drivers/thunderbolt/quirks.c
31 index 4ab3803e10c83..638cb5fb22c11 100644
32 --- a/drivers/thunderbolt/quirks.c
33 +++ b/drivers/thunderbolt/quirks.c
34 @@ -42,6 +42,12 @@ static void quirk_usb3_maximum_bandwidth(struct tb_switch *sw)
35 }
36 }
37
38 +static void quirk_block_rpm_in_redrive(struct tb_switch *sw)
39 +{
40 + sw->quirks |= QUIRK_KEEP_POWER_IN_DP_REDRIVE;
41 + tb_sw_dbg(sw, "preventing runtime PM in DP redrive mode\n");
42 +}
43 +
44 struct tb_quirk {
45 u16 hw_vendor_id;
46 u16 hw_device_id;
47 @@ -85,6 +91,14 @@ static const struct tb_quirk tb_quirks[] = {
48 quirk_usb3_maximum_bandwidth },
49 { 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HUB_40G_BRIDGE, 0x0000, 0x0000,
50 quirk_usb3_maximum_bandwidth },
51 + /*
52 + * Block Runtime PM in DP redrive mode for Intel Barlow Ridge host
53 + * controllers.
54 + */
55 + { 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HOST_80G_NHI, 0x0000, 0x0000,
56 + quirk_block_rpm_in_redrive },
57 + { 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HOST_40G_NHI, 0x0000, 0x0000,
58 + quirk_block_rpm_in_redrive },
59 /*
60 * CLx is not supported on AMD USB4 Yellow Carp and Pink Sardine platforms.
61 */
62 diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
63 index e1eb092ad1d67..e83269dc2b067 100644
64 --- a/drivers/thunderbolt/tb.c
65 +++ b/drivers/thunderbolt/tb.c
66 @@ -1050,6 +1050,49 @@ static void tb_tunnel_dp(struct tb *tb)
67 pm_runtime_put_autosuspend(&in->sw->dev);
68 }
69
70 +static void tb_enter_redrive(struct tb_port *port)
71 +{
72 + struct tb_switch *sw = port->sw;
73 +
74 + if (!(sw->quirks & QUIRK_KEEP_POWER_IN_DP_REDRIVE))
75 + return;
76 +
77 + /*
78 + * If we get hot-unplug for the DP IN port of the host router
79 + * and the DP resource is not available anymore it means there
80 + * is a monitor connected directly to the Type-C port and we are
81 + * in "redrive" mode. For this to work we cannot enter RTD3 so
82 + * we bump up the runtime PM reference count here.
83 + */
84 + if (!tb_port_is_dpin(port))
85 + return;
86 + if (tb_route(sw))
87 + return;
88 + if (!tb_switch_query_dp_resource(sw, port)) {
89 + port->redrive = true;
90 + pm_runtime_get(&sw->dev);
91 + tb_port_dbg(port, "enter redrive mode, keeping powered\n");
92 + }
93 +}
94 +
95 +static void tb_exit_redrive(struct tb_port *port)
96 +{
97 + struct tb_switch *sw = port->sw;
98 +
99 + if (!(sw->quirks & QUIRK_KEEP_POWER_IN_DP_REDRIVE))
100 + return;
101 +
102 + if (!tb_port_is_dpin(port))
103 + return;
104 + if (tb_route(sw))
105 + return;
106 + if (port->redrive && tb_switch_query_dp_resource(sw, port)) {
107 + port->redrive = false;
108 + pm_runtime_put(&sw->dev);
109 + tb_port_dbg(port, "exit redrive mode\n");
110 + }
111 +}
112 +
113 static void tb_dp_resource_unavailable(struct tb *tb, struct tb_port *port)
114 {
115 struct tb_port *in, *out;
116 @@ -1066,7 +1109,10 @@ static void tb_dp_resource_unavailable(struct tb *tb, struct tb_port *port)
117 }
118
119 tunnel = tb_find_tunnel(tb, TB_TUNNEL_DP, in, out);
120 - tb_deactivate_and_free_tunnel(tunnel);
121 + if (tunnel)
122 + tb_deactivate_and_free_tunnel(tunnel);
123 + else
124 + tb_enter_redrive(port);
125 list_del_init(&port->list);
126
127 /*
128 @@ -1092,6 +1138,7 @@ static void tb_dp_resource_available(struct tb *tb, struct tb_port *port)
129 tb_port_dbg(port, "DP %s resource available\n",
130 tb_port_is_dpin(port) ? "IN" : "OUT");
131 list_add_tail(&port->list, &tcm->dp_resources);
132 + tb_exit_redrive(port);
133
134 /* Look for suitable DP IN <-> DP OUT pairs now */
135 tb_tunnel_dp(tb);
136 diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
137 index f79cae48a8eab..b3fec5f8e20cd 100644
138 --- a/drivers/thunderbolt/tb.h
139 +++ b/drivers/thunderbolt/tb.h
140 @@ -27,6 +27,8 @@
141 #define QUIRK_FORCE_POWER_LINK_CONTROLLER BIT(0)
142 /* Disable CLx if not supported */
143 #define QUIRK_NO_CLX BIT(1)
144 +/* Need to keep power on while USB4 port is in redrive mode */
145 +#define QUIRK_KEEP_POWER_IN_DP_REDRIVE BIT(2)
146
147 /**
148 * struct tb_nvm - Structure holding NVM information
149 @@ -254,6 +256,7 @@ struct tb_switch {
150 * DMA paths through this port.
151 * @max_bw: Maximum possible bandwidth through this adapter if set to
152 * non-zero.
153 + * @redrive: For DP IN, if true the adapter is in redrive mode.
154 *
155 * In USB4 terminology this structure represents an adapter (protocol or
156 * lane adapter).
157 @@ -280,6 +283,7 @@ struct tb_port {
158 unsigned int ctl_credits;
159 unsigned int dma_credits;
160 unsigned int max_bw;
161 + bool redrive;
162 };
163
164 /**
165 --
166 2.43.0
167