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