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