提交 8e9267bb 编写于 作者: R Radion Mirchevsky 提交者: Mika Westerberg

thunderbolt: Add tb_switch_find_by_route()

With the new ICM messaging there is need for find switch by route string
instead of link and depth. Add new function that makes it possible.
Signed-off-by: NRadion Mirchevsky <radion.mirchevsky@intel.com>
Signed-off-by: NMika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: NAndy Shevchenko <andy.shevchenko@gmail.com>
上级 b6b0ea70
...@@ -1479,6 +1479,7 @@ struct tb_sw_lookup { ...@@ -1479,6 +1479,7 @@ struct tb_sw_lookup {
u8 link; u8 link;
u8 depth; u8 depth;
const uuid_t *uuid; const uuid_t *uuid;
u64 route;
}; };
static int tb_switch_match(struct device *dev, void *data) static int tb_switch_match(struct device *dev, void *data)
...@@ -1494,6 +1495,11 @@ static int tb_switch_match(struct device *dev, void *data) ...@@ -1494,6 +1495,11 @@ static int tb_switch_match(struct device *dev, void *data)
if (lookup->uuid) if (lookup->uuid)
return !memcmp(sw->uuid, lookup->uuid, sizeof(*lookup->uuid)); return !memcmp(sw->uuid, lookup->uuid, sizeof(*lookup->uuid));
if (lookup->route) {
return sw->config.route_lo == lower_32_bits(lookup->route) &&
sw->config.route_hi == upper_32_bits(lookup->route);
}
/* Root switch is matched only by depth */ /* Root switch is matched only by depth */
if (!lookup->depth) if (!lookup->depth)
return !sw->depth; return !sw->depth;
...@@ -1551,6 +1557,33 @@ struct tb_switch *tb_switch_find_by_uuid(struct tb *tb, const uuid_t *uuid) ...@@ -1551,6 +1557,33 @@ struct tb_switch *tb_switch_find_by_uuid(struct tb *tb, const uuid_t *uuid)
return NULL; return NULL;
} }
/**
* tb_switch_find_by_route() - Find switch by route string
* @tb: Domain the switch belongs
* @route: Route string to look for
*
* Returned switch has reference count increased so the caller needs to
* call tb_switch_put() when done with the switch.
*/
struct tb_switch *tb_switch_find_by_route(struct tb *tb, u64 route)
{
struct tb_sw_lookup lookup;
struct device *dev;
if (!route)
return tb_switch_get(tb->root_switch);
memset(&lookup, 0, sizeof(lookup));
lookup.tb = tb;
lookup.route = route;
dev = bus_find_device(&tb_bus_type, NULL, &lookup, tb_switch_match);
if (dev)
return tb_to_switch(dev);
return NULL;
}
void tb_switch_exit(void) void tb_switch_exit(void)
{ {
ida_destroy(&nvm_ida); ida_destroy(&nvm_ida);
......
...@@ -386,6 +386,7 @@ struct tb_switch *get_switch_at_route(struct tb_switch *sw, u64 route); ...@@ -386,6 +386,7 @@ struct tb_switch *get_switch_at_route(struct tb_switch *sw, u64 route);
struct tb_switch *tb_switch_find_by_link_depth(struct tb *tb, u8 link, struct tb_switch *tb_switch_find_by_link_depth(struct tb *tb, u8 link,
u8 depth); u8 depth);
struct tb_switch *tb_switch_find_by_uuid(struct tb *tb, const uuid_t *uuid); struct tb_switch *tb_switch_find_by_uuid(struct tb *tb, const uuid_t *uuid);
struct tb_switch *tb_switch_find_by_route(struct tb *tb, u64 route);
static inline struct tb_switch *tb_switch_get(struct tb_switch *sw) static inline struct tb_switch *tb_switch_get(struct tb_switch *sw)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册