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