[IPoIB] Fix NDIS WHQL 1c_OffloadInvalid test failure.
[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                 offsetof( NDIS_TASK_OFFLOAD, TaskBuffer ) +\r
1293                 sizeof(NDIS_TASK_TCP_IP_CHECKSUM);\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 static NDIS_STATUS\r
1358 __ipoib_set_tcp_task_offload(\r
1359         IN                              ipoib_adapter_t*                        p_adapter,\r
1360         IN                              void* const                                     p_info_buf,\r
1361         IN                              ULONG* const                            p_info_len )\r
1362 {\r
1363         NDIS_TASK_OFFLOAD_HEADER        *p_offload_hdr;\r
1364         NDIS_TASK_OFFLOAD                       *p_offload_task;\r
1365         NDIS_TASK_TCP_IP_CHECKSUM       *p_offload_chksum;\r
1366 \r
1367         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1368                 ("Port %d received set for OID_TCP_TASK_OFFLOAD\n",\r
1369                 p_adapter->guids.port_num) );\r
1370 \r
1371         p_offload_hdr = (NDIS_TASK_OFFLOAD_HEADER*)p_info_buf;\r
1372 \r
1373         if( *p_info_len < sizeof(NDIS_TASK_OFFLOAD_HEADER) )\r
1374                 return NDIS_STATUS_INVALID_LENGTH;\r
1375 \r
1376         if( p_offload_hdr->Version != NDIS_TASK_OFFLOAD_VERSION )\r
1377                 return NDIS_STATUS_INVALID_DATA;\r
1378 \r
1379         if( p_offload_hdr->Size != sizeof(NDIS_TASK_OFFLOAD_HEADER) )\r
1380                 return NDIS_STATUS_INVALID_LENGTH;\r
1381 \r
1382         if( !p_offload_hdr->OffsetFirstTask )\r
1383                 return NDIS_STATUS_SUCCESS;\r
1384 \r
1385         if( p_offload_hdr->EncapsulationFormat.Encapsulation !=\r
1386                 IEEE_802_3_Encapsulation )\r
1387         {\r
1388                 return NDIS_STATUS_INVALID_DATA;\r
1389         }\r
1390 \r
1391         p_offload_task = (NDIS_TASK_OFFLOAD*)\r
1392                 (((UCHAR*)p_offload_hdr) + p_offload_hdr->OffsetFirstTask);\r
1393 \r
1394         if( *p_info_len < sizeof(NDIS_TASK_OFFLOAD_HEADER) +\r
1395                 offsetof( NDIS_TASK_OFFLOAD, TaskBuffer ) +\r
1396                 sizeof(NDIS_TASK_TCP_IP_CHECKSUM) )\r
1397         {\r
1398                 return NDIS_STATUS_INVALID_LENGTH;\r
1399         }\r
1400 \r
1401         if( p_offload_task->Version != NDIS_TASK_OFFLOAD_VERSION )\r
1402                 return NDIS_STATUS_INVALID_DATA;\r
1403         p_offload_chksum =\r
1404                 (NDIS_TASK_TCP_IP_CHECKSUM*)p_offload_task->TaskBuffer;\r
1405 \r
1406         if( !p_adapter->params.send_chksum_offload &&\r
1407                 (p_offload_chksum->V4Transmit.IpOptionsSupported ||\r
1408                 p_offload_chksum->V4Transmit.TcpOptionsSupported ||\r
1409                 p_offload_chksum->V4Transmit.TcpChecksum ||\r
1410                 p_offload_chksum->V4Transmit.UdpChecksum ||\r
1411                 p_offload_chksum->V4Transmit.IpChecksum) )\r
1412         {\r
1413                 return NDIS_STATUS_NOT_SUPPORTED;\r
1414         }\r
1415 \r
1416         return NDIS_STATUS_SUCCESS;\r
1417 }\r
1418 \r
1419 \r
1420 //! Issues a hardware reset to the NIC and/or resets the driver's software state.\r
1421 /*  Tear down the connection and start over again.  This is only called when there is a problem.\r
1422 For example, if a send, query info, or set info had a time out.  MiniportCheckForHang will\r
1423 be called first.\r
1424 IRQL = DISPATCH_LEVEL\r
1425 \r
1426 @param p_addr_resetPointer to BOOLLEAN that is set to TRUE if the NDIS\r
1427 library should call MiniportSetInformation to restore addressing information to the current values.\r
1428 @param adapter_context The adapter context allocated at start\r
1429 @return NDIS_STATUS_SUCCESS, NDIS_STATUS_PENDING, NDIS_STATUS_NOT_RESETTABLE,\r
1430 NDIS_STATUS_RESET_IN_PROGRESS, NDIS_STATUS_SOFT_ERRORS, NDIS_STATUS_HARD_ERRORS\r
1431 */\r
1432 NDIS_STATUS\r
1433 ipoib_reset(\r
1434                 OUT                     PBOOLEAN                                        p_addr_reset,\r
1435         IN                              NDIS_HANDLE                                     adapter_context)\r
1436 {\r
1437         ipoib_adapter_t* p_adapter;\r
1438 \r
1439         IPOIB_ENTER( IPOIB_DBG_INIT );\r
1440 \r
1441         CL_ASSERT( p_addr_reset );\r
1442         CL_ASSERT( adapter_context );\r
1443         p_adapter = (ipoib_adapter_t*)adapter_context;\r
1444 \r
1445         switch( ipoib_reset_adapter( p_adapter ) )\r
1446         {\r
1447         case IB_NOT_DONE:\r
1448                 IPOIB_EXIT( IPOIB_DBG_INIT );\r
1449                 return NDIS_STATUS_PENDING;\r
1450 \r
1451         case IB_SUCCESS:\r
1452                 IPOIB_EXIT( IPOIB_DBG_INIT );\r
1453                 *p_addr_reset = TRUE;\r
1454                 return NDIS_STATUS_SUCCESS;\r
1455 \r
1456         default:\r
1457                 IPOIB_EXIT( IPOIB_DBG_INIT );\r
1458                 return NDIS_STATUS_HARD_ERRORS;\r
1459         }\r
1460 }\r
1461 \r
1462 \r
1463 //! Request changes in the state information that the miniport driver maintains\r
1464 /*  For example, this is used to set multicast addresses and the packet filter.\r
1465 IRQL = DISPATCH_LEVEL\r
1466 \r
1467 @param adapter_context The adapter context allocated at start\r
1468 @param oid Object ID representing the set operation to be carried out\r
1469 @param info_buf Buffer containing input for this set and location for any output\r
1470 @param info_buf_len Number of bytes available in info_buf\r
1471 @param p_bytes_read Pointer to number of bytes read from info_buf\r
1472 @param p_bytes_needed Pointer to number of bytes needed to satisfy this oid\r
1473 @return NDIS_STATUS_SUCCESS, NDIS_STATUS_PENDING, NDIS_STATUS_INVALID_OID,\r
1474 NDIS_STATUS_INVALID_LENGTH, NDIS_STATUS_INVALID_DATA, NDIS_STATUS_NOT_ACCEPTED,\r
1475 NDIS_STATUS_NOT_SUPPORTED, NDIS_STATUS_RESOURCES\r
1476 */\r
1477 NDIS_STATUS\r
1478 ipoib_set_info(\r
1479         IN                              NDIS_HANDLE                                     adapter_context,\r
1480         IN                              NDIS_OID                                        oid,\r
1481         IN                              PVOID                                           info_buf,\r
1482         IN                              ULONG                                           info_buf_len,\r
1483                 OUT                     PULONG                                          p_bytes_read,\r
1484                 OUT                     PULONG                                          p_bytes_needed )\r
1485 {\r
1486         ipoib_adapter_t*        p_adapter;\r
1487         NDIS_STATUS                     status;\r
1488 \r
1489         ULONG                           buf_len;\r
1490         uint8_t                         port_num;\r
1491 \r
1492         KLOCK_QUEUE_HANDLE      hdl;\r
1493         \r
1494         IPOIB_ENTER( IPOIB_DBG_OID );\r
1495 \r
1496         CL_ASSERT( adapter_context );\r
1497         p_adapter = (ipoib_adapter_t*)adapter_context;\r
1498 \r
1499         CL_ASSERT( p_bytes_read );\r
1500         CL_ASSERT( p_bytes_needed );\r
1501         CL_ASSERT( !p_adapter->pending_set );\r
1502 \r
1503         status = NDIS_STATUS_SUCCESS;\r
1504         *p_bytes_needed = 0;\r
1505         buf_len = sizeof(ULONG);\r
1506 \r
1507         port_num = p_adapter->guids.port_num;\r
1508 \r
1509         switch( oid )\r
1510         {\r
1511         /* Required General */\r
1512         case OID_GEN_CURRENT_PACKET_FILTER:\r
1513                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1514                         ("Port %d received set for OID_GEN_CURRENT_PACKET_FILTER\n", port_num));\r
1515                 if( info_buf_len < sizeof(p_adapter->packet_filter) )\r
1516                 {\r
1517                         status = NDIS_STATUS_INVALID_LENGTH;\r
1518                 }\r
1519                 else if( !info_buf )\r
1520                 {\r
1521                         status = NDIS_STATUS_INVALID_DATA;\r
1522                 }\r
1523                 else\r
1524                 {\r
1525                         KeAcquireInStackQueuedSpinLock( &g_ipoib.lock, &hdl );\r
1526                         cl_obj_lock( &p_adapter->obj );\r
1527                         switch( p_adapter->state )\r
1528                         {\r
1529                         case IB_PNP_PORT_ADD:\r
1530                                 p_adapter->set_oid.oid = oid;\r
1531                                 p_adapter->set_oid.p_buf = info_buf;\r
1532                                 p_adapter->set_oid.buf_len = info_buf_len;\r
1533                                 p_adapter->set_oid.p_bytes_used = p_bytes_read;\r
1534                                 p_adapter->set_oid.p_bytes_needed = p_bytes_needed;\r
1535                                 p_adapter->pending_set = TRUE;\r
1536                                 status = NDIS_STATUS_PENDING;\r
1537                                 break;\r
1538 \r
1539                         case IB_PNP_PORT_REMOVE:\r
1540                                 status = NDIS_STATUS_NOT_ACCEPTED;\r
1541                                 break;\r
1542 \r
1543                         default:\r
1544                                 if( !p_adapter->packet_filter && (*(uint32_t*)info_buf) )\r
1545                                 {\r
1546                                         cl_qlist_insert_tail(\r
1547                                                 &g_ipoib.adapter_list, &p_adapter->entry );\r
1548 \r
1549                                         /*\r
1550                                          * Filter was zero, now non-zero.  Register IP addresses\r
1551                                          * with SA.\r
1552                                          */\r
1553                                         ipoib_reg_addrs( p_adapter );\r
1554                                 }\r
1555                                 else if( p_adapter->packet_filter && !(*(uint32_t*)info_buf) )\r
1556                                 {\r
1557                                         /*\r
1558                                          * Filter was non-zero, now zero.  Deregister IP addresses.\r
1559                                          */\r
1560                                         ipoib_dereg_addrs( p_adapter );\r
1561 \r
1562                                         ASSERT( cl_qlist_count( &g_ipoib.adapter_list ) );\r
1563                                         cl_qlist_remove_item(\r
1564                                                 &g_ipoib.adapter_list, &p_adapter->entry );\r
1565                                 }\r
1566 \r
1567                                 p_adapter->packet_filter = *(uint32_t*)info_buf;\r
1568                         }\r
1569                         cl_obj_unlock( &p_adapter->obj );\r
1570                         KeReleaseInStackQueuedSpinLock( &hdl );\r
1571                 }\r
1572                 break;\r
1573 \r
1574         case OID_GEN_CURRENT_LOOKAHEAD:\r
1575                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1576                         ("Port %d received set for OID_GEN_CURRENT_LOOKAHEAD\n", port_num));\r
1577                 if( info_buf_len < buf_len )\r
1578                         status = NDIS_STATUS_INVALID_LENGTH;\r
1579                 break;\r
1580 \r
1581         case OID_GEN_PROTOCOL_OPTIONS:\r
1582                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1583                         ("Port %d received set for OID_GEN_PROTOCOL_OPTIONS\n", port_num));\r
1584                 if( info_buf_len < buf_len )\r
1585                         status = NDIS_STATUS_INVALID_LENGTH;\r
1586                 break;\r
1587 \r
1588         case OID_GEN_NETWORK_LAYER_ADDRESSES:\r
1589                 status = __ipoib_set_net_addr( p_adapter, info_buf, info_buf_len, p_bytes_read, p_bytes_needed);\r
1590                 break;\r
1591 \r
1592 #ifdef NDIS51_MINIPORT\r
1593         case OID_GEN_MACHINE_NAME:\r
1594                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1595                         ("Port %d received set for OID_GEN_MACHINE_NAME\n", port_num) );\r
1596                 break;\r
1597 #endif\r
1598 \r
1599         /* Required Ethernet operational characteristics */\r
1600         case OID_802_3_MULTICAST_LIST:\r
1601                 IPOIB_TRACE( IPOIB_DBG_OID,\r
1602                         ("Port %d received set for OID_802_3_MULTICAST_LIST\n", port_num) );\r
1603                 if( info_buf_len > MAX_MCAST * sizeof(mac_addr_t) )\r
1604                 {\r
1605                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1606                                 ("Port %d OID_802_3_MULTICAST_LIST - Multicast list full.\n", port_num) );\r
1607                         status = NDIS_STATUS_MULTICAST_FULL;\r
1608                         *p_bytes_needed = MAX_MCAST * sizeof(mac_addr_t);\r
1609                 }\r
1610                 else if( info_buf_len % sizeof(mac_addr_t) )\r
1611                 {\r
1612                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1613                                 ("Port %d OID_802_3_MULTICAST_LIST - Invalid input buffer.\n", port_num) );\r
1614                         status = NDIS_STATUS_INVALID_DATA;\r
1615                 }\r
1616                 else if( !info_buf && info_buf_len )\r
1617                 {\r
1618                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1619                                 ("Port %d OID_802_3_MULTICAST_LIST - Invalid input buffer.\n", port_num) );\r
1620                         status = NDIS_STATUS_INVALID_DATA;\r
1621                 }\r
1622                 else\r
1623                 {\r
1624                         ipoib_refresh_mcast( p_adapter, (mac_addr_t*)info_buf,\r
1625                                 (uint8_t)(info_buf_len / sizeof(mac_addr_t)) );\r
1626 \r
1627                         buf_len = info_buf_len;\r
1628                         /*\r
1629                          * Note that we don't return pending.  It will likely take longer\r
1630                          * for our SA transactions to complete than NDIS will give us\r
1631                          * before reseting the adapter.  If an SA failure is encountered,\r
1632                          * the adapter will be marked as hung and we will get reset.\r
1633                          */\r
1634                         status = NDIS_STATUS_SUCCESS;\r
1635                 }\r
1636                 break;\r
1637 \r
1638         case OID_TCP_TASK_OFFLOAD:\r
1639                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1640                         ("Port %d received set for OID_TCP_TASK_OFFLOAD\n", port_num) );\r
1641 \r
1642                 buf_len = info_buf_len;\r
1643                 status =\r
1644                         __ipoib_set_tcp_task_offload( p_adapter, info_buf, &buf_len );\r
1645                 break;\r
1646 \r
1647         /* Optional General */\r
1648         case OID_GEN_TRANSPORT_HEADER_OFFSET:\r
1649 #ifdef NDIS51_MINIPORT\r
1650         case OID_GEN_RNDIS_CONFIG_PARAMETER:\r
1651         case OID_GEN_VLAN_ID:\r
1652 #endif\r
1653                 status = NDIS_STATUS_NOT_SUPPORTED;\r
1654                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1655                         ("Port %d received an unsupported oid of 0x%.8X!\n", port_num, oid));\r
1656                 break;\r
1657 \r
1658         case OID_GEN_SUPPORTED_LIST:\r
1659         case OID_GEN_HARDWARE_STATUS:\r
1660         case OID_GEN_MEDIA_SUPPORTED:\r
1661         case OID_GEN_MEDIA_IN_USE:\r
1662         case OID_GEN_MAXIMUM_FRAME_SIZE:\r
1663         case OID_GEN_LINK_SPEED:\r
1664         case OID_GEN_TRANSMIT_BUFFER_SPACE:\r
1665         case OID_GEN_RECEIVE_BUFFER_SPACE:\r
1666         case OID_GEN_MAXIMUM_LOOKAHEAD:\r
1667         case OID_GEN_TRANSMIT_BLOCK_SIZE:\r
1668         case OID_GEN_RECEIVE_BLOCK_SIZE:\r
1669         case OID_GEN_MAXIMUM_TOTAL_SIZE:\r
1670         case OID_GEN_VENDOR_ID:\r
1671         case OID_GEN_VENDOR_DESCRIPTION:\r
1672         case OID_GEN_VENDOR_DRIVER_VERSION:\r
1673         case OID_GEN_DRIVER_VERSION:\r
1674         case OID_GEN_MAC_OPTIONS:\r
1675         case OID_GEN_MEDIA_CONNECT_STATUS:\r
1676         case OID_GEN_MAXIMUM_SEND_PACKETS:\r
1677         case OID_GEN_SUPPORTED_GUIDS:\r
1678         case OID_GEN_PHYSICAL_MEDIUM:\r
1679         default:\r
1680                 status = NDIS_STATUS_INVALID_OID;\r
1681                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1682                         ("Port %d received an invalid oid of 0x%.8X!\n", port_num, oid));\r
1683                 break;\r
1684         }\r
1685 \r
1686         if( status == NDIS_STATUS_SUCCESS )\r
1687         {\r
1688                 *p_bytes_read = buf_len;\r
1689         }\r
1690         else\r
1691         {\r
1692                 if( status == NDIS_STATUS_INVALID_LENGTH )\r
1693                 {\r
1694                         if ( !*p_bytes_needed )\r
1695                         {\r
1696                                 *p_bytes_needed = buf_len;\r
1697                         }\r
1698                 }\r
1699 \r
1700                 *p_bytes_read = 0;\r
1701         }\r
1702 \r
1703         IPOIB_EXIT( IPOIB_DBG_OID );\r
1704         return status;\r
1705 }\r
1706 \r
1707 \r
1708 //! Transfers some number of packets, specified as an array of packet pointers, over the network. \r
1709 /*  For a deserialized driver, these packets are completed asynchronously\r
1710 using NdisMSendComplete.\r
1711 IRQL <= DISPATCH_LEVEL\r
1712 \r
1713 @param adapter_context Pointer to ipoib_adapter_t structure with per NIC state\r
1714 @param packet_array Array of packets to send\r
1715 @param numPackets Number of packets in the array\r
1716 */\r
1717 void\r
1718 ipoib_send_packets(\r
1719         IN                              NDIS_HANDLE                                     adapter_context,\r
1720         IN                              PPNDIS_PACKET                           packet_array,\r
1721         IN                              UINT                                            num_packets )\r
1722 {\r
1723         ipoib_adapter_t         *p_adapter;\r
1724         ipoib_port_t            *p_port;\r
1725         UINT                            packet_num;\r
1726         PERF_DECLARE( SendPackets );\r
1727         PERF_DECLARE( PortSend );\r
1728 \r
1729         IPOIB_ENTER( IPOIB_DBG_SEND );\r
1730 \r
1731         cl_perf_start( SendPackets );\r
1732 \r
1733         CL_ASSERT( adapter_context );\r
1734         p_adapter = (ipoib_adapter_t*)adapter_context;\r
1735 \r
1736         cl_obj_lock( &p_adapter->obj );\r
1737         if( p_adapter->state != IB_PNP_PORT_ACTIVE || !p_adapter->p_port )\r
1738         {\r
1739                 cl_obj_unlock( &p_adapter->obj );\r
1740                 for( packet_num = 0; packet_num < num_packets; ++packet_num )\r
1741                 {\r
1742                         ipoib_inc_send_stat( p_adapter, IP_STAT_DROPPED, 0 );\r
1743                         NdisMSendComplete( p_adapter->h_adapter,\r
1744                                 packet_array[packet_num], NDIS_STATUS_ADAPTER_NOT_READY );\r
1745                 }\r
1746                 IPOIB_EXIT( IPOIB_DBG_SEND );\r
1747                 return;\r
1748         }\r
1749 \r
1750         p_port = p_adapter->p_port;\r
1751         cl_obj_ref( &p_port->obj );\r
1752         cl_obj_unlock( &p_adapter->obj );\r
1753 \r
1754         cl_perf_start( PortSend );\r
1755         ipoib_port_send( p_port, packet_array, num_packets );\r
1756         cl_perf_stop( &p_port->p_adapter->perf, PortSend );\r
1757         cl_obj_deref( &p_port->obj );\r
1758 \r
1759         cl_perf_stop( &p_adapter->perf, SendPackets );\r
1760 \r
1761         cl_perf_log( &p_adapter->perf, SendBundle, num_packets );\r
1762 \r
1763         IPOIB_EXIT( IPOIB_DBG_SEND );\r
1764 }\r
1765 \r
1766 \r
1767 void\r
1768 ipoib_pnp_notify(\r
1769         IN                              NDIS_HANDLE                                     adapter_context,\r
1770         IN                              NDIS_DEVICE_PNP_EVENT           pnp_event,\r
1771         IN                              PVOID                                           info_buf,\r
1772         IN                              ULONG                                           info_buf_len )\r
1773 {\r
1774         ipoib_adapter_t *p_adapter;\r
1775 \r
1776         IPOIB_ENTER( IPOIB_DBG_PNP );\r
1777 \r
1778         UNUSED_PARAM( info_buf );\r
1779         UNUSED_PARAM( info_buf_len );\r
1780 \r
1781         p_adapter = (ipoib_adapter_t*)adapter_context;\r
1782 \r
1783         IPOIB_TRACE( IPOIB_DBG_PNP, ("Event %d\n", pnp_event) );\r
1784         if( pnp_event != NdisDevicePnPEventPowerProfileChanged )\r
1785         {\r
1786                 cl_obj_lock( &p_adapter->obj );\r
1787                 p_adapter->state = IB_PNP_PORT_REMOVE;\r
1788                 cl_obj_unlock( &p_adapter->obj );\r
1789 \r
1790                 ipoib_resume_oids( p_adapter );\r
1791         }\r
1792 \r
1793         IPOIB_EXIT( IPOIB_DBG_PNP );\r
1794 }\r
1795 \r
1796 \r
1797 void\r
1798 ipoib_shutdown(\r
1799         IN                              PVOID                                           adapter_context )\r
1800 {\r
1801         IPOIB_ENTER( IPOIB_DBG_INIT );\r
1802         UNUSED_PARAM( adapter_context );\r
1803         IPOIB_EXIT( IPOIB_DBG_INIT );\r
1804 }\r
1805 \r
1806 \r
1807 void\r
1808 ipoib_resume_oids(\r
1809         IN                              ipoib_adapter_t* const          p_adapter )\r
1810 {\r
1811         ULONG                           info;\r
1812         NDIS_STATUS                     status;\r
1813         boolean_t                       pending_query, pending_set;\r
1814         pending_oid_t           query_oid = {0};\r
1815         pending_oid_t           set_oid = {0};\r
1816         KLOCK_QUEUE_HANDLE      hdl;\r
1817 \r
1818         IPOIB_ENTER( IPOIB_DBG_INIT );\r
1819 \r
1820         cl_obj_lock( &p_adapter->obj );\r
1821         /*\r
1822          * Set the status depending on our state.  Fail OID requests that\r
1823          * are pending while we reset the adapter.\r
1824          */\r
1825         switch( p_adapter->state )\r
1826         {\r
1827         case IB_PNP_PORT_ADD:\r
1828                 status = NDIS_STATUS_FAILURE;\r
1829                 break;\r
1830 \r
1831         case IB_PNP_PORT_REMOVE:\r
1832                 status = NDIS_STATUS_NOT_ACCEPTED;\r
1833                 break;\r
1834                 \r
1835         default:\r
1836                 status = NDIS_STATUS_SUCCESS;\r
1837         }\r
1838 \r
1839         pending_query = p_adapter->pending_query;\r
1840         if( pending_query )\r
1841         {\r
1842                 query_oid = p_adapter->query_oid;\r
1843                 p_adapter->pending_query = FALSE;\r
1844         }\r
1845         pending_set = p_adapter->pending_set;\r
1846         if( pending_set )\r
1847         {\r
1848                 set_oid = p_adapter->set_oid;\r
1849                 p_adapter->pending_set = FALSE;\r
1850         }\r
1851         cl_obj_unlock( &p_adapter->obj );\r
1852 \r
1853         /*\r
1854          * If we had a pending OID request for OID_GEN_LINK_SPEED,\r
1855          * complete it now.  Note that we hold the object lock since\r
1856          * NdisMQueryInformationComplete is called at DISPATCH_LEVEL.\r
1857          */\r
1858         if( pending_query )\r
1859         {\r
1860                 switch( query_oid.oid )\r
1861                 {\r
1862                 case OID_GEN_LINK_SPEED:\r
1863                         ipoib_complete_query( p_adapter, &query_oid,\r
1864                                 status, &p_adapter->rate, sizeof(p_adapter->rate) );\r
1865                         break;\r
1866 \r
1867                 case OID_GEN_MEDIA_CONNECT_STATUS:\r
1868                         info = NdisMediaStateConnected;\r
1869                         ipoib_complete_query( p_adapter, &query_oid,\r
1870                                 status, &info, sizeof(info) );\r
1871                         break;\r
1872 \r
1873                 default:\r
1874                         CL_ASSERT( query_oid.oid == OID_GEN_LINK_SPEED ||\r
1875                                 query_oid.oid == OID_GEN_MEDIA_CONNECT_STATUS );\r
1876                         break;\r
1877                 }\r
1878         }\r
1879 \r
1880         if( pending_set )\r
1881         {\r
1882                 switch( set_oid.oid )\r
1883                 {\r
1884                 case OID_GEN_CURRENT_PACKET_FILTER:\r
1885                         /* Validation already performed in the SetInformation path. */\r
1886 \r
1887                         KeAcquireInStackQueuedSpinLock( &g_ipoib.lock, &hdl );\r
1888                         cl_obj_lock( &p_adapter->obj );\r
1889                         if( !p_adapter->packet_filter && (*(PULONG)set_oid.p_buf) )\r
1890                         {\r
1891                                 cl_qlist_insert_tail(\r
1892                                         &g_ipoib.adapter_list, &p_adapter->entry );\r
1893                                 /*\r
1894                                  * Filter was zero, now non-zero.  Register IP addresses\r
1895                                  * with SA.\r
1896                                  */\r
1897                                 ipoib_reg_addrs( p_adapter );\r
1898                         }\r
1899                         else if( p_adapter->packet_filter && !(*(PULONG)set_oid.p_buf) )\r
1900                         {\r
1901                                 /* Filter was non-zero, now zero.  Deregister IP addresses. */\r
1902                                 ipoib_dereg_addrs( p_adapter );\r
1903 \r
1904                                 ASSERT( cl_qlist_count( &g_ipoib.adapter_list ) );\r
1905                                 cl_qlist_remove_item(\r
1906                                         &g_ipoib.adapter_list, &p_adapter->entry );\r
1907                         }\r
1908                         p_adapter->packet_filter = *(PULONG)set_oid.p_buf;\r
1909 \r
1910                         cl_obj_unlock( &p_adapter->obj );\r
1911                         KeReleaseInStackQueuedSpinLock( &hdl );\r
1912 \r
1913                         NdisMSetInformationComplete( p_adapter->h_adapter, status );\r
1914                         break;\r
1915 \r
1916                 case OID_GEN_NETWORK_LAYER_ADDRESSES:\r
1917                         status = __ipoib_set_net_addr( p_adapter,\r
1918                                                                                    p_adapter->set_oid.p_buf,\r
1919                                                                                    p_adapter->set_oid.buf_len,\r
1920                                                                                    p_adapter->set_oid.p_bytes_used,\r
1921                                                                                    p_adapter->set_oid.p_bytes_needed );\r
1922                         if( status != NDIS_STATUS_PENDING )\r
1923                         {\r
1924                                 NdisMSetInformationComplete( p_adapter->h_adapter, status );\r
1925                         }\r
1926                         break;\r
1927 \r
1928                 default:\r
1929                         CL_ASSERT( set_oid.oid && 0 );\r
1930                         break;\r
1931                 }\r
1932         }\r
1933 \r
1934         IPOIB_EXIT( IPOIB_DBG_INIT );\r
1935 }\r
1936 \r
1937 \r
1938 static NDIS_STATUS\r
1939 __ipoib_set_net_addr(\r
1940         IN              ipoib_adapter_t *       p_adapter,\r
1941         IN              PVOID                           info_buf,\r
1942         IN              ULONG                           info_buf_len,\r
1943                 OUT     PULONG                          p_bytes_read,\r
1944                 OUT     PULONG                          p_bytes_needed )\r
1945 {\r
1946         NDIS_STATUS                             status;\r
1947         PNETWORK_ADDRESS_LIST   p_net_addrs;\r
1948         PNETWORK_ADDRESS                p_net_addr_oid;\r
1949         PNETWORK_ADDRESS_IP             p_ip_addr;\r
1950 \r
1951         net_address_item_t              *p_addr_item;\r
1952 \r
1953         cl_status_t                             cl_status;\r
1954 \r
1955         size_t                                  idx;\r
1956         LONG                                    i;\r
1957         ULONG                                   addr_size;\r
1958         ULONG                                   total_size;\r
1959 \r
1960         uint8_t                                 port_num;\r
1961 \r
1962         IPOIB_ENTER( IPOIB_DBG_OID );\r
1963 \r
1964         status = NDIS_STATUS_SUCCESS;\r
1965         port_num = p_adapter->guids.port_num;\r
1966 \r
1967         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
1968                 ("Port %d received set for OID_GEN_NETWORK_LAYER_ADDRESSES\n",\r
1969                 port_num) );\r
1970 \r
1971         if( !info_buf )\r
1972         {\r
1973                 IPOIB_TRACE( IPOIB_DBG_ERROR,\r
1974                         ("Port %d - OID_GEN_NETWORK_LAYER_ADDRESSES - "\r
1975                         "NULL buffer\n", port_num) );\r
1976                 IPOIB_EXIT( IPOIB_DBG_OID );\r
1977                 return NDIS_STATUS_INVALID_DATA;\r
1978         }\r
1979 \r
1980         /*\r
1981          * Must use field offset because the structures define array's of size one\r
1982          * of a the incorrect type for what is really stored.\r
1983          */\r
1984         if( info_buf_len < FIELD_OFFSET(NETWORK_ADDRESS_LIST, Address) )\r
1985         {\r
1986                 IPOIB_TRACE( IPOIB_DBG_ERROR, \r
1987                         ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - "\r
1988                         "bad length of %d, not enough "\r
1989                         "for NETWORK_ADDRESS_LIST (%d)\n", port_num, info_buf_len,\r
1990                         FIELD_OFFSET(NETWORK_ADDRESS_LIST, Address)) );\r
1991                 *p_bytes_needed = FIELD_OFFSET(NETWORK_ADDRESS_LIST, Address);\r
1992                 IPOIB_EXIT( IPOIB_DBG_OID );\r
1993                 return NDIS_STATUS_INVALID_LENGTH;\r
1994         }\r
1995 \r
1996         p_net_addrs = (PNETWORK_ADDRESS_LIST)info_buf;\r
1997         if( p_net_addrs->AddressCount == 0)\r
1998         {\r
1999                 if( p_net_addrs->AddressType == NDIS_PROTOCOL_ID_TCP_IP )\r
2000                 {\r
2001                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
2002                                 ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - "\r
2003                                 "clear TCP/IP addresses\n", port_num) );\r
2004                 }\r
2005                 else\r
2006                 {\r
2007                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
2008                                 ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - "\r
2009                                 "Non TCP/IP address type of 0x%.4X on clear\n",\r
2010                                 port_num, p_net_addrs->AddressType) );\r
2011                         IPOIB_EXIT( IPOIB_DBG_OID );\r
2012                         return NDIS_STATUS_SUCCESS;\r
2013                 }\r
2014         }\r
2015 \r
2016         addr_size = FIELD_OFFSET(NETWORK_ADDRESS, Address) +\r
2017                 NETWORK_ADDRESS_LENGTH_IP;\r
2018         total_size = FIELD_OFFSET(NETWORK_ADDRESS_LIST, Address) +\r
2019                 addr_size * p_net_addrs->AddressCount;\r
2020 \r
2021         if( info_buf_len < total_size )\r
2022         {\r
2023                 IPOIB_TRACE( IPOIB_DBG_ERROR,\r
2024                         ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - "\r
2025                         "bad length of %d, %d required for %d addresses\n",\r
2026                         port_num, info_buf_len, total_size, p_net_addrs->AddressCount) );\r
2027                 *p_bytes_needed = total_size;\r
2028                 IPOIB_EXIT( IPOIB_DBG_OID );\r
2029                 return NDIS_STATUS_INVALID_LENGTH;\r
2030         }\r
2031 \r
2032         /* Lock lists for duration since SA callbacks can occur on other CPUs */\r
2033         cl_obj_lock( &p_adapter->obj );\r
2034 \r
2035         /* Set the capacity of the vector to accomodate all assinged addresses. */\r
2036         cl_status = cl_vector_set_capacity(\r
2037                 &p_adapter->ip_vector, p_net_addrs->AddressCount );\r
2038         if( cl_status != CL_SUCCESS )\r
2039         {\r
2040                 cl_obj_unlock( &p_adapter->obj );\r
2041                 IPOIB_TRACE( IPOIB_DBG_ERROR,\r
2042                         ("Port %d - OID_GEN_NETWORK_LAYER_ADDRESSES - "\r
2043                         "Failed to set IP vector capacity: %s\n",\r
2044                         CL_STATUS_MSG(cl_status)) );\r
2045                 IPOIB_EXIT( IPOIB_DBG_OID );\r
2046                 return NDIS_STATUS_RESOURCES;\r
2047         }\r
2048 \r
2049         *p_bytes_read = total_size;\r
2050 \r
2051         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
2052                 ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - List contains %d addresses\n",\r
2053                         port_num, p_net_addrs->AddressCount));\r
2054 \r
2055         /* First look for addresses we had that should be removed */\r
2056         for( idx = 0; idx != cl_vector_get_size( &p_adapter->ip_vector ); idx++ )\r
2057         {\r
2058                 p_addr_item = (net_address_item_t*)\r
2059                         cl_vector_get_ptr( &p_adapter->ip_vector, idx );\r
2060                 p_net_addr_oid = (PNETWORK_ADDRESS)p_net_addrs->Address;\r
2061 \r
2062                 for( i = 0; i < p_net_addrs->AddressCount; ++i, p_net_addr_oid =\r
2063                         (PNETWORK_ADDRESS)((uint8_t *)p_net_addr_oid +\r
2064                         FIELD_OFFSET(NETWORK_ADDRESS, Address) +\r
2065                         p_net_addr_oid->AddressLength) )\r
2066                 {\r
2067 \r
2068                         if( p_net_addr_oid->AddressType != NDIS_PROTOCOL_ID_TCP_IP )\r
2069                         {\r
2070                                 IPOIB_TRACE( IPOIB_DBG_WARN,\r
2071                                         ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Address %d is wrong type of 0x%.4X, "\r
2072                                                 "should be 0x%.4X\n", port_num, i, p_net_addr_oid->AddressType,\r
2073                                                 NDIS_PROTOCOL_ID_TCP_IP));\r
2074                                 continue;\r
2075                         }\r
2076 \r
2077                         if( p_net_addr_oid->AddressLength != NETWORK_ADDRESS_LENGTH_IP)\r
2078                         {\r
2079                                 IPOIB_TRACE( IPOIB_DBG_WARN,\r
2080                                         ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Address %d is wrong size of %d, "\r
2081                                                 "should be %d\n", port_num, i, p_net_addr_oid->AddressLength,\r
2082                                                 NETWORK_ADDRESS_LENGTH_IP));\r
2083                                 continue;\r
2084                         }\r
2085 \r
2086                         p_ip_addr = (PNETWORK_ADDRESS_IP)p_net_addr_oid->Address;\r
2087                         if( !cl_memcmp( &p_ip_addr->in_addr,\r
2088                                 &p_addr_item->address.as_ulong, sizeof(ULONG) ) )\r
2089                         {\r
2090                                 break;\r
2091                         }\r
2092                 }\r
2093 \r
2094                 if( i == p_net_addrs->AddressCount )\r
2095                 {\r
2096                         /* Didn't find a match, delete from SA */\r
2097                         IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
2098                                 ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Deleting Address %d.%d.%d.%d\n",\r
2099                                         port_num,\r
2100                                         p_addr_item->address.as_bytes[0],\r
2101                                         p_addr_item->address.as_bytes[1],\r
2102                                         p_addr_item->address.as_bytes[2],\r
2103                                         p_addr_item->address.as_bytes[3]));\r
2104 \r
2105                         if( p_addr_item->p_reg )\r
2106                         {\r
2107                                 if( p_addr_item->p_reg->h_reg_svc )\r
2108                                 {\r
2109                                         p_adapter->p_ifc->dereg_svc(\r
2110                                                 p_addr_item->p_reg->h_reg_svc, __ipoib_ats_dereg_cb );\r
2111                                 }\r
2112                                 else\r
2113                                 {\r
2114                                         cl_free( p_addr_item->p_reg );\r
2115                                 }\r
2116                                 p_addr_item->p_reg = NULL;\r
2117                         }\r
2118                         p_addr_item->address.as_ulong = 0;\r
2119                 }\r
2120         }\r
2121 \r
2122         /* Now look for new addresses */\r
2123         p_net_addr_oid = (NETWORK_ADDRESS *)p_net_addrs->Address;\r
2124         idx = 0;\r
2125         for( i = 0; i < p_net_addrs->AddressCount; i++, p_net_addr_oid =\r
2126                 (PNETWORK_ADDRESS)((uint8_t *)p_net_addr_oid +\r
2127                 FIELD_OFFSET(NETWORK_ADDRESS, Address) + p_net_addr_oid->AddressLength) )\r
2128         {\r
2129 \r
2130                 if( p_net_addr_oid->AddressType != NDIS_PROTOCOL_ID_TCP_IP )\r
2131                 {\r
2132                         IPOIB_TRACE( IPOIB_DBG_WARN,\r
2133                                 ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Address %d is wrong type of 0x%.4X, "\r
2134                                         "should be 0x%.4X\n", port_num, i, p_net_addr_oid->AddressType,\r
2135                                         NDIS_PROTOCOL_ID_TCP_IP));\r
2136                         continue;\r
2137                 }\r
2138 \r
2139                 if( p_net_addr_oid->AddressLength != NETWORK_ADDRESS_LENGTH_IP)\r
2140                 {\r
2141                         IPOIB_TRACE( IPOIB_DBG_WARN,\r
2142                                 ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Address %d is wrong size of %d, "\r
2143                                         "should be %d\n", port_num, i, p_net_addr_oid->AddressLength,\r
2144                                         NETWORK_ADDRESS_LENGTH_IP));\r
2145                         continue;\r
2146                 }\r
2147 \r
2148                 p_ip_addr = (PNETWORK_ADDRESS_IP)p_net_addr_oid->Address;\r
2149 \r
2150                 /* Size the vector as needed. */\r
2151                 if( cl_vector_get_size( &p_adapter->ip_vector ) <= idx )\r
2152                         cl_vector_set_size( &p_adapter->ip_vector, idx + 1 );\r
2153 \r
2154                 p_addr_item = cl_vector_get_ptr( &p_adapter->ip_vector, idx );\r
2155                 if( !cl_memcmp( &p_ip_addr->in_addr, &p_addr_item->address.as_ulong,\r
2156                         sizeof(ULONG) ) )\r
2157                 {\r
2158                         idx++;\r
2159                         /* Already have this address - no change needed */\r
2160                         continue;\r
2161                 }\r
2162 \r
2163                 /*\r
2164                  * Copy the address information, but don't register yet - the port\r
2165                  * could be down.\r
2166                  */\r
2167                 if( p_addr_item->p_reg )\r
2168                 {\r
2169                         /* If in use by some other address, deregister. */\r
2170                         if( p_addr_item->p_reg->h_reg_svc )\r
2171                         {\r
2172                                 p_adapter->p_ifc->dereg_svc(\r
2173                                         p_addr_item->p_reg->h_reg_svc, __ipoib_ats_dereg_cb );\r
2174                         }\r
2175                         else\r
2176                         {\r
2177                                 cl_free( p_addr_item->p_reg );\r
2178                         }\r
2179                         p_addr_item->p_reg = NULL;\r
2180                 }\r
2181                 memcpy ((void *)&p_addr_item->address.as_ulong, (const void *)&p_ip_addr->in_addr, sizeof(ULONG) );\r
2182                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
2183                         ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Adding Address %d.%d.%d.%d\n",\r
2184                         port_num,\r
2185                         p_addr_item->address.as_bytes[0],\r
2186                         p_addr_item->address.as_bytes[1],\r
2187                         p_addr_item->address.as_bytes[2],\r
2188                         p_addr_item->address.as_bytes[3]) );\r
2189                 idx++;\r
2190         }\r
2191 \r
2192         /* Now clear any extra entries that shouldn't be there. */\r
2193         while( idx < cl_vector_get_size( &p_adapter->ip_vector ) )\r
2194         {\r
2195                 p_addr_item = (net_address_item_t*)\r
2196                         cl_vector_get_ptr( &p_adapter->ip_vector,\r
2197                         cl_vector_get_size( &p_adapter->ip_vector ) - 1 );\r
2198 \r
2199                 if( p_addr_item->p_reg )\r
2200                 {\r
2201                         if( p_addr_item->p_reg->h_reg_svc )\r
2202                         {\r
2203                                 p_adapter->p_ifc->dereg_svc(\r
2204                                         p_addr_item->p_reg->h_reg_svc, __ipoib_ats_dereg_cb );\r
2205                         }\r
2206                         else\r
2207                         {\r
2208                                 cl_free( p_addr_item->p_reg );\r
2209                         }\r
2210                         p_addr_item->p_reg = NULL;\r
2211                         p_addr_item->address.as_ulong = 0;\r
2212                 }\r
2213 \r
2214                 /* No need to check return value - shrinking always succeeds. */\r
2215                 cl_vector_set_size( &p_adapter->ip_vector,\r
2216                         cl_vector_get_size( &p_adapter->ip_vector ) - 1 );\r
2217         }\r
2218 \r
2219         if( p_adapter->state == IB_PNP_PORT_ACTIVE && p_adapter->packet_filter )\r
2220                 ipoib_reg_addrs( p_adapter );\r
2221 \r
2222         cl_obj_unlock( &p_adapter->obj );\r
2223 \r
2224         IPOIB_EXIT( IPOIB_DBG_OID );\r
2225         return NDIS_STATUS_SUCCESS;\r
2226 }\r
2227 \r
2228 \r
2229 /* Object lock is held when this function is called. */\r
2230 void\r
2231 ipoib_reg_addrs(\r
2232         IN                              ipoib_adapter_t* const          p_adapter )\r
2233 {\r
2234         net_address_item_t              *p_addr_item;\r
2235 \r
2236         size_t                                  idx;\r
2237 \r
2238         uint8_t                                 port_num;\r
2239 \r
2240         ib_api_status_t                 ib_status;\r
2241         ib_reg_svc_req_t                ib_service;\r
2242         ib_gid_t                                port_gid;\r
2243 \r
2244         IPOIB_ENTER( IPOIB_DBG_OID );\r
2245 \r
2246         port_num = p_adapter->guids.port_num;\r
2247 \r
2248         /* Setup our service call with things common to all calls */\r
2249         cl_memset( &ib_service, 0, sizeof(ib_service) );\r
2250 \r
2251         /* BUGBUG Only register local subnet GID prefix for now */\r
2252         ib_gid_set_default( &port_gid, p_adapter->guids.port_guid );\r
2253         ib_service.svc_rec.service_gid          = port_gid;\r
2254 \r
2255         ib_service.svc_rec.service_pkey         = IB_DEFAULT_PKEY;\r
2256         ib_service.svc_rec.service_lease        = IB_INFINITE_SERVICE_LEASE;\r
2257 \r
2258         /* Must cast here because the service name is an array of unsigned chars but\r
2259          * strcpy want a pointer to a signed char */\r
2260         strcpy( (char *)ib_service.svc_rec.service_name, ATS_NAME );\r
2261 \r
2262         /* IP Address in question will be put in below */\r
2263         ib_service.port_guid            = p_adapter->guids.port_guid;\r
2264         ib_service.timeout_ms           = p_adapter->params.sa_timeout;\r
2265         ib_service.retry_cnt            = p_adapter->params.sa_retry_cnt;\r
2266 \r
2267         /* Can't set IB_FLAGS_SYNC here because I can't wait at dispatch */\r
2268         ib_service.flags                        = 0;\r
2269 \r
2270         /* Service context will be put in below */\r
2271 \r
2272         ib_service.svc_data_mask        = IB_SR_COMPMASK_SID            |\r
2273                                                                   IB_SR_COMPMASK_SGID           |\r
2274                                                                   IB_SR_COMPMASK_SPKEY          |\r
2275                                                                   IB_SR_COMPMASK_SLEASE         |\r
2276                                                                   IB_SR_COMPMASK_SNAME          |\r
2277                                                                   IB_SR_COMPMASK_SDATA8_12      |\r
2278                                                                   IB_SR_COMPMASK_SDATA8_13      |\r
2279                                                                   IB_SR_COMPMASK_SDATA8_14      |\r
2280                                                                   IB_SR_COMPMASK_SDATA8_15;\r
2281         ib_service.pfn_reg_svc_cb = __ipoib_ats_reg_cb;\r
2282 \r
2283         for( idx = 0; idx < cl_vector_get_size( &p_adapter->ip_vector); idx++ )\r
2284         {\r
2285                 p_addr_item = (net_address_item_t*)\r
2286                         cl_vector_get_ptr(  &p_adapter->ip_vector, idx );\r
2287 \r
2288                 if( p_addr_item->p_reg )\r
2289                         continue;\r
2290 \r
2291                 p_addr_item->p_reg = cl_zalloc( sizeof(ats_reg_t) );\r
2292                 if( !p_addr_item->p_reg )\r
2293                         break;\r
2294 \r
2295                 p_addr_item->p_reg->p_adapter = p_adapter;\r
2296 \r
2297                 ib_service.svc_context          = p_addr_item->p_reg;\r
2298 \r
2299                 ib_service.svc_rec.service_id =\r
2300                         ATS_SERVICE_ID & CL_HTON64(0xFFFFFFFFFFFFFF00);\r
2301                 /* ATS service IDs start at 0x10000CE100415453 */\r
2302                 ib_service.svc_rec.service_id |= ((uint64_t)(idx + 0x53)) << 56;\r
2303 \r
2304                 cl_memcpy( &ib_service.svc_rec.service_data8[ATS_IPV4_OFFSET],\r
2305                         p_addr_item->address.as_bytes, IPV4_ADDR_SIZE );\r
2306 \r
2307                 /* Take a reference for each service request. */\r
2308                 cl_obj_ref(&p_adapter->obj);\r
2309                 ib_status = p_adapter->p_ifc->reg_svc(\r
2310                         p_adapter->h_al, &ib_service, &p_addr_item->p_reg->h_reg_svc );\r
2311                 if( ib_status != IB_SUCCESS )\r
2312                 {\r
2313                         if( ib_status == IB_INVALID_GUID )\r
2314                         {\r
2315                                 /* If this occurs, we log the error but do not fail the OID yet */\r
2316                                 IPOIB_TRACE( IPOIB_DBG_WARN,\r
2317                                         ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - "\r
2318                                         "Failed to register IP Address "\r
2319                                         "of %d.%d.%d.%d with error IB_INVALID_GUID\n",\r
2320                                         port_num,\r
2321                                         p_addr_item->address.as_bytes[0],\r
2322                                         p_addr_item->address.as_bytes[1],\r
2323                                         p_addr_item->address.as_bytes[2],\r
2324                                         p_addr_item->address.as_bytes[3]) );\r
2325                         }\r
2326                         else\r
2327                         {\r
2328                                 /* Fatal error. */\r
2329                                 IPOIB_TRACE( IPOIB_DBG_ERROR,\r
2330                                         ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Failed to register IP Address "\r
2331                                         "of %d.%d.%d.%d with error %s\n",\r
2332                                         port_num,\r
2333                                         p_addr_item->address.as_bytes[0],\r
2334                                         p_addr_item->address.as_bytes[1],\r
2335                                         p_addr_item->address.as_bytes[2],\r
2336                                         p_addr_item->address.as_bytes[3],\r
2337                                         p_adapter->p_ifc->get_err_str( ib_status )) );\r
2338                                 p_adapter->hung = TRUE;\r
2339                         }\r
2340                         cl_obj_deref(&p_adapter->obj);\r
2341                         cl_free( p_addr_item->p_reg );\r
2342                         p_addr_item->p_reg = NULL;\r
2343                 }\r
2344         }\r
2345 \r
2346         IPOIB_EXIT( IPOIB_DBG_OID );\r
2347 }\r
2348 \r
2349 \r
2350 /* Object lock is held when this function is called. */\r
2351 void\r
2352 ipoib_dereg_addrs(\r
2353         IN                              ipoib_adapter_t* const          p_adapter )\r
2354 {\r
2355         net_address_item_t              *p_addr_item;\r
2356 \r
2357         size_t                                  idx;\r
2358 \r
2359         IPOIB_ENTER( IPOIB_DBG_OID );\r
2360 \r
2361         for( idx = 0; idx < cl_vector_get_size( &p_adapter->ip_vector); idx++ )\r
2362         {\r
2363                 p_addr_item = (net_address_item_t*)\r
2364                         cl_vector_get_ptr( &p_adapter->ip_vector, idx );\r
2365 \r
2366                 if( !p_addr_item->p_reg )\r
2367                         continue;\r
2368 \r
2369                 if( p_addr_item->p_reg->h_reg_svc )\r
2370                 {\r
2371                         p_adapter->p_ifc->dereg_svc(\r
2372                                 p_addr_item->p_reg->h_reg_svc, __ipoib_ats_dereg_cb );\r
2373                 }\r
2374                 else\r
2375                 {\r
2376                         cl_free( p_addr_item->p_reg );\r
2377                 }\r
2378                 p_addr_item->p_reg = NULL;\r
2379         }\r
2380 \r
2381         IPOIB_EXIT( IPOIB_DBG_OID );\r
2382 }\r
2383 \r
2384 \r
2385 static void\r
2386 __ipoib_ats_reg_cb(\r
2387         IN                              ib_reg_svc_rec_t                        *p_reg_svc_rec )\r
2388 {\r
2389         ats_reg_t                               *p_reg;\r
2390         uint8_t                                 port_num;\r
2391 \r
2392         IPOIB_ENTER( IPOIB_DBG_OID );\r
2393 \r
2394         CL_ASSERT( p_reg_svc_rec );\r
2395         CL_ASSERT( p_reg_svc_rec->svc_context );\r
2396 \r
2397         p_reg = (ats_reg_t* __ptr64)p_reg_svc_rec->svc_context;\r
2398         port_num = p_reg->p_adapter->guids.port_num;\r
2399 \r
2400         cl_obj_lock( &p_reg->p_adapter->obj );\r
2401 \r
2402         if( p_reg_svc_rec->req_status == IB_SUCCESS &&\r
2403                 !p_reg_svc_rec->resp_status )\r
2404         {\r
2405                 IPOIB_TRACE( IPOIB_DBG_OID | IPOIB_DBG_INFO,\r
2406                                          ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Registered IP Address "\r
2407                                           "of %d.%d.%d.%d\n",\r
2408                                           port_num,\r
2409                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET],\r
2410                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET+1],\r
2411                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET+2],\r
2412                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET+3]) );\r
2413         }\r
2414         else if( p_reg_svc_rec->req_status != IB_CANCELED )\r
2415         {\r
2416                 IPOIB_TRACE( IPOIB_DBG_ERROR,\r
2417                                          ("Port %d OID_GEN_NETWORK_LAYER_ADDRESSES - Failed to register IP Address "\r
2418                                           "of %d.%d.%d.%d with error %s\n",\r
2419                                           port_num,\r
2420                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET],\r
2421                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET+1],\r
2422                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET+2],\r
2423                                           p_reg_svc_rec->svc_rec.service_data8[ATS_IPV4_OFFSET+3],\r
2424                                           p_reg->p_adapter->p_ifc->get_err_str( p_reg_svc_rec->resp_status )) );\r
2425                 p_reg->p_adapter->hung = TRUE;\r
2426                 p_reg->h_reg_svc = NULL;\r
2427         }\r
2428 \r
2429         cl_obj_unlock( &p_reg->p_adapter->obj );\r
2430         cl_obj_deref(&p_reg->p_adapter->obj);\r
2431 \r
2432         IPOIB_EXIT( IPOIB_DBG_OID );\r
2433 }\r
2434 \r
2435 \r
2436 static void\r
2437 __ipoib_ats_dereg_cb(\r
2438         IN                              void                                            *context )\r
2439 {\r
2440         cl_free( context );\r
2441 }\r