[IPoIB, Complib] Fix NDIS WHQL 1c_KernelCalls public import test failures.
[mirror/winof/.git] / ulp / ipoib / kernel / ipoib_driver.c
1 /*\r
2  * Copyright (c) 2005 SilverStorm Technologies.  All rights reserved.\r
3  *\r
4  * This software is available to you under the OpenIB.org BSD license\r
5  * below:\r
6  *\r
7  *     Redistribution and use in source and binary forms, with or\r
8  *     without modification, are permitted provided that the following\r
9  *     conditions are met:\r
10  *\r
11  *      - Redistributions of source code must retain the above\r
12  *        copyright notice, this list of conditions and the following\r
13  *        disclaimer.\r
14  *\r
15  *      - Redistributions in binary form must reproduce the above\r
16  *        copyright notice, this list of conditions and the following\r
17  *        disclaimer in the documentation and/or other materials\r
18  *        provided with the distribution.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
27  * SOFTWARE.\r
28  *\r
29  * $Id$\r
30  */\r
31 \r
32 \r
33 #include "ipoib_driver.h"\r
34 #include "ipoib_debug.h"\r
35 #include "ipoib_port.h"\r
36 #include "ipoib_ibat.h"\r
37 #include <complib/cl_bus_ifc.h>\r
38 #include <complib/cl_init.h>\r
39 #include <initguid.h>\r
40 #include <iba/ipoib_ifc.h>\r
41 \r
42 \r
43 /* Default parameters values for optional parameters */\r
44 #define DEF_WSDP_ENABLED        FALSE\r
45 #define DEF_STATIC_LID          0\r
46 #define DEF_RECV_GROWTH         0\r
47 \r
48 \r
49 #if defined(NDIS50_MINIPORT)\r
50 #define MAJOR_NDIS_VERSION 5\r
51 #define MINOR_NDIS_VERSION 0\r
52 #elif defined (NDIS51_MINIPORT)\r
53 #define MAJOR_NDIS_VERSION 5\r
54 #define MINOR_NDIS_VERSION 1\r
55 #else\r
56 #error NDIS Version not defined, try defining NDIS50_MINIPORT or NDIS51_MINIPORT\r
57 #endif\r
58 \r
59 static const NDIS_OID SUPPORTED_OIDS[] =\r
60 {\r
61         OID_GEN_SUPPORTED_LIST,\r
62         OID_GEN_HARDWARE_STATUS,\r
63         OID_GEN_MEDIA_SUPPORTED,\r
64         OID_GEN_MEDIA_IN_USE,\r
65         OID_GEN_MAXIMUM_LOOKAHEAD,\r
66         OID_GEN_MAXIMUM_FRAME_SIZE,\r
67         OID_GEN_LINK_SPEED,\r
68         OID_GEN_TRANSMIT_BUFFER_SPACE,\r
69         OID_GEN_RECEIVE_BUFFER_SPACE,\r
70         OID_GEN_TRANSMIT_BLOCK_SIZE,\r
71         OID_GEN_RECEIVE_BLOCK_SIZE,\r
72         OID_GEN_VENDOR_ID,\r
73         OID_GEN_VENDOR_DESCRIPTION,\r
74         OID_GEN_CURRENT_PACKET_FILTER,\r
75         OID_GEN_CURRENT_LOOKAHEAD,\r
76         OID_GEN_DRIVER_VERSION,\r
77         OID_GEN_MAXIMUM_TOTAL_SIZE,\r
78         OID_GEN_PROTOCOL_OPTIONS,\r
79         OID_GEN_MAC_OPTIONS,\r
80         OID_GEN_MEDIA_CONNECT_STATUS,\r
81         OID_GEN_MAXIMUM_SEND_PACKETS,\r
82         OID_GEN_NETWORK_LAYER_ADDRESSES,\r
83         OID_GEN_VENDOR_DRIVER_VERSION,\r
84         OID_GEN_PHYSICAL_MEDIUM,\r
85         OID_GEN_XMIT_OK,\r
86         OID_GEN_RCV_OK,\r
87         OID_GEN_XMIT_ERROR,\r
88         OID_GEN_RCV_ERROR,\r
89         OID_GEN_RCV_NO_BUFFER,\r
90         OID_GEN_DIRECTED_BYTES_XMIT,\r
91         OID_GEN_DIRECTED_FRAMES_XMIT,\r
92         OID_GEN_MULTICAST_BYTES_XMIT,\r
93         OID_GEN_MULTICAST_FRAMES_XMIT,\r
94         OID_GEN_BROADCAST_BYTES_XMIT,\r
95         OID_GEN_BROADCAST_FRAMES_XMIT,\r
96         OID_GEN_DIRECTED_BYTES_RCV,\r
97         OID_GEN_DIRECTED_FRAMES_RCV,\r
98         OID_GEN_MULTICAST_BYTES_RCV,\r
99         OID_GEN_MULTICAST_FRAMES_RCV,\r
100         OID_GEN_BROADCAST_BYTES_RCV,\r
101         OID_GEN_BROADCAST_FRAMES_RCV,\r
102         OID_802_3_PERMANENT_ADDRESS,\r
103         OID_802_3_CURRENT_ADDRESS,\r
104         OID_802_3_MULTICAST_LIST,\r
105         OID_802_3_MAXIMUM_LIST_SIZE,\r
106         OID_802_3_MAC_OPTIONS,\r
107         OID_802_3_RCV_ERROR_ALIGNMENT,\r
108         OID_802_3_XMIT_ONE_COLLISION,\r
109         OID_802_3_XMIT_MORE_COLLISIONS,\r
110         OID_TCP_TASK_OFFLOAD\r
111 };\r
112 \r
113 static const unsigned char VENDOR_ID[] = {0x00, 0x06, 0x6A, 0x00};\r
114 \r
115 #define VENDOR_DESCRIPTION "Internet Protocol over InfiniBand"\r
116 \r
117 #define IB_INFINITE_SERVICE_LEASE       0xFFFFFFFF\r
118 \r
119 \r
120 /* Global driver debug level */\r
121 uint32_t                g_ipoib_dbg_lvl = IPOIB_DBG_ERROR;\r
122 ipoib_globals_t g_ipoib = {0};\r
123 \r
124 \r
125 NTSTATUS\r
126 DriverEntry(\r
127         IN                              PDRIVER_OBJECT                          p_drv_obj,\r
128         IN                              PUNICODE_STRING                         p_reg_path );\r
129 \r
130 VOID\r
131 ipoib_unload(\r
132         IN                              PDRIVER_OBJECT                          p_drv_obj );\r
133 \r
134 NDIS_STATUS\r
135 ipoib_initialize(\r
136                 OUT                     PNDIS_STATUS                            p_open_err_status,\r
137                 OUT                     PUINT                                           p_selected_medium_index,\r
138         IN                              PNDIS_MEDIUM                            medium_array,\r
139         IN                              UINT                                            medium_array_size,\r
140         IN                              NDIS_HANDLE                                     h_adapter,\r
141         IN                              NDIS_HANDLE                                     wrapper_configuration_context );\r
142 \r
143 BOOLEAN\r
144 ipoib_check_for_hang(\r
145         IN                              NDIS_HANDLE                                     adapter_context );\r
146 \r
147 void\r
148 ipoib_halt(\r
149         IN                              NDIS_HANDLE                                     adapter_context );\r
150 \r
151 NDIS_STATUS\r
152 ipoib_query_info(\r
153         IN                              NDIS_HANDLE                                     adapter_context,\r
154         IN                              NDIS_OID                                        oid,\r
155         IN                              PVOID                                           info_buf,\r
156         IN                              ULONG                                           info_buf_len,\r
157                 OUT                     PULONG                                          p_bytes_written,\r
158                 OUT                     PULONG                                          p_bytes_needed );\r
159 \r
160 NDIS_STATUS\r
161 ipoib_reset(\r
162                 OUT                     PBOOLEAN                                        p_addressing_reset,\r
163         IN                              NDIS_HANDLE                                     adapter_context );\r
164 \r
165 NDIS_STATUS\r
166 ipoib_set_info(\r
167         IN                              NDIS_HANDLE                                     adapter_context,\r
168         IN                              NDIS_OID                                        oid,\r
169         IN                              PVOID                                           info_buf,\r
170         IN                              ULONG                                           info_buf_length,\r
171                 OUT                     PULONG                                          p_bytes_read,\r
172                 OUT                     PULONG                                          p_bytes_needed );\r
173 \r
174 void\r
175 ipoib_send_packets(\r
176         IN                              NDIS_HANDLE                                     adapter_context,\r
177         IN                              PPNDIS_PACKET                           packet_array,\r
178         IN                              UINT                                            num_packets );\r
179 \r
180 void\r
181 ipoib_pnp_notify(\r
182         IN                              NDIS_HANDLE                                     adapter_context,\r
183         IN                              NDIS_DEVICE_PNP_EVENT           pnp_event,\r
184         IN                              PVOID                                           info_buf,\r
185         IN                              ULONG                                           info_buf_len );\r
186 \r
187 void\r
188 ipoib_shutdown(\r
189         IN                              PVOID                                           adapter_context );\r
190 \r
191 static void\r
192 ipoib_complete_query(\r
193         IN                              ipoib_adapter_t* const          p_adapter,\r
194         IN                              pending_oid_t* const            p_oid_info,\r
195         IN              const   NDIS_STATUS                                     status,\r
196         IN              const   void* const                                     p_buf,\r
197         IN              const   ULONG                                           buf_len );\r
198 \r
199 static NDIS_STATUS\r
200 __ipoib_set_net_addr(\r
201         IN              ipoib_adapter_t *       p_adapter,\r
202         IN              PVOID                           info_buf,\r
203         IN              ULONG                           info_buf_len,\r
204                 OUT     PULONG                          p_bytes_read,\r
205                 OUT     PULONG                          p_bytes_needed );\r
206 \r
207 static NDIS_STATUS\r
208 __ipoib_get_tcp_task_offload(\r
209         IN                              ipoib_adapter_t*                        p_adapter,\r
210         IN                              pending_oid_t* const            p_oid_info );\r
211 \r
212 static void\r
213 __ipoib_ats_reg_cb(\r
214         IN                              ib_reg_svc_rec_t                        *p_reg_svc_rec );\r
215 \r
216 static void\r
217 __ipoib_ats_dereg_cb(\r
218         IN                              void                                            *context );\r
219 \r
220 static NTSTATUS\r
221 __ipoib_read_registry(\r
222         IN                              UNICODE_STRING* const           p_registry_path );\r
223 \r
224 \r
225 //! Standard Windows Device Driver Entry Point\r
226 /*! DriverEntry is the first routine called after a driver is loaded, and\r
227 is responsible for initializing the driver.  On W2k this occurs when the PnP\r
228 Manager matched a PnP ID to one in an INF file that references this driver.\r
229 Any not success return value will cause the driver to fail to load.\r
230 IRQL = PASSIVE_LEVEL\r
231 \r
232 @param p_drv_obj Pointer to Driver Object for this device driver\r
233 @param p_registry_path Pointer to unicode string containing path to this driver's registry area\r
234 @return STATUS_SUCCESS, NDIS_STATUS_BAD_CHARACTERISTICS, NDIS_STATUS_BAD_VERSION,\r
235 NDIS_STATUS_RESOURCES, or NDIS_STATUS_FAILURE\r
236 */\r
237 NTSTATUS\r
238 DriverEntry(\r
239         IN                              PDRIVER_OBJECT                          p_drv_obj,\r
240         IN                              PUNICODE_STRING                         p_registry_path )\r
241 {\r
242         NDIS_STATUS                                             status;\r
243         NDIS_HANDLE                                             ndis_handle;\r
244         NDIS_MINIPORT_CHARACTERISTICS   characteristics;\r
245 \r
246         IPOIB_ENTER( IPOIB_DBG_INIT );\r
247 \r
248 #ifdef _DEBUG_\r
249         PAGED_CODE();\r
250 #endif\r
251 \r
252         status = CL_INIT;\r
253         if( !NT_SUCCESS( status ) )\r
254         {\r
255                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR,\r
256                         ("cl_init failed.\n") );\r
257                 return status;\r
258         }\r
259 \r
260         status          = NDIS_STATUS_SUCCESS;\r
261         ndis_handle     = NULL;\r
262 \r
263         __ipoib_read_registry(p_registry_path);\r
264         \r
265         KeInitializeSpinLock( &g_ipoib.lock );\r
266         cl_qlist_init( &g_ipoib.adapter_list );\r
267 \r
268         NdisMInitializeWrapper(\r
269                 &g_ipoib.h_ndis_wrapper, p_drv_obj, p_registry_path, NULL );\r
270 \r
271         memset(&characteristics, 0, sizeof(characteristics));\r
272         characteristics.MajorNdisVersion                = MAJOR_NDIS_VERSION;\r
273         characteristics.MinorNdisVersion                = MINOR_NDIS_VERSION;\r
274         characteristics.CheckForHangHandler             = ipoib_check_for_hang;\r
275         characteristics.HaltHandler                             = ipoib_halt;\r
276         characteristics.InitializeHandler               = ipoib_initialize;\r
277         characteristics.QueryInformationHandler = ipoib_query_info;\r
278         characteristics.ResetHandler                    = ipoib_reset;\r
279         characteristics.SetInformationHandler   = ipoib_set_info;\r
280 \r
281         characteristics.ReturnPacketHandler             = ipoib_return_packet;\r
282         characteristics.SendPacketsHandler              = ipoib_send_packets;\r
283 \r
284 #ifdef NDIS51_MINIPORT\r
285         characteristics.PnPEventNotifyHandler   = ipoib_pnp_notify;\r
286         characteristics.AdapterShutdownHandler  = ipoib_shutdown;\r
287 #endif\r
288 \r
289         status = NdisMRegisterMiniport(\r
290                 g_ipoib.h_ndis_wrapper, &characteristics, sizeof(characteristics) );\r
291         if( status != NDIS_STATUS_SUCCESS )\r
292         {\r
293                 IPOIB_TRACE( IPOIB_DBG_ERROR, \r
294                         ("NdisMRegisterMiniport failed with status of %d\n", status) );\r
295                 NdisTerminateWrapper( g_ipoib.h_ndis_wrapper, NULL );\r
296                 CL_DEINIT;\r
297                 return status;\r
298         }\r
299 \r
300         NdisMRegisterUnloadHandler( g_ipoib.h_ndis_wrapper, ipoib_unload );\r
301 \r
302         IPOIB_EXIT( IPOIB_DBG_INIT );\r
303         return status;\r
304 }\r
305 \r
306 \r
307 static NTSTATUS\r
308 __ipoib_read_registry(\r
309         IN                              UNICODE_STRING* const           p_registry_path )\r
310 {\r
311         NTSTATUS                                                status;\r
312         /* Remember the terminating entry in the table below. */\r
313         RTL_QUERY_REGISTRY_TABLE                table[2];\r
314         UNICODE_STRING                                  param_path;\r
315 \r
316         IPOIB_ENTER( IPOIB_DBG_INIT );\r
317 \r
318         RtlInitUnicodeString( &param_path, NULL );\r
319         param_path.MaximumLength = p_registry_path->Length + \r
320                 sizeof(L"\\Parameters");\r
321         param_path.Buffer = cl_zalloc( param_path.MaximumLength );\r
322         if( !param_path.Buffer )\r
323         {\r
324                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR, \r
325                         ("Failed to allocate parameters path buffer.\n") );\r
326                 return STATUS_INSUFFICIENT_RESOURCES;\r
327         }\r
328 \r
329         RtlAppendUnicodeStringToString( &param_path, p_registry_path );\r
330         RtlAppendUnicodeToString( &param_path, L"\\Parameters" );\r
331 \r
332         /*\r
333          * Clear the table.  This clears all the query callback pointers,\r
334          * and sets up the terminating table entry.\r
335          */\r
336         cl_memclr( table, sizeof(table) );\r
337 \r
338         /* Setup the table entries. */\r
339         table[0].Flags = RTL_QUERY_REGISTRY_DIRECT;\r
340         table[0].Name = L"DebugFlags";\r
341         table[0].EntryContext = &g_ipoib_dbg_lvl;\r
342         table[0].DefaultType = REG_DWORD;\r
343         table[0].DefaultData = &g_ipoib_dbg_lvl;\r
344         table[0].DefaultLength = sizeof(ULONG);\r
345 \r
346         /* Have at it! */\r
347         status = RtlQueryRegistryValues( RTL_REGISTRY_ABSOLUTE, \r
348                 param_path.Buffer, table, NULL, NULL );\r
349 \r
350         cl_free( param_path.Buffer );\r
351         IPOIB_EXIT( IPOIB_DBG_INIT );\r
352         return status;\r
353 }\r
354 \r
355 \r
356 VOID\r
357 ipoib_unload(\r
358         IN                              PDRIVER_OBJECT                          p_drv_obj )\r
359 {\r
360         IPOIB_ENTER( IPOIB_DBG_INIT );\r
361         UNREFERENCED_PARAMETER( p_drv_obj );\r
362         CL_DEINIT;\r
363         IPOIB_EXIT( IPOIB_DBG_INIT );\r
364 }\r
365 \r
366 \r
367 NDIS_STATUS\r
368 ipoib_get_adapter_params(\r
369         IN                              NDIS_HANDLE* const                      wrapper_config_context,\r
370                 OUT                     ipoib_params_t* const           p_params )\r
371 {\r
372         NDIS_STATUS                                             status;\r
373         NDIS_HANDLE                                             h_config;\r
374         NDIS_CONFIGURATION_PARAMETER    *p_param;\r
375         NDIS_STRING                                             keyword;\r
376 \r
377         IPOIB_ENTER( IPOIB_DBG_INIT );\r
378 \r
379         NdisOpenConfiguration( &status, &h_config, wrapper_config_context );\r
380         if( status != NDIS_STATUS_SUCCESS )\r
381         {\r
382                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR,\r
383                         ("NdisOpenConfiguration returned 0x%.8x\n", status) );\r
384                 return status;\r
385         }\r
386 \r
387         /* Required: Receive queue depth. */\r
388         RtlInitUnicodeString( &keyword, L"RqDepth" );\r
389         NdisReadConfiguration(\r
390                 &status, &p_param, h_config, &keyword, NdisParameterInteger );\r
391         if( status != NDIS_STATUS_SUCCESS )\r
392         {\r
393                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR,\r
394                         ("Receive Queue Depth parameter missing.\n") );\r
395                 return status;\r
396         }\r
397         p_params->rq_depth = p_param->ParameterData.IntegerData;\r
398 \r
399         /* Required: Send queue depth. */\r
400         RtlInitUnicodeString( &keyword, L"SqDepth" );\r
401         NdisReadConfiguration(\r
402                 &status, &p_param, h_config, &keyword, NdisParameterInteger );\r
403         if( status != NDIS_STATUS_SUCCESS )\r
404         {\r
405                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR,\r
406                         ("Send Queue Depth parameter missing.\n") );\r
407                 return status;\r
408         }\r
409         p_params->sq_depth = p_param->ParameterData.IntegerData;\r
410         /* Send queue depth needs to be a power of two. */\r
411         if( p_params->sq_depth <= 128 )\r
412                 p_params->sq_depth = 128;\r
413         else if( p_params->sq_depth <= 256 )\r
414                 p_params->sq_depth = 256;\r
415         else if( p_params->sq_depth <= 512 )\r
416                 p_params->sq_depth = 512;\r
417         else\r
418                 p_params->sq_depth = 1024;\r
419 \r
420         /* Required: Send Checksum Offload. */\r
421         RtlInitUnicodeString( &keyword, L"SendChksum" );\r
422         NdisReadConfiguration(\r
423                 &status, &p_param, h_config, &keyword, NdisParameterInteger );\r
424         if( status != NDIS_STATUS_SUCCESS )\r
425         {\r
426                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR,\r
427                         ("Send Checksum Offload parameter missing.\n") );\r
428                 return status;\r
429         }\r
430         p_params->send_chksum_offload = (p_param->ParameterData.IntegerData != 0);\r
431 \r
432         /* Optional: WSDP support. */\r
433         RtlInitUnicodeString( &keyword, L"WsdpEnabled" );\r
434         NdisReadConfiguration(\r
435                 &status, &p_param, h_config, &keyword, NdisParameterInteger );\r
436         if( status != NDIS_STATUS_SUCCESS )\r
437                 p_params->wsdp_enabled = DEF_WSDP_ENABLED;\r
438         else\r
439                 p_params->wsdp_enabled = (p_param->ParameterData.IntegerData != 0);\r
440 \r
441         /* Optional: Static LID assignment if SM is not up. */\r
442         RtlInitUnicodeString( &keyword, L"StaticLid" );\r
443         NdisReadConfiguration(\r
444                 &status, &p_param, h_config, &keyword, NdisParameterInteger );\r
445         if( status != NDIS_STATUS_SUCCESS )\r
446                 p_params->static_lid = DEF_STATIC_LID;\r
447         else\r
448                 p_params->static_lid = (uint16_t)p_param->ParameterData.IntegerData;\r
449 \r
450         /* Required: SA query timeout, in milliseconds. */\r
451         RtlInitUnicodeString( &keyword, L"SaTimeout" );\r
452         NdisReadConfiguration(\r
453                 &status, &p_param, h_config, &keyword, NdisParameterInteger );\r
454         if( status != NDIS_STATUS_SUCCESS )\r
455         {\r
456                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR,\r
457                         ("SA query timeout parameter missing.\n") );\r
458                 return status;\r
459         }\r
460         p_params->sa_timeout = p_param->ParameterData.IntegerData;\r
461 \r
462         /* Required: SA query retry count. */\r
463         RtlInitUnicodeString( &keyword, L"SaRetries" );\r
464         NdisReadConfiguration(\r
465                 &status, &p_param, h_config, &keyword, NdisParameterInteger );\r
466         if( status != NDIS_STATUS_SUCCESS )\r
467         {\r
468                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR,\r
469                         ("SA query retry count parameter missing.\n") );\r
470                 return status;\r
471         }\r
472         p_params->sa_retry_cnt = p_param->ParameterData.IntegerData;\r
473 \r
474         /* Required: Receive pool to queue depth ratio. */\r
475         RtlInitUnicodeString( &keyword, L"RecvRatio" );\r
476         NdisReadConfiguration(\r
477                 &status, &p_param, h_config, &keyword, NdisParameterInteger );\r
478         if( status != NDIS_STATUS_SUCCESS )\r
479         {\r
480                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR,\r
481                         ("Receive pool to queue depth ratio parameter missing.\n") );\r
482                 return status;\r
483         }\r
484         p_params->recv_pool_ratio = p_param->ParameterData.IntegerData;\r
485 \r
486         /* Required: Receive pool growth threshold. */\r
487         RtlInitUnicodeString( &keyword, L"RecvGrowth" );\r
488         NdisReadConfiguration(\r
489                 &status, &p_param, h_config, &keyword, NdisParameterInteger );\r
490         if( status != NDIS_STATUS_SUCCESS )\r
491                 p_params->recv_growth = DEF_RECV_GROWTH;\r
492         else\r
493                 p_params->recv_growth = (p_param->ParameterData.IntegerData != 0);\r
494 \r
495         NdisCloseConfiguration( h_config );\r
496 \r
497         IPOIB_EXIT( IPOIB_DBG_INIT );\r
498         return NDIS_STATUS_SUCCESS;\r
499 }\r
500 \r
501 \r
502 NDIS_STATUS\r
503 ipoib_get_adapter_guids(\r
504         IN                              NDIS_HANDLE* const                      h_adapter,\r
505         IN      OUT                     ipoib_adapter_t                         *p_adapter )\r
506 {\r
507         NTSTATUS                        status;\r
508         ib_al_ifc_data_t        data;\r
509         IO_STACK_LOCATION       io_stack, *p_fwd_io_stack;\r
510         DEVICE_OBJECT           *p_pdo;\r
511         IRP                                     *p_irp;\r
512         KEVENT                          event;\r
513         IO_STATUS_BLOCK         io_status;\r
514 \r
515         IPOIB_ENTER( IPOIB_DBG_INIT );\r
516 \r
517         NdisMGetDeviceProperty( h_adapter, &p_pdo, NULL, NULL, NULL, NULL );\r
518 \r
519         /* Query for our interface */\r
520         data.size = sizeof(ipoib_ifc_data_t);\r
521         data.version = IPOIB_INTERFACE_DATA_VERSION;\r
522         data.type = &GUID_IPOIB_INTERFACE_DATA;\r
523         data.p_data = &p_adapter->guids;\r
524 \r
525         io_stack.MinorFunction = IRP_MN_QUERY_INTERFACE;\r
526         io_stack.Parameters.QueryInterface.Version = AL_INTERFACE_VERSION;\r
527         io_stack.Parameters.QueryInterface.Size = sizeof(ib_al_ifc_t);\r
528         io_stack.Parameters.QueryInterface.Interface =\r
529                 (INTERFACE*)p_adapter->p_ifc;\r
530         io_stack.Parameters.QueryInterface.InterfaceSpecificData = &data;\r
531         io_stack.Parameters.QueryInterface.InterfaceType = \r
532                 &GUID_IB_AL_INTERFACE;\r
533 \r
534         KeInitializeEvent( &event, NotificationEvent, FALSE );\r
535 \r
536         /* Build the IRP for the HCA. */\r
537         p_irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP, p_pdo,\r
538                 NULL, 0, NULL, &event, &io_status );\r
539         if( !p_irp )\r
540         {\r
541                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR,\r
542                         ("Failed to allocate query interface IRP.\n") );\r
543                 return STATUS_INSUFFICIENT_RESOURCES;\r
544         }\r
545 \r
546         /* Copy the request query parameters. */\r
547         p_fwd_io_stack = IoGetNextIrpStackLocation( p_irp );\r
548         p_fwd_io_stack->MinorFunction = IRP_MN_QUERY_INTERFACE;\r
549         p_fwd_io_stack->Parameters.QueryInterface =\r
550                 io_stack.Parameters.QueryInterface;\r
551         p_irp->IoStatus.Status = STATUS_NOT_SUPPORTED;\r
552 \r
553         /* Send the IRP. */\r
554         status = IoCallDriver( p_pdo, p_irp );\r
555         if( status == STATUS_PENDING )\r
556         {\r
557                 KeWaitForSingleObject( &event, Executive, KernelMode,\r
558                         FALSE, NULL );\r
559                 status = io_status.Status;\r
560         }\r
561 \r
562         if( !NT_SUCCESS( status ) )\r
563         {\r
564                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR,\r
565                         ("Query interface for IPOIB interface returned %08x.\n", status) );\r
566                 return status;\r
567         }\r
568 \r
569         /*\r
570          * Dereference the interface now so that the bus driver doesn't fail a\r
571          * query remove IRP.  We will always get unloaded before the bus driver\r
572          * since we're a child device.\r
573          */\r
574         p_adapter->p_ifc->wdm.InterfaceDereference(\r
575                 p_adapter->p_ifc->wdm.Context );\r
576         IPOIB_EXIT( IPOIB_DBG_INIT );\r
577         return NDIS_STATUS_SUCCESS;\r
578 }\r
579 \r
580 \r
581 //! Initialization function called for each IOC discovered\r
582 /*  The MiniportInitialize function is a required function that sets up a\r
583 NIC (or virtual NIC) for network I/O operations, claims all hardware\r
584 resources necessary to the NIC in the registry, and allocates resources\r
585 the driver needs to carry out network I/O operations.\r
586 IRQL = PASSIVE_LEVEL\r
587 \r
588 @param p_open_status Pointer to a status field set if this function returns NDIS_STATUS_OPEN_ERROR\r
589 @param p_selected_medium_index Pointer to unsigned integer noting index into medium_array for this NIC\r
590 @param medium_array Array of mediums for this NIC\r
591 @param medium_array_size Number of elements in medium_array\r
592 @param h_adapter Handle assigned by NDIS for this NIC\r
593 @param wrapper_config_context Handle used for Ndis initialization functions\r
594 @return NDIS_STATUS_SUCCESS, NDIS_STATUS_UNSUPPORTED_MEDIA, NDIS_STATUS_RESOURCES,\r
595 NDIS_STATUS_NOT_SUPPORTED \r
596 */\r
597 NDIS_STATUS\r
598 ipoib_initialize(\r
599                 OUT                     PNDIS_STATUS                            p_open_status,\r
600                 OUT                     PUINT                                           p_selected_medium_index,\r
601         IN                              PNDIS_MEDIUM                            medium_array,\r
602         IN                              UINT                                            medium_array_size,\r
603         IN                              NDIS_HANDLE                                     h_adapter,\r
604         IN                              NDIS_HANDLE                                     wrapper_config_context )\r
605 {\r
606         NDIS_STATUS                     status;\r
607         ib_api_status_t         ib_status;\r
608         UINT                            medium_index;\r
609         ipoib_adapter_t         *p_adapter;\r
610 \r
611         IPOIB_ENTER( IPOIB_DBG_INIT );\r
612 \r
613 #ifdef _DEBUG_\r
614         PAGED_CODE();\r
615 #endif\r
616 \r
617         UNUSED_PARAM( p_open_status );\r
618         UNUSED_PARAM( wrapper_config_context );\r
619 \r
620         /* Search for our medium */\r
621         for( medium_index = 0; medium_index < medium_array_size; ++medium_index )\r
622         {\r
623                 /* Check to see if we found our medium */\r
624                 if( medium_array[medium_index] == NdisMedium802_3 )\r
625                         break;\r
626         }\r
627 \r
628         if( medium_index == medium_array_size ) /* Never found it */\r
629         {\r
630                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR, ("No supported media.\n") );\r
631                 return NDIS_STATUS_UNSUPPORTED_MEDIA;\r
632         }\r
633 \r
634         *p_selected_medium_index = medium_index;\r
635 \r
636         /* Create the adapter adapter */\r
637         ib_status = ipoib_create_adapter( wrapper_config_context, h_adapter, &p_adapter );\r
638         if( ib_status != IB_SUCCESS )\r
639         {\r
640                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR,\r
641                         ("ipoib_create_adapter returned status %d.\n", ib_status ) );\r
642                 return NDIS_STATUS_FAILURE;\r
643         }\r
644 \r
645         /* Allow ten seconds for all SA queries to finish up. */\r
646         NdisMSetAttributesEx( h_adapter, p_adapter, 5,\r
647                 NDIS_ATTRIBUTE_BUS_MASTER | NDIS_ATTRIBUTE_DESERIALIZE |\r
648                 NDIS_ATTRIBUTE_USES_SAFE_BUFFER_APIS,\r
649                 NdisInterfacePNPBus );\r
650 \r
651 #if IPOIB_USE_DMA\r
652         status =\r
653                 NdisMInitializeScatterGatherDma( h_adapter, TRUE, XFER_BLOCK_SIZE );\r
654         if( status != NDIS_STATUS_SUCCESS )\r
655         {\r
656                 ipoib_destroy_adapter( p_adapter );\r
657                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR,\r
658                         ("NdisMInitializeScatterGatherDma returned 0x%.8x.\n", status) );\r
659                 return status;\r
660         }\r
661 #endif\r
662 \r
663         /* Create the adapter adapter */\r
664         ib_status = ipoib_start_adapter( p_adapter );\r
665         if( ib_status != IB_SUCCESS )\r
666         {\r
667                 NdisWriteErrorLogEntry( h_adapter,\r
668                         NDIS_ERROR_CODE_HARDWARE_FAILURE, 0 );\r
669                 ipoib_destroy_adapter( p_adapter );\r
670                 IPOIB_TRACE_EXIT( IPOIB_DBG_ERROR,\r
671                         ("ipoib_start_adapter returned status %d.\n", ib_status ) );\r
672                 return NDIS_STATUS_FAILURE;\r
673         }\r
674 \r
675         ipoib_ref_ibat();\r
676 \r
677         IPOIB_EXIT( IPOIB_DBG_INIT );\r
678         return status;\r
679 }\r
680 \r
681 \r
682 //! Deallocates resources when the NIC is removed and halts the NIC..\r
683 /*  IRQL = DISPATCH_LEVEL\r
684 \r
685 @param adapter_context The adapter context allocated at start\r
686 */\r
687 void\r
688 ipoib_halt(\r
689         IN                              NDIS_HANDLE                                     adapter_context )\r
690 {\r
691         ipoib_adapter_t *p_adapter;\r
692 \r
693         IPOIB_ENTER( IPOIB_DBG_INIT );\r
694 \r
695         ipoib_deref_ibat();\r
696 \r
697         CL_ASSERT( adapter_context );\r
698         p_adapter = (ipoib_adapter_t*)adapter_context;\r
699 \r
700         IPOIB_TRACE( IPOIB_DBG_INIT | IPOIB_DBG_INFO,\r
701                         ("Port %016I64x (CA %016I64x port %d) halting\n",\r
702                         p_adapter->guids.port_guid, p_adapter->guids.ca_guid,\r
703                         p_adapter->guids.port_num) );\r
704 \r
705         ipoib_destroy_adapter( p_adapter );\r
706 \r
707         IPOIB_EXIT( IPOIB_DBG_INIT );\r
708 }\r
709 \r
710 \r
711 //! Reports the state of the NIC, or monitors the responsiveness of an underlying device driver.\r
712 /*  IRQL = DISPATCH_LEVEL\r
713 \r
714 @param adapter_context The adapter context allocated at start\r
715 @return TRUE if the driver determines that its NIC is not operating\r
716 */\r
717 BOOLEAN\r
718 ipoib_check_for_hang(\r
719         IN                              NDIS_HANDLE                                     adapter_context )\r
720 {\r
721         ipoib_adapter_t *p_adapter;\r
722 \r
723         IPOIB_ENTER( IPOIB_DBG_INIT );\r
724         CL_ASSERT( adapter_context );\r
725         p_adapter = (ipoib_adapter_t*)adapter_context;\r
726         IPOIB_EXIT( IPOIB_DBG_INIT );\r
727         return (p_adapter->hung? TRUE:FALSE);\r
728 }\r
729 \r
730 \r
731 //! Returns information about the capabilities and status of the driver and/or its NIC.\r
732 /*  IRQL = DISPATCH_LEVEL\r
733 \r
734 @param adapter_context The adapter context allocated at start\r
735 @param oid Object ID representing the query operation to be carried out\r
736 @param info_buf Buffer containing any input for this query and location for output\r
737 @param info_buf_len Number of bytes available in info_buf\r
738 @param p_bytes_written Pointer to number of bytes written into info_buf\r
739 @param p_bytes_needed Pointer to number of bytes needed to satisfy this oid\r
740 @return NDIS_STATUS_SUCCESS, NDIS_STATUS_PENDING, NDIS_STATUS_INVALID_OID,\r
741 NDIS_STATUS_INVALID_LENGTH, NDIS_STATUS_NOT_ACCEPTED, NDIS_STATUS_NOT_SUPPORTED,\r
742 NDIS_STATUS_RESOURCES\r
743 */\r
744 NDIS_STATUS\r
745 ipoib_query_info(\r
746         IN                              NDIS_HANDLE                                     adapter_context,\r
747         IN                              NDIS_OID                                        oid,\r
748         IN                              PVOID                                           info_buf,\r
749         IN                              ULONG                                           info_buf_len,\r
750                 OUT                     PULONG                                          p_bytes_written,\r
751                 OUT                     PULONG                                          p_bytes_needed )\r
752 {\r
753         ipoib_adapter_t         *p_adapter;\r
754         NDIS_STATUS                     status;\r
755         USHORT                          version;\r
756         ULONG                           info;\r
757         PVOID                           src_buf;\r
758         ULONG                           buf_len;\r
759         pending_oid_t           oid_info;\r
760         uint8_t                         port_num;\r
761 \r
762         IPOIB_ENTER( IPOIB_DBG_OID );\r
763 \r
764         oid_info.oid = oid;\r
765         oid_info.p_buf = info_buf;\r
766         oid_info.buf_len = info_buf_len;\r
767         oid_info.p_bytes_used = p_bytes_written;\r
768         oid_info.p_bytes_needed = p_bytes_needed;\r
769 \r
770         CL_ASSERT( adapter_context );\r
771         p_adapter = (ipoib_adapter_t*)adapter_context;\r
772 \r
773         CL_ASSERT( p_bytes_written );\r
774         CL_ASSERT( p_bytes_needed );\r
775         CL_ASSERT( !p_adapter->pending_query );\r
776 \r
777         status = NDIS_STATUS_SUCCESS;\r
778         src_buf = &info;\r
779         buf_len = sizeof(info);\r
780 \r
781         port_num = p_adapter->guids.port_num;\r
782 \r
783         switch( oid )\r
784         {\r
785         /* Required General */\r
786         case OID_GEN_SUPPORTED_LIST:\r
787                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
788                         ("Port %d received query for OID_GEN_SUPPORTED_LIST\n", port_num) );\r
789                 src_buf = (PVOID)SUPPORTED_OIDS;\r
790                 buf_len = sizeof(SUPPORTED_OIDS);\r
791                 break;\r
792 \r
793         case OID_GEN_HARDWARE_STATUS:\r
794                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
795                         ("Port %d received query for OID_GEN_HARDWARE_STATUS\n", port_num) );\r
796                 cl_obj_lock( &p_adapter->obj );\r
797                 switch( p_adapter->state )\r
798                 {\r
799                 case IB_PNP_PORT_ADD:\r
800                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
801                                 ("Port %d returning NdisHardwareStatusInitializing\n", port_num) );\r
802                         info = NdisHardwareStatusInitializing;\r
803                         break;\r
804                         \r
805                 case IB_PNP_PORT_ACTIVE:\r
806                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
807                                 ("Port %d returning NdisHardwareStatusReady\n", port_num) );\r
808                         info = NdisHardwareStatusReady;\r
809                         break;\r
810 \r
811                 default:\r
812                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
813                                 ("Port %d returning NdisHardwareStatusNotReady\n", port_num) );\r
814                         info = NdisHardwareStatusNotReady;\r
815                 }\r
816                 cl_obj_unlock( &p_adapter->obj );\r
817                 break;\r
818 \r
819         case OID_GEN_MEDIA_SUPPORTED:\r
820         case OID_GEN_MEDIA_IN_USE:\r
821                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
822                         ("Port %d received query for OID_GEN_MEDIA_SUPPORTED "\r
823                         "or OID_GEN_MEDIA_IN_USE\n", port_num) );\r
824                 info = NdisMedium802_3;\r
825                 break;\r
826 \r
827         case OID_GEN_MAXIMUM_FRAME_SIZE:\r
828                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
829                         ("Port %d received query for OID_GEN_MAXIMUM_FRAME_SIZE\n", port_num) );\r
830                 info = PAYLOAD_MTU;\r
831                 break;\r
832 \r
833         case OID_GEN_LINK_SPEED:\r
834                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
835                         ("Port %d received query for OID_GEN_LINK_SPEED\n", port_num) );\r
836                 cl_obj_lock( &p_adapter->obj );\r
837                 switch( p_adapter->state )\r
838                 {\r
839                 case IB_PNP_PORT_ADD:\r
840                         /* Mark the adapter as pending an OID */\r
841                         p_adapter->pending_query = TRUE;\r
842 \r
843                         /* Save the request parameters. */\r
844                         p_adapter->query_oid = oid_info;\r
845 \r
846                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
847                                 ("Port %d returning NDIS_STATUS_PENDING\n", port_num) );\r
848                         status = NDIS_STATUS_PENDING;\r
849                         break;\r
850 \r
851                 case IB_PNP_PORT_REMOVE:\r
852                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
853                                 ("Port %d returning NDIS_STATUS_NOT_ACCEPTED\n", port_num) );\r
854                         status = NDIS_STATUS_NOT_ACCEPTED;\r
855                         break;\r
856 \r
857                 default:\r
858                         CL_ASSERT( p_adapter->p_port );\r
859                         info = p_adapter->rate;\r
860                         break;\r
861                 }\r
862                 cl_obj_unlock( &p_adapter->obj );\r
863                 break;\r
864 \r
865         case OID_GEN_TRANSMIT_BUFFER_SPACE:\r
866                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
867                         ("Port %d received query for OID_GEN_TRANSMIT_BUFFER_SPACE\n", port_num) );\r
868                 info = p_adapter->params.sq_depth * XFER_BLOCK_SIZE;\r
869                 break;\r
870 \r
871         case OID_GEN_RECEIVE_BUFFER_SPACE:\r
872                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
873                         ("Port %d received query for OID_GEN_TRANSMIT_BUFFER_SPACE "\r
874                         "or OID_GEN_RECEIVE_BUFFER_SPACE\n", port_num) );\r
875                 info = p_adapter->params.rq_depth * XFER_BLOCK_SIZE;\r
876                 break;\r
877 \r
878         case OID_GEN_MAXIMUM_LOOKAHEAD:\r
879         case OID_GEN_CURRENT_LOOKAHEAD:\r
880         case OID_GEN_TRANSMIT_BLOCK_SIZE:\r
881         case OID_GEN_RECEIVE_BLOCK_SIZE:\r
882         case OID_GEN_MAXIMUM_TOTAL_SIZE:\r
883                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
884                         ("Port %d received query for OID_GEN_MAXIMUM_LOOKAHEAD "\r
885                         "or OID_GEN_CURRENT_LOOKAHEAD or "\r
886                         "OID_GEN_TRANSMIT_BLOCK_SIZE or "\r
887                         "OID_GEN_RECEIVE_BLOCK_SIZE or "\r
888                         "OID_GEN_MAXIMUM_TOTAL_SIZE\n", port_num) );\r
889                 info = XFER_BLOCK_SIZE;\r
890                 break;\r
891 \r
892         case OID_GEN_VENDOR_ID:\r
893                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
894                         ("Port %d received query for OID_GEN_VENDOR_ID\n", port_num) );\r
895                 src_buf = (void*)VENDOR_ID;\r
896                 buf_len = sizeof(VENDOR_ID);\r
897                 break;\r
898 \r
899         case OID_GEN_VENDOR_DESCRIPTION:\r
900                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO, \r
901                         ("Port %d received query for OID_GEN_VENDOR_DESCRIPTION\n", port_num) );\r
902                 src_buf = VENDOR_DESCRIPTION;\r
903                 buf_len = sizeof(VENDOR_DESCRIPTION);\r
904                 break;\r
905 \r
906         case OID_GEN_VENDOR_DRIVER_VERSION:\r
907                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
908                         ("Port %d received query for OID_GEN_VENDOR_DRIVER_VERSION\n", port_num) );\r
909                 src_buf = &version;\r
910                 buf_len = sizeof(version);\r
911                 //TODO: Figure out what the right version is.\r
912                 version = 1 << 8 | 1;\r
913                 break;\r
914 \r
915         case OID_GEN_PHYSICAL_MEDIUM:\r
916                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
917                         ("Port %d received query for OID_GEN_PHYSICAL_MEDIUM\n", port_num) );\r
918                 info = NdisPhysicalMediumUnspecified;\r
919                 break;\r
920 \r
921         case OID_GEN_CURRENT_PACKET_FILTER:\r
922                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
923                         ("Port %d received query for OID_GEN_CURRENT_PACKET_FILTER\n", port_num) );\r
924                 info = p_adapter->packet_filter;\r
925                 break;\r
926 \r
927         case OID_GEN_DRIVER_VERSION:\r
928                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
929                         ("Port %d received query for OID_GEN_DRIVER_VERSION\n", port_num) );\r
930                 src_buf = &version;\r
931                 buf_len = sizeof(version);\r
932                 version = MAJOR_NDIS_VERSION << 8 | MINOR_NDIS_VERSION;\r
933                 break;\r
934 \r
935         case OID_GEN_MAC_OPTIONS:\r
936                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
937                         ("Port %d received query for OID_GEN_MAC_OPTIONS\n", port_num) );\r
938                 info = NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA |\r
939                         NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |\r
940                         NDIS_MAC_OPTION_NO_LOOPBACK |\r
941                         NDIS_MAC_OPTION_FULL_DUPLEX;\r
942 //TODO: Figure out if we will support priority and VLANs.\r
943 //                              NDIS_MAC_OPTION_8021P_PRIORITY;\r
944 //#ifdef NDIS51_MINIPORT\r
945 //                      info |= NDIS_MAC_OPTION_8021Q_VLAN;\r
946 //#endif\r
947                 break;\r
948 \r
949         case OID_GEN_MEDIA_CONNECT_STATUS:\r
950                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
951                         ("Port %d received query for OID_GEN_MEDIA_CONNECT_STATUS\n", port_num) );\r
952                 cl_obj_lock( &p_adapter->obj );\r
953                 switch( p_adapter->state )\r
954                 {\r
955                 case IB_PNP_PORT_ADD:\r
956                         /*\r
957                          * Delay reporting media state until we know whether the port is\r
958                          * either up or down.\r
959                          */\r
960                         p_adapter->pending_query = TRUE;\r
961                         p_adapter->query_oid = oid_info;\r
962 \r
963                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
964                                 ("Port %d returning NDIS_STATUS_PENDING\n", port_num) );\r
965                         status = NDIS_STATUS_PENDING;\r
966                         break;\r
967 \r
968                 case IB_PNP_PORT_ACTIVE:\r
969                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
970                                 ("Port %d returning NdisMediaStateConnected\n", port_num) );\r
971                         info = NdisMediaStateConnected;\r
972                         break;\r
973 \r
974                 case IB_PNP_PORT_REMOVE:\r
975                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
976                                 ("Port %d returning NDIS_STATUS_NOT_ACCEPTED\n", port_num) );\r
977                         status = NDIS_STATUS_NOT_ACCEPTED;\r
978                         break;\r
979 \r
980                 default:\r
981                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
982                                 ("Port %d returning NdisMediaStateDisconnected\n", port_num) );\r
983                         info = NdisMediaStateDisconnected;\r
984                 }\r
985                 cl_obj_unlock( &p_adapter->obj );\r
986                 break;\r
987 \r
988         case OID_GEN_MAXIMUM_SEND_PACKETS:\r
989                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
990                         ("Port %d received query for OID_GEN_MAXIMUM_SEND_PACKETS\n", port_num) );\r
991                 info = MAXULONG;\r
992                 break;\r
993 \r
994         /* Required General Statistics */\r
995         case OID_GEN_XMIT_OK:\r
996                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
997                         ("Port %d received query for OID_GEN_XMIT_OK\n", port_num) );\r
998                 src_buf = NULL;\r
999                 status = ipoib_get_send_stat( p_adapter, IP_STAT_SUCCESS, &oid_info );\r
1000                 break;\r
1001 \r
1002         case OID_GEN_RCV_OK:\r
1003                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1004                         ("Port %d received query for OID_GEN_RCV_OK\n", port_num) );\r
1005                 src_buf = NULL;\r
1006                 status = ipoib_get_recv_stat( p_adapter, IP_STAT_SUCCESS, &oid_info );\r
1007                 break;\r
1008 \r
1009         case OID_GEN_XMIT_ERROR:\r
1010                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1011                         ("Port %d received query for OID_GEN_XMIT_ERROR\n", port_num) );\r
1012                 src_buf = NULL;\r
1013                 status = ipoib_get_send_stat( p_adapter, IP_STAT_ERROR, &oid_info );\r
1014                 break;\r
1015 \r
1016         case OID_GEN_RCV_ERROR:\r
1017                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1018                         ("Port %d received query for OID_GEN_RCV_ERROR\n", port_num) );\r
1019                 src_buf = NULL;\r
1020                 status = ipoib_get_recv_stat( p_adapter, IP_STAT_ERROR, &oid_info );\r
1021                 break;\r
1022 \r
1023         case OID_GEN_RCV_NO_BUFFER:\r
1024                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1025                         ("Port %d received query for OID_GEN_RCV_NO_BUFFER\n", port_num) );\r
1026                 src_buf = NULL;\r
1027                 status = ipoib_get_recv_stat( p_adapter, IP_STAT_DROPPED, &oid_info );\r
1028                 break;\r
1029 \r
1030         case OID_GEN_DIRECTED_BYTES_XMIT:\r
1031                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1032                         ("Port %d received query for OID_GEN_DIRECTED_BYTES_XMIT\n", port_num) );\r
1033                 src_buf = NULL;\r
1034                 status = ipoib_get_send_stat( p_adapter, IP_STAT_UCAST_BYTES, &oid_info );\r
1035                 break;\r
1036 \r
1037         case OID_GEN_DIRECTED_FRAMES_XMIT:\r
1038                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1039                         ("Port %d received query for OID_GEN_DIRECTED_FRAMES_XMIT\n", port_num) );\r
1040                 src_buf = NULL;\r
1041                 status = ipoib_get_send_stat( p_adapter, IP_STAT_UCAST_FRAMES, &oid_info );\r
1042                 break;\r
1043 \r
1044         case OID_GEN_MULTICAST_BYTES_XMIT:\r
1045                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1046                         ("Port %d received query for OID_GEN_MULTICAST_BYTES_XMIT\n", port_num) );\r
1047                 src_buf = NULL;\r
1048                 status = ipoib_get_send_stat( p_adapter, IP_STAT_MCAST_BYTES, &oid_info );\r
1049                 break;\r
1050 \r
1051         case OID_GEN_MULTICAST_FRAMES_XMIT:\r
1052                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1053                         ("Port %d received query for OID_GEN_MULTICAST_FRAMES_XMIT\n", port_num) );\r
1054                 src_buf = NULL;\r
1055                 status = ipoib_get_send_stat( p_adapter, IP_STAT_MCAST_FRAMES, &oid_info );\r
1056                 break;\r
1057 \r
1058         case OID_GEN_BROADCAST_BYTES_XMIT:\r
1059                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1060                         ("Port %d received query for OID_GEN_BROADCAST_BYTES_XMIT\n", port_num) );\r
1061                 src_buf = NULL;\r
1062                 status = ipoib_get_send_stat( p_adapter, IP_STAT_BCAST_BYTES, &oid_info );\r
1063                 break;\r
1064 \r
1065         case OID_GEN_BROADCAST_FRAMES_XMIT:\r
1066                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1067                         ("Port %d received query for OID_GEN_BROADCAST_FRAMES_XMIT\n", port_num) );\r
1068                 src_buf = NULL;\r
1069                 status = ipoib_get_send_stat( p_adapter, IP_STAT_BCAST_FRAMES, &oid_info );\r
1070                 break;\r
1071 \r
1072         case OID_GEN_DIRECTED_BYTES_RCV:\r
1073                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1074                         ("Port %d received query for OID_GEN_DIRECTED_BYTES_RCV\n", port_num) );\r
1075                 src_buf = NULL;\r
1076                 status = ipoib_get_recv_stat( p_adapter, IP_STAT_UCAST_BYTES, &oid_info );\r
1077                 break;\r
1078 \r
1079         case OID_GEN_DIRECTED_FRAMES_RCV:\r
1080                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1081                         ("Port %d received query for OID_GEN_DIRECTED_FRAMES_RCV\n", port_num) );\r
1082                 src_buf = NULL;\r
1083                 status = ipoib_get_recv_stat( p_adapter, IP_STAT_UCAST_FRAMES, &oid_info );\r
1084                 break;\r
1085 \r
1086         case OID_GEN_MULTICAST_BYTES_RCV:\r
1087                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1088                         ("Port %d received query for OID_GEN_MULTICAST_BYTES_RCV\n", port_num) );\r
1089                 src_buf = NULL;\r
1090                 status = ipoib_get_recv_stat( p_adapter, IP_STAT_MCAST_BYTES, &oid_info );\r
1091                 break;\r
1092 \r
1093         case OID_GEN_MULTICAST_FRAMES_RCV:\r
1094                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1095                         ("Port %d received query for OID_GEN_MULTICAST_FRAMES_RCV\n", port_num) );\r
1096                 src_buf = NULL;\r
1097                 status = ipoib_get_recv_stat( p_adapter, IP_STAT_MCAST_FRAMES, &oid_info );\r
1098                 break;\r
1099 \r
1100         case OID_GEN_BROADCAST_BYTES_RCV:\r
1101                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1102                         ("Port %d received query for OID_GEN_BROADCAST_BYTES_RCV\n", port_num) );\r
1103                 src_buf = NULL;\r
1104                 status = ipoib_get_recv_stat( p_adapter, IP_STAT_BCAST_BYTES, &oid_info );\r
1105                 break;\r
1106 \r
1107         case OID_GEN_BROADCAST_FRAMES_RCV:\r
1108                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1109                         ("Port %d received query for OID_GEN_BROADCAST_FRAMES_RCV\n", port_num) );\r
1110                 src_buf = NULL;\r
1111                 status = ipoib_get_recv_stat( p_adapter, IP_STAT_BCAST_FRAMES, &oid_info );\r
1112                 break;\r
1113 \r
1114         /* Required Ethernet operational characteristics */\r
1115         case OID_802_3_PERMANENT_ADDRESS:\r
1116         case OID_802_3_CURRENT_ADDRESS:\r
1117 #if defined( _DEBUG_ )\r
1118                 if( oid == OID_802_3_PERMANENT_ADDRESS )\r
1119                 {\r
1120                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1121                                 ("Port %d received query for OID_802_3_PERMANENT_ADDRESS\n", port_num) );\r
1122                 }\r
1123                 else\r
1124                 {\r
1125                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1126                                 ("Port %d received query for OID_802_3_CURRENT_ADDRESS\n", port_num) );\r
1127                 }\r
1128 #endif  /* defined( _DEBUG_ )*/\r
1129                 src_buf = &p_adapter->mac;\r
1130                 buf_len = sizeof(p_adapter->mac);\r
1131                 break;\r
1132 \r
1133         case OID_802_3_MULTICAST_LIST:\r
1134                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1135                         ("Port %d received query for OID_802_3_MULTICAST_LIST\n", port_num) );\r
1136                 src_buf = p_adapter->mcast_array;\r
1137                 buf_len = p_adapter->mcast_array_size * sizeof(mac_addr_t);\r
1138                 break;\r
1139 \r
1140         case OID_802_3_MAXIMUM_LIST_SIZE:\r
1141                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1142                         ("Port %d received query for OID_802_3_MAXIMUM_LIST_SIZE\n", port_num) );\r
1143                 info = MAX_MCAST;\r
1144                 break;\r
1145 \r
1146         case OID_802_3_MAC_OPTIONS:\r
1147                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1148                         ("Port %d received query for OID_802_3_MAC_OPTIONS\n", port_num) );\r
1149                 info = 0;\r
1150                 break;\r
1151 \r
1152         /* Required Ethernet stats */\r
1153         case OID_802_3_RCV_ERROR_ALIGNMENT:\r
1154         case OID_802_3_XMIT_ONE_COLLISION:\r
1155         case OID_802_3_XMIT_MORE_COLLISIONS:\r
1156                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1157                         ("Port %d received query for OID_802_3_RCV_ERROR_ALIGNMENT or "\r
1158                         "OID_802_3_XMIT_ONE_COLLISION or "\r
1159                         "OID_802_3_XMIT_MORE_COLLISIONS\n", port_num) );\r
1160                 info = 0;\r
1161                 break;\r
1162 \r
1163         case OID_TCP_TASK_OFFLOAD:\r
1164                 src_buf = NULL;\r
1165                 status = __ipoib_get_tcp_task_offload( p_adapter, &oid_info );\r
1166                 break;\r
1167 \r
1168         /* Optional General */\r
1169         case OID_GEN_SUPPORTED_GUIDS:\r
1170 #ifdef NDIS51_MINIPORT\r
1171         case OID_GEN_VLAN_ID:\r
1172 #endif\r
1173 \r
1174         /* Optional General Stats */\r
1175         case OID_GEN_RCV_CRC_ERROR:\r
1176         case OID_GEN_TRANSMIT_QUEUE_LENGTH:\r
1177 \r
1178         /* Optional Ethernet Stats */\r
1179         case OID_802_3_XMIT_DEFERRED:\r
1180         case OID_802_3_XMIT_MAX_COLLISIONS:\r
1181         case OID_802_3_RCV_OVERRUN:\r
1182         case OID_802_3_XMIT_UNDERRUN:\r
1183         case OID_802_3_XMIT_HEARTBEAT_FAILURE:\r
1184         case OID_802_3_XMIT_TIMES_CRS_LOST:\r
1185         case OID_802_3_XMIT_LATE_COLLISIONS:\r
1186         case OID_PNP_CAPABILITIES:\r
1187                 status = NDIS_STATUS_NOT_SUPPORTED;\r
1188                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1189                         ("Port %d received an unsupported oid of 0x%.8X!\n", port_num, oid) );\r
1190                 break;\r
1191 \r
1192         case OID_GEN_PROTOCOL_OPTIONS:\r
1193         case OID_GEN_NETWORK_LAYER_ADDRESSES:\r
1194         case OID_GEN_TRANSPORT_HEADER_OFFSET:\r
1195 #ifdef NDIS51_MINIPORT\r
1196         case OID_GEN_MACHINE_NAME:\r
1197         case OID_GEN_RNDIS_CONFIG_PARAMETER:\r
1198 #endif\r
1199         default:\r
1200                 status = NDIS_STATUS_INVALID_OID;\r
1201                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1202                         ("Port %d received an invalid oid of 0x%.8X!\n", port_num, oid) );\r
1203                 break;\r
1204         }\r
1205 \r
1206         /*\r
1207          * Complete the request as if it was handled asynchronously to maximize\r
1208          * code reuse for when we really handle the requests asynchronously.\r
1209          * Note that this requires the QueryInformation entry point to always\r
1210          * return NDIS_STATUS_PENDING\r
1211          */\r
1212         if( status != NDIS_STATUS_PENDING )\r
1213         {\r
1214                 ipoib_complete_query(\r
1215                         p_adapter, &oid_info, status, src_buf, buf_len );\r
1216         }\r
1217 \r
1218         IPOIB_EXIT( IPOIB_DBG_OID );\r
1219         return NDIS_STATUS_PENDING;\r
1220 }\r
1221 \r
1222 \r
1223 static void\r
1224 ipoib_complete_query(\r
1225         IN                              ipoib_adapter_t* const          p_adapter,\r
1226         IN                              pending_oid_t* const            p_oid_info,\r
1227         IN              const   NDIS_STATUS                                     status,\r
1228         IN              const   void* const                                     p_buf,\r
1229         IN              const   ULONG                                           buf_len )\r
1230 {\r
1231         NDIS_STATUS             oid_status = status;\r
1232 \r
1233         IPOIB_ENTER( IPOIB_DBG_OID );\r
1234 \r
1235         CL_ASSERT( status != NDIS_STATUS_PENDING );\r
1236 \r
1237         if( status == NDIS_STATUS_SUCCESS )\r
1238         {\r
1239                 if( p_oid_info->buf_len < buf_len )\r
1240                 {\r
1241                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1242                                 ("Insufficient buffer space.  "\r
1243                                 "Returning NDIS_STATUS_INVALID_LENGTH.\n") );\r
1244                         oid_status = NDIS_STATUS_INVALID_LENGTH;\r
1245                         *p_oid_info->p_bytes_needed = buf_len;\r
1246                         *p_oid_info->p_bytes_used = 0;\r
1247                 }\r
1248                 else if( p_oid_info->p_buf )\r
1249                 {\r
1250                         /* Only copy if we have a distinct source buffer. */\r
1251                         if( p_buf )\r
1252                         {\r
1253                                 NdisMoveMemory( p_oid_info->p_buf, p_buf, buf_len );\r
1254                                 *p_oid_info->p_bytes_used = buf_len;\r
1255                         }\r
1256                 }\r
1257                 else\r
1258                 {\r
1259                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1260                                 ("Returning NDIS_NOT_ACCEPTED") );\r
1261                         oid_status = NDIS_STATUS_NOT_ACCEPTED;\r
1262                 }\r
1263         }\r
1264         else\r
1265         {\r
1266                 *p_oid_info->p_bytes_used = 0;\r
1267         }\r
1268 \r
1269         p_adapter->pending_query = FALSE;\r
1270 \r
1271         NdisMQueryInformationComplete( p_adapter->h_adapter, oid_status );\r
1272 \r
1273         IPOIB_EXIT( IPOIB_DBG_OID );\r
1274 }\r
1275 \r
1276 \r
1277 static NDIS_STATUS\r
1278 __ipoib_get_tcp_task_offload(\r
1279         IN                              ipoib_adapter_t*                        p_adapter,\r
1280         IN                              pending_oid_t* const            p_oid_info )\r
1281 {\r
1282         NDIS_TASK_OFFLOAD_HEADER        *p_offload_hdr;\r
1283         NDIS_TASK_OFFLOAD                       *p_offload_task;\r
1284         NDIS_TASK_TCP_IP_CHECKSUM       *p_offload_chksum;\r
1285         ULONG                                           buf_len;\r
1286 \r
1287         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1288                 ("Port %d received query for OID_TCP_TASK_OFFLOAD\n",\r
1289                 p_adapter->guids.port_num) );\r
1290 \r
1291         buf_len = sizeof(NDIS_TASK_OFFLOAD_HEADER) +\r
1292                 sizeof(NDIS_TASK_OFFLOAD) +\r
1293                 sizeof(NDIS_TASK_TCP_IP_CHECKSUM) - 1;\r
1294 \r
1295         *(p_oid_info->p_bytes_needed) = buf_len;\r
1296 \r
1297         if( p_oid_info->buf_len < buf_len )\r
1298                 return NDIS_STATUS_INVALID_LENGTH;\r
1299 \r
1300         p_offload_hdr = (NDIS_TASK_OFFLOAD_HEADER*)p_oid_info->p_buf;\r
1301         if( p_offload_hdr->Version != NDIS_TASK_OFFLOAD_VERSION )\r
1302                 return NDIS_STATUS_INVALID_DATA;\r
1303 \r
1304         if( p_offload_hdr->EncapsulationFormat.Encapsulation !=\r
1305                 IEEE_802_3_Encapsulation )\r
1306         {\r
1307                 return NDIS_STATUS_INVALID_DATA;\r
1308         }\r
1309 \r
1310         p_offload_hdr->OffsetFirstTask = sizeof(NDIS_TASK_OFFLOAD_HEADER);\r
1311         p_offload_task = (NDIS_TASK_OFFLOAD*)(p_offload_hdr + 1);\r
1312         p_offload_task->Version = NDIS_TASK_OFFLOAD_VERSION;\r
1313         p_offload_task->Size = sizeof(NDIS_TASK_OFFLOAD);\r
1314         p_offload_task->Task = TcpIpChecksumNdisTask;\r
1315         p_offload_task->OffsetNextTask = 0;\r
1316         p_offload_task->TaskBufferLength = sizeof(NDIS_TASK_TCP_IP_CHECKSUM);\r
1317         p_offload_chksum =\r
1318                 (NDIS_TASK_TCP_IP_CHECKSUM*)p_offload_task->TaskBuffer;\r
1319 \r
1320         p_offload_chksum->V4Transmit.IpOptionsSupported =\r
1321                 p_adapter->params.send_chksum_offload;\r
1322         p_offload_chksum->V4Transmit.TcpOptionsSupported =\r
1323                 p_adapter->params.send_chksum_offload;\r
1324         p_offload_chksum->V4Transmit.TcpChecksum =\r
1325                 p_adapter->params.send_chksum_offload;\r
1326         p_offload_chksum->V4Transmit.UdpChecksum =\r
1327                 p_adapter->params.send_chksum_offload;\r
1328         p_offload_chksum->V4Transmit.IpChecksum =\r
1329                 p_adapter->params.send_chksum_offload;\r
1330 \r
1331         /*\r
1332          * Only receive checksum can be offloaded thanks to\r
1333          * the IB physical layer.\r
1334          */\r
1335         p_offload_chksum->V4Receive.IpOptionsSupported = TRUE;\r
1336         p_offload_chksum->V4Receive.TcpOptionsSupported = TRUE;\r
1337         p_offload_chksum->V4Receive.TcpChecksum = TRUE;\r
1338         p_offload_chksum->V4Receive.UdpChecksum = TRUE;\r
1339         p_offload_chksum->V4Receive.IpChecksum = TRUE;\r
1340 \r
1341         p_offload_chksum->V6Transmit.IpOptionsSupported = FALSE;\r
1342         p_offload_chksum->V6Transmit.TcpOptionsSupported = FALSE;\r
1343         p_offload_chksum->V6Transmit.TcpChecksum = FALSE;\r
1344         p_offload_chksum->V6Transmit.UdpChecksum = FALSE;\r
1345 \r
1346         p_offload_chksum->V6Receive.IpOptionsSupported = FALSE;\r
1347         p_offload_chksum->V6Receive.TcpOptionsSupported = FALSE;\r
1348         p_offload_chksum->V6Receive.TcpChecksum = FALSE;\r
1349         p_offload_chksum->V6Receive.UdpChecksum = FALSE;\r
1350 \r
1351         *(p_oid_info->p_bytes_used) = buf_len;\r
1352 \r
1353         return NDIS_STATUS_SUCCESS;\r
1354 }\r
1355 \r
1356 \r
1357 //! Issues a hardware reset to the NIC and/or resets the driver's software state.\r
1358 /*  Tear down the connection and start over again.  This is only called when there is a problem.\r
1359 For example, if a send, query info, or set info had a time out.  MiniportCheckForHang will\r
1360 be called first.\r
1361 IRQL = DISPATCH_LEVEL\r
1362 \r
1363 @param p_addr_resetPointer to BOOLLEAN that is set to TRUE if the NDIS\r
1364 library should call MiniportSetInformation to restore addressing information to the current values.\r
1365 @param adapter_context The adapter context allocated at start\r
1366 @return NDIS_STATUS_SUCCESS, NDIS_STATUS_PENDING, NDIS_STATUS_NOT_RESETTABLE,\r
1367 NDIS_STATUS_RESET_IN_PROGRESS, NDIS_STATUS_SOFT_ERRORS, NDIS_STATUS_HARD_ERRORS\r
1368 */\r
1369 NDIS_STATUS\r
1370 ipoib_reset(\r
1371                 OUT                     PBOOLEAN                                        p_addr_reset,\r
1372         IN                              NDIS_HANDLE                                     adapter_context)\r
1373 {\r
1374         ipoib_adapter_t* p_adapter;\r
1375 \r
1376         IPOIB_ENTER( IPOIB_DBG_INIT );\r
1377 \r
1378         CL_ASSERT( p_addr_reset );\r
1379         CL_ASSERT( adapter_context );\r
1380         p_adapter = (ipoib_adapter_t*)adapter_context;\r
1381 \r
1382         switch( ipoib_reset_adapter( p_adapter ) )\r
1383         {\r
1384         case IB_NOT_DONE:\r
1385                 IPOIB_EXIT( IPOIB_DBG_INIT );\r
1386                 return NDIS_STATUS_PENDING;\r
1387 \r
1388         case IB_SUCCESS:\r
1389                 IPOIB_EXIT( IPOIB_DBG_INIT );\r
1390                 *p_addr_reset = TRUE;\r
1391                 return NDIS_STATUS_SUCCESS;\r
1392 \r
1393         default:\r
1394                 IPOIB_EXIT( IPOIB_DBG_INIT );\r
1395                 return NDIS_STATUS_HARD_ERRORS;\r
1396         }\r
1397 }\r
1398 \r
1399 \r
1400 //! Request changes in the state information that the miniport driver maintains\r
1401 /*  For example, this is used to set multicast addresses and the packet filter.\r
1402 IRQL = DISPATCH_LEVEL\r
1403 \r
1404 @param adapter_context The adapter context allocated at start\r
1405 @param oid Object ID representing the set operation to be carried out\r
1406 @param info_buf Buffer containing input for this set and location for any output\r
1407 @param info_buf_len Number of bytes available in info_buf\r
1408 @param p_bytes_read Pointer to number of bytes read from info_buf\r
1409 @param p_bytes_needed Pointer to number of bytes needed to satisfy this oid\r
1410 @return NDIS_STATUS_SUCCESS, NDIS_STATUS_PENDING, NDIS_STATUS_INVALID_OID,\r
1411 NDIS_STATUS_INVALID_LENGTH, NDIS_STATUS_INVALID_DATA, NDIS_STATUS_NOT_ACCEPTED,\r
1412 NDIS_STATUS_NOT_SUPPORTED, NDIS_STATUS_RESOURCES\r
1413 */\r
1414 NDIS_STATUS\r
1415 ipoib_set_info(\r
1416         IN                              NDIS_HANDLE                                     adapter_context,\r
1417         IN                              NDIS_OID                                        oid,\r
1418         IN                              PVOID                                           info_buf,\r
1419         IN                              ULONG                                           info_buf_len,\r
1420                 OUT                     PULONG                                          p_bytes_read,\r
1421                 OUT                     PULONG                                          p_bytes_needed )\r
1422 {\r
1423         ipoib_adapter_t*        p_adapter;\r
1424         NDIS_STATUS                     status;\r
1425 \r
1426         ULONG                           buf_len;\r
1427         uint8_t                         port_num;\r
1428 \r
1429         KLOCK_QUEUE_HANDLE      hdl;\r
1430         \r
1431         IPOIB_ENTER( IPOIB_DBG_OID );\r
1432 \r
1433         CL_ASSERT( adapter_context );\r
1434         p_adapter = (ipoib_adapter_t*)adapter_context;\r
1435 \r
1436         CL_ASSERT( p_bytes_read );\r
1437         CL_ASSERT( p_bytes_needed );\r
1438         CL_ASSERT( !p_adapter->pending_set );\r
1439 \r
1440         status = NDIS_STATUS_SUCCESS;\r
1441         *p_bytes_needed = 0;\r
1442         buf_len = sizeof(ULONG);\r
1443 \r
1444         port_num = p_adapter->guids.port_num;\r
1445 \r
1446         switch( oid )\r
1447         {\r
1448         /* Required General */\r
1449         case OID_GEN_CURRENT_PACKET_FILTER:\r
1450                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1451                         ("Port %d received set for OID_GEN_CURRENT_PACKET_FILTER\n", port_num));\r
1452                 if( info_buf_len < sizeof(p_adapter->packet_filter) )\r
1453                 {\r
1454                         status = NDIS_STATUS_INVALID_LENGTH;\r
1455                 }\r
1456                 else if( !info_buf )\r
1457                 {\r
1458                         status = NDIS_STATUS_INVALID_DATA;\r
1459                 }\r
1460                 else\r
1461                 {\r
1462                         KeAcquireInStackQueuedSpinLock( &g_ipoib.lock, &hdl );\r
1463                         cl_obj_lock( &p_adapter->obj );\r
1464                         switch( p_adapter->state )\r
1465                         {\r
1466                         case IB_PNP_PORT_ADD:\r
1467                                 p_adapter->set_oid.oid = oid;\r
1468                                 p_adapter->set_oid.p_buf = info_buf;\r
1469                                 p_adapter->set_oid.buf_len = info_buf_len;\r
1470                                 p_adapter->set_oid.p_bytes_used = p_bytes_read;\r
1471                                 p_adapter->set_oid.p_bytes_needed = p_bytes_needed;\r
1472                                 p_adapter->pending_set = TRUE;\r
1473                                 status = NDIS_STATUS_PENDING;\r
1474                                 break;\r
1475 \r
1476                         case IB_PNP_PORT_REMOVE:\r
1477                                 status = NDIS_STATUS_NOT_ACCEPTED;\r
1478                                 break;\r
1479 \r
1480                         default:\r
1481                                 if( !p_adapter->packet_filter && (*(uint32_t*)info_buf) )\r
1482                                 {\r
1483                                         cl_qlist_insert_tail(\r
1484                                                 &g_ipoib.adapter_list, &p_adapter->entry );\r
1485 \r
1486                                         /*\r
1487                                          * Filter was zero, now non-zero.  Register IP addresses\r
1488                                          * with SA.\r
1489                                          */\r
1490                                         ipoib_reg_addrs( p_adapter );\r
1491                                 }\r
1492                                 else if( p_adapter->packet_filter && !(*(uint32_t*)info_buf) )\r
1493                                 {\r
1494                                         /*\r
1495                                          * Filter was non-zero, now zero.  Deregister IP addresses.\r
1496                                          */\r
1497                                         ipoib_dereg_addrs( p_adapter );\r
1498 \r
1499                                         ASSERT( cl_qlist_count( &g_ipoib.adapter_list ) );\r
1500                                         cl_qlist_remove_item(\r
1501                                                 &g_ipoib.adapter_list, &p_adapter->entry );\r
1502                                 }\r
1503 \r
1504                                 p_adapter->packet_filter = *(uint32_t*)info_buf;\r
1505                         }\r
1506                         cl_obj_unlock( &p_adapter->obj );\r
1507                         KeReleaseInStackQueuedSpinLock( &hdl );\r
1508                 }\r
1509                 break;\r
1510 \r
1511         case OID_GEN_CURRENT_LOOKAHEAD:\r
1512                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1513                         ("Port %d received set for OID_GEN_CURRENT_LOOKAHEAD\n", port_num));\r
1514                 if( info_buf_len < buf_len )\r
1515                         status = NDIS_STATUS_INVALID_LENGTH;\r
1516                 break;\r
1517 \r
1518         case OID_GEN_PROTOCOL_OPTIONS:\r
1519                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1520                         ("Port %d received set for OID_GEN_PROTOCOL_OPTIONS\n", port_num));\r
1521                 if( info_buf_len < buf_len )\r
1522                         status = NDIS_STATUS_INVALID_LENGTH;\r
1523                 break;\r
1524 \r
1525         case OID_GEN_NETWORK_LAYER_ADDRESSES:\r
1526                 status = __ipoib_set_net_addr( p_adapter, info_buf, info_buf_len, p_bytes_read, p_bytes_needed);\r
1527                 break;\r
1528 \r
1529 #ifdef NDIS51_MINIPORT\r
1530         case OID_GEN_MACHINE_NAME:\r
1531                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1532                         ("Port %d received set for OID_GEN_MACHINE_NAME\n", port_num) );\r
1533                 break;\r
1534 #endif\r
1535 \r
1536         /* Required Ethernet operational characteristics */\r
1537         case OID_802_3_MULTICAST_LIST:\r
1538                 IPOIB_TRACE( IPOIB_DBG_OID,\r
1539                         ("Port %d received set for OID_802_3_MULTICAST_LIST\n", port_num) );\r
1540                 if( info_buf_len > MAX_MCAST * sizeof(mac_addr_t) )\r
1541                 {\r
1542                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1543                                 ("Port %d OID_802_3_MULTICAST_LIST - Multicast list full.\n", port_num) );\r
1544                         status = NDIS_STATUS_MULTICAST_FULL;\r
1545                         *p_bytes_needed = MAX_MCAST * sizeof(mac_addr_t);\r
1546                 }\r
1547                 else if( info_buf_len % sizeof(mac_addr_t) )\r
1548                 {\r
1549                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1550                                 ("Port %d OID_802_3_MULTICAST_LIST - Invalid input buffer.\n", port_num) );\r
1551                         status = NDIS_STATUS_INVALID_DATA;\r
1552                 }\r
1553                 else if( !info_buf && info_buf_len )\r
1554                 {\r
1555                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1556                                 ("Port %d OID_802_3_MULTICAST_LIST - Invalid input buffer.\n", port_num) );\r
1557                         status = NDIS_STATUS_INVALID_DATA;\r
1558                 }\r
1559                 else\r
1560                 {\r
1561                         ipoib_refresh_mcast( p_adapter, (mac_addr_t*)info_buf,\r
1562                                 (uint8_t)(info_buf_len / sizeof(mac_addr_t)) );\r
1563 \r
1564                         buf_len = info_buf_len;\r
1565                         /*\r
1566                          * Note that we don't return pending.  It will likely take longer\r
1567                          * for our SA transactions to complete than NDIS will give us\r
1568                          * before reseting the adapter.  If an SA failure is encountered,\r
1569                          * the adapter will be marked as hung and we will get reset.\r
1570                          */\r
1571                         status = NDIS_STATUS_SUCCESS;\r
1572                 }\r
1573                 break;\r
1574 \r
1575         case OID_TCP_TASK_OFFLOAD:\r
1576                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1577                         ("Port %d received set for OID_TCP_TASK_OFFLOAD\n", port_num) );\r
1578                 /* TODO: See if we need to handle this OID, or if just setting the\r
1579                 * checksum OK flags in the packets always works. */\r
1580                 break;\r
1581 \r
1582         /* Optional General */\r
1583         case OID_GEN_TRANSPORT_HEADER_OFFSET:\r
1584 #ifdef NDIS51_MINIPORT\r
1585         case OID_GEN_RNDIS_CONFIG_PARAMETER:\r
1586         case OID_GEN_VLAN_ID:\r
1587 #endif\r
1588                 status = NDIS_STATUS_NOT_SUPPORTED;\r
1589                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1590                         ("Port %d received an unsupported oid of 0x%.8X!\n", port_num, oid));\r
1591                 break;\r
1592 \r
1593         case OID_GEN_SUPPORTED_LIST:\r
1594         case OID_GEN_HARDWARE_STATUS:\r
1595         case OID_GEN_MEDIA_SUPPORTED:\r
1596         case OID_GEN_MEDIA_IN_USE:\r
1597         case OID_GEN_MAXIMUM_FRAME_SIZE:\r
1598         case OID_GEN_LINK_SPEED:\r
1599         case OID_GEN_TRANSMIT_BUFFER_SPACE:\r
1600         case OID_GEN_RECEIVE_BUFFER_SPACE:\r
1601         case OID_GEN_MAXIMUM_LOOKAHEAD:\r
1602         case OID_GEN_TRANSMIT_BLOCK_SIZE:\r
1603         case OID_GEN_RECEIVE_BLOCK_SIZE:\r
1604         case OID_GEN_MAXIMUM_TOTAL_SIZE:\r
1605         case OID_GEN_VENDOR_ID:\r
1606         case OID_GEN_VENDOR_DESCRIPTION:\r
1607         case OID_GEN_VENDOR_DRIVER_VERSION:\r
1608         case OID_GEN_DRIVER_VERSION:\r
1609         case OID_GEN_MAC_OPTIONS:\r
1610         case OID_GEN_MEDIA_CONNECT_STATUS:\r
1611         case OID_GEN_MAXIMUM_SEND_PACKETS:\r
1612         case OID_GEN_SUPPORTED_GUIDS:\r
1613         case OID_GEN_PHYSICAL_MEDIUM:\r
1614         default:\r
1615                 status = NDIS_STATUS_INVALID_OID;\r
1616                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1617                         ("Port %d received an invalid oid of 0x%.8X!\n", port_num, oid));\r
1618                 break;\r
1619         }\r
1620 \r
1621         if( status == NDIS_STATUS_SUCCESS )\r
1622         {\r
1623                 *p_bytes_read = buf_len;\r
1624         }\r
1625         else\r
1626         {\r
1627                 if( status == NDIS_STATUS_INVALID_LENGTH )\r
1628                 {\r
1629                         if ( !*p_bytes_needed )\r
1630                         {\r
1631                                 *p_bytes_needed = buf_len;\r
1632                         }\r
1633                 }\r
1634 \r
1635                 *p_bytes_read = 0;\r
1636         }\r
1637 \r
1638         IPOIB_EXIT( IPOIB_DBG_OID );\r
1639         return status;\r
1640 }\r
1641 \r
1642 \r
1643 //! Transfers some number of packets, specified as an array of packet pointers, over the network. \r
1644 /*  For a deserialized driver, these packets are completed asynchronously\r
1645 using NdisMSendComplete.\r
1646 IRQL <= DISPATCH_LEVEL\r
1647 \r
1648 @param adapter_context Pointer to ipoib_adapter_t structure with per NIC state\r
1649 @param packet_array Array of packets to send\r
1650 @param numPackets Number of packets in the array\r
1651 */\r
1652 void\r
1653 ipoib_send_packets(\r
1654         IN                              NDIS_HANDLE                                     adapter_context,\r
1655         IN                              PPNDIS_PACKET                           packet_array,\r
1656         IN                              UINT                                            num_packets )\r
1657 {\r
1658         ipoib_adapter_t         *p_adapter;\r
1659         ipoib_port_t            *p_port;\r
1660         UINT                            packet_num;\r
1661         PERF_DECLARE( SendPackets );\r
1662         PERF_DECLARE( PortSend );\r
1663 \r
1664         IPOIB_ENTER( IPOIB_DBG_SEND );\r
1665 \r
1666         cl_perf_start( SendPackets );\r
1667 \r
1668         CL_ASSERT( adapter_context );\r
1669         p_adapter = (ipoib_adapter_t*)adapter_context;\r
1670 \r
1671         cl_obj_lock( &p_adapter->obj );\r
1672         if( p_adapter->state != IB_PNP_PORT_ACTIVE || !p_adapter->p_port )\r
1673         {\r
1674                 cl_obj_unlock( &p_adapter->obj );\r
1675                 for( packet_num = 0; packet_num < num_packets; ++packet_num )\r
1676                 {\r
1677                         ipoib_inc_send_stat( p_adapter, IP_STAT_DROPPED, 0 );\r
1678                         NdisMSendComplete( p_adapter->h_adapter,\r
1679                                 packet_array[packet_num], NDIS_STATUS_ADAPTER_NOT_READY );\r
1680                 }\r
1681                 IPOIB_EXIT( IPOIB_DBG_SEND );\r
1682                 return;\r
1683         }\r
1684 \r
1685         p_port = p_adapter->p_port;\r
1686         cl_obj_ref( &p_port->obj );\r
1687         cl_obj_unlock( &p_adapter->obj );\r
1688 \r
1689         cl_perf_start( PortSend );\r
1690         ipoib_port_send( p_port, packet_array, num_packets );\r
1691         cl_perf_stop( &p_port->p_adapter->perf, PortSend );\r
1692         cl_obj_deref( &p_port->obj );\r
1693 \r
1694         cl_perf_stop( &p_adapter->perf, SendPackets );\r
1695 \r
1696         cl_perf_log( &p_adapter->perf, SendBundle, num_packets );\r
1697 \r
1698         IPOIB_EXIT( IPOIB_DBG_SEND );\r
1699 }\r
1700 \r
1701 \r
1702 void\r
1703 ipoib_pnp_notify(\r
1704         IN                              NDIS_HANDLE                                     adapter_context,\r
1705         IN                              NDIS_DEVICE_PNP_EVENT           pnp_event,\r
1706         IN                              PVOID                                           info_buf,\r
1707         IN                              ULONG                                           info_buf_len )\r
1708 {\r
1709         ipoib_adapter_t *p_adapter;\r
1710 \r
1711         IPOIB_ENTER( IPOIB_DBG_PNP );\r
1712 \r
1713         UNUSED_PARAM( info_buf );\r
1714         UNUSED_PARAM( info_buf_len );\r
1715 \r
1716         p_adapter = (ipoib_adapter_t*)adapter_context;\r
1717 \r
1718         IPOIB_TRACE( IPOIB_DBG_PNP, ("Event %d\n", pnp_event) );\r
1719         if( pnp_event != NdisDevicePnPEventPowerProfileChanged )\r
1720         {\r
1721                 cl_obj_lock( &p_adapter->obj );\r
1722                 p_adapter->state = IB_PNP_PORT_REMOVE;\r
1723                 cl_obj_unlock( &p_adapter->obj );\r
1724 \r
1725                 ipoib_resume_oids( p_adapter );\r
1726         }\r
1727 \r
1728         IPOIB_EXIT( IPOIB_DBG_PNP );\r
1729 }\r
1730 \r
1731 \r
1732 void\r
1733 ipoib_shutdown(\r
1734         IN                              PVOID                                           adapter_context )\r
1735 {\r
1736         IPOIB_ENTER( IPOIB_DBG_INIT );\r
1737         UNUSED_PARAM( adapter_context );\r
1738         IPOIB_EXIT( IPOIB_DBG_INIT );\r
1739 }\r
1740 \r
1741 \r
1742 void\r
1743 ipoib_resume_oids(\r
1744         IN                              ipoib_adapter_t* const          p_adapter )\r
1745 {\r
1746         ULONG                           info;\r
1747         NDIS_STATUS                     status;\r
1748         boolean_t                       pending_query, pending_set;\r
1749         pending_oid_t           query_oid = {0};\r
1750         pending_oid_t           set_oid = {0};\r
1751         KLOCK_QUEUE_HANDLE      hdl;\r
1752 \r
1753         IPOIB_ENTER( IPOIB_DBG_INIT );\r
1754 \r
1755         cl_obj_lock( &p_adapter->obj );\r
1756         /*\r
1757          * Set the status depending on our state.  Fail OID requests that\r
1758          * are pending while we reset the adapter.\r
1759          */\r
1760         switch( p_adapter->state )\r
1761         {\r
1762         case IB_PNP_PORT_ADD:\r
1763                 status = NDIS_STATUS_FAILURE;\r
1764                 break;\r
1765 \r
1766         case IB_PNP_PORT_REMOVE:\r
1767                 status = NDIS_STATUS_NOT_ACCEPTED;\r
1768                 break;\r
1769                 \r
1770         default:\r
1771                 status = NDIS_STATUS_SUCCESS;\r
1772         }\r
1773 \r
1774         pending_query = p_adapter->pending_query;\r
1775         if( pending_query )\r
1776         {\r
1777                 query_oid = p_adapter->query_oid;\r
1778                 p_adapter->pending_query = FALSE;\r
1779         }\r
1780         pending_set = p_adapter->pending_set;\r
1781         if( pending_set )\r
1782         {\r
1783                 set_oid = p_adapter->set_oid;\r
1784                 p_adapter->pending_set = FALSE;\r
1785         }\r
1786         cl_obj_unlock( &p_adapter->obj );\r
1787 \r
1788         /*\r
1789          * If we had a pending OID request for OID_GEN_LINK_SPEED,\r
1790          * complete it now.  Note that we hold the object lock since\r
1791          * NdisMQueryInformationComplete is called at DISPATCH_LEVEL.\r
1792          */\r
1793         if( pending_query )\r
1794         {\r
1795                 switch( query_oid.oid )\r
1796                 {\r
1797                 case OID_GEN_LINK_SPEED:\r
1798                         ipoib_complete_query( p_adapter, &query_oid,\r
1799                                 status, &p_adapter->rate, sizeof(p_adapter->rate) );\r
1800                         break;\r
1801 \r
1802                 case OID_GEN_MEDIA_CONNECT_STATUS:\r
1803                         info = NdisMediaStateConnected;\r
1804                         ipoib_complete_query( p_adapter, &query_oid,\r
1805                                 status, &info, sizeof(info) );\r
1806                         break;\r
1807 \r
1808                 default:\r
1809                         CL_ASSERT( query_oid.oid == OID_GEN_LINK_SPEED ||\r
1810                                 query_oid.oid == OID_GEN_MEDIA_CONNECT_STATUS );\r
1811                         break;\r
1812                 }\r
1813         }\r
1814 \r
1815         if( pending_set )\r
1816         {\r
1817                 switch( set_oid.oid )\r
1818                 {\r
1819                 case OID_GEN_CURRENT_PACKET_FILTER:\r
1820                         /* Validation already performed in the SetInformation path. */\r
1821 \r
1822                         KeAcquireInStackQueuedSpinLock( &g_ipoib.lock, &hdl );\r
1823                         cl_obj_lock( &p_adapter->obj );\r
1824                         if( !p_adapter->packet_filter && (*(PULONG)set_oid.p_buf) )\r
1825                         {\r
1826                                 cl_qlist_insert_tail(\r
1827                                         &g_ipoib.adapter_list, &p_adapter->entry );\r
1828                                 /*\r
1829                                  * Filter was zero, now non-zero.  Register IP addresses\r
1830                                  * with SA.\r
1831                                  */\r
1832                                 ipoib_reg_addrs( p_adapter );\r
1833                         }\r
1834                         else if( p_adapter->packet_filter && !(*(PULONG)set_oid.p_buf) )\r
1835                         {\r
1836                                 /* Filter was non-zero, now zero.  Deregister IP addresses. */\r
1837                                 ipoib_dereg_addrs( p_adapter );\r
1838 \r
1839                                 ASSERT( cl_qlist_count( &g_ipoib.adapter_list ) );\r
1840                                 cl_qlist_remove_item(\r
1841                                         &g_ipoib.adapter_list, &p_adapter->entry );\r
1842                         }\r
1843                         p_adapter->packet_filter = *(PULONG)set_oid.p_buf;\r
1844 \r
1845                         cl_obj_unlock( &p_adapter->obj );\r
1846                         KeReleaseInStackQueuedSpinLock( &hdl );\r
1847 \r
1848                         NdisMSetInformationComplete( p_adapter->h_adapter, status );\r
1849                         break;\r
1850 \r
1851                 case OID_GEN_NETWORK_LAYER_ADDRESSES:\r
1852                         status = __ipoib_set_net_addr( p_adapter,\r
1853                                                                                    p_adapter->set_oid.p_buf,\r
1854                                                                                    p_adapter->set_oid.buf_len,\r
1855                                                                                    p_adapter->set_oid.p_bytes_used,\r
1856                                                                                    p_adapter->set_oid.p_bytes_needed );\r
1857                         if( status != NDIS_STATUS_PENDING )\r
1858                         {\r
1859                                 NdisMSetInformationComplete( p_adapter->h_adapter, status );\r
1860                         }\r
1861                         break;\r
1862 \r
1863                 default:\r
1864                         CL_ASSERT( set_oid.oid && 0 );\r
1865                         break;\r
1866                 }\r
1867         }\r
1868 \r
1869         IPOIB_EXIT( IPOIB_DBG_INIT );\r
1870 }\r
1871 \r
1872 \r
1873 static NDIS_STATUS\r
1874 __ipoib_set_net_addr(\r
1875         IN              ipoib_adapter_t *       p_adapter,\r
1876         IN              PVOID                           info_buf,\r
1877         IN              ULONG                           info_buf_len,\r
1878                 OUT     PULONG                          p_bytes_read,\r
1879                 OUT     PULONG                          p_bytes_needed )\r
1880 {\r
1881         NDIS_STATUS                             status;\r
1882         PNETWORK_ADDRESS_LIST   p_net_addrs;\r
1883         PNETWORK_ADDRESS                p_net_addr_oid;\r
1884         PNETWORK_ADDRESS_IP             p_ip_addr;\r
1885 \r
1886         net_address_item_t              *p_addr_item;\r
1887 \r
1888         cl_status_t                             cl_status;\r
1889 \r
1890         size_t                                  idx;\r
1891         LONG                                    i;\r
1892         ULONG                                   addr_size;\r
1893         ULONG                                   total_size;\r
1894 \r
1895         uint8_t                                 port_num;\r
1896 \r
1897         IPOIB_ENTER( IPOIB_DBG_OID );\r
1898 \r
1899         status = NDIS_STATUS_SUCCESS;\r
1900         port_num = p_adapter->guids.port_num;\r
1901 \r
1902         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1903                 ("Port %d received set for OID_GEN_NETWORK_LAYER_ADDRESSES\n",\r
1904                 port_num) );\r
1905 \r
1906         if( !info_buf )\r
1907         {\r
1908                 IPOIB_TRACE( IPOIB_DBG_ERROR,\r
1909                         ("Port %d - OID_GEN_NETWORK_LAYER_ADDRESSES - "\r
1910                         "NULL buffer\n", port_num) );\r
1911                 IPOIB_EXIT( IPOIB_DBG_OID );\r
1912                 return NDIS_STATUS_INVALID_DATA;\r
1913         }\r
1914 \r
1915         /*\r
1916          * Must use field offset because the structures define array's of size one\r
1917          * of a the incorrect type for what is really stored.\r
1918          */\r
1919         if( info_buf_len < FIELD_OFFSET(NETWORK_ADDRESS_LIST, Address) )\r
1920         {\r
1921                 IPOIB_TRACE( IPOIB_DBG_ERROR, \r
1922                         ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - "\r
1923                         "bad length of %d, not enough "\r
1924                         "for NETWORK_ADDRESS_LIST (%d)\n", port_num, info_buf_len,\r
1925                         FIELD_OFFSET(NETWORK_ADDRESS_LIST, Address)) );\r
1926                 *p_bytes_needed = FIELD_OFFSET(NETWORK_ADDRESS_LIST, Address);\r
1927                 IPOIB_EXIT( IPOIB_DBG_OID );\r
1928                 return NDIS_STATUS_INVALID_LENGTH;\r
1929         }\r
1930 \r
1931         p_net_addrs = (PNETWORK_ADDRESS_LIST)info_buf;\r
1932         if( p_net_addrs->AddressCount == 0)\r
1933         {\r
1934                 if( p_net_addrs->AddressType == NDIS_PROTOCOL_ID_TCP_IP )\r
1935                 {\r
1936                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1937                                 ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - "\r
1938                                 "clear TCP/IP addresses\n", port_num) );\r
1939                 }\r
1940                 else\r
1941                 {\r
1942                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1943                                 ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - "\r
1944                                 "Non TCP/IP address type of 0x%.4X on clear\n",\r
1945                                 port_num, p_net_addrs->AddressType) );\r
1946                         IPOIB_EXIT( IPOIB_DBG_OID );\r
1947                         return NDIS_STATUS_SUCCESS;\r
1948                 }\r
1949         }\r
1950 \r
1951         addr_size = FIELD_OFFSET(NETWORK_ADDRESS, Address) +\r
1952                 NETWORK_ADDRESS_LENGTH_IP;\r
1953         total_size = FIELD_OFFSET(NETWORK_ADDRESS_LIST, Address) +\r
1954                 addr_size * p_net_addrs->AddressCount;\r
1955 \r
1956         if( info_buf_len < total_size )\r
1957         {\r
1958                 IPOIB_TRACE( IPOIB_DBG_ERROR,\r
1959                         ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - "\r
1960                         "bad length of %d, %d required for %d addresses\n",\r
1961                         port_num, info_buf_len, total_size, p_net_addrs->AddressCount) );\r
1962                 *p_bytes_needed = total_size;\r
1963                 IPOIB_EXIT( IPOIB_DBG_OID );\r
1964                 return NDIS_STATUS_INVALID_LENGTH;\r
1965         }\r
1966 \r
1967         /* Lock lists for duration since SA callbacks can occur on other CPUs */\r
1968         cl_obj_lock( &p_adapter->obj );\r
1969 \r
1970         /* Set the capacity of the vector to accomodate all assinged addresses. */\r
1971         cl_status = cl_vector_set_capacity(\r
1972                 &p_adapter->ip_vector, p_net_addrs->AddressCount );\r
1973         if( cl_status != CL_SUCCESS )\r
1974         {\r
1975                 cl_obj_unlock( &p_adapter->obj );\r
1976                 IPOIB_TRACE( IPOIB_DBG_ERROR,\r
1977                         ("Port %d - OID_GEN_NETWORK_LAYER_ADDRESSES - "\r
1978                         "Failed to set IP vector capacity: %s\n",\r
1979                         CL_STATUS_MSG(cl_status)) );\r
1980                 IPOIB_EXIT( IPOIB_DBG_OID );\r
1981                 return NDIS_STATUS_RESOURCES;\r
1982         }\r
1983 \r
1984         *p_bytes_read = total_size;\r
1985 \r
1986         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1987                 ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - List contains %d addresses\n",\r
1988                         port_num, p_net_addrs->AddressCount));\r
1989 \r
1990         /* First look for addresses we had that should be removed */\r
1991         for( idx = 0; idx != cl_vector_get_size( &p_adapter->ip_vector ); idx++ )\r
1992         {\r
1993                 p_addr_item = (net_address_item_t*)\r
1994                         cl_vector_get_ptr( &p_adapter->ip_vector, idx );\r
1995                 p_net_addr_oid = (PNETWORK_ADDRESS)p_net_addrs->Address;\r
1996 \r
1997                 for( i = 0; i < p_net_addrs->AddressCount; ++i, p_net_addr_oid =\r
1998                         (PNETWORK_ADDRESS)((uint8_t *)p_net_addr_oid +\r
1999                         FIELD_OFFSET(NETWORK_ADDRESS, Address) +\r
2000                         p_net_addr_oid->AddressLength) )\r
2001                 {\r
2002 \r
2003                         if( p_net_addr_oid->AddressType != NDIS_PROTOCOL_ID_TCP_IP )\r
2004                         {\r
2005                                 IPOIB_TRACE( IPOIB_DBG_WARN,\r
2006                                         ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Address %d is wrong type of 0x%.4X, "\r
2007                                                 "should be 0x%.4X\n", port_num, i, p_net_addr_oid->AddressType,\r
2008                                                 NDIS_PROTOCOL_ID_TCP_IP));\r
2009                                 continue;\r
2010                         }\r
2011 \r
2012                         if( p_net_addr_oid->AddressLength != NETWORK_ADDRESS_LENGTH_IP)\r
2013                         {\r
2014                                 IPOIB_TRACE( IPOIB_DBG_WARN,\r
2015                                         ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Address %d is wrong size of %d, "\r
2016                                                 "should be %d\n", port_num, i, p_net_addr_oid->AddressLength,\r
2017                                                 NETWORK_ADDRESS_LENGTH_IP));\r
2018                                 continue;\r
2019                         }\r
2020 \r
2021                         p_ip_addr = (PNETWORK_ADDRESS_IP)p_net_addr_oid->Address;\r
2022                         if( !cl_memcmp( &p_ip_addr->in_addr,\r
2023                                 &p_addr_item->address.as_ulong, sizeof(ULONG) ) )\r
2024                         {\r
2025                                 break;\r
2026                         }\r
2027                 }\r
2028 \r
2029                 if( i == p_net_addrs->AddressCount )\r
2030                 {\r
2031                         /* Didn't find a match, delete from SA */\r
2032                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
2033                                 ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Deleting Address %d.%d.%d.%d\n",\r
2034                                         port_num,\r
2035                                         p_addr_item->address.as_bytes[0],\r
2036                                         p_addr_item->address.as_bytes[1],\r
2037                                         p_addr_item->address.as_bytes[2],\r
2038                                         p_addr_item->address.as_bytes[3]));\r
2039 \r
2040                         if( p_addr_item->p_reg )\r
2041                         {\r
2042                                 if( p_addr_item->p_reg->h_reg_svc )\r
2043                                 {\r
2044                                         p_adapter->p_ifc->dereg_svc(\r
2045                                                 p_addr_item->p_reg->h_reg_svc, __ipoib_ats_dereg_cb );\r
2046                                 }\r
2047                                 else\r
2048                                 {\r
2049                                         cl_free( p_addr_item->p_reg );\r
2050                                 }\r
2051                                 p_addr_item->p_reg = NULL;\r
2052                         }\r
2053                         p_addr_item->address.as_ulong = 0;\r
2054                 }\r
2055         }\r
2056 \r
2057         /* Now look for new addresses */\r
2058         p_net_addr_oid = (NETWORK_ADDRESS *)p_net_addrs->Address;\r
2059         idx = 0;\r
2060         for( i = 0; i < p_net_addrs->AddressCount; i++, p_net_addr_oid =\r
2061                 (PNETWORK_ADDRESS)((uint8_t *)p_net_addr_oid +\r
2062                 FIELD_OFFSET(NETWORK_ADDRESS, Address) + p_net_addr_oid->AddressLength) )\r
2063         {\r
2064 \r
2065                 if( p_net_addr_oid->AddressType != NDIS_PROTOCOL_ID_TCP_IP )\r
2066                 {\r
2067                         IPOIB_TRACE( IPOIB_DBG_WARN,\r
2068                                 ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Address %d is wrong type of 0x%.4X, "\r
2069                                         "should be 0x%.4X\n", port_num, i, p_net_addr_oid->AddressType,\r
2070                                         NDIS_PROTOCOL_ID_TCP_IP));\r
2071                         continue;\r
2072                 }\r
2073 \r
2074                 if( p_net_addr_oid->AddressLength != NETWORK_ADDRESS_LENGTH_IP)\r
2075                 {\r
2076                         IPOIB_TRACE( IPOIB_DBG_WARN,\r
2077                                 ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Address %d is wrong size of %d, "\r
2078                                         "should be %d\n", port_num, i, p_net_addr_oid->AddressLength,\r
2079                                         NETWORK_ADDRESS_LENGTH_IP));\r
2080                         continue;\r
2081                 }\r
2082 \r
2083                 p_ip_addr = (PNETWORK_ADDRESS_IP)p_net_addr_oid->Address;\r
2084 \r
2085                 /* Size the vector as needed. */\r
2086                 if( cl_vector_get_size( &p_adapter->ip_vector ) <= idx )\r
2087                         cl_vector_set_size( &p_adapter->ip_vector, idx + 1 );\r
2088 \r
2089                 p_addr_item = cl_vector_get_ptr( &p_adapter->ip_vector, idx );\r
2090                 if( !cl_memcmp( &p_ip_addr->in_addr, &p_addr_item->address.as_ulong,\r
2091                         sizeof(ULONG) ) )\r
2092                 {\r
2093                         idx++;\r
2094                         /* Already have this address - no change needed */\r
2095                         continue;\r
2096                 }\r
2097 \r
2098                 /*\r
2099                  * Copy the address information, but don't register yet - the port\r
2100                  * could be down.\r
2101                  */\r
2102                 if( p_addr_item->p_reg )\r
2103                 {\r
2104                         /* If in use by some other address, deregister. */\r
2105                         if( p_addr_item->p_reg->h_reg_svc )\r
2106                         {\r
2107                                 p_adapter->p_ifc->dereg_svc(\r
2108                                         p_addr_item->p_reg->h_reg_svc, __ipoib_ats_dereg_cb );\r
2109                         }\r
2110                         else\r
2111                         {\r
2112                                 cl_free( p_addr_item->p_reg );\r
2113                         }\r
2114                         p_addr_item->p_reg = NULL;\r
2115                 }\r
2116                 memcpy ((void *)&p_addr_item->address.as_ulong, (const void *)&p_ip_addr->in_addr, sizeof(ULONG) );\r
2117                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
2118                         ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Adding Address %d.%d.%d.%d\n",\r
2119                         port_num,\r
2120                         p_addr_item->address.as_bytes[0],\r
2121                         p_addr_item->address.as_bytes[1],\r
2122                         p_addr_item->address.as_bytes[2],\r
2123                         p_addr_item->address.as_bytes[3]) );\r
2124                 idx++;\r
2125         }\r
2126 \r
2127         /* Now clear any extra entries that shouldn't be there. */\r
2128         while( idx < cl_vector_get_size( &p_adapter->ip_vector ) )\r
2129         {\r
2130                 p_addr_item = (net_address_item_t*)\r
2131                         cl_vector_get_ptr( &p_adapter->ip_vector,\r
2132                         cl_vector_get_size( &p_adapter->ip_vector ) - 1 );\r
2133 \r
2134                 if( p_addr_item->p_reg )\r
2135                 {\r
2136                         if( p_addr_item->p_reg->h_reg_svc )\r
2137                         {\r
2138                                 p_adapter->p_ifc->dereg_svc(\r
2139                                         p_addr_item->p_reg->h_reg_svc, __ipoib_ats_dereg_cb );\r
2140                         }\r
2141                         else\r
2142                         {\r
2143                                 cl_free( p_addr_item->p_reg );\r
2144                         }\r
2145                         p_addr_item->p_reg = NULL;\r
2146                         p_addr_item->address.as_ulong = 0;\r
2147                 }\r
2148 \r
2149                 /* No need to check return value - shrinking always succeeds. */\r
2150                 cl_vector_set_size( &p_adapter->ip_vector,\r
2151                         cl_vector_get_size( &p_adapter->ip_vector ) - 1 );\r
2152         }\r
2153 \r
2154         if( p_adapter->state == IB_PNP_PORT_ACTIVE && p_adapter->packet_filter )\r
2155                 ipoib_reg_addrs( p_adapter );\r
2156 \r
2157         cl_obj_unlock( &p_adapter->obj );\r
2158 \r
2159         IPOIB_EXIT( IPOIB_DBG_OID );\r
2160         return NDIS_STATUS_SUCCESS;\r
2161 }\r
2162 \r
2163 \r
2164 /* Object lock is held when this function is called. */\r
2165 void\r
2166 ipoib_reg_addrs(\r
2167         IN                              ipoib_adapter_t* const          p_adapter )\r
2168 {\r
2169         net_address_item_t              *p_addr_item;\r
2170 \r
2171         size_t                                  idx;\r
2172 \r
2173         uint8_t                                 port_num;\r
2174 \r
2175         ib_api_status_t                 ib_status;\r
2176         ib_reg_svc_req_t                ib_service;\r
2177         ib_gid_t                                port_gid;\r
2178 \r
2179         IPOIB_ENTER( IPOIB_DBG_OID );\r
2180 \r
2181         port_num = p_adapter->guids.port_num;\r
2182 \r
2183         /* Setup our service call with things common to all calls */\r
2184         cl_memset( &ib_service, 0, sizeof(ib_service) );\r
2185 \r
2186         /* BUGBUG Only register local subnet GID prefix for now */\r
2187         ib_gid_set_default( &port_gid, p_adapter->guids.port_guid );\r
2188         ib_service.svc_rec.service_gid          = port_gid;\r
2189 \r
2190         ib_service.svc_rec.service_pkey         = IB_DEFAULT_PKEY;\r
2191         ib_service.svc_rec.service_lease        = IB_INFINITE_SERVICE_LEASE;\r
2192 \r
2193         /* Must cast here because the service name is an array of unsigned chars but\r
2194          * strcpy want a pointer to a signed char */\r
2195         strcpy( (char *)ib_service.svc_rec.service_name, ATS_NAME );\r
2196 \r
2197         /* IP Address in question will be put in below */\r
2198         ib_service.port_guid            = p_adapter->guids.port_guid;\r
2199         ib_service.timeout_ms           = p_adapter->params.sa_timeout;\r
2200         ib_service.retry_cnt            = p_adapter->params.sa_retry_cnt;\r
2201 \r
2202         /* Can't set IB_FLAGS_SYNC here because I can't wait at dispatch */\r
2203         ib_service.flags                        = 0;\r
2204 \r
2205         /* Service context will be put in below */\r
2206 \r
2207         ib_service.svc_data_mask        = IB_SR_COMPMASK_SID            |\r
2208                                                                   IB_SR_COMPMASK_SGID           |\r
2209                                                                   IB_SR_COMPMASK_SPKEY          |\r
2210                                                                   IB_SR_COMPMASK_SLEASE         |\r
2211                                                                   IB_SR_COMPMASK_SNAME          |\r
2212                                                                   IB_SR_COMPMASK_SDATA8_12      |\r
2213                                                                   IB_SR_COMPMASK_SDATA8_13      |\r
2214                                                                   IB_SR_COMPMASK_SDATA8_14      |\r
2215                                                                   IB_SR_COMPMASK_SDATA8_15;\r
2216         ib_service.pfn_reg_svc_cb = __ipoib_ats_reg_cb;\r
2217 \r
2218         for( idx = 0; idx < cl_vector_get_size( &p_adapter->ip_vector); idx++ )\r
2219         {\r
2220                 p_addr_item = (net_address_item_t*)\r
2221                         cl_vector_get_ptr(  &p_adapter->ip_vector, idx );\r
2222 \r
2223                 if( p_addr_item->p_reg )\r
2224                         continue;\r
2225 \r
2226                 p_addr_item->p_reg = cl_zalloc( sizeof(ats_reg_t) );\r
2227                 if( !p_addr_item->p_reg )\r
2228                         break;\r
2229 \r
2230                 p_addr_item->p_reg->p_adapter = p_adapter;\r
2231 \r
2232                 ib_service.svc_context          = p_addr_item->p_reg;\r
2233 \r
2234                 ib_service.svc_rec.service_id =\r
2235                         ATS_SERVICE_ID & CL_HTON64(0xFFFFFFFFFFFFFF00);\r
2236                 /* ATS service IDs start at 0x10000CE100415453 */\r
2237                 ib_service.svc_rec.service_id |= ((uint64_t)(idx + 0x53)) << 56;\r
2238 \r
2239                 cl_memcpy( &ib_service.svc_rec.service_data8[ATS_IPV4_OFFSET],\r
2240                         p_addr_item->address.as_bytes, IPV4_ADDR_SIZE );\r
2241 \r
2242                 /* Take a reference for each service request. */\r
2243                 cl_obj_ref(&p_adapter->obj);\r
2244                 ib_status = p_adapter->p_ifc->reg_svc(\r
2245                         p_adapter->h_al, &ib_service, &p_addr_item->p_reg->h_reg_svc );\r
2246                 if( ib_status != IB_SUCCESS )\r
2247                 {\r
2248                         if( ib_status == IB_INVALID_GUID )\r
2249                         {\r
2250                                 /* If this occurs, we log the error but do not fail the OID yet */\r
2251                                 IPOIB_TRACE( IPOIB_DBG_WARN,\r
2252                                         ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - "\r
2253                                         "Failed to register IP Address "\r
2254                                         "of %d.%d.%d.%d with error IB_INVALID_GUID\n",\r
2255                                         port_num,\r
2256                                         p_addr_item->address.as_bytes[0],\r
2257                                         p_addr_item->address.as_bytes[1],\r
2258                                         p_addr_item->address.as_bytes[2],\r
2259                                         p_addr_item->address.as_bytes[3]) );\r
2260                         }\r
2261                         else\r
2262                         {\r
2263                                 /* Fatal error. */\r
2264                                 IPOIB_TRACE( IPOIB_DBG_ERROR,\r
2265                                         ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Failed to register IP Address "\r
2266                                         "of %d.%d.%d.%d with error %s\n",\r
2267                                         port_num,\r
2268                                         p_addr_item->address.as_bytes[0],\r
2269                                         p_addr_item->address.as_bytes[1],\r
2270                                         p_addr_item->address.as_bytes[2],\r
2271                                         p_addr_item->address.as_bytes[3],\r
2272                                         p_adapter->p_ifc->get_err_str( ib_status )) );\r
2273                                 p_adapter->hung = TRUE;\r
2274                         }\r
2275                         cl_obj_deref(&p_adapter->obj);\r
2276                         cl_free( p_addr_item->p_reg );\r
2277                         p_addr_item->p_reg = NULL;\r
2278                 }\r
2279         }\r
2280 \r
2281         IPOIB_EXIT( IPOIB_DBG_OID );\r
2282 }\r
2283 \r
2284 \r
2285 /* Object lock is held when this function is called. */\r
2286 void\r
2287 ipoib_dereg_addrs(\r
2288         IN                              ipoib_adapter_t* const          p_adapter )\r
2289 {\r
2290         net_address_item_t              *p_addr_item;\r
2291 \r
2292         size_t                                  idx;\r
2293 \r
2294         IPOIB_ENTER( IPOIB_DBG_OID );\r
2295 \r
2296         for( idx = 0; idx < cl_vector_get_size( &p_adapter->ip_vector); idx++ )\r
2297         {\r
2298                 p_addr_item = (net_address_item_t*)\r
2299                         cl_vector_get_ptr( &p_adapter->ip_vector, idx );\r
2300 \r
2301                 if( !p_addr_item->p_reg )\r
2302                         continue;\r
2303 \r
2304                 if( p_addr_item->p_reg->h_reg_svc )\r
2305                 {\r
2306                         p_adapter->p_ifc->dereg_svc(\r
2307                                 p_addr_item->p_reg->h_reg_svc, __ipoib_ats_dereg_cb );\r
2308                 }\r
2309                 else\r
2310                 {\r
2311                         cl_free( p_addr_item->p_reg );\r
2312                 }\r
2313                 p_addr_item->p_reg = NULL;\r
2314         }\r
2315 \r
2316         IPOIB_EXIT( IPOIB_DBG_OID );\r
2317 }\r
2318 \r
2319 \r
2320 static void\r
2321 __ipoib_ats_reg_cb(\r
2322         IN                              ib_reg_svc_rec_t                        *p_reg_svc_rec )\r
2323 {\r
2324         ats_reg_t                               *p_reg;\r
2325         uint8_t                                 port_num;\r
2326 \r
2327         IPOIB_ENTER( IPOIB_DBG_OID );\r
2328 \r
2329         CL_ASSERT( p_reg_svc_rec );\r
2330         CL_ASSERT( p_reg_svc_rec->svc_context );\r
2331 \r
2332         p_reg = (ats_reg_t* __ptr64)p_reg_svc_rec->svc_context;\r
2333         port_num = p_reg->p_adapter->guids.port_num;\r
2334 \r
2335         cl_obj_lock( &p_reg->p_adapter->obj );\r
2336 \r
2337         if( p_reg_svc_rec->req_status == IB_SUCCESS &&\r
2338                 !p_reg_svc_rec->resp_status )\r
2339         {\r
2340                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
2341                                          ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Registered IP Address "\r
2342                                           "of %d.%d.%d.%d\n",\r
2343                                           port_num,\r
2344                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET],\r
2345                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET+1],\r
2346                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET+2],\r
2347                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET+3]) );\r
2348         }\r
2349         else if( p_reg_svc_rec->req_status != IB_CANCELED )\r
2350         {\r
2351                 IPOIB_TRACE( IPOIB_DBG_ERROR,\r
2352                                          ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Failed to register IP Address "\r
2353                                           "of %d.%d.%d.%d with error %s\n",\r
2354                                           port_num,\r
2355                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET],\r
2356                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET+1],\r
2357                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET+2],\r
2358                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET+3],\r
2359                                           p_reg->p_adapter->p_ifc->get_err_str( p_reg_svc_rec->resp_status )) );\r
2360                 p_reg->p_adapter->hung = TRUE;\r
2361                 p_reg->h_reg_svc = NULL;\r
2362         }\r
2363 \r
2364         cl_obj_unlock( &p_reg->p_adapter->obj );\r
2365         cl_obj_deref(&p_reg->p_adapter->obj);\r
2366 \r
2367         IPOIB_EXIT( IPOIB_DBG_OID );\r
2368 }\r
2369 \r
2370 \r
2371 static void\r
2372 __ipoib_ats_dereg_cb(\r
2373         IN                              void                                            *context )\r
2374 {\r
2375         cl_free( context );\r
2376 }\r