Commit 769da970 authored by Mika Westerberg's avatar Mika Westerberg

thunderbolt: Introduce tb_tunnel_direction_downstream()

This helper takes tunnel as parameter. Convert existing code to call
this where possible.

No functional changes.
Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
parent fca0f40a
...@@ -1387,7 +1387,7 @@ tb_recalc_estimated_bandwidth_for_group(struct tb_bandwidth_group *group) ...@@ -1387,7 +1387,7 @@ tb_recalc_estimated_bandwidth_for_group(struct tb_bandwidth_group *group)
* - available bandwidth along the path * - available bandwidth along the path
* - bandwidth allocated for USB 3.x but not used. * - bandwidth allocated for USB 3.x but not used.
*/ */
if (tb_port_path_direction_downstream(in, out)) if (tb_tunnel_direction_downstream(tunnel))
estimated_bw = estimated_down; estimated_bw = estimated_down;
else else
estimated_bw = estimated_up; estimated_bw = estimated_up;
...@@ -2388,11 +2388,11 @@ static void tb_handle_dp_bandwidth_request(struct work_struct *work) ...@@ -2388,11 +2388,11 @@ static void tb_handle_dp_bandwidth_request(struct work_struct *work)
{ {
struct tb_hotplug_event *ev = container_of(work, typeof(*ev), work); struct tb_hotplug_event *ev = container_of(work, typeof(*ev), work);
int requested_bw, requested_up, requested_down, ret; int requested_bw, requested_up, requested_down, ret;
struct tb_port *in, *out;
struct tb_tunnel *tunnel; struct tb_tunnel *tunnel;
struct tb *tb = ev->tb; struct tb *tb = ev->tb;
struct tb_cm *tcm = tb_priv(tb); struct tb_cm *tcm = tb_priv(tb);
struct tb_switch *sw; struct tb_switch *sw;
struct tb_port *in;
pm_runtime_get_sync(&tb->dev); pm_runtime_get_sync(&tb->dev);
...@@ -2456,10 +2456,7 @@ static void tb_handle_dp_bandwidth_request(struct work_struct *work) ...@@ -2456,10 +2456,7 @@ static void tb_handle_dp_bandwidth_request(struct work_struct *work)
tb_port_dbg(in, "requested bandwidth %d Mb/s\n", requested_bw); tb_port_dbg(in, "requested bandwidth %d Mb/s\n", requested_bw);
if (tb_tunnel_direction_downstream(tunnel)) {
out = tunnel->dst_port;
if (tb_port_path_direction_downstream(in, out)) {
requested_up = -1; requested_up = -1;
requested_down = requested_bw; requested_down = requested_bw;
} else { } else {
......
...@@ -706,7 +706,7 @@ static int tb_dp_xchg_caps(struct tb_tunnel *tunnel) ...@@ -706,7 +706,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 (tb_port_path_direction_downstream(in, out)) if (tb_tunnel_direction_downstream(tunnel))
max_bw = tunnel->max_down; max_bw = tunnel->max_down;
else else
max_bw = tunnel->max_up; max_bw = tunnel->max_up;
...@@ -831,7 +831,7 @@ static int tb_dp_bandwidth_alloc_mode_enable(struct tb_tunnel *tunnel) ...@@ -831,7 +831,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 (tb_port_path_direction_downstream(in, out)) if (tb_tunnel_direction_downstream(tunnel))
estimated_bw = tunnel->max_down; estimated_bw = tunnel->max_down;
else else
estimated_bw = tunnel->max_up; estimated_bw = tunnel->max_up;
...@@ -971,7 +971,6 @@ static int tb_dp_bandwidth_mode_consumed_bandwidth(struct tb_tunnel *tunnel, ...@@ -971,7 +971,6 @@ static int tb_dp_bandwidth_mode_consumed_bandwidth(struct tb_tunnel *tunnel,
int *consumed_up, int *consumed_up,
int *consumed_down) int *consumed_down)
{ {
struct tb_port *out = tunnel->dst_port;
struct tb_port *in = tunnel->src_port; struct tb_port *in = tunnel->src_port;
int ret, allocated_bw, max_bw_rounded; int ret, allocated_bw, max_bw_rounded;
...@@ -993,7 +992,7 @@ static int tb_dp_bandwidth_mode_consumed_bandwidth(struct tb_tunnel *tunnel, ...@@ -993,7 +992,7 @@ static int tb_dp_bandwidth_mode_consumed_bandwidth(struct tb_tunnel *tunnel,
if (allocated_bw == max_bw_rounded) if (allocated_bw == max_bw_rounded)
allocated_bw = ret; allocated_bw = ret;
if (tb_port_path_direction_downstream(in, out)) { if (tb_tunnel_direction_downstream(tunnel)) {
*consumed_up = 0; *consumed_up = 0;
*consumed_down = allocated_bw; *consumed_down = allocated_bw;
} else { } else {
...@@ -1007,7 +1006,6 @@ static int tb_dp_bandwidth_mode_consumed_bandwidth(struct tb_tunnel *tunnel, ...@@ -1007,7 +1006,6 @@ static int tb_dp_bandwidth_mode_consumed_bandwidth(struct tb_tunnel *tunnel,
static int tb_dp_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up, static int tb_dp_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up,
int *allocated_down) int *allocated_down)
{ {
struct tb_port *out = tunnel->dst_port;
struct tb_port *in = tunnel->src_port; struct tb_port *in = tunnel->src_port;
/* /*
...@@ -1029,7 +1027,7 @@ static int tb_dp_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up ...@@ -1029,7 +1027,7 @@ static int tb_dp_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up
if (allocated_bw == max_bw_rounded) if (allocated_bw == max_bw_rounded)
allocated_bw = ret; allocated_bw = ret;
if (tb_port_path_direction_downstream(in, out)) { if (tb_tunnel_direction_downstream(tunnel)) {
*allocated_up = 0; *allocated_up = 0;
*allocated_down = allocated_bw; *allocated_down = allocated_bw;
} else { } else {
...@@ -1046,7 +1044,6 @@ static int tb_dp_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up ...@@ -1046,7 +1044,6 @@ static int tb_dp_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up
static int tb_dp_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up, static int tb_dp_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up,
int *alloc_down) int *alloc_down)
{ {
struct tb_port *out = tunnel->dst_port;
struct tb_port *in = tunnel->src_port; struct tb_port *in = tunnel->src_port;
int max_bw_rounded, ret, tmp; int max_bw_rounded, ret, tmp;
...@@ -1057,7 +1054,7 @@ static int tb_dp_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up, ...@@ -1057,7 +1054,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 (tb_port_path_direction_downstream(in, out)) { if (tb_tunnel_direction_downstream(tunnel)) {
tmp = min(*alloc_down, max_bw_rounded); tmp = min(*alloc_down, max_bw_rounded);
ret = usb4_dp_port_allocate_bandwidth(in, tmp); ret = usb4_dp_port_allocate_bandwidth(in, tmp);
if (ret) if (ret)
...@@ -1143,17 +1140,16 @@ static int tb_dp_read_cap(struct tb_tunnel *tunnel, unsigned int cap, u32 *rate, ...@@ -1143,17 +1140,16 @@ static int tb_dp_read_cap(struct tb_tunnel *tunnel, unsigned int cap, u32 *rate,
static int tb_dp_maximum_bandwidth(struct tb_tunnel *tunnel, int *max_up, static int tb_dp_maximum_bandwidth(struct tb_tunnel *tunnel, int *max_up,
int *max_down) int *max_down)
{ {
struct tb_port *in = tunnel->src_port;
int ret; int ret;
if (!usb4_dp_port_bandwidth_mode_enabled(in)) if (!usb4_dp_port_bandwidth_mode_enabled(tunnel->src_port))
return -EOPNOTSUPP; return -EOPNOTSUPP;
ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, NULL); ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, NULL);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (tb_port_path_direction_downstream(in, tunnel->dst_port)) { if (tb_tunnel_direction_downstream(tunnel)) {
*max_up = 0; *max_up = 0;
*max_down = ret; *max_down = ret;
} else { } else {
...@@ -1167,8 +1163,7 @@ static int tb_dp_maximum_bandwidth(struct tb_tunnel *tunnel, int *max_up, ...@@ -1167,8 +1163,7 @@ static int tb_dp_maximum_bandwidth(struct tb_tunnel *tunnel, int *max_up,
static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up, static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
int *consumed_down) int *consumed_down)
{ {
struct tb_port *in = tunnel->src_port; const struct tb_switch *sw = tunnel->src_port->sw;
const struct tb_switch *sw = in->sw;
u32 rate = 0, lanes = 0; u32 rate = 0, lanes = 0;
int ret; int ret;
...@@ -1214,7 +1209,7 @@ static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up, ...@@ -1214,7 +1209,7 @@ static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
return 0; return 0;
} }
if (tb_port_path_direction_downstream(in, tunnel->dst_port)) { if (tb_tunnel_direction_downstream(tunnel)) {
*consumed_up = 0; *consumed_up = 0;
*consumed_down = tb_dp_bandwidth(rate, lanes); *consumed_down = tb_dp_bandwidth(rate, lanes);
} else { } else {
......
...@@ -139,6 +139,12 @@ static inline bool tb_tunnel_is_usb3(const struct tb_tunnel *tunnel) ...@@ -139,6 +139,12 @@ static inline bool tb_tunnel_is_usb3(const struct tb_tunnel *tunnel)
return tunnel->type == TB_TUNNEL_USB3; return tunnel->type == TB_TUNNEL_USB3;
} }
static inline bool tb_tunnel_direction_downstream(const struct tb_tunnel *tunnel)
{
return tb_port_path_direction_downstream(tunnel->src_port,
tunnel->dst_port);
}
const char *tb_tunnel_type_name(const struct tb_tunnel *tunnel); const char *tb_tunnel_type_name(const struct tb_tunnel *tunnel);
#define __TB_TUNNEL_PRINT(level, tunnel, fmt, arg...) \ #define __TB_TUNNEL_PRINT(level, tunnel, fmt, arg...) \
......
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