From cdcebf6830f9b7805f1d798e820387cf01d60311 Mon Sep 17 00:00:00 2001 From: ftillier Date: Mon, 5 Dec 2005 17:35:07 +0000 Subject: [PATCH] [IPoIB] Add support for generating globally unique Ethernet MAC addresses from Mellanox GUIDs. Submitted by Yossi Leybovich (sleybo@mellanox.co.il) git-svn-id: svn://openib.tc.cornell.edu/gen1@194 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- trunk/ulp/ipoib/kernel/ipoib_xfr_mgr.h | 138 ++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 4 deletions(-) diff --git a/trunk/ulp/ipoib/kernel/ipoib_xfr_mgr.h b/trunk/ulp/ipoib/kernel/ipoib_xfr_mgr.h index 2b5a3b88..84d3c7c9 100644 --- a/trunk/ulp/ipoib/kernel/ipoib_xfr_mgr.h +++ b/trunk/ulp/ipoib/kernel/ipoib_xfr_mgr.h @@ -191,6 +191,68 @@ ipoib_mac_from_sst_guid( *********/ +/****f* IPOIB/ipoib_mac_from_mlx_guid +* NAME +* ipoib_mac_from_sst_guid +* +* DESCRIPTION +* Generates an ethernet MAC address given a Mellanox port GUID. +* +* SYNOPSIS +*/ +static inline ib_api_status_t +ipoib_mac_from_mlx_guid( + IN const net64_t port_guid, + OUT mac_addr_t* const p_mac_addr ) +{ + const uint8_t *p_guid = (const uint8_t*)&port_guid; + uint32_t low24; + + /* Port guid is in network byte order. OUI is in lower 3 bytes. */ + ASSERT( p_guid[0] == 0x00 && p_guid[1] == 0x02 && p_guid[2] == 0xc9 ); + + if( (port_guid & CL_HTON64( 0x000000ffff0000 )) != + CL_HTON64(0x00000002000000)) + { + return IB_INVALID_GUID; + } + + low24 = ((uint32_t)cl_ntoh64( port_guid ) & 0x00FFFFFF); + + p_mac_addr->addr[0] = p_guid[0]; + p_mac_addr->addr[1] = p_guid[1]; + p_mac_addr->addr[2] = p_guid[2]; + p_mac_addr->addr[3] = (uint8_t)(low24 >> 16); + p_mac_addr->addr[4] = (uint8_t)(low24 >> 8); + p_mac_addr->addr[5] = (uint8_t)low24; + + 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 +* The algorithm to convert portGuid to MAC address is as per DN0074, and +* assumes a 2 port HCA. +* +* SEE ALSO +* IPOIB +*********/ + + /****f* IPOIB/ipoib_mac_from_guid * NAME * ipoib_mac_from_guid @@ -216,7 +278,13 @@ ipoib_mac_from_guid( if( status == IB_SUCCESS ) return IB_SUCCESS; } - + if( p_guid[0] == 0x00 && p_guid[1] == 0x02 && p_guid[2] == 0xc9 ) + { + status = ipoib_mac_from_mlx_guid( port_guid, p_mac_addr ); + if( status == IB_SUCCESS ) + return IB_SUCCESS; + } + /* Value of zero is reserved. */ laa = cl_atomic_inc( &g_ipoib.laa_idx ); @@ -256,9 +324,9 @@ ipoib_mac_from_guid( *********/ -/****f* IPOIB/ipoib_guid_from_mac +/****f* IPOIB/ipoib_sst_guid_from_mac * NAME -* ipoib_guid_from_mac +* ipoib_sst_guid_from_mac * * DESCRIPTION * Generates a port GUID given an ethernet MAC address. @@ -266,7 +334,7 @@ ipoib_mac_from_guid( * SYNOPSIS */ static inline ib_api_status_t -ipoib_guid_from_mac( +ipoib_sst_guid_from_mac( IN const mac_addr_t mac, OUT net64_t* const p_port_guid ) { @@ -329,6 +397,68 @@ ipoib_guid_from_mac( *********/ +/****f* IPOIB/ipoib_mlx_guid_from_mac +* NAME +* ipoib_mlx_guid_from_mac +* +* DESCRIPTION +* Generates a port GUID given an ethernet MAC address. +* +* SYNOPSIS +*/ +static inline ib_api_status_t +ipoib_mlx_guid_from_mac( + IN const mac_addr_t mac, + OUT net64_t* const p_port_guid ) +{ + uint8_t *p_guid = (uint8_t*)p_port_guid; + uint32_t low24; + + /* MAC address is in network byte order. OUI is in lower 3 bytes. */ + if( mac.addr[0] != 0x00 || + mac.addr[1] != 0x02 || + mac.addr[2] != 0xc9 ) + { + return IB_INVALID_GUID; + } + + low24 = mac.addr[3] << 16 || mac.addr[4] << 8 || mac.addr[5]; + + /* OUI */ + p_guid[0] = mac.addr[0]; + p_guid[1] = mac.addr[1]; + p_guid[2] = mac.addr[2]; + p_guid[3] = 0x02; + p_guid[4] = 0x00; + /* Serial Number */ + p_guid[5] = (uint8_t)(low24 >> 16); + p_guid[6] = (uint8_t)(low24 >> 8); + p_guid[7] = (uint8_t)low24; + + 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 +* The algorithm to convert portGuid to MAC address is as +* +* SEE ALSO +* IPOIB +*********/ #ifdef __cplusplus -- 2.41.0