summaryrefslogtreecommitdiff
path: root/drivers/thunderbolt/path.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/thunderbolt/path.c')
-rw-r--r--drivers/thunderbolt/path.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/drivers/thunderbolt/path.c b/drivers/thunderbolt/path.c
index ad58559ea88e..03e7b714deab 100644
--- a/drivers/thunderbolt/path.c
+++ b/drivers/thunderbolt/path.c
@@ -229,7 +229,7 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,
struct tb_port *dst, int dst_hopid, int link_nr,
const char *name)
{
- struct tb_port *in_port, *out_port;
+ struct tb_port *in_port, *out_port, *first_port, *last_port;
int in_hopid, out_hopid;
struct tb_path *path;
size_t num_hops;
@@ -239,12 +239,23 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,
if (!path)
return NULL;
- /*
- * Number of hops on a path is the distance between the two
- * switches plus the source adapter port.
- */
- num_hops = abs(tb_route_length(tb_route(src->sw)) -
- tb_route_length(tb_route(dst->sw))) + 1;
+ first_port = last_port = NULL;
+ i = 0;
+ tb_for_each_port_on_path(src, dst, in_port) {
+ if (!first_port)
+ first_port = in_port;
+ last_port = in_port;
+ i++;
+ }
+
+ /* Check that src and dst are reachable */
+ if (first_port != src || last_port != dst) {
+ kfree(path);
+ return NULL;
+ }
+
+ /* Each hop takes two ports */
+ num_hops = i / 2;
path->hops = kcalloc(num_hops, sizeof(*path->hops), GFP_KERNEL);
if (!path->hops) {
@@ -559,21 +570,20 @@ bool tb_path_is_invalid(struct tb_path *path)
}
/**
- * tb_path_switch_on_path() - Does the path go through certain switch
+ * tb_path_port_on_path() - Does the path go through certain port
* @path: Path to check
- * @sw: Switch to check
+ * @port: Switch to check
*
- * Goes over all hops on path and checks if @sw is any of them.
+ * Goes over all hops on path and checks if @port is any of them.
* Direction does not matter.
*/
-bool tb_path_switch_on_path(const struct tb_path *path,
- const struct tb_switch *sw)
+bool tb_path_port_on_path(const struct tb_path *path, const struct tb_port *port)
{
int i;
for (i = 0; i < path->path_length; i++) {
- if (path->hops[i].in_port->sw == sw ||
- path->hops[i].out_port->sw == sw)
+ if (path->hops[i].in_port == port ||
+ path->hops[i].out_port == port)
return true;
}