}\r
\r
\r
-static void AL_API\r
-query_ip_address_callback(\r
- ib_query_rec_t *p_query_rec )\r
-{\r
- struct ip_query_context *query_context =\r
- (struct ip_query_context * __ptr64)p_query_rec->query_context;\r
- cl_fmap_item_t *p_item;\r
-\r
- IBSP_ENTER( IBSP_DBG_HW );\r
- IBSP_TRACE( IBSP_DBG_HW,\r
- ("status is %s\n", ib_get_err_str( p_query_rec->status )) );\r
-\r
- if( p_query_rec->status == IB_SUCCESS )\r
- {\r
- unsigned int i;\r
-\r
- IBSP_TRACE( IBSP_DBG_HW, ("got %d records\n", p_query_rec->result_cnt) );\r
-\r
- for( i = 0; i < p_query_rec->result_cnt; i++ )\r
- {\r
- ib_service_record_t *service_record =\r
- ib_get_query_svc_rec(p_query_rec->p_result_mad, i);\r
- struct ibsp_ip_addr *ip_addr;\r
-\r
- ip_addr =\r
- HeapAlloc( g_ibsp.heap, HEAP_ZERO_MEMORY, sizeof(struct ibsp_ip_addr) );\r
- if( !ip_addr )\r
- {\r
- IBSP_ERROR_EXIT( ("no memory\n") );\r
- break;\r
- }\r
-\r
- /* Copy the IP address */\r
- ip_addr->ip_addr.S_un.S_addr =\r
- *(ib_net32_t *) & service_record->service_data8[ATS_IPV4_OFFSET];\r
- ip_addr->p_port = query_context->p_port;\r
-\r
- p_item = cl_fmap_insert(\r
- query_context->p_ip_map, ip_addr, &ip_addr->item );\r
- if( p_item != &ip_addr->item )\r
- {\r
- /* Duplicate! Should never happen. */\r
- IBSP_ERROR(\r
- ("Got duplicate addr %s\n", inet_ntoa( ip_addr->ip_addr )) );\r
- HeapFree( g_ibsp.heap, 0, ip_addr );\r
- continue;\r
- }\r
-\r
- IBSP_TRACE( IBSP_DBG_HW,\r
- (" Got addr %s\n", inet_ntoa( ip_addr->ip_addr )) );\r
- }\r
- }\r
- else if( p_query_rec->p_result_mad )\r
- {\r
- IBSP_TRACE( IBSP_DBG_HW, ("SA status is %x\n",\r
- p_query_rec->p_result_mad->p_mad_buf->status) );\r
- }\r
-\r
- if( p_query_rec->p_result_mad )\r
- ib_put_mad( p_query_rec->p_result_mad );\r
-\r
- IBSP_EXIT( IBSP_DBG_HW );\r
-}\r
-\r
-\r
/* Synchronously query the SA for an IP address. */\r
int\r
query_ip_address(\r
IN struct ibsp_port *p_port,\r
IN OUT cl_fmap_t *p_ip_map )\r
{\r
- ib_user_query_t user_query;\r
- struct ip_query_context query_context;\r
- ib_service_record_t service_record;\r
- ib_query_handle_t query_handle;\r
- ib_query_req_t query_req;\r
- ib_api_status_t status;\r
+ IOCTL_IBAT_IP_ADDRESSES_IN in;\r
+ IOCTL_IBAT_IP_ADDRESSES_OUT *p_out;\r
+ DWORD size;\r
+ LONG i;\r
+ cl_fmap_item_t *p_item;\r
\r
IBSP_ENTER( IBSP_DBG_HW );\r
\r
/* The list must be initialized and empty */\r
CL_ASSERT( !cl_fmap_count( p_ip_map ) );\r
\r
- query_context.p_ip_map = p_ip_map;\r
- query_context.p_port = p_port;\r
+ in.Version = IBAT_IOCTL_VERSION;\r
+ in.PortGuid = p_port->guid;\r
\r
- query_req.query_type = IB_QUERY_USER_DEFINED;\r
- query_req.p_query_input = &user_query;\r
- query_req.port_guid = p_port->guid;\r
- query_req.timeout_ms = 500; /* 500ms timeout */\r
- query_req.retry_cnt = 4; /* retry 4 times */\r
- query_req.flags = IB_FLAGS_SYNC;\r
- query_req.query_context = &query_context;\r
- query_req.pfn_query_cb = query_ip_address_callback;\r
+ cl_spinlock_acquire( &g_ibsp.ip_mutex );\r
+ if( g_ibsp.h_ibat_dev == INVALID_HANDLE_VALUE )\r
+ {\r
+ g_ibsp.h_ibat_dev = CreateFileW( IBAT_WIN32_NAME,\r
+ GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,\r
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );\r
+ }\r
+ cl_spinlock_release( &g_ibsp.ip_mutex );\r
\r
- user_query.method = IB_MAD_METHOD_GETTABLE;\r
- user_query.attr_id = IB_MAD_ATTR_SERVICE_RECORD;\r
- user_query.attr_size = sizeof(ib_service_record_t);\r
- user_query.comp_mask = IB_SR_COMPMASK_SGID |\r
- IB_SR_COMPMASK_SPKEY | IB_SR_COMPMASK_SLEASE | IB_SR_COMPMASK_SNAME;\r
+ size = sizeof(IOCTL_IBAT_IP_ADDRESSES_OUT);\r
\r
- user_query.p_attr = &service_record;\r
+ do\r
+ {\r
+ p_out = HeapAlloc( g_ibsp.heap, 0, size );\r
\r
- memset( &service_record, 0, sizeof(service_record) );\r
- service_record.service_pkey = IB_DEFAULT_PKEY;\r
- ib_gid_set_default( &service_record.service_gid, p_port->guid );\r
- service_record.service_lease = 0xFFFFFFFF;\r
- strcpy( (void *)service_record.service_name, ATS_NAME );\r
+ if( !p_out )\r
+ {\r
+ IBSP_ERROR_EXIT( ("Failed to allocate output buffer.\n") );\r
+ return -1;\r
+ }\r
+\r
+ if( !DeviceIoControl( g_ibsp.h_ibat_dev, IOCTL_IBAT_IP_ADDRESSES,\r
+ &in, sizeof(in), p_out, sizeof(IOCTL_IBAT_IP_ADDRESSES_OUT),\r
+ &size, NULL ) )\r
+ {\r
+ HeapFree( g_ibsp.heap, 0, p_out );\r
+ IBSP_ERROR_EXIT(\r
+ ("IOCTL_IBAT_IP_ADDRESSES for port %I64x failed (%x).\n",\r
+ p_port->guid, GetLastError()) );\r
+ return -1;\r
+ }\r
\r
- fzprint(("%s():%d:0x%x:0x%x: Calling ib_query() pfn_query_cb=0x%p..\n", __FUNCTION__,\r
- __LINE__, GetCurrentProcessId(),\r
- GetCurrentThreadId(), query_req.pfn_query_cb));\r
+ if( p_out->Size > size )\r
+ {\r
+ size = p_out->Size;\r
+ HeapFree( g_ibsp.heap, 0, p_out );\r
+ p_out = NULL;\r
+ }\r
\r
- status = ib_query( g_ibsp.al_handle, &query_req, &query_handle );\r
+ } while( !p_out );\r
\r
- if( status != IB_SUCCESS && status != IB_INVALID_GUID )\r
+ IBSP_TRACE( IBSP_DBG_HW, ("Port %I64x has %d IP addresses.\n",\r
+ p_port->guid, p_out->AddressCount) );\r
+\r
+ for( i = 0; i < p_out->AddressCount; i++ )\r
{\r
- IBSP_ERROR( ("ib_query failed (%d)\n", status) );\r
- CL_ASSERT( !cl_fmap_count( p_ip_map ) );\r
+ struct ibsp_ip_addr *ip_addr;\r
\r
- IBSP_ERROR_EXIT(\r
- ("Failed to build list of IP addr for port %016I64x\n",\r
- CL_HTON64( p_port->guid )) );\r
+ ip_addr = HeapAlloc(\r
+ g_ibsp.heap, 0, sizeof(struct ibsp_ip_addr) );\r
+ if( !ip_addr )\r
+ {\r
+ IBSP_ERROR_EXIT( ("no memory\n") );\r
+ break;\r
+ }\r
\r
- IBSP_ERROR_EXIT( ("query_ip_address failed\n") );\r
- return 1;\r
- }\r
+ /* Copy the IP address */\r
+ ip_addr->ip_addr.S_un.S_addr =\r
+ *(ib_net32_t *) &p_out->Address[i].Address[ATS_IPV4_OFFSET];\r
+ ip_addr->p_port = p_port;\r
\r
- fzprint(("%s():%d:0x%x:0x%x: Done calling ib_query() status=(%d)\n", __FUNCTION__,\r
- __LINE__, GetCurrentProcessId(), GetCurrentThreadId(), status));\r
+ p_item = cl_fmap_insert( p_ip_map, ip_addr, &ip_addr->item );\r
+ if( p_item != &ip_addr->item )\r
+ {\r
+ /* Duplicate! Should never happen. */\r
+ IBSP_ERROR(\r
+ ("Got duplicate addr %s\n", inet_ntoa( ip_addr->ip_addr )) );\r
+ HeapFree( g_ibsp.heap, 0, ip_addr );\r
+ continue;\r
+ }\r
\r
+ IBSP_TRACE( IBSP_DBG_HW,\r
+ ("Got addr %s\n", inet_ntoa( ip_addr->ip_addr )) );\r
+ }\r
+\r
+ HeapFree( g_ibsp.heap, 0, p_out );\r
\r
IBSP_EXIT( IBSP_DBG_HW );\r
return 0;\r
return 0;\r
}\r
\r
-\r
-void\r
-update_all_ip_addrs(void)\r
-{\r
- cl_list_item_t *p_hca_item, *p_port_item;\r
- struct ibsp_hca *p_hca;\r
- struct ibsp_port *p_port;\r
-\r
- IBSP_ENTER( IBSP_DBG_HW );\r
-\r
- cl_spinlock_acquire( &g_ibsp.hca_mutex );\r
- for( p_hca_item = cl_qlist_head( &g_ibsp.hca_list );\r
- p_hca_item != cl_qlist_end( &g_ibsp.hca_list );\r
- p_hca_item = cl_qlist_next( p_hca_item ) )\r
- {\r
- p_hca = PARENT_STRUCT( p_hca_item, struct ibsp_hca, item );\r
-\r
- cl_spinlock_acquire( &p_hca->port_lock );\r
- for( p_port_item = cl_qlist_head( &p_hca->port_list );\r
- p_port_item != cl_qlist_end( &p_hca->port_list );\r
- p_port_item = cl_qlist_next( p_port_item ) )\r
- {\r
- p_port = PARENT_STRUCT( p_port_item, struct ibsp_port, item );\r
- update_ip_addresses( p_port );\r
- }\r
- cl_spinlock_release( &p_hca->port_lock );\r
- }\r
- cl_spinlock_release( &g_ibsp.hca_mutex );\r
-\r
- IBSP_EXIT( IBSP_DBG_HW );\r
-}\r
-\r
/*--------------------------------------------------------------------------*/\r
\r
/* \r
switch( num_ip )\r
{\r
case 0:\r
+ cl_spinlock_acquire( &g_ibsp.ip_mutex );\r
+ if( g_ibsp.h_ibat_dev != INVALID_HANDLE_VALUE )\r
+ {\r
+ CloseHandle( g_ibsp.h_ibat_dev );\r
+ g_ibsp.h_ibat_dev = INVALID_HANDLE_VALUE;\r
+ }\r
+ cl_spinlock_release( &g_ibsp.ip_mutex );\r
break;\r
\r
default:\r