Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Radion Mirchevsky <radion.mirchevsky@intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

authored by

Radion Mirchevsky and committed by
Mika Westerberg
8e9267bb b6b0ea70

+34
+33
drivers/thunderbolt/switch.c
··· 1479 1479 u8 link; 1480 1480 u8 depth; 1481 1481 const uuid_t *uuid; 1482 + u64 route; 1482 1483 }; 1483 1484 1484 1485 static int tb_switch_match(struct device *dev, void *data) ··· 1494 1493 1495 1494 if (lookup->uuid) 1496 1495 return !memcmp(sw->uuid, lookup->uuid, sizeof(*lookup->uuid)); 1496 + 1497 + if (lookup->route) { 1498 + return sw->config.route_lo == lower_32_bits(lookup->route) && 1499 + sw->config.route_hi == upper_32_bits(lookup->route); 1500 + } 1497 1501 1498 1502 /* Root switch is matched only by depth */ 1499 1503 if (!lookup->depth) ··· 1549 1543 memset(&lookup, 0, sizeof(lookup)); 1550 1544 lookup.tb = tb; 1551 1545 lookup.uuid = uuid; 1546 + 1547 + dev = bus_find_device(&tb_bus_type, NULL, &lookup, tb_switch_match); 1548 + if (dev) 1549 + return tb_to_switch(dev); 1550 + 1551 + return NULL; 1552 + } 1553 + 1554 + /** 1555 + * tb_switch_find_by_route() - Find switch by route string 1556 + * @tb: Domain the switch belongs 1557 + * @route: Route string to look for 1558 + * 1559 + * Returned switch has reference count increased so the caller needs to 1560 + * call tb_switch_put() when done with the switch. 1561 + */ 1562 + struct tb_switch *tb_switch_find_by_route(struct tb *tb, u64 route) 1563 + { 1564 + struct tb_sw_lookup lookup; 1565 + struct device *dev; 1566 + 1567 + if (!route) 1568 + return tb_switch_get(tb->root_switch); 1569 + 1570 + memset(&lookup, 0, sizeof(lookup)); 1571 + lookup.tb = tb; 1572 + lookup.route = route; 1552 1573 1553 1574 dev = bus_find_device(&tb_bus_type, NULL, &lookup, tb_switch_match); 1554 1575 if (dev)
+1
drivers/thunderbolt/tb.h
··· 386 386 struct tb_switch *tb_switch_find_by_link_depth(struct tb *tb, u8 link, 387 387 u8 depth); 388 388 struct tb_switch *tb_switch_find_by_uuid(struct tb *tb, const uuid_t *uuid); 389 + struct tb_switch *tb_switch_find_by_route(struct tb *tb, u64 route); 389 390 390 391 static inline struct tb_switch *tb_switch_get(struct tb_switch *sw) 391 392 {