[Openib-windows] IPoIB GUID to MAC conversion

Fab Tillier ftillier at silverstorm.com
Fri May 27 00:20:44 PDT 2005


> From: Tillier, Fabian
> Sent: Thursday, May 26, 2005 11:13 PM
> 
> I will therefore work to create a patch that implements option 2 unless I
> hear otherwise from folks here.

Here's a patch that should generate LAAs for local and remote nodes.  It will
only generate up to 2^32 - 1 LAAs before running out and stopping.  I limited it
to 32-bits so I could use interlocked increments and eliminate any
synchronization issues.  Note that this patch compiles but is not tested.

- Fab

Index: kernel/ipoib_xfr_mgr.h
===================================================================
--- kernel/ipoib_xfr_mgr.h	(revision 14)
+++ kernel/ipoib_xfr_mgr.h	(working copy)
@@ -88,6 +88,10 @@
 {
 #endif
 
+/* Global counter for generating LAA MACs */
+extern atomic32_t		g_laa_idx;
+
+
 /*
  * Address accessors
  */
@@ -125,17 +129,17 @@
 }
 
 
-/****f* IPOIB/ipoib_mac_from_guid
+/****f* IPOIB/ipoib_mac_from_sst_guid
 * NAME
-*	ipoib_mac_from_guid
+*	ipoib_mac_from_sst_guid
 *
 * DESCRIPTION
-*	Generates an ethernet MAC address given a port GUID.
+*	Generates an ethernet MAC address given a SilverStorm port GUID.
 *
 * SYNOPSIS
 */
 static inline ib_api_status_t
-ipoib_mac_from_guid(
+ipoib_mac_from_sst_guid(
 	IN		const	net64_t
port_guid,
 		OUT			mac_addr_t* const
p_mac_addr )
 {
@@ -143,8 +147,7 @@
 	uint32_t		low24;
 
 	/* Port guid is in network byte order.  OUI is in lower 3 bytes. */
-	if( p_guid[0] != 0x00 || p_guid[1] != 0x06 || p_guid[2] != 0x6a )
-		return IB_INVALID_GUID;
+	ASSERT( p_guid[0] == 0x00 && p_guid[1] == 0x06 && p_guid[2] == 0x6a );
 
 	/*
 	 * We end up using only the lower 23-bits of the GUID.  Trap that
@@ -191,6 +194,71 @@
 *********/
 
 
+/****f* IPOIB/ipoib_mac_from_guid
+* NAME
+*	ipoib_mac_from_guid
+*
+* DESCRIPTION
+*	Generates an ethernet MAC address given a port GUID.
+*
+* SYNOPSIS
+*/
+static inline ib_api_status_t
+ipoib_mac_from_guid(
+	IN		const	net64_t
port_guid,
+		OUT			mac_addr_t* const
p_mac_addr )
+{
+	ib_api_status_t	status;
+	const uint8_t	*p_guid = (const uint8_t*)&port_guid;
+	uint32_t		laa;
+
+	/* Port guid is in network byte order.  OUI is in lower 3 bytes. */
+	if( p_guid[0] == 0x00 && p_guid[1] == 0x06 && p_guid[2] == 0x6a )
+	{
+		status = ipoib_mac_from_sst_guid( port_guid, p_mac_addr );
+		if( status == IB_SUCCESS )
+			return IB_SUCCESS;
+	}
+
+	/* Value of zero is reserved. */
+	laa = cl_atomic_inc( &g_laa_idx );
+
+	if( !laa )
+		return IB_INVALID_GUID;
+
+	p_mac_addr->addr[0] = 2; /* LAA bit */
+	p_mac_addr->addr[1] = 0;
+	p_mac_addr->addr[2] = (uint8_t)(laa >> 24);
+	p_mac_addr->addr[3] = (uint8_t)(laa >> 16);
+	p_mac_addr->addr[4] = (uint8_t)(laa >> 8);
+	p_mac_addr->addr[5] = (uint8_t)laa;
+	
+	return IB_SUCCESS;
+}
+/*
+* PARAMETERS
+*	port_guid
+*		The port GUID, in network byte order, for which to generate a
+*		MAC address.
+*
+*	p_mac_addr
+*		Pointer to a mac address in which to store the results.
+*
+* RETURN VALUES
+*	IB_SUCCESS
+*		The MAC address was successfully converted.
+*
+*	IB_INVALID_GUID
+*		The port GUID provided was not a known GUID format.
+*
+* NOTES
+*	Creates a locally administered address using a global incrementing
counter.
+*
+* SEE ALSO
+*	IPOIB
+*********/
+
+
 /****f* IPOIB/ipoib_guid_from_mac
 * NAME
 *	ipoib_guid_from_mac
Index: kernel/ipoib_driver.c
===================================================================
--- kernel/ipoib_driver.c	(revision 15)
+++ kernel/ipoib_driver.c	(working copy)
@@ -120,6 +120,7 @@
 
 /* Global driver debug level */
 uint32_t	g_ipoib_dbg_lvl = IPOIB_DBG_ERROR;
+atomic32_t	g_laa_idx = 0;
 
 
 NTSTATUS




More information about the ofw mailing list