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>
@@ -401,6 +403,8 @@ int main(int argc, char **argv)
401403 uint32_t vendorid , rem_vendorid ;
402404 uint16_t devid , rem_devid ;
403405 uint64_t val ;
406+ ext_umad_ca_t ext_ca = {};
407+ bool is_planarized_fabric = false;
404408 char * endp ;
405409 char usage_args [] = "<dest dr_path|lid|guid> <portnum> [<op>]\n"
406410 "\nSupported ops: enable, disable, on, off, reset, speed, espeed, fdr10,\n"
@@ -420,22 +424,48 @@ int main(int argc, char **argv)
420424 ibdiag_process_opts (argc , argv , NULL , NULL , NULL , NULL ,
421425 usage_args , usage_examples );
422426
427+ if (ext_umad_get_ca_by_name (ibd_ca , ibd_ca_port , & ext_ca ) < 0 )
428+ IBEXIT ("Couldn't find the umad CA\n" );
429+ if (!ext_ca .gsi .name [0 ] || !ext_ca .smi .name [0 ])
430+ IBEXIT ("Invalid CA name found\n" );
431+
432+ if (strncmp (ext_ca .gsi .name , ext_ca .smi .name , UMAD_CA_NAME_LEN ))
433+ is_planarized_fabric = true;
434+
423435 argc -= optind ;
424436 argv += optind ;
425437
426438 if (argc < 2 )
427439 ibdiag_show_usage ();
428440
429- srcport = mad_rpc_open_port (ibd_ca , ibd_ca_port , mgmt_classes , 3 );
441+ // srcport should be the SMI port
442+ srcport = mad_rpc_open_port (ext_ca .smi .name , ext_ca .smi .ports [0 ], mgmt_classes , 3 );
430443 if (!srcport )
431- IBEXIT ("Failed to open '%s' port '%d'" , ibd_ca , ibd_ca_port );
444+ IBEXIT ("Failed to open '%s' port '%d'" , ext_ca . smi . name , ext_ca . smi . ports [ 0 ] );
432445
433446 smp_mkey_set (srcport , ibd_mkey );
434447
435- if (resolve_portid_str (ibd_ca , ibd_ca_port , & portid , argv [0 ],
436- ibd_dest_type , ibd_sm_id , srcport ) < 0 )
448+ if (resolve_portid_str (ext_ca . smi . name , ext_ca . smi . ports [ 0 ] , & portid , argv [0 ],
449+ ibd_dest_type , ibd_sm_id , srcport ) < 0 )
437450 IBEXIT ("can't resolve destination port %s" , argv [0 ]);
438451
452+ if (is_planarized_fabric && (ibd_dest_type != IB_DEST_DRPATH )) {
453+ int rc = 0 ;
454+ struct ibnd_config config = {};
455+ config .mkey = ibd_mkey ;
456+ config .timeout_ms = ibd_timeout ;
457+
458+ ibnd_fabric_t * fabric = ibnd_discover_fabric (ext_ca .smi .name , ext_ca .smi .ports [0 ], NULL , & config );
459+ if (!fabric )
460+ IBEXIT ("Discovery failed" );
461+
462+ rc = convert_portid_to_dr (fabric , & portid , ibd_dest_type );
463+ ibnd_destroy_fabric (fabric );
464+
465+ if (rc < 0 )
466+ IBEXIT ("Coultnd't convert destination port %s to direct route" , argv [0 ]);
467+ }
468+
439469 if (argc > 1 )
440470 portnum = strtol (argv [1 ], NULL , 0 );
441471
0 commit comments