[WSD] Use IBAT to get local IP addresses.
authorftillier <ftillier@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Thu, 8 Dec 2005 04:37:07 +0000 (04:37 +0000)
committerftillier <ftillier@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Thu, 8 Dec 2005 04:37:07 +0000 (04:37 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@200 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

ulp/wsd/user/ibsp_iblow.c
ulp/wsd/user/ibsp_ip.c
ulp/wsd/user/ibspdll.h
ulp/wsd/user/ibspproto.h
ulp/wsd/user/ibspstruct.h
ulp/wsd/user/misc.c

index 67ec7ac..0122fbe 100644 (file)
@@ -862,9 +862,6 @@ ibsp_initialize(void)
                goto done;\r
        }\r
 \r
-       /* Populate IP list. */\r
-       update_all_ip_addrs();\r
-\r
        STAT_INC( thread_num );\r
 \r
        ret = 0;\r
index 0ad6960..d0a6d70 100644 (file)
@@ -72,137 +72,102 @@ ip_cmp(
 }\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
@@ -281,38 +246,6 @@ update_ip_addresses(
        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
@@ -603,6 +536,13 @@ build_ip_list(
        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
index 0feaa3d..75e2eea 100644 (file)
 #include <stdlib.h>\r
 #include <ws2spi.h>\r
 #include <ws2san.h>\r
+#include <devioctl.h>\r
 \r
 #include <iba/ib_al.h>\r
+#include <iba/ib_at_ioctl.h>\r
 #include <complib/cl_timer.h>\r
 \r
 #include "ibspdefines.h"\r
index f799fe1..4f866f8 100644 (file)
@@ -151,9 +151,6 @@ ibal_to_wsa_error(
        IN                              const ib_api_status_t           status );\r
 \r
 /* Protos from ibsp_ip.c */\r
-void\r
-update_all_ip_addrs(void);\r
-\r
 intn_t CL_API\r
 ip_cmp(\r
        IN      const void* const               p_key1,\r
index 164d016..fe04c40 100644 (file)
@@ -442,6 +442,7 @@ struct ibspdll_globals
        cl_qlist_t hca_list;\r
        cl_spinlock_t hca_mutex;\r
 \r
+       HANDLE                  h_ibat_dev;\r
        cl_fmap_t               ip_map;                 /* list of all IP addresses supported by all the ports. */\r
        cl_spinlock_t   ip_mutex;\r
 \r
index 1bf4598..2f92f82 100644 (file)
@@ -98,6 +98,7 @@ init_globals( void )
        cl_qlist_init( &g_ibsp.hca_list );\r
        cl_spinlock_init( &g_ibsp.hca_mutex );\r
 \r
+       g_ibsp.h_ibat_dev = INVALID_HANDLE_VALUE;\r
        cl_fmap_init( &g_ibsp.ip_map, ip_cmp );\r
        cl_spinlock_init( &g_ibsp.ip_mutex );\r
 \r
@@ -114,7 +115,9 @@ void
 release_globals( void )\r
 {\r
        HeapDestroy( g_ibsp.heap );\r
-       g_ibsp.heap = NULL;\r
+\r
+       if( g_ibsp.h_ibat_dev != INVALID_HANDLE_VALUE )\r
+               CloseHandle( g_ibsp.h_ibat_dev );\r
 \r
        cl_spinlock_destroy( &g_ibsp.socket_info_mutex );\r
        cl_spinlock_destroy( &g_ibsp.hca_mutex );\r