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

thunderbolt: Add tb_xdomain_find_by_route()

This is needed by the new ICM interface to find xdomains by route string
instead of link and depth.

While there update existing tb_xdomain_find_* functions to use
tb_xdomain_get() instead of open-coding the same.

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
484cb153 8e9267bb

+49 -13
+36 -13
drivers/thunderbolt/xdomain.c
··· 1255 1255 const uuid_t *uuid; 1256 1256 u8 link; 1257 1257 u8 depth; 1258 + u64 route; 1258 1259 }; 1259 1260 1260 1261 static struct tb_xdomain *switch_find_xdomain(struct tb_switch *sw, ··· 1276 1275 if (lookup->uuid) { 1277 1276 if (uuid_equal(xd->remote_uuid, lookup->uuid)) 1278 1277 return xd; 1279 - } else if (lookup->link == xd->link && 1278 + } else if (lookup->link && 1279 + lookup->link == xd->link && 1280 1280 lookup->depth == xd->depth) { 1281 + return xd; 1282 + } else if (lookup->route && 1283 + lookup->route == xd->route) { 1281 1284 return xd; 1282 1285 } 1283 1286 } else if (port->remote) { ··· 1318 1313 lookup.uuid = uuid; 1319 1314 1320 1315 xd = switch_find_xdomain(tb->root_switch, &lookup); 1321 - if (xd) { 1322 - get_device(&xd->dev); 1323 - return xd; 1324 - } 1325 - 1326 - return NULL; 1316 + return tb_xdomain_get(xd); 1327 1317 } 1328 1318 EXPORT_SYMBOL_GPL(tb_xdomain_find_by_uuid); 1329 1319 ··· 1349 1349 lookup.depth = depth; 1350 1350 1351 1351 xd = switch_find_xdomain(tb->root_switch, &lookup); 1352 - if (xd) { 1353 - get_device(&xd->dev); 1354 - return xd; 1355 - } 1356 - 1357 - return NULL; 1352 + return tb_xdomain_get(xd); 1358 1353 } 1354 + 1355 + /** 1356 + * tb_xdomain_find_by_route() - Find an XDomain by route string 1357 + * @tb: Domain where the XDomain belongs to 1358 + * @route: XDomain route string 1359 + * 1360 + * Finds XDomain by walking through the Thunderbolt topology below @tb. 1361 + * The returned XDomain will have its reference count increased so the 1362 + * caller needs to call tb_xdomain_put() when it is done with the 1363 + * object. 1364 + * 1365 + * This will find all XDomains including the ones that are not yet added 1366 + * to the bus (handshake is still in progress). 1367 + * 1368 + * The caller needs to hold @tb->lock. 1369 + */ 1370 + struct tb_xdomain *tb_xdomain_find_by_route(struct tb *tb, u64 route) 1371 + { 1372 + struct tb_xdomain_lookup lookup; 1373 + struct tb_xdomain *xd; 1374 + 1375 + memset(&lookup, 0, sizeof(lookup)); 1376 + lookup.route = route; 1377 + 1378 + xd = switch_find_xdomain(tb->root_switch, &lookup); 1379 + return tb_xdomain_get(xd); 1380 + } 1381 + EXPORT_SYMBOL_GPL(tb_xdomain_find_by_route); 1359 1382 1360 1383 bool tb_xdomain_handle_request(struct tb *tb, enum tb_cfg_pkg_type type, 1361 1384 const void *buf, size_t size)
+13
include/linux/thunderbolt.h
··· 237 237 u16 receive_ring); 238 238 int tb_xdomain_disable_paths(struct tb_xdomain *xd); 239 239 struct tb_xdomain *tb_xdomain_find_by_uuid(struct tb *tb, const uuid_t *uuid); 240 + struct tb_xdomain *tb_xdomain_find_by_route(struct tb *tb, u64 route); 240 241 241 242 static inline struct tb_xdomain * 242 243 tb_xdomain_find_by_uuid_locked(struct tb *tb, const uuid_t *uuid) ··· 246 245 247 246 mutex_lock(&tb->lock); 248 247 xd = tb_xdomain_find_by_uuid(tb, uuid); 248 + mutex_unlock(&tb->lock); 249 + 250 + return xd; 251 + } 252 + 253 + static inline struct tb_xdomain * 254 + tb_xdomain_find_by_route_locked(struct tb *tb, u64 route) 255 + { 256 + struct tb_xdomain *xd; 257 + 258 + mutex_lock(&tb->lock); 259 + xd = tb_xdomain_find_by_route(tb, route); 249 260 mutex_unlock(&tb->lock); 250 261 251 262 return xd;