Improvements and Lunar Lake support
Subsystems (2)
cover Improvements and Lunar Lake support
Hi all,
This series adds improvements around USB4 v2 support, PCIe tunneling, some minor fixes and also adds Intel Lunar Lake support.
Gil Fine (7):
thunderbolt: Handle lane bonding of Gen 4 XDomain links properly
thunderbolt: Move width_name() helper to tb.h
thunderbolt: Log XDomain link speed and width
thunderbolt: Transition link to asymmetric only when both sides support it
thunderbolt: Improve logging when DisplayPort resource is added due to hotplug
thunderbolt: Make PCIe tunnel setup and teardown follow CM guide
thunderbolt: Disable PCIe extended encapsulation upon teardown properly
Mika Westerberg (4):
thunderbolt: Unwind TMU configuration if tb_switch_set_tmu_mode_params() fails
thunderbolt: Disable CL states only when actually needed
thunderbolt: Use tb_dp_read_cap() to read DP_COMMON_CAP as well
thunderbolt: Add support for Intel Lunar Lake
drivers/thunderbolt/nhi.c | 4 +++ drivers/thunderbolt/nhi.h | 2 ++ drivers/thunderbolt/switch.c | 20 ++----------- drivers/thunderbolt/tb.c | 46 ++++++++++++++++++----------- drivers/thunderbolt/tb.h | 16 +++++++++++ drivers/thunderbolt/tmu.c | 2 +- drivers/thunderbolt/tunnel.c | 44 ++++++++++++++++++++-------- drivers/thunderbolt/xdomain.c | 54 ++++++++++++++++++++++++++++++++++- 8 files changed, 139 insertions(+), 49 deletions(-)
Signature · 1 line
2.42.0
PATCH 1/11 thunderbolt: Unwind TMU configuration if tb_switch_set_tmu_mode_params() fails
Dan reported that the kernel test robot found an issue with the TMU code namely in tb_switch_tmu_change_mode() where we should actually go back to the previous mode in case of failure instead of just returning back the error. Fix this by unwinding the configuration as we do with the other error paths in this function.
--- drivers/thunderbolt/tmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/tmu.c +1 -1
@@ -894,7 +894,7 @@ static int tb_switch_tmu_change_mode(struct tb_switch *sw) ret =tb_switch_set_tmu_mode_params (sw, sw->tmu.mode_request);if (ret) -return ret; + goto out;/* Program the new mode and the downstream router lane adapter */ switch (sw->tmu.mode_request) {
Signature · 1 line
2.42.0
PATCH 2/11 thunderbolt: Handle lane bonding of Gen 4 XDomain links properly
In reply to Mika WesterbergFrom: Gil Fine <[email protected]>
Gen 4 links come up as bonded already so we are not supposed to initiate lane bonding on them. However, we should still update the port structures accordingly. Split these into their own functions to make it easier to follow.
--- drivers/thunderbolt/tb.c | 2 -- drivers/thunderbolt/xdomain.c | 49 ++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-)
drivers/thunderbolt/tb.c +0 -2
@@ -513,8 +513,6 @@ static void tb_port_unconfigure_xdomain(struct tb_port *port)usb4_port_unconfigure_xdomain (port); elsetb_lc_unconfigure_xdomain (port ); - -tb_port_enable (port->dual_link_port); }static void tb_scan_xdomain (struct tb_port *port)
drivers/thunderbolt/xdomain.c +48 -1
67 lines not on this page · raw message
Signature · 1 line
2.42.0
PATCH 3/11 thunderbolt: Move width_name() helper to tb.h
In reply to Mika WesterbergFrom: Gil Fine <[email protected]>
We are going to use it in subsequent patches, so make it available outside of switch.c. Also, change the name to tb_width_name() to follow the naming conventions.
--- drivers/thunderbolt/switch.c | 20 ++------------------ drivers/thunderbolt/tb.h | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-)
drivers/thunderbolt/switch.c +2 -18
@@ -941,22 +941,6 @@ int tb_port_get_link_generation(struct tb_port *port) } } -static const char *width_name (enum tb_link_width width) -{ -switch (width) { -case TB_LINK_WIDTH_SINGLE : -return "symmetric, single lane" ; -case TB_LINK_WIDTH_DUAL : -return "symmetric, dual lanes" ; -case TB_LINK_WIDTH_ASYM_TX : -return "asymmetric, 3 transmitters, 1 receiver" ; -case TB_LINK_WIDTH_ASYM_RX : -return "asymmetric, 3 receivers, 1 transmitter" ; -default : -return "unknown" ; - } -} -/** * tb_port_get_link_width() - Get current link width * @port: Port to check (USB4 or CIO)
@@ -2769,7 +2753,7 @@ static void tb_switch_link_init(struct tb_switch *sw)return ;tb_sw_dbg (sw,"current link speed %u.0 Gb/s\n" , sw->link_speed); -tb_sw_dbg (sw,"current link width %s\n" ,width_name (sw->link_width)); +tb_sw_dbg (sw,"current link width %s\n" ,tb_width_name (sw->link_width)); bonded = sw->link_width >=TB_LINK_WIDTH_DUAL ;
@@ -3029,7 +3013,7 @@ int tb_switch_set_link_width(struct tb_switch *sw, enum tb_link_width width)tb_switch_update_link_attributes (sw); -tb_sw_dbg (sw,"link width set to %s\n" ,width_name (width)); +tb_sw_dbg (sw,"link width set to %s\n" ,tb_width_name (width));return ret; }
drivers/thunderbolt/tb.h +16 -0
@@ -568,6 +568,22 @@ static inline struct tb_port *tb_port_at(u64 route, struct tb_switch *sw)return &sw->ports[port]; } +static inline const char *tb_width_name (enum tb_link_width width) +{ +switch (width) { +case TB_LINK_WIDTH_SINGLE : +return "symmetric, single lane" ; +case TB_LINK_WIDTH_DUAL : +return "symmetric, dual lanes" ; +case TB_LINK_WIDTH_ASYM_TX : +return "asymmetric, 3 transmitters, 1 receiver" ; +case TB_LINK_WIDTH_ASYM_RX : +return "asymmetric, 3 receivers, 1 transmitter" ; +default : +return "unknown" ; + } +} +/** * tb_port_has_remote() - Does the port have switch connected downstream * @port: Port to check
Signature · 1 line
2.42.0
PATCH 4/11 thunderbolt: Log XDomain link speed and width
In reply to Mika WesterbergFrom: Gil Fine <[email protected]>
In the same way we do for routers. This is useful for debugging purposes.
--- drivers/thunderbolt/xdomain.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/thunderbolt/xdomain.c +5 -0
@@ -1462,6 +1462,11 @@ static int tb_xdomain_get_properties(struct tb_xdomain *xd)tb_port_disable (port->dual_link_port); } +dev_dbg (&xd->dev,"current link speed %u.0 Gb/s\n" , + xd->link_speed); +dev_dbg (&xd->dev,"current link width %s\n" , +tb_width_name (xd->link_width)); +if (device_add (&xd->dev)) {dev_err (&xd->dev,"failed to add XDomain device\n" );return -ENODEV ;
Signature · 1 line
2.42.0
PATCH 5/11 thunderbolt: Transition link to asymmetric only when both sides support it
In reply to Mika WesterbergFrom: Gil Fine <[email protected]>
We can transition Gen 4 link to asymmetric only when both sides of the link support it in the required direction. For this reason make sure that the downstream adapter also supports asymmetric link before starting the transition.
--- drivers/thunderbolt/tb.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/thunderbolt/tb.c +10 -6
@@ -1104,8 +1104,9 @@ static int tb_configure_asym(struct tb *tb, struct tb_port *src_port, clx =tb_disable_clx (sw);tb_for_each_upstream_port_on_path (src_port, dst_port, up) { +struct tb_port *down =tb_switch_downstream_port (up->sw); +enum tb_link_width width_up, width_down;int consumed_up, consumed_down; -enum tb_link_width width; ret =tb_consumed_dp_bandwidth (tb, src_port, dst_port, up, &consumed_up, &consumed_down);
@@ -1126,7 +1127,8 @@ static int tb_configure_asym(struct tb *tb, struct tb_port *src_port,if (consumed_down + requested_down < asym_threshold)continue ; - width =TB_LINK_WIDTH_ASYM_RX ; + width_up =TB_LINK_WIDTH_ASYM_RX ; + width_down =TB_LINK_WIDTH_ASYM_TX ; }else {/* Upstream, the opposite of above */ if (consumed_down + requested_down >=TB_ASYM_MIN ) {
@@ -1136,13 +1138,15 @@ static int tb_configure_asym(struct tb *tb, struct tb_port *src_port,if (consumed_up + requested_up < asym_threshold)continue ; - width =TB_LINK_WIDTH_ASYM_TX ; + width_up =TB_LINK_WIDTH_ASYM_TX ; + width_down =TB_LINK_WIDTH_ASYM_RX ; } -if (up->sw->link_width == width) +if (up->sw->link_width == width_up)continue ; -if (!tb_port_width_supported (up, width)) +if (!tb_port_width_supported (up, width_up) || + !tb_port_width_supported (down, width_down))continue ;tb_sw_dbg (up->sw,"configuring asymmetric link\n" );
@@ -1151,7 +1155,7 @@ static int tb_configure_asym(struct tb *tb, struct tb_port *src_port,* Here requested + consumed > threshold so we need to * transtion the link into asymmetric now. */ - ret =tb_switch_set_link_width (up->sw, width); + ret =tb_switch_set_link_width (up->sw, width_up);if (ret) {tb_sw_warn (up->sw,"failed to set link width\n" );break ;
Signature · 1 line
2.42.0
PATCH 6/11 thunderbolt: Disable CL states only when actually needed
In reply to Mika WesterbergIf there is not going to be an actual transition to asymmetric or symmetric, there is no point to disable and re-enable CL states either. So instead disable them only when we know that an actual transition is going to take place.
--- drivers/thunderbolt/tb.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
drivers/thunderbolt/tb.c +18 -8
@@ -1085,15 +1085,14 @@ static int tb_configure_asym(struct tb *tb, struct tb_port *src_port, struct tb_port *dst_port, int requested_up, int requested_down) { + bool clx = false, clx_disabled = false, downstream;struct tb_switch *sw; -bool clx, downstream;struct tb_port *up;int ret =0 ;if (!asym_threshold)return 0 ; -/* Disable CL states before doing any transitions */ downstream =tb_port_path_direction_downstream (src_port, dst_port);/* Pick up router deepest in the hierarchy */ if (downstream)
@@ -1101,8 +1100,6 @@ static int tb_configure_asym(struct tb *tb, struct tb_port *src_port,else sw = src_port->sw; - clx =tb_disable_clx (sw); -tb_for_each_upstream_port_on_path (src_port, dst_port, up) {struct tb_port *down =tb_switch_downstream_port (up->sw);enum tb_link_width width_up, width_down;
@@ -1149,6 +1146,16 @@ static int tb_configure_asym(struct tb *tb, struct tb_port *src_port, !tb_port_width_supported(down, width_down))continue ; +/* +* Disable CL states before doing any transitions. We +* delayed it until now that we know there is a real +* transition taking place. +*/ +if (!clx_disabled) { + clx =tb_disable_clx (sw); + clx_disabled = true; + } +tb_sw_dbg (up->sw,"configuring asymmetric link\n" );/*
@@ -1185,15 +1192,14 @@ static int tb_configure_sym(struct tb *tb, struct tb_port *src_port, struct tb_port *dst_port, int requested_up, int requested_down) { + bool clx = false, clx_disabled = false, downstream;struct tb_switch *sw; -bool clx, downstream;struct tb_port *up;int ret =0 ;if (!asym_threshold)return 0 ; -/* Disable CL states before doing any transitions */ downstream =tb_port_path_direction_downstream (src_port, dst_port);/* Pick up router deepest in the hierarchy */ if (downstream)
@@ -1201,8 +1207,6 @@ static int tb_configure_sym(struct tb *tb, struct tb_port *src_port,else sw = src_port->sw; - clx =tb_disable_clx (sw); -tb_for_each_upstream_port_on_path (src_port, dst_port, up) {int consumed_up, consumed_down;
@@ -1235,6 +1239,12 @@ static int tb_configure_sym(struct tb *tb, struct tb_port *src_port,if (up->sw->link_width ==TB_LINK_WIDTH_DUAL )continue ; +/* Disable CL states before doing any transitions */ +if (!clx_disabled) { + clx =tb_disable_clx (sw); + clx_disabled = true; + } +tb_sw_dbg (up->sw,"configuring symmetric link\n" ); ret =tb_switch_set_link_width (up->sw,TB_LINK_WIDTH_DUAL );
Signature · 1 line
2.42.0
PATCH 7/11 thunderbolt: Use tb_dp_read_cap() to read DP_COMMON_CAP as well
In reply to Mika WesterbergThere is no point doing this separately as the register layout is the same. For this reason rename tb_dp_read_dprx() to tb_dp_wait_dprx() and call tb_dp_read_cap() instead.
While there add debug log if the DPRX capability read times out.
--- drivers/thunderbolt/tunnel.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/thunderbolt/tunnel.c +7 -6
@@ -1067,8 +1067,7 @@ static int tb_dp_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up,return 0 ; } -static int tb_dp_read_dprx (struct tb_tunnel *tunnel,u32 *rate,u32 *lanes, -int timeout_msec) +static int tb_dp_wait_dprx (struct tb_tunnel *tunnel,int timeout_msec) {ktime_t timeout =ktime_add_ms (ktime_get (), timeout_msec);struct tb_port *in = tunnel->src_port;
@@ -1087,15 +1086,13 @@ static int tb_dp_read_dprx(struct tb_tunnel *tunnel, u32 *rate, u32 *lanes,return ret;if (val &DP_COMMON_CAP_DPRX_DONE ) { - *rate =tb_dp_cap_get_rate (val); - *lanes =tb_dp_cap_get_lanes (val); -tb_tunnel_dbg (tunnel,"DPRX read done\n" );return 0 ; }usleep_range (100 ,150 ); }while (ktime_before (ktime_get (), timeout)); +tb_tunnel_dbg (tunnel,"DPRX read timeout\n" );return -ETIMEDOUT ; }
@@ -1110,6 +1107,7 @@ static int tb_dp_read_cap(struct tb_tunnel *tunnel, unsigned int cap, u32 *rate,switch (cap) {case DP_LOCAL_CAP :case DP_REMOTE_CAP : +case DP_COMMON_CAP :break ;default :
@@ -1182,7 +1180,7 @@ static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,* reduced one). Otherwise return the remote (possibly * reduced) caps. */ - ret =tb_dp_read_dprx (tunnel, &rate, &lanes,150 ); + ret =tb_dp_wait_dprx (tunnel,150 );if (ret) {if (ret == -ETIMEDOUT ) ret = tb_dp_read_cap(tunnel, DP_REMOTE_CAP,
@@ -1190,6 +1188,9 @@ static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,if (ret)return ret; } + ret =tb_dp_read_cap (tunnel,DP_COMMON_CAP , &rate, &lanes); +if (ret) +return ret; }else if (sw->generation >=2 ) { ret =tb_dp_read_cap (tunnel,DP_REMOTE_CAP , &rate, &lanes);if (ret)
Signature · 1 line
2.42.0
PATCH 8/11 thunderbolt: Improve logging when DisplayPort resource is added due to hotplug
In reply to Mika WesterbergFrom: Gil Fine <[email protected]>
To allow us differentiate how DisplayPort resource is added to the DisplayPort resources list make the debug log to append "hotplug" when this was due to an actual hotplug.
--- drivers/thunderbolt/tb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/tb.c +1 -1
@@ -1913,7 +1913,7 @@ static void tb_dp_resource_available(struct tb *tb, struct tb_port *port)return ; } -tb_port_dbg (port,"DP %s resource available\n" , +tb_port_dbg (port,"DP %s resource available after hotplug\n" ,tb_port_is_dpin (port) ?"IN" :"OUT" );list_add_tail (&port->list, &tcm->dp_resources);
Signature · 1 line
2.42.0
PATCH 9/11 thunderbolt: Make PCIe tunnel setup and teardown follow CM guide
In reply to Mika WesterbergFrom: Gil Fine <[email protected]>
The USB4 Connection Manager guide suggests that the PCIe paths are enabled from the upstream adapter to the downstream adapter and vice versa on disable so make the driver follows this sequence.
--- drivers/thunderbolt/tunnel.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/thunderbolt/tunnel.c +10 -3
@@ -199,14 +199,21 @@ static int tb_pci_activate(struct tb_tunnel *tunnel, bool activate)return res; } - res =tb_pci_port_enable (tunnel->src_port, activate); +if (activate) + res =tb_pci_port_enable (tunnel->dst_port, activate); +else + res =tb_pci_port_enable (tunnel->src_port, activate);if (res)return res; -if (tb_port_is_pcie_up (tunnel->dst_port)) { - res =tb_pci_port_enable (tunnel->dst_port, activate); + +if (activate) { + res =tb_pci_port_enable (tunnel->src_port, activate);if (res)return res; + }else { +/* Downstream router could be unplugged */ +tb_pci_port_enable (tunnel->dst_port, activate); }return activate ?0 :tb_pci_set_ext_encapsulation (tunnel, activate);
Signature · 1 line
2.42.0
PATCH 10/11 thunderbolt: Disable PCIe extended encapsulation upon teardown properly
In reply to Mika WesterbergFrom: Gil Fine <[email protected]>
In case of PCIe tunnel teardown (including if caused by router unplug), PCIe extended encapsulation bit should be cleared in downstream and upstream routers accordingly.
--- drivers/thunderbolt/tunnel.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/thunderbolt/tunnel.c +15 -3
@@ -173,16 +173,28 @@ static int tb_pci_set_ext_encapsulation(struct tb_tunnel *tunnel, bool enable)int ret;/* Only supported of both routers are at least USB4 v2 */ -if (tb_port_get_link_generation (port) <4 ) +if ((usb4_switch_version (tunnel->src_port->sw) <2 ) || + (usb4_switch_version (tunnel->dst_port->sw) <2 )) +return 0 ; + +if (enable &&tb_port_get_link_generation (port) <4 )return 0 ; ret =usb4_pci_port_set_ext_encapsulation (tunnel->src_port, enable);if (ret)return ret; +/* +* Downstream router could be unplugged so disable of encapsulation +* in upstream router is still possible. +*/ ret =usb4_pci_port_set_ext_encapsulation (tunnel->dst_port, enable); -if (ret) -return ret; +if (ret) { +if (enable) +return ret; +if (ret != -ENODEV ) +return ret; + }tb_tunnel_dbg (tunnel,"extended encapsulation %s\n" ,str_enabled_disabled (enable));
Signature · 1 line
2.42.0
PATCH 11/11 thunderbolt: Add support for Intel Lunar Lake
In reply to Mika WesterbergIntel Lunar Lake has similar integrated Thunderbolt/USB4 controller as Intel Meteor Lake with some small differences in the host router (it has 3 DP IN adapters for instance). Add the Intel Lunar Lake PCI IDs to the driver list of supported devices.
--- drivers/thunderbolt/nhi.c | 4 ++++ drivers/thunderbolt/nhi.h | 2 ++ 2 files changed, 6 insertions(+)
drivers/thunderbolt/nhi.c +4 -0
@@ -1517,6 +1517,10 @@ static struct pci_device_id nhi_ids[] = { .driver_data = (kernel_ulong_t)&icl_nhi_ops }, { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_MTL_P_NHI1), .driver_data = (kernel_ulong_t)&icl_nhi_ops }, + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_LNL_NHI0), + .driver_data = (kernel_ulong_t)&icl_nhi_ops }, + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_LNL_NHI1), + .driver_data = (kernel_ulong_t)&icl_nhi_ops }, { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HOST_80G_NHI) }, { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HOST_40G_NHI) },
drivers/thunderbolt/nhi.h +2 -0
@@ -90,6 +90,8 @@ extern const struct tb_nhi_ops icl_nhi_ops;#define PCI_DEVICE_ID_INTEL_TGL_H_NHI1 0x9a21#define PCI_DEVICE_ID_INTEL_RPL_NHI0 0xa73e#define PCI_DEVICE_ID_INTEL_RPL_NHI1 0xa76d +#define PCI_DEVICE_ID_INTEL_LNL_NHI0 0xa833 +#define PCI_DEVICE_ID_INTEL_LNL_NHI1 0xa834#define PCI_CLASS_SERIAL_USB_USB4 0x0c0340
Signature · 1 line
2.42.0
Quoted 14 lines · Mika Westerberg
Hi all,
This series adds improvements around USB4 v2 support, PCIe tunneling, some minor fixes and also adds Intel Lunar Lake support.
Gil Fine (7):
thunderbolt: Handle lane bonding of Gen 4 XDomain links properly
thunderbolt: Movewidth_name()helper totb.h
thunderbolt: Log XDomain link speed and width
thunderbolt: Transition link to asymmetric only when both sides support it
thunderbolt: Improve logging when DisplayPort resource is added due to hotplug
thunderbolt: Make PCIe tunnel setup and teardown follow CM guide
thunderbolt: Disable PCIe extended encapsulation upon teardown properly
Quoted 5 lines
Mika Westerberg (4):
thunderbolt: Unwind TMU configuration iftb_switch_set_tmu_mode_params()fails
thunderbolt: Disable CL states only when actually needed
thunderbolt: Usetb_dp_read_cap()to readDP_COMMON_CAPas well
thunderbolt: Add support for Intel Lunar Lake
All applied to thunderbolt.git/next.