staticint tb_path_find_src_hopid(struct tb_port *src, conststruct tb_port *dst, int dst_hopid)
{ struct tb_port *out; int i;
for (i = TB_PATH_MIN_HOPID; i <= src->config.max_in_hop_id; i++) {
out = tb_path_find_dst_port(src, i, dst_hopid); if (out == dst) return i;
}
return 0;
}
/** * tb_path_discover() - Discover a path * @src: First input port of a path * @src_hopid: Starting HopID of a path (%-1 if don't care) * @dst: Expected destination port of the path (%NULL if don't care) * @dst_hopid: HopID to the @dst (%-1 if don't care) * @last: Last port is filled here if not %NULL * @name: Name of the path * @alloc_hopid: Allocate HopIDs for the ports * * Follows a path starting from @src and @src_hopid to the last output * port of the path. Allocates HopIDs for the visited ports (if * @alloc_hopid is true). Call tb_path_free() to release the path and * allocated HopIDs when the path is not needed anymore. * * Note function discovers also incomplete paths so caller should check * that the @dst port is the expected one. If it is not, the path can be * cleaned up by calling tb_path_deactivate() before tb_path_free(). * * Return: Discovered path on success, %NULL in case of failure
*/ struct tb_path *tb_path_discover(struct tb_port *src, int src_hopid, struct tb_port *dst, int dst_hopid, struct tb_port **last, constchar *name, bool alloc_hopid)
{ struct tb_port *out_port; struct tb_regs_hop hop; struct tb_path *path; struct tb_switch *sw; struct tb_port *p;
size_t num_hops; int ret, i, h;
if (src_hopid < 0 && dst) { /* * For incomplete paths the intermediate HopID can be * different from the one used by the protocol adapter * so in that case find a path that ends on @dst with * matching @dst_hopid. That should give us the correct * HopID for the @src.
*/
src_hopid = tb_path_find_src_hopid(src, dst, dst_hopid); if (!src_hopid) return NULL;
}
p = src;
h = src_hopid;
num_hops = 0;
for (i = 0; p && i < TB_PATH_MAX_HOPS; i++) {
sw = p->sw;
ret = tb_port_read(p, &hop, TB_CFG_HOPS, 2 * h, 2); if (ret) {
tb_port_warn(p, "failed to read path at %d\n", h); return NULL;
}
/* If the hop is not enabled we got an incomplete path */ if (!hop.enable) break;
out_port = &sw->ports[hop.out_port]; if (last)
*last = out_port;
h = hop.next_hop;
p = out_port->remote;
num_hops++;
}
path = kzalloc(sizeof(*path), GFP_KERNEL); if (!path) return NULL;
err:
tb_port_warn(src, "failed to discover path starting at HopID %d\n",
src_hopid);
tb_path_free(path); return NULL;
}
/** * tb_path_alloc() - allocate a thunderbolt path between two ports * @tb: Domain pointer * @src: Source port of the path * @src_hopid: HopID used for the first ingress port in the path * @dst: Destination port of the path * @dst_hopid: HopID used for the last egress port in the path * @link_nr: Preferred link if there are dual links on the path * @name: Name of the path * * Creates path between two ports starting with given @src_hopid. Reserves * HopIDs for each port (they can be different from @src_hopid depending on * how many HopIDs each port already have reserved). If there are dual * links on the path, prioritizes using @link_nr but takes into account * that the lanes may be bonded. * * Return: Returns a tb_path on success or NULL on failure.
*/ 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, constchar *name)
{ struct tb_port *in_port, *out_port, *first_port, *last_port; int in_hopid, out_hopid; struct tb_path *path;
size_t num_hops; int i, ret;
path = kzalloc(sizeof(*path), GFP_KERNEL); if (!path) return NULL;
for (i = 0; i < num_hops; i++) {
in_port = tb_next_port_on_path(src, dst, out_port); if (!in_port) goto err;
/* When lanes are bonded primary link must be used */ if (!in_port->bonded && in_port->dual_link_port &&
in_port->link_nr != link_nr)
in_port = in_port->dual_link_port;
ret = tb_port_alloc_in_hopid(in_port, in_hopid, in_hopid); if (ret < 0) goto err;
in_hopid = ret;
out_port = tb_next_port_on_path(src, dst, in_port); if (!out_port) goto err;
/* * Pick up right port when going from non-bonded to * bonded or from bonded to non-bonded.
*/ if (out_port->dual_link_port) { if (!in_port->bonded && out_port->bonded &&
out_port->link_nr) { /* * Use primary link when going from * non-bonded to bonded.
*/
out_port = out_port->dual_link_port;
} elseif (!out_port->bonded &&
out_port->link_nr != link_nr) { /* * If out port is not bonded follow * link_nr.
*/
out_port = out_port->dual_link_port;
}
}
if (i == num_hops - 1)
ret = tb_port_alloc_out_hopid(out_port, dst_hopid,
dst_hopid); else
ret = tb_port_alloc_out_hopid(out_port, -1, -1);
/** * tb_path_free() - free a path * @path: Path to free * * Frees a path. The path does not need to be deactivated.
*/ void tb_path_free(struct tb_path *path)
{ if (path->alloc_hopid) { int i;
for (i = 0; i < path->path_length; i++) { conststruct tb_path_hop *hop = &path->hops[i];
if (hop->in_port)
tb_port_release_in_hopid(hop->in_port,
hop->in_hop_index); if (hop->out_port)
tb_port_release_out_hopid(hop->out_port,
hop->next_hop_index);
}
}
kfree(path->hops);
kfree(path);
}
staticvoid __tb_path_deallocate_nfc(struct tb_path *path, int first_hop)
{ int i, res; for (i = first_hop; i < path->path_length; i++) {
res = tb_port_add_nfc_credits(path->hops[i].in_port,
-path->hops[i].nfc_credits); if (res)
tb_port_warn(path->hops[i].in_port, "nfc credits deallocation failed for hop %d\n",
i);
}
}
staticint __tb_path_deactivate_hop(struct tb_port *port, int hop_index, bool clear_fc)
{ struct tb_regs_hop hop;
ktime_t timeout; int ret;
/* Disable the path */
ret = tb_port_read(port, &hop, TB_CFG_HOPS, 2 * hop_index, 2); if (ret) return ret;
/* Already disabled */ if (!hop.enable) return 0;
hop.enable = 0;
ret = tb_port_write(port, &hop, TB_CFG_HOPS, 2 * hop_index, 2); if (ret) return ret;
/* Wait until it is drained */
timeout = ktime_add_ms(ktime_get(), 500); do {
ret = tb_port_read(port, &hop, TB_CFG_HOPS, 2 * hop_index, 2); if (ret) return ret;
if (!hop.pending) { if (clear_fc) { /* * Clear flow control. Protocol adapters * IFC and ISE bits are vendor defined * in the USB4 spec so we clear them * only for pre-USB4 adapters.
*/ if (!tb_switch_is_usb4(port->sw)) {
hop.ingress_fc = 0;
hop.ingress_shared_buffer = 0;
}
hop.egress_fc = 0;
hop.egress_shared_buffer = 0;
usleep_range(10, 20);
} while (ktime_before(ktime_get(), timeout));
return -ETIMEDOUT;
}
/** * tb_path_deactivate_hop() - Deactivate one path in path config space * @port: Lane or protocol adapter * @hop_index: HopID of the path to be cleared * * This deactivates or clears a single path config space entry at * @hop_index. Returns %0 in success and negative errno otherwise.
*/ int tb_path_deactivate_hop(struct tb_port *port, int hop_index)
{ return __tb_path_deactivate_hop(port, hop_index, true);
}
staticvoid __tb_path_deactivate_hops(struct tb_path *path, int first_hop)
{ int i, res;
for (i = first_hop; i < path->path_length; i++) {
res = __tb_path_deactivate_hop(path->hops[i].in_port,
path->hops[i].in_hop_index,
path->clear_fc); if (res && res != -ENODEV)
tb_port_warn(path->hops[i].in_port, "hop deactivation failed for hop %d, index %d\n",
i, path->hops[i].in_hop_index);
}
}
void tb_path_deactivate(struct tb_path *path)
{ if (!path->activated) {
tb_WARN(path->tb, "trying to deactivate an inactive path\n"); return;
}
tb_dbg(path->tb, "deactivating %s path from %llx:%u to %llx:%u\n",
path->name, tb_route(path->hops[0].in_port->sw),
path->hops[0].in_port->port,
tb_route(path->hops[path->path_length - 1].out_port->sw),
path->hops[path->path_length - 1].out_port->port);
__tb_path_deactivate_hops(path, 0);
__tb_path_deallocate_nfc(path, 0);
path->activated = false;
}
/** * tb_path_activate() - activate a path * @path: Path to activate * * Activate a path starting with the last hop and iterating backwards. The * caller must fill path->hops before calling tb_path_activate(). * * Return: Returns 0 on success or an error code on failure.
*/ int tb_path_activate(struct tb_path *path)
{ int i, res; enum tb_path_port out_mask, in_mask; if (path->activated) {
tb_WARN(path->tb, "trying to activate already activated path\n"); return -EINVAL;
}
tb_dbg(path->tb, "activating %s path from %llx:%u to %llx:%u\n",
path->name, tb_route(path->hops[0].in_port->sw),
path->hops[0].in_port->port,
tb_route(path->hops[path->path_length - 1].out_port->sw),
path->hops[path->path_length - 1].out_port->port);
/* Clear counters. */ for (i = path->path_length - 1; i >= 0; i--) { if (path->hops[i].in_counter_index == -1) continue;
res = tb_port_clear_counter(path->hops[i].in_port,
path->hops[i].in_counter_index); if (res) goto err;
}
/* Add non flow controlled credits. */ for (i = path->path_length - 1; i >= 0; i--) {
res = tb_port_add_nfc_credits(path->hops[i].in_port,
path->hops[i].nfc_credits); if (res) {
__tb_path_deallocate_nfc(path, i); goto err;
}
}
/* Activate hops. */ for (i = path->path_length - 1; i >= 0; i--) { struct tb_regs_hop hop = { 0 };
/* If it is left active deactivate it first */
__tb_path_deactivate_hop(path->hops[i].in_port,
path->hops[i].in_hop_index, path->clear_fc);
/** * tb_path_is_invalid() - check whether any ports on the path are invalid * @path: Path to check * * Return: Returns true if the path is invalid, false otherwise.
*/ bool tb_path_is_invalid(struct tb_path *path)
{ int i = 0; for (i = 0; i < path->path_length; i++) { if (path->hops[i].in_port->sw->is_unplugged) returntrue; if (path->hops[i].out_port->sw->is_unplugged) returntrue;
} returnfalse;
}
/** * tb_path_port_on_path() - Does the path go through certain port * @path: Path to check * @port: Switch to check * * Goes over all hops on path and checks if @port is any of them. * Direction does not matter.
*/ bool tb_path_port_on_path(conststruct tb_path *path, conststruct tb_port *port)
{ int i;
for (i = 0; i < path->path_length; i++) { if (path->hops[i].in_port == port ||
path->hops[i].out_port == port) returntrue;
}
returnfalse;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.