Lines Matching full:path

3  * Thunderbolt driver - path/tunnel functionality
50 tb_port_warn(port, "failed to read path at %d\n", hopid); in tb_path_find_dst_port()
81 * tb_path_discover() - Discover a path
82 * @src: First input port of a path
83 * @src_hopid: Starting HopID of a path (%-1 if don't care)
84 * @dst: Expected destination port of the path (%NULL if don't care)
87 * @name: Name of the path
90 * Follows a path starting from @src and @src_hopid to the last output
91 * port of the path. Allocates HopIDs for the visited ports (if
92 * @alloc_hopid is true). Call tb_path_free() to release the path and
93 * allocated HopIDs when the path is not needed anymore.
96 * that the @dst port is the expected one. If it is not, the path can be
99 * Return: Discovered path on success, %NULL in case of failure
108 struct tb_path *path; in tb_path_discover() local
118 * so in that case find a path that ends on @dst with in tb_path_discover()
136 tb_port_warn(p, "failed to read path at %d\n", h); in tb_path_discover()
140 /* If the hop is not enabled we got an incomplete path */ in tb_path_discover()
153 path = kzalloc(sizeof(*path), GFP_KERNEL); in tb_path_discover()
154 if (!path) in tb_path_discover()
157 path->name = name; in tb_path_discover()
158 path->tb = src->sw->tb; in tb_path_discover()
159 path->path_length = num_hops; in tb_path_discover()
160 path->activated = true; in tb_path_discover()
161 path->alloc_hopid = alloc_hopid; in tb_path_discover()
163 path->hops = kcalloc(num_hops, sizeof(*path->hops), GFP_KERNEL); in tb_path_discover()
164 if (!path->hops) { in tb_path_discover()
165 kfree(path); in tb_path_discover()
169 tb_dbg(path->tb, "discovering %s path starting from %llx:%u\n", in tb_path_discover()
170 path->name, tb_route(src->sw), src->port); in tb_path_discover()
182 tb_port_warn(p, "failed to read path at %d\n", h); in tb_path_discover()
198 path->hops[i].in_port = p; in tb_path_discover()
199 path->hops[i].in_hop_index = h; in tb_path_discover()
200 path->hops[i].in_counter_index = -1; in tb_path_discover()
201 path->hops[i].out_port = out_port; in tb_path_discover()
202 path->hops[i].next_hop_index = next_hop; in tb_path_discover()
204 tb_dump_hop(&path->hops[i], &hop); in tb_path_discover()
210 tb_dbg(path->tb, "path discovery complete\n"); in tb_path_discover()
211 return path; in tb_path_discover()
214 tb_port_warn(src, "failed to discover path starting at HopID %d\n", in tb_path_discover()
216 tb_path_free(path); in tb_path_discover()
221 * tb_path_alloc() - allocate a thunderbolt path between two ports
223 * @src: Source port of the path
224 * @src_hopid: HopID used for the first ingress port in the path
225 * @dst: Destination port of the path
226 * @dst_hopid: HopID used for the last egress port in the path
227 * @link_nr: Preferred link if there are dual links on the path
228 * @name: Name of the path
230 * Creates path between two ports starting with given @src_hopid. Reserves
233 * links on the path, prioritizes using @link_nr but takes into account
244 struct tb_path *path; in tb_path_alloc() local
248 path = kzalloc(sizeof(*path), GFP_KERNEL); in tb_path_alloc()
249 if (!path) in tb_path_alloc()
263 kfree(path); in tb_path_alloc()
270 path->hops = kcalloc(num_hops, sizeof(*path->hops), GFP_KERNEL); in tb_path_alloc()
271 if (!path->hops) { in tb_path_alloc()
272 kfree(path); in tb_path_alloc()
276 path->alloc_hopid = true; in tb_path_alloc()
332 path->hops[i].in_hop_index = in_hopid; in tb_path_alloc()
333 path->hops[i].in_port = in_port; in tb_path_alloc()
334 path->hops[i].in_counter_index = -1; in tb_path_alloc()
335 path->hops[i].out_port = out_port; in tb_path_alloc()
336 path->hops[i].next_hop_index = out_hopid; in tb_path_alloc()
341 path->tb = tb; in tb_path_alloc()
342 path->path_length = num_hops; in tb_path_alloc()
343 path->name = name; in tb_path_alloc()
345 return path; in tb_path_alloc()
348 tb_path_free(path); in tb_path_alloc()
353 * tb_path_free() - free a path
354 * @path: Path to free
356 * Frees a path. The path does not need to be deactivated.
358 void tb_path_free(struct tb_path *path) in tb_path_free() argument
360 if (path->alloc_hopid) { in tb_path_free()
363 for (i = 0; i < path->path_length; i++) { in tb_path_free()
364 const struct tb_path_hop *hop = &path->hops[i]; in tb_path_free()
375 kfree(path->hops); in tb_path_free()
376 kfree(path); in tb_path_free()
379 static void __tb_path_deallocate_nfc(struct tb_path *path, int first_hop) in __tb_path_deallocate_nfc() argument
382 for (i = first_hop; i < path->path_length; i++) { in __tb_path_deallocate_nfc()
383 res = tb_port_add_nfc_credits(path->hops[i].in_port, in __tb_path_deallocate_nfc()
384 -path->hops[i].nfc_credits); in __tb_path_deallocate_nfc()
386 tb_port_warn(path->hops[i].in_port, in __tb_path_deallocate_nfc()
399 /* Disable the path */ in __tb_path_deactivate_hop()
449 static void __tb_path_deactivate_hops(struct tb_path *path, int first_hop) in __tb_path_deactivate_hops() argument
453 for (i = first_hop; i < path->path_length; i++) { in __tb_path_deactivate_hops()
454 res = __tb_path_deactivate_hop(path->hops[i].in_port, in __tb_path_deactivate_hops()
455 path->hops[i].in_hop_index, in __tb_path_deactivate_hops()
456 path->clear_fc); in __tb_path_deactivate_hops()
458 tb_port_warn(path->hops[i].in_port, in __tb_path_deactivate_hops()
460 i, path->hops[i].in_hop_index); in __tb_path_deactivate_hops()
464 void tb_path_deactivate(struct tb_path *path) in tb_path_deactivate() argument
466 if (!path->activated) { in tb_path_deactivate()
467 tb_WARN(path->tb, "trying to deactivate an inactive path\n"); in tb_path_deactivate()
470 tb_dbg(path->tb, in tb_path_deactivate()
471 "deactivating %s path from %llx:%u to %llx:%u\n", in tb_path_deactivate()
472 path->name, tb_route(path->hops[0].in_port->sw), in tb_path_deactivate()
473 path->hops[0].in_port->port, in tb_path_deactivate()
474 tb_route(path->hops[path->path_length - 1].out_port->sw), in tb_path_deactivate()
475 path->hops[path->path_length - 1].out_port->port); in tb_path_deactivate()
476 __tb_path_deactivate_hops(path, 0); in tb_path_deactivate()
477 __tb_path_deallocate_nfc(path, 0); in tb_path_deactivate()
478 path->activated = false; in tb_path_deactivate()
482 * tb_path_activate() - activate a path
483 * @path: Path to activate
485 * Activate a path starting with the last hop and iterating backwards. The
486 * caller must fill path->hops before calling tb_path_activate().
490 int tb_path_activate(struct tb_path *path) in tb_path_activate() argument
494 if (path->activated) { in tb_path_activate()
495 tb_WARN(path->tb, "trying to activate already activated path\n"); in tb_path_activate()
499 tb_dbg(path->tb, in tb_path_activate()
500 "activating %s path from %llx:%u to %llx:%u\n", in tb_path_activate()
501 path->name, tb_route(path->hops[0].in_port->sw), in tb_path_activate()
502 path->hops[0].in_port->port, in tb_path_activate()
503 tb_route(path->hops[path->path_length - 1].out_port->sw), in tb_path_activate()
504 path->hops[path->path_length - 1].out_port->port); in tb_path_activate()
507 for (i = path->path_length - 1; i >= 0; i--) { in tb_path_activate()
508 if (path->hops[i].in_counter_index == -1) in tb_path_activate()
510 res = tb_port_clear_counter(path->hops[i].in_port, in tb_path_activate()
511 path->hops[i].in_counter_index); in tb_path_activate()
517 for (i = path->path_length - 1; i >= 0; i--) { in tb_path_activate()
518 res = tb_port_add_nfc_credits(path->hops[i].in_port, in tb_path_activate()
519 path->hops[i].nfc_credits); in tb_path_activate()
521 __tb_path_deallocate_nfc(path, i); in tb_path_activate()
527 for (i = path->path_length - 1; i >= 0; i--) { in tb_path_activate()
531 __tb_path_deactivate_hop(path->hops[i].in_port, in tb_path_activate()
532 path->hops[i].in_hop_index, path->clear_fc); in tb_path_activate()
535 hop.next_hop = path->hops[i].next_hop_index; in tb_path_activate()
536 hop.out_port = path->hops[i].out_port->port; in tb_path_activate()
537 hop.initial_credits = path->hops[i].initial_credits; in tb_path_activate()
542 out_mask = (i == path->path_length - 1) ? in tb_path_activate()
545 hop.weight = path->weight; in tb_path_activate()
547 hop.priority = path->priority; in tb_path_activate()
548 hop.drop_packages = path->drop_packages; in tb_path_activate()
549 hop.counter = path->hops[i].in_counter_index; in tb_path_activate()
550 hop.counter_enable = path->hops[i].in_counter_index != -1; in tb_path_activate()
551 hop.ingress_fc = path->ingress_fc_enable & in_mask; in tb_path_activate()
552 hop.egress_fc = path->egress_fc_enable & out_mask; in tb_path_activate()
553 hop.ingress_shared_buffer = path->ingress_shared_buffer in tb_path_activate()
555 hop.egress_shared_buffer = path->egress_shared_buffer in tb_path_activate()
559 tb_port_dbg(path->hops[i].in_port, "Writing hop %d\n", i); in tb_path_activate()
560 tb_dump_hop(&path->hops[i], &hop); in tb_path_activate()
561 res = tb_port_write(path->hops[i].in_port, &hop, TB_CFG_HOPS, in tb_path_activate()
562 2 * path->hops[i].in_hop_index, 2); in tb_path_activate()
564 __tb_path_deactivate_hops(path, i); in tb_path_activate()
565 __tb_path_deallocate_nfc(path, 0); in tb_path_activate()
569 path->activated = true; in tb_path_activate()
570 tb_dbg(path->tb, "path activation complete\n"); in tb_path_activate()
573 tb_WARN(path->tb, "path activation failed\n"); in tb_path_activate()
578 * tb_path_is_invalid() - check whether any ports on the path are invalid
579 * @path: Path to check
581 * Return: Returns true if the path is invalid, false otherwise.
583 bool tb_path_is_invalid(struct tb_path *path) in tb_path_is_invalid() argument
586 for (i = 0; i < path->path_length; i++) { in tb_path_is_invalid()
587 if (path->hops[i].in_port->sw->is_unplugged) in tb_path_is_invalid()
589 if (path->hops[i].out_port->sw->is_unplugged) in tb_path_is_invalid()
596 * tb_path_port_on_path() - Does the path go through certain port
597 * @path: Path to check
600 * Goes over all hops on path and checks if @port is any of them.
603 bool tb_path_port_on_path(const struct tb_path *path, const struct tb_port *port) in tb_path_port_on_path() argument
607 for (i = 0; i < path->path_length; i++) { in tb_path_port_on_path()
608 if (path->hops[i].in_port == port || in tb_path_port_on_path()
609 path->hops[i].out_port == port) in tb_path_port_on_path()