xref: /linux/drivers/thunderbolt/quirks.c (revision 2a31b5378c6db9c4a8d399e5d10d32cd4b732bef)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Thunderbolt driver - quirks
4  *
5  * Copyright (c) 2020 Mario Limonciello <mario.limonciello@dell.com>
6  */
7 
8 #include "tb.h"
9 
10 static void quirk_force_power_link(struct tb_switch *sw)
11 {
12 	sw->quirks |= QUIRK_FORCE_POWER_LINK_CONTROLLER;
13 	tb_sw_dbg(sw, "forcing power to link controller\n");
14 }
15 
16 static void quirk_dp_credit_allocation(struct tb_switch *sw)
17 {
18 	if (sw->credit_allocation && sw->min_dp_main_credits == 56) {
19 		sw->min_dp_main_credits = 18;
20 		tb_sw_dbg(sw, "quirked DP main: %u\n", sw->min_dp_main_credits);
21 	}
22 }
23 
24 static void quirk_clx_disable(struct tb_switch *sw)
25 {
26 	if (tb_switch_is_titan_ridge(sw) && sw->nvm && sw->nvm->major >= 0x65)
27 		return;
28 
29 	sw->quirks |= QUIRK_NO_CLX;
30 	tb_sw_dbg(sw, "disabling CL states\n");
31 }
32 
33 static void quirk_usb3_maximum_bandwidth(struct tb_switch *sw)
34 {
35 	struct tb_port *port;
36 
37 	if (tb_switch_is_icm(sw))
38 		return;
39 
40 	tb_switch_for_each_port(sw, port) {
41 		if (!tb_port_is_usb3_down(port))
42 			continue;
43 		port->max_bw = 16376;
44 		tb_port_dbg(port, "USB3 maximum bandwidth limited to %u Mb/s\n",
45 			    port->max_bw);
46 	}
47 }
48 
49 static void quirk_block_rpm_in_redrive(struct tb_switch *sw)
50 {
51 	sw->quirks |= QUIRK_KEEP_POWER_IN_DP_REDRIVE;
52 	tb_sw_dbg(sw, "preventing runtime PM in DP redrive mode\n");
53 }
54 
55 struct tb_quirk {
56 	u16 hw_vendor_id;
57 	u16 hw_device_id;
58 	u16 vendor;
59 	u16 device;
60 	void (*hook)(struct tb_switch *sw);
61 };
62 
63 static const struct tb_quirk tb_quirks[] = {
64 	/* Dell WD19TB supports self-authentication on unplug */
65 	{ 0x0000, 0x0000, 0x00d4, 0xb070, quirk_force_power_link },
66 	{ 0x0000, 0x0000, 0x00d4, 0xb071, quirk_force_power_link },
67 
68 	/* Intel Titan Ridge CLx is unstable on early firmware versions */
69 	{ 0x8086, PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_BRIDGE, 0x0000, 0x0000,
70 		  quirk_clx_disable },
71 	/*
72 	 * Intel Goshen Ridge NVM 27 and before report wrong number of
73 	 * DP buffers.
74 	 */
75 	{ 0x8087, 0x0b26, 0x0000, 0x0000, quirk_dp_credit_allocation },
76 	/*
77 	 * Limit the maximum USB3 bandwidth for the following Intel USB4
78 	 * host routers due to a hardware issue.
79 	 */
80 	{ 0x8087, PCI_DEVICE_ID_INTEL_ADL_NHI0, 0x0000, 0x0000,
81 		  quirk_usb3_maximum_bandwidth },
82 	{ 0x8087, PCI_DEVICE_ID_INTEL_ADL_NHI1, 0x0000, 0x0000,
83 		  quirk_usb3_maximum_bandwidth },
84 	{ 0x8087, PCI_DEVICE_ID_INTEL_RPL_NHI0, 0x0000, 0x0000,
85 		  quirk_usb3_maximum_bandwidth },
86 	{ 0x8087, PCI_DEVICE_ID_INTEL_RPL_NHI1, 0x0000, 0x0000,
87 		  quirk_usb3_maximum_bandwidth },
88 	{ 0x8087, PCI_DEVICE_ID_INTEL_MTL_M_NHI0, 0x0000, 0x0000,
89 		  quirk_usb3_maximum_bandwidth },
90 	{ 0x8087, PCI_DEVICE_ID_INTEL_MTL_P_NHI0, 0x0000, 0x0000,
91 		  quirk_usb3_maximum_bandwidth },
92 	{ 0x8087, PCI_DEVICE_ID_INTEL_MTL_P_NHI1, 0x0000, 0x0000,
93 		  quirk_usb3_maximum_bandwidth },
94 	{ 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HOST_80G_NHI, 0x0000, 0x0000,
95 		  quirk_usb3_maximum_bandwidth },
96 	{ 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HOST_40G_NHI, 0x0000, 0x0000,
97 		  quirk_usb3_maximum_bandwidth },
98 	{ 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HUB_80G_BRIDGE, 0x0000, 0x0000,
99 		  quirk_usb3_maximum_bandwidth },
100 	{ 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HUB_40G_BRIDGE, 0x0000, 0x0000,
101 		  quirk_usb3_maximum_bandwidth },
102 	/* CLx is unstable on the Anker Prime TB5 dock (DROM 01ea:83b5) */
103 	{ 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HUB_80G_BRIDGE, 0x01ea, 0x83b5,
104 		  quirk_clx_disable },
105 	/*
106 	 * Block Runtime PM in DP redrive mode for Intel Barlow Ridge host
107 	 * controllers.
108 	 */
109 	{ 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HOST_80G_NHI, 0x0000, 0x0000,
110 		  quirk_block_rpm_in_redrive },
111 	{ 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HOST_40G_NHI, 0x0000, 0x0000,
112 		  quirk_block_rpm_in_redrive },
113 	/*
114 	 * CLx is not supported on AMD USB4 Yellow Carp and Pink Sardine platforms.
115 	 */
116 	{ 0x0438, 0x0208, 0x0000, 0x0000, quirk_clx_disable },
117 	{ 0x0438, 0x0209, 0x0000, 0x0000, quirk_clx_disable },
118 	{ 0x0438, 0x020a, 0x0000, 0x0000, quirk_clx_disable },
119 	{ 0x0438, 0x020b, 0x0000, 0x0000, quirk_clx_disable },
120 };
121 
122 /**
123  * tb_check_quirks() - Check for quirks to apply
124  * @sw: Thunderbolt switch
125  *
126  * Apply any quirks for the Thunderbolt controller.
127  */
128 void tb_check_quirks(struct tb_switch *sw)
129 {
130 	int i;
131 
132 	for (i = 0; i < ARRAY_SIZE(tb_quirks); i++) {
133 		const struct tb_quirk *q = &tb_quirks[i];
134 
135 		if (q->hw_vendor_id && q->hw_vendor_id != sw->config.vendor_id)
136 			continue;
137 		if (q->hw_device_id && q->hw_device_id != sw->config.device_id)
138 			continue;
139 		if (q->vendor && q->vendor != sw->vendor)
140 			continue;
141 		if (q->device && q->device != sw->device)
142 			continue;
143 
144 		tb_sw_dbg(sw, "running %ps\n", q->hook);
145 		q->hook(sw);
146 	}
147 }
148