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