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