thunderbolt: Rework TMU and CLx support
Subsystems (2)
cover thunderbolt: Rework TMU and CLx support
Hi all,
This series reworks the TMU and CLx support code to match better what we do elsewhere in the driver and prepares for USB4v2 adaptive TMU support that we are going to add in the subsequent series (I'm sending that out later this week). I've split this part as separate from USB4v2 support hoping that it makes reviewing them easier.
Gil Fine (1):
thunderbolt: Introduce tb_switch_downstream_port()
Mika Westerberg (19):
thunderbolt: Introduce tb_xdomain_downstream_port()
thunderbolt: Fix a couple of style issues in TMU code
thunderbolt: Drop useless 'unidirectional' parameter from tb_switch_tmu_is_enabled()
thunderbolt: Rework Titan Ridge TMU objection disable function
thunderbolt: Get rid of tb_switch_enable_tmu_1st_child()
thunderbolt: Move TMU configuration to tb_enable_tmu()
thunderbolt: Move tb_enable_tmu() close to other TMU functions
thunderbolt: Check valid TMU configuration in tb_switch_tmu_configure()
thunderbolt: Move CLx support functions into clx.c
thunderbolt: Get rid of __tb_switch_[en|dis]able_clx()
thunderbolt: Move CLx enabling into tb_enable_clx()
thunderbolt: Switch CL states from enum to a bitmask
thunderbolt: Check for first depth router in tb.c
thunderbolt: Do not call CLx functions from TMU code
thunderbolt: Prefix TMU post time log message with "TMU: "
thunderbolt: Prefix CL state related log messages with "CLx: "
thunderbolt: Initialize CL states from the hardware
thunderbolt: Make tb_switch_clx_disable() return CL states that were enabled
thunderbolt: Disable CL states when a DMA tunnel is established
drivers/thunderbolt/Makefile | 2 +- drivers/thunderbolt/acpi.c | 5 +- drivers/thunderbolt/clx.c | 416 ++++++++++++++++++++++++++++++++++ drivers/thunderbolt/debugfs.c | 35 ++- drivers/thunderbolt/icm.c | 24 +- drivers/thunderbolt/switch.c | 378 +----------------------------- drivers/thunderbolt/tb.c | 227 +++++++++++++------ drivers/thunderbolt/tb.h | 102 ++++----- drivers/thunderbolt/tmu.c | 152 ++++--------- drivers/thunderbolt/usb4.c | 9 +- drivers/thunderbolt/xdomain.c | 16 +- 11 files changed, 719 insertions(+), 647 deletions(-) create mode 100644 drivers/thunderbolt/clx.c
Signature · 1 line
2.39.2
PATCH 4/20 thunderbolt: Drop useless 'unidirectional' parameter from tb_switch_tmu_is_enabled()
There is no point passing it as we already have a field for that. While there clean up the kernel-doc of things that do not really belong to the API documentation (these can be figured out from the spec itself).
No functional changes.
--- drivers/thunderbolt/tb.c | 2 +- drivers/thunderbolt/tb.h | 10 ++++------ drivers/thunderbolt/tmu.c | 11 ++++------- 3 files changed, 9 insertions(+), 14 deletions(-)
drivers/thunderbolt/tb.c +1 -1
@@ -362,7 +362,7 @@ static int tb_enable_tmu(struct tb_switch *sw)int ret;/* If it is already enabled in correct mode, don't touch it */ -if (tb_switch_tmu_is_enabled (sw, sw->tmu.unidirectional_request)) +if (tb_switch_tmu_is_enabled (sw))return 0 ; ret =tb_switch_tmu_disable (sw);
drivers/thunderbolt/tb.h +4 -6
@@ -995,16 +995,14 @@ void tb_switch_enable_tmu_1st_child(struct tb_switch *sw,/** * tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled * @sw: Router whose TMU mode to check -* @unidirectional: If uni-directional (bi-directional otherwise) * -* Return true if hardware TMU configuration matches the one passed in -* as parameter. That is HiFi/Normal and either uni-directional or bi-directional. +* Return true if hardware TMU configuration matches the requested +* configuration. */ -static inline bool tb_switch_tmu_is_enabled (const struct tb_switch *sw, -bool unidirectional) +static inline bool tb_switch_tmu_is_enabled (const struct tb_switch *sw) {return sw->tmu.rate == sw->tmu.rate_request && - sw->tmu.unidirectional == unidirectional; + sw->tmu.unidirectional == sw->tmu.unidirectional_request; }static inline const char *tb_switch_clx_name (enum tb_clx clx)
drivers/thunderbolt/tmu.c +4 -7
@@ -639,12 +639,9 @@ static int tb_switch_tmu_change_mode(struct tb_switch *sw)* tb_switch_tmu_enable() - Enable TMU on a router * @sw: Router whose TMU to enable * -* Enables TMU of a router to be in uni-directional Normal/HiFi -* or bi-directional HiFi mode. Calling tb_switch_tmu_configure() is required -* before calling this function, to select the mode Normal/HiFi and -* directionality (uni-directional/bi-directional). -* In HiFi mode all tunneling should work. In Normal mode, DP tunneling can't -* work. Uni-directional mode is required for CLx (Link Low-Power) to work. +* Enables TMU of a router to be in uni-directional Normal/HiFi or +* bi-directional HiFi mode. Calling tb_switch_tmu_configure() is +* required before calling this function. */ int tb_switch_tmu_enable (struct tb_switch *sw) {
@@ -662,7 +659,7 @@ int tb_switch_tmu_enable(struct tb_switch *sw)if (!tb_switch_is_clx_supported (sw))return 0 ; -if (tb_switch_tmu_is_enabled (sw, sw->tmu.unidirectional_request)) +if (tb_switch_tmu_is_enabled (sw))return 0 ;if (tb_switch_is_titan_ridge (sw) && unidirectional) {
Signature · 1 line
2.39.2
PATCH 2/20 thunderbolt: Introduce tb_xdomain_downstream_port()
In reply to Mika WesterbergIn the same way we did for the routers add a function that returns the parent routers downstream facing port for XDomain devices.
--- drivers/thunderbolt/tb.h | 11 +++++++++++ drivers/thunderbolt/xdomain.c | 16 +++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-)
drivers/thunderbolt/tb.h +11 -0
@@ -1197,6 +1197,17 @@ static inline struct tb_switch *tb_xdomain_parent(struct tb_xdomain *xd)return tb_to_switch (xd->dev.parent); } +/** +* tb_xdomain_downstream_port() - Return downstream facing port of parent router +* @xd: Xdomain pointer +* +* Returns the downstream port the XDomain is connected to. +*/ +static inline struct tb_port *tb_xdomain_downstream_port (struct tb_xdomain *xd) +{ +return tb_port_at (xd->route,tb_xdomain_parent (xd)); +} +int tb_retimer_nvm_read (struct tb_retimer *rt,unsigned int address,void *buf,size_t size);int tb_retimer_scan (struct tb_port *port,bool add);
drivers/thunderbolt/xdomain.c +7 -9
@@ -537,9 +537,8 @@ static int tb_xdp_link_state_status_request(struct tb_ctl *ctl, u64 route,static int tb_xdp_link_state_status_response (struct tb *tb,struct tb_ctl *ctl,struct tb_xdomain *xd,u8 sequence) { -struct tb_switch *sw =tb_to_switch (xd->dev.parent);struct tb_xdp_link_state_status_response res; -struct tb_port *port =tb_port_at (xd->route, sw); +struct tb_port *port =tb_xdomain_downstream_port (xd);u32 val[2 ];int ret;
@@ -1137,7 +1136,7 @@ static int tb_xdomain_update_link_attributes(struct tb_xdomain *xd)struct tb_port *port;int ret; - port =tb_port_at (xd->route,tb_xdomain_parent (xd)); + port =tb_xdomain_downstream_port (xd); ret =tb_port_get_link_speed (port);if (ret <0 )
@@ -1251,8 +1250,7 @@ static int tb_xdomain_get_link_status(struct tb_xdomain *xd)static int tb_xdomain_link_state_change (struct tb_xdomain *xd,unsigned int width) { -struct tb_switch *sw =tb_to_switch (xd->dev.parent); -struct tb_port *port =tb_port_at (xd->route, sw); +struct tb_port *port =tb_xdomain_downstream_port (xd);struct tb *tb = xd->tb;u8 tlw, tls;u32 val;
@@ -1309,7 +1307,7 @@ static int tb_xdomain_bond_lanes_uuid_high(struct tb_xdomain *xd)return -ETIMEDOUT ; } - port =tb_port_at (xd->route,tb_xdomain_parent (xd)); + port =tb_xdomain_downstream_port (xd);/* * We can't use tb_xdomain_lane_bonding_enable() here because it
@@ -1425,7 +1423,7 @@ static int tb_xdomain_get_properties(struct tb_xdomain *xd)if (xd->bonding_possible) {struct tb_port *port; - port =tb_port_at (xd->route,tb_xdomain_parent (xd)); + port =tb_xdomain_downstream_port (xd);if (!port->bonded)tb_port_disable (port->dual_link_port); }
@@ -1979,7 +1977,7 @@ int tb_xdomain_lane_bonding_enable(struct tb_xdomain *xd)struct tb_port *port;int ret; - port =tb_port_at (xd->route,tb_xdomain_parent (xd)); + port =tb_xdomain_downstream_port (xd);if (!port->dual_link_port)return -ENODEV ;
@@ -2024,7 +2022,7 @@ void tb_xdomain_lane_bonding_disable(struct tb_xdomain *xd) {struct tb_port *port; - port =tb_port_at (xd->route,tb_xdomain_parent (xd)); + port =tb_xdomain_downstream_port (xd);if (port->dual_link_port) {tb_port_lane_bonding_disable (port);if (tb_port_wait_for_link_width (port,1 ,100 ) == -ETIMEDOUT )
Signature · 1 line
2.39.2
PATCH 9/20 thunderbolt: Check valid TMU configuration in tb_switch_tmu_configure()
In reply to Mika WesterbergInstead of at enable time we can do this already in tb_switch_tmu_configure().
--- drivers/thunderbolt/tb.c | 6 ++++-- drivers/thunderbolt/tb.h | 5 ++--- drivers/thunderbolt/tmu.c | 13 ++++++++----- 3 files changed, 14 insertions(+), 10 deletions(-)
drivers/thunderbolt/tb.c +4 -2
@@ -282,9 +282,11 @@ static int tb_enable_tmu(struct tb_switch *sw)* highest accuracy. */ if (tb_switch_is_clx_enabled (sw,TB_CL1 )) -tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_NORMAL , true); + ret =tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_NORMAL , true);else -tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_HIFI , false); + ret =tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_HIFI , false); +if (ret) +return ret;/* If it is already enabled in correct mode, don't touch it */ if (tb_switch_tmu_is_enabled (sw))
drivers/thunderbolt/tb.h +2 -3
@@ -987,9 +987,8 @@ int tb_switch_tmu_init(struct tb_switch *sw);int tb_switch_tmu_post_time (struct tb_switch *sw);int tb_switch_tmu_disable (struct tb_switch *sw);int tb_switch_tmu_enable (struct tb_switch *sw); -void tb_switch_tmu_configure (struct tb_switch *sw, -enum tb_switch_tmu_rate rate, -bool unidirectional); +int tb_switch_tmu_configure (struct tb_switch *sw,enum tb_switch_tmu_rate rate, +bool unidirectional);/** * tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled * @sw: Router whose TMU mode to check
drivers/thunderbolt/tmu.c +8 -5
@@ -648,9 +648,6 @@ int tb_switch_tmu_enable(struct tb_switch *sw)bool unidirectional = sw->tmu.unidirectional_request;int ret; -if (unidirectional && !sw->tmu.has_ucap) -return -EOPNOTSUPP ; -/* * No need to enable TMU on devices that don't support CLx since on * these devices e.g. Alpine Ridge and earlier, the TMU mode HiFi
@@ -724,10 +721,16 @@ int tb_switch_tmu_enable(struct tb_switch *sw)* * Selects the rate of the TMU and directionality (uni-directional or * bi-directional). Must be called before tb_switch_tmu_enable(). +* +* Returns %0 in success and negative errno otherwise. */ -void tb_switch_tmu_configure (struct tb_switch *sw, -enum tb_switch_tmu_rate rate,bool unidirectional) +int tb_switch_tmu_configure (struct tb_switch *sw,enum tb_switch_tmu_rate rate, +bool unidirectional) { +if (unidirectional && !sw->tmu.has_ucap) +return -EINVAL ; + sw->tmu.unidirectional_request = unidirectional; sw->tmu.rate_request = rate; +return 0 ; }
Signature · 1 line
2.39.2
PATCH 3/20 thunderbolt: Fix a couple of style issues in TMU code
In reply to Mika WesterbergDrop extra empty line and get rid of the '__' in function names. No functional changes.
--- drivers/thunderbolt/tmu.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
drivers/thunderbolt/tmu.c +11 -12
@@ -395,7 +395,6 @@ int tb_switch_tmu_disable(struct tb_switch *sw)if (sw->tmu.rate ==TB_SWITCH_TMU_RATE_OFF )return 0 ; -if (tb_route (sw)) {bool unidirectional = sw->tmu.unidirectional;struct tb_port *down, *up;
@@ -439,7 +438,7 @@ int tb_switch_tmu_disable(struct tb_switch *sw)return 0 ; } -static void __tb_switch_tmu_off (struct tb_switch *sw,bool unidirectional) +static void tb_switch_tmu_off (struct tb_switch *sw,bool unidirectional) {struct tb_port *down, *up;
@@ -469,7 +468,7 @@ static void __tb_switch_tmu_off(struct tb_switch *sw, bool unidirectional)* This function is called when the previous TMU mode was * TB_SWITCH_TMU_RATE_OFF. */ -static int __tb_switch_tmu_enable_bidirectional (struct tb_switch *sw) +static int tb_switch_tmu_enable_bidirectional (struct tb_switch *sw) {struct tb_port *up, *down;int ret;
@@ -500,7 +499,7 @@ static int __tb_switch_tmu_enable_bidirectional(struct tb_switch *sw)return 0 ; out: -__tb_switch_tmu_off (sw, false); +tb_switch_tmu_off (sw, false);return ret; }
@@ -533,7 +532,7 @@ static int tb_switch_tmu_unidirectional_enable(struct tb_switch *sw)* This function is called when the previous TMU mode was * TB_SWITCH_TMU_RATE_OFF. */ -static int __tb_switch_tmu_enable_unidirectional (struct tb_switch *sw) +static int tb_switch_tmu_enable_unidirectional (struct tb_switch *sw) {struct tb_port *up, *down;int ret;
@@ -568,11 +567,11 @@ static int __tb_switch_tmu_enable_unidirectional(struct tb_switch *sw)return 0 ; out: -__tb_switch_tmu_off (sw, true); +tb_switch_tmu_off (sw, true);return ret; } -static void __tb_switch_tmu_change_mode_prev (struct tb_switch *sw) +static void tb_switch_tmu_change_mode_prev (struct tb_switch *sw) {struct tb_port *down, *up;
@@ -594,7 +593,7 @@ static void __tb_switch_tmu_change_mode_prev(struct tb_switch *sw)tb_port_tmu_set_unidirectional (up, sw->tmu.unidirectional); } -static int __tb_switch_tmu_change_mode (struct tb_switch *sw) +static int tb_switch_tmu_change_mode (struct tb_switch *sw) {struct tb_port *up, *down;int ret;
@@ -632,7 +631,7 @@ static int __tb_switch_tmu_change_mode(struct tb_switch *sw)return 0 ; out: -__tb_switch_tmu_change_mode_prev (sw); +tb_switch_tmu_change_mode_prev (sw);return ret; }
@@ -695,13 +694,13 @@ int tb_switch_tmu_enable(struct tb_switch *sw)*/ if (sw->tmu.rate ==TB_SWITCH_TMU_RATE_OFF ) {if (unidirectional) - ret =__tb_switch_tmu_enable_unidirectional (sw); + ret =tb_switch_tmu_enable_unidirectional (sw);else - ret =__tb_switch_tmu_enable_bidirectional (sw); + ret =tb_switch_tmu_enable_bidirectional (sw);if (ret)return ret; }else if (sw->tmu.rate ==TB_SWITCH_TMU_RATE_NORMAL ) { - ret =__tb_switch_tmu_change_mode (sw); + ret =tb_switch_tmu_change_mode (sw);if (ret)return ret; }
Signature · 1 line
2.39.2
PATCH 6/20 thunderbolt: Get rid of tb_switch_enable_tmu_1st_child()
In reply to Mika WesterbergThis is better to be part of the software connection manager flows in tb.c. Also name the new function tb_increase_tmu_accuracy() to match what it actually does.
--- drivers/thunderbolt/tb.c | 43 +++++++++++++++++++++++++++++++-------- drivers/thunderbolt/tb.h | 2 -- drivers/thunderbolt/tmu.c | 29 -------------------------- 3 files changed, 34 insertions(+), 40 deletions(-)
drivers/thunderbolt/tb.c +34 -9
@@ -240,6 +240,38 @@ static void tb_discover_dp_resources(struct tb *tb) } } +static int tb_increase_switch_tmu_accuracy (struct device *dev,void *data) +{ +struct tb_switch *sw; + + sw =tb_to_switch (dev); +if (sw) { +tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_HIFI , +tb_switch_is_clx_enabled (sw,TB_CL1 )); +if (tb_switch_tmu_enable (sw)) +tb_sw_warn (sw,"failed to increase TMU rate\n" ); + } + +return 0 ; +} + +static void tb_increase_tmu_accuracy (struct tb_tunnel *tunnel) +{ +struct tb_switch *sw; + +if (!tunnel) +return ; + +/* +* Once first DP tunnel is established we change the TMU +* accuracy of first depth child routers (and the host router) +* to the highest. This is needed for the DP tunneling to work +* but also allows CL0s. +*/ + sw = tunnel->tb->root_switch; +device_for_each_child (&sw->dev,NULL , tb_increase_switch_tmu_accuracy); +} +static void tb_switch_discover_tunnels (struct tb_switch *sw,struct list_head *list,bool alloc_hopids)
@@ -253,13 +285,7 @@ static void tb_switch_discover_tunnels(struct tb_switch *sw,switch (port->config.type) {case TB_TYPE_DP_HDMI_IN : tunnel =tb_tunnel_discover_dp (tb, port, alloc_hopids); -/* -* In case of DP tunnel exists, change host router's -* 1st children TMU mode to HiFi for CL0s to work. -*/ -if (tunnel) -tb_switch_enable_tmu_1st_child (tb->root_switch, -TB_SWITCH_TMU_RATE_HIFI ); +tb_increase_tmu_accuracy (tunnel);break ;case TB_TYPE_PCIE_DOWN :
@@ -1263,8 +1289,7 @@ static void tb_tunnel_dp(struct tb *tb)* In case of DP tunnel exists, change host router's 1st children * TMU mode to HiFi for CL0s to work. */ -tb_switch_enable_tmu_1st_child (tb->root_switch,TB_SWITCH_TMU_RATE_HIFI ); - +tb_increase_tmu_accuracy (tunnel);return ; err_free:
drivers/thunderbolt/tb.h +0 -2
@@ -990,8 +990,6 @@ int tb_switch_tmu_enable(struct tb_switch *sw);void tb_switch_tmu_configure (struct tb_switch *sw,enum tb_switch_tmu_rate rate,bool unidirectional); -void tb_switch_enable_tmu_1st_child (struct tb_switch *sw, -enum tb_switch_tmu_rate rate);/** * tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled * @sw: Router whose TMU mode to check
drivers/thunderbolt/tmu.c +0 -29
@@ -731,32 +731,3 @@ void tb_switch_tmu_configure(struct tb_switch *sw, sw->tmu.unidirectional_request = unidirectional; sw->tmu.rate_request = rate; } - -static int tb_switch_tmu_config_enable (struct device *dev,void *rate) -{ -if (tb_is_switch (dev)) { -struct tb_switch *sw =tb_to_switch (dev); - -tb_switch_tmu_configure (sw, *(enum tb_switch_tmu_rate *)rate, -tb_switch_is_clx_enabled (sw,TB_CL1 )); -if (tb_switch_tmu_enable (sw)) -tb_sw_dbg (sw,"fail switching TMU mode for 1st depth router\n" ); - } - -return 0 ; -} - -/** -* tb_switch_enable_tmu_1st_child - Configure and enable TMU for 1st chidren -* @sw: The router to configure and enable it's children TMU -* @rate: Rate of the TMU to configure the router's chidren to -* -* Configures and enables the TMU mode of 1st depth children of the specified -* router to the specified rate. -*/ -void tb_switch_enable_tmu_1st_child (struct tb_switch *sw, -enum tb_switch_tmu_rate rate) -{ -device_for_each_child (&sw->dev, &rate, - tb_switch_tmu_config_enable); -}
Signature · 1 line
2.39.2
PATCH 1/20 thunderbolt: Introduce tb_switch_downstream_port()
In reply to Mika WesterbergFrom: Gil Fine <[email protected]>
Introduce tb_switch_downstream_port() helper function that returns the downstream port of a parent switch that is connected to the upstream port of specified switch. From now on, we use it all across the driver where applicable.
While there fix a whitespace in comment and rename 'downstream' to 'down' to be consistent with the rest of the driver.
--- drivers/thunderbolt/acpi.c | 5 ++--- drivers/thunderbolt/icm.c | 24 ++++++++++-------------- drivers/thunderbolt/switch.c | 19 +++++++------------ drivers/thunderbolt/tb.c | 8 +++----- drivers/thunderbolt/tb.h | 14 ++++++++++++++ drivers/thunderbolt/tmu.c | 29 +++++++++++++---------------- drivers/thunderbolt/usb4.c | 9 ++++----- 7 files changed, 53 insertions(+), 55 deletions(-)
drivers/thunderbolt/acpi.c +2 -3
@@ -296,16 +296,15 @@ static bool tb_acpi_bus_match(struct device *dev)static struct acpi_device *tb_acpi_switch_find_companion (struct tb_switch *sw) { +struct tb_switch *parent_sw =tb_switch_parent (sw);struct acpi_device *adev =NULL ; -struct tb_switch *parent_sw;/* * Device routers exists under the downstream facing USB4 port * of the parent router. Their _ADR is always 0. */ - parent_sw =tb_switch_parent (sw);if (parent_sw) { -struct tb_port *port =tb_port_at (tb_route (sw), parent_sw); +struct tb_port *port =tb_switch_downstream_port (sw);struct acpi_device *port_adev; port_adev = acpi_find_child_by_adr(ACPI_COMPANION(&parent_sw->dev),
drivers/thunderbolt/icm.c +10 -14
@@ -644,13 +644,14 @@ static int add_switch(struct tb_switch *parent_sw, struct tb_switch *sw)return ret; } -static void update_switch (struct tb_switch *parent_sw,struct tb_switch *sw, -u64 route,u8 connection_id,u8 connection_key, -u8 link,u8 depth,bool boot) +static void update_switch (struct tb_switch *sw,u64 route,u8 connection_id, +u8 connection_key,u8 link,u8 depth,bool boot) { +struct tb_switch *parent_sw =tb_switch_parent (sw); +/* Disconnect from parent */ -tb_port_at (tb_route (sw), parent_sw)->remote =NULL ; -/* Re-connect via updated port*/ +tb_switch_downstream_port (sw)->remote =NULL ; +/* Re-connect via updated port */ tb_port_at (route, parent_sw)->remote =tb_upstream_port (sw);/* Update with the new addressing information */
@@ -671,10 +672,7 @@ static void update_switch(struct tb_switch *parent_sw, struct tb_switch *sw,static void remove_switch (struct tb_switch *sw) { -struct tb_switch *parent_sw; - - parent_sw =tb_to_switch (sw->dev.parent); -tb_port_at (tb_route (sw), parent_sw)->remote =NULL ; +tb_switch_downstream_port (sw)->remote =NULL ;tb_switch_remove (sw); }
@@ -755,7 +753,6 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)if (sw) {u8 phy_port, sw_phy_port; - parent_sw =tb_to_switch (sw->dev.parent); sw_phy_port =tb_phy_port_from_link (sw->link); phy_port =tb_phy_port_from_link (link);
@@ -785,7 +782,7 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) route =tb_route (sw); } -update_switch (parent_sw, sw, route, pkg->connection_id, +update_switch (sw, route, pkg->connection_id, pkg->connection_key, link, depth, boot);tb_switch_put (sw);return ;
@@ -1236,9 +1233,8 @@ __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr,if (sw) {/* Update the switch if it is still in the same place */ if (tb_route (sw) == route && !!sw->authorized == authorized) { - parent_sw =tb_to_switch (sw->dev.parent); -update_switch (parent_sw, sw, route, pkg->connection_id, -0 ,0 ,0 , boot); +update_switch (sw, route, pkg->connection_id,0 ,0 ,0 , + boot);tb_switch_put (sw);return ; }
drivers/thunderbolt/switch.c +7 -12
@@ -2754,7 +2754,6 @@ static int tb_switch_update_link_attributes(struct tb_switch *sw)*/ int tb_switch_lane_bonding_enable (struct tb_switch *sw) { -struct tb_switch *parent =tb_to_switch (sw->dev.parent);struct tb_port *up, *down;u64 route =tb_route (sw);int ret;
@@ -2766,7 +2765,7 @@ int tb_switch_lane_bonding_enable(struct tb_switch *sw)return 0 ; up =tb_upstream_port (sw); - down =tb_port_at (route, parent); + down =tb_switch_downstream_port (sw);if (!tb_port_is_width_supported (up,2 ) || !tb_port_is_width_supported (down,2 ))
@@ -2808,7 +2807,6 @@ int tb_switch_lane_bonding_enable(struct tb_switch *sw)*/ void tb_switch_lane_bonding_disable (struct tb_switch *sw) { -struct tb_switch *parent =tb_to_switch (sw->dev.parent);struct tb_port *up, *down;if (!tb_route (sw))
@@ -2818,7 +2816,7 @@ void tb_switch_lane_bonding_disable(struct tb_switch *sw)if (!up->bonded)return ; - down =tb_port_at (tb_route (sw), parent); + down =tb_switch_downstream_port (sw);tb_port_lane_bonding_disable (up);tb_port_lane_bonding_disable (down);
@@ -3476,7 +3474,6 @@ struct tb_port *tb_switch_find_port(struct tb_switch *sw,static int tb_switch_pm_secondary_resolve (struct tb_switch *sw) { -struct tb_switch *parent =tb_switch_parent (sw);struct tb_port *up, *down;int ret;
@@ -3484,7 +3481,7 @@ static int tb_switch_pm_secondary_resolve(struct tb_switch *sw)return 0 ; up =tb_upstream_port (sw); - down =tb_port_at (tb_route (sw), parent); + down =tb_switch_downstream_port (sw); ret =tb_port_pm_secondary_enable (up);if (ret)return ret;
@@ -3494,7 +3491,6 @@ static int tb_switch_pm_secondary_resolve(struct tb_switch *sw)static int __tb_switch_enable_clx (struct tb_switch *sw,enum tb_clx clx) { -struct tb_switch *parent =tb_switch_parent (sw);bool up_clx_support, down_clx_support;struct tb_port *up, *down;int ret;
@@ -3510,7 +3506,7 @@ static int __tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx)return 0 ;/* Enable CLx only for first hop router (depth = 1) */ -if (tb_route (parent)) +if (tb_route (tb_switch_parent (sw)))return 0 ; ret =tb_switch_pm_secondary_resolve (sw);
@@ -3518,7 +3514,7 @@ static int __tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx)return ret; up =tb_upstream_port (sw); - down =tb_port_at (tb_route (sw), parent); + down =tb_switch_downstream_port (sw); up_clx_support =tb_port_clx_supported (up, clx); down_clx_support =tb_port_clx_supported (down, clx);
@@ -3594,7 +3590,6 @@ int tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx)static int __tb_switch_disable_clx (struct tb_switch *sw,enum tb_clx clx) { -struct tb_switch *parent =tb_switch_parent (sw);struct tb_port *up, *down;int ret;
@@ -3609,11 +3604,11 @@ static int __tb_switch_disable_clx(struct tb_switch *sw, enum tb_clx clx)return 0 ;/* Disable CLx only for first hop router (depth = 1) */ -if (tb_route (parent)) +if (tb_route (tb_switch_parent (sw)))return 0 ; up =tb_upstream_port (sw); - down =tb_port_at (tb_route (sw), parent); + down =tb_switch_downstream_port (sw); ret =tb_port_clx_disable (up, clx);if (ret)return ret;
drivers/thunderbolt/tb.c +3 -5
@@ -628,7 +628,7 @@ static int tb_tunnel_usb3(struct tb *tb, struct tb_switch *sw)* Look up available down port. Since we are chaining it should * be found right above this switch. */ - port =tb_port_at (tb_route (sw), parent); + port =tb_switch_downstream_port (sw); down =tb_find_usb3_down (parent, port);if (!down)return 0 ;
@@ -1378,7 +1378,6 @@ static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw) {struct tb_port *up, *down, *port;struct tb_cm *tcm =tb_priv (tb); -struct tb_switch *parent_sw;struct tb_tunnel *tunnel; up =tb_switch_find_port (sw,TB_TYPE_PCIE_UP );
@@ -1389,9 +1388,8 @@ static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw)* Look up available down port. Since we are chaining it should * be found right above this switch. */ - parent_sw =tb_to_switch (sw->dev.parent); - port =tb_port_at (tb_route (sw), parent_sw); - down =tb_find_pcie_down (parent_sw, port); + port =tb_switch_downstream_port (sw); + down =tb_find_pcie_down (tb_switch_parent (sw), port);if (!down)return 0 ;
drivers/thunderbolt/tb.h +14 -0
@@ -857,6 +857,20 @@ static inline struct tb_switch *tb_switch_parent(struct tb_switch *sw)return tb_to_switch (sw->dev.parent); } +/** +* tb_switch_downstream_port() - Return downstream facing port of parent router +* @sw: Device router pointer +* +* Only call for device routers. Returns the downstream facing port of +* the parent router. +*/ +static inline struct tb_port *tb_switch_downstream_port (struct tb_switch *sw) +{ +if (WARN_ON (!tb_route (sw))) +return NULL ; +return tb_port_at (tb_route (sw),tb_switch_parent (sw)); +} +static inline bool tb_switch_is_light_ridge (const struct tb_switch *sw) { return sw->config.vendor_id == PCI_VENDOR_ID_INTEL &&
drivers/thunderbolt/tmu.c +13 -16
@@ -398,11 +398,10 @@ int tb_switch_tmu_disable(struct tb_switch *sw)if (tb_route (sw)) {bool unidirectional = sw->tmu.unidirectional; -struct tb_switch *parent =tb_switch_parent (sw);struct tb_port *down, *up;int ret; - down =tb_port_at (tb_route (sw), parent); + down =tb_switch_downstream_port (sw); up =tb_upstream_port (sw);/* * In case of uni-directional time sync, TMU handshake is
@@ -442,10 +441,9 @@ int tb_switch_tmu_disable(struct tb_switch *sw)static void __tb_switch_tmu_off (struct tb_switch *sw,bool unidirectional) { -struct tb_switch *parent =tb_switch_parent (sw);struct tb_port *down, *up; - down =tb_port_at (tb_route (sw), parent); + down =tb_switch_downstream_port (sw); up =tb_upstream_port (sw);/* * In case of any failure in one of the steps when setting
@@ -457,7 +455,8 @@ static void __tb_switch_tmu_off(struct tb_switch *sw, bool unidirectional)tb_port_tmu_time_sync_disable (down);tb_port_tmu_time_sync_disable (up);if (unidirectional) -tb_switch_tmu_rate_write (parent,TB_SWITCH_TMU_RATE_OFF ); +tb_switch_tmu_rate_write (tb_switch_parent (sw), +TB_SWITCH_TMU_RATE_OFF );else tb_switch_tmu_rate_write (sw,TB_SWITCH_TMU_RATE_OFF );
@@ -472,12 +471,11 @@ static void __tb_switch_tmu_off(struct tb_switch *sw, bool unidirectional)*/ static int __tb_switch_tmu_enable_bidirectional (struct tb_switch *sw) { -struct tb_switch *parent =tb_switch_parent (sw);struct tb_port *up, *down;int ret; up =tb_upstream_port (sw); - down =tb_port_at (tb_route (sw), parent); + down =tb_switch_downstream_port (sw); ret =tb_port_tmu_unidirectional_disable (up);if (ret)
@@ -537,13 +535,13 @@ static int tb_switch_tmu_unidirectional_enable(struct tb_switch *sw)*/ static int __tb_switch_tmu_enable_unidirectional (struct tb_switch *sw) { -struct tb_switch *parent =tb_switch_parent (sw);struct tb_port *up, *down;int ret; up =tb_upstream_port (sw); - down =tb_port_at (tb_route (sw), parent); - ret =tb_switch_tmu_rate_write (parent, sw->tmu.rate_request); + down =tb_switch_downstream_port (sw); + ret =tb_switch_tmu_rate_write (tb_switch_parent (sw), + sw->tmu.rate_request);if (ret)return ret;
@@ -576,10 +574,9 @@ static int __tb_switch_tmu_enable_unidirectional(struct tb_switch *sw)static void __tb_switch_tmu_change_mode_prev (struct tb_switch *sw) { -struct tb_switch *parent =tb_switch_parent (sw);struct tb_port *down, *up; - down =tb_port_at (tb_route (sw), parent); + down =tb_switch_downstream_port (sw); up =tb_upstream_port (sw);/* * In case of any failure in one of the steps when change mode,
@@ -589,7 +586,7 @@ static void __tb_switch_tmu_change_mode_prev(struct tb_switch *sw)*/ tb_port_tmu_set_unidirectional (down, sw->tmu.unidirectional);if (sw->tmu.unidirectional_request) -tb_switch_tmu_rate_write (parent, sw->tmu.rate); +tb_switch_tmu_rate_write (tb_switch_parent (sw), sw->tmu.rate);else tb_switch_tmu_rate_write (sw, sw->tmu.rate);
@@ -599,18 +596,18 @@ static void __tb_switch_tmu_change_mode_prev(struct tb_switch *sw)static int __tb_switch_tmu_change_mode (struct tb_switch *sw) { -struct tb_switch *parent =tb_switch_parent (sw);struct tb_port *up, *down;int ret; up =tb_upstream_port (sw); - down =tb_port_at (tb_route (sw), parent); + down =tb_switch_downstream_port (sw); ret =tb_port_tmu_set_unidirectional (down, sw->tmu.unidirectional_request);if (ret) goto out;if (sw->tmu.unidirectional_request) - ret =tb_switch_tmu_rate_write (parent, sw->tmu.rate_request); + ret =tb_switch_tmu_rate_write (tb_switch_parent (sw), + sw->tmu.rate_request);else ret =tb_switch_tmu_rate_write (sw, sw->tmu.rate_request);if (ret)
drivers/thunderbolt/usb4.c +4 -5
@@ -234,8 +234,8 @@ static bool link_is_usb4(struct tb_port *port)*/ int usb4_switch_setup (struct tb_switch *sw) { -struct tb_port *downstream_port; -struct tb_switch *parent; +struct tb_switch *parent =tb_switch_parent (sw); +struct tb_port *down;bool tbt3, xhci;u32 val =0 ;int ret;
@@ -249,9 +249,8 @@ int usb4_switch_setup(struct tb_switch *sw)if (ret)return ret; - parent =tb_switch_parent (sw); - downstream_port =tb_port_at (tb_route (sw), parent); - sw->link_usb4 =link_is_usb4 (downstream_port); + down =tb_switch_downstream_port (sw); + sw->link_usb4 =link_is_usb4 (down);tb_sw_dbg (sw,"link: %s\n" , sw->link_usb4 ?"USB4" :"TBT" ); xhci = val &ROUTER_CS_6_HCI ;
Signature · 1 line
2.39.2
PATCH 5/20 thunderbolt: Rework Titan Ridge TMU objection disable function
In reply to Mika WesterbergNow this is split into two with one having a misleading name (tb_switch_tmu_unidirectional_enable()).
Make this easier to read, rename and consolidate the two functions into one with name that explains what it actually does. Use the two constants as well that were added but never used to make it clear which bits are being set.
No functional changes.
--- drivers/thunderbolt/tmu.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
drivers/thunderbolt/tmu.c +10 -14
@@ -503,8 +503,10 @@ static int tb_switch_tmu_enable_bidirectional(struct tb_switch *sw)return ret; } -static int tb_switch_tmu_objection_mask (struct tb_switch *sw) +/* Only needed for Titan Ridge */ +static int tb_switch_tmu_disable_objections (struct tb_switch *sw) { +struct tb_port *up =tb_upstream_port (sw);u32 val;int ret;
@@ -515,17 +517,15 @@ static int tb_switch_tmu_objection_mask(struct tb_switch *sw) val &= ~TB_TIME_VSEC_3_CS_9_TMU_OBJ_MASK ; -return tb_sw_write (sw, &val,TB_CFG_SWITCH , - sw->cap_vsec_tmu +TB_TIME_VSEC_3_CS_9 ,1 ); -} - -static int tb_switch_tmu_unidirectional_enable (struct tb_switch *sw) -{ -struct tb_port *up =tb_upstream_port (sw); + ret =tb_sw_write (sw, &val,TB_CFG_SWITCH , + sw->cap_vsec_tmu +TB_TIME_VSEC_3_CS_9 ,1 ); +if (ret) +return ret;return tb_port_tmu_write (up,TMU_ADP_CS_6 ,TMU_ADP_CS_6_DISABLE_TMU_OBJ_MASK , -TMU_ADP_CS_6_DISABLE_TMU_OBJ_MASK ); +TMU_ADP_CS_6_DISABLE_TMU_OBJ_CL1 | +TMU_ADP_CS_6_DISABLE_TMU_OBJ_CL2 ); }/*
@@ -670,11 +670,7 @@ int tb_switch_tmu_enable(struct tb_switch *sw)if (!tb_switch_is_clx_enabled (sw,TB_CL1 ))return -EOPNOTSUPP ; - ret =tb_switch_tmu_objection_mask (sw); -if (ret) -return ret; - - ret =tb_switch_tmu_unidirectional_enable (sw); + ret =tb_switch_tmu_disable_objections (sw);if (ret)return ret; }
Signature · 1 line
2.39.2
PATCH 7/20 thunderbolt: Move TMU configuration to tb_enable_tmu()
In reply to Mika WesterbergThere is no need to duplicate the code the enables TMU. Also update the comment to better explain why we do this in the first place.
No functional changes.
--- drivers/thunderbolt/tb.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-)
drivers/thunderbolt/tb.c +10 -20
@@ -387,6 +387,16 @@ static int tb_enable_tmu(struct tb_switch *sw) {int ret; +/* +* If CL1 is enabled then we need to configure the TMU accuracy +* level to normal. Otherwise we keep the TMU running at the +* highest accuracy. +*/ +if (tb_switch_is_clx_enabled (sw,TB_CL1 )) +tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_NORMAL , true); +else +tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_HIFI , false); +/* If it is already enabled in correct mode, don't touch it */ if (tb_switch_tmu_is_enabled (sw))return 0 ;
@@ -873,16 +883,6 @@ static void tb_scan_port(struct tb_port *port) tb_switch_clx_name(TB_CL1)); } -if (tb_switch_is_clx_enabled (sw,TB_CL1 )) -/* -* To support highest CLx state, we set router's TMU to -* Normal-Uni mode. -*/ -tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_NORMAL , true); -else -/* If CLx disabled, configure router's TMU to HiFi-Bidir mode*/ -tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_HIFI , false); -if (tb_enable_tmu (sw))tb_sw_warn (sw,"failed to enable TMU\n" );
@@ -2035,16 +2035,6 @@ static void tb_restore_children(struct tb_switch *sw)tb_sw_warn (sw,"failed to re-enable %s on upstream port\n" ,tb_switch_clx_name (TB_CL1 )); -if (tb_switch_is_clx_enabled (sw,TB_CL1 )) -/* -* To support highest CLx state, we set router's TMU to -* Normal-Uni mode. -*/ -tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_NORMAL , true); -else -/* If CLx disabled, configure router's TMU to HiFi-Bidir mode*/ -tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_HIFI , false); -if (tb_enable_tmu (sw))tb_sw_warn (sw,"failed to restore TMU configuration\n" );
Signature · 1 line
2.39.2
PATCH 12/20 thunderbolt: Move CLx enabling into tb_enable_clx()
In reply to Mika WesterbergThis avoids some duplication and makes the flow slightly easier to understand. Also follows what we do in tb_enable_tmu().
--- drivers/thunderbolt/tb.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
drivers/thunderbolt/tb.c +17 -17
@@ -240,6 +240,18 @@ static void tb_discover_dp_resources(struct tb *tb) } } +static int tb_enable_clx (struct tb_switch *sw) +{ +int ret; + +/* +* CL0s and CL1 are enabled and supported together. +* Silently ignore CLx enabling in case CLx is not supported. +*/ + ret =tb_switch_clx_enable (sw,TB_CL1 ); +return ret == -EOPNOTSUPP ?0 : ret; +} +static int tb_increase_switch_tmu_accuracy (struct device *dev,void *data) {struct tb_switch *sw;
@@ -777,7 +789,6 @@ static void tb_scan_port(struct tb_port *port)struct tb_port *upstream_port;bool discovery = false;struct tb_switch *sw; -int ret;if (tb_is_upstream_port (port))return ;
@@ -876,14 +887,10 @@ static void tb_scan_port(struct tb_port *port)* CL0s and CL1 are enabled and supported together. * Silently ignore CLx enabling in case CLx is not supported. */ -if (discovery) { +if (discovery)tb_sw_dbg (sw,"discovery, not touching CL states\n" ); - }else { - ret =tb_switch_clx_enable (sw,TB_CL1 ); -if (ret && ret != -EOPNOTSUPP ) -tb_sw_warn (sw,"failed to enable %s on upstream port\n" , -tb_switch_clx_name (TB_CL1 )); - } +else if (tb_enable_clx (sw)) +tb_sw_warn (sw,"failed to enable CL states\n" );if (tb_enable_tmu (sw))tb_sw_warn (sw,"failed to enable TMU\n" );
@@ -2022,20 +2029,13 @@ static int tb_suspend_noirq(struct tb *tb)static void tb_restore_children (struct tb_switch *sw) {struct tb_port *port; -int ret;/* No need to restore if the router is already unplugged */ if (sw->is_unplugged)return ; -/* -* CL0s and CL1 are enabled and supported together. -* Silently ignore CLx re-enabling in case CLx is not supported. -*/ - ret =tb_switch_clx_enable (sw,TB_CL1 ); -if (ret && ret != -EOPNOTSUPP ) -tb_sw_warn (sw,"failed to re-enable %s on upstream port\n" , -tb_switch_clx_name (TB_CL1 )); +if (tb_enable_clx (sw)) +tb_sw_warn (sw,"failed to re-enable CL states\n" );if (tb_enable_tmu (sw))tb_sw_warn (sw,"failed to restore TMU configuration\n" );
Signature · 1 line
2.39.2
PATCH 8/20 thunderbolt: Move tb_enable_tmu() close to other TMU functions
In reply to Mika WesterbergThis makes the code easier to follow. No functional changes.
--- drivers/thunderbolt/tb.c | 58 ++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 29 deletions(-)
drivers/thunderbolt/tb.c +29 -29
@@ -272,6 +272,35 @@ static void tb_increase_tmu_accuracy(struct tb_tunnel *tunnel)device_for_each_child (&sw->dev,NULL , tb_increase_switch_tmu_accuracy); } +static int tb_enable_tmu (struct tb_switch *sw) +{ +int ret; + +/* +* If CL1 is enabled then we need to configure the TMU accuracy +* level to normal. Otherwise we keep the TMU running at the +* highest accuracy. +*/ +if (tb_switch_is_clx_enabled (sw,TB_CL1 )) +tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_NORMAL , true); +else +tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_HIFI , false); + +/* If it is already enabled in correct mode, don't touch it */ +if (tb_switch_tmu_is_enabled (sw)) +return 0 ; + + ret =tb_switch_tmu_disable (sw); +if (ret) +return ret; + + ret =tb_switch_tmu_post_time (sw); +if (ret) +return ret; + +return tb_switch_tmu_enable (sw); +} +static void tb_switch_discover_tunnels (struct tb_switch *sw,struct list_head *list,bool alloc_hopids)
@@ -383,35 +412,6 @@ static void tb_scan_xdomain(struct tb_port *port) } } -static int tb_enable_tmu (struct tb_switch *sw) -{ -int ret; - -/* -* If CL1 is enabled then we need to configure the TMU accuracy -* level to normal. Otherwise we keep the TMU running at the -* highest accuracy. -*/ -if (tb_switch_is_clx_enabled (sw,TB_CL1 )) -tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_NORMAL , true); -else -tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_HIFI , false); - -/* If it is already enabled in correct mode, don't touch it */ -if (tb_switch_tmu_is_enabled (sw)) -return 0 ; - - ret =tb_switch_tmu_disable (sw); -if (ret) -return ret; - - ret =tb_switch_tmu_post_time (sw); -if (ret) -return ret; - -return tb_switch_tmu_enable (sw); -} -/** * tb_find_unused_port() - return the first inactive port on @sw * @sw: Switch to find the port on
Signature · 1 line
2.39.2
PATCH 11/20 thunderbolt: Get rid of __tb_switch_[en|dis]able_clx()
In reply to Mika WesterbergNo need to have separate functions for these so fold them into tb_switch_clx_enable() and tb_switch_clx_disable() accordingly.
No functional changes.
--- drivers/thunderbolt/clx.c | 91 ++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 49 deletions(-)
drivers/thunderbolt/clx.c +42 -49
@@ -205,12 +205,46 @@ static int tb_switch_mask_clx_objections(struct tb_switch *sw) sw->cap_lp + offset, ARRAY_SIZE(val)); } -static int __tb_switch_enable_clx (struct tb_switch *sw,enum tb_clx clx) +/** +* tb_switch_clx_enable() - Enable CLx on upstream port of specified router +* @sw: Router to enable CLx for +* @clx: The CLx state to enable +* +* Enable CLx state only for first hop router. That is the most common +* use-case, that is intended for better thermal management, and so helps +* to improve performance. CLx is enabled only if both sides of the link +* support CLx, and if both sides of the link are not configured as two +* single lane links and only if the link is not inter-domain link. The +* complete set of conditions is described in CM Guide 1.0 section 8.1. +* +* Return: Returns 0 on success or an error code on failure. +*/ +int tb_switch_clx_enable (struct tb_switch *sw,enum tb_clx clx) { +struct tb_switch *root_sw = sw->tb->root_switch;bool up_clx_support, down_clx_support;struct tb_port *up, *down;int ret; +if (!clx_enabled) +return 0 ; + +/* +* CLx is not enabled and validated on Intel USB4 platforms before +* Alder Lake. +*/ +if (root_sw->generation <4 ||tb_switch_is_tiger_lake (root_sw)) +return 0 ; + +switch (clx) { +case TB_CL1 : +/* CL0s and CL1 are enabled and supported together */ +break ; + +default : +return -EOPNOTSUPP ; + } +if (!tb_switch_clx_is_supported (sw))return 0 ;
@@ -267,47 +301,28 @@ static int __tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx) }/** -* tb_switch_clx_enable() - Enable CLx on upstream port of specified router -* @sw: Router to enable CLx for -* @clx: The CLx state to enable -* -* Enable CLx state only for first hop router. That is the most common -* use-case, that is intended for better thermal management, and so helps -* to improve performance. CLx is enabled only if both sides of the link -* support CLx, and if both sides of the link are not configured as two -* single lane links and only if the link is not inter-domain link. The -* complete set of conditions is described in CM Guide 1.0 section 8.1. +* tb_switch_clx_disable() - Disable CLx on upstream port of specified router +* @sw: Router to disable CLx for +* @clx: The CLx state to disable * * Return: Returns 0 on success or an error code on failure. */ -int tb_switch_clx_enable (struct tb_switch *sw,enum tb_clx clx) +int tb_switch_clx_disable (struct tb_switch *sw,enum tb_clx clx) { -struct tb_switch *root_sw = sw->tb->root_switch; +struct tb_port *up, *down; +int ret;if (!clx_enabled)return 0 ; -/* -* CLx is not enabled and validated on Intel USB4 platforms before -* Alder Lake. -*/ -if (root_sw->generation <4 ||tb_switch_is_tiger_lake (root_sw)) -return 0 ; -switch (clx) {case TB_CL1 :/* CL0s and CL1 are enabled and supported together */ -return __tb_switch_enable_clx (sw, clx); +break ;default :return -EOPNOTSUPP ; } -} - -static int __tb_switch_disable_clx (struct tb_switch *sw,enum tb_clx clx) -{ -struct tb_port *up, *down; -int ret;if (!tb_switch_clx_is_supported (sw))return 0 ;
@@ -338,25 +353,3 @@ static int __tb_switch_disable_clx(struct tb_switch *sw, enum tb_clx clx)tb_port_dbg (up,"%s disabled\n" ,tb_switch_clx_name (clx));return 0 ; } - -/** -* tb_switch_cls_disable() - Disable CLx on upstream port of specified router -* @sw: Router to disable CLx for -* @clx: The CLx state to disable -* -* Return: Returns 0 on success or an error code on failure. -*/ -int tb_switch_clx_disable (struct tb_switch *sw,enum tb_clx clx) -{ -if (!clx_enabled) -return 0 ; - -switch (clx) { -case TB_CL1 : -/* CL0s and CL1 are enabled and supported together */ -return __tb_switch_disable_clx (sw, clx); - -default : -return -EOPNOTSUPP ; - } -}
Signature · 1 line
2.39.2
PATCH 14/20 thunderbolt: Check for first depth router in tb.c
In reply to Mika WesterbergCurrently tb_switch_clx_enable() enables CL states only for the first depth router. This is something we may want to change in the future and in addition it is not visible from the calling path at all. For this reason do the check in the tb.c so it is immediately visible that we only do this for the first depth router. Fix the kernel-docs accordingly.
--- drivers/thunderbolt/clx.c | 22 ++++++---------------- drivers/thunderbolt/tb.c | 10 ++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-)
drivers/thunderbolt/clx.c +6 -16
@@ -257,14 +257,12 @@ static const char *clx_name(unsigned int clx)* @sw: Router to enable CLx for * @clx: The CLx state to enable * -* Enable CLx state only for first hop router. That is the most common -* use-case, that is intended for better thermal management, and so helps -* to improve performance. CLx is enabled only if both sides of the link -* support CLx, and if both sides of the link are not configured as two -* single lane links and only if the link is not inter-domain link. The -* complete set of conditions is described in CM Guide 1.0 section 8.1. +* CLx is enabled only if both sides of the link support CLx, and if both sides +* of the link are not configured as two single lane links and only if the link +* is not inter-domain link. The complete set of conditions is described in CM +* Guide 1.0 section 8.1. * -* Return: Returns 0 on success or an error code on failure. +* Returns %0 on success or an error code on failure. */ int tb_switch_clx_enable (struct tb_switch *sw,unsigned int clx) {
@@ -284,10 +282,6 @@ int tb_switch_clx_enable(struct tb_switch *sw, unsigned int clx) !tb_switch_clx_is_supported(sw))return 0 ; -/* Enable CLx only for first hop router (depth = 1) */ -if (tb_route (tb_switch_parent (sw))) -return 0 ; -/* CL2 is not yet supported */ if (clx &TB_CL2 )return -EOPNOTSUPP ;
@@ -340,7 +334,7 @@ int tb_switch_clx_enable(struct tb_switch *sw, unsigned int clx)* Disables all CL states of the given router. Can be called on any * router and if the states were not enabled already does nothing. * -* Return: Returns 0 on success or an error code on failure. +* Returns %0 on success or an error code on failure. */ int tb_switch_clx_disable (struct tb_switch *sw) {
@@ -351,10 +345,6 @@ int tb_switch_clx_disable(struct tb_switch *sw)if (!tb_switch_clx_is_supported (sw))return 0 ; -/* Disable CLx only for first hop router (depth = 1) */ -if (tb_route (tb_switch_parent (sw))) -return 0 ; -if (!clx)return 0 ;
drivers/thunderbolt/tb.c +10 -0
@@ -244,6 +244,16 @@ static int tb_enable_clx(struct tb_switch *sw) {int ret; +/* +* Currently only enable CLx for the first link. This is enough +* to allow the CPU to save energy at least on Intel hardware +* and makes it slightly simpler to implement. We may change +* this in the future to cover the whole topology if it turns +* out to be beneficial. +*/ +if (sw->config.depth !=1 ) +return 0 ; +/* * CL0s and CL1 are enabled and supported together. * Silently ignore CLx enabling in case CLx is not supported.
Signature · 1 line
2.39.2
PATCH 16/20 thunderbolt: Prefix TMU post time log message with "TMU: "
In reply to Mika WesterbergFollowing what we do with other messages in this file. No functional changes.
--- drivers/thunderbolt/tmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/tmu.c +1 -1
@@ -308,7 +308,7 @@ int tb_switch_tmu_post_time(struct tb_switch *sw)return ret;for (i =0 ; i <ARRAY_SIZE (gm_local_time); i++) -tb_sw_dbg (root_switch,"local_time[%d]=0x%08x\n" , i, +tb_sw_dbg (root_switch,"TMU: local_time[%d]=0x%08x\n" , i, gm_local_time[i]);/* Convert to nanoseconds (drop fractional part) */
Signature · 1 line
2.39.2
PATCH 10/20 thunderbolt: Move CLx support functions into clx.c
In reply to Mika WesterbergThere really don't belong to switch.c so move them into their own file. As we do this rename the functions to match the conventions used elsewhere in the driver.
No functional changes.
--- drivers/thunderbolt/Makefile | 2 +- drivers/thunderbolt/clx.c | 362 ++++++++++++++++++++++++++++++++++ drivers/thunderbolt/debugfs.c | 2 +- drivers/thunderbolt/switch.c | 362 +--------------------------------- drivers/thunderbolt/tb.c | 8 +- drivers/thunderbolt/tb.h | 17 +- drivers/thunderbolt/tmu.c | 6 +- 7 files changed, 381 insertions(+), 378 deletions(-) create mode 100644 drivers/thunderbolt/clx.c
drivers/thunderbolt/Makefile +1 -1
@@ -2,7 +2,7 @@ obj-${CONFIG_USB4} := thunderbolt.o thunderbolt-objs := nhi.o nhi_ops.o ctl.o tb.o switch.o cap.o path.o tunnel.o eeprom.o thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o tmu.o usb4.o -thunderbolt-objs += usb4_port.o nvm.o retimer.o quirks.o +thunderbolt-objs += usb4_port.o nvm.o retimer.o quirks.o clx.o thunderbolt-${CONFIG_ACPI} += acpi.o thunderbolt-$(CONFIG_DEBUG_FS) += debugfs.o
drivers/thunderbolt/clx.c new file +362 -0
362 lines not on this page · raw message
drivers/thunderbolt/debugfs.c +1 -1
@@ -570,7 +570,7 @@ static int margining_run_write(void *data, u64 val)* CL states may interfere with lane margining so inform the user know * and bail out. */ -if (tb_port_is_clx_enabled (port,TB_CL1 |TB_CL2 )) { +if (tb_port_clx_is_enabled (port,TB_CL1 |TB_CL2 )) {tb_port_warn (port,"CL states are enabled, Disable them with clx=0 and re-connect\n" ); ret = -EINVAL ;
drivers/thunderbolt/switch.c +2 -360
386 lines not on this page · raw message
drivers/thunderbolt/tb.c +4 -4
@@ -247,7 +247,7 @@ static int tb_increase_switch_tmu_accuracy(struct device *dev, void *data) sw =tb_to_switch (dev);if (sw) {tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_HIFI , -tb_switch_is_clx_enabled (sw,TB_CL1 )); +tb_switch_clx_is_enabled (sw,TB_CL1 ));if (tb_switch_tmu_enable (sw))tb_sw_warn (sw,"failed to increase TMU rate\n" ); }
@@ -281,7 +281,7 @@ static int tb_enable_tmu(struct tb_switch *sw)* level to normal. Otherwise we keep the TMU running at the * highest accuracy. */ -if (tb_switch_is_clx_enabled (sw,TB_CL1 )) +if (tb_switch_clx_is_enabled (sw,TB_CL1 )) ret =tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_NORMAL , true);else ret =tb_switch_tmu_configure (sw,TB_SWITCH_TMU_RATE_HIFI , false);
@@ -879,7 +879,7 @@ static void tb_scan_port(struct tb_port *port)if (discovery) {tb_sw_dbg (sw,"discovery, not touching CL states\n" ); }else { - ret =tb_switch_enable_clx (sw,TB_CL1 ); + ret =tb_switch_clx_enable (sw,TB_CL1 );if (ret && ret != -EOPNOTSUPP )tb_sw_warn (sw,"failed to enable %s on upstream port\n" ,tb_switch_clx_name (TB_CL1 ));
@@ -2032,7 +2032,7 @@ static void tb_restore_children(struct tb_switch *sw)* CL0s and CL1 are enabled and supported together. * Silently ignore CLx re-enabling in case CLx is not supported. */ - ret =tb_switch_enable_clx (sw,TB_CL1 ); + ret =tb_switch_clx_enable (sw,TB_CL1 );if (ret && ret != -EOPNOTSUPP )tb_sw_warn (sw,"failed to re-enable %s on upstream port\n" ,tb_switch_clx_name (TB_CL1 ));
drivers/thunderbolt/tb.h +8 -9
@@ -1002,6 +1002,8 @@ static inline bool tb_switch_tmu_is_enabled(const struct tb_switch *sw) sw->tmu.unidirectional == sw->tmu.unidirectional_request; } +bool tb_port_clx_is_enabled (struct tb_port *port,unsigned int clx_mask); +static inline const char *tb_switch_clx_name (enum tb_clx clx) {switch (clx) {
@@ -1013,28 +1015,28 @@ static inline const char *tb_switch_clx_name(enum tb_clx clx) } } -int tb_switch_enable_clx (struct tb_switch *sw,enum tb_clx clx); -int tb_switch_disable_clx (struct tb_switch *sw,enum tb_clx clx); +int tb_switch_clx_enable (struct tb_switch *sw,enum tb_clx clx); +int tb_switch_clx_disable (struct tb_switch *sw,enum tb_clx clx);/** -* tb_switch_is_clx_enabled() - Checks if the CLx is enabled +* tb_switch_clx_is_enabled() - Checks if the CLx is enabled * @sw: Router to check for the CLx * @clx: The CLx state to check for * * Checks if the specified CLx is enabled on the router upstream link. * Not applicable for a host router. */ -static inline bool tb_switch_is_clx_enabled (const struct tb_switch *sw, +static inline bool tb_switch_clx_is_enabled (const struct tb_switch *sw,enum tb_clx clx) {return sw->clx == clx; }/** -* tb_switch_is_clx_supported() - Is CLx supported on this type of router +* tb_switch_clx_is_supported() - Is CLx supported on this type of router * @sw: The router to check CLx support for */ -static inline bool tb_switch_is_clx_supported (const struct tb_switch *sw) +static inline bool tb_switch_clx_is_supported (const struct tb_switch *sw) {if (sw->quirks &QUIRK_NO_CLX )return false;
@@ -1042,8 +1044,6 @@ static inline bool tb_switch_is_clx_supported(const struct tb_switch *sw)return tb_switch_is_usb4 (sw) ||tb_switch_is_titan_ridge (sw); } -int tb_switch_mask_clx_objections (struct tb_switch *sw); -int tb_switch_pcie_l1_enable (struct tb_switch *sw);int tb_switch_xhci_connect (struct tb_switch *sw);
@@ -1089,7 +1089,6 @@ void tb_port_lane_bonding_disable(struct tb_port *port);int tb_port_wait_for_link_width (struct tb_port *port,int width,int timeout_msec);int tb_port_update_credits (struct tb_port *port); -bool tb_port_is_clx_enabled (struct tb_port *port,unsigned int clx);int tb_switch_find_vse_cap (struct tb_switch *sw,enum tb_switch_vse_cap vsec);int tb_switch_find_cap (struct tb_switch *sw,enum tb_switch_cap cap);
drivers/thunderbolt/tmu.c +3 -3
@@ -388,7 +388,7 @@ int tb_switch_tmu_disable(struct tb_switch *sw)* on these devices e.g. Alpine Ridge and earlier, the TMU mode * HiFi bi-directional is enabled by default and we don't change it. */ -if (!tb_switch_is_clx_supported (sw)) +if (!tb_switch_clx_is_supported (sw))return 0 ;/* Already disabled? */
@@ -653,7 +653,7 @@ int tb_switch_tmu_enable(struct tb_switch *sw)* these devices e.g. Alpine Ridge and earlier, the TMU mode HiFi * bi-directional is enabled by default. */ -if (!tb_switch_is_clx_supported (sw)) +if (!tb_switch_clx_is_supported (sw))return 0 ;if (tb_switch_tmu_is_enabled (sw))
@@ -664,7 +664,7 @@ int tb_switch_tmu_enable(struct tb_switch *sw)* Titan Ridge supports CL0s and CL1 only. CL0s and CL1 are * enabled and supported together. */ -if (!tb_switch_is_clx_enabled (sw,TB_CL1 )) +if (!tb_switch_clx_is_enabled (sw,TB_CL1 ))return -EOPNOTSUPP ; ret =tb_switch_tmu_disable_objections (sw);
Signature · 1 line
2.39.2
PATCH 13/20 thunderbolt: Switch CL states from enum to a bitmask
In reply to Mika WesterbergThis is more natural and follows the hardware register layout better. This makes it easier to see which CL states we enable (even though they should be enabled together). Rename 'clx_mask' to 'clx' everywhere as this is now always bitmask.
--- drivers/thunderbolt/clx.c | 169 ++++++++++++++++++++--------------- drivers/thunderbolt/switch.c | 7 +- drivers/thunderbolt/tb.c | 2 +- drivers/thunderbolt/tb.h | 54 ++++------- 4 files changed, 113 insertions(+), 119 deletions(-)
drivers/thunderbolt/clx.c +95 -74
@@ -45,7 +45,7 @@ static int tb_port_pm_secondary_disable(struct tb_port *port) }/* Called for USB4 or Titan Ridge routers only */ -static bool tb_port_clx_supported (struct tb_port *port,unsigned int clx_mask) +static bool tb_port_clx_supported (struct tb_port *port,unsigned int clx) {u32 val, mask =0 ;bool ret;
@@ -65,11 +65,11 @@ static bool tb_port_clx_supported(struct tb_port *port, unsigned int clx_mask)return false; } -if (clx_mask &TB_CL1 ) { -/* CL0s and CL1 are enabled and supported together */ - mask |=LANE_ADP_CS_0_CL0S_SUPPORT |LANE_ADP_CS_0_CL1_SUPPORT ; - } -if (clx_mask &TB_CL2 ) +if (clx &TB_CL0S ) + mask |=LANE_ADP_CS_0_CL0S_SUPPORT ; +if (clx &TB_CL1 ) + mask |=LANE_ADP_CS_0_CL1_SUPPORT ; +if (clx &TB_CL2 ) mask |=LANE_ADP_CS_0_CL2_SUPPORT ; ret = tb_port_read(port, &val, TB_CFG_PORT,
@@ -80,16 +80,17 @@ static bool tb_port_clx_supported(struct tb_port *port, unsigned int clx_mask)return !!(val & mask); } -static int tb_port_clx_set (struct tb_port *port,enum tb_clx clx,bool enable) +static int tb_port_clx_set (struct tb_port *port,unsigned int clx,bool enable) { -u32 phy, mask; +u32 phy, mask =0 ;int ret; -/* CL0s and CL1 are enabled and supported together */ -if (clx ==TB_CL1 ) - mask =LANE_ADP_CS_1_CL0S_ENABLE |LANE_ADP_CS_1_CL1_ENABLE ; -else -/* For now we support only CL0s and CL1. Not CL2 */ +if (clx &TB_CL0S ) + mask |=LANE_ADP_CS_1_CL0S_ENABLE ; +if (clx &TB_CL1 ) + mask |=LANE_ADP_CS_1_CL1_ENABLE ; + +if (!mask)return -EOPNOTSUPP ; ret = tb_port_read(port, &phy, TB_CFG_PORT,
@@ -106,12 +107,12 @@ static int tb_port_clx_set(struct tb_port *port, enum tb_clx clx, bool enable) port->cap_phy + LANE_ADP_CS_1, 1); } -static int tb_port_clx_disable (struct tb_port *port,enum tb_clx clx) +static int tb_port_clx_disable (struct tb_port *port,unsigned int clx) {return tb_port_clx_set (port, clx, false); } -static int tb_port_clx_enable (struct tb_port *port,enum tb_clx clx) +static int tb_port_clx_enable (struct tb_port *port,unsigned int clx) {return tb_port_clx_set (port, clx, true); }
@@ -119,21 +120,23 @@ static int tb_port_clx_enable(struct tb_port *port, enum tb_clx clx)/** * tb_port_clx_is_enabled() - Is given CL state enabled * @port: USB4 port to check -* @clx_mask: Mask of CL states to check +* @clx: Mask of CL states to check * * Returns true if any of the given CL states is enabled for @port. */ -bool tb_port_clx_is_enabled (struct tb_port *port,unsigned int clx_mask) +bool tb_port_clx_is_enabled (struct tb_port *port,unsigned int clx) {u32 val, mask =0 ;int ret; -if (!tb_port_clx_supported (port, clx_mask)) +if (!tb_port_clx_supported (port, clx))return false; -if (clx_mask &TB_CL1 ) - mask |=LANE_ADP_CS_1_CL0S_ENABLE |LANE_ADP_CS_1_CL1_ENABLE ; -if (clx_mask &TB_CL2 ) +if (clx &TB_CL0S ) + mask |=LANE_ADP_CS_1_CL0S_ENABLE ; +if (clx &TB_CL1 ) + mask |=LANE_ADP_CS_1_CL1_ENABLE ; +if (clx &TB_CL2 ) mask |=LANE_ADP_CS_1_CL2_ENABLE ; ret = tb_port_read(port, &val, TB_CFG_PORT,
@@ -205,6 +208,50 @@ 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 */ +if (clx &TB_CL2 ) +return (clx & (TB_CL0S |TB_CL1 )) == (TB_CL0S |TB_CL1 ); +if (clx &TB_CL1 ) +return (clx &TB_CL0S ) ==TB_CL0S ; +return true; +} + +static const char *clx_name (unsigned int clx) +{ +if (clx &TB_CL2 ) +return "CL0s/CL1/CL2" ; +if (clx &TB_CL1 ) +return "CL0s/CL1" ; +if (clx &TB_CL0S ) +return "CL0s" ; + +return "unknown" ; +} +/** * tb_switch_clx_enable() - Enable CLx on upstream port of specified router * @sw: Router to enable CLx for
@@ -219,46 +266,32 @@ static int tb_switch_mask_clx_objections(struct tb_switch *sw)* * Return: Returns 0 on success or an error code on failure. */ -int tb_switch_clx_enable (struct tb_switch *sw,enum tb_clx clx) +int tb_switch_clx_enable (struct tb_switch *sw,unsigned int clx) { -struct tb_switch *root_sw = sw->tb->root_switch;bool up_clx_support, down_clx_support; +struct tb_switch *parent_sw;struct tb_port *up, *down;int ret; -if (!clx_enabled) -return 0 ; +if (!validate_mask (clx)) +return -EINVAL ; -/* -* CLx is not enabled and validated on Intel USB4 platforms before -* Alder Lake. -*/ -if (root_sw->generation <4 ||tb_switch_is_tiger_lake (root_sw)) + parent_sw =tb_switch_parent (sw); +if (!parent_sw)return 0 ; -switch (clx) { -case TB_CL1 : -/* CL0s and CL1 are enabled and supported together */ -break ; - -default : -return -EOPNOTSUPP ; - } - -if (!tb_switch_clx_is_supported (sw)) -return 0 ; - -/* -* Enable CLx for host router's downstream port as part of the -* downstream router enabling procedure. -*/ -if (!tb_route (sw)) +if (!tb_switch_clx_is_supported (parent_sw) || + !tb_switch_clx_is_supported (sw))return 0 ;/* Enable CLx only for first hop router (depth = 1) */ if (tb_route (tb_switch_parent (sw)))return 0 ; +/* CL2 is not yet supported */ +if (clx &TB_CL2 ) +return -EOPNOTSUPP ; + ret =tb_switch_pm_secondary_resolve (sw);if (ret)return ret;
@@ -269,9 +302,9 @@ int tb_switch_clx_enable(struct tb_switch *sw, enum tb_clx clx) up_clx_support =tb_port_clx_supported (up, clx); down_clx_support =tb_port_clx_supported (down, clx); -tb_port_dbg (up,"%s %ssupported\n" ,tb_switch_clx_name (clx), +tb_port_dbg (up,"%s %ssupported\n" ,clx_name (clx), up_clx_support ?"" :"not " ); -tb_port_dbg (down,"%s %ssupported\n" ,tb_switch_clx_name (clx), +tb_port_dbg (down,"%s %ssupported\n" ,clx_name (clx), down_clx_support ?"" :"not " );if (!up_clx_support || !down_clx_support)
@@ -294,52 +327,40 @@ int tb_switch_clx_enable(struct tb_switch *sw, enum tb_clx clx)return ret; } - sw->clx = clx; + sw->clx |= clx; -tb_port_dbg (up,"%s enabled\n" ,tb_switch_clx_name (clx)); +tb_port_dbg (up,"%s enabled\n" ,clx_name (clx));return 0 ; }/** * tb_switch_clx_disable() - Disable CLx on upstream port of specified router * @sw: Router to disable CLx for -* @clx: The CLx state to disable +* +* Disables all CL states of the given router. Can be called on any +* router and if the states were not enabled already does nothing. * * Return: Returns 0 on success or an error code on failure. */ -int tb_switch_clx_disable (struct tb_switch *sw,enum tb_clx clx) +int tb_switch_clx_disable (struct tb_switch *sw) { +unsigned int clx = sw->clx;struct tb_port *up, *down;int ret; -if (!clx_enabled) -return 0 ; - -switch (clx) { -case TB_CL1 : -/* CL0s and CL1 are enabled and supported together */ -break ; - -default : -return -EOPNOTSUPP ; - } -if (!tb_switch_clx_is_supported (sw))return 0 ; -/* -* Disable CLx for host router's downstream port as part of the -* downstream router enabling procedure. -*/ -if (!tb_route (sw)) -return 0 ; -/* Disable CLx only for first hop router (depth = 1) */ if (tb_route (tb_switch_parent (sw)))return 0 ; +if (!clx) +return 0 ; + up =tb_upstream_port (sw); down =tb_switch_downstream_port (sw); + ret =tb_port_clx_disable (up, clx);if (ret)return ret;
@@ -348,8 +369,8 @@ int tb_switch_clx_disable(struct tb_switch *sw, enum tb_clx clx)if (ret)return ret; - sw->clx =TB_CLX_DISABLE ; + sw->clx =0 ; -tb_port_dbg (up,"%s disabled\n" ,tb_switch_clx_name (clx)); +tb_port_dbg (up,"%s disabled\n" ,clx_name (clx));return 0 ; }
drivers/thunderbolt/switch.c +1 -6
@@ -3111,13 +3111,8 @@ void tb_switch_suspend(struct tb_switch *sw, bool runtime)/* * Actually only needed for Titan Ridge but for simplicity can be * done for USB4 device too as CLx is re-enabled at resume. -* CL0s and CL1 are enabled and supported together. */ -if (tb_switch_clx_is_enabled (sw,TB_CL1 )) { -if (tb_switch_clx_disable (sw,TB_CL1 )) -tb_sw_warn (sw,"failed to disable %s on upstream port\n" , -tb_switch_clx_name (TB_CL1 )); - } +tb_switch_clx_disable (sw); err =tb_plug_events_active (sw, false);if (err)
drivers/thunderbolt/tb.c +1 -1
@@ -248,7 +248,7 @@ static int tb_enable_clx(struct tb_switch *sw)* CL0s and CL1 are enabled and supported together. * Silently ignore CLx enabling in case CLx is not supported. */ - ret =tb_switch_clx_enable (sw,TB_CL1 ); + ret =tb_switch_clx_enable (sw,TB_CL0S |TB_CL1 );return ret == -EOPNOTSUPP ?0 : ret; }
drivers/thunderbolt/tb.h +16 -38
95 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH 15/20 thunderbolt: Do not call CLx functions from TMU code
In reply to Mika WesterbergThere is really no need to call any of the CLx functions in the TMU code so remove all these checks. This makes the TMU enable/disable flows easier to follow as well.
--- drivers/thunderbolt/tmu.c | 23 ----------------------- 1 file changed, 23 deletions(-)
drivers/thunderbolt/tmu.c +0 -23
@@ -383,14 +383,6 @@ int tb_switch_tmu_post_time(struct tb_switch *sw)*/ int tb_switch_tmu_disable (struct tb_switch *sw) { -/* -* No need to disable TMU on devices that don't support CLx since -* on these devices e.g. Alpine Ridge and earlier, the TMU mode -* HiFi bi-directional is enabled by default and we don't change it. -*/ -if (!tb_switch_clx_is_supported (sw)) -return 0 ; -/* Already disabled? */ if (sw->tmu.rate ==TB_SWITCH_TMU_RATE_OFF )return 0 ;
@@ -648,25 +640,10 @@ int tb_switch_tmu_enable(struct tb_switch *sw)bool unidirectional = sw->tmu.unidirectional_request;int ret; -/* -* No need to enable TMU on devices that don't support CLx since on -* these devices e.g. Alpine Ridge and earlier, the TMU mode HiFi -* bi-directional is enabled by default. -*/ -if (!tb_switch_clx_is_supported (sw)) -return 0 ; -if (tb_switch_tmu_is_enabled (sw))return 0 ;if (tb_switch_is_titan_ridge (sw) && unidirectional) { -/* -* Titan Ridge supports CL0s and CL1 only. CL0s and CL1 are -* enabled and supported together. -*/ -if (!tb_switch_clx_is_enabled (sw,TB_CL1 )) -return -EOPNOTSUPP ; - ret =tb_switch_tmu_disable_objections (sw);if (ret)return ret;
Signature · 1 line
2.39.2
PATCH 17/20 thunderbolt: Prefix CL state related log messages with "CLx: "
In reply to Mika WesterbergThis makes it easier to spot from the logs and follows what we do with the TMU code already. We also log enabling/disabling CL states using the tb_sw_dbg() instead of tb_port_dbg().
--- drivers/thunderbolt/clx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/thunderbolt/clx.c +4 -4
@@ -296,9 +296,9 @@ int tb_switch_clx_enable(struct tb_switch *sw, unsigned int clx) up_clx_support =tb_port_clx_supported (up, clx); down_clx_support =tb_port_clx_supported (down, clx); -tb_port_dbg (up,"%s %ssupported\n" ,clx_name (clx), +tb_port_dbg (up,"CLx: %s %ssupported\n" ,clx_name (clx), up_clx_support ?"" :"not " ); -tb_port_dbg (down,"%s %ssupported\n" ,clx_name (clx), +tb_port_dbg (down,"CLx: %s %ssupported\n" ,clx_name (clx), down_clx_support ?"" :"not " );if (!up_clx_support || !down_clx_support)
@@ -323,7 +323,7 @@ int tb_switch_clx_enable(struct tb_switch *sw, unsigned int clx) sw->clx |= clx; -tb_port_dbg (up,"%s enabled\n" ,clx_name (clx)); +tb_sw_dbg (sw,"CLx: %s enabled\n" ,clx_name (clx));return 0 ; }
@@ -361,6 +361,6 @@ int tb_switch_clx_disable(struct tb_switch *sw) sw->clx =0 ; -tb_port_dbg (up,"%s disabled\n" ,clx_name (clx)); +tb_sw_dbg (sw,"CLx: %s disabled\n" ,clx_name (clx));return 0 ; }
Signature · 1 line
2.39.2
PATCH 19/20 thunderbolt: Make tb_switch_clx_disable() return CL states that were enabled
In reply to Mika WesterbergThis allows us to disable all CL states temporarily when running lane margining and then return back the previously enabled states.
--- drivers/thunderbolt/clx.c | 8 ++++++-- drivers/thunderbolt/debugfs.c | 35 ++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 13 deletions(-)
drivers/thunderbolt/clx.c +6 -2
@@ -317,6 +317,9 @@ int tb_switch_clx_enable(struct tb_switch *sw, unsigned int clx)struct tb_port *up, *down;int ret; +if (!clx) +return 0 ; +if (!validate_mask (clx))return -EINVAL ;
@@ -380,7 +383,8 @@ int tb_switch_clx_enable(struct tb_switch *sw, unsigned int clx)* Disables all CL states of the given router. Can be called on any * router and if the states were not enabled already does nothing. * -* Returns %0 on success or an error code on failure. +* Returns the CL states that were disabled or negative errno in case of +* failure. */ int tb_switch_clx_disable (struct tb_switch *sw) {
@@ -408,5 +412,5 @@ int tb_switch_clx_disable(struct tb_switch *sw) sw->clx =0 ;tb_sw_dbg (sw,"CLx: %s disabled\n" ,clx_name (clx)); -return 0 ; +return clx; }
drivers/thunderbolt/debugfs.c +24 -11
@@ -553,8 +553,9 @@ static int margining_run_write(void *data, u64 val)struct usb4_port *usb4 = port->usb4;struct tb_switch *sw = port->sw;struct tb_margining *margining; +struct tb_switch *down_sw;struct tb *tb = sw->tb; -int ret; +int ret, clx;if (val !=1 )return -EINVAL ;
@@ -566,15 +567,24 @@ static int margining_run_write(void *data, u64 val) goto out_rpm_put; } -/* -* CL states may interfere with lane margining so inform the user know -* and bail out. -*/ -if (tb_port_clx_is_enabled (port,TB_CL1 |TB_CL2 )) { -tb_port_warn (port, -"CL states are enabled, Disable them with clx=0 and re-connect\n" ); - ret = -EINVAL ; - goto out_unlock; +if (tb_is_upstream_port (port)) + down_sw = sw; +else if (port->remote) + down_sw = port->remote->sw; +else + down_sw =NULL ; + +if (down_sw) { +/* +* CL states may interfere with lane margining so +* disable them temporarily now. +*/ + ret =tb_switch_clx_disable (down_sw); +if (ret <0 ) { +tb_sw_warn (down_sw,"failed to disable CL states\n" ); + goto out_unlock; + } + clx = ret; } margining = usb4->margining;
@@ -586,7 +596,7 @@ static int margining_run_write(void *data, u64 val) margining->right_high, USB4_MARGIN_SW_COUNTER_CLEAR);if (ret) - goto out_unlock; + goto out_clx; ret =usb4_port_sw_margin_errors (port, &margining->results[0 ]); }else {
@@ -600,6 +610,9 @@ static int margining_run_write(void *data, u64 val) margining->right_high, margining->results); } +out_clx: +if (down_sw) +tb_switch_clx_enable (down_sw, clx); out_unlock:mutex_unlock (&tb->lock); out_rpm_put:
Signature · 1 line
2.39.2
PATCH 20/20 thunderbolt: Disable CL states when a DMA tunnel is established
In reply to Mika WesterbergTunnels between hosts should not have CL states enabled because otherwise they might enter a low power state without the other end noticing which causes packets to be lost. For this reason disable all CL states upon first DMA tunnel creation. Once the last DMA tunnel is torn down we try to re-enable them.
--- drivers/thunderbolt/clx.c | 2 +- drivers/thunderbolt/tb.c | 62 +++++++++++++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 6 deletions(-)
drivers/thunderbolt/clx.c +1 -1
@@ -317,7 +317,7 @@ int tb_switch_clx_enable(struct tb_switch *sw, unsigned int clx)struct tb_port *up, *down;int ret; -if (!clx) +if (!clx || sw->clx == clx)return 0 ;if (!validate_mask (clx))
drivers/thunderbolt/tb.c +57 -5
116 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH 18/20 thunderbolt: Initialize CL states from the hardware
In reply to Mika WesterbergIn case the boot firmware enabled any of them, read the currently configured CL states and update the router structure accordingly.
--- drivers/thunderbolt/clx.c | 100 +++++++++++++++++++++++++---------- drivers/thunderbolt/switch.c | 4 ++ drivers/thunderbolt/tb.h | 1 + 3 files changed, 78 insertions(+), 27 deletions(-)
drivers/thunderbolt/clx.c +73 -27
@@ -15,6 +15,21 @@ static bool clx_enabled = true;module_param_named (clx, clx_enabled, bool,0444 );MODULE_PARM_DESC (clx,"allow low power states on the high-speed lanes (default: true)" ); +static const char *clx_name (unsigned int clx) +{ +if (!clx) +return "disabled" ; + +if (clx &TB_CL2 ) +return "CL0s/CL1/CL2" ; +if (clx &TB_CL1 ) +return "CL0s/CL1" ; +if (clx &TB_CL0S ) +return "CL0s" ; + +return "unknown" ; +} +static int tb_port_pm_secondary_set (struct tb_port *port,bool secondary) {u32 phy;
@@ -117,6 +132,29 @@ static int tb_port_clx_enable(struct tb_port *port, unsigned int clx)return tb_port_clx_set (port, clx, true); } +static int tb_port_clx (struct tb_port *port) +{ +u32 val; +int ret; + +if (!tb_port_clx_supported (port,TB_CL0S |TB_CL1 |TB_CL2 )) +return 0 ; + + ret =tb_port_read (port, &val,TB_CFG_PORT , + port->cap_phy +LANE_ADP_CS_1 ,1 ); +if (ret) +return ret; + +if (val &LANE_ADP_CS_1_CL0S_ENABLE ) + ret |=TB_CL0S ; +if (val &LANE_ADP_CS_1_CL1_ENABLE ) + ret |=TB_CL1 ; +if (val &LANE_ADP_CS_1_CL2_ENABLE ) + ret |=TB_CL2 ; + +return ret; +} +/** * tb_port_clx_is_enabled() - Is given CL state enabled * @port: USB4 port to check
@@ -126,25 +164,45 @@ static int tb_port_clx_enable(struct tb_port *port, unsigned int clx)*/ bool tb_port_clx_is_enabled (struct tb_port *port,unsigned int clx) { -u32 val, mask =0 ; -int ret; +return !!(tb_port_clx (port) & clx); +} -if (!tb_port_clx_supported (port, clx)) -return false; +/** +* tb_switch_clx_init() - Initialize router CL states +* @sw: Router +* +* Can be called for any router. Initializes the current CL state by +* reading it from the hardware. +* +* Returns %0 in case of success and negative errno in case of failure. +*/ +int tb_switch_clx_init (struct tb_switch *sw) +{ +struct tb_port *up, *down; +unsigned int clx, tmp; -if (clx &TB_CL0S ) - mask |=LANE_ADP_CS_1_CL0S_ENABLE ; -if (clx &TB_CL1 ) - mask |=LANE_ADP_CS_1_CL1_ENABLE ; -if (clx &TB_CL2 ) - mask |=LANE_ADP_CS_1_CL2_ENABLE ; +if (tb_switch_is_icm (sw)) +return 0 ; - ret =tb_port_read (port, &val,TB_CFG_PORT , - port->cap_phy +LANE_ADP_CS_1 ,1 ); -if (ret) -return false; +if (!tb_route (sw)) +return 0 ; -return !!(val & mask); +if (!tb_switch_clx_is_supported (sw)) +return 0 ; + + up =tb_upstream_port (sw); + down =tb_switch_downstream_port (sw); + + clx =tb_port_clx (up); + tmp =tb_port_clx (down); +if (clx != tmp) +tb_sw_warn (sw,"CLx: inconsistent configuration %#x != %#x\n" , + clx, tmp); + +tb_sw_dbg (sw,"CLx: current mode: %s\n" ,clx_name (clx)); + + sw->clx = clx; +return 0 ; }static int tb_switch_pm_secondary_resolve (struct tb_switch *sw)
@@ -240,18 +298,6 @@ static bool validate_mask(unsigned int clx)return true; } -static const char *clx_name (unsigned int clx) -{ -if (clx &TB_CL2 ) -return "CL0s/CL1/CL2" ; -if (clx &TB_CL1 ) -return "CL0s/CL1" ; -if (clx &TB_CL0S ) -return "CL0s" ; - -return "unknown" ; -} -/** * tb_switch_clx_enable() - Enable CLx on upstream port of specified router * @sw: Router to enable CLx for
drivers/thunderbolt/switch.c +4 -0
@@ -2859,6 +2859,10 @@ int tb_switch_add(struct tb_switch *sw)if (ret)return ret; + ret =tb_switch_clx_init (sw); +if (ret) +return ret; + ret =tb_switch_tmu_init (sw);if (ret)return ret;
drivers/thunderbolt/tb.h +1 -0
@@ -1002,6 +1002,7 @@ 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.39.2
Quoted 23 lines · Mika Westerberg
Hi all,
This series reworks the TMU and CLx support code to match better what we do elsewhere in the driver and prepares for USB4v2 adaptive TMU support that we are going to add in the subsequent series (I'm sending that out later this week). I've split this part as separate from USB4v2 support hoping that it makes reviewing them easier.
Gil Fine (1):
thunderbolt: Introducetb_switch_downstream_port()Mika Westerberg (19):
thunderbolt: Introducetb_xdomain_downstream_port()
thunderbolt: Fix a couple of style issues in TMU code
thunderbolt: Drop useless 'unidirectional' parameter fromtb_switch_tmu_is_enabled()
thunderbolt: Rework Titan Ridge TMU objection disable function
thunderbolt: Get rid oftb_switch_enable_tmu_1st_child()
thunderbolt: Move TMU configuration totb_enable_tmu()
thunderbolt: Movetb_enable_tmu()close to other TMU functions
thunderbolt: Check valid TMU configuration intb_switch_tmu_configure()
thunderbolt: Move CLx support functions intoclx.c
thunderbolt: Get rid of __tb_switch_[en|dis]able_clx()
thunderbolt: Move CLx enabling intotb_enable_clx()
Quoted 8 lines
thunderbolt: Switch CL states from enum to a bitmask
thunderbolt: Check for first depth router intb.c
thunderbolt: Do not call CLx functions from TMU code
thunderbolt: Prefix TMU post time log message with "TMU: "
thunderbolt: Prefix CL state related log messages with "CLx: "
thunderbolt: Initialize CL states from the hardware
thunderbolt: Maketb_switch_clx_disable()return CL states that were enabled
thunderbolt: Disable CL states when a DMA tunnel is established
All applied to thunderbolt.git/next.