3333 *
3434 */
3535
36+ #include "infiniband/ibnetdisc.h"
3637#include <stdio.h>
3738#include <stdlib.h>
39+ #include <stdbool.h>
3840#include <unistd.h>
3941#include <string.h>
4042#include <errno.h>
@@ -436,6 +438,8 @@ int main(int argc, char **argv)
436438 uint32_t vendorid , rem_vendorid ;
437439 uint16_t devid , rem_devid ;
438440 uint64_t val ;
441+ ext_umad_ca_t ext_ca = {};
442+ bool is_planarized_fabric = false;
439443 char * endp ;
440444 char usage_args [] = "<dest dr_path|lid|guid> <portnum> [<op>]\n"
441445 "\nSupported ops: enable, disable, on, off, reset, speed, espeed, fdr10,\n"
@@ -455,22 +459,51 @@ int main(int argc, char **argv)
455459 ibdiag_process_opts (argc , argv , NULL , NULL , NULL , NULL ,
456460 usage_args , usage_examples );
457461
462+ if (ext_umad_get_ca_by_name (ibd_ca , ibd_ca_port , & ext_ca ) < 0 )
463+ IBEXIT ("Couldn't find the umad CA\n" );
464+ if (!ext_ca .gsi .name [0 ] || !ext_ca .smi .name [0 ])
465+ IBEXIT ("Invalid CA name found\n" );
466+
467+ if (strncmp (ext_ca .gsi .name , ext_ca .smi .name , UMAD_CA_NAME_LEN ))
468+ is_planarized_fabric = true;
469+
458470 argc -= optind ;
459471 argv += optind ;
460472
461473 if (argc < 2 )
462474 ibdiag_show_usage ();
463475
464- srcport = mad_rpc_open_port (ibd_ca , ibd_ca_port , mgmt_classes , 3 );
476+ // srcport should be the SMI port
477+ srcport = mad_rpc_open_port (ext_ca .smi .name , ext_ca .smi .ports [0 ], mgmt_classes , 3 );
465478 if (!srcport )
466- IBEXIT ("Failed to open '%s' port '%d'" , ibd_ca , ibd_ca_port );
479+ IBEXIT ("Failed to open '%s' port '%d'" , ext_ca . smi . name , ext_ca . smi . ports [ 0 ] );
467480
468481 smp_mkey_set (srcport , ibd_mkey );
469482
470- if (resolve_portid_str (ibd_ca , ibd_ca_port , & portid , argv [0 ],
471- ibd_dest_type , ibd_sm_id , srcport ) < 0 )
483+ if (resolve_portid_str (ext_ca . smi . name , ext_ca . smi . ports [ 0 ] , & portid , argv [0 ],
484+ ibd_dest_type , ibd_sm_id , srcport ) < 0 )
472485 IBEXIT ("can't resolve destination port %s" , argv [0 ]);
473486
487+ if (is_planarized_fabric && (ibd_dest_type != IB_DEST_DRPATH )) {
488+ int rc = 0 ;
489+ struct ibnd_config config = {};
490+
491+ config .mkey = ibd_mkey ;
492+ config .timeout_ms = ibd_timeout ;
493+
494+ ibnd_fabric_t * fabric = ibnd_discover_fabric (ext_ca .smi .name ,
495+ ext_ca .smi .ports [0 ], NULL , & config );
496+
497+ if (!fabric )
498+ IBEXIT ("Discovery failed" );
499+
500+ rc = convert_portid_to_dr (fabric , & portid , ibd_dest_type );
501+ ibnd_destroy_fabric (fabric );
502+
503+ if (rc < 0 )
504+ IBEXIT ("Coultnd't convert destination port %s to direct route" , argv [0 ]);
505+ }
506+
474507 if (argc > 1 )
475508 portnum = strtol (argv [1 ], NULL , 0 );
476509
0 commit comments