0bc3ebd55a07920fbe8872ba7e2ab1623f542705
[mirror/winof/.git] / ulp / ipoib_NDIS6_CM / 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: ipoib_driver.c 4506 2009-06-23 14:40:54Z xalex $\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 #define MAJOR_DRIVER_VERSION 2\r
58 #define MINOR_DRIVER_VERSION 1\r
59 #if defined(NDIS60_MINIPORT)\r
60 #define MAJOR_NDIS_VERSION 6\r
61 #define MINOR_NDIS_VERSION 0\r
62 \r
63 #else\r
64 #error NDIS Version not defined, try defining NDIS60_MINIPORT\r
65 #endif\r
66 \r
67 PDRIVER_OBJECT                          g_p_drv_obj;\r
68 \r
69 \r
70 #if 0\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 #endif\r
125 \r
126 NDIS_OID NICSupportedOidsTest[] =\r
127 {\r
128     OID_GEN_SUPPORTED_LIST,\r
129     OID_GEN_HARDWARE_STATUS,\r
130     OID_GEN_MEDIA_SUPPORTED,\r
131     OID_GEN_MEDIA_IN_USE,\r
132     OID_GEN_MAXIMUM_LOOKAHEAD,\r
133     OID_GEN_MAXIMUM_FRAME_SIZE,\r
134     OID_GEN_TRANSMIT_BUFFER_SPACE,\r
135     OID_GEN_RECEIVE_BUFFER_SPACE,\r
136     OID_GEN_TRANSMIT_BLOCK_SIZE,\r
137     OID_GEN_RECEIVE_BLOCK_SIZE,\r
138     OID_GEN_VENDOR_ID,\r
139     OID_GEN_VENDOR_DESCRIPTION,\r
140     OID_GEN_VENDOR_DRIVER_VERSION,\r
141     OID_GEN_CURRENT_PACKET_FILTER,\r
142     OID_GEN_CURRENT_LOOKAHEAD,\r
143     OID_GEN_DRIVER_VERSION,\r
144     OID_GEN_MAXIMUM_TOTAL_SIZE,\r
145     OID_GEN_MAC_OPTIONS,\r
146     OID_GEN_MAXIMUM_SEND_PACKETS,\r
147     OID_GEN_XMIT_OK,\r
148     OID_GEN_RCV_OK,\r
149     OID_GEN_XMIT_ERROR,\r
150     OID_GEN_RCV_ERROR,\r
151     OID_GEN_RCV_NO_BUFFER,\r
152     OID_GEN_RCV_CRC_ERROR,\r
153     OID_GEN_TRANSMIT_QUEUE_LENGTH,\r
154     OID_802_3_PERMANENT_ADDRESS,\r
155     OID_802_3_CURRENT_ADDRESS,\r
156     OID_802_3_MULTICAST_LIST,\r
157     OID_802_3_MAXIMUM_LIST_SIZE,\r
158     OID_802_3_RCV_ERROR_ALIGNMENT,\r
159     OID_802_3_XMIT_ONE_COLLISION,\r
160     OID_802_3_XMIT_MORE_COLLISIONS,\r
161     OID_802_3_XMIT_DEFERRED,\r
162     OID_802_3_XMIT_MAX_COLLISIONS,\r
163     OID_802_3_RCV_OVERRUN,\r
164     OID_802_3_XMIT_UNDERRUN,\r
165     OID_802_3_XMIT_HEARTBEAT_FAILURE,\r
166     OID_802_3_XMIT_TIMES_CRS_LOST,\r
167     OID_802_3_XMIT_LATE_COLLISIONS,\r
168 \r
169 #if !BUILD_W2K\r
170     OID_GEN_PHYSICAL_MEDIUM,\r
171 #endif\r
172 \r
173     OID_TCP_TASK_OFFLOAD,\r
174     \r
175 /* powermanagement */\r
176 \r
177     OID_PNP_CAPABILITIES,\r
178     OID_PNP_SET_POWER,\r
179     OID_PNP_QUERY_POWER,\r
180     OID_PNP_ADD_WAKE_UP_PATTERN,\r
181     OID_PNP_REMOVE_WAKE_UP_PATTERN,\r
182     OID_PNP_ENABLE_WAKE_UP,\r
183 \r
184 \r
185 /* custom oid WMI support */\r
186 //    OID_CUSTOM_PERF_COUNTERS,\r
187  //   OID_CUSTOM_STRING,\r
188 \r
189     OID_GEN_RECEIVE_SCALE_CAPABILITIES,\r
190     OID_GEN_RECEIVE_SCALE_PARAMETERS,\r
191 \r
192 //\r
193 // new and required for NDIS 6 miniports\r
194 //\r
195     OID_GEN_LINK_PARAMETERS,\r
196     OID_GEN_INTERRUPT_MODERATION,\r
197     OID_GEN_STATISTICS,\r
198 \r
199 /* Offload */\r
200     OID_TCP_OFFLOAD_CURRENT_CONFIG,\r
201     OID_TCP_OFFLOAD_PARAMETERS,\r
202     OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES,\r
203     OID_OFFLOAD_ENCAPSULATION,\r
204 \r
205 /* Header - Data seperation */\r
206    // OID_GEN_HD_SPLIT_PARAMETERS,\r
207  //   OID_GEN_HD_SPLIT_CURRENT_CONFIG,\r
208     \r
209 /* VLAN */\r
210   //  OID_ADD_VALN_ID,\r
211  //   OID_DELETE_VLAN_ID,\r
212 \r
213 /* Set MAC */\r
214   //  OID_SET_MAC_ADDRESS\r
215 \r
216 };\r
217 \r
218 static const NDIS_OID SUPPORTED_OIDS[] =\r
219 {\r
220     OID_GEN_SUPPORTED_LIST,\r
221     OID_GEN_HARDWARE_STATUS,\r
222     OID_GEN_MEDIA_SUPPORTED,\r
223     OID_GEN_MEDIA_IN_USE,\r
224     OID_GEN_MAXIMUM_LOOKAHEAD,\r
225     OID_GEN_MAXIMUM_FRAME_SIZE,\r
226     OID_GEN_TRANSMIT_BUFFER_SPACE,\r
227     OID_GEN_RECEIVE_BUFFER_SPACE,\r
228     OID_GEN_TRANSMIT_BLOCK_SIZE,\r
229     OID_GEN_RECEIVE_BLOCK_SIZE,\r
230     OID_GEN_VENDOR_ID,\r
231     OID_GEN_VENDOR_DESCRIPTION,\r
232     OID_GEN_VENDOR_DRIVER_VERSION,\r
233     OID_GEN_CURRENT_PACKET_FILTER,\r
234     OID_GEN_CURRENT_LOOKAHEAD,\r
235     OID_GEN_DRIVER_VERSION,\r
236     OID_GEN_MAXIMUM_TOTAL_SIZE,\r
237     OID_GEN_MAC_OPTIONS,\r
238     OID_GEN_MAXIMUM_SEND_PACKETS,\r
239     OID_GEN_XMIT_OK,\r
240     OID_GEN_RCV_OK,\r
241     OID_GEN_XMIT_ERROR,\r
242     OID_GEN_RCV_ERROR,\r
243     OID_GEN_RCV_NO_BUFFER,\r
244     OID_GEN_RCV_CRC_ERROR,\r
245     OID_GEN_TRANSMIT_QUEUE_LENGTH,\r
246     OID_802_3_PERMANENT_ADDRESS,\r
247     OID_802_3_CURRENT_ADDRESS,\r
248     OID_802_3_MULTICAST_LIST,\r
249     OID_802_3_MAXIMUM_LIST_SIZE,\r
250     OID_802_3_RCV_ERROR_ALIGNMENT,\r
251     OID_802_3_XMIT_ONE_COLLISION,\r
252     OID_802_3_XMIT_MORE_COLLISIONS,\r
253     OID_802_3_XMIT_DEFERRED,\r
254     OID_802_3_XMIT_MAX_COLLISIONS,\r
255     OID_802_3_RCV_OVERRUN,\r
256     OID_802_3_XMIT_UNDERRUN,\r
257     OID_802_3_XMIT_HEARTBEAT_FAILURE,\r
258     OID_802_3_XMIT_TIMES_CRS_LOST,\r
259     OID_802_3_XMIT_LATE_COLLISIONS,\r
260 \r
261 #if !BUILD_W2K\r
262     OID_GEN_PHYSICAL_MEDIUM,\r
263 #endif\r
264 \r
265     OID_TCP_TASK_OFFLOAD,\r
266     \r
267 /* powermanagement */\r
268 \r
269     OID_PNP_CAPABILITIES,\r
270     OID_PNP_SET_POWER,\r
271     OID_PNP_QUERY_POWER,\r
272     OID_PNP_ADD_WAKE_UP_PATTERN,\r
273     OID_PNP_REMOVE_WAKE_UP_PATTERN,\r
274     OID_PNP_ENABLE_WAKE_UP,\r
275 \r
276 #if 0\r
277 /* custom oid WMI support */\r
278     OID_CUSTOM_PERF_COUNTERS,\r
279     OID_CUSTOM_STRING,\r
280 #endif\r
281 \r
282     OID_GEN_RECEIVE_SCALE_CAPABILITIES,\r
283     OID_GEN_RECEIVE_SCALE_PARAMETERS,\r
284    \r
285 \r
286 //\r
287 // new and required for NDIS 6 miniports\r
288 //\r
289     OID_GEN_LINK_PARAMETERS,\r
290     OID_GEN_INTERRUPT_MODERATION,\r
291     OID_GEN_STATISTICS,\r
292 \r
293 /* Offload */\r
294     OID_TCP_OFFLOAD_CURRENT_CONFIG,\r
295     OID_TCP_OFFLOAD_PARAMETERS,\r
296     OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES,\r
297     OID_OFFLOAD_ENCAPSULATION,\r
298     \r
299 #if 0\r
300 \r
301 /* Header - Data seperation */\r
302     OID_GEN_HD_SPLIT_PARAMETERS,\r
303     OID_GEN_HD_SPLIT_CURRENT_CONFIG,\r
304 \r
305 /* VLAN */\r
306     OID_ADD_VALN_ID,\r
307     OID_DELETE_VLAN_ID,\r
308 \r
309 \r
310 /* Set MAC */\r
311     OID_SET_MAC_ADDRESS\r
312 #endif\r
313 \r
314 };\r
315 \r
316 static const unsigned char VENDOR_ID[] = {0x00, 0x06, 0x6A, 0x00};\r
317 \r
318 #define VENDOR_DESCRIPTION "Internet Protocol over InfiniBand"\r
319 \r
320 #define IB_INFINITE_SERVICE_LEASE       0xFFFFFFFF\r
321 \r
322 //The mask is 8 bit and can't contain more than 6 non-zero bits\r
323 #define MAX_GUID_MAX 0xFC\r
324 \r
325 \r
326 /* Global driver debug level */\r
327 uint32_t                g_ipoib_dbg_level = TRACE_LEVEL_ERROR;\r
328 uint32_t                g_ipoib_dbg_flags = 0x00000fff;\r
329 ipoib_globals_t g_ipoib = {0};\r
330 NDIS_HANDLE             g_IpoibMiniportDriverHandle = NULL;\r
331 NDIS_HANDLE             g_IpoibDriverContext = NULL;\r
332 \r
333 \r
334 \r
335 typedef struct _IPOIB_REG_ENTRY\r
336 {\r
337         NDIS_STRING RegName;                // variable name text\r
338         BOOLEAN     bRequired;              // 1 -> required, 0 -> optional\r
339         UINT        FieldOffset;            // offset in parent struct\r
340         UINT        FieldSize;              // size (in bytes) of the field\r
341         UINT        Default;                // default value to use\r
342         UINT        Min;                    // minimum value allowed\r
343         UINT        Max;                    // maximum value allowed\r
344 } IPOIB_REG_ENTRY, *PIPOIB_REG_ENTRY;\r
345 \r
346 IPOIB_REG_ENTRY HCARegTable[] = {\r
347         // reg value name             If Required  Offset in parentr struct             Field size                  Default         Min     Max\r
348         {NDIS_STRING_CONST("GUIDMask"),         0, IPOIB_OFFSET(guid_mask),             IPOIB_SIZE(guid_mask),          0,          0,    MAX_GUID_MAX},\r
349         /* GUIDMask should be the first element */\r
350         {NDIS_STRING_CONST("RqDepth"),          1, IPOIB_OFFSET(rq_depth),              IPOIB_SIZE(rq_depth),           512,        128,    1024},\r
351         {NDIS_STRING_CONST("RqLowWatermark"),   0, IPOIB_OFFSET(rq_low_watermark),      IPOIB_SIZE(rq_low_watermark),   4,          2,      8},\r
352         {NDIS_STRING_CONST("SqDepth"),          1, IPOIB_OFFSET(sq_depth),              IPOIB_SIZE(sq_depth),           512,        128,    1024},\r
353         {NDIS_STRING_CONST("SendChksum"),       1, IPOIB_OFFSET(send_chksum_offload),   IPOIB_SIZE(send_chksum_offload),CSUM_ENABLED,CSUM_DISABLED,CSUM_BYPASS},\r
354         {NDIS_STRING_CONST("RecvChksum"),       1, IPOIB_OFFSET(recv_chksum_offload),   IPOIB_SIZE(recv_chksum_offload),CSUM_ENABLED,CSUM_DISABLED,CSUM_BYPASS},\r
355         {NDIS_STRING_CONST("SaTimeout"),        1, IPOIB_OFFSET(sa_timeout),            IPOIB_SIZE(sa_timeout),         1000,       250,    UINT_MAX},\r
356         {NDIS_STRING_CONST("SaRetries"),        1, IPOIB_OFFSET(sa_retry_cnt),          IPOIB_SIZE(sa_retry_cnt),       10,         1,      UINT_MAX},\r
357         {NDIS_STRING_CONST("RecvRatio"),        1, IPOIB_OFFSET(recv_pool_ratio),       IPOIB_SIZE(recv_pool_ratio),    1,          1,      10},\r
358         {NDIS_STRING_CONST("PayloadMtu"),       1, IPOIB_OFFSET(payload_mtu),           IPOIB_SIZE(payload_mtu),        2044,       512,   MAX_UD_PAYLOAD_MTU},\r
359         {NDIS_STRING_CONST("lso"),              0, IPOIB_OFFSET(lso),                   IPOIB_SIZE(lso),                0,          0,      1},\r
360         {NDIS_STRING_CONST("MCLeaveRescan"),    1, IPOIB_OFFSET(mc_leave_rescan),       IPOIB_SIZE(mc_leave_rescan),    260,        1,    3600},\r
361         {NDIS_STRING_CONST("BCJoinRetry"),          1, IPOIB_OFFSET(bc_join_retry),                 IPOIB_SIZE(bc_join_retry),      50,         0,    1000},\r
362         {NDIS_STRING_CONST("CmEnabled"),        0, IPOIB_OFFSET(cm_enabled),            IPOIB_SIZE(cm_enabled),         FALSE,     FALSE, TRUE},\r
363         {NDIS_STRING_CONST("CmPayloadMtu"),     1, IPOIB_OFFSET(cm_payload_mtu),        IPOIB_SIZE(cm_payload_mtu),     MAX_CM_PAYLOAD_MTU, 512, MAX_CM_PAYLOAD_MTU}\r
364 \r
365 };  \r
366 \r
367 #define IPOIB_NUM_REG_PARAMS (sizeof (HCARegTable) / sizeof(IPOIB_REG_ENTRY))\r
368 \r
369 \r
370 void\r
371 ipoib_create_log(\r
372         NDIS_HANDLE h_adapter,\r
373         UINT ind,\r
374         ULONG eventLogMsgId)\r
375 \r
376 {\r
377 #define cMaxStrLen  40\r
378 #define cArrLen  3\r
379 \r
380         PWCHAR logMsgArray[cArrLen]; \r
381         WCHAR strVal[cMaxStrLen];\r
382         NDIS_STRING AdapterInstanceName;\r
383 \r
384         IPOIB_INIT_NDIS_STRING(&AdapterInstanceName);\r
385         if (NdisMQueryAdapterInstanceName(&AdapterInstanceName, h_adapter)!= NDIS_STATUS_SUCCESS ){\r
386                 ASSERT(FALSE);\r
387                 IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR,IPOIB_DBG_ERROR, ("[IPoIB] Init:Failed to retreive adapter name.\n"));\r
388                 return;\r
389         }\r
390         logMsgArray[0] = AdapterInstanceName.Buffer;\r
391         \r
392         if (RtlStringCbPrintfW(strVal, sizeof(strVal), L"0x%x", HCARegTable[ind].Default) != STATUS_SUCCESS) {\r
393                 ASSERT(FALSE);\r
394                 IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR,IPOIB_DBG_ERROR,\r
395                 ("[IPoIB] Init: Problem copying string value: exiting\n"));   \r
396                 return;\r
397         }\r
398         \r
399         logMsgArray[0] = AdapterInstanceName.Buffer;\r
400         logMsgArray[1] = HCARegTable[ind].RegName.Buffer;\r
401         logMsgArray[2] = strVal;\r
402         \r
403         NdisWriteEventLogEntry(g_p_drv_obj, eventLogMsgId, 0, cArrLen, &logMsgArray, 0, NULL);\r
404 \r
405 }\r
406 \r
407 \r
408 \r
409 NTSTATUS\r
410 DriverEntry(\r
411         IN                              PDRIVER_OBJECT                          p_drv_obj,\r
412         IN                              PUNICODE_STRING                         p_reg_path );\r
413 \r
414 VOID\r
415 ipoib_unload(\r
416         IN                              PDRIVER_OBJECT                          p_drv_obj );\r
417 \r
418 NDIS_STATUS\r
419 ipoib_initialize_ex(\r
420         IN                              NDIS_HANDLE                     h_adapter,\r
421     IN                          NDIS_HANDLE             config_context,\r
422     IN PNDIS_MINIPORT_INIT_PARAMETERS   MiniportInitParameters);\r
423 \r
424 NDIS_STATUS \r
425 MPInitializeTest(\r
426     IN  NDIS_HANDLE                        MiniportAdapterHandle,\r
427     IN  NDIS_HANDLE                        MiniportDriverContext,\r
428     IN  PNDIS_MINIPORT_INIT_PARAMETERS     MiniportInitParameters\r
429     );\r
430 \r
431 \r
432 \r
433 BOOLEAN\r
434 ipoib_check_for_hang(\r
435         IN                              NDIS_HANDLE                                     adapter_context );\r
436 \r
437 void\r
438 ipoib_halt_ex(\r
439         IN NDIS_HANDLE  adapter_context,\r
440         IN                      NDIS_HALT_ACTION            HaltAction);\r
441 \r
442 NDIS_STATUS\r
443 ipoib_query_info(\r
444         IN                              NDIS_HANDLE                                     adapter_context,\r
445         IN                              NDIS_OID                                        oid,\r
446         IN                              PVOID                                           info_buf,\r
447         IN                              ULONG                                           info_buf_len,\r
448                 OUT                     PULONG                                          p_bytes_written,\r
449                 OUT                     PULONG                                          p_bytes_needed );\r
450 \r
451 \r
452 \r
453 NDIS_STATUS\r
454 ipoib_reset(\r
455     IN  NDIS_HANDLE     adapter_context,\r
456     OUT PBOOLEAN        p_addr_reset);\r
457 \r
458 NDIS_STATUS\r
459 ipoib_set_info(\r
460         IN                              NDIS_HANDLE                                     adapter_context,\r
461         IN                              NDIS_OID                                        oid,\r
462         IN                              PVOID                                           info_buf,\r
463         IN                              ULONG                                           info_buf_length,\r
464                 OUT                     PULONG                                          p_bytes_read,\r
465                 OUT                     PULONG                                          p_bytes_needed );\r
466 \r
467 //NDIS60\r
468 void\r
469 ipoib_send_net_buffer_list(\r
470     IN  NDIS_HANDLE         adapter_context,\r
471     IN  PNET_BUFFER_LIST    net_buffer_list,\r
472     IN  NDIS_PORT_NUMBER    port_num,\r
473     IN  ULONG               send_flags);\r
474 \r
475 void\r
476 ipoib_pnp_notify(\r
477         IN                              NDIS_HANDLE                                     adapter_context,\r
478         IN PNET_DEVICE_PNP_EVENT  pnp_event);\r
479 \r
480 VOID\r
481 ipoib_shutdown_ex(\r
482         IN NDIS_HANDLE  adapter_context,\r
483         IN NDIS_SHUTDOWN_ACTION  shutdown_action);\r
484 \r
485 \r
486 void\r
487 ipoib_cancel_xmit(\r
488         IN                              NDIS_HANDLE                                     adapter_context,\r
489         IN                              PVOID                                           cancel_id );\r
490 \r
491 \r
492 static void\r
493 ipoib_complete_query(\r
494         IN                              ipoib_adapter_t* const          p_adapter,\r
495         IN                              pending_oid_t* const            p_oid_info,\r
496         IN              const   NDIS_STATUS                                     status,\r
497         IN              const   void* const                                     p_buf,\r
498         IN              const   ULONG                                           buf_len );\r
499 \r
500 static NDIS_STATUS\r
501 __ipoib_set_net_addr(\r
502         IN              ipoib_adapter_t *       p_adapter,\r
503         IN              PVOID                           info_buf,\r
504         IN              ULONG                           info_buf_len,\r
505                 OUT     PULONG                          p_bytes_read,\r
506                 OUT     PULONG                          p_bytes_needed );\r
507 \r
508 static NDIS_STATUS\r
509 __ipoib_get_tcp_task_offload(\r
510         IN                              ipoib_adapter_t*                        p_adapter,\r
511         OUT                             pending_oid_t                           *pNdisRequest);\r
512 \r
513 static void\r
514 __ipoib_ats_reg_cb(\r
515         IN                              ib_reg_svc_rec_t                        *p_reg_svc_rec );\r
516 \r
517 static void\r
518 __ipoib_ats_dereg_cb(\r
519         IN                              void                                            *context );\r
520 \r
521 static NTSTATUS\r
522 __ipoib_read_registry(\r
523         IN                              UNICODE_STRING* const           p_registry_path );\r
524 \r
525 static NDIS_STATUS\r
526 ipoib_set_options(\r
527     IN NDIS_HANDLE  NdisMiniportDriverHandle,\r
528     IN NDIS_HANDLE  MiniportDriverContext);\r
529 \r
530 static NDIS_STATUS\r
531 ipoib_oid_handler(\r
532     IN  NDIS_HANDLE         adapter_context,\r
533     IN  PNDIS_OID_REQUEST   pNdisRequest);\r
534 \r
535 static void\r
536 ipoib_cancel_oid_request(\r
537     IN  NDIS_HANDLE            adapter_context,\r
538     IN  PVOID                  requestId);\r
539         \r
540 static NDIS_STATUS \r
541 ipoib_pause(\r
542     IN  NDIS_HANDLE                         adapter_context,    \r
543     IN  PNDIS_MINIPORT_PAUSE_PARAMETERS     pause_parameters);\r
544 \r
545 static NDIS_STATUS \r
546 ipoib_restart(\r
547     IN  NDIS_HANDLE                         adapter_context,    \r
548     IN  PNDIS_MINIPORT_RESTART_PARAMETERS   restart_parameters);\r
549 \r
550 \r
551 \r
552 //! Standard Windows Device Driver Entry Point\r
553 /*! DriverEntry is the first routine called after a driver is loaded, and\r
554 is responsible for initializing the driver.  On W2k this occurs when the PnP\r
555 Manager matched a PnP ID to one in an INF file that references this driver.\r
556 Any not success return value will cause the driver to fail to load.\r
557 IRQL = PASSIVE_LEVEL\r
558 \r
559 @param p_drv_obj Pointer to Driver Object for this device driver\r
560 @param p_registry_path Pointer to unicode string containing path to this driver's registry area\r
561 @return STATUS_SUCCESS, NDIS_STATUS_BAD_CHARACTERISTICS, NDIS_STATUS_BAD_VERSION,\r
562 NDIS_STATUS_RESOURCES, or NDIS_STATUS_FAILURE\r
563 */\r
564 NTSTATUS\r
565 DriverEntry(\r
566         IN                              PDRIVER_OBJECT                          p_drv_obj,\r
567         IN                              PUNICODE_STRING                         p_registry_path )\r
568 {\r
569         NDIS_STATUS                                             status;\r
570         NDIS_MINIPORT_DRIVER_CHARACTERISTICS characteristics;\r
571 \r
572         IPOIB_ENTER( IPOIB_DBG_INIT );\r
573         g_p_drv_obj = p_drv_obj;\r
574 \r
575 #ifdef _DEBUG_\r
576         PAGED_CODE();\r
577 #endif\r
578 #if defined(EVENT_TRACING)\r
579         WPP_INIT_TRACING(p_drv_obj, p_registry_path);\r
580 #endif\r
581         status = CL_INIT;\r
582         if( !NT_SUCCESS( status ) )\r
583         {\r
584                 IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
585                         ("cl_init failed.\n") );\r
586                 return status;\r
587         }\r
588 \r
589         __ipoib_read_registry(p_registry_path);\r
590         \r
591         KeInitializeSpinLock( &g_ipoib.lock );\r
592         cl_qlist_init( &g_ipoib.adapter_list );\r
593 \r
594     NdisZeroMemory(&characteristics, sizeof(characteristics));\r
595 \r
596     characteristics.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_DRIVER_CHARACTERISTICS,\r
597     characteristics.Header.Size = sizeof(NDIS_MINIPORT_DRIVER_CHARACTERISTICS);\r
598     characteristics.Header.Revision = NDIS_MINIPORT_DRIVER_CHARACTERISTICS_REVISION_1;\r
599 \r
600         characteristics.MajorNdisVersion                = MAJOR_NDIS_VERSION;\r
601         characteristics.MinorNdisVersion                = MINOR_NDIS_VERSION;\r
602     characteristics.MajorDriverVersion          = MAJOR_DRIVER_VERSION;\r
603     characteristics.MinorDriverVersion          = MINOR_DRIVER_VERSION;\r
604 \r
605 \r
606         characteristics.CheckForHangHandlerEx           = ipoib_check_for_hang;\r
607         characteristics.HaltHandlerEx                           = ipoib_halt_ex;\r
608         characteristics.InitializeHandlerEx             = ipoib_initialize_ex;// MPInitializeTest\r
609         characteristics.OidRequestHandler                       = ipoib_oid_handler;\r
610         characteristics.CancelOidRequestHandler         = ipoib_cancel_oid_request;\r
611         characteristics.ResetHandlerEx                          = ipoib_reset;\r
612         characteristics.DevicePnPEventNotifyHandler     = ipoib_pnp_notify;\r
613         characteristics.ReturnNetBufferListsHandler     = ipoib_return_net_buffer_list;\r
614         characteristics.SendNetBufferListsHandler       = ipoib_send_net_buffer_list;\r
615 \r
616         characteristics.SetOptionsHandler                       = ipoib_set_options;\r
617         characteristics.PauseHandler                            = ipoib_pause;\r
618         characteristics.RestartHandler                          = ipoib_restart;\r
619         characteristics.UnloadHandler                           = ipoib_unload;\r
620         characteristics.CancelSendHandler                       = ipoib_cancel_xmit;\r
621         characteristics.ShutdownHandlerEx                       = ipoib_shutdown_ex;\r
622 \r
623 \r
624 \r
625 //TODO NDIS60 set g_ prefix to global variables\r
626         status = NdisMRegisterMiniportDriver(\r
627                 p_drv_obj, p_registry_path,(PNDIS_HANDLE)&g_IpoibDriverContext, &characteristics,&g_IpoibMiniportDriverHandle );\r
628         if( status != NDIS_STATUS_SUCCESS )\r
629         {\r
630                 IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR, \r
631                         ("NdisMRegisterMiniportDriver failed with status of %d\n", status) );\r
632                 CL_DEINIT;\r
633         }\r
634 \r
635         IPOIB_EXIT( IPOIB_DBG_INIT );\r
636         return status;\r
637 }\r
638 \r
639 static NDIS_STATUS\r
640 ipoib_set_options(\r
641     IN NDIS_HANDLE  NdisMiniportDriverHandle,\r
642     IN NDIS_HANDLE  MiniportDriverContext\r
643     )\r
644 {\r
645         IPOIB_ENTER( IPOIB_DBG_INIT );\r
646 \r
647     UNREFERENCED_PARAMETER(NdisMiniportDriverHandle);\r
648     UNREFERENCED_PARAMETER(MiniportDriverContext);\r
649    \r
650         IPOIB_EXIT( IPOIB_DBG_INIT );\r
651     return NDIS_STATUS_SUCCESS;\r
652 }\r
653 \r
654 static NTSTATUS\r
655 __ipoib_read_registry(\r
656         IN                              UNICODE_STRING* const           p_registry_path )\r
657 {\r
658         NTSTATUS                                                status;\r
659         /* Remember the terminating entry in the table below. */\r
660         RTL_QUERY_REGISTRY_TABLE                table[4];\r
661         UNICODE_STRING                                  param_path;\r
662 \r
663         IPOIB_ENTER( IPOIB_DBG_INIT );\r
664         RtlInitUnicodeString( &param_path, NULL );\r
665         param_path.MaximumLength = p_registry_path->Length + \r
666                 sizeof(L"\\Parameters");\r
667         param_path.Buffer = cl_zalloc( param_path.MaximumLength );\r
668         if( !param_path.Buffer )\r
669         {\r
670                 IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR, \r
671                         ("Failed to allocate parameters path buffer.\n") );\r
672                 return STATUS_INSUFFICIENT_RESOURCES;\r
673         }\r
674 \r
675         RtlAppendUnicodeStringToString( &param_path, p_registry_path );\r
676         RtlAppendUnicodeToString( &param_path, L"\\Parameters" );\r
677 \r
678         /*\r
679          * Clear the table.  This clears all the query callback pointers,\r
680          * and sets up the terminating table entry.\r
681          */\r
682         cl_memclr( table, sizeof(table) );\r
683 \r
684         /* Setup the table entries. */\r
685         table[0].Flags = RTL_QUERY_REGISTRY_DIRECT;\r
686         table[0].Name = L"DebugLevel";\r
687         table[0].EntryContext = &g_ipoib_dbg_level;\r
688         table[0].DefaultType = REG_DWORD;\r
689         table[0].DefaultData = &g_ipoib_dbg_level;\r
690         table[0].DefaultLength = sizeof(ULONG);\r
691 \r
692         table[1].Flags = RTL_QUERY_REGISTRY_DIRECT;\r
693         table[1].Name = L"DebugFlags";\r
694         table[1].EntryContext = &g_ipoib_dbg_flags;\r
695         table[1].DefaultType = REG_DWORD;\r
696         table[1].DefaultData = &g_ipoib_dbg_flags;\r
697         table[1].DefaultLength = sizeof(ULONG);\r
698 \r
699         table[2].Flags = RTL_QUERY_REGISTRY_DIRECT;\r
700         table[2].Name = L"bypass_check_bcast_rate";\r
701         table[2].EntryContext = &g_ipoib.bypass_check_bcast_rate;\r
702         table[2].DefaultType = REG_DWORD;\r
703         table[2].DefaultData = &g_ipoib.bypass_check_bcast_rate;\r
704         table[2].DefaultLength = sizeof(ULONG);\r
705 \r
706         /* Have at it! */\r
707         status = RtlQueryRegistryValues( RTL_REGISTRY_ABSOLUTE, \r
708                 param_path.Buffer, table, NULL, NULL );\r
709 \r
710         IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
711                         ("debug level %d debug flags 0x%.8x\n",\r
712                         g_ipoib_dbg_level,\r
713                         g_ipoib_dbg_flags));\r
714 \r
715 #if DBG\r
716         if( g_ipoib_dbg_flags & IPOIB_DBG_ERR )\r
717                 g_ipoib_dbg_flags |= CL_DBG_ERROR;\r
718 #endif\r
719 \r
720         cl_free( param_path.Buffer );\r
721         IPOIB_EXIT( IPOIB_DBG_INIT );\r
722         return status;\r
723 }\r
724 \r
725 \r
726 VOID\r
727 ipoib_unload(\r
728         IN                              PDRIVER_OBJECT                          p_drv_obj )\r
729 {\r
730         IPOIB_ENTER( IPOIB_DBG_INIT );\r
731         UNREFERENCED_PARAMETER(p_drv_obj);\r
732         #if defined(EVENT_TRACING)\r
733         WPP_CLEANUP(p_drv_obj);\r
734         #endif\r
735         //NDIS6.0\r
736         NdisMDeregisterMiniportDriver(g_IpoibMiniportDriverHandle);\r
737         UNREFERENCED_PARAMETER( p_drv_obj );\r
738         CL_DEINIT;\r
739         IPOIB_EXIT( IPOIB_DBG_INIT );\r
740 }\r
741 \r
742 \r
743 \r
744 NDIS_STATUS\r
745 ipoib_get_adapter_params(\r
746         IN                              NDIS_HANDLE* const                      wrapper_config_context,\r
747         IN      OUT                     ipoib_adapter_t                         *p_adapter,\r
748         OUT                             PUCHAR                                          *p_mac,\r
749         OUT                             UINT                                            *p_len)\r
750 {\r
751         NDIS_STATUS                                             status;\r
752         NDIS_HANDLE                                             h_config;\r
753     NDIS_CONFIGURATION_OBJECT           config_obj;\r
754         NDIS_CONFIGURATION_PARAMETER    *p_param;\r
755         UINT                                                    value;\r
756         PIPOIB_REG_ENTRY                                pRegEntry;\r
757         UINT                                                    i;\r
758         PUCHAR                                                  structPointer;\r
759         \r
760         int sq_depth_step = 128;\r
761 \r
762         UNUSED_PARAM(wrapper_config_context);\r
763         IPOIB_ENTER( IPOIB_DBG_INIT );\r
764 \r
765     config_obj.Header.Type = NDIS_OBJECT_TYPE_CONFIGURATION_OBJECT;\r
766     config_obj.Header.Revision = NDIS_CONFIGURATION_OBJECT_REVISION_1;\r
767     config_obj.Header.Size = sizeof(NDIS_CONFIGURATION_OBJECT);\r
768     config_obj.NdisHandle = p_adapter->h_adapter;\r
769     config_obj.Flags = 0;\r
770 \r
771         status = NdisOpenConfigurationEx( &config_obj, &h_config);\r
772         if( status != NDIS_STATUS_SUCCESS )\r
773         {\r
774                 IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
775                         ("NdisOpenConfigurationEx returned 0x%.8x\n", status) );\r
776                 return status;\r
777         }\r
778 \r
779         // read all the registry values \r
780         for (i = 0, pRegEntry = HCARegTable; i < IPOIB_NUM_REG_PARAMS; ++i)\r
781         {\r
782                 // initialize pointer to appropriate place inside 'params'\r
783                 structPointer = (PUCHAR) &p_adapter->params + pRegEntry[i].FieldOffset;\r
784 \r
785                 // Get the configuration value for a specific parameter.  Under NT the\r
786                 // parameters are all read in as DWORDs.\r
787                 NdisReadConfiguration(\r
788                         &status,\r
789                         &p_param,\r
790                         h_config,\r
791                         &pRegEntry[i].RegName,\r
792                         NdisParameterInteger);\r
793 \r
794                 // If the parameter was present, then check its value for validity.\r
795                 if (status == NDIS_STATUS_SUCCESS)\r
796                 {\r
797                         // Check that param value is not too small or too large\r
798                         if (p_param->ParameterData.IntegerData < pRegEntry[i].Min ||\r
799                                 p_param->ParameterData.IntegerData > pRegEntry[i].Max)\r
800                         {\r
801                                 value = pRegEntry[i].Default;\r
802                                 ipoib_create_log(p_adapter->h_adapter, i, EVENT_IPOIB_WRONG_PARAMETER_WRN);\r
803                                 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
804 \r
805                         }\r
806                         else\r
807                         {\r
808                                 value = p_param->ParameterData.IntegerData;\r
809                                 IPOIB_PRINT(TRACE_LEVEL_VERBOSE, IPOIB_DBG_INIT, ("Read configuration. Registry %S, Value= 0x%x\n", pRegEntry[i].RegName.Buffer, value));\r
810                         }\r
811                 }\r
812 \r
813                 else\r
814                 {\r
815                         value = pRegEntry[i].Default;\r
816                         status = NDIS_STATUS_SUCCESS;\r
817                         if (pRegEntry[i].bRequired)\r
818                         {\r
819                                 ipoib_create_log(p_adapter->h_adapter, i, EVENT_IPOIB_WRONG_PARAMETER_ERR);\r
820                                 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
821                         }\r
822                         else\r
823                         {\r
824                                 ipoib_create_log(p_adapter->h_adapter, i, EVENT_IPOIB_WRONG_PARAMETER_INFO);\r
825                                 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
826                         }\r
827 \r
828                 }\r
829                 //\r
830                 // Store the value in the adapter structure.\r
831                 //\r
832                 switch(pRegEntry[i].FieldSize)\r
833                 {\r
834                         case 1:\r
835                                 *((PUCHAR) structPointer) = (UCHAR) value;\r
836                                 break;\r
837 \r
838                         case 2:\r
839                                 *((PUSHORT) structPointer) = (USHORT) value;\r
840                                 break;\r
841 \r
842                         case 4:\r
843                                 *((PULONG) structPointer) = (ULONG) value;\r
844                                 break;\r
845 \r
846                         default:\r
847                                 IPOIB_PRINT(TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR, ("Bogus field size %d\n", pRegEntry[i].FieldSize));\r
848                                 break;\r
849                 }\r
850         }\r
851 \r
852         // Send queue depth needs to be a power of two\r
853         //static const INT sq_depth_step = 128;\r
854 \r
855         if (p_adapter->params.sq_depth % sq_depth_step) {\r
856                 static const c_sq_ind = 2;\r
857                 p_adapter->params.sq_depth = sq_depth_step *(\r
858                         p_adapter->params.sq_depth / sq_depth_step + !!( (p_adapter->params.sq_depth % sq_depth_step) > (sq_depth_step/2) ));\r
859                 ipoib_create_log(p_adapter->h_adapter, c_sq_ind, EVENT_IPOIB_WRONG_PARAMETER_WRN);\r
860                 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
861 \r
862         }\r
863 \r
864 \r
865         // Adjusting the low watermark parameter\r
866         p_adapter->params.rq_low_watermark =\r
867                         p_adapter->params.rq_depth / p_adapter->params.rq_low_watermark;\r
868         \r
869         /* disable CM if LSO is active */\r
870         if( p_adapter->params.cm_enabled )\r
871         {\r
872                 p_adapter->params.cm_enabled = !p_adapter->params.lso;\r
873                 if( !p_adapter->params.cm_enabled )\r
874                 {\r
875                         NdisWriteErrorLogEntry( p_adapter->h_adapter,\r
876                                 EVENT_IPOIB_CONNECTED_MODE_ERR, 1, 0xbadc0de0 );\r
877                 }\r
878         }\r
879 \r
880         if( p_adapter->params.cm_enabled )\r
881         {\r
882                 p_adapter->params.cm_xfer_block_size = \r
883                         (sizeof(eth_hdr_t) + p_adapter->params.cm_payload_mtu);\r
884         }\r
885 \r
886                 p_adapter->params.xfer_block_size = \r
887                         (sizeof(eth_hdr_t) + p_adapter->params.payload_mtu);\r
888 \r
889         NdisReadNetworkAddress( &status, p_mac, p_len, h_config );\r
890 \r
891         NdisCloseConfiguration( h_config );\r
892 \r
893         IPOIB_EXIT( IPOIB_DBG_INIT );\r
894         return NDIS_STATUS_SUCCESS;\r
895 }\r
896 \r
897 \r
898 NDIS_STATUS\r
899 ipoib_get_adapter_guids(\r
900         IN                              NDIS_HANDLE* const                      h_adapter,\r
901         IN      OUT                     ipoib_adapter_t                         *p_adapter )\r
902 {\r
903         NTSTATUS                        status;\r
904         ib_al_ifc_data_t        data;\r
905         IO_STACK_LOCATION       io_stack, *p_fwd_io_stack;\r
906         DEVICE_OBJECT           *p_pdo;\r
907         IRP                                     *p_irp;\r
908         KEVENT                          event;\r
909         IO_STATUS_BLOCK         io_status;\r
910 \r
911         IPOIB_ENTER( IPOIB_DBG_INIT );\r
912 \r
913         NdisMGetDeviceProperty( h_adapter, &p_pdo, NULL, NULL, NULL, NULL );\r
914 \r
915         /* Query for our interface */\r
916         data.size = sizeof(ipoib_ifc_data_t);\r
917         data.version = IPOIB_INTERFACE_DATA_VERSION;\r
918         data.type = &GUID_IPOIB_INTERFACE_DATA;\r
919         data.p_data = &p_adapter->guids;\r
920 \r
921         io_stack.MinorFunction = IRP_MN_QUERY_INTERFACE;\r
922         io_stack.Parameters.QueryInterface.Version = AL_INTERFACE_VERSION;\r
923         io_stack.Parameters.QueryInterface.Size = sizeof(ib_al_ifc_t);\r
924         io_stack.Parameters.QueryInterface.Interface =\r
925                 (INTERFACE*)p_adapter->p_ifc;\r
926         io_stack.Parameters.QueryInterface.InterfaceSpecificData = &data;\r
927         io_stack.Parameters.QueryInterface.InterfaceType = \r
928                 &GUID_IB_AL_INTERFACE;\r
929 \r
930         KeInitializeEvent( &event, NotificationEvent, FALSE );\r
931 \r
932         /* Build the IRP for the HCA. */\r
933         p_irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP, p_pdo,\r
934                 NULL, 0, NULL, &event, &io_status );\r
935         if( !p_irp )\r
936         {\r
937                 IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
938                         ("Failed to allocate query interface IRP.\n") );\r
939                 return STATUS_INSUFFICIENT_RESOURCES;\r
940         }\r
941 \r
942         /* Copy the request query parameters. */\r
943         p_fwd_io_stack = IoGetNextIrpStackLocation( p_irp );\r
944         p_fwd_io_stack->MinorFunction = IRP_MN_QUERY_INTERFACE;\r
945         p_fwd_io_stack->Parameters.QueryInterface =\r
946                 io_stack.Parameters.QueryInterface;\r
947         p_irp->IoStatus.Status = STATUS_NOT_SUPPORTED;\r
948 \r
949         /* Send the IRP. */\r
950         status = IoCallDriver( p_pdo, p_irp );\r
951         if( status == STATUS_PENDING )\r
952         {\r
953                 KeWaitForSingleObject( &event, Executive, KernelMode,\r
954                         FALSE, NULL );\r
955                 status = io_status.Status;\r
956         }\r
957 \r
958         if( !NT_SUCCESS( status ) )\r
959         {\r
960                 IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
961                         ("Query interface for IPOIB interface returned %08x.\n", status) );\r
962                 return status;\r
963         }\r
964 \r
965         /*\r
966          * Dereference the interface now so that the bus driver doesn't fail a\r
967          * query remove IRP.  We will always get unloaded before the bus driver\r
968          * since we're a child device.\r
969          */\r
970         if (p_adapter->p_ifc)\r
971         p_adapter->p_ifc->wdm.InterfaceDereference(\r
972                 p_adapter->p_ifc->wdm.Context );\r
973         IPOIB_EXIT( IPOIB_DBG_INIT );\r
974         return NDIS_STATUS_SUCCESS;\r
975 }\r
976 \r
977 \r
978 //! Initialization function called for each IOC discovered\r
979 /*  The MiniportInitialize function is a required function that sets up a\r
980 NIC (or virtual NIC) for network I/O operations, claims all hardware\r
981 resources necessary to the NIC in the registry, and allocates resources\r
982 the driver needs to carry out network I/O operations.\r
983 IRQL = PASSIVE_LEVEL\r
984 \r
985 @param p_open_status Pointer to a status field set if this function returns NDIS_STATUS_OPEN_ERROR\r
986 @param p_selected_medium_index Pointer to unsigned integer noting index into medium_array for this NIC\r
987 @param medium_array Array of mediums for this NIC\r
988 @param medium_array_size Number of elements in medium_array\r
989 @param h_adapter Handle assigned by NDIS for this NIC\r
990 @param wrapper_config_context Handle used for Ndis initialization functions\r
991 @return NDIS_STATUS_SUCCESS, NDIS_STATUS_UNSUPPORTED_MEDIA, NDIS_STATUS_RESOURCES,\r
992 NDIS_STATUS_NOT_SUPPORTED \r
993 */\r
994 \r
995 /*void foo1(int i)\r
996 {\r
997                 char temp[5200];\r
998                 if (i ==0) return;\r
999                 cl_msg_out("i = %d\n", i);\r
1000                 foo1(i-1);\r
1001          \r
1002 }*/\r
1003         \r
1004 NDIS_STATUS\r
1005 SetDeviceRegistrationAttributes(\r
1006         ipoib_adapter_t *p_adapter,\r
1007     NDIS_HANDLE h_adapter\r
1008     )\r
1009 {\r
1010     NDIS_MINIPORT_ADD_DEVICE_REGISTRATION_ATTRIBUTES atr;\r
1011     NTSTATUS Status;\r
1012 \r
1013     NdisZeroMemory(&atr, sizeof(NDIS_MINIPORT_ADD_DEVICE_REGISTRATION_ATTRIBUTES));\r
1014 \r
1015     //\r
1016     // setting registration attributes\r
1017     //\r
1018     atr.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADD_DEVICE_REGISTRATION_ATTRIBUTES;\r
1019     atr.Header.Revision = NDIS_MINIPORT_ADD_DEVICE_REGISTRATION_ATTRIBUTES_REVISION_1;\r
1020     atr.Header.Size = NDIS_SIZEOF_MINIPORT_ADD_DEVICE_REGISTRATION_ATTRIBUTES_REVISION_1;\r
1021 \r
1022 \r
1023     atr.MiniportAddDeviceContext = (NDIS_HANDLE)p_adapter;\r
1024     atr.Flags = 0; \r
1025 \r
1026     Status = NdisMSetMiniportAttributes(h_adapter,\r
1027                     (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&atr);\r
1028 \r
1029     return Status;\r
1030 }\r
1031 \r
1032 //NDIS 6.1\r
1033 #if 0\r
1034 NDIS_STATUS\r
1035 SetHardwareAssistAttributes(\r
1036     ipoib_adapter_t *p_adapter,\r
1037     NDIS_HANDLE h_adapter\r
1038     )\r
1039 {\r
1040     NDIS_MINIPORT_ADAPTER_HARDWARE_ASSIST_ATTRIBUTES atr;\r
1041     NTSTATUS Status;\r
1042 \r
1043     NdisZeroMemory(&atr, sizeof(NDIS_MINIPORT_ADAPTER_HARDWARE_ASSIST_ATTRIBUTES));\r
1044 \r
1045     //\r
1046     // setting registration attributes\r
1047     //\r
1048     atr.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_HARDWARE_ASSIST_ATTRIBUTES;\r
1049     atr.Header.Revision = NDIS_MINIPORT_ADAPTER_HARDWARE_ASSIST_ATTRIBUTES_REVISION_1;\r
1050     atr.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_HARDWARE_ASSIST_ATTRIBUTES_REVISION_1;\r
1051 \r
1052     NDIS_HD_SPLIT_ATTRIBUTES nhsa;\r
1053     NdisZeroMemory(&nhsa, sizeof(nhsa));\r
1054 \r
1055     nhsa.Header.Type = NDIS_OBJECT_TYPE_HD_SPLIT_ATTRIBUTES;\r
1056     nhsa.Header.Revision = NDIS_OFFLOAD_REVISION_1;\r
1057     nhsa.Header.Size = NDIS_SIZEOF_HD_SPLIT_ATTRIBUTES_REVISION_1;\r
1058 \r
1059     // BUGBUG: We are just cheating here ...\r
1060     nhsa.HardwareCapabilities = NDIS_HD_SPLIT_CAPS_SUPPORTS_HEADER_DATA_SPLIT;\r
1061 #if 0\r
1062     ... Only supported on B0\r
1063 \r
1064                                  NDIS_HD_SPLIT_CAPS_SUPPORTS_IPV4_OPTIONS |\r
1065                                  NDIS_HD_SPLIT_CAPS_SUPPORTS_IPV6_EXTENSION_HEADERS |\r
1066                                  NDIS_HD_SPLIT_CAPS_SUPPORTS_TCP_OPTIONS;\r
1067 #endif\r
1068 \r
1069     // The bellow should be left zero\r
1070     if (pPort->Config.HeaderDataSplit) {\r
1071         nhsa.CurrentCapabilities = NDIS_HD_SPLIT_CAPS_SUPPORTS_HEADER_DATA_SPLIT;\r
1072     } else {\r
1073         nhsa.CurrentCapabilities = 0;\r
1074     }\r
1075 \r
1076     nhsa.HDSplitFlags = 0;\r
1077     nhsa.BackfillSize = 0;\r
1078     nhsa.MaxHeaderSize = 0;    \r
1079 \r
1080     atr.HDSplitAttributes = &nhsa;\r
1081 \r
1082     Status = NdisMSetMiniportAttributes(h_adapter,\r
1083                     (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&atr);\r
1084 \r
1085     if (nhsa.HDSplitFlags & NDIS_HD_SPLIT_ENABLE_HEADER_DATA_SPLIT) {\r
1086         ASSERT(pPort->Config.HeaderDataSplit == TRUE);\r
1087         pPort->Config.HeaderDataSplit = TRUE;\r
1088     } \r
1089     else {\r
1090         ASSERT(pPort->Config.HeaderDataSplit == FALSE);\r
1091         pPort->Config.HeaderDataSplit = FALSE;\r
1092     }\r
1093 \r
1094     return Status;\r
1095 }\r
1096 #endif\r
1097 \r
1098 /*++\r
1099 Routine Description:\r
1100     the routine sets attributes that are associated with a miniport adapter.\r
1101 \r
1102 Arguments:\r
1103     pPort - Pointer to port object\r
1104 \r
1105 Return Value:\r
1106     NDIS_STATUS\r
1107 \r
1108 Note:\r
1109     Should be called in PASSIVE_LEVEL\r
1110     \r
1111 --*/\r
1112 NDIS_STATUS\r
1113 SetAdapterRegistrationAttributes(\r
1114         ipoib_adapter_t *p_adapter,\r
1115         NDIS_HANDLE     h_adapter\r
1116         )\r
1117         {\r
1118         NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES atr;\r
1119         NTSTATUS Status;\r
1120 \r
1121         NdisZeroMemory(&atr, sizeof(NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES));\r
1122 \r
1123         /* setting registration attributes */\r
1124 \r
1125         atr.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES;\r
1126         atr.Header.Revision = NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;\r
1127         atr.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;\r
1128         //TODO NDIS60 Port or adapter\r
1129         atr.MiniportAdapterContext = (NDIS_HANDLE)p_adapter; //(NDIS_HANDLE)pPort->p_adapter;\r
1130         atr.AttributeFlags = NDIS_MINIPORT_ATTRIBUTES_BUS_MASTER;\r
1131         atr.CheckForHangTimeInSeconds = 10;\r
1132         atr.InterfaceType = NdisInterfacePci ;   // ???? UH\r
1133         //TODO NDIS60 PNP or PCI ?\r
1134         //RegistrationAttributes.InterfaceType = NdisInterfacePNPBus;\r
1135 \r
1136         Status = NdisMSetMiniportAttributes(h_adapter,\r
1137                         (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&atr);\r
1138 \r
1139         return Status;\r
1140 }\r
1141 \r
1142 \r
1143 /*++\r
1144 Routine Description:\r
1145     the routine sets generic attributes that are associated with a miniport \r
1146     adapter.\r
1147 \r
1148 Arguments:\r
1149     pPort - Pointer to port object\r
1150 \r
1151 Return Value:\r
1152     NDIS_STATUS\r
1153 \r
1154 Note:\r
1155     Should be called in PASSIVE_LEVEL\r
1156     \r
1157 --*/\r
1158 NDIS_STATUS\r
1159 SetGenericAttributes(\r
1160     ipoib_adapter_t *p_adapter,\r
1161     NDIS_HANDLE h_adapter\r
1162     )\r
1163 {\r
1164     NDIS_STATUS Status;\r
1165 \r
1166     NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES gat;\r
1167     NdisZeroMemory(&gat, sizeof(NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES));\r
1168 \r
1169         /* set up generic attributes */\r
1170 \r
1171         gat.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES;\r
1172         gat.Header.Revision = NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1;\r
1173         gat.Header.Size = sizeof(NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES);\r
1174 \r
1175         gat.MediaType = NdisMedium802_3;    \r
1176         gat.MaxXmitLinkSpeed = IPOIB_MEDIA_MAX_SPEED;\r
1177         gat.MaxRcvLinkSpeed = IPOIB_MEDIA_MAX_SPEED;\r
1178         gat.XmitLinkSpeed = IPOIB_MEDIA_MAX_SPEED; //TODO NDIS60 NDIS_LINK_SPEED_UNKNOWN\r
1179         gat.RcvLinkSpeed = IPOIB_MEDIA_MAX_SPEED; // TODO NDIS60 NDIS_LINK_SPEED_UNKNOWN ???\r
1180 \r
1181         gat.MediaConnectState = MediaConnectStateConnected; //TODO NDIS60 Check the current state\r
1182         gat.MediaDuplexState = MediaDuplexStateFull;\r
1183 \r
1184         gat.MtuSize = MAX_IB_MTU;\r
1185         gat.LookaheadSize = MAX_XFER_BLOCK_SIZE;\r
1186         gat.MacOptions = NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA | \r
1187                                          NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |\r
1188                                          NDIS_MAC_OPTION_NO_LOOPBACK |\r
1189                                          NDIS_MAC_OPTION_FULL_DUPLEX;\r
1190                                         //NDIS_MAC_OPTION_8021P_PRIORITY; //TODO NDIS60\r
1191                                         // DT: Enable for Header Data Split WHQL\r
1192                                         // |  NDIS_MAC_OPTION_8021Q_VLAN;\r
1193 \r
1194         gat.SupportedPacketFilters =    NDIS_PACKET_TYPE_DIRECTED |\r
1195                                                                         NDIS_PACKET_TYPE_MULTICAST |\r
1196                                                                         //NDIS_PACKET_TYPE_ALL_MULTICAST |\r
1197                                                                         NDIS_PACKET_TYPE_BROADCAST;\r
1198                                          \r
1199         gat.MaxMulticastListSize = MAX_MCAST;\r
1200 \r
1201         gat.MacAddressLength = HW_ADDR_LEN;\r
1202         \r
1203         NdisMoveMemory(gat.PermanentMacAddress,\r
1204                                         p_adapter->mac.addr,\r
1205                                         HW_ADDR_LEN);\r
1206 \r
1207         NdisMoveMemory(gat.CurrentMacAddress,\r
1208                                         p_adapter->params.conf_mac.addr,\r
1209                                         HW_ADDR_LEN);\r
1210 \r
1211 \r
1212         gat.PhysicalMediumType = NdisPhysicalMedium802_3;\r
1213         gat.AccessType = NET_IF_ACCESS_BROADCAST; \r
1214 \r
1215         gat.SupportedOidList = (PNDIS_OID)SUPPORTED_OIDS;\r
1216         gat.SupportedOidListLength = sizeof(SUPPORTED_OIDS);\r
1217 \r
1218 \r
1219         gat.DirectionType = NET_IF_DIRECTION_SENDRECEIVE; \r
1220         gat.ConnectionType = NET_IF_CONNECTION_DEDICATED; \r
1221         gat.IfType = IF_TYPE_ETHERNET_CSMACD; \r
1222         gat.IfConnectorPresent = TRUE; \r
1223         //TODO NDIS60 This value is absent for ETH driver\r
1224         gat.AccessType = NET_IF_ACCESS_BROADCAST; // NET_IF_ACCESS_BROADCAST for a typical ethernet adapter\r
1225 \r
1226 \r
1227         //TODO NDIS60 is it possible to reduce unsupported statistics\r
1228         gat.SupportedStatistics = \r
1229                                 NDIS_STATISTICS_XMIT_OK_SUPPORTED |\r
1230                                 NDIS_STATISTICS_RCV_OK_SUPPORTED |\r
1231                                 NDIS_STATISTICS_XMIT_ERROR_SUPPORTED |\r
1232                                 NDIS_STATISTICS_RCV_ERROR_SUPPORTED |\r
1233                                 NDIS_STATISTICS_RCV_CRC_ERROR_SUPPORTED |\r
1234                                 NDIS_STATISTICS_RCV_NO_BUFFER_SUPPORTED |\r
1235                                 NDIS_STATISTICS_TRANSMIT_QUEUE_LENGTH_SUPPORTED;\r
1236 \r
1237         //SupportedStatistics = NDIS_STATISTICS_XMIT_OK_SUPPORTED |\r
1238                                                         // NDIS_STATISTICS_GEN_STATISTICS_SUPPORTED;\r
1239 \r
1240 \r
1241     //\r
1242     // Set power management capabilities\r
1243     //\r
1244     gat.PowerManagementCapabilities = NULL;\r
1245 #if 0\r
1246     NDIS_PNP_CAPABILITIES PowerManagementCapabilities;\r
1247     NdisZeroMemory(&PowerManagementCapabilities, sizeof(NDIS_PNP_CAPABILITIES));\r
1248     if (MPIsPoMgmtSupported(pPort))\r
1249     {\r
1250         MPFillPoMgmtCaps(pPort, &PowerManagementCapabilities, &Status, &unUsed);\r
1251         ASSERT(NT_SUCCESS(Status)); \r
1252         gat.PowerManagementCapabilities = &PowerManagementCapabilities;\r
1253     } \r
1254     else\r
1255     {\r
1256         \r
1257     }\r
1258 #endif\r
1259 \r
1260     //\r
1261     // Set RSS attributes\r
1262     //\r
1263     gat.RecvScaleCapabilities = NULL;\r
1264 #if 0\r
1265     NDIS_RECEIVE_SCALE_CAPABILITIES RssCapabilities;\r
1266     NdisZeroMemory(&RssCapabilities, sizeof(PNDIS_RECEIVE_SCALE_CAPABILITIES));\r
1267     Status = MPFillRssCapabilities(pPort, &RssCapabilities, &unUsed);\r
1268     if (NT_SUCCESS(Status)) \r
1269     {\r
1270         gat.RecvScaleCapabilities = &RssCapabilities;\r
1271     } \r
1272     else\r
1273     {\r
1274         //\r
1275         // do not fail the call because of failure to get PM caps\r
1276         //\r
1277         Status = NDIS_STATUS_SUCCESS;\r
1278         gat.RecvScaleCapabilities = NULL;\r
1279     }\r
1280 #endif\r
1281 \r
1282         Status = NdisMSetMiniportAttributes(h_adapter,\r
1283                         (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&gat);\r
1284 \r
1285         return Status;\r
1286 }\r
1287 \r
1288 \r
1289 /*++\r
1290 Routine Description:\r
1291     The routine sets an NDIS_OFFLOAD structure indicates the current offload \r
1292     capabilities that are provided by the miniport adapter \r
1293     \r
1294 Arguments:\r
1295     pPort - a pointer to port object\r
1296     offload - reference to NDIS_OFFLOAD object that should be filled\r
1297 \r
1298 Return Value:\r
1299     None.\r
1300     \r
1301 --*/\r
1302 static\r
1303 void\r
1304 OffloadConfig(\r
1305         ipoib_adapter_t *p_adapter,\r
1306         NDIS_OFFLOAD *p_offload\r
1307         )\r
1308\r
1309 \r
1310         ULONG ulEncapsulation = NDIS_ENCAPSULATION_IEEE_802_3 | NDIS_ENCAPSULATION_IEEE_802_3_P_AND_Q;\r
1311 \r
1312         NdisZeroMemory(p_offload, NDIS_SIZEOF_NDIS_OFFLOAD_REVISION_1);\r
1313 \r
1314         p_offload->Header.Type = NDIS_OBJECT_TYPE_OFFLOAD;\r
1315         p_offload->Header.Revision = NDIS_OFFLOAD_REVISION_1; // BUGBUG: do we need to support revision 2? UH 17-May-2008\r
1316         p_offload->Header.Size = NDIS_SIZEOF_NDIS_OFFLOAD_REVISION_1;\r
1317 \r
1318         p_offload->Checksum.IPv4Transmit.Encapsulation = ulEncapsulation;\r
1319         p_offload->Checksum.IPv4Transmit.IpOptionsSupported = \r
1320         p_offload->Checksum.IPv4Transmit.TcpOptionsSupported = \r
1321         p_offload->Checksum.IPv4Transmit.TcpChecksum = \r
1322         p_offload->Checksum.IPv4Transmit.UdpChecksum = \r
1323         p_offload->Checksum.IPv4Transmit.IpChecksum =!!(p_adapter->params.send_chksum_offload);\r
1324 \r
1325         p_offload->Checksum.IPv4Receive.Encapsulation = ulEncapsulation;\r
1326         p_offload->Checksum.IPv4Receive.IpOptionsSupported = \r
1327         p_offload->Checksum.IPv4Receive.TcpOptionsSupported = \r
1328         p_offload->Checksum.IPv4Receive.TcpChecksum = \r
1329         p_offload->Checksum.IPv4Receive.UdpChecksum = \r
1330         p_offload->Checksum.IPv4Receive.IpChecksum = !!(p_adapter->params.recv_chksum_offload); //TODO NDIS60\r
1331 \r
1332 \r
1333         p_offload->Checksum.IPv6Transmit.Encapsulation = ulEncapsulation;\r
1334         p_offload->Checksum.IPv6Transmit.IpExtensionHeadersSupported = \r
1335         p_offload->Checksum.IPv6Transmit.TcpOptionsSupported =\r
1336         p_offload->Checksum.IPv6Transmit.TcpChecksum = \r
1337         p_offload->Checksum.IPv6Transmit.UdpChecksum = FALSE;\r
1338 \r
1339 \r
1340         p_offload->Checksum.IPv6Receive.Encapsulation = ulEncapsulation;\r
1341         p_offload->Checksum.IPv6Receive.IpExtensionHeadersSupported = \r
1342         p_offload->Checksum.IPv6Receive.TcpOptionsSupported = \r
1343         p_offload->Checksum.IPv6Receive.TcpChecksum = \r
1344         p_offload->Checksum.IPv6Receive.UdpChecksum = FALSE;\r
1345 \r
1346         if (p_adapter->params.lso)\r
1347         {\r
1348                 p_offload->LsoV1.IPv4.Encapsulation = ulEncapsulation;\r
1349                 p_offload->LsoV1.IPv4.MaxOffLoadSize = LARGE_SEND_OFFLOAD_SIZE;\r
1350 #define LSO_MIN_SEG_COUNT 2\r
1351                 p_offload->LsoV1.IPv4.MinSegmentCount = LSO_MIN_SEG_COUNT;\r
1352         \r
1353                 \r
1354                 p_offload->LsoV1.IPv4.TcpOptions = NDIS_OFFLOAD_SUPPORTED;\r
1355                 p_offload->LsoV1.IPv4.IpOptions = NDIS_OFFLOAD_SUPPORTED;\r
1356 \r
1357                 p_offload->LsoV2.IPv4.Encapsulation = ulEncapsulation;\r
1358                 p_offload->LsoV2.IPv4.MaxOffLoadSize = LARGE_SEND_OFFLOAD_SIZE;\r
1359                 p_offload->LsoV2.IPv4.MinSegmentCount = LSO_MIN_SEG_COUNT;\r
1360 \r
1361                 p_offload->LsoV2.IPv6.Encapsulation = ulEncapsulation;\r
1362                 p_offload->LsoV2.IPv6.MaxOffLoadSize = LARGE_SEND_OFFLOAD_SIZE;\r
1363                 p_offload->LsoV2.IPv6.MinSegmentCount = LSO_MIN_SEG_COUNT;\r
1364 \r
1365                 p_offload->LsoV2.IPv6.IpExtensionHeadersSupported = NDIS_OFFLOAD_NOT_SUPPORTED;\r
1366                 p_offload->LsoV2.IPv6.TcpOptionsSupported = NDIS_OFFLOAD_SUPPORTED;\r
1367         }\r
1368 \r
1369 }\r
1370 \r
1371 \r
1372 /*++\r
1373 Routine Description:\r
1374     The routine sets an NDIS_OFFLOAD structure that indicates all the task \r
1375     offload capabilites that are supported by the NIC. These capabilities include\r
1376     capabilities that are currently disabled by standardized keywords in the registry. \r
1377     \r
1378 Arguments:\r
1379     offload - reference to NDIS_OFFLOAD object that should be filled\r
1380 \r
1381 Return Value:\r
1382     None.\r
1383     \r
1384 --*/\r
1385 static\r
1386 void\r
1387 OffloadCapabilities(\r
1388         NDIS_OFFLOAD    *p_offload\r
1389         )\r
1390\r
1391         ULONG ulEncapsulation = NDIS_ENCAPSULATION_IEEE_802_3 | NDIS_ENCAPSULATION_IEEE_802_3_P_AND_Q ;\r
1392         NdisZeroMemory(p_offload, NDIS_SIZEOF_NDIS_OFFLOAD_REVISION_1);    \r
1393 \r
1394         p_offload->Header.Type = NDIS_OBJECT_TYPE_OFFLOAD;\r
1395         p_offload->Header.Revision = NDIS_OFFLOAD_REVISION_1; // BUGBUG: do we need to support revision 2? UH 17-May-2008\r
1396         p_offload->Header.Size = NDIS_SIZEOF_NDIS_OFFLOAD_REVISION_1;\r
1397 \r
1398         p_offload->Checksum.IPv4Transmit.Encapsulation = ulEncapsulation;\r
1399         p_offload->Checksum.IPv4Transmit.IpOptionsSupported = TRUE;\r
1400         p_offload->Checksum.IPv4Transmit.TcpOptionsSupported = TRUE;\r
1401         p_offload->Checksum.IPv4Transmit.TcpChecksum = TRUE;\r
1402         p_offload->Checksum.IPv4Transmit.UdpChecksum = TRUE;\r
1403         p_offload->Checksum.IPv4Transmit.IpChecksum = TRUE;\r
1404 \r
1405         p_offload->Checksum.IPv4Receive.Encapsulation = ulEncapsulation;\r
1406         p_offload->Checksum.IPv4Receive.IpOptionsSupported = TRUE;\r
1407         p_offload->Checksum.IPv4Receive.TcpOptionsSupported = TRUE;\r
1408         p_offload->Checksum.IPv4Receive.TcpChecksum = TRUE;\r
1409         p_offload->Checksum.IPv4Receive.UdpChecksum = TRUE; \r
1410         p_offload->Checksum.IPv4Receive.IpChecksum = TRUE;\r
1411 \r
1412 \r
1413         //\r
1414         //  BUGBUG::\r
1415         //  During a HW bug that didn't handle correctly packets with \r
1416         //  IPv6 Extension Headers -> we set IpExtensionHeadersSupported to TRUE\r
1417         //\r
1418         p_offload->Checksum.IPv6Transmit.Encapsulation = ulEncapsulation;\r
1419         p_offload->Checksum.IPv6Transmit.IpExtensionHeadersSupported = TRUE;\r
1420         p_offload->Checksum.IPv6Transmit.TcpOptionsSupported = TRUE;\r
1421         p_offload->Checksum.IPv6Transmit.TcpChecksum = TRUE;\r
1422         p_offload->Checksum.IPv6Transmit.UdpChecksum = TRUE;\r
1423 \r
1424 \r
1425         p_offload->Checksum.IPv6Receive.Encapsulation = ulEncapsulation;\r
1426         p_offload->Checksum.IPv6Receive.IpExtensionHeadersSupported = TRUE;\r
1427         p_offload->Checksum.IPv6Receive.TcpOptionsSupported = TRUE;\r
1428         p_offload->Checksum.IPv6Receive.TcpChecksum = TRUE;\r
1429         p_offload->Checksum.IPv6Receive.UdpChecksum = TRUE;\r
1430 \r
1431         p_offload->LsoV1.IPv4.Encapsulation = ulEncapsulation;\r
1432         p_offload->LsoV1.IPv4.MaxOffLoadSize = LARGE_SEND_OFFLOAD_SIZE;\r
1433         p_offload->LsoV1.IPv4.MinSegmentCount = 2;\r
1434         p_offload->LsoV1.IPv4.TcpOptions = NDIS_OFFLOAD_SUPPORTED;\r
1435         p_offload->LsoV1.IPv4.IpOptions = NDIS_OFFLOAD_SUPPORTED;\r
1436 \r
1437         p_offload->LsoV2.IPv4.Encapsulation = ulEncapsulation;\r
1438         p_offload->LsoV2.IPv4.MaxOffLoadSize = LARGE_SEND_OFFLOAD_SIZE;\r
1439         p_offload->LsoV2.IPv4.MinSegmentCount = 2;\r
1440 \r
1441         p_offload->LsoV2.IPv6.Encapsulation = ulEncapsulation;\r
1442         p_offload->LsoV2.IPv6.MaxOffLoadSize = LARGE_SEND_OFFLOAD_SIZE;\r
1443         p_offload->LsoV2.IPv6.MinSegmentCount = 2;\r
1444 \r
1445         p_offload->LsoV2.IPv6.IpExtensionHeadersSupported = NDIS_OFFLOAD_NOT_SUPPORTED;\r
1446         p_offload->LsoV2.IPv6.TcpOptionsSupported = NDIS_OFFLOAD_SUPPORTED;\r
1447 \r
1448         }\r
1449 \r
1450 \r
1451 /*++\r
1452 Routine Description:\r
1453     The routine sets offload attributes that are associated with a miniport \r
1454     adapter.\r
1455 \r
1456 Arguments:\r
1457     pPort - Pointer to port object\r
1458 \r
1459 Return Value:\r
1460     NDIS_STATUS\r
1461 \r
1462 Note:\r
1463     Should be called in PASSIVE_LEVEL\r
1464     \r
1465 --*/\r
1466 NDIS_STATUS\r
1467 SetOffloadAttributes(\r
1468         ipoib_adapter_t *p_adapter,\r
1469         NDIS_HANDLE     h_adapter\r
1470         )\r
1471 {\r
1472         NDIS_STATUS Status;\r
1473         NDIS_OFFLOAD offload,hwOffload;\r
1474         //ULONG ulEncapsulation = NDIS_ENCAPSULATION_IEEE_802_3 | NDIS_ENCAPSULATION_IEEE_802_3_P_AND_Q;\r
1475 \r
1476         NDIS_MINIPORT_ADAPTER_OFFLOAD_ATTRIBUTES oat;    \r
1477         NdisZeroMemory(&oat, sizeof(NDIS_MINIPORT_ADAPTER_OFFLOAD_ATTRIBUTES));\r
1478 \r
1479         oat.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_OFFLOAD_ATTRIBUTES;\r
1480         oat.Header.Revision = NDIS_MINIPORT_ADAPTER_OFFLOAD_ATTRIBUTES_REVISION_1;\r
1481         oat.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_OFFLOAD_ATTRIBUTES_REVISION_1;\r
1482 \r
1483 \r
1484         OffloadConfig(p_adapter, &offload);\r
1485 \r
1486 \r
1487         OffloadCapabilities(&hwOffload);\r
1488 \r
1489         oat.DefaultOffloadConfiguration = &offload;\r
1490         oat.HardwareOffloadCapabilities = &hwOffload;\r
1491 \r
1492         Status = NdisMSetMiniportAttributes(h_adapter,\r
1493                                 (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&oat);\r
1494 \r
1495         return Status;\r
1496 }\r
1497 \r
1498 \r
1499 /*++\r
1500 \r
1501 Routine Description:\r
1502     An NDIS 6.0 miniport driver must call NdisMSetMiniportAttributes\r
1503     at least twice. The first call is to register itself with NDIS.\r
1504     The second call is to register the miniport driver's general\r
1505     attributes with NDIS.\r
1506 \r
1507     NdisMSetMiniportAttributes takes a parameter of type\r
1508     NDIS_MINIPORT_ADAPTER_ATTRIBUTES, which is a union of several miniport\r
1509     adapter attributes. Miniport drivers must first call\r
1510     NdisMSetMiniportAttributes and pass in an\r
1511     NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES structure\r
1512     that contains the pointer to its own context area, attribute flags,\r
1513     check-for-hang time, and interface type.\r
1514 \r
1515     All NDIS 6.0 miniport drivers are deserialized by default.\r
1516 \r
1517 Arguments:\r
1518     pPort - Pointer to port object\r
1519 \r
1520 Return Value:\r
1521     NDIS_STATUS\r
1522 \r
1523 Note:\r
1524     Should be called in PASSIVE_LEVEL\r
1525     \r
1526 --*/\r
1527         NDIS_STATUS\r
1528         SetAttributes(\r
1529         ipoib_adapter_t *p_adapter,\r
1530         NDIS_HANDLE     h_adapter\r
1531         )\r
1532         {\r
1533         NTSTATUS Status;\r
1534 \r
1535 \r
1536         Status = SetDeviceRegistrationAttributes(p_adapter, h_adapter);\r
1537         if (Status != NDIS_STATUS_SUCCESS)\r
1538         {\r
1539                 //ETH_PRINT(TRACE_LEVEL_ERROR, ETH_INIT, "Set device registration failed Error=0x%x\n", Status);\r
1540                 return Status;\r
1541         }\r
1542 \r
1543 \r
1544         Status = SetAdapterRegistrationAttributes(p_adapter, h_adapter);\r
1545         if (Status != NDIS_STATUS_SUCCESS)\r
1546         {\r
1547                 //ETH_PRINT(TRACE_LEVEL_ERROR, ETH_INIT, "Set adapter attributes failed Error=0x%x\n", Status);\r
1548                 return Status;\r
1549         }\r
1550 \r
1551         Status = SetOffloadAttributes(p_adapter, h_adapter);\r
1552         if (Status != NDIS_STATUS_SUCCESS)\r
1553         {\r
1554                 //ETH_PRINT(TRACE_LEVEL_ERROR, ETH_INIT, "Set OFFLOAD attributes failed Error=0x%x\n", Status);\r
1555                 return Status;\r
1556         }\r
1557         \r
1558 #if 0\r
1559         if(!pPort->Config.fWHQL)\r
1560         {\r
1561                 Status = SetHardwareAssistAttributes(pPort);\r
1562                 if (Status != NDIS_STATUS_SUCCESS)\r
1563                 {\r
1564                     //ETH_PRINT(TRACE_LEVEL_ERROR, ETH_INIT, "Set Hardware Assist Attributes failed Error=0x%x\n", Status);\r
1565                     return Status;\r
1566                 }\r
1567         }\r
1568 #endif\r
1569 \r
1570         Status = SetGenericAttributes(p_adapter, h_adapter);\r
1571         if (Status != NDIS_STATUS_SUCCESS)\r
1572         {\r
1573             //ETH_PRINT(TRACE_LEVEL_ERROR, ETH_INIT, "Set generic attributes failed Error=0x%x\n", Status);\r
1574             return Status;\r
1575         }\r
1576 \r
1577         return Status;\r
1578 }\r
1579 \r
1580 \r
1581 \r
1582 NDIS_STATUS\r
1583 InitNdisScatterGatherDma(\r
1584         ipoib_adapter_t *p_adapter,\r
1585         NDIS_HANDLE             h_adapter\r
1586         )\r
1587 {\r
1588         NDIS_STATUS                                             status;\r
1589         NDIS_SG_DMA_DESCRIPTION                 DmaDescription;\r
1590         \r
1591         NdisZeroMemory(&DmaDescription, sizeof(DmaDescription));\r
1592 \r
1593         DmaDescription.Header.Type = NDIS_OBJECT_TYPE_SG_DMA_DESCRIPTION;\r
1594         DmaDescription.Header.Revision = NDIS_SG_DMA_DESCRIPTION_REVISION_1;\r
1595         DmaDescription.Header.Size = sizeof(NDIS_SG_DMA_DESCRIPTION);\r
1596         DmaDescription.Flags = NDIS_SG_DMA_64_BIT_ADDRESS; \r
1597         //\r
1598         // Even if offload is enabled, the packet size for mapping shouldn't change\r
1599         //\r
1600         DmaDescription.MaximumPhysicalMapping = LARGE_SEND_OFFLOAD_SIZE + LSO_MAX_HEADER;\r
1601 \r
1602         DmaDescription.ProcessSGListHandler = ipoib_process_sg_list;\r
1603         DmaDescription.SharedMemAllocateCompleteHandler = NULL;\r
1604 \r
1605         DmaDescription.Header.Type = NDIS_OBJECT_TYPE_SG_DMA_DESCRIPTION;\r
1606         DmaDescription.Header.Revision = NDIS_SG_DMA_DESCRIPTION_REVISION_1;\r
1607         DmaDescription.Header.Size = sizeof(NDIS_SG_DMA_DESCRIPTION);//NDIS_SIZEOF_SG_DMA_DESCRIPTION_REVISION_1;\r
1608 \r
1609         DmaDescription.Flags = NDIS_SG_DMA_64_BIT_ADDRESS;\r
1610         //DmaDescription.MaximumPhysicalMapping = pPort->p_adapter->params.xfer_block_size;\r
1611 \r
1612         DmaDescription.ProcessSGListHandler = ipoib_process_sg_list;\r
1613         DmaDescription.SharedMemAllocateCompleteHandler = NULL;\r
1614         \r
1615         status = NdisMRegisterScatterGatherDma(\r
1616                                         h_adapter,\r
1617                                         &DmaDescription,\r
1618                                         &p_adapter->NdisMiniportDmaHandle);\r
1619 \r
1620         if( status != NDIS_STATUS_SUCCESS )\r
1621         {\r
1622                 //TODO NDIS60\r
1623                 //ipoib_destroy_adapter( p_adapter );\r
1624                 IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
1625                                                  ("NdisMRegisterScatterGatherDma returned 0x%.8x.\n", status) );\r
1626                 \r
1627         }\r
1628         //NDIS sets this value before it returns from NdisMRegisterScatterGatherDma. \r
1629                 //Miniport drivers should use this size to preallocate memory for each scatter/gather list. \r
1630         p_adapter->sg_list_size = DmaDescription.ScatterGatherListSize ;\r
1631         \r
1632         return status;\r
1633 }\r
1634 \r
1635 \r
1636 NDIS_STATUS \r
1637 MPInitializeTest(\r
1638     IN  NDIS_HANDLE                        MiniportAdapterHandle,\r
1639     IN  NDIS_HANDLE                        MiniportDriverContext,\r
1640     IN  PNDIS_MINIPORT_INIT_PARAMETERS     MiniportInitParameters\r
1641     )\r
1642 /*++\r
1643 Routine Description:\r
1644 \r
1645     MiniportInitialize handler\r
1646 \r
1647 Arguments:\r
1648 \r
1649     MiniportAdapterHandle   The handle NDIS uses to refer to us\r
1650     MiniportDriverContext   Handle passed to NDIS when we registered the driver\r
1651     MiniportInitParameters  Initialization parameters\r
1652     \r
1653 Return Value:\r
1654 \r
1655     NDIS_STATUS_SUCCESS unless something goes wrong\r
1656 \r
1657 --*/\r
1658 {\r
1659 \r
1660         NDIS_STATUS Status = NDIS_STATUS_SUCCESS;\r
1661     //PMP_PORT pPort = NULL;\r
1662     ipoib_adapter_t     *p_adapter;\r
1663 //    NDIS_MINIPORT_INTERRUPT_CHARACTERISTICS  Interrupt;\r
1664     NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES   RegistrationAttributes;\r
1665     NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES        GeneralAttributes;\r
1666     //NDIS_TIMER_CHARACTERISTICS                      Timer;               \r
1667     NDIS_PNP_CAPABILITIES          PowerManagementCapabilities;    \r
1668     //PMP_ADAPTER     Adapter = NULL;\r
1669     //PVOID           NetworkAddress;\r
1670 //    UINT            index;\r
1671 //    UINT            uiPnpCommandValue;\r
1672 //    ULONG           ulInfoLen;\r
1673     //ULONG           InterruptVersion;\r
1674 //    LARGE_INTEGER   liDueTime;\r
1675     //BOOLEAN         isTimerAlreadyInQueue = FALSE;\r
1676 //      uint8_t portId;\r
1677         ib_api_status_t         ib_status;\r
1678 #if 0   \r
1679 #if DBG\r
1680     LARGE_INTEGER   TS, TD, TE;\r
1681 #endif\r
1682 #endif\r
1683 \r
1684     cl_dbg_out ("====> MPInitialize\n");\r
1685 \r
1686     UNREFERENCED_PARAMETER(MiniportDriverContext);\r
1687     UNREFERENCED_PARAMETER(MiniportInitParameters);\r
1688   \r
1689 \r
1690 \r
1691         \r
1692 \r
1693     {\r
1694 \r
1695                 ib_status = ipoib_create_adapter(MiniportDriverContext, MiniportAdapterHandle, &p_adapter );\r
1696                 if( ib_status != IB_SUCCESS )\r
1697                 {\r
1698                         ASSERT(FALSE);\r
1699                         IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
1700                                 ("ipoib_create_adapter returned status %d.\n", ib_status ) );\r
1701                         return NDIS_STATUS_FAILURE;\r
1702                 }\r
1703 \r
1704        \r
1705 \r
1706         NdisZeroMemory(&RegistrationAttributes, sizeof(NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES));\r
1707         NdisZeroMemory(&GeneralAttributes, sizeof(NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES));\r
1708 \r
1709         //\r
1710         // setting registration attributes\r
1711         //\r
1712         RegistrationAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES;\r
1713         RegistrationAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;\r
1714         RegistrationAttributes.Header.Size = sizeof(NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES);\r
1715 \r
1716         RegistrationAttributes.MiniportAdapterContext = (NDIS_HANDLE)p_adapter;\r
1717         RegistrationAttributes.AttributeFlags = NDIS_MINIPORT_ATTRIBUTES_HARDWARE_DEVICE | \r
1718                                                 NDIS_MINIPORT_ATTRIBUTES_BUS_MASTER;\r
1719         \r
1720         RegistrationAttributes.CheckForHangTimeInSeconds = 2;\r
1721         RegistrationAttributes.InterfaceType = NdisInterfacePci;\r
1722 \r
1723         Status = NdisMSetMiniportAttributes(MiniportAdapterHandle,\r
1724                                             (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&RegistrationAttributes);\r
1725 \r
1726         if (Status != NDIS_STATUS_SUCCESS)\r
1727         {\r
1728             //break;\r
1729             return Status;\r
1730         }\r
1731 \r
1732 #if 0         \r
1733         //\r
1734         // Read the registry parameters\r
1735         //\r
1736         Status = NICReadRegParameters(Adapter);\r
1737         \r
1738         if (Status != NDIS_STATUS_SUCCESS) \r
1739         {\r
1740             break;\r
1741         }\r
1742 \r
1743        \r
1744         //\r
1745         // Find the physical adapter\r
1746         //\r
1747         Status = MpFindAdapter(Adapter, MiniportInitParameters->AllocatedResources);\r
1748         if (Status != NDIS_STATUS_SUCCESS)\r
1749         {\r
1750             break;\r
1751         }\r
1752 \r
1753         //\r
1754         // Map bus-relative IO range to system IO space\r
1755         //\r
1756         Status = NdisMRegisterIoPortRange(\r
1757                      (PVOID *)&Adapter->PortOffset,\r
1758                      Adapter->AdapterHandle,\r
1759                      Adapter->IoBaseAddress,\r
1760                      Adapter->IoRange);\r
1761         if (Status != NDIS_STATUS_SUCCESS)\r
1762         {\r
1763             DBGPRINT(MP_ERROR, ("NdisMRegisterioPortRange failed\n"));\r
1764     \r
1765             NdisWriteErrorLogEntry(\r
1766                 Adapter->AdapterHandle,\r
1767                 NDIS_ERROR_CODE_BAD_IO_BASE_ADDRESS,\r
1768                 0);\r
1769         \r
1770             break;\r
1771         }\r
1772         \r
1773         //\r
1774         // Read additional info from NIC such as MAC address\r
1775         //\r
1776         Status = NICReadAdapterInfo(Adapter);\r
1777         if (Status != NDIS_STATUS_SUCCESS) \r
1778         {\r
1779             break;\r
1780         }\r
1781 \r
1782 #endif\r
1783         //\r
1784         // set up generic attributes\r
1785         //\r
1786                 \r
1787 \r
1788         GeneralAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES;\r
1789         GeneralAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1;\r
1790         GeneralAttributes.Header.Size = sizeof(NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES);\r
1791 \r
1792         GeneralAttributes.MediaType = NdisMedium802_3;\r
1793 \r
1794         GeneralAttributes.MtuSize = DEFAULT_MTU;\r
1795 #define LINE_SPEED_10_GBTS 10000000000\r
1796         GeneralAttributes.MaxXmitLinkSpeed = LINE_SPEED_10_GBTS;\r
1797         GeneralAttributes.MaxRcvLinkSpeed = LINE_SPEED_10_GBTS;\r
1798         GeneralAttributes.XmitLinkSpeed = NDIS_LINK_SPEED_UNKNOWN;\r
1799         GeneralAttributes.RcvLinkSpeed = NDIS_LINK_SPEED_UNKNOWN;\r
1800         GeneralAttributes.MediaConnectState = MediaConnectStateUnknown;\r
1801         GeneralAttributes.MediaDuplexState = MediaDuplexStateUnknown;\r
1802         GeneralAttributes.LookaheadSize = MAX_XFER_BLOCK_SIZE;\r
1803 #if 0\r
1804         MPFillPoMgmtCaps (Adapter, \r
1805                           &PowerManagementCapabilities, \r
1806                           &Status,\r
1807                           &ulInfoLen);\r
1808 #endif\r
1809                 NdisZeroMemory(&PowerManagementCapabilities, sizeof(NDIS_PNP_CAPABILITIES));\r
1810         Status = NDIS_STATUS_NOT_SUPPORTED;\r
1811        // ulInfoLen = 0;\r
1812 \r
1813         if (Status == NDIS_STATUS_SUCCESS)\r
1814         {\r
1815             GeneralAttributes.PowerManagementCapabilities = &PowerManagementCapabilities;\r
1816         }\r
1817         else\r
1818         {\r
1819             GeneralAttributes.PowerManagementCapabilities = NULL;\r
1820         }\r
1821 \r
1822         //\r
1823         // do not fail the call because of failure to get PM caps\r
1824         //\r
1825         Status = NDIS_STATUS_SUCCESS;\r
1826 \r
1827         GeneralAttributes.MacOptions = NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA | \r
1828                                        NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |\r
1829                                        NDIS_MAC_OPTION_NO_LOOPBACK;\r
1830 \r
1831         GeneralAttributes.SupportedPacketFilters = NDIS_PACKET_TYPE_DIRECTED |\r
1832                                                    NDIS_PACKET_TYPE_MULTICAST |\r
1833                                                    NDIS_PACKET_TYPE_ALL_MULTICAST |\r
1834                                                    NDIS_PACKET_TYPE_BROADCAST;\r
1835         \r
1836         GeneralAttributes.MaxMulticastListSize = MAX_MCAST;\r
1837         GeneralAttributes.MacAddressLength = HW_ADDR_LEN;\r
1838       NdisMoveMemory(GeneralAttributes.PermanentMacAddress,\r
1839                                 p_adapter->mac.addr,\r
1840                                 HW_ADDR_LEN);\r
1841 \r
1842         NdisMoveMemory(GeneralAttributes.CurrentMacAddress,\r
1843                                 p_adapter->params.conf_mac.addr,\r
1844                                 HW_ADDR_LEN);\r
1845         GeneralAttributes.RecvScaleCapabilities = NULL;\r
1846         GeneralAttributes.AccessType = NET_IF_ACCESS_BROADCAST; // NET_IF_ACCESS_BROADCAST for a typical ethernet adapter\r
1847         GeneralAttributes.DirectionType = NET_IF_DIRECTION_SENDRECEIVE; // NET_IF_DIRECTION_SENDRECEIVE for a typical ethernet adapter\r
1848         GeneralAttributes.ConnectionType = NET_IF_CONNECTION_DEDICATED;  // NET_IF_CONNECTION_DEDICATED for a typical ethernet adapter\r
1849         GeneralAttributes.IfType = IF_TYPE_ETHERNET_CSMACD; // IF_TYPE_ETHERNET_CSMACD for a typical ethernet adapter (regardless of speed)\r
1850         GeneralAttributes.IfConnectorPresent = TRUE; // RFC 2665 TRUE if physical adapter\r
1851 \r
1852         GeneralAttributes.SupportedStatistics = NDIS_STATISTICS_XMIT_OK_SUPPORTED |\r
1853                                                 NDIS_STATISTICS_RCV_OK_SUPPORTED |\r
1854                                                 NDIS_STATISTICS_XMIT_ERROR_SUPPORTED |\r
1855                                                 NDIS_STATISTICS_RCV_ERROR_SUPPORTED |\r
1856                                                 NDIS_STATISTICS_RCV_CRC_ERROR_SUPPORTED |\r
1857                                                 NDIS_STATISTICS_RCV_NO_BUFFER_SUPPORTED |\r
1858                                                 NDIS_STATISTICS_TRANSMIT_QUEUE_LENGTH_SUPPORTED |\r
1859                                                 NDIS_STATISTICS_GEN_STATISTICS_SUPPORTED;\r
1860                       \r
1861         GeneralAttributes.SupportedOidList = NICSupportedOidsTest;\r
1862         GeneralAttributes.SupportedOidListLength = sizeof(NICSupportedOidsTest);\r
1863 \r
1864         Status = NdisMSetMiniportAttributes(MiniportAdapterHandle,\r
1865                                             (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&GeneralAttributes);\r
1866 \r
1867 \r
1868 #if 0        \r
1869         //\r
1870         // Allocate all other memory blocks including shared memory\r
1871         //\r
1872         Status = NICAllocAdapterMemory(Adapter);\r
1873         if (Status != NDIS_STATUS_SUCCESS) \r
1874         {\r
1875             break;\r
1876         }\r
1877         //\r
1878         // Init send data structures\r
1879         //\r
1880         NICInitSend(Adapter);\r
1881 \r
1882         //\r
1883         // Init receive data structures\r
1884         //\r
1885         Status = NICInitRecv(Adapter);\r
1886         if (Status != NDIS_STATUS_SUCCESS)\r
1887         {\r
1888             break;\r
1889         }\r
1890         //\r
1891         // Map bus-relative registers to virtual system-space\r
1892         // \r
1893         Status = NdisMMapIoSpace(\r
1894                      (PVOID *) &(Adapter->CSRAddress),\r
1895                      Adapter->AdapterHandle,\r
1896                      Adapter->MemPhysAddress,\r
1897                      NIC_MAP_IOSPACE_LENGTH);\r
1898         if (Status != NDIS_STATUS_SUCCESS)\r
1899         {\r
1900             DBGPRINT(MP_ERROR, ("NdisMMapIoSpace failed\n"));\r
1901     \r
1902             NdisWriteErrorLogEntry(\r
1903                 Adapter->AdapterHandle,\r
1904                 NDIS_ERROR_CODE_RESOURCE_CONFLICT,\r
1905                 1,\r
1906                 ERRLOG_MAP_IO_SPACE);\r
1907         \r
1908             break;\r
1909         }\r
1910 \r
1911         DBGPRINT(MP_INFO, ("CSRAddress="PTR_FORMAT"\n", Adapter->CSRAddress));\r
1912 \r
1913         //\r
1914         // Disable interrupts here which is as soon as possible\r
1915         //\r
1916         NICDisableInterrupt(Adapter);\r
1917 #endif\r
1918                      \r
1919         //\r
1920         // Register the interrupt\r
1921         //\r
1922         //\r
1923         \r
1924         //\r
1925         // the embeded NDIS interrupt structure is already zero'ed out\r
1926         // as part of the adapter structure\r
1927         //\r
1928  #if 0\r
1929         NdisZeroMemory(&Interrupt, sizeof(NDIS_MINIPORT_INTERRUPT_CHARACTERISTICS));\r
1930         \r
1931         Interrupt.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_INTERRUPT;\r
1932         Interrupt.Header.Revision = NDIS_MINIPORT_INTERRUPT_REVISION_1;\r
1933         Interrupt.Header.Size = sizeof(NDIS_MINIPORT_INTERRUPT_CHARACTERISTICS);\r
1934 \r
1935         Interrupt.InterruptHandler = MPIsr;\r
1936         Interrupt.InterruptDpcHandler = MPHandleInterrupt;\r
1937         Interrupt.DisableInterruptHandler = NULL;\r
1938         Interrupt.EnableInterruptHandler = NULL;\r
1939 \r
1940 \r
1941 \r
1942         Status = NdisMRegisterInterruptEx(Adapter->AdapterHandle,\r
1943                                           Adapter,\r
1944                                           &Interrupt,\r
1945                                           &Adapter->NdisInterruptHandle\r
1946                                           );\r
1947         \r
1948                                         \r
1949         if (Status != NDIS_STATUS_SUCCESS)\r
1950         {\r
1951             DBGPRINT(MP_ERROR, ("NdisMRegisterInterrupt failed\n"));\r
1952     \r
1953             NdisWriteErrorLogEntry(\r
1954                 Adapter->AdapterHandle,\r
1955                 NDIS_ERROR_CODE_INTERRUPT_CONNECT,\r
1956                 0);\r
1957         \r
1958             break;\r
1959         }\r
1960         \r
1961         //\r
1962         // If the driver support MSI\r
1963         //\r
1964         Adapter->InterruptType = Interrupt.InterruptType;\r
1965 \r
1966         if (Adapter->InterruptType == NDIS_CONNECT_MESSAGE_BASED)\r
1967         {\r
1968             Adapter->MessageInfoTable = Interrupt.MessageInfoTable;\r
1969         }\r
1970         \r
1971         //\r
1972         // If the driver supports MSI, here it should what kind of interrupt is granted. If MSI is granted,\r
1973         // the driver can check Adapter->MessageInfoTable to get MSI information\r
1974         //\r
1975         \r
1976         \r
1977         MP_SET_FLAG(Adapter, fMP_ADAPTER_INTERRUPT_IN_USE);\r
1978 \r
1979         //\r
1980         // Test our adapter hardware\r
1981         //\r
1982         Status = NICSelfTest(Adapter);\r
1983         if (Status != NDIS_STATUS_SUCCESS)\r
1984         {\r
1985             break;\r
1986         }\r
1987         \r
1988         //\r
1989         // Init the hardware and set up everything\r
1990         //\r
1991         Status = NICInitializeAdapter(Adapter);\r
1992         if (Status != NDIS_STATUS_SUCCESS)\r
1993         {\r
1994             break;\r
1995         }\r
1996         \r
1997         //\r
1998         // initial state is paused\r
1999         //\r
2000         Adapter->AdapterState = NicPaused;\r
2001         \r
2002         //\r
2003         // Set the link detection flag\r
2004         //\r
2005         MP_SET_FLAG(Adapter, fMP_ADAPTER_LINK_DETECTION);\r
2006       \r
2007         //\r
2008         // Increment the reference count so halt handler will wait \r
2009         //\r
2010         MP_INC_REF(Adapter);        \r
2011 \r
2012         //\r
2013         // Enable the interrupt\r
2014         //\r
2015         NICEnableInterrupt(Adapter);\r
2016 \r
2017         \r
2018         NdisZeroMemory(&Timer, sizeof(NDIS_TIMER_CHARACTERISTICS));\r
2019         \r
2020         Timer.Header.Type = NDIS_OBJECT_TYPE_TIMER_CHARACTERISTICS;\r
2021         Timer.Header.Revision = NDIS_TIMER_CHARACTERISTICS_REVISION_1;\r
2022         Timer.Header.Size = sizeof(NDIS_TIMER_CHARACTERISTICS);\r
2023 \r
2024         Timer.AllocationTag = NIC_TAG;\r
2025         Timer.TimerFunction = MpLinkDetectionDpc;\r
2026         Timer.FunctionContext = Adapter;\r
2027 \r
2028         //\r
2029         // Minimize init-time\r
2030         //\r
2031         Status = NdisAllocateTimerObject(\r
2032             Adapter->AdapterHandle,\r
2033             &Timer,\r
2034             &Adapter->LinkDetectionTimerHandle);\r
2035 \r
2036         if (Status != NDIS_STATUS_SUCCESS)\r
2037         {\r
2038             break;\r
2039         }\r
2040 \r
2041         liDueTime.QuadPart = NIC_LINK_DETECTION_DELAY;\r
2042         isTimerAlreadyInQueue =NdisSetTimerObject(Adapter->LinkDetectionTimerHandle, liDueTime, 0, NULL);\r
2043         ASSERT(!isTimerAlreadyInQueue);\r
2044 #endif       \r
2045         }  \r
2046 #if 0\r
2047     if (Adapter && (Status != NDIS_STATUS_SUCCESS))\r
2048     {\r
2049         //\r
2050         // Undo everything if it failed\r
2051         //\r
2052         MP_DEC_REF(Adapter);\r
2053         MpFreeAdapter(Adapter);\r
2054     }\r
2055 \r
2056     DBGPRINT_S(Status, ("<==== MPInitialize, Status=%x\n", Status));\r
2057 #endif\r
2058                 /* Create the adapter adapter */\r
2059                 ib_status = ipoib_start_adapter( p_adapter );\r
2060                 if( ib_status != IB_SUCCESS )\r
2061                 {\r
2062                         ASSERT(FALSE);\r
2063 \r
2064                         IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
2065                                 ("ipoib_start_adapter returned status %d.\n", ib_status ) );\r
2066                         return NDIS_STATUS_FAILURE;\r
2067                 }\r
2068         \r
2069                 ipoib_ref_ibat();\r
2070     return NDIS_STATUS_SUCCESS;\r
2071 }\r
2072 \r
2073 \r
2074 \r
2075 NDIS_STATUS\r
2076 ipoib_initialize_ex(\r
2077                 IN NDIS_HANDLE  h_adapter,\r
2078                 IN NDIS_HANDLE  config_context,\r
2079                 IN PNDIS_MINIPORT_INIT_PARAMETERS  MiniportInitParameters)\r
2080         {\r
2081                 NDIS_STATUS             status;\r
2082                 ib_api_status_t         ib_status;\r
2083                 ipoib_adapter_t         *p_adapter;\r
2084                 //NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES RegistrationAttributes;\r
2085                 //NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES              GeneralAttributes;\r
2086 #if IPOIB_USE_DMA\r
2087                 //NDIS_SG_DMA_DESCRIPTION       DmaDescription;\r
2088 #endif\r
2089                 IPOIB_ENTER( IPOIB_DBG_INIT );\r
2090         \r
2091 #ifdef _DEBUG_\r
2092                 PAGED_CODE();\r
2093 #endif\r
2094                 \r
2095                 UNUSED_PARAM( config_context );\r
2096                 UNUSED_PARAM( MiniportInitParameters );\r
2097                 \r
2098                 //foo1(100);\r
2099                 /* Create the adapter adapter */\r
2100                 ib_status = ipoib_create_adapter(config_context, h_adapter, &p_adapter );\r
2101                 if( ib_status != IB_SUCCESS )\r
2102                 {\r
2103                         ASSERT(FALSE);\r
2104                         IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
2105                                 ("ipoib_create_adapter returned status %d.\n", ib_status ) );\r
2106                         return NDIS_STATUS_FAILURE;\r
2107                 }\r
2108                 p_adapter->ipoib_state = IPOIB_PAUSED;\r
2109                 status  = SetAttributes(p_adapter, h_adapter);\r
2110                 if (status != NDIS_STATUS_SUCCESS) {\r
2111                         ASSERT(FALSE);\r
2112                 }\r
2113 #if 0\r
2114                 NdisZeroMemory(&RegistrationAttributes, sizeof(NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES));\r
2115                 NdisZeroMemory(&GeneralAttributes, sizeof(NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES));\r
2116         \r
2117                 /* setting registration attributes */\r
2118                 RegistrationAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES;\r
2119                 RegistrationAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;\r
2120                 RegistrationAttributes.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;\r
2121         \r
2122                 RegistrationAttributes.MiniportAdapterContext = (NDIS_HANDLE)p_adapter;\r
2123                 RegistrationAttributes.AttributeFlags = NDIS_MINIPORT_ATTRIBUTES_BUS_MASTER;\r
2124                                                                                                                 \r
2125                 RegistrationAttributes.CheckForHangTimeInSeconds = 10;\r
2126                 RegistrationAttributes.InterfaceType = NdisInterfacePNPBus;\r
2127         \r
2128                 status = NdisMSetMiniportAttributes(h_adapter,\r
2129                                                                                    (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&RegistrationAttributes);\r
2130         \r
2131                 if (status != NDIS_STATUS_SUCCESS)\r
2132                 {\r
2133                         ipoib_destroy_adapter( p_adapter );\r
2134                         IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
2135                                 ("NdisMSetMiniportAttributes returned 0x%.8x.\n", status) );\r
2136                         return status;\r
2137                 }\r
2138         \r
2139                 /* set up generic attributes */\r
2140         \r
2141                  GeneralAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES;\r
2142                  GeneralAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1;\r
2143                  GeneralAttributes.Header.Size = sizeof(NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES);\r
2144         \r
2145                  GeneralAttributes.MediaType = NdisMedium802_3;\r
2146                 //TODO\r
2147                  GeneralAttributes.MtuSize = MAX_IB_MTU;\r
2148                  GeneralAttributes.MaxXmitLinkSpeed = IPOIB_MEDIA_MAX_SPEED;\r
2149                  GeneralAttributes.MaxRcvLinkSpeed = IPOIB_MEDIA_MAX_SPEED;\r
2150                  GeneralAttributes.XmitLinkSpeed = NDIS_LINK_SPEED_UNKNOWN;\r
2151                  GeneralAttributes.RcvLinkSpeed = NDIS_LINK_SPEED_UNKNOWN;\r
2152                  GeneralAttributes.MediaConnectState = MediaConnectStateUnknown;\r
2153                  GeneralAttributes.MediaDuplexState = MediaDuplexStateUnknown;\r
2154                  GeneralAttributes.LookaheadSize = MAX_XFER_BLOCK_SIZE;\r
2155         \r
2156                  GeneralAttributes.PowerManagementCapabilities = NULL;\r
2157         \r
2158                  GeneralAttributes.MacOptions = NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA |\r
2159                                                                                 NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |\r
2160                                                                                 NDIS_MAC_OPTION_NO_LOOPBACK |\r
2161                                                                                 NDIS_MAC_OPTION_FULL_DUPLEX;\r
2162         \r
2163                  GeneralAttributes.SupportedPacketFilters = NDIS_PACKET_TYPE_DIRECTED |\r
2164                                                                                                         NDIS_PACKET_TYPE_MULTICAST |\r
2165                                                                                                         NDIS_PACKET_TYPE_ALL_MULTICAST |\r
2166                                                                                                         NDIS_PACKET_TYPE_BROADCAST;\r
2167                         \r
2168                  GeneralAttributes.MaxMulticastListSize = MAX_MCAST;\r
2169                  GeneralAttributes.MacAddressLength = HW_ADDR_LEN;\r
2170         \r
2171                  NdisMoveMemory(GeneralAttributes.PermanentMacAddress,\r
2172                                                 p_adapter->mac.addr,\r
2173                                                 HW_ADDR_LEN);\r
2174         \r
2175                  NdisMoveMemory(GeneralAttributes.CurrentMacAddress,\r
2176                                                 p_adapter->params.conf_mac.addr,\r
2177                                                 HW_ADDR_LEN);\r
2178         \r
2179                         \r
2180                  GeneralAttributes.PhysicalMediumType = NdisPhysicalMediumUnspecified;\r
2181                  GeneralAttributes.RecvScaleCapabilities = NULL;\r
2182                  GeneralAttributes.AccessType = NET_IF_ACCESS_BROADCAST; // NET_IF_ACCESS_BROADCAST for a typical ethernet adapter\r
2183                  GeneralAttributes.DirectionType = NET_IF_DIRECTION_SENDRECEIVE; // NET_IF_DIRECTION_SENDRECEIVE for a typical ethernet adapter\r
2184                  GeneralAttributes.ConnectionType = NET_IF_CONNECTION_DEDICATED;  // NET_IF_CONNECTION_DEDICATED for a typical ethernet adapter\r
2185                  GeneralAttributes.IfType = IF_TYPE_ETHERNET_CSMACD; // IF_TYPE_ETHERNET_CSMACD for a typical ethernet adapter (regardless of speed)\r
2186                  GeneralAttributes.IfConnectorPresent = TRUE; // RFC 2665 TRUE if physical adapter\r
2187         \r
2188                  GeneralAttributes.SupportedStatistics = NDIS_STATISTICS_XMIT_OK_SUPPORTED |\r
2189                                                                                                  NDIS_STATISTICS_RCV_OK_SUPPORTED |\r
2190                                                                                                  NDIS_STATISTICS_XMIT_ERROR_SUPPORTED |\r
2191                                                                                                  NDIS_STATISTICS_RCV_ERROR_SUPPORTED |\r
2192                                                                                                  NDIS_STATISTICS_RCV_CRC_ERROR_SUPPORTED |\r
2193                                                                                                  NDIS_STATISTICS_RCV_NO_BUFFER_SUPPORTED |\r
2194                                                                                                  NDIS_STATISTICS_TRANSMIT_QUEUE_LENGTH_SUPPORTED |\r
2195                                                                                                  NDIS_STATISTICS_GEN_STATISTICS_SUPPORTED;\r
2196                                                   \r
2197                  GeneralAttributes.SupportedOidList = (PNDIS_OID)SUPPORTED_OIDS;\r
2198                  GeneralAttributes.SupportedOidListLength = sizeof(SUPPORTED_OIDS);\r
2199         \r
2200                  status = NdisMSetMiniportAttributes(h_adapter,\r
2201                                                                                         (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&GeneralAttributes);\r
2202         \r
2203                  if (status != NDIS_STATUS_SUCCESS)\r
2204                  {\r
2205                          IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
2206                                  ("NdisMSetMiniportAttributes returned 0x%.8x.\n", status) );\r
2207                  }\r
2208         \r
2209 #if IPOIB_USE_DMA\r
2210         \r
2211                  NdisZeroMemory(&DmaDescription, sizeof(DmaDescription));\r
2212         \r
2213                  DmaDescription.Header.Type = NDIS_OBJECT_TYPE_SG_DMA_DESCRIPTION;\r
2214                  DmaDescription.Header.Revision = NDIS_SG_DMA_DESCRIPTION_REVISION_1;\r
2215                  DmaDescription.Header.Size = sizeof(NDIS_SG_DMA_DESCRIPTION);//NDIS_SIZEOF_SG_DMA_DESCRIPTION_REVISION_1;\r
2216         \r
2217                  DmaDescription.Flags = NDIS_SG_DMA_64_BIT_ADDRESS;\r
2218                  DmaDescription.MaximumPhysicalMapping = p_adapter->params.xfer_block_size;\r
2219                 \r
2220                  DmaDescription.ProcessSGListHandler = ipoib_process_sg_list;\r
2221                  DmaDescription.SharedMemAllocateCompleteHandler = NULL;\r
2222         \r
2223                  status = NdisMRegisterScatterGatherDma(\r
2224                                                 p_adapter->h_adapter,\r
2225                                                 &DmaDescription,\r
2226                                                 &p_adapter->NdisMiniportDmaHandle);\r
2227                                                 \r
2228                  if( status != NDIS_STATUS_SUCCESS )\r
2229                  {\r
2230                          ipoib_destroy_adapter( p_adapter );\r
2231                          IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
2232                                                          ("NdisMRegisterScatterGatherDma returned 0x%.8x.\n", status) );\r
2233                          return status;\r
2234                  }\r
2235 \r
2236                 \r
2237                 \r
2238 #endif\r
2239 #endif //if 0\r
2240 \r
2241 \r
2242 \r
2243 #if IPOIB_USE_DMA\r
2244 \r
2245                 InitNdisScatterGatherDma(p_adapter, h_adapter);\r
2246 \r
2247 \r
2248 \r
2249 #endif\r
2250                 /* Create the adapter adapter */\r
2251                 ib_status = ipoib_start_adapter( p_adapter );\r
2252                 if( ib_status != IB_SUCCESS )\r
2253                 {\r
2254                         ASSERT(FALSE);\r
2255                         NdisWriteErrorLogEntry( h_adapter,\r
2256                                 NDIS_ERROR_CODE_HARDWARE_FAILURE, 0 );\r
2257 #if  IPOIB_USE_DMA\r
2258                         NdisMDeregisterScatterGatherDma(p_adapter->NdisMiniportDmaHandle);\r
2259 #endif\r
2260                         ipoib_destroy_adapter( p_adapter );\r
2261                         IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
2262                                 ("ipoib_start_adapter returned status %d.\n", ib_status ) );\r
2263                         return NDIS_STATUS_FAILURE;\r
2264                 }\r
2265         \r
2266                 ipoib_ref_ibat();\r
2267         \r
2268                 IPOIB_EXIT( IPOIB_DBG_INIT );\r
2269                 return status;\r
2270         }\r
2271 \r
2272 \r
2273 //! Deallocates resources when the NIC is removed and halts the NIC..\r
2274 //TODO: Dispatch or Passive ?\r
2275 /*  IRQL = DISPATCH_LEVEL\r
2276 \r
2277 @param adapter_context The adapter context allocated at start\r
2278 */\r
2279 void\r
2280 ipoib_halt_ex(\r
2281         IN                              NDIS_HANDLE                                     adapter_context,\r
2282         IN                      NDIS_HALT_ACTION            HaltAction )\r
2283 {\r
2284         ipoib_adapter_t *p_adapter;\r
2285 \r
2286         IPOIB_ENTER( IPOIB_DBG_INIT );\r
2287 \r
2288         UNUSED_PARAM(HaltAction);\r
2289 //return;               \r
2290         ipoib_deref_ibat();\r
2291 \r
2292         CL_ASSERT( adapter_context );\r
2293         p_adapter = (ipoib_adapter_t*)adapter_context;\r
2294 \r
2295         IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_INIT,\r
2296                         ("Port %016I64x (CA %016I64x port %d) halting\n",\r
2297                         p_adapter->guids.port_guid.guid, p_adapter->guids.ca_guid,\r
2298                         p_adapter->guids.port_num) );\r
2299 \r
2300 #if IPOIB_USE_DMA\r
2301         if (p_adapter->NdisMiniportDmaHandle != NULL)\r
2302         {\r
2303                 NdisMDeregisterScatterGatherDma(p_adapter->NdisMiniportDmaHandle);\r
2304                 p_adapter->NdisMiniportDmaHandle = NULL;\r
2305         }\r
2306 #endif\r
2307         ipoib_destroy_adapter( p_adapter );\r
2308 \r
2309         IPOIB_EXIT( IPOIB_DBG_INIT );\r
2310 }\r
2311 \r
2312 \r
2313 //! Reports the state of the NIC, or monitors the responsiveness of an underlying device driver.\r
2314 /*  IRQL = DISPATCH_LEVEL\r
2315 \r
2316 @param adapter_context The adapter context allocated at start\r
2317 @return TRUE if the driver determines that its NIC is not operating\r
2318 */\r
2319 BOOLEAN\r
2320 ipoib_check_for_hang(\r
2321         IN                              NDIS_HANDLE                                     adapter_context )\r
2322 {\r
2323         ipoib_adapter_t *p_adapter;\r
2324 \r
2325         IPOIB_ENTER( IPOIB_DBG_INIT );\r
2326 //return FALSE;\r
2327         CL_ASSERT( adapter_context );\r
2328         p_adapter = (ipoib_adapter_t*)adapter_context;\r
2329 \r
2330         if( p_adapter->reset )\r
2331         {\r
2332                 IPOIB_EXIT( IPOIB_DBG_INIT );\r
2333                 return FALSE;\r
2334         }\r
2335         if (p_adapter->hung) {\r
2336                 ipoib_resume_oids(p_adapter);\r
2337         }\r
2338 \r
2339         IPOIB_EXIT( IPOIB_DBG_INIT );\r
2340         return (p_adapter->hung? TRUE:FALSE);\r
2341 }\r
2342 \r
2343 \r
2344 /*++\r
2345 Routine Description:\r
2346         The routine sets an NDIS_OFFLOAD structure indicates the current offload \r
2347         capabilities that are provided by the miniport adapter \r
2348 \r
2349 Arguments:\r
2350         pPort - a pointer to port object\r
2351         offload - reference to NDIS_OFFLOAD object that should be filled\r
2352 \r
2353 Return Value:\r
2354         None.\r
2355 \r
2356 --*/\r
2357 //TODO\r
2358 #if 0\r
2359 static\r
2360 void\r
2361 __ipoib_get_offload_config(\r
2362         ipoib_port_t *pPort,\r
2363         NDIS_OFFLOAD *p_offload\r
2364         )\r
2365 {\r
2366         NDIS_STATUS Status;\r
2367         ULONG TxChksumOffload = ((MP_GET_PORT_CONFIG(pPort, TxChksumOffload) == TRUE) ? NDIS_OFFLOAD_SET_ON : NDIS_OFFLOAD_SET_OFF);\r
2368         ULONG RxChksumOffload = ((MP_GET_PORT_CONFIG(pPort, RxChksumOffload) == TRUE) ? NDIS_OFFLOAD_SET_ON : NDIS_OFFLOAD_SET_OFF);\r
2369         BOOLEAN fLargeSendOffload = MP_GET_PORT_CONFIG(pPort, LargeSendOffload);\r
2370         ULONG ulEncapsulation = NDIS_ENCAPSULATION_IEEE_802_3 | NDIS_ENCAPSULATION_IEEE_802_3_P_AND_Q;\r
2371             \r
2372         NdisZeroMemory(&*p_offload, sizeof(NDIS_OFFLOAD));\r
2373         *p_offload.Header.Type = NDIS_OBJECT_TYPE_OFFLOAD;\r
2374         *p_offload.Header.Revision = NDIS_OFFLOAD_REVISION_1; // BUGBUG: do we need to support revision 2? UH 17-May-2008\r
2375         *p_offload.Header.Size = NDIS_SIZEOF_NDIS_OFFLOAD_REVISION_1;\r
2376 \r
2377         *p_offload.Checksum.IPv4Transmit.Encapsulation = ulEncapsulation;\r
2378         *p_offload.Checksum.IPv4Transmit.IpOptionsSupported = TxChksumOffload;\r
2379         *p_offload.Checksum.IPv4Transmit.TcpOptionsSupported = TxChksumOffload;\r
2380         *p_offload.Checksum.IPv4Transmit.TcpChecksum = TxChksumOffload;\r
2381         *p_offload.Checksum.IPv4Transmit.UdpChecksum = NDIS_OFFLOAD_NOT_SUPPORTED;\r
2382         *p_offload.Checksum.IPv4Transmit.IpChecksum = TxChksumOffload;\r
2383 \r
2384         *p_offload.Checksum.IPv4Receive.Encapsulation = ulEncapsulation;\r
2385         *p_offload.Checksum.IPv4Receive.IpOptionsSupported = RxChksumOffload;\r
2386         *p_offload.Checksum.IPv4Receive.TcpOptionsSupported = RxChksumOffload;\r
2387         *p_offload.Checksum.IPv4Receive.TcpChecksum = RxChksumOffload;\r
2388         *p_offload.Checksum.IPv4Receive.UdpChecksum = NDIS_OFFLOAD_NOT_SUPPORTED; \r
2389         *p_offload.Checksum.IPv4Receive.IpChecksum = RxChksumOffload;\r
2390 \r
2391         *p_offload.Checksum.IPv6Transmit.Encapsulation = ulEncapsulation;\r
2392         *p_offload.Checksum.IPv6Transmit.IpExtensionHeadersSupported = TxChksumOffload;\r
2393         *p_offload.Checksum.IPv6Transmit.TcpOptionsSupported = TxChksumOffload;\r
2394         *p_offload.Checksum.IPv6Transmit.TcpChecksum = TxChksumOffload;\r
2395         *p_offload.Checksum.IPv6Transmit.UdpChecksum = NDIS_OFFLOAD_NOT_SUPPORTED;\r
2396 \r
2397 \r
2398         *p_offload.Checksum.IPv6Receive.Encapsulation = ulEncapsulation;\r
2399         *p_offload.Checksum.IPv6Receive.IpExtensionHeadersSupported = RxChksumOffload;\r
2400         *p_offload.Checksum.IPv6Receive.TcpOptionsSupported = RxChksumOffload;\r
2401         *p_offload.Checksum.IPv6Receive.TcpChecksum = RxChksumOffload;\r
2402         *p_offload.Checksum.IPv6Receive.UdpChecksum = NDIS_OFFLOAD_NOT_SUPPORTED;\r
2403 \r
2404         if (fLargeSendOffload)\r
2405         {\r
2406             *p_offload.LsoV1.IPv4.Encapsulation = ulEncapsulation;\r
2407             *p_offload.LsoV1.IPv4.MaxOffLoadSize = LARGE_SEND_OFFLOAD_SIZE;\r
2408             *p_offload.LsoV1.IPv4.MinSegmentCount = 1;\r
2409             *p_offload.LsoV1.IPv4.TcpOptions = NDIS_OFFLOAD_SUPPORTED;\r
2410             *p_offload.LsoV1.IPv4.IpOptions = NDIS_OFFLOAD_SUPPORTED;\r
2411         }\r
2412 }\r
2413 #endif\r
2414 \r
2415 //! Returns information about the capabilities and status of the driver and/or its NIC.\r
2416 /*  IRQL = DISPATCH_LEVEL\r
2417 \r
2418 @param adapter_context The adapter context allocated at start\r
2419 @param oid Object ID representing the query operation to be carried out\r
2420 @param info_buf Buffer containing any input for this query and location for output\r
2421 @param info_buf_len Number of bytes available in info_buf\r
2422 @param p_bytes_written Pointer to number of bytes written into info_buf\r
2423 @param p_bytes_needed Pointer to number of bytes needed to satisfy this oid\r
2424 @return NDIS_STATUS_SUCCESS, NDIS_STATUS_PENDING, NDIS_STATUS_INVALID_OID,\r
2425 NDIS_STATUS_INVALID_LENGTH, NDIS_STATUS_NOT_ACCEPTED, NDIS_STATUS_NOT_SUPPORTED,\r
2426 NDIS_STATUS_RESOURCES\r
2427 */\r
2428         NDIS_STATUS\r
2429 ipoib_query_info(\r
2430         IN                              NDIS_HANDLE                                     adapter_context,\r
2431         IN                              NDIS_OID                                        oid,\r
2432         IN                              PVOID                                           info_buf,\r
2433         IN                              ULONG                                           info_buf_len,\r
2434                 OUT                     PULONG                                          p_bytes_written,\r
2435                 OUT                     PULONG                                          p_bytes_needed )\r
2436         {\r
2437         ipoib_adapter_t         *p_adapter;\r
2438                 NDIS_STATUS             status;\r
2439                 USHORT                          version;\r
2440         ULONG                           info;\r
2441                 PVOID                           src_buf;\r
2442                 ULONG                           buf_len;\r
2443                 pending_oid_t           oid_info;\r
2444         uint8_t                         port_num;\r
2445                 \r
2446                 IPOIB_ENTER( IPOIB_DBG_OID );\r
2447                 \r
2448                 oid_info.oid = oid;\r
2449                 oid_info.p_buf = info_buf;\r
2450                 oid_info.buf_len = info_buf_len;\r
2451                 oid_info.p_bytes_used = p_bytes_written;\r
2452                 oid_info.p_bytes_needed = p_bytes_needed;\r
2453                 \r
2454                 CL_ASSERT( adapter_context );\r
2455                 p_adapter = (ipoib_adapter_t*)adapter_context;\r
2456 \r
2457                 CL_ASSERT( p_bytes_written );\r
2458                 CL_ASSERT( p_bytes_needed );\r
2459                 CL_ASSERT( !p_adapter->pending_query );\r
2460                 \r
2461                         status = NDIS_STATUS_SUCCESS;\r
2462                         src_buf = &info;\r
2463                 buf_len = sizeof(info);\r
2464         \r
2465                 port_num = p_adapter->guids.port_num;\r
2466         \r
2467                 switch( oid )\r
2468                 {\r
2469                 /* Required General */\r
2470                 case OID_GEN_SUPPORTED_LIST:\r
2471                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2472                                 ("Port %d received query for OID_GEN_SUPPORTED_LIST\n", port_num) );\r
2473                         src_buf = (PVOID)SUPPORTED_OIDS;\r
2474                         buf_len = sizeof(SUPPORTED_OIDS);\r
2475                         break;\r
2476         \r
2477                 case OID_GEN_HARDWARE_STATUS:\r
2478                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2479                                 ("Port %d received query for OID_GEN_HARDWARE_STATUS\n", port_num) );\r
2480                         cl_obj_lock( &p_adapter->obj );\r
2481                         switch( p_adapter->state )\r
2482                         {\r
2483                         case IB_PNP_PORT_ADD:\r
2484                                 IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2485                                         ("Port %d returning NdisHardwareStatusInitializing\n", port_num) );\r
2486                                 info = NdisHardwareStatusInitializing;\r
2487                                 break;\r
2488                                 \r
2489                         case IB_PNP_PORT_ACTIVE:\r
2490                                 IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2491                                         ("Port %d returning NdisHardwareStatusReady\n", port_num) );\r
2492                                 info = NdisHardwareStatusReady;\r
2493                                 break;\r
2494         \r
2495                         default:\r
2496                                 IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2497                                         ("Port %d returning NdisHardwareStatusNotReady\n", port_num) );\r
2498                                 info = NdisHardwareStatusNotReady;\r
2499                         }\r
2500                         cl_obj_unlock( &p_adapter->obj );\r
2501                         break;\r
2502         \r
2503                 case OID_GEN_MEDIA_SUPPORTED:\r
2504                 case OID_GEN_MEDIA_IN_USE:\r
2505                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2506                                 ("Port %d received query for OID_GEN_MEDIA_SUPPORTED "\r
2507                                 "or OID_GEN_MEDIA_IN_USE\n", port_num) );\r
2508                         info = NdisMedium802_3;\r
2509                         break;\r
2510         \r
2511                 case OID_GEN_MAXIMUM_FRAME_SIZE:\r
2512                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2513                                 ("Port %d received query for OID_GEN_MAXIMUM_FRAME_SIZE\n", port_num) );\r
2514                         if( p_adapter->params.cm_enabled )\r
2515                         {\r
2516                                 info = p_adapter->params.cm_payload_mtu;\r
2517                         }\r
2518                         else\r
2519                         {\r
2520                                 info = p_adapter->params.payload_mtu;\r
2521                         }\r
2522                         break;\r
2523         \r
2524                 case OID_GEN_LINK_SPEED:\r
2525                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2526                                 ("Port %d received query for OID_GEN_LINK_SPEED\n", port_num) );\r
2527                         if (info_buf_len < buf_len)\r
2528                         {\r
2529                                 break;\r
2530                         }\r
2531         \r
2532                         cl_obj_lock( &p_adapter->obj );\r
2533                         switch( p_adapter->state )\r
2534                         {\r
2535                         case IB_PNP_PORT_ADD:\r
2536                                 /* Mark the adapter as pending an OID */\r
2537                                 p_adapter->pending_query = TRUE;\r
2538         \r
2539                                 /* Save the request parameters. */\r
2540                                 p_adapter->query_oid = oid_info;\r
2541         \r
2542                                 IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2543                                         ("Port %d returning NDIS_STATUS_PENDING\n", port_num) );\r
2544                                 status = NDIS_STATUS_PENDING;\r
2545                                 break;\r
2546         \r
2547                         case IB_PNP_PORT_REMOVE:\r
2548                                 IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2549                                         ("Port %d returning NDIS_STATUS_NOT_ACCEPTED\n", port_num) );\r
2550                                 status = NDIS_STATUS_NOT_ACCEPTED;\r
2551                                 break;\r
2552         \r
2553                         default:\r
2554                                 CL_ASSERT( p_adapter->p_port );\r
2555                                 info = p_adapter->port_rate;\r
2556                                 break;\r
2557                         }\r
2558                         cl_obj_unlock( &p_adapter->obj );\r
2559                         break;\r
2560         \r
2561                 case OID_GEN_TRANSMIT_BUFFER_SPACE:\r
2562                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2563                                 ("Port %d received query for OID_GEN_TRANSMIT_BUFFER_SPACE\n", port_num) );\r
2564                         if( p_adapter->params.cm_enabled )\r
2565                                 info = p_adapter->params.sq_depth * p_adapter->params.cm_xfer_block_size;\r
2566                         else\r
2567                                 info = p_adapter->params.sq_depth * p_adapter->params.xfer_block_size;\r
2568                         break;\r
2569         \r
2570                 case OID_GEN_RECEIVE_BUFFER_SPACE:\r
2571                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2572                                 ("Port %d received query for OID_GEN_TRANSMIT_BUFFER_SPACE "\r
2573                                 "or OID_GEN_RECEIVE_BUFFER_SPACE\n", port_num) );\r
2574                         if( p_adapter->params.cm_enabled )\r
2575                                 info = p_adapter->params.rq_depth * p_adapter->params.cm_xfer_block_size;\r
2576                         else\r
2577                                 info = p_adapter->params.rq_depth * p_adapter->params.xfer_block_size;\r
2578                         break;\r
2579         \r
2580                 case OID_GEN_MAXIMUM_LOOKAHEAD:\r
2581                 case OID_GEN_CURRENT_LOOKAHEAD:\r
2582                 case OID_GEN_TRANSMIT_BLOCK_SIZE:\r
2583                 case OID_GEN_RECEIVE_BLOCK_SIZE:\r
2584                 case OID_GEN_MAXIMUM_TOTAL_SIZE:\r
2585                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2586                                 ("Port %d received query for OID_GEN_MAXIMUM_LOOKAHEAD "\r
2587                                 "or OID_GEN_CURRENT_LOOKAHEAD or "\r
2588                                 "OID_GEN_TRANSMIT_BLOCK_SIZE or "\r
2589                                 "OID_GEN_RECEIVE_BLOCK_SIZE or "\r
2590                                 "OID_GEN_MAXIMUM_TOTAL_SIZE\n", port_num) );\r
2591                         if( p_adapter->params.cm_enabled )\r
2592                                 info = p_adapter->params.cm_xfer_block_size;\r
2593                         else\r
2594                                 info = p_adapter->params.xfer_block_size;\r
2595                         break;\r
2596         \r
2597                 case OID_GEN_VENDOR_ID:\r
2598                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2599                                 ("Port %d received query for OID_GEN_VENDOR_ID\n", port_num) );\r
2600                         src_buf = (void*)VENDOR_ID;\r
2601                 buf_len = sizeof(VENDOR_ID);\r
2602                         break;\r
2603         \r
2604                 case OID_GEN_VENDOR_DESCRIPTION:\r
2605                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID, \r
2606                                 ("Port %d received query for OID_GEN_VENDOR_DESCRIPTION\n", port_num) );\r
2607                         src_buf = VENDOR_DESCRIPTION;\r
2608                 buf_len = sizeof(VENDOR_DESCRIPTION);\r
2609                         break;\r
2610         \r
2611                 case OID_GEN_VENDOR_DRIVER_VERSION:\r
2612                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2613                                 ("Port %d received query for OID_GEN_VENDOR_DRIVER_VERSION\n", port_num) );\r
2614                         src_buf = &version;\r
2615                 buf_len = sizeof(version);\r
2616                         //TODO: Figure out what the right version is.\r
2617                         version = 1 << 8 | 1;\r
2618                         break;\r
2619         \r
2620                 case OID_GEN_PHYSICAL_MEDIUM:\r
2621                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2622                                 ("Port %d received query for OID_GEN_PHYSICAL_MEDIUM\n", port_num) );\r
2623                         info = NdisPhysicalMediumUnspecified;\r
2624                         break;\r
2625         \r
2626                 case OID_GEN_CURRENT_PACKET_FILTER:\r
2627                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2628                                 ("Port %d received query for OID_GEN_CURRENT_PACKET_FILTER\n", port_num) );\r
2629                         info = p_adapter->packet_filter;\r
2630                         break;\r
2631         \r
2632                 case OID_GEN_DRIVER_VERSION:\r
2633                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2634                                 ("Port %d received query for OID_GEN_DRIVER_VERSION\n", port_num) );\r
2635                         src_buf = &version;\r
2636                 buf_len = sizeof(version);\r
2637                         version = MAJOR_NDIS_VERSION << 8 | MINOR_NDIS_VERSION;\r
2638                         break;\r
2639         \r
2640                 case OID_GEN_MAC_OPTIONS:\r
2641                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2642                                 ("Port %d received query for OID_GEN_MAC_OPTIONS\n", port_num) );\r
2643                         info = NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA |\r
2644                                 NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |\r
2645                                 NDIS_MAC_OPTION_NO_LOOPBACK |\r
2646                                 NDIS_MAC_OPTION_FULL_DUPLEX;\r
2647         //TODO: Figure out if we will support priority and VLANs.\r
2648         //                              NDIS_MAC_OPTION_8021P_PRIORITY;\r
2649         //#ifdef NDIS51_MINIPORT\r
2650         //                      info |= NDIS_MAC_OPTION_8021Q_VLAN;\r
2651         //#endif\r
2652                         break;\r
2653         \r
2654                 case OID_GEN_MEDIA_CONNECT_STATUS:\r
2655                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2656                                 ("Port %d received query for OID_GEN_MEDIA_CONNECT_STATUS\n", port_num) );\r
2657                         cl_obj_lock( &p_adapter->obj );\r
2658                         switch( p_adapter->state )\r
2659                         {\r
2660                         case IB_PNP_PORT_ADD:\r
2661                         case IB_PNP_PORT_INIT:\r
2662                                 /*\r
2663                                  * Delay reporting media state until we know whether the port is\r
2664                                  * either up or down.\r
2665                                  */\r
2666                                 p_adapter->pending_query = TRUE;\r
2667                                 p_adapter->query_oid = oid_info;\r
2668         \r
2669                                 IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2670                                         ("Port %d returning NDIS_STATUS_PENDING\n", port_num) );\r
2671                                 status = NDIS_STATUS_PENDING;\r
2672                                 break;\r
2673         \r
2674                         case IB_PNP_PORT_ACTIVE:\r
2675                                 IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2676                                         ("Port %d returning NdisMediaStateConnected\n", port_num) );\r
2677                                 info = NdisMediaStateConnected;\r
2678                                 break;\r
2679         \r
2680                         case IB_PNP_PORT_REMOVE:\r
2681                                 IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2682                                         ("Port %d returning NDIS_STATUS_NOT_ACCEPTED\n", port_num) );\r
2683                                 status = NDIS_STATUS_NOT_ACCEPTED;\r
2684                                 break;\r
2685         \r
2686                         default:\r
2687                                 IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2688                                         ("Port %d returning NdisMediaStateDisconnected\n", port_num) );\r
2689                                 info = NdisMediaStateDisconnected;\r
2690                         }\r
2691                         cl_obj_unlock( &p_adapter->obj );\r
2692                         break;\r
2693         \r
2694                 case OID_GEN_MAXIMUM_SEND_PACKETS:\r
2695                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2696                                 ("Port %d received query for OID_GEN_MAXIMUM_SEND_PACKETS\n", port_num) );\r
2697                         info = MINIPORT_MAX_SEND_PACKETS;\r
2698                         break;\r
2699         \r
2700                 /* Required General Statistics */\r
2701                 case OID_GEN_STATISTICS:\r
2702                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2703                                 ("Port %d received query for OID_GEN_STATISTICS\n", port_num) );\r
2704                         src_buf = NULL;   \r
2705                          buf_len =  sizeof(NDIS_STATISTICS_INFO);\r
2706                         if (info_buf_len < buf_len)\r
2707                         {\r
2708                            break;\r
2709                         } \r
2710                         status = ipoib_get_gen_stat(p_adapter, &oid_info );\r
2711                         break;\r
2712         \r
2713                 case OID_GEN_XMIT_OK:\r
2714                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2715                                 ("Port %d received query for OID_GEN_XMIT_OK\n", port_num) );\r
2716                         src_buf = NULL;\r
2717                         status = ipoib_get_send_stat( p_adapter, IP_STAT_SUCCESS, &oid_info );\r
2718                         break;\r
2719         \r
2720                 case OID_GEN_RCV_OK:\r
2721                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2722                                 ("Port %d received query for OID_GEN_RCV_OK\n", port_num) );\r
2723                         src_buf = NULL;\r
2724                         status = ipoib_get_recv_stat( p_adapter, IP_STAT_SUCCESS, &oid_info );\r
2725                         break;\r
2726         \r
2727                 case OID_GEN_XMIT_ERROR:\r
2728                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2729                                 ("Port %d received query for OID_GEN_XMIT_ERROR\n", port_num) );\r
2730                         src_buf = NULL;\r
2731                         status = ipoib_get_send_stat( p_adapter, IP_STAT_ERROR, &oid_info );\r
2732                         break;\r
2733         \r
2734                 case OID_GEN_RCV_ERROR:\r
2735                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2736                                 ("Port %d received query for OID_GEN_RCV_ERROR\n", port_num) );\r
2737                         src_buf = NULL;\r
2738                         status = ipoib_get_recv_stat( p_adapter, IP_STAT_ERROR, &oid_info );\r
2739                         break;\r
2740         \r
2741                 case OID_GEN_RCV_NO_BUFFER:\r
2742                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2743                                 ("Port %d received query for OID_GEN_RCV_NO_BUFFER\n", port_num) );\r
2744                         src_buf = NULL;\r
2745                         status = ipoib_get_recv_stat( p_adapter, IP_STAT_DROPPED, &oid_info );\r
2746                         break;\r
2747         \r
2748                 case OID_GEN_DIRECTED_BYTES_XMIT:\r
2749                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2750                                 ("Port %d received query for OID_GEN_DIRECTED_BYTES_XMIT\n", port_num) );\r
2751                         src_buf = NULL;\r
2752                         status = ipoib_get_send_stat( p_adapter, IP_STAT_UCAST_BYTES, &oid_info );\r
2753                         break;\r
2754         \r
2755                 case OID_GEN_DIRECTED_FRAMES_XMIT:\r
2756                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2757                                 ("Port %d received query for OID_GEN_DIRECTED_FRAMES_XMIT\n", port_num) );\r
2758                         src_buf = NULL;\r
2759                         status = ipoib_get_send_stat( p_adapter, IP_STAT_UCAST_FRAMES, &oid_info );\r
2760                         break;\r
2761         \r
2762                 case OID_GEN_MULTICAST_BYTES_XMIT:\r
2763                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2764                                 ("Port %d received query for OID_GEN_MULTICAST_BYTES_XMIT\n", port_num) );\r
2765                         src_buf = NULL;\r
2766                         status = ipoib_get_send_stat( p_adapter, IP_STAT_MCAST_BYTES, &oid_info );\r
2767                         break;\r
2768         \r
2769                 case OID_GEN_MULTICAST_FRAMES_XMIT:\r
2770                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2771                                 ("Port %d received query for OID_GEN_MULTICAST_FRAMES_XMIT\n", port_num) );\r
2772                         src_buf = NULL;\r
2773                         status = ipoib_get_send_stat( p_adapter, IP_STAT_MCAST_FRAMES, &oid_info );\r
2774                         break;\r
2775         \r
2776                 case OID_GEN_BROADCAST_BYTES_XMIT:\r
2777                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2778                                 ("Port %d received query for OID_GEN_BROADCAST_BYTES_XMIT\n", port_num) );\r
2779                         src_buf = NULL;\r
2780                         status = ipoib_get_send_stat( p_adapter, IP_STAT_BCAST_BYTES, &oid_info );\r
2781                         break;\r
2782         \r
2783                 case OID_GEN_BROADCAST_FRAMES_XMIT:\r
2784                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2785                                 ("Port %d received query for OID_GEN_BROADCAST_FRAMES_XMIT\n", port_num) );\r
2786                         src_buf = NULL;\r
2787                         status = ipoib_get_send_stat( p_adapter, IP_STAT_BCAST_FRAMES, &oid_info );\r
2788                         break;\r
2789         \r
2790                 case OID_GEN_DIRECTED_BYTES_RCV:\r
2791                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2792                                 ("Port %d received query for OID_GEN_DIRECTED_BYTES_RCV\n", port_num) );\r
2793                         src_buf = NULL;\r
2794                         status = ipoib_get_recv_stat( p_adapter, IP_STAT_UCAST_BYTES, &oid_info );\r
2795                         break;\r
2796         \r
2797                 case OID_GEN_DIRECTED_FRAMES_RCV:\r
2798                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2799                                 ("Port %d received query for OID_GEN_DIRECTED_FRAMES_RCV\n", port_num) );\r
2800                         src_buf = NULL;\r
2801                         status = ipoib_get_recv_stat( p_adapter, IP_STAT_UCAST_FRAMES, &oid_info );\r
2802                         break;\r
2803         \r
2804                 case OID_GEN_MULTICAST_BYTES_RCV:\r
2805                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2806                                 ("Port %d received query for OID_GEN_MULTICAST_BYTES_RCV\n", port_num) );\r
2807                         src_buf = NULL;\r
2808                         status = ipoib_get_recv_stat( p_adapter, IP_STAT_MCAST_BYTES, &oid_info );\r
2809                         break;\r
2810         \r
2811                 case OID_GEN_MULTICAST_FRAMES_RCV:\r
2812                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2813                                 ("Port %d received query for OID_GEN_MULTICAST_FRAMES_RCV\n", port_num) );\r
2814                         src_buf = NULL;\r
2815                         status = ipoib_get_recv_stat( p_adapter, IP_STAT_MCAST_FRAMES, &oid_info );\r
2816                         break;\r
2817         \r
2818                 case OID_GEN_BROADCAST_BYTES_RCV:\r
2819                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2820                                 ("Port %d received query for OID_GEN_BROADCAST_BYTES_RCV\n", port_num) );\r
2821                         src_buf = NULL;\r
2822                         status = ipoib_get_recv_stat( p_adapter, IP_STAT_BCAST_BYTES, &oid_info );\r
2823                         break;\r
2824         \r
2825                 case OID_GEN_BROADCAST_FRAMES_RCV:\r
2826                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2827                                 ("Port %d received query for OID_GEN_BROADCAST_FRAMES_RCV\n", port_num) );\r
2828                         src_buf = NULL;\r
2829                         status = ipoib_get_recv_stat( p_adapter, IP_STAT_BCAST_FRAMES, &oid_info );\r
2830                         break;\r
2831         \r
2832                 /* Required Ethernet operational characteristics */\r
2833                 case OID_802_3_PERMANENT_ADDRESS:\r
2834                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2835                                 ("Port %d received query for OID_802_3_PERMANENT_ADDRESS\n", port_num) );\r
2836                         src_buf = &p_adapter->mac;\r
2837                 buf_len = sizeof(p_adapter->mac);\r
2838                         break;\r
2839         \r
2840                 case OID_802_3_CURRENT_ADDRESS:\r
2841                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2842                                 ("Port %d received query for OID_802_3_CURRENT_ADDRESS\n", port_num) );\r
2843                         src_buf = &p_adapter->params.conf_mac;\r
2844                 buf_len = sizeof(p_adapter->params.conf_mac);\r
2845                         break;\r
2846         \r
2847                 case OID_802_3_MULTICAST_LIST:\r
2848                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2849                                 ("Port %d received query for OID_802_3_MULTICAST_LIST\n", port_num) );\r
2850                         src_buf = p_adapter->mcast_array;\r
2851                 buf_len = p_adapter->mcast_array_size * sizeof(mac_addr_t);\r
2852                         break;\r
2853         \r
2854                 case OID_802_3_MAXIMUM_LIST_SIZE:\r
2855                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2856                                 ("Port %d received query for OID_802_3_MAXIMUM_LIST_SIZE\n", port_num) );\r
2857                         info = MAX_MCAST;\r
2858                         break;\r
2859         \r
2860                 case OID_802_3_MAC_OPTIONS:\r
2861                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2862                                 ("Port %d received query for OID_802_3_MAC_OPTIONS\n", port_num) );\r
2863                         info = 0;\r
2864                         break;\r
2865         \r
2866                 /* Required Ethernet stats */\r
2867                 case OID_802_3_RCV_ERROR_ALIGNMENT:\r
2868                 case OID_802_3_XMIT_ONE_COLLISION:\r
2869                 case OID_802_3_XMIT_MORE_COLLISIONS:\r
2870                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2871                                 ("Port %d received query for OID_802_3_RCV_ERROR_ALIGNMENT or "\r
2872                                 "OID_802_3_XMIT_ONE_COLLISION or "\r
2873                                 "OID_802_3_XMIT_MORE_COLLISIONS\n", port_num) );\r
2874                         info = 0;\r
2875                         break;\r
2876         \r
2877                 case OID_TCP_TASK_OFFLOAD:\r
2878                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2879                                 ("Port %d received query for OID_TCP_TASK_OFFLOAD\n", port_num) );\r
2880                         src_buf = NULL;\r
2881                         status = __ipoib_get_tcp_task_offload( p_adapter, &oid_info );\r
2882                         break;\r
2883         \r
2884                 /* Optional General */\r
2885                 case OID_GEN_SUPPORTED_GUIDS:\r
2886 #ifdef NDIS51_MINIPORT\r
2887                 case OID_GEN_VLAN_ID:\r
2888 #endif\r
2889         \r
2890                 /* Optional General Stats */\r
2891                 case OID_GEN_RCV_CRC_ERROR:\r
2892                 case OID_GEN_TRANSMIT_QUEUE_LENGTH:\r
2893         \r
2894                 /* Optional Ethernet Stats */\r
2895                 case OID_802_3_XMIT_DEFERRED:\r
2896                 case OID_802_3_XMIT_MAX_COLLISIONS:\r
2897                 case OID_802_3_RCV_OVERRUN:\r
2898                 case OID_802_3_XMIT_UNDERRUN:\r
2899                 case OID_802_3_XMIT_HEARTBEAT_FAILURE:\r
2900                 case OID_802_3_XMIT_TIMES_CRS_LOST:\r
2901                 case OID_802_3_XMIT_LATE_COLLISIONS:\r
2902                 case OID_PNP_CAPABILITIES:\r
2903                         status = NDIS_STATUS_NOT_SUPPORTED;\r
2904                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2905                                 ("Port %d received an unsupported oid of 0x%.8X!\n", port_num, oid) );\r
2906                         break;\r
2907         \r
2908                 case OID_GEN_PROTOCOL_OPTIONS:\r
2909                 case OID_GEN_NETWORK_LAYER_ADDRESSES:\r
2910                 case OID_GEN_TRANSPORT_HEADER_OFFSET:\r
2911                 case OID_PNP_ENABLE_WAKE_UP:\r
2912                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2913                                 ("Port %d received query for OID_GEN_PROTOCOL_OPTIONS or OID_GEN_NETWORK_LAYER_ADDRESSES or OID_GEN_TRANSPORT_HEADER_OFFSET  OID_PNP_ENABLE_WAKE_UPn", port_num) );\r
2914                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2915                                 ("Number of OID: 0x%.8X!\n", oid) );\r
2916                         status = NDIS_STATUS_SUCCESS; \r
2917                         break;\r
2918                         \r
2919                 case OID_PNP_QUERY_POWER:\r
2920                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2921                                 ("Port %d received query for OID_TCP_TASK_OFFLOAD\n", port_num) );\r
2922                         // Status is pre-set in this routine to Success\r
2923                         status = NDIS_STATUS_SUCCESS; \r
2924                         break;\r
2925         \r
2926                 case OID_TCP_OFFLOAD_CURRENT_CONFIG:\r
2927                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2928                                 ("Port %d received query for OID_PNP_QUERY_POWER\n", port_num) );\r
2929                                 //ulBytesAvailable = ulInfoLen = sizeof(NDIS_OFFLOAD);\r
2930                                 if (info_buf_len <  sizeof(NDIS_OFFLOAD))\r
2931                                 {\r
2932                                         status = NDIS_STATUS_BUFFER_TOO_SHORT;\r
2933                                         *p_bytes_needed = sizeof(NDIS_OFFLOAD) ;\r
2934                                         break;\r
2935                                 }\r
2936         \r
2937                                 //ipoib_offload_config(pPort, &offload);\r
2938                                 //pInfo = &offload;\r
2939                                 break;\r
2940         \r
2941                 default:\r
2942                         status = NDIS_STATUS_INVALID_OID;\r
2943                 //      IPOIB_PRINT( TRACE_LEVEL_ERROR,IPOIB_DBG_OID,\r
2944                         //      ("Port %d received an invalid oid of 0x%.8X!\n", port_num, oid) );\r
2945                         break;\r
2946                 }\r
2947         \r
2948                 /*\r
2949                  * Complete the request as if it was handled asynchronously to maximize\r
2950                  * code reuse for when we really handle the requests asynchronously.\r
2951                  * Note that this requires the QueryInformation entry point to always\r
2952                  * return NDIS_STATUS_PENDING\r
2953                  */\r
2954                 if( status != NDIS_STATUS_PENDING )\r
2955                 {\r
2956                         ipoib_complete_query(\r
2957                                 p_adapter, &oid_info, status, src_buf, buf_len );\r
2958                         return status;\r
2959                 }\r
2960         \r
2961                 IPOIB_EXIT( IPOIB_DBG_OID );\r
2962                 return NDIS_STATUS_PENDING;\r
2963         }\r
2964         \r
2965 \r
2966 static void\r
2967 ipoib_complete_query(\r
2968         IN                              ipoib_adapter_t* const          p_adapter,\r
2969         IN                              pending_oid_t* const            p_oid_info,\r
2970         IN              const   NDIS_STATUS                                     status,\r
2971         IN              const   void* const                                     p_buf,\r
2972         IN              const   ULONG                                           buf_len )\r
2973 {\r
2974         NDIS_STATUS             oid_status = status;\r
2975 \r
2976         IPOIB_ENTER( IPOIB_DBG_OID );\r
2977 \r
2978         CL_ASSERT( status != NDIS_STATUS_PENDING );\r
2979 \r
2980         if( status == NDIS_STATUS_SUCCESS )\r
2981         {\r
2982                 if( p_oid_info->buf_len < buf_len )\r
2983                 {\r
2984                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
2985                                 ("Insufficient buffer space.  "\r
2986                                 "Returning NDIS_STATUS_INVALID_LENGTH.\n") );\r
2987                         oid_status = NDIS_STATUS_INVALID_LENGTH;\r
2988                         *p_oid_info->p_bytes_needed = buf_len;\r
2989                         *p_oid_info->p_bytes_used = 0;\r
2990                 }\r
2991                 else if( p_oid_info->p_buf )\r
2992                 {\r
2993                         /* Only copy if we have a distinct source buffer. */\r
2994                         if( p_buf )\r
2995                         {\r
2996                                 NdisMoveMemory( p_oid_info->p_buf, p_buf, buf_len );\r
2997                                 *p_oid_info->p_bytes_used = buf_len;\r
2998                         }\r
2999                 }\r
3000                 else\r
3001                 {\r
3002                         IPOIB_PRINT( TRACE_LEVEL_INFORMATION,IPOIB_DBG_OID,\r
3003                                 ("Returning NDIS_NOT_ACCEPTED") );\r
3004                         oid_status = NDIS_STATUS_NOT_ACCEPTED;\r
3005                 }\r
3006         }\r
3007         else\r
3008         {\r
3009                 *p_oid_info->p_bytes_used = 0;\r
3010         }