Lines Matching +full:port +full:-
2 * Copyright (c) 2004-2009 Voltaire Inc. All rights reserved.
16 * - Redistributions of source code must retain the above
20 * - Redistributions in binary form must reproduce the above
74 typedef struct Port Port; typedef
78 struct Port { struct
79 Port *next; argument
80 Port *remoteport; argument
103 Port *ports; argument
120 * Checks whether or not the port state is other than active.
121 * The "sw" argument is only relevant when the port is on a
123 * Returns 1 when port is not active and 0 when active.
124 * Base switch port 0 is considered always active.
126 static int is_port_inactive(Node * node, Port * port, Switch * sw) in is_port_inactive() argument
129 if (port->state != 4 && in is_port_inactive()
130 (node->type != IB_NODE_SWITCH || in is_port_inactive()
131 (node->type == IB_NODE_SWITCH && sw->enhsp0))) in is_port_inactive()
136 static int get_node(Node * node, Port * port, ib_portid_t * portid) in get_node() argument
138 void *pi = port->portinfo, *ni = node->nodeinfo, *nd = node->nodedesc; in get_node()
141 memset(ni, 0, sizeof(node->nodeinfo)); in get_node()
143 return -1; in get_node()
145 memset(nd, 0, sizeof(node->nodedesc)); in get_node()
147 return -1; in get_node()
156 memset(pi, 0, sizeof(port->portinfo)); in get_node()
158 return -1; in get_node()
160 mad_decode_field(ni, IB_NODE_GUID_F, &node->nodeguid); in get_node()
161 mad_decode_field(ni, IB_NODE_TYPE_F, &node->type); in get_node()
162 mad_decode_field(ni, IB_NODE_NPORTS_F, &node->numports); in get_node()
164 mad_decode_field(ni, IB_NODE_PORT_GUID_F, &port->portguid); in get_node()
165 mad_decode_field(ni, IB_NODE_LOCAL_PORT_F, &port->portnum); in get_node()
166 mad_decode_field(pi, IB_PORT_LID_F, &port->lid); in get_node()
167 mad_decode_field(pi, IB_PORT_LMC_F, &port->lmc); in get_node()
168 mad_decode_field(pi, IB_PORT_STATE_F, &port->state); in get_node()
171 node->nodeguid, node->nodedesc); in get_node()
177 void *si = sw->switchinfo, *fdb = sw->fdb; in switch_lookup()
179 memset(si, 0, sizeof(sw->switchinfo)); in switch_lookup()
182 return -1; in switch_lookup()
184 mad_decode_field(si, IB_SW_LINEAR_FDB_CAP_F, &sw->linearcap); in switch_lookup()
185 mad_decode_field(si, IB_SW_LINEAR_FDB_TOP_F, &sw->linearFDBtop); in switch_lookup()
186 mad_decode_field(si, IB_SW_ENHANCED_PORT0_F, &sw->enhsp0); in switch_lookup()
188 if (lid >= sw->linearcap && lid > sw->linearFDBtop) in switch_lookup()
189 return -1; in switch_lookup()
191 memset(fdb, 0, sizeof(sw->fdb)); in switch_lookup()
194 return -1; in switch_lookup()
196 DEBUG("portid %s: forward lid %d to port %d", in switch_lookup()
197 portid2str(portid), lid, sw->fdb[lid % 64]); in switch_lookup()
198 return sw->fdb[lid % 64]; in switch_lookup()
201 static int sameport(Port * a, Port * b) in sameport()
203 return a->portguid == b->portguid || (force && a->lid == b->lid); in sameport()
208 if (path->cnt + 2 >= sizeof(path->p)) in extend_dpath()
209 return -1; in extend_dpath()
210 ++path->cnt; in extend_dpath()
211 path->p[path->cnt] = (uint8_t) nextport; in extend_dpath()
212 return path->cnt; in extend_dpath()
215 static void dump_endnode(int dump, char *prompt, Node * node, Port * port) in dump_endnode() argument
223 prompt, node->nodeguid, in dump_endnode()
224 node->type == IB_NODE_SWITCH ? 0 : port->portnum); in dump_endnode()
229 remap_node_name(node_name_map, node->nodeguid, node->nodedesc); in dump_endnode()
231 fprintf(f, "%s %s {0x%016" PRIx64 "} portnum %d lid %u-%u \"%s\"\n", in dump_endnode()
233 (node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"), in dump_endnode()
234 node->nodeguid, in dump_endnode()
235 node->type == IB_NODE_SWITCH ? 0 : port->portnum, port->lid, in dump_endnode()
236 port->lid + (1 << port->lmc) - 1, nodename); in dump_endnode()
241 static void dump_route(int dump, Node * node, int outport, Port * port) in dump_route() argument
249 remap_node_name(node_name_map, node->nodeguid, node->nodedesc); in dump_route()
252 fprintf(f, "[%d] -> {0x%016" PRIx64 "}[%d]\n", in dump_route()
253 outport, port->portguid, port->portnum); in dump_route()
255 fprintf(f, "[%d] -> %s port {0x%016" PRIx64 in dump_route()
256 "}[%d] lid %u-%u \"%s\"\n", outport, in dump_route()
257 (node->type <= in dump_route()
258 IB_NODE_MAX ? node_type_str[node->type] : "???"), in dump_route()
259 port->portguid, port->portnum, port->lid, in dump_route()
260 port->lid + (1 << port->lmc) - 1, nodename); in dump_route()
268 Port *port, fromport, toport, nextport; in find_route() local
276 memset(&fromport,0,sizeof(Port)); in find_route()
277 memset(&toport,0,sizeof(Port)); in find_route()
278 memset(&nextport,0,sizeof(Port)); in find_route()
286 return -1; in find_route()
287 if (to->lid > 0) in find_route()
288 toport.lid = to->lid; in find_route()
289 IBWARN("Force: look for lid %d", to->lid); in find_route()
293 port = &fromport; in find_route()
294 portnum = port->portnum; in find_route()
296 dump_endnode(dump, "From", node, port); in find_route()
297 if (node->type == IB_NODE_SWITCH) { in find_route()
298 next_sw_outport = switch_lookup(&sw, from, to->lid); in find_route()
299 if (next_sw_outport < 0 || next_sw_outport > node->numports) { in find_route()
300 /* Need to print the port in badtbl */ in find_route()
306 while (maxhops--) { in find_route()
307 if (is_port_inactive(node, port, &sw)) in find_route()
310 if (sameport(port, &toport)) in find_route()
313 if (node->type == IB_NODE_SWITCH) { in find_route()
317 if (extend_dpath(&from->drpath, outport) < 0) in find_route()
321 IBWARN("can't reach port at %s", in find_route()
323 return -1; in find_route()
329 break; /* found SMA port */ in find_route()
331 } else if ((node->type == IB_NODE_CA) || in find_route()
332 (node->type == IB_NODE_ROUTER)) { in find_route()
337 if (!sameport(port, &fromport)) { in find_route()
339 ("can't continue: reached CA or router port %" in find_route()
340 PRIx64 ", lid %d", port->portguid, in find_route()
341 port->lid); in find_route()
342 return -1; in find_route()
344 /* we are at CA or router "from" - go one hop back to (hopefully) a switch */ in find_route()
345 if (from->drpath.cnt > 0) { in find_route()
346 DEBUG("ca or router node - return back 1 hop"); in find_route()
347 from->drpath.cnt--; in find_route()
351 && extend_dpath(&from->drpath, portnum) < 0) in find_route()
355 IBWARN("can't reach port at %s", in find_route()
357 return -1; in find_route()
359 /* fix port num to be seen from the CA or router side */ in find_route()
362 from->drpath.p[from->drpath.cnt + 1]; in find_route()
366 next_sw_outport = switch_lookup(&sw, from, to->lid); in find_route()
369 /* needed to print the port in badtbl */ in find_route()
375 port = &nextport; in find_route()
376 if (is_port_inactive(&nextnode, port, &sw)) in find_route()
379 portnum = port->portnum; in find_route()
380 dump_route(dump, node, outport, port); in find_route()
385 return -1; in find_route()
387 dump_endnode(dump, "To", node, port); in find_route()
391 IBWARN("Bad port state found: node \"%s\" port %d state %d", in find_route()
392 clean_nodedesc(node->nodedesc), portnum, port->state); in find_route()
393 return -1; in find_route()
395 IBWARN("Bad out port state found: node \"%s\" outport %d state %d", in find_route()
396 clean_nodedesc(node->nodedesc), outport, port->state); in find_route()
397 return -1; in find_route()
401 clean_nodedesc(node->nodedesc), to->lid, outport, sw.linearFDBtop); in find_route()
402 return -1; in find_route()
405 return -1; in find_route()
418 int hash = HASHGUID(new->nodeguid) % HTSZ; in insert_node()
421 for (node = nodestbl[hash]; node; node = node->htnext) in insert_node()
422 if (node->nodeguid == new->nodeguid) { in insert_node()
423 DEBUG("node %" PRIx64 " already exists", new->nodeguid); in insert_node()
424 return -1; in insert_node()
427 new->htnext = nodestbl[hash]; in insert_node()
433 static int get_port(Port * port, int portnum, ib_portid_t * portid) in get_port() argument
438 port->portnum = portnum; in get_port()
442 return -1; in get_port()
444 mad_decode_field(pi, IB_PORT_LID_F, &port->lid); in get_port()
445 mad_decode_field(pi, IB_PORT_LMC_F, &port->lmc); in get_port()
446 mad_decode_field(pi, IB_PORT_STATE_F, &port->state); in get_port()
447 mad_decode_field(pi, IB_PORT_PHYS_STATE_F, &port->physstate); in get_port()
450 portid2str(portid), portnum, port->lid, port->state, in get_port()
451 port->physstate); in get_port()
455 static void link_port(Port * port, Node * node) in link_port() argument
457 port->next = node->ports; in link_port()
458 node->ports = port; in link_port()
461 static int new_node(Node * node, Port * port, ib_portid_t * path, int dist) in new_node() argument
463 if (port->portguid == target_portguid) { in new_node()
464 node->dist = -1; /* tag as target */ in new_node()
465 link_port(port, node); in new_node()
466 dump_endnode(ibverbose, "found target", node, port); in new_node()
472 return -1; /* known switch */ in new_node()
474 VERBOSE("insert dist %d node %p port %d lid %d", dist, node, in new_node()
475 port->portnum, port->lid); in new_node()
477 link_port(port, node); in new_node()
479 node->dist = dist; in new_node()
480 node->path = *path; in new_node()
481 node->dnext = nodesdist[dist]; in new_node()
501 return -1; in switch_mclookup()
503 mlid -= 0xc000; in switch_mclookup()
508 return -1; in switch_mclookup()
511 maxsets = (node->numports + 15) / 16; /* round up */ in switch_mclookup()
517 return -1; in switch_mclookup()
526 ": mlid 0x%x is forwarded to port %d", in switch_mclookup()
527 node->nodeguid, mlid + 0xc000, i + set * 16); in switch_mclookup()
535 * Return 1 if found, 0 if not, -1 on errors.
540 Port *port, *remoteport; in find_mcpath() local
551 if (!(port = calloc(1, sizeof(Port)))) in find_mcpath()
554 if (get_node(node, port, from) < 0) { in find_mcpath()
559 node->upnode = 0; /* root */ in find_mcpath()
560 if ((r = new_node(node, port, from, 0)) > 0) { in find_mcpath()
561 if (node->type != IB_NODE_SWITCH) { in find_mcpath()
573 for (node = nodesdist[dist]; node; node = node->dnext) { in find_mcpath()
575 path = &node->path; in find_mcpath()
579 node->ports); in find_mcpath()
583 if (node->type != IB_NODE_SWITCH) { in find_mcpath()
586 leafport = path->drpath.p[path->drpath.cnt]; in find_mcpath()
587 map[port->portnum] = 1; in find_mcpath()
588 node->upport = 0; /* starting here */ in find_mcpath()
590 " lid %d port %d (leafport %d)", in find_mcpath()
591 node->nodeguid, port->lid, port->portnum, in find_mcpath()
595 /* if starting from a leaf port fix up port (up port) */ in find_mcpath()
597 node->upport = leafport; in find_mcpath()
601 "", node->nodeguid); in find_mcpath()
606 for (i = 1; i <= node->numports; i++) { in find_mcpath()
607 if (!map[i] || i == node->upport) in find_mcpath()
611 if (from->drpath.cnt > 0) in find_mcpath()
612 path->drpath.cnt--; in find_mcpath()
614 if (!(port = calloc(1, sizeof(Port)))) in find_mcpath()
617 if (get_port(port, i, path) < 0) { in find_mcpath()
619 ("can't reach node %s port %d", in find_mcpath()
621 free(port); in find_mcpath()
625 if (port->physstate != 5) { /* LinkUP */ in find_mcpath()
626 free(port); in find_mcpath()
630 link_port(port, node); in find_mcpath()
633 if (extend_dpath(&path->drpath, i) < 0) { in find_mcpath()
634 free(port); in find_mcpath()
642 if (!(remoteport = calloc(1, sizeof(Port)))) in find_mcpath()
647 ("NodeInfo on %s port %d failed, skipping port", in find_mcpath()
649 path->drpath.cnt--; /* restore path */ in find_mcpath()
655 remotenode->upnode = node; in find_mcpath()
656 remotenode->upport = remoteport->portnum; in find_mcpath()
657 remoteport->remoteport = port; in find_mcpath()
666 else if (remotenode->type == IB_NODE_SWITCH) in find_mcpath()
671 path->drpath.cnt--; /* restore path */ in find_mcpath()
682 Port toport; in find_target_portguid()
685 IBWARN("can't find to port\n"); in find_target_portguid()
686 return -1; in find_target_portguid()
696 if (node->upnode) in dump_mcpath()
697 dump_mcpath(node->upnode, dumplevel); in dump_mcpath()
700 remap_node_name(node_name_map, node->nodeguid, node->nodedesc); in dump_mcpath()
702 if (!node->dist) { in dump_mcpath()
703 printf("From %s 0x%" PRIx64 " port %d lid %u-%u \"%s\"\n", in dump_mcpath()
704 (node->type <= in dump_mcpath()
705 IB_NODE_MAX ? node_type_str[node->type] : "???"), in dump_mcpath()
706 node->nodeguid, node->ports->portnum, node->ports->lid, in dump_mcpath()
707 node->ports->lid + (1 << node->ports->lmc) - 1, in dump_mcpath()
712 if (node->dist) { in dump_mcpath()
714 printf("[%d] -> %s {0x%016" PRIx64 "}[%d]\n", in dump_mcpath()
715 node->ports->remoteport->portnum, in dump_mcpath()
716 (node->type <= in dump_mcpath()
717 IB_NODE_MAX ? node_type_str[node->type] : in dump_mcpath()
718 "???"), node->nodeguid, node->upport); in dump_mcpath()
720 printf("[%d] -> %s 0x%" PRIx64 "[%d] lid %u \"%s\"\n", in dump_mcpath()
721 node->ports->remoteport->portnum, in dump_mcpath()
722 (node->type <= in dump_mcpath()
723 IB_NODE_MAX ? node_type_str[node->type] : in dump_mcpath()
724 "???"), node->nodeguid, node->upport, in dump_mcpath()
725 node->ports->lid, nodename); in dump_mcpath()
728 if (node->dist < 0) in dump_mcpath()
730 printf("To %s 0x%" PRIx64 " port %d lid %u-%u \"%s\"\n", in dump_mcpath()
731 (node->type <= in dump_mcpath()
732 IB_NODE_MAX ? node_type_str[node->type] : "???"), in dump_mcpath()
733 node->nodeguid, node->ports->portnum, node->ports->lid, in dump_mcpath()
734 node->ports->lid + (1 << node->ports->lmc) - 1, in dump_mcpath()
747 return -1; in resolve_lid()
774 return -1; in process_opt()
792 {"node-name-map", 1, 1, "<file>", "node name map file"}, in main()
795 char usage_args[] = "<src-addr> <dest-addr>"; in main()
797 "- Unicast examples:", in main()
799 "-n 4 16\t\t# same, but using simple output format", in main()
800 "-G 0x8f1040396522d 0x002c9000100d051\t# use guid addresses", in main()
802 " - Multicast examples:", in main()
803 "-m 0xc000 4 16\t# show multicast path of mlid 0xc000 between lids 4 and 16", in main()
811 argc -= optind; in main()
822 IBEXIT("Failed to open '%s' port '%d'", ibd_ca, ibd_ca_port); in main()
830 IBEXIT("can't resolve source port %s", argv[0]); in main()
834 IBEXIT("can't resolve destination port %s", argv[1]); in main()
838 IBEXIT("cannot resolve lid for port \'%s\'", in main()
841 IBEXIT("cannot resolve lid for port \'%s\'", in main()
851 /* first find a direct path to the src port */ in main()
853 IBEXIT("can't find a route to the src port"); in main()