[ofw] RE: [osmtest] Adding support for default guid selection when running osmtest

Tzachi Dar tzachid at mellanox.co.il
Wed Feb 11 02:15:45 PST 2009


Applied on 1940.
 
Thanks
Tzachi


________________________________

	From: Alex Naslednikov 
	Sent: Tuesday, February 10, 2009 7:59 PM
	To: ofw at lists.openfabrics.org
	Cc: Tzachi Dar; Yevgeny Kliteynik
	Subject: [osmtest] Adding support for default guid selection
when running osmtest
	
	
	Index: D:/Windows/MLNX_WINOF/ulp/opensm/user/osmtest/main.c
	 
	
===================================================================
	 
	--- D:/Windows/MLNX_WINOF/ulp/opensm/user/osmtest/main.c
(revision 3519)
	 
	+++ D:/Windows/MLNX_WINOF/ulp/opensm/user/osmtest/main.c
(revision 3520)
	 
	@@ -75,6 +75,140 @@
	 
	
	
/**********************************************************************
	
**********************************************************************/
	+ib_net64_t
	+get_port_guid(
	+  IN osmtest_t *p_osm, uint64_t port_guid,
	+  IN boolean_t is_service)
	+{
	+  uint32_t i;
	+  uint32_t choice = 0;
	+  char junk[128];
	+  boolean_t done_flag = FALSE;
	+  ib_api_status_t status;
	+  uint32_t num_ports = GUID_ARRAY_SIZE;
	+  ib_port_attr_t attr_array[GUID_ARRAY_SIZE];
	+  
	+  /*
	+    Call the transport layer for a list of local port
	+    GUID values.
	+  */
	+  status = osm_vendor_get_all_port_attr( p_osm->p_vendor,
attr_array, &num_ports );
	+  if( status != IB_SUCCESS )
	+  {
	+    printf( "\nError from osm_vendor_get_all_port_attr (%x)\n",
status);
	+    return( 0 );
	+  }
	+
	+  /* if num_ports is 0 - return 0 */
	+  if( num_ports == 0 )
	+  {
	+    printf( "\nNo local ports detected!\n" );
	+    return( 0 );
	+  }
	+  /* If num_ports is 1, then there is only one possible port to
use. Use it. */
	+  if ( num_ports == 1 )
	+  {
	+    printf("Using default GUID 0x%" PRIx64 "\n",
cl_hton64(attr_array[0].port_guid));
	+    return( attr_array[0].port_guid );
	+  }
	+
	+#if defined ( OSM_VENDOR_INTF_OPENIB )
	+  /* If port_guid is 0, and this is gen2 - use the default port
whose info is in attr_array[0] */
	+  if ( port_guid == 0 )
	+  {
	+    printf("Using default GUID 0x%" PRIx64 "\n",
cl_hton64(attr_array[0].port_guid));
	+    return( attr_array[0].port_guid );
	+  }
	+#endif /* OSM_VENDOR_INTF_OPENIB */
	+
	+  /* If port_guid is 0, and we are in windows - find the first
port with link_state != DOWN and
	+     use it as default port. */
	+  if ( port_guid == 0 )
	+  {
	+    for ( i = 0; i < num_ports; i++ )
	+    {
	+      if (attr_array[i].link_state > IB_LINK_DOWN)
	+      {
	+        /* Use this port */
	+        printf("Using default guid 0x%" PRIx64 "\n",
cl_hton64(attr_array[i].port_guid));
	+        return( attr_array[i].port_guid );
	+      }
	+    }
	+    /* If we are running as a service, and all ports are down
we return the 
	+       first port (we can't open a window, as a service)*/
	+       if (is_service) {
	+         return( attr_array[0].port_guid );
	+       }
	+  }
	+
	+  /* More than one possible port - list all ports and let the
user to choose. */
	+  while( done_flag == FALSE )
	+  {
	+    printf( "\nChoose a local port number with which to
bind:\n\n" );
	+    /* If this is gen2 code - then port 0 has details of the
default port used. 
	+       no need to print it.
	+       If this is not gen2 code - need to print details of all
ports. */
	+#if defined ( OSM_VENDOR_INTF_OPENIB )
	+    for( i = 1; i < num_ports; i++ )
	+    {
	+      printf("\t%u: GUID = 0x%8" PRIx64 ", lid = 0x%04X, state
= %s\n",
	+             i, cl_ntoh64( attr_array[i].port_guid ),
	+             attr_array[i].lid,
	+             ib_get_port_state_str( attr_array[i].link_state )
);
	+    }
	+    printf( "\nEnter choice (1-%u): ", i-1 );
	+# else
	+    for( i = 0; i < num_ports; i++ )
	+    {
	+      /*
	+        Print the index + 1 since by convention, port numbers
	+        start with 1 on host channel adapters.
	+      */
	+
	+      printf("\t%u: GUID = 0x%8" PRIx64 ", lid = 0x%04X, state
= %s\n",
	+             i+1, cl_ntoh64( attr_array[i].port_guid ),
	+             attr_array[i].lid,
	+             ib_get_port_state_str( attr_array[i].link_state )
);
	+    }
	+    printf( "\nEnter choice (1-%u): ", i );
	+#endif /* OSM_VENDOR_INTF_OPENIB */
	+
	+    fflush( stdout );
	+    if (scanf( "%u", &choice ))
	+    {
	+      /* If gen2 code - choice can be between 1 to num_ports-1
	+         if not gen2 code - choice can be between 1 to
num_ports */
	+#if defined ( OSM_VENDOR_INTF_OPENIB )
	+      if( choice >= num_ports )
	+# else
	+      if( choice > num_ports || choice < 1 )
	+#endif /* OSM_VENDOR_INTF_OPENIB */
	+      {
	+        printf("\nError: Lame choice!\n");
	+        fflush( stdin );
	+      }
	+      else
	+      {
	+        done_flag = TRUE;
	+      }
	+    }
	+    else
	+    {
	+      /* get rid of the junk in the selection line */
	+      scanf( "%s", junk );
	+      printf("\nError: Lame choice!\n"); 
	+      fflush( stdin );
	+    }
	+  }
	+#if defined ( OSM_VENDOR_INTF_OPENIB )
	+  printf("Choice guid=0x%8" PRIx64 "\n", cl_ntoh64(
attr_array[choice].port_guid ));       
	+  return( attr_array[choice].port_guid );
	+# else
	+  return( attr_array[choice - 1].port_guid );
	+#endif /* OSM_VENDOR_INTF_OPENIB */
	+}
	
+/**********************************************************************
	+
**********************************************************************/
	 void show_usage(void);
	 
	 void
	@@ -513,9 +647,19 @@
	 
	  }
	 
	  /*
	+    If the user didn't specify a GUID on the command line,
	+    then get a port GUID value with which to bind.
	+  */
	+ if (guid == 0 && !(guid = get_port_guid(&osm_test, guid,1))) {
	+  printf("\nError: port guid 0x%" PRIx64 " not found\n", guid);
	+  goto Exit;
	+ }
	+
	+ /*
	   * Guid may be zero going into this function if the user
	   * hasn't specified a binding port on the command line.
	   */
	+  
	  status = osmtest_bind( &osm_test, (uint16_t)max_lid, guid );
	  if (status != IB_SUCCESS) exit(status);
	

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20090211/c498d9d0/attachment.html>


More information about the ofw mailing list