Commit 2bfeca73 authored by Gil Fine's avatar Gil Fine Committed by Mika Westerberg

thunderbolt: Introduce tb_port_path_direction_downstream()

Introduce tb_port_path_direction_downstream() to check if path from
source adapter to destination adapter is directed towards downstream.
Convert existing users to call this helper instead of open-coding.

No functional changes.
Signed-off-by: default avatarGil Fine <gil.fine@linux.intel.com>
Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
parent ce91d793
...@@ -553,7 +553,7 @@ static struct tb_tunnel *tb_find_first_usb3_tunnel(struct tb *tb, ...@@ -553,7 +553,7 @@ static struct tb_tunnel *tb_find_first_usb3_tunnel(struct tb *tb,
struct tb_switch *sw; struct tb_switch *sw;
/* Pick the router that is deepest in the topology */ /* Pick the router that is deepest in the topology */
if (dst_port->sw->config.depth > src_port->sw->config.depth) if (tb_port_path_direction_downstream(src_port, dst_port))
sw = dst_port->sw; sw = dst_port->sw;
else else
sw = src_port->sw; sw = src_port->sw;
...@@ -1224,7 +1224,7 @@ tb_recalc_estimated_bandwidth_for_group(struct tb_bandwidth_group *group) ...@@ -1224,7 +1224,7 @@ tb_recalc_estimated_bandwidth_for_group(struct tb_bandwidth_group *group)
"re-calculated estimated bandwidth %u/%u Mb/s\n", "re-calculated estimated bandwidth %u/%u Mb/s\n",
estimated_up, estimated_down); estimated_up, estimated_down);
if (in->sw->config.depth < out->sw->config.depth) if (tb_port_path_direction_downstream(in, out))
estimated_bw = estimated_down; estimated_bw = estimated_down;
else else
estimated_bw = estimated_up; estimated_bw = estimated_up;
...@@ -1958,7 +1958,7 @@ static void tb_handle_dp_bandwidth_request(struct work_struct *work) ...@@ -1958,7 +1958,7 @@ static void tb_handle_dp_bandwidth_request(struct work_struct *work)
out = tunnel->dst_port; out = tunnel->dst_port;
if (in->sw->config.depth < out->sw->config.depth) { if (tb_port_path_direction_downstream(in, out)) {
requested_up = -1; requested_up = -1;
requested_down = requested_bw; requested_down = requested_bw;
} else { } else {
......
...@@ -1041,6 +1041,21 @@ void tb_port_release_out_hopid(struct tb_port *port, int hopid); ...@@ -1041,6 +1041,21 @@ void tb_port_release_out_hopid(struct tb_port *port, int hopid);
struct tb_port *tb_next_port_on_path(struct tb_port *start, struct tb_port *end, struct tb_port *tb_next_port_on_path(struct tb_port *start, struct tb_port *end,
struct tb_port *prev); struct tb_port *prev);
/**
* tb_port_path_direction_downstream() - Checks if path directed downstream
* @src: Source adapter
* @dst: Destination adapter
*
* Returns %true only if the specified path from source adapter (@src)
* to destination adapter (@dst) is directed downstream.
*/
static inline bool
tb_port_path_direction_downstream(const struct tb_port *src,
const struct tb_port *dst)
{
return src->sw->config.depth < dst->sw->config.depth;
}
static inline bool tb_port_use_credit_allocation(const struct tb_port *port) static inline bool tb_port_use_credit_allocation(const struct tb_port *port)
{ {
return tb_port_is_null(port) && port->sw->credit_allocation; return tb_port_is_null(port) && port->sw->credit_allocation;
......
...@@ -687,7 +687,7 @@ static int tb_dp_xchg_caps(struct tb_tunnel *tunnel) ...@@ -687,7 +687,7 @@ static int tb_dp_xchg_caps(struct tb_tunnel *tunnel)
"DP OUT maximum supported bandwidth %u Mb/s x%u = %u Mb/s\n", "DP OUT maximum supported bandwidth %u Mb/s x%u = %u Mb/s\n",
out_rate, out_lanes, bw); out_rate, out_lanes, bw);
if (in->sw->config.depth < out->sw->config.depth) if (tb_port_path_direction_downstream(in, out))
max_bw = tunnel->max_down; max_bw = tunnel->max_down;
else else
max_bw = tunnel->max_up; max_bw = tunnel->max_up;
...@@ -812,7 +812,7 @@ static int tb_dp_bandwidth_alloc_mode_enable(struct tb_tunnel *tunnel) ...@@ -812,7 +812,7 @@ static int tb_dp_bandwidth_alloc_mode_enable(struct tb_tunnel *tunnel)
* max_up/down fields. For discovery we just read what the * max_up/down fields. For discovery we just read what the
* estimation was set to. * estimation was set to.
*/ */
if (in->sw->config.depth < out->sw->config.depth) if (tb_port_path_direction_downstream(in, out))
estimated_bw = tunnel->max_down; estimated_bw = tunnel->max_down;
else else
estimated_bw = tunnel->max_up; estimated_bw = tunnel->max_up;
...@@ -982,7 +982,7 @@ static int tb_dp_bandwidth_mode_consumed_bandwidth(struct tb_tunnel *tunnel, ...@@ -982,7 +982,7 @@ static int tb_dp_bandwidth_mode_consumed_bandwidth(struct tb_tunnel *tunnel,
if (allocated_bw == max_bw) if (allocated_bw == max_bw)
allocated_bw = ret; allocated_bw = ret;
if (in->sw->config.depth < out->sw->config.depth) { if (tb_port_path_direction_downstream(in, out)) {
*consumed_up = 0; *consumed_up = 0;
*consumed_down = allocated_bw; *consumed_down = allocated_bw;
} else { } else {
...@@ -1017,7 +1017,7 @@ static int tb_dp_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up ...@@ -1017,7 +1017,7 @@ static int tb_dp_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up
if (allocated_bw == max_bw) if (allocated_bw == max_bw)
allocated_bw = ret; allocated_bw = ret;
if (in->sw->config.depth < out->sw->config.depth) { if (tb_port_path_direction_downstream(in, out)) {
*allocated_up = 0; *allocated_up = 0;
*allocated_down = allocated_bw; *allocated_down = allocated_bw;
} else { } else {
...@@ -1045,7 +1045,7 @@ static int tb_dp_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up, ...@@ -1045,7 +1045,7 @@ static int tb_dp_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up,
if (ret < 0) if (ret < 0)
return ret; return ret;
if (in->sw->config.depth < out->sw->config.depth) { if (tb_port_path_direction_downstream(in, out)) {
tmp = min(*alloc_down, max_bw); tmp = min(*alloc_down, max_bw);
ret = usb4_dp_port_allocate_bandwidth(in, tmp); ret = usb4_dp_port_allocate_bandwidth(in, tmp);
if (ret) if (ret)
...@@ -1143,7 +1143,7 @@ static int tb_dp_maximum_bandwidth(struct tb_tunnel *tunnel, int *max_up, ...@@ -1143,7 +1143,7 @@ static int tb_dp_maximum_bandwidth(struct tb_tunnel *tunnel, int *max_up,
if (ret < 0) if (ret < 0)
return ret; return ret;
if (in->sw->config.depth < tunnel->dst_port->sw->config.depth) { if (tb_port_path_direction_downstream(in, tunnel->dst_port)) {
*max_up = 0; *max_up = 0;
*max_down = ret; *max_down = ret;
} else { } else {
...@@ -1201,7 +1201,7 @@ static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up, ...@@ -1201,7 +1201,7 @@ static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
return 0; return 0;
} }
if (in->sw->config.depth < tunnel->dst_port->sw->config.depth) { if (tb_port_path_direction_downstream(in, tunnel->dst_port)) {
*consumed_up = 0; *consumed_up = 0;
*consumed_down = tb_dp_bandwidth(rate, lanes); *consumed_down = tb_dp_bandwidth(rate, lanes);
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment