From: ftillier Date: Thu, 8 Dec 2005 04:37:07 +0000 (+0000) Subject: [WSD] Use IBAT to get local IP addresses. X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=045387a1231d42d1147518bd8fc4bfb2ef138717;p=~shefty%2Frdma-win.git [WSD] Use IBAT to get local IP addresses. git-svn-id: svn://openib.tc.cornell.edu/gen1@200 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- diff --git a/trunk/ulp/wsd/user/ibsp_iblow.c b/trunk/ulp/wsd/user/ibsp_iblow.c index 67ec7acf..0122fbed 100644 --- a/trunk/ulp/wsd/user/ibsp_iblow.c +++ b/trunk/ulp/wsd/user/ibsp_iblow.c @@ -862,9 +862,6 @@ ibsp_initialize(void) goto done; } - /* Populate IP list. */ - update_all_ip_addrs(); - STAT_INC( thread_num ); ret = 0; diff --git a/trunk/ulp/wsd/user/ibsp_ip.c b/trunk/ulp/wsd/user/ibsp_ip.c index 0ad69600..d0a6d70f 100644 --- a/trunk/ulp/wsd/user/ibsp_ip.c +++ b/trunk/ulp/wsd/user/ibsp_ip.c @@ -72,137 +72,102 @@ ip_cmp( } -static void AL_API -query_ip_address_callback( - ib_query_rec_t *p_query_rec ) -{ - struct ip_query_context *query_context = - (struct ip_query_context * __ptr64)p_query_rec->query_context; - cl_fmap_item_t *p_item; - - IBSP_ENTER( IBSP_DBG_HW ); - IBSP_TRACE( IBSP_DBG_HW, - ("status is %s\n", ib_get_err_str( p_query_rec->status )) ); - - if( p_query_rec->status == IB_SUCCESS ) - { - unsigned int i; - - IBSP_TRACE( IBSP_DBG_HW, ("got %d records\n", p_query_rec->result_cnt) ); - - for( i = 0; i < p_query_rec->result_cnt; i++ ) - { - ib_service_record_t *service_record = - ib_get_query_svc_rec(p_query_rec->p_result_mad, i); - struct ibsp_ip_addr *ip_addr; - - ip_addr = - HeapAlloc( g_ibsp.heap, HEAP_ZERO_MEMORY, sizeof(struct ibsp_ip_addr) ); - if( !ip_addr ) - { - IBSP_ERROR_EXIT( ("no memory\n") ); - break; - } - - /* Copy the IP address */ - ip_addr->ip_addr.S_un.S_addr = - *(ib_net32_t *) & service_record->service_data8[ATS_IPV4_OFFSET]; - ip_addr->p_port = query_context->p_port; - - p_item = cl_fmap_insert( - query_context->p_ip_map, ip_addr, &ip_addr->item ); - if( p_item != &ip_addr->item ) - { - /* Duplicate! Should never happen. */ - IBSP_ERROR( - ("Got duplicate addr %s\n", inet_ntoa( ip_addr->ip_addr )) ); - HeapFree( g_ibsp.heap, 0, ip_addr ); - continue; - } - - IBSP_TRACE( IBSP_DBG_HW, - (" Got addr %s\n", inet_ntoa( ip_addr->ip_addr )) ); - } - } - else if( p_query_rec->p_result_mad ) - { - IBSP_TRACE( IBSP_DBG_HW, ("SA status is %x\n", - p_query_rec->p_result_mad->p_mad_buf->status) ); - } - - if( p_query_rec->p_result_mad ) - ib_put_mad( p_query_rec->p_result_mad ); - - IBSP_EXIT( IBSP_DBG_HW ); -} - - /* Synchronously query the SA for an IP address. */ int query_ip_address( IN struct ibsp_port *p_port, IN OUT cl_fmap_t *p_ip_map ) { - ib_user_query_t user_query; - struct ip_query_context query_context; - ib_service_record_t service_record; - ib_query_handle_t query_handle; - ib_query_req_t query_req; - ib_api_status_t status; + IOCTL_IBAT_IP_ADDRESSES_IN in; + IOCTL_IBAT_IP_ADDRESSES_OUT *p_out; + DWORD size; + LONG i; + cl_fmap_item_t *p_item; IBSP_ENTER( IBSP_DBG_HW ); /* The list must be initialized and empty */ CL_ASSERT( !cl_fmap_count( p_ip_map ) ); - query_context.p_ip_map = p_ip_map; - query_context.p_port = p_port; + in.Version = IBAT_IOCTL_VERSION; + in.PortGuid = p_port->guid; - query_req.query_type = IB_QUERY_USER_DEFINED; - query_req.p_query_input = &user_query; - query_req.port_guid = p_port->guid; - query_req.timeout_ms = 500; /* 500ms timeout */ - query_req.retry_cnt = 4; /* retry 4 times */ - query_req.flags = IB_FLAGS_SYNC; - query_req.query_context = &query_context; - query_req.pfn_query_cb = query_ip_address_callback; + cl_spinlock_acquire( &g_ibsp.ip_mutex ); + if( g_ibsp.h_ibat_dev == INVALID_HANDLE_VALUE ) + { + g_ibsp.h_ibat_dev = CreateFileW( IBAT_WIN32_NAME, + GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); + } + cl_spinlock_release( &g_ibsp.ip_mutex ); - user_query.method = IB_MAD_METHOD_GETTABLE; - user_query.attr_id = IB_MAD_ATTR_SERVICE_RECORD; - user_query.attr_size = sizeof(ib_service_record_t); - user_query.comp_mask = IB_SR_COMPMASK_SGID | - IB_SR_COMPMASK_SPKEY | IB_SR_COMPMASK_SLEASE | IB_SR_COMPMASK_SNAME; + size = sizeof(IOCTL_IBAT_IP_ADDRESSES_OUT); - user_query.p_attr = &service_record; + do + { + p_out = HeapAlloc( g_ibsp.heap, 0, size ); - memset( &service_record, 0, sizeof(service_record) ); - service_record.service_pkey = IB_DEFAULT_PKEY; - ib_gid_set_default( &service_record.service_gid, p_port->guid ); - service_record.service_lease = 0xFFFFFFFF; - strcpy( (void *)service_record.service_name, ATS_NAME ); + if( !p_out ) + { + IBSP_ERROR_EXIT( ("Failed to allocate output buffer.\n") ); + return -1; + } + + if( !DeviceIoControl( g_ibsp.h_ibat_dev, IOCTL_IBAT_IP_ADDRESSES, + &in, sizeof(in), p_out, sizeof(IOCTL_IBAT_IP_ADDRESSES_OUT), + &size, NULL ) ) + { + HeapFree( g_ibsp.heap, 0, p_out ); + IBSP_ERROR_EXIT( + ("IOCTL_IBAT_IP_ADDRESSES for port %I64x failed (%x).\n", + p_port->guid, GetLastError()) ); + return -1; + } - fzprint(("%s():%d:0x%x:0x%x: Calling ib_query() pfn_query_cb=0x%p..\n", __FUNCTION__, - __LINE__, GetCurrentProcessId(), - GetCurrentThreadId(), query_req.pfn_query_cb)); + if( p_out->Size > size ) + { + size = p_out->Size; + HeapFree( g_ibsp.heap, 0, p_out ); + p_out = NULL; + } - status = ib_query( g_ibsp.al_handle, &query_req, &query_handle ); + } while( !p_out ); - if( status != IB_SUCCESS && status != IB_INVALID_GUID ) + IBSP_TRACE( IBSP_DBG_HW, ("Port %I64x has %d IP addresses.\n", + p_port->guid, p_out->AddressCount) ); + + for( i = 0; i < p_out->AddressCount; i++ ) { - IBSP_ERROR( ("ib_query failed (%d)\n", status) ); - CL_ASSERT( !cl_fmap_count( p_ip_map ) ); + struct ibsp_ip_addr *ip_addr; - IBSP_ERROR_EXIT( - ("Failed to build list of IP addr for port %016I64x\n", - CL_HTON64( p_port->guid )) ); + ip_addr = HeapAlloc( + g_ibsp.heap, 0, sizeof(struct ibsp_ip_addr) ); + if( !ip_addr ) + { + IBSP_ERROR_EXIT( ("no memory\n") ); + break; + } - IBSP_ERROR_EXIT( ("query_ip_address failed\n") ); - return 1; - } + /* Copy the IP address */ + ip_addr->ip_addr.S_un.S_addr = + *(ib_net32_t *) &p_out->Address[i].Address[ATS_IPV4_OFFSET]; + ip_addr->p_port = p_port; - fzprint(("%s():%d:0x%x:0x%x: Done calling ib_query() status=(%d)\n", __FUNCTION__, - __LINE__, GetCurrentProcessId(), GetCurrentThreadId(), status)); + p_item = cl_fmap_insert( p_ip_map, ip_addr, &ip_addr->item ); + if( p_item != &ip_addr->item ) + { + /* Duplicate! Should never happen. */ + IBSP_ERROR( + ("Got duplicate addr %s\n", inet_ntoa( ip_addr->ip_addr )) ); + HeapFree( g_ibsp.heap, 0, ip_addr ); + continue; + } + IBSP_TRACE( IBSP_DBG_HW, + ("Got addr %s\n", inet_ntoa( ip_addr->ip_addr )) ); + } + + HeapFree( g_ibsp.heap, 0, p_out ); IBSP_EXIT( IBSP_DBG_HW ); return 0; @@ -281,38 +246,6 @@ update_ip_addresses( return 0; } - -void -update_all_ip_addrs(void) -{ - cl_list_item_t *p_hca_item, *p_port_item; - struct ibsp_hca *p_hca; - struct ibsp_port *p_port; - - IBSP_ENTER( IBSP_DBG_HW ); - - cl_spinlock_acquire( &g_ibsp.hca_mutex ); - for( p_hca_item = cl_qlist_head( &g_ibsp.hca_list ); - p_hca_item != cl_qlist_end( &g_ibsp.hca_list ); - p_hca_item = cl_qlist_next( p_hca_item ) ) - { - p_hca = PARENT_STRUCT( p_hca_item, struct ibsp_hca, item ); - - cl_spinlock_acquire( &p_hca->port_lock ); - for( p_port_item = cl_qlist_head( &p_hca->port_list ); - p_port_item != cl_qlist_end( &p_hca->port_list ); - p_port_item = cl_qlist_next( p_port_item ) ) - { - p_port = PARENT_STRUCT( p_port_item, struct ibsp_port, item ); - update_ip_addresses( p_port ); - } - cl_spinlock_release( &p_hca->port_lock ); - } - cl_spinlock_release( &g_ibsp.hca_mutex ); - - IBSP_EXIT( IBSP_DBG_HW ); -} - /*--------------------------------------------------------------------------*/ /* @@ -603,6 +536,13 @@ build_ip_list( switch( num_ip ) { case 0: + cl_spinlock_acquire( &g_ibsp.ip_mutex ); + if( g_ibsp.h_ibat_dev != INVALID_HANDLE_VALUE ) + { + CloseHandle( g_ibsp.h_ibat_dev ); + g_ibsp.h_ibat_dev = INVALID_HANDLE_VALUE; + } + cl_spinlock_release( &g_ibsp.ip_mutex ); break; default: diff --git a/trunk/ulp/wsd/user/ibspdll.h b/trunk/ulp/wsd/user/ibspdll.h index 0feaa3d8..75e2eea6 100644 --- a/trunk/ulp/wsd/user/ibspdll.h +++ b/trunk/ulp/wsd/user/ibspdll.h @@ -41,8 +41,10 @@ #include #include #include +#include #include +#include #include #include "ibspdefines.h" diff --git a/trunk/ulp/wsd/user/ibspproto.h b/trunk/ulp/wsd/user/ibspproto.h index f799fe15..4f866f82 100644 --- a/trunk/ulp/wsd/user/ibspproto.h +++ b/trunk/ulp/wsd/user/ibspproto.h @@ -151,9 +151,6 @@ ibal_to_wsa_error( IN const ib_api_status_t status ); /* Protos from ibsp_ip.c */ -void -update_all_ip_addrs(void); - intn_t CL_API ip_cmp( IN const void* const p_key1, diff --git a/trunk/ulp/wsd/user/ibspstruct.h b/trunk/ulp/wsd/user/ibspstruct.h index 164d0166..fe04c402 100644 --- a/trunk/ulp/wsd/user/ibspstruct.h +++ b/trunk/ulp/wsd/user/ibspstruct.h @@ -442,6 +442,7 @@ struct ibspdll_globals cl_qlist_t hca_list; cl_spinlock_t hca_mutex; + HANDLE h_ibat_dev; cl_fmap_t ip_map; /* list of all IP addresses supported by all the ports. */ cl_spinlock_t ip_mutex; diff --git a/trunk/ulp/wsd/user/misc.c b/trunk/ulp/wsd/user/misc.c index 1bf45987..2f92f822 100644 --- a/trunk/ulp/wsd/user/misc.c +++ b/trunk/ulp/wsd/user/misc.c @@ -98,6 +98,7 @@ init_globals( void ) cl_qlist_init( &g_ibsp.hca_list ); cl_spinlock_init( &g_ibsp.hca_mutex ); + g_ibsp.h_ibat_dev = INVALID_HANDLE_VALUE; cl_fmap_init( &g_ibsp.ip_map, ip_cmp ); cl_spinlock_init( &g_ibsp.ip_mutex ); @@ -114,7 +115,9 @@ void release_globals( void ) { HeapDestroy( g_ibsp.heap ); - g_ibsp.heap = NULL; + + if( g_ibsp.h_ibat_dev != INVALID_HANDLE_VALUE ) + CloseHandle( g_ibsp.h_ibat_dev ); cl_spinlock_destroy( &g_ibsp.socket_info_mutex ); cl_spinlock_destroy( &g_ibsp.hca_mutex );