47dded07318e92765c1cf7f4832bb89d56391184
[mirror/winof/.git] / ulp / ipoib_NDIS6_CM / kernel / ipoib_port.h
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_port.h 4226 2009-04-06 06:01:03Z xalex $\r
32  */\r
33 \r
34 \r
35 \r
36 #ifndef _IPOIB_PORT_H_\r
37 #define _IPOIB_PORT_H_\r
38 \r
39 \r
40 #include <iba/ib_al.h>\r
41 #include <complib/cl_obj.h>\r
42 #include <complib/cl_qmap.h>\r
43 #include <complib/cl_fleximap.h>\r
44 #include <ip_packet.h>\r
45 #include "ipoib_xfr_mgr.h"\r
46 #include "ipoib_endpoint.h"\r
47 \r
48 \r
49 /*\r
50  * Define to place receive buffer inline in receive descriptor.\r
51  */\r
52 #define IPOIB_INLINE_RECV       1\r
53 \r
54 /* \r
55  *  Invalid pkey index\r
56  */\r
57 #define PKEY_INVALID_INDEX      0xFFFF\r
58 \r
59 /*\r
60  * Define to control how transfers are done.  When defined as 1, causes\r
61  * packets to be sent using NDIS DMA facilities (getting the SGL from the\r
62  * packet).  When defined as 0, uses the NDIS_BUFFER structures as MDLs\r
63  * to get the physical page mappings of the buffers.\r
64  */\r
65 #define IPOIB_USE_DMA   1\r
66 \r
67 //Used in RECV flow\r
68 #define IPOIB_PORT_FROM_NBL( P )        \\r
69         (((ipoib_port_t**)NET_BUFFER_LIST_MINIPORT_RESERVED(P))[1])\r
70 \r
71 //Used in RECV flow\r
72 #define IPOIB_RECV_FROM_NBL( P )        \\r
73         (((ipoib_recv_desc_t**)NET_BUFFER_LIST_MINIPORT_RESERVED(P))[0])\r
74         \r
75 //Used in CM SEND flow - to update\r
76 #define IPOIB_LIST_ITEM_FROM_NBL( P ) \\r
77         ((cl_list_item_t*)NET_BUFFER_LIST_MINIPORT_RESERVED(P))\r
78 \r
79 //Used in SEND flow\r
80 #define IPOIB_INFO_FROM_NB( P ) \\r
81         (((ipoib_send_NB_SG **)NET_BUFFER_MINIPORT_RESERVED(P))[0])\r
82 \r
83 //Used in SEND flow\r
84 #define IPOIB_GET_NET_BUFFER_LIST_REF_COUNT(_NetBufferList)     ((_NetBufferList)->MiniportReserved[0])\r
85 #define IPOIB_DEC_NET_BUFFER_LIST_REF_COUNT(_NetBufferList)     (*(PULONG)&(_NetBufferList)->MiniportReserved[0])--\r
86 \r
87 \r
88 \r
89 typedef struct _ipoib_ib_mgr\r
90 {\r
91         ib_ca_handle_t                  h_ca;\r
92         ib_pd_handle_t                  h_pd;\r
93         ib_cq_handle_t                  h_recv_cq;\r
94         ib_cq_handle_t                  h_send_cq;\r
95         ib_qp_handle_t                  h_qp;\r
96         ib_query_handle_t               h_query;\r
97         ib_srq_handle_t                 h_srq;\r
98         net32_t                                 qpn;\r
99 \r
100         ib_mr_handle_t                  h_mr;\r
101         net32_t                                 lkey;\r
102 \r
103         uint8_t                                 rate;\r
104         ib_member_rec_t                 bcast_rec;\r
105 \r
106 }       ipoib_ib_mgr_t;\r
107 /*\r
108 * FIELDS\r
109 *       h_ca\r
110 *               CA handle for all IB resources.\r
111 *\r
112 *       h_pd\r
113 *               PD handle for all IB resources.\r
114 *\r
115 *       h_recv_cq\r
116 *               Recv CQ handle.\r
117 *\r
118 *       h_send_cq\r
119 *               Send CQ handle.\r
120 *\r
121 *       h_qp\r
122 *               QP handle for data transfers.\r
123 *\r
124 *       h_query\r
125 *               Query handle for cancelling SA queries.\r
126 *\r
127 *       h_mr\r
128 *               Registration handle for all of physical memory.  Used for\r
129 *               send/receive buffers to simplify growing the receive pool.\r
130 *\r
131 *       lkey\r
132 *               LKey for the memory region.\r
133 *\r
134 *       bcast_rec\r
135 *               Cached information about the broadcast group, used to specify\r
136 *               parameters used to join other multicast groups.\r
137 *********/\r
138 \r
139 \r
140 #include <complib/cl_packon.h>\r
141 /****s* IPoIB Driver/ipoib_hdr_t\r
142 * NAME\r
143 *       ipoib_hdr_t\r
144 *\r
145 * DESCRIPTION\r
146 *       IPoIB packet header.\r
147 *\r
148 * SYNOPSIS\r
149 */\r
150 typedef struct _ipoib_hdr\r
151 {\r
152         net16_t                 type;\r
153         net16_t                 resv;\r
154 \r
155 }       PACK_SUFFIX ipoib_hdr_t;\r
156 /*\r
157 * FIELDS\r
158 *       type\r
159 *               Protocol type.\r
160 *\r
161 *       resv\r
162 *               Reserved portion of IPoIB header.\r
163 *********/\r
164 \r
165 typedef struct _ipoib_arp_pkt\r
166 {\r
167         net16_t                 hw_type;\r
168         net16_t                 prot_type;\r
169         uint8_t                 hw_size;\r
170         uint8_t                 prot_size;\r
171         net16_t                 op;\r
172         ipoib_hw_addr_t src_hw;\r
173         net32_t                 src_ip;\r
174         ipoib_hw_addr_t dst_hw;\r
175         net32_t                 dst_ip;\r
176 \r
177 }       PACK_SUFFIX ipoib_arp_pkt_t;\r
178 \r
179 \r
180 /****s* IPoIB Driver/ipoib_pkt_t\r
181 * NAME\r
182 *       ipoib_pkt_t\r
183 *\r
184 * DESCRIPTION\r
185 *       Represents an IPoIB packet with no GRH.\r
186 *\r
187 * SYNOPSIS\r
188 */\r
189 typedef struct _ipoib_pkt\r
190 {\r
191         ipoib_hdr_t             hdr;\r
192         union _payload\r
193         {\r
194                 uint8_t                 data[MAX_UD_PAYLOAD_MTU];\r
195                 ipoib_arp_pkt_t arp;\r
196                 ip_pkt_t                ip;\r
197 \r
198         }       PACK_SUFFIX type;\r
199 \r
200 }       PACK_SUFFIX ipoib_pkt_t;\r
201 /*\r
202 * FIELDS\r
203 *       hdr\r
204 *               IPoIB header.\r
205 *\r
206 *       type\r
207 *               Union for different types of payloads.\r
208 *\r
209 *       type.data\r
210 *               raw packet.\r
211 *\r
212 *       type.ib_arp\r
213 *               IPoIB ARP packet.\r
214 *\r
215 *       type.arp\r
216 *               Ethernet ARP packet.\r
217 *\r
218 *       type.ip\r
219 *               IP packet.\r
220 *********/\r
221 \r
222 \r
223 /****s* IPoIB Driver/recv_buf_t\r
224 * NAME\r
225 *       recv_buf_t\r
226 *\r
227 * DESCRIPTION\r
228 *       Represents a receive buffer, including the ethernet header\r
229 *       used to indicate the receive to the OS.\r
230 *\r
231 * SYNOPSIS\r
232 */\r
233 typedef union _recv_buf\r
234 {\r
235         struct _recv_buf_type_eth\r
236         {\r
237                 uint8_t                 pad[sizeof(ib_grh_t) +\r
238                                                         sizeof(ipoib_hdr_t) -\r
239                                                         sizeof(eth_hdr_t)];\r
240                 eth_pkt_t               pkt;    /* data starts at sizeof(grh)+sizeof(eth_hdr) */\r
241 \r
242         }       PACK_SUFFIX eth;\r
243 \r
244         struct _recv_buf_type_ib\r
245         {\r
246                 ib_grh_t                grh;    /* Must be same offset as lcl_rt.ib.pkt */\r
247                 ipoib_pkt_t             pkt;    /* data starts at 10+grh+4 */\r
248 \r
249         }       PACK_SUFFIX ib;\r
250 \r
251 }       PACK_SUFFIX recv_buf_t;\r
252 /*\r
253 * FIELDS\r
254 *       eth.pkt\r
255 *               Ethernet packet, used to indicate the receive to the OS.\r
256 *\r
257 *       ib.grh\r
258 *               GRH for a globally routed received packet.\r
259 *\r
260 *       ib.pkt\r
261 *               IPOIB packet representing a globally routed received packet.\r
262 *\r
263 * NOTES\r
264 *       When posting the work request, the address of ib.grh is used.\r
265 *\r
266 *       TODO: Do we need a pad to offset the header so that the data ends up\r
267 *       aligned on a pointer boundary?\r
268 *********/\r
269 \r
270 /****s* IPoIB Driver/send_buf_t\r
271 * NAME\r
272 *       send_buf_t\r
273 *\r
274 * DESCRIPTION\r
275 *       Represents a send buffer, used to convert packets to IPoIB format.\r
276 *\r
277 * SYNOPSIS\r
278 */\r
279 typedef union _send_buf\r
280 {\r
281         uint8_t                 data[MAX_UD_PAYLOAD_MTU];\r
282         ipoib_arp_pkt_t arp;\r
283         ip_pkt_t                ip;\r
284 \r
285 }       PACK_SUFFIX send_buf_t;\r
286 /*\r
287 * FIELDS\r
288 *       data\r
289 *               IP/ARP packet.\r
290 *\r
291 * NOTES\r
292 *       TODO: Do we need a pad to offset the header so that the data ends up\r
293 *       aligned on a pointer boundary?\r
294 *********/\r
295 #include <complib/cl_packoff.h>\r
296 \r
297 \r
298 typedef struct _ipoib_buf_mgr\r
299 {\r
300         cl_qpool_t                      recv_pool;\r
301 \r
302         NDIS_HANDLE                     h_packet_pool;\r
303         NDIS_HANDLE                     h_buffer_pool;\r
304 \r
305         NPAGED_LOOKASIDE_LIST   send_buf_list;\r
306         NDIS_HANDLE                     h_send_pkt_pool;\r
307         NDIS_HANDLE                     h_send_buf_pool;\r
308 \r
309 }       ipoib_buf_mgr_t;\r
310 /*\r
311 * FIELDS\r
312 *       recv_pool\r
313 *               Pool of ipoib_recv_desc_t structures.\r
314 *\r
315 *       h_packet_pool\r
316 *               NDIS packet pool, used to indicate receives to NDIS.\r
317 *\r
318 *       h_buffer_pool\r
319 *               NDIS buffer pool, used to indicate receives to NDIS.\r
320 *\r
321 *       send_buf_list\r
322 *               Lookaside list for dynamically allocating send buffers for send\r
323 *               that require copies (ARP, DHCP, and any with more physical pages\r
324 *               than can fit in the local data segments).\r
325 *********/\r
326 \r
327 \r
328 typedef enum _ipoib_pkt_type\r
329 {\r
330         PKT_TYPE_UCAST,\r
331         PKT_TYPE_BCAST,\r
332         PKT_TYPE_MCAST,\r
333         PKT_TYPE_CM_UCAST\r
334 \r
335 }       ipoib_pkt_type_t;\r
336 \r
337 typedef struct _ipoib_cm_desc\r
338 {\r
339         cl_pool_item_t                          item;   /* Must be first. */\r
340         uint32_t                                        len;\r
341         ipoib_pkt_type_t                        type;\r
342         ib_recv_wr_t                            wr;\r
343         ib_local_ds_t                           local_ds[2];\r
344         cl_list_item_t                          list_item;\r
345         uint8_t*                                        p_alloc_buf;\r
346         uint8_t*                                        p_buf;\r
347         uint32_t                                        alloc_buf_size;\r
348         uint32_t                                        buf_size;\r
349         net32_t                                         lkey;\r
350         ib_mr_handle_t                          h_mr;\r
351         NDIS_TCP_IP_CHECKSUM_PACKET_INFO        ndis_csum;\r
352 \r
353 }       ipoib_cm_desc_t;\r
354 \r
355 typedef struct _ipoib_recv_desc\r
356 {\r
357         cl_pool_item_t          item;   /* Must be first. */\r
358         uint32_t                        len;\r
359         ipoib_pkt_type_t        type;\r
360         ib_recv_wr_t            wr;\r
361         ib_local_ds_t           local_ds[2];\r
362         NDIS_TCP_IP_CHECKSUM_PACKET_INFO        ndis_csum;\r
363 #if IPOIB_INLINE_RECV\r
364         recv_buf_t                      buf;\r
365 #else\r
366         recv_buf_t                      *p_buf;\r
367 #endif\r
368 \r
369 }       ipoib_recv_desc_t;\r
370 /*\r
371 * FIELDS\r
372 *       item\r
373 *               Pool item for storing descriptors in a pool.\r
374 *\r
375 *       len\r
376 *               Length to indicate to NDIS.  This is different than the length of the\r
377 *               received data as some data is IPoIB specific and filtered out.\r
378 *\r
379 *       type\r
380 *               Type of packet, used in filtering received packets against the packet\r
381 *               filter.  Also used to update stats.\r
382 *\r
383 *       wr\r
384 *               Receive work request.\r
385 *\r
386 *       local_ds\r
387 *               Local data segments.  The second segment is only used if a buffer\r
388 *               spans physical pages.\r
389 *\r
390 *       buf\r
391 *               Buffer for the receive.\r
392 *\r
393 * NOTES\r
394 *       The pool item is always first to allow casting form a cl_pool_item_t or\r
395 *       cl_list_item_t to the descriptor.\r
396 *********/\r
397 typedef struct __ipoib_send_wr\r
398 {\r
399         ib_send_wr_t            wr;\r
400         ib_local_ds_t           local_ds[MAX_SEND_SGE]; /* Must be last. */\r
401 } ipoib_send_wr_t;\r
402 \r
403 typedef enum __send_dir\r
404 {\r
405         SEND_UD_QP = 1,\r
406         SEND_RC_QP = 2\r
407 } send_dir_t;\r
408 \r
409 typedef struct _ipoib_send_desc\r
410 {\r
411         PNET_BUFFER_LIST    p_netbuf_list;\r
412         ipoib_endpt_t           *p_endpt;\r
413         send_buf_t                      *p_buf;\r
414         ib_qp_handle_t          send_qp;\r
415         send_dir_t                      send_dir;\r
416         uint32_t                        num_wrs;\r
417         ipoib_send_wr_t         send_wr[MAX_WRS_PER_MSG];\r
418 \r
419 }       ipoib_send_desc_t;\r
420 /*\r
421 * FIELDS\r
422 *       p_pkt\r
423 *               Pointer to the NDIS_PACKET associated with the send operation.\r
424 *\r
425 *       p_endpt\r
426 *               Endpoint for this send.\r
427 *\r
428 *       p_buf\r
429 *               Buffer for the send, if allocated.\r
430 *\r
431 *       wr\r
432 *               Send work request.\r
433 *\r
434 *       pkt_hdr\r
435 *               IPoIB packet header, pointed to by the first local datasegment.\r
436 *\r
437 *       local_ds\r
438 *               Local data segment array.  Placed last to allow allocating beyond the\r
439 *               end of the descriptor for additional datasegments.\r
440 *\r
441 * NOTES\r
442 *       The pool item is always first to allow casting form a cl_pool_item_t or\r
443 *       cl_list_item_t to the descriptor.\r
444 *********/\r
445 \r
446 \r
447 typedef struct _ipoib_recv_mgr\r
448 {\r
449         int32_t                 depth;\r
450 \r
451         NET_BUFFER_LIST         **recv_NBL_array;\r
452 \r
453         cl_qlist_t              done_list;\r
454 \r
455 }       ipoib_recv_mgr_t;\r
456 /*\r
457 * FIELDS\r
458 *       depth\r
459 *               Current number of WRs posted.\r
460 *\r
461 *       p_head\r
462 *               Pointer to work completion in descriptor at the head of the QP.\r
463 *\r
464 *       p_tail\r
465 *               Pointer to the work completion in the descriptor at the tail of the QP.\r
466 *\r
467 *       recv_NBL_array\r
468 *               Array of pointers to NDIS_PACKET used to indicate receives.\r
469 *\r
470 *       done_list\r
471 *               List of receive descriptors that need to be indicated to NDIS.\r
472 *********/\r
473 #if 0\r
474 class ItemListElement: public cl_list_item_t {\r
475         public:\r
476                 ItemListElement() : p_port(NULL), p_nbl(NULL), p_curr_nbl(NULL) {};\r
477                 virtual ~ItemListElement() {};\r
478                 \r
479                 ipoib_port_t            *p_port;\r
480                 PNET_BUFFER_LIST        p_nbl;\r
481                 PNET_BUFFER                     p_curr_nb;\r
482 }\r
483 \r
484 class ItemList {\r
485         //friend PendingListElement;\r
486         public:\r
487         \r
488                 ItemList(ULONG size): _size(size), _cnt(0) {\r
489                         item_array = new ItemListItem(size);\r
490                         RtlSecureZeroMemory(item_array, sizeof (item_array));\r
491                 }\r
492                 \r
493                 virtual ~PendingList() { free(item_array); } ;\r
494                 \r
495                 ItemListElement * \r
496                 GetListElement() {\r
497                         if (_cnt == _size) {\r
498                                 cl_dbg_out("Out of memory!\n");\r
499                                 return NULL;\r
500                         }\r
501                         return item_array[cnt_++];\r
502                 }\r
503 \r
504                 void\r
505                 PutListElement ( /*PendingListElement * list_elem*/) {\r
506                         //ASSERT(list_elem.p_list == list\r
507                         RtlSecureZeroMemory(&list_elem[_cnt], sizeof (ItemListElement));\r
508                         ASSERT(_cnt > 0);\r
509                         --_cnt;\r
510                         \r
511                 }\r
512 \r
513 \r
514         private:\r
515                 ULONG                           _size;\r
516                 ULONG                           _cnt;\r
517                 ItemListItem            *item_array;\r
518 }\r
519         \r
520 \r
521 static const ULONG ItemListPoolSize(500);\r
522 #endif\r
523 \r
524 \r
525 \r
526 \r
527 typedef struct _ipoib_send_mgr\r
528 {\r
529         atomic32_t                      depth;\r
530         cl_qlist_t                      pending_list;\r
531         ipoib_send_desc_t       desc;\r
532         cl_qpool_t                      send_pool;\r
533 \r
534 }       ipoib_send_mgr_t;\r
535 \r
536 \r
537 \r
538 /*\r
539 * FIELDS\r
540 *       depth\r
541 *               Current number of WRs posted, used to queue pending requests.\r
542 *\r
543 *       pending_list\r
544 *               List of NDIS_PACKET structures that are awaiting available WRs to send.\r
545 *********/\r
546 \r
547 \r
548 typedef struct _ipoib_endpt_mgr\r
549 {\r
550         cl_qmap_t                               mac_endpts;\r
551         cl_fmap_t                               gid_endpts;\r
552         cl_qmap_t                               lid_endpts;\r
553         cl_fmap_t                               conn_endpts;\r
554         LIST_ENTRY                      pending_conns;\r
555         LIST_ENTRY                              remove_conns;\r
556         NDIS_SPIN_LOCK                  conn_lock;\r
557         NDIS_SPIN_LOCK                  remove_lock;\r
558         cl_thread_t                             h_thread;\r
559         cl_event_t                              event;\r
560         uint32_t                                thread_is_done;\r
561 }       ipoib_endpt_mgr_t;\r
562 /*\r
563 * FIELDS\r
564 *       mac_endpts\r
565 *               Map of enpoints, keyed by MAC address.\r
566 *\r
567 *       gid_endpts\r
568 *               Map of enpoints, keyed by GID.\r
569 *\r
570 *       lid_endpts\r
571 *               Map of enpoints, keyed by LID.  Only enpoints on the same subnet\r
572 *               are inserted in the LID map.\r
573 *\r
574 *       conn_endpts\r
575 *               Map of connected endpts, keyed by remote gid.\r
576 *********/\r
577 \r
578 #pragma warning(disable:4324)   // structure padded due to align()\r
579 typedef struct _ipoib_port\r
580 {\r
581         cl_obj_t                                obj;\r
582         cl_obj_rel_t                    rel;\r
583 \r
584         ib_qp_state_t                   state;\r
585 \r
586         cl_spinlock_t                   recv_lock;\r
587         cl_spinlock_t                   send_lock;\r
588 \r
589         struct _ipoib_adapter   *p_adapter;\r
590         uint8_t                                 port_num;\r
591 \r
592         KEVENT                                  sa_event;\r
593 \r
594         atomic32_t                              mcast_cnt;\r
595         KEVENT                                  leave_mcast_event;\r
596         \r
597         ipoib_ib_mgr_t                  ib_mgr;\r
598 \r
599         ipoib_buf_mgr_t                 buf_mgr;\r
600 \r
601         ipoib_recv_mgr_t                recv_mgr;\r
602         ipoib_send_mgr_t                send_mgr;\r
603         ipoib_send_desc_t *             p_desc;\r
604 \r
605         KDPC                                    recv_dpc;\r
606 \r
607         ipoib_endpt_mgr_t               endpt_mgr;\r
608 \r
609         endpt_buf_mgr_t                 cm_buf_mgr;\r
610         endpt_recv_mgr_t                cm_recv_mgr;\r
611 \r
612         ipoib_endpt_t                   *p_local_endpt;\r
613         ib_ca_attr_t                    *p_ca_attrs;\r
614 #if DBG\r
615         atomic32_t                              ref[ref_array_size];\r
616 #endif\r
617 \r
618         atomic32_t                              endpt_rdr;\r
619 \r
620         atomic32_t                              hdr_idx;\r
621         uint16_t                                pkey_index;\r
622         KDPC                                    gc_dpc;\r
623         KTIMER                                  gc_timer;\r
624         uint32_t                                bc_join_retry_cnt;\r
625         ib_net16_t                              base_lid;\r
626         ipoib_hdr_t                             hdr[1]; /* Must be last! */\r
627 \r
628 }       ipoib_port_t;\r
629 #pragma warning(default:4324)\r
630 \r
631 /*\r
632 * FIELDS\r
633 *       obj\r
634 *               Complib object for reference counting, relationships,\r
635 *               and destruction synchronization.\r
636 *\r
637 *       rel\r
638 *               Relationship to associate the port with the adapter.\r
639 *\r
640 *       state\r
641 *               State of the port object.  Tracks QP state fairly closely.\r
642 *\r
643 *       recv_lock\r
644 *               Spinlock to protect receive operations.\r
645 *\r
646 *       send_lock\r
647 *               Spinlock to protect send operations.\r
648 *\r
649 *       p_adapter\r
650 *               Parent adapter.  Used to get AL handle.\r
651 *\r
652 *       port_num\r
653 *               Port number of this adapter.\r
654 *\r
655 *       ib_mgr\r
656 *               IB resource manager.\r
657 *\r
658 *       recv_mgr\r
659 *               Receive manager.\r
660 *\r
661 *       send_mgr\r
662 *               Send manager.\r
663 *\r
664 *       endpt_mgr\r
665 *               Endpoint manager.\r
666 *********/\r
667 typedef struct _sgl_context\r
668 {\r
669         MDL                                     *p_mdl;\r
670         NET_BUFFER_LIST         *p_netbuffer_list;\r
671         ipoib_port_t            *p_port;\r
672 }sgl_context_t;\r
673 \r
674 #if 0\r
675 \r
676 class ipoib_send_NB_SG: public cl_pool_item_t{\r
677 public:\r
678         \r
679         ipoib_send_NB_SG(): p_port(NULL), p_nbl (NULL), p_curr_nb(NULL), p_endpt(NULL), p_send_buf(NULL), p_sgl(NULL) {};\r
680         virtual ~ipoib_send_NB_SG();\r
681 #endif\r
682 typedef struct ipoib_send_NB_SG_t {\r
683 //private: //TODO make data private\r
684         cl_pool_item_t                  pool_item;\r
685         ipoib_port_t                    *p_port;\r
686         PNET_BUFFER_LIST                p_nbl;\r
687         PNET_BUFFER                             p_curr_nb;\r
688         ipoib_endpt_t                   *p_endpt;\r
689         send_buf_t                              *p_send_buf;\r
690         PSCATTER_GATHER_LIST    p_sgl;\r
691 } ipoib_send_NB_SG;\r
692 \r
693 ib_api_status_t\r
694 ipoib_create_port(\r
695         IN                              struct _ipoib_adapter* const    p_adapter,\r
696         IN                              ib_pnp_port_rec_t* const        p_pnp_rec,\r
697                 OUT                     ipoib_port_t** const            pp_port );\r
698 \r
699 void\r
700 ipoib_port_destroy(\r
701         IN                              ipoib_port_t* const                     p_port );\r
702 \r
703 void\r
704 ipoib_port_up(\r
705         IN                              ipoib_port_t* const                     p_port,\r
706         IN              const   ib_pnp_port_rec_t* const        p_pnp_rec );\r
707 \r
708 void\r
709 ipoib_port_down(\r
710         IN                              ipoib_port_t* const                     p_port );\r
711 \r
712 ib_api_status_t\r
713 ipoib_port_join_mcast(\r
714         IN                              ipoib_port_t* const                     p_port,\r
715         IN              const   mac_addr_t                              mac,\r
716         IN              const   uint8_t                                 state );\r
717 \r
718 \r
719 void\r
720 ipoib_leave_mcast_cb(\r
721         IN                              void                            *context );\r
722 \r
723 \r
724 void\r
725 ipoib_port_remove_endpt(\r
726         IN                              ipoib_port_t* const                     p_port,\r
727         IN              const   mac_addr_t                                      mac );\r
728 \r
729 void\r
730 ipoib_port_send(\r
731         IN                              ipoib_port_t* const                     p_port,\r
732         IN                              NET_BUFFER_LIST                         *net_buffer_list,\r
733         IN                              ULONG                                           send_flags );\r
734 \r
735 void\r
736 ipoib_return_net_buffer_list(\r
737         IN                              NDIS_HANDLE                                     adapter_context,\r
738         IN                              PNET_BUFFER_LIST                        p_netbuffer_lists,\r
739         IN                              ULONG                                           return_flags);\r
740 \r
741 void\r
742 ipoib_port_resume(\r
743         IN                              ipoib_port_t* const                     p_port,\r
744         IN boolean_t                                                            b_pending );\r
745 \r
746 NTSTATUS\r
747 ipoib_mac_to_gid(\r
748         IN                              ipoib_port_t* const                     p_port,\r
749         IN              const   mac_addr_t                                      mac,\r
750                 OUT                     ib_gid_t*                                       p_gid );\r
751 \r
752 NTSTATUS\r
753 ipoib_mac_to_path(\r
754         IN                              ipoib_port_t* const                     p_port,\r
755         IN              const   mac_addr_t                                      mac,\r
756                 OUT                     ib_path_rec_t*                          p_path );\r
757 \r
758 void \r
759 ipoib_process_sg_list(\r
760     IN  PDEVICE_OBJECT          pDO,\r
761     IN  PVOID                   pIrp,\r
762     IN  PSCATTER_GATHER_LIST    pSGList,\r
763     IN  PVOID                   Context);\r
764     \r
765 inline void ipoib_port_ref(\r
766         IN                              ipoib_port_t *                          p_port, \r
767         IN                              int                                             type);\r
768 \r
769 inline void ipoib_port_deref(\r
770         IN                              ipoib_port_t *                          p_port,\r
771         IN                              int                                             type);\r
772 \r
773 #if 0\r
774 // This function is only used to monitor send failures\r
775 static inline VOID NdisMSendCompleteX(\r
776         IN NDIS_HANDLE  MiniportAdapterHandle,\r
777         IN PNDIS_PACKET  Packet,\r
778         IN NDIS_STATUS  Status\r
779         ) {\r
780         if (Status != NDIS_STATUS_SUCCESS) {\r
781                 IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
782                         ("Sending status other than Success to NDIS\n"));\r
783         }\r
784         NdisMSendComplete(MiniportAdapterHandle,Packet,Status);\r
785 }\r
786 #else\r
787 //#define NdisMSendCompleteX NdisMSendComplete\r
788 #endif\r
789 \r
790 ipoib_endpt_t*\r
791 ipoib_endpt_get_by_gid(\r
792         IN                              ipoib_port_t* const                     p_port,\r
793         IN              const   ib_gid_t* const                         p_gid );\r
794 \r
795 ipoib_endpt_t*\r
796 ipoib_endpt_get_by_lid(\r
797         IN                              ipoib_port_t* const                     p_port,\r
798         IN              const   net16_t                                         lid );\r
799 \r
800 ib_api_status_t\r
801 ipoib_port_srq_init(\r
802         IN              ipoib_port_t* const             p_port );\r
803 \r
804 void\r
805 ipoib_port_srq_destroy( \r
806         IN              ipoib_port_t* const             p_port );\r
807 \r
808 #if 0 //CM\r
809 ib_api_status_t\r
810 ipoib_port_listen(\r
811          IN             ipoib_port_t* const             p_port );\r
812 \r
813 ib_api_status_t\r
814 ipoib_port_cancel_listen(\r
815         IN              ipoib_port_t*   const   p_port,\r
816         IN              ipoib_endpt_t* const    p_endpt ) {\r
817         UNUSED_PARAM(p_port);\r
818         UNUSED_PARAM(p_endpt);\r
819         return IB_SUCCESS;\r
820 }\r
821 #endif \r
822 \r
823 ib_api_status_t\r
824 endpt_cm_buf_mgr_init(\r
825         IN              ipoib_port_t* const                     p_port );\r
826 \r
827 void\r
828 endpt_cm_buf_mgr_destroy(\r
829         IN              ipoib_port_t* const             p_port );\r
830 \r
831 void\r
832 endpt_cm_buf_mgr_reset(\r
833         IN              ipoib_port_t* const             p_port );\r
834 \r
835 void\r
836 endpt_cm_buf_mgr_put_recv(\r
837         IN              endpt_buf_mgr_t * const         p_buf_mgr,\r
838         IN              ipoib_cm_desc_t* const          p_desc );\r
839 \r
840 void\r
841 endpt_cm_buf_mgr_put_recv_list(\r
842         IN              endpt_buf_mgr_t * const         p_buf_mgr,\r
843         IN              cl_qlist_t* const                       p_list );\r
844 \r
845 uint32_t\r
846 endpt_cm_recv_mgr_build_pkt_array(\r
847         IN              ipoib_port_t* const                     p_port,\r
848         IN              ipoib_endpt_t* const            p_endpt,\r
849         IN              cl_qlist_t* const                       p_done_list,\r
850         IN OUT  uint32_t*                                       p_bytes_recv );\r
851 \r
852 ib_api_status_t\r
853 endpt_cm_post_recv(\r
854         IN              ipoib_port_t* const                     p_port );\r
855 \r
856 /*void\r
857 endpt_cm_destroy_conn(\r
858         IN              ipoib_port_t* const                     p_port,\r
859         IN              ipoib_endpt_t* const            p_endpt );\r
860 */\r
861 void\r
862 endpt_cm_disconnect(\r
863         IN              ipoib_port_t*   const           p_port,\r
864         IN              ipoib_endpt_t*  const           p_endpt );\r
865 void\r
866 endpt_cm_flush_recv(\r
867         IN                              ipoib_port_t* const             p_port,\r
868         IN                              ipoib_endpt_t* const    p_endpt );\r
869 \r
870 ib_api_status_t\r
871 ipoib_recv_dhcp(\r
872         IN                              ipoib_port_t* const                     p_port,\r
873         IN              const   ipoib_pkt_t* const                      p_ipoib,\r
874                 OUT                     eth_pkt_t* const                        p_eth,\r
875         IN                              ipoib_endpt_t* const            p_src,\r
876         IN                              ipoib_endpt_t* const            p_dst );\r
877 \r
878 void\r
879 ipoib_port_cancel_xmit(\r
880         IN                              ipoib_port_t* const             p_port,\r
881         IN                              PVOID                                    cancel_id );\r
882 \r
883 static inline uint32_t\r
884 __port_attr_to_mtu_size(uint32_t value)\r
885 {\r
886         switch (value) \r
887         {\r
888         default:\r
889         case IB_MTU_LEN_2048:\r
890                 return 2048;\r
891         case IB_MTU_LEN_4096:\r
892                 return 4096;\r
893         case IB_MTU_LEN_1024:\r
894                 return 1024;\r
895         case IB_MTU_LEN_512:\r
896                 return  512;\r
897         case IB_MTU_LEN_256:\r
898                 return  256;\r
899         }\r
900 }\r
901 #endif  /* _IPOIB_PORT_H_ */\r