thunderbolt: DisplayPort and logging improvements & cleanups
Subsystems (3)
cover thunderbolt: DisplayPort and logging improvements & cleanups
Hi all,
This series improves the DisplayPort tunneling slightly to handle several "active" DP IN/OUT pairs so that for each of them a DP tunnel is created. It also improves pairing when eGPU with DP IN adapter is plugged in.
The rest are logging improvements and small cleanups here and there. I'm planning to merge these for v6.7.
Gil Fine (5):
thunderbolt: Fix debug log when DisplayPort adapter not available for pairing
thunderbolt: Fix typo of HPD bit for Hot Plug Detect
thunderbolt: Log NVM version of routers and retimers
thunderbolt: Create multiple DisplayPort tunnels if there are more DP IN/OUT pairs
thunderbolt: Add DP IN added last in the head of the list of DP resources
Mika Westerberg (8):
thunderbolt: dma_test: Use enum tb_link_width
thunderbolt: Get rid of usb4_usb3_port_actual_link_rate()
thunderbolt: Make tb_switch_clx_is_supported() static
thunderbolt: Check for unplugged router in tb_switch_clx_disable()
thunderbolt: Fix typo in enum tb_link_width kernel-doc
thunderbolt: Use tb_tunnel_dbg() where possible to make logging more consistent
thunderbolt: Expose tb_tunnel_xxx() log macros to the rest of the driver
thunderbolt: Use tb_tunnel_xxx() log macros in tb.c
drivers/thunderbolt/clx.c | 47 ++++++++------- drivers/thunderbolt/dma_test.c | 14 ++--- drivers/thunderbolt/retimer.c | 1 + drivers/thunderbolt/switch.c | 9 +-- drivers/thunderbolt/tb.c | 85 +++++++++++++++------------ drivers/thunderbolt/tb.h | 2 - drivers/thunderbolt/tb_regs.h | 7 +-- drivers/thunderbolt/tunnel.c | 102 ++++++++++++--------------------- drivers/thunderbolt/tunnel.h | 24 +++++++- drivers/thunderbolt/usb4.c | 29 ---------- include/linux/thunderbolt.h | 2 +- 11 files changed, 148 insertions(+), 174 deletions(-)
Signature · 1 line
2.40.1
PATCH 1/13 thunderbolt: dma_test: Use enum tb_link_width
Since we have it, use it in the DMA test driver as well.
--- drivers/thunderbolt/dma_test.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/thunderbolt/dma_test.c +5 -9
@@ -101,7 +101,7 @@ struct dma_test {unsigned int packets_sent;unsigned int packets_received;unsigned int link_speed; -unsigned int link_width; +enum tb_link_width link_width;unsigned int crc_errors;unsigned int buffer_overflow_errors;enum dma_test_result result;
@@ -465,9 +465,9 @@ DMA_TEST_DEBUGFS_ATTR(packets_to_send, packets_to_send_get,static int dma_test_set_bonding (struct dma_test *dt) {switch (dt->link_width) { -case 2 : +case TB_LINK_WIDTH_DUAL :return tb_xdomain_lane_bonding_enable (dt->xd); -case 1 : +case TB_LINK_WIDTH_SINGLE :tb_xdomain_lane_bonding_disable (dt->xd); fallthrough;default :
@@ -490,12 +490,8 @@ static void dma_test_check_errors(struct dma_test *dt, int ret)if (!dt->error_code) {if (dt->link_speed && dt->xd->link_speed != dt->link_speed) { dt->error_code =DMA_TEST_SPEED_ERROR ; - }else if (dt->link_width) { -const struct tb_xdomain *xd = dt->xd; - -if ((dt->link_width ==1 && xd->link_width !=TB_LINK_WIDTH_SINGLE ) || - (dt->link_width ==2 && xd->link_width <TB_LINK_WIDTH_DUAL )) - dt->error_code =DMA_TEST_WIDTH_ERROR ; + }else if (dt->link_width && dt->link_width != dt->xd->link_width) { + dt->error_code =DMA_TEST_WIDTH_ERROR ; }else if (dt->packets_to_send != dt->packets_sent || dt->packets_to_receive != dt->packets_received || dt->crc_errors || dt->buffer_overflow_errors) {
Signature · 1 line
2.40.1
PATCH 2/13 thunderbolt: Get rid of usb4_usb3_port_actual_link_rate()
In reply to Mika WesterbergIt turns out there is no need to use the actual link rate when reclaiming bandwidth for USB 3.x. The reason is that we use consumed bandwidth which is coming from xHCI when releasing bandwidth (for example for DisplayPort tunneling) and this can be anything between 1000 Mb/s to maximum, so when reclaiming we can just bump it up back to maximum instead of actual link rate (which is always <= maximum).
This allows us to get rid of couple of unnecessary lines of code.
--- drivers/thunderbolt/tb.h | 1 - drivers/thunderbolt/tb_regs.h | 3 --- drivers/thunderbolt/tunnel.c | 11 ++--------- drivers/thunderbolt/usb4.c | 29 ----------------------------- 4 files changed, 2 insertions(+), 42 deletions(-)
drivers/thunderbolt/tb.h +0 -1
@@ -1283,7 +1283,6 @@ int usb4_port_retimer_nvm_read(struct tb_port *port, u8 index, unsigned int address, void *buf, size_t size);int usb4_usb3_port_max_link_rate (struct tb_port *port); -int usb4_usb3_port_actual_link_rate (struct tb_port *port);int usb4_usb3_port_allocated_bandwidth (struct tb_port *port,int *upstream_bw,int *downstream_bw); int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw,
drivers/thunderbolt/tb_regs.h +0 -3
@@ -484,9 +484,6 @@ struct tb_regs_port_header {#define ADP_USB3_CS_3 0x03#define ADP_USB3_CS_3_SCALE_MASK GENMASK(5, 0)#define ADP_USB3_CS_4 0x04 -#define ADP_USB3_CS_4_ALR_MASK GENMASK(6, 0) -#define ADP_USB3_CS_4_ALR_20G 0x1 -#define ADP_USB3_CS_4_ULV BIT(7)#define ADP_USB3_CS_4_MSLR_MASK GENMASK(18, 12)#define ADP_USB3_CS_4_MSLR_SHIFT 12#define ADP_USB3_CS_4_MSLR_20G 0x1
drivers/thunderbolt/tunnel.c +2 -9
@@ -1790,17 +1790,10 @@ static void tb_usb3_reclaim_available_bandwidth(struct tb_tunnel *tunnel, {int ret, max_rate, allocate_up, allocate_down; - ret =usb4_usb3_port_actual_link_rate (tunnel->src_port); + ret =tb_usb3_max_link_rate (tunnel->dst_port, tunnel->src_port);if (ret <0 ) { -tb_tunnel_warn (tunnel,"failed to read actual link rate\n" ); +tb_tunnel_warn (tunnel,"failed to read maximum link rate\n" );return ; - }else if (!ret) { -/* Use maximum link rate if the link valid is not set */ - ret =tb_usb3_max_link_rate (tunnel->dst_port, tunnel->src_port); -if (ret <0 ) { -tb_tunnel_warn (tunnel,"failed to read maximum link rate\n" ); -return ; - } }/*
drivers/thunderbolt/usb4.c +0 -29
@@ -1946,35 +1946,6 @@ int usb4_usb3_port_max_link_rate(struct tb_port *port)return usb4_usb3_port_max_bandwidth (port, ret); } -/** -* usb4_usb3_port_actual_link_rate() - Established USB3 link rate -* @port: USB3 adapter port -* -* Return actual established link rate of a USB3 adapter in Mb/s. If the -* link is not up returns %0 and negative errno in case of failure. -*/ -int usb4_usb3_port_actual_link_rate (struct tb_port *port) -{ -int ret, lr; -u32 val; - -if (!tb_port_is_usb3_down (port) && !tb_port_is_usb3_up (port)) -return -EINVAL ; - - ret =tb_port_read (port, &val,TB_CFG_PORT , - port->cap_adap +ADP_USB3_CS_4 ,1 ); -if (ret) -return ret; - -if (!(val &ADP_USB3_CS_4_ULV )) -return 0 ; - - lr = val &ADP_USB3_CS_4_ALR_MASK ; - ret = lr ==ADP_USB3_CS_4_ALR_20G ?20000 :10000 ; - -return usb4_usb3_port_max_bandwidth (port, ret); -} -static int usb4_usb3_port_cm_request (struct tb_port *port,bool request) {int ret;
Signature · 1 line
2.40.1
PATCH 3/13 thunderbolt: Make tb_switch_clx_is_supported() static
In reply to Mika WesterbergThis function is not used outside of clx.c so make it static. No functional changes.
--- drivers/thunderbolt/clx.c | 44 +++++++++++++++++++-------------------- drivers/thunderbolt/tb.h | 1 - 2 files changed, 22 insertions(+), 23 deletions(-)
drivers/thunderbolt/clx.c +22 -22
@@ -174,6 +174,28 @@ bool tb_port_clx_is_enabled(struct tb_port *port, unsigned int clx)return !!(tb_port_clx (port) & clx); } +/** +* tb_switch_clx_is_supported() - Is CLx supported on this type of router +* @sw: The router to check CLx support for +*/ +static bool tb_switch_clx_is_supported (const struct tb_switch *sw) +{ +if (!clx_enabled) +return false; + +if (sw->quirks &QUIRK_NO_CLX ) +return false; + +/* +* CLx is not enabled and validated on Intel USB4 platforms +* before Alder Lake. +*/ +if (tb_switch_is_tiger_lake (sw)) +return false; + +return tb_switch_is_usb4 (sw) ||tb_switch_is_titan_ridge (sw); +} +/** * tb_switch_clx_init() - Initialize router CL states * @sw: Router
@@ -273,28 +295,6 @@ static int tb_switch_mask_clx_objections(struct tb_switch *sw) sw->cap_lp + offset, ARRAY_SIZE(val)); } -/** -* tb_switch_clx_is_supported() - Is CLx supported on this type of router -* @sw: The router to check CLx support for -*/ -bool tb_switch_clx_is_supported (const struct tb_switch *sw) -{ -if (!clx_enabled) -return false; - -if (sw->quirks &QUIRK_NO_CLX ) -return false; - -/* -* CLx is not enabled and validated on Intel USB4 platforms -* before Alder Lake. -*/ -if (tb_switch_is_tiger_lake (sw)) -return false; - -return tb_switch_is_usb4 (sw) ||tb_switch_is_titan_ridge (sw); -} -static bool validate_mask (unsigned int clx) {/* Previous states need to be enabled */
drivers/thunderbolt/tb.h +0 -1
@@ -1001,7 +1001,6 @@ static inline bool tb_switch_tmu_is_enabled(const struct tb_switch *sw)bool tb_port_clx_is_enabled (struct tb_port *port,unsigned int clx);int tb_switch_clx_init (struct tb_switch *sw); -bool tb_switch_clx_is_supported (const struct tb_switch *sw);int tb_switch_clx_enable (struct tb_switch *sw,unsigned int clx);int tb_switch_clx_disable (struct tb_switch *sw);
Signature · 1 line
2.40.1
PATCH 4/13 thunderbolt: Check for unplugged router in tb_switch_clx_disable()
In reply to Mika WesterbergThere is no point disabling CL states if the router is unplugged so in that case return early.
--- drivers/thunderbolt/clx.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/thunderbolt/clx.c +3 -0
@@ -405,6 +405,9 @@ int tb_switch_clx_disable(struct tb_switch *sw)if (!clx)return 0 ; +if (sw->is_unplugged) +return clx; + up =tb_upstream_port (sw); down =tb_switch_downstream_port (sw);
Signature · 1 line
2.40.1
PATCH 5/13 thunderbolt: Fix debug log when DisplayPort adapter not available for pairing
In reply to Mika WesterbergFrom: Gil Fine <[email protected]>
Fix debug log when looking for a DisplayPort adapter pair of DP IN and DP OUT. In case of no DP adapter available, log the type of the DP adapter that is not available.
--- drivers/thunderbolt/tb.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/thunderbolt/tb.c +3 -4
@@ -1311,13 +1311,12 @@ static void tb_tunnel_dp(struct tb *tb)continue ; } -tb_port_dbg (port,"DP IN available\n" ); + in = port; +tb_port_dbg (in,"DP IN available\n" ); out =tb_find_dp_out (tb, port); -if (out) { - in = port; +if (out)break ; - } }if (!in) {
Signature · 1 line
2.40.1
PATCH 6/13 thunderbolt: Fix typo in enum tb_link_width kernel-doc
In reply to Mika WesterbergTypo trasmitters -> transmitters.
--- include/linux/thunderbolt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/thunderbolt.h +1 -1
@@ -175,7 +175,7 @@ void tb_unregister_property_dir(const char *key, struct tb_property_dir *dir);* enum tb_link_width - Thunderbolt/USB4 link width * @TB_LINK_WIDTH_SINGLE: Single lane link * @TB_LINK_WIDTH_DUAL: Dual lane symmetric link -* @TB_LINK_WIDTH_ASYM_TX: Dual lane asymmetric Gen 4 link with 3 trasmitters +* @TB_LINK_WIDTH_ASYM_TX: Dual lane asymmetric Gen 4 link with 3 transmitters * @TB_LINK_WIDTH_ASYM_RX: Dual lane asymmetric Gen 4 link with 3 receivers */ enum tb_link_width {
Signature · 1 line
2.40.1
PATCH 7/13 thunderbolt: Fix typo of HPD bit for Hot Plug Detect
In reply to Mika WesterbergFrom: Gil Fine <[email protected]>
Fix typo of HPD bit stands for Hot Plug Detect.
--- drivers/thunderbolt/switch.c | 8 ++++---- drivers/thunderbolt/tb_regs.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/thunderbolt/switch.c +4 -4
@@ -1332,7 +1332,7 @@ int tb_pci_port_enable(struct tb_port *port, bool enable)* tb_dp_port_hpd_is_active() - Is HPD already active * @port: DP out port to check * -* Checks if the DP OUT adapter port has HDP bit already set. +* Checks if the DP OUT adapter port has HPD bit already set. */ int tb_dp_port_hpd_is_active (struct tb_port *port) {
@@ -1344,14 +1344,14 @@ int tb_dp_port_hpd_is_active(struct tb_port *port)if (ret)return ret; -return !!(data &ADP_DP_CS_2_HDP ); +return !!(data &ADP_DP_CS_2_HPD ); }/** * tb_dp_port_hpd_clear() - Clear HPD from DP IN port * @port: Port to clear HPD * -* If the DP IN port has HDP set, this function can be used to clear it. +* If the DP IN port has HPD set, this function can be used to clear it. */ int tb_dp_port_hpd_clear (struct tb_port *port) {
@@ -1363,7 +1363,7 @@ int tb_dp_port_hpd_clear(struct tb_port *port)if (ret)return ret; - data |=ADP_DP_CS_3_HDPC ; + data |=ADP_DP_CS_3_HPDC ;return tb_port_write (port, &data,TB_CFG_PORT , port->cap_adap +ADP_DP_CS_3 ,1 ); }
drivers/thunderbolt/tb_regs.h +2 -2
@@ -400,7 +400,7 @@ struct tb_regs_port_header {#define ADP_DP_CS_1_AUX_RX_HOPID_SHIFT 11#define ADP_DP_CS_2 0x02#define ADP_DP_CS_2_NRD_MLC_MASK GENMASK(2, 0) -#define ADP_DP_CS_2_HDP BIT(6) +#define ADP_DP_CS_2_HPD BIT(6)#define ADP_DP_CS_2_NRD_MLR_MASK GENMASK(9, 7)#define ADP_DP_CS_2_NRD_MLR_SHIFT 7#define ADP_DP_CS_2_CA BIT(10)
@@ -417,7 +417,7 @@ struct tb_regs_port_header {#define ADP_DP_CS_2_ESTIMATED_BW_MASK GENMASK(31, 24)#define ADP_DP_CS_2_ESTIMATED_BW_SHIFT 24#define ADP_DP_CS_3 0x03 -#define ADP_DP_CS_3_HDPC BIT(9) +#define ADP_DP_CS_3_HPDC BIT(9)#define DP_LOCAL_CAP 0x04#define DP_REMOTE_CAP 0x05/* For DP IN adapter */
Signature · 1 line
2.40.1
PATCH 8/13 thunderbolt: Use tb_tunnel_dbg() where possible to make logging more consistent
In reply to Mika WesterbergThis makes it easier to find out the tunnel in question. Also drop a couple of lines that generate duplicate information.
--- drivers/thunderbolt/tunnel.c | 65 +++++++++++++++++------------------- 1 file changed, 30 insertions(+), 35 deletions(-)
drivers/thunderbolt/tunnel.c +30 -35
@@ -614,8 +614,9 @@ static int tb_dp_xchg_caps(struct tb_tunnel *tunnel) in_rate =tb_dp_cap_get_rate (in_dp_cap); in_lanes =tb_dp_cap_get_lanes (in_dp_cap); -tb_port_dbg (in,"maximum supported bandwidth %u Mb/s x%u = %u Mb/s\n" , - in_rate, in_lanes,tb_dp_bandwidth (in_rate, in_lanes)); +tb_tunnel_dbg (tunnel, +"DP IN maximum supported bandwidth %u Mb/s x%u = %u Mb/s\n" , + in_rate, in_lanes,tb_dp_bandwidth (in_rate, in_lanes));/* * If the tunnel bandwidth is limited (max_bw is set) then see
@@ -624,8 +625,9 @@ static int tb_dp_xchg_caps(struct tb_tunnel *tunnel) out_rate =tb_dp_cap_get_rate (out_dp_cap); out_lanes =tb_dp_cap_get_lanes (out_dp_cap); bw =tb_dp_bandwidth (out_rate, out_lanes); -tb_port_dbg (out,"maximum supported bandwidth %u Mb/s x%u = %u Mb/s\n" , - out_rate, out_lanes, bw); +tb_tunnel_dbg (tunnel, +"DP OUT maximum supported bandwidth %u Mb/s x%u = %u Mb/s\n" , + out_rate, out_lanes, bw);if (in->sw->config.depth < out->sw->config.depth) max_bw = tunnel->max_down;
@@ -639,13 +641,14 @@ static int tb_dp_xchg_caps(struct tb_tunnel *tunnel) out_rate, out_lanes, &new_rate, &new_lanes);if (ret) { -tb_port_info (out,"not enough bandwidth for DP tunnel\n" ); +tb_tunnel_info (tunnel,"not enough bandwidth\n" );return ret; } new_bw =tb_dp_bandwidth (new_rate, new_lanes); -tb_port_dbg (out,"bandwidth reduced to %u Mb/s x%u = %u Mb/s\n" , - new_rate, new_lanes, new_bw); +tb_tunnel_dbg (tunnel, +"bandwidth reduced to %u Mb/s x%u = %u Mb/s\n" , + new_rate, new_lanes, new_bw);/* * Set new rate and number of lanes before writing it to
@@ -662,7 +665,7 @@ static int tb_dp_xchg_caps(struct tb_tunnel *tunnel)*/ if (tb_route (out->sw) &&tb_switch_is_titan_ridge (out->sw)) { out_dp_cap |=DP_COMMON_CAP_LTTPR_NS ; -tb_port_dbg (out,"disabling LTTPR\n" ); +tb_tunnel_dbg (tunnel,"disabling LTTPR\n" ); } return tb_port_write(in, &out_dp_cap, TB_CFG_PORT,
@@ -712,8 +715,8 @@ static int tb_dp_bandwidth_alloc_mode_enable(struct tb_tunnel *tunnel) lanes =min (in_lanes, out_lanes); tmp =tb_dp_bandwidth (rate, lanes); -tb_port_dbg (in,"non-reduced bandwidth %u Mb/s x%u = %u Mb/s\n" , rate, - lanes, tmp); +tb_tunnel_dbg (tunnel,"non-reduced bandwidth %u Mb/s x%u = %u Mb/s\n" , + rate, lanes, tmp); ret =usb4_dp_port_set_nrd (in, rate, lanes);if (ret)
@@ -728,15 +731,15 @@ static int tb_dp_bandwidth_alloc_mode_enable(struct tb_tunnel *tunnel) rate =min (in_rate, out_rate); tmp =tb_dp_bandwidth (rate, lanes); -tb_port_dbg (in, -"maximum bandwidth through allocation mode %u Mb/s x%u = %u Mb/s\n" , - rate, lanes, tmp); +tb_tunnel_dbg (tunnel, +"maximum bandwidth through allocation mode %u Mb/s x%u = %u Mb/s\n" , + rate, lanes, tmp);for (granularity =250 ; tmp / granularity >255 && granularity <=1000 ; granularity *=2 ) ; -tb_port_dbg (in,"granularity %d Mb/s\n" , granularity); +tb_tunnel_dbg (tunnel,"granularity %d Mb/s\n" , granularity);/* * Returns -EINVAL if granularity above is outside of the
@@ -756,7 +759,7 @@ static int tb_dp_bandwidth_alloc_mode_enable(struct tb_tunnel *tunnel)else estimated_bw = tunnel->max_up; -tb_port_dbg (in,"estimated bandwidth %d Mb/s\n" , estimated_bw); +tb_tunnel_dbg (tunnel,"estimated bandwidth %d Mb/s\n" , estimated_bw); ret =usb4_dp_port_set_estimated_bandwidth (in, estimated_bw);if (ret)
@@ -767,7 +770,7 @@ static int tb_dp_bandwidth_alloc_mode_enable(struct tb_tunnel *tunnel)if (ret)return ret; -tb_port_dbg (in,"bandwidth allocation mode enabled\n" ); +tb_tunnel_dbg (tunnel,"bandwidth allocation mode enabled\n" );return 0 ; }
@@ -788,7 +791,7 @@ static int tb_dp_init(struct tb_tunnel *tunnel)if (!usb4_dp_port_bandwidth_mode_supported (in))return 0 ; -tb_port_dbg (in,"bandwidth allocation mode supported\n" ); +tb_tunnel_dbg (tunnel,"bandwidth allocation mode supported\n" ); ret =usb4_dp_port_set_cm_id (in, tb->index);if (ret)
@@ -805,7 +808,7 @@ static void tb_dp_deinit(struct tb_tunnel *tunnel)return ;if (usb4_dp_port_bandwidth_mode_enabled (in)) {usb4_dp_port_set_cm_bandwidth_mode_supported (in, false); -tb_port_dbg (in,"bandwidth allocation mode disabled\n" ); +tb_tunnel_dbg (tunnel,"bandwidth allocation mode disabled\n" ); } }
@@ -921,9 +924,6 @@ static int tb_dp_bandwidth_mode_consumed_bandwidth(struct tb_tunnel *tunnel,if (allocated_bw == max_bw) allocated_bw = ret; -tb_port_dbg (in,"consumed bandwidth through allocation mode %d Mb/s\n" , - allocated_bw); -if (in->sw->config.depth < out->sw->config.depth) { *consumed_up =0 ; *consumed_down = allocated_bw;
@@ -1006,9 +1006,6 @@ static int tb_dp_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up,/* Now we can use BW mode registers to figure out the bandwidth */ /* TODO: need to handle discovery too */ tunnel->bw_mode = true; - -tb_port_dbg (in,"allocated bandwidth through allocation mode %d Mb/s\n" , - tmp);return 0 ; }
@@ -1035,8 +1032,7 @@ static int tb_dp_read_dprx(struct tb_tunnel *tunnel, u32 *rate, u32 *lanes, *rate =tb_dp_cap_get_rate (val); *lanes =tb_dp_cap_get_lanes (val); -tb_port_dbg (in,"consumed bandwidth through DPRX %d Mb/s\n" , -tb_dp_bandwidth (*rate, *lanes)); +tb_tunnel_dbg (tunnel,"DPRX read done\n" );return 0 ; }usleep_range (100 ,150 );
@@ -1073,9 +1069,6 @@ static int tb_dp_read_cap(struct tb_tunnel *tunnel, unsigned int cap, u32 *rate, *rate =tb_dp_cap_get_rate (val); *lanes =tb_dp_cap_get_lanes (val); - -tb_port_dbg (in,"bandwidth from %#x capability %d Mb/s\n" , cap, -tb_dp_bandwidth (*rate, *lanes));return 0 ; }
@@ -1253,8 +1246,9 @@ static void tb_dp_dump(struct tb_tunnel *tunnel) rate =tb_dp_cap_get_rate (dp_cap); lanes =tb_dp_cap_get_lanes (dp_cap); -tb_port_dbg (in,"maximum supported bandwidth %u Mb/s x%u = %u Mb/s\n" , - rate, lanes,tb_dp_bandwidth (rate, lanes)); +tb_tunnel_dbg (tunnel, +"DP IN maximum supported bandwidth %u Mb/s x%u = %u Mb/s\n" , + rate, lanes,tb_dp_bandwidth (rate, lanes)); out = tunnel->dst_port;
@@ -1265,8 +1259,9 @@ static void tb_dp_dump(struct tb_tunnel *tunnel) rate =tb_dp_cap_get_rate (dp_cap); lanes =tb_dp_cap_get_lanes (dp_cap); -tb_port_dbg (out,"maximum supported bandwidth %u Mb/s x%u = %u Mb/s\n" , - rate, lanes,tb_dp_bandwidth (rate, lanes)); +tb_tunnel_dbg (tunnel, +"DP OUT maximum supported bandwidth %u Mb/s x%u = %u Mb/s\n" , + rate, lanes,tb_dp_bandwidth (rate, lanes));if (tb_port_read (in, &dp_cap,TB_CFG_PORT , in->cap_adap +DP_REMOTE_CAP ,1 ))
@@ -1275,8 +1270,8 @@ static void tb_dp_dump(struct tb_tunnel *tunnel) rate =tb_dp_cap_get_rate (dp_cap); lanes =tb_dp_cap_get_lanes (dp_cap); -tb_port_dbg (in,"reduced bandwidth %u Mb/s x%u = %u Mb/s\n" , - rate, lanes,tb_dp_bandwidth (rate, lanes)); +tb_tunnel_dbg (tunnel,"reduced bandwidth %u Mb/s x%u = %u Mb/s\n" , + rate, lanes,tb_dp_bandwidth (rate, lanes)); }/**
Signature · 1 line
2.40.1
PATCH 9/13 thunderbolt: Expose tb_tunnel_xxx() log macros to the rest of the driver
In reply to Mika WesterbergIn order to allow more consistent logging of tunnel related information make these logging macros available to the rest of the driver.
--- drivers/thunderbolt/tunnel.c | 26 +++++--------------------- drivers/thunderbolt/tunnel.h | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 22 deletions(-)
drivers/thunderbolt/tunnel.c +5 -21
@@ -58,27 +58,6 @@ MODULE_PARM_DESC(bw_alloc_mode,static const char *const tb_tunnel_names[] = {"PCI" ,"DP" ,"DMA" ,"USB3" }; -#define __TB_TUNNEL_PRINT(level, tunnel, fmt, arg...) \ - do { \ - struct tb_tunnel *__tunnel = (tunnel); \ - level(__tunnel->tb, "%llx:%u <-> %llx:%u (%s): " fmt, \ - tb_route(__tunnel->src_port->sw), \ - __tunnel->src_port->port, \ - tb_route(__tunnel->dst_port->sw), \ - __tunnel->dst_port->port, \ - tb_tunnel_names[__tunnel->type], \ - ## arg); \ - } while (0) - -#define tb_tunnel_WARN(tunnel, fmt, arg...) \ - __TB_TUNNEL_PRINT(tb_WARN, tunnel, fmt, ##arg) -#define tb_tunnel_warn(tunnel, fmt, arg...) \ - __TB_TUNNEL_PRINT(tb_warn, tunnel, fmt, ##arg) -#define tb_tunnel_info(tunnel, fmt, arg...) \ - __TB_TUNNEL_PRINT(tb_info, tunnel, fmt, ##arg) -#define tb_tunnel_dbg(tunnel, fmt, arg...) \ - __TB_TUNNEL_PRINT(tb_dbg, tunnel, fmt, ##arg) -static inline unsigned int tb_usable_credits (const struct tb_port *port) {return port->total_credits - port->ctl_credits;
@@ -2375,3 +2354,8 @@ void tb_tunnel_reclaim_available_bandwidth(struct tb_tunnel *tunnel, tunnel->reclaim_available_bandwidth (tunnel, available_up, available_down); } + +const char *tb_tunnel_type_name (const struct tb_tunnel *tunnel) +{ +return tb_tunnel_names[tunnel->type]; +}
drivers/thunderbolt/tunnel.h +23 -1
@@ -137,5 +137,27 @@ static inline bool tb_tunnel_is_usb3(const struct tb_tunnel *tunnel)return tunnel->type ==TB_TUNNEL_USB3 ; } -#endif +const char *tb_tunnel_type_name (const struct tb_tunnel *tunnel); + +#define __TB_TUNNEL_PRINT(level, tunnel, fmt, arg...) \ + do { \ + struct tb_tunnel *__tunnel = (tunnel); \ + level(__tunnel->tb, "%llx:%u <-> %llx:%u (%s): " fmt, \ + tb_route(__tunnel->src_port->sw), \ + __tunnel->src_port->port, \ + tb_route(__tunnel->dst_port->sw), \ + __tunnel->dst_port->port, \ + tb_tunnel_type_name(__tunnel), \ + ## arg); \ + } while (0) +#define tb_tunnel_WARN(tunnel, fmt, arg...) \ + __TB_TUNNEL_PRINT(tb_WARN, tunnel, fmt, ##arg) +#define tb_tunnel_warn(tunnel, fmt, arg...) \ + __TB_TUNNEL_PRINT(tb_warn, tunnel, fmt, ##arg) +#define tb_tunnel_info(tunnel, fmt, arg...) \ + __TB_TUNNEL_PRINT(tb_info, tunnel, fmt, ##arg) +#define tb_tunnel_dbg(tunnel, fmt, arg...) \ + __TB_TUNNEL_PRINT(tb_dbg, tunnel, fmt, ##arg) + +#endif
Signature · 1 line
2.40.1
PATCH 10/13 thunderbolt: Use tb_tunnel_xxx() log macros in tb.c
In reply to Mika WesterbergNow that the macros are available we can use them in tb.c. This makes the log output more consistent.
--- drivers/thunderbolt/tb.c | 50 ++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 22 deletions(-)
drivers/thunderbolt/tb.c +28 -22
@@ -729,7 +729,7 @@ static void tb_reclaim_usb3_bandwidth(struct tb *tb, struct tb_port *src_port,if (!tunnel)return ; -tb_dbg (tb,"reclaiming unused bandwidth for USB3\n" ); +tb_tunnel_dbg (tunnel,"reclaiming unused bandwidth\n" );/* * Calculate available bandwidth for the first hop USB3 tunnel.
@@ -738,12 +738,12 @@ static void tb_reclaim_usb3_bandwidth(struct tb *tb, struct tb_port *src_port, ret =tb_available_bandwidth (tb, tunnel->src_port, tunnel->dst_port, &available_up, &available_down);if (ret) { -tb_warn (tb,"failed to calculate available bandwidth\n" ); +tb_tunnel_warn (tunnel,"failed to calculate available bandwidth\n" );return ; } -tb_dbg (tb,"available bandwidth for USB3 %d/%d Mb/s\n" , - available_up, available_down); +tb_tunnel_dbg (tunnel,"available bandwidth %d/%d Mb/s\n" , available_up, + available_down);tb_tunnel_reclaim_available_bandwidth (tunnel, &available_up, &available_down); }
@@ -1188,7 +1188,7 @@ tb_recalc_estimated_bandwidth_for_group(struct tb_bandwidth_group *group) ret =tb_release_unused_usb3_bandwidth (tb, first_tunnel->src_port, first_tunnel->dst_port);if (ret) { -tb_port_warn (in, +tb_tunnel_warn (tunnel,"failed to release unused bandwidth\n" );break ; }
@@ -1198,7 +1198,7 @@ tb_recalc_estimated_bandwidth_for_group(struct tb_bandwidth_group *group) ret =tb_available_bandwidth (tb, in, out, &estimated_up, &estimated_down);if (ret) { -tb_port_warn (in, +tb_tunnel_warn (tunnel,"failed to re-calculate estimated bandwidth\n" );break ; }
@@ -1209,8 +1209,9 @@ tb_recalc_estimated_bandwidth_for_group(struct tb_bandwidth_group *group)* - available bandwidth along the path * - bandwidth allocated for USB 3.x but not used. */ -tb_port_dbg (in,"re-calculated estimated bandwidth %u/%u Mb/s\n" , - estimated_up, estimated_down); +tb_tunnel_dbg (tunnel, +"re-calculated estimated bandwidth %u/%u Mb/s\n" , + estimated_up, estimated_down);if (in->sw->config.depth < out->sw->config.depth) estimated_bw = estimated_down;
@@ -1218,7 +1219,8 @@ tb_recalc_estimated_bandwidth_for_group(struct tb_bandwidth_group *group) estimated_bw = estimated_up;if (usb4_dp_port_set_estimated_bandwidth (in, estimated_bw)) -tb_port_warn (in,"failed to update estimated bandwidth\n" ); +tb_tunnel_warn (tunnel, +"failed to update estimated bandwidth\n" ); }if (first_tunnel)
@@ -1780,8 +1782,8 @@ static int tb_alloc_dp_bandwidth(struct tb_tunnel *tunnel, int *requested_up, in = tunnel->src_port; out = tunnel->dst_port; -tb_port_dbg (in,"bandwidth allocated currently %d/%d Mb/s\n" , - allocated_up, allocated_down); +tb_tunnel_dbg (tunnel,"bandwidth allocated currently %d/%d Mb/s\n" , + allocated_up, allocated_down);/* * If we get rounded up request from graphics side, say HBR2 x 4
@@ -1822,14 +1824,15 @@ static int tb_alloc_dp_bandwidth(struct tb_tunnel *tunnel, int *requested_up,else if (requested_down_corrected <0 ) requested_down_corrected =0 ; -tb_port_dbg (in,"corrected bandwidth request %d/%d Mb/s\n" , - requested_up_corrected, requested_down_corrected); +tb_tunnel_dbg (tunnel,"corrected bandwidth request %d/%d Mb/s\n" , + requested_up_corrected, requested_down_corrected);if ((*requested_up >=0 && requested_up_corrected > max_up_rounded) || (*requested_down >=0 && requested_down_corrected > max_down_rounded)) { -tb_port_dbg (in,"bandwidth request too high (%d/%d Mb/s > %d/%d Mb/s)\n" , - requested_up_corrected, requested_down_corrected, - max_up_rounded, max_down_rounded); +tb_tunnel_dbg (tunnel, +"bandwidth request too high (%d/%d Mb/s > %d/%d Mb/s)\n" , + requested_up_corrected, requested_down_corrected, + max_up_rounded, max_down_rounded);return -ENOBUFS ; }
@@ -1864,8 +1867,8 @@ static int tb_alloc_dp_bandwidth(struct tb_tunnel *tunnel, int *requested_up,if (ret) goto reclaim; -tb_port_dbg (in,"bandwidth available for allocation %d/%d Mb/s\n" , - available_up, available_down); +tb_tunnel_dbg (tunnel,"bandwidth available for allocation %d/%d Mb/s\n" , + available_up, available_down);if ((*requested_up >=0 && available_up >= requested_up_corrected) || (*requested_down >=0 && available_down >= requested_down_corrected)) {
@@ -1947,12 +1950,15 @@ static void tb_handle_dp_bandwidth_request(struct work_struct *work) ret =tb_alloc_dp_bandwidth (tunnel, &requested_up, &requested_down);if (ret) {if (ret == -ENOBUFS ) -tb_port_warn (in,"not enough bandwidth available\n" ); +tb_tunnel_warn (tunnel, +"not enough bandwidth available\n" );else -tb_port_warn (in,"failed to change bandwidth allocation\n" ); +tb_tunnel_warn (tunnel, +"failed to change bandwidth allocation\n" ); }else { -tb_port_dbg (in,"bandwidth allocation changed to %d/%d Mb/s\n" , - requested_up, requested_down); +tb_tunnel_dbg (tunnel, +"bandwidth allocation changed to %d/%d Mb/s\n" , + requested_up, requested_down);/* Update other clients about the allocation change */ tb_recalc_estimated_bandwidth (tb);
Signature · 1 line
2.40.1
PATCH 11/13 thunderbolt: Log NVM version of routers and retimers
In reply to Mika WesterbergFrom: Gil Fine <[email protected]>
This is useful when debugging possible issues.
--- drivers/thunderbolt/retimer.c | 1 + drivers/thunderbolt/switch.c | 1 + 2 files changed, 2 insertions(+)
drivers/thunderbolt/retimer.c +1 -0
@@ -94,6 +94,7 @@ static int tb_retimer_nvm_add(struct tb_retimer *rt) goto err_nvm; rt->nvm = nvm; +dev_dbg (&rt->dev,"NVM version %x.%x\n" , nvm->major, nvm->minor);return 0 ; err_nvm:
drivers/thunderbolt/switch.c +1 -0
@@ -372,6 +372,7 @@ static int tb_switch_nvm_add(struct tb_switch *sw) ret =tb_nvm_add_active (nvm, nvm_read);if (ret) goto err_nvm; +tb_sw_dbg (sw,"NVM version %x.%x\n" , nvm->major, nvm->minor); }if (!sw->no_nvm_upgrade) {
Signature · 1 line
2.40.1
PATCH 12/13 thunderbolt: Create multiple DisplayPort tunnels if there are more DP IN/OUT pairs
In reply to Mika WesterbergFrom: Gil Fine <[email protected]>
Currently we only create one DisplayPort tunnel even if there would be more DP IN/OUT pairs available. Specifically this happens when a router is unplugged and we check if a new DisplayPort tunnel can be created. To cover this create tunnels as long as we find suitable DP IN/OUT pairs.
--- drivers/thunderbolt/tb.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
drivers/thunderbolt/tb.c +17 -9
@@ -1284,18 +1284,13 @@ static struct tb_port *tb_find_dp_out(struct tb *tb, struct tb_port *in)return NULL ; } -static void tb_tunnel_dp (struct tb *tb) +static bool tb_tunnel_one_dp (struct tb *tb) {int available_up, available_down, ret, link_nr;struct tb_cm *tcm =tb_priv (tb);struct tb_port *port, *in, *out;struct tb_tunnel *tunnel; -if (!tb_acpi_may_tunnel_dp ()) { -tb_dbg (tb,"DP tunneling disabled, not creating tunnel\n" ); -return ; - } -/* * Find pair of inactive DP IN and DP OUT adapters and then * establish a DP tunnel between them.
@@ -1323,11 +1318,11 @@ static void tb_tunnel_dp(struct tb *tb)if (!in) {tb_dbg (tb,"no suitable DP IN adapter available, not tunneling\n" ); -return ; +return false; }if (!out) {tb_dbg (tb,"no suitable DP OUT adapter available, not tunneling\n" ); -return ; +return false; }/*
@@ -1400,7 +1395,7 @@ static void tb_tunnel_dp(struct tb *tb)* TMU mode to HiFi for CL0s to work. */ tb_increase_tmu_accuracy (tunnel); -return ; +return true; err_free:tb_tunnel_free (tunnel);
@@ -1415,6 +1410,19 @@ static void tb_tunnel_dp(struct tb *tb)pm_runtime_put_autosuspend (&out->sw->dev);pm_runtime_mark_last_busy (&in->sw->dev);pm_runtime_put_autosuspend (&in->sw->dev); + +return false; +} + +static void tb_tunnel_dp (struct tb *tb) +{ +if (!tb_acpi_may_tunnel_dp ()) { +tb_dbg (tb,"DP tunneling disabled, not creating tunnel\n" ); +return ; + } + +while (tb_tunnel_one_dp (tb)) + ; }static void tb_dp_resource_unavailable (struct tb *tb,struct tb_port *port)
Signature · 1 line
2.40.1
PATCH 13/13 thunderbolt: Add DP IN added last in the head of the list of DP resources
In reply to Mika WesterbergFrom: Gil Fine <[email protected]>
If DP IN on device router exist, position it at the beginning of the DP resources list, so that it is used before DP IN on host router. This way external GPU will be prioritized when pairing DP IN and DP OUT for DisplayPort tunnel setup.
--- drivers/thunderbolt/tb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/tb.c +1 -1
@@ -190,7 +190,7 @@ static void tb_add_dp_resources(struct tb_switch *sw)if (!tb_switch_query_dp_resource (sw, port))continue ; -list_add_tail (&port->list, &tcm->dp_resources); +list_add (&port->list, &tcm->dp_resources);tb_port_dbg (port,"DP IN resource available\n" ); } }
Signature · 1 line
2.40.1
Quoted 7 lines · Mika Westerberg
Gil Fine (5):
thunderbolt: Fix debug log when DisplayPort adapter not available for pairing
thunderbolt: Fix typo of HPD bit for Hot Plug Detect
thunderbolt: Log NVM version of routers and retimers
thunderbolt: Create multiple DisplayPort tunnels if there are more DP IN/OUT pairs
thunderbolt: Add DP IN added last in the head of the list of DP resources
Quoted 9 lines
Mika Westerberg (8):
thunderbolt:dma_test: Use enumtb_link_width
thunderbolt: Get rid ofusb4_usb3_port_actual_link_rate()
thunderbolt: Maketb_switch_clx_is_supported()static
thunderbolt: Check for unplugged router intb_switch_clx_disable()
thunderbolt: Fix typo in enumtb_link_widthkernel-doc
thunderbolt: Usetb_tunnel_dbg()where possible to make logging more consistent
thunderbolt: Exposetb_tunnel_xxx()log macros to the rest of the driver
thunderbolt: Usetb_tunnel_xxx()log macros intb.c
All applied to thunderbolt.git/next.