Whamcloud - gitweb
LU-56 lnet: match-table for Portals
[fs/lustre-release.git] / lnet / include / lnet / lib-lnet.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  *
34  * lnet/include/lnet/lib-lnet.h
35  *
36  * Top level include for library side routines
37  */
38
39 #ifndef __LNET_LIB_LNET_H__
40 #define __LNET_LIB_LNET_H__
41
42 #if defined(__linux__)
43 #include <lnet/linux/lib-lnet.h>
44 #elif defined(__APPLE__)
45 #include <lnet/darwin/lib-lnet.h>
46 #elif defined(__WINNT__)
47 #include <lnet/winnt/lib-lnet.h>
48 #else
49 #error Unsupported Operating System
50 #endif
51
52 #include <libcfs/libcfs.h>
53 #include <lnet/types.h>
54 #include <lnet/lnet.h>
55 #include <lnet/lib-types.h>
56
57 extern lnet_t  the_lnet;                        /* THE network */
58
59 static inline int lnet_is_wire_handle_none (lnet_handle_wire_t *wh)
60 {
61         return (wh->wh_interface_cookie == LNET_WIRE_HANDLE_COOKIE_NONE &&
62                 wh->wh_object_cookie == LNET_WIRE_HANDLE_COOKIE_NONE);
63 }
64
65 static inline int lnet_md_exhausted (lnet_libmd_t *md)
66 {
67         return (md->md_threshold == 0 ||
68                 ((md->md_options & LNET_MD_MAX_SIZE) != 0 &&
69                  md->md_offset + md->md_max_size > md->md_length));
70 }
71
72 static inline int lnet_md_unlinkable (lnet_libmd_t *md)
73 {
74         /* Should unlink md when its refcount is 0 and either:
75          *  - md has been flagged for deletion (by auto unlink or LNetM[DE]Unlink,
76          *    in the latter case md may not be exhausted).
77          *  - auto unlink is on and md is exhausted.
78          */
79         if (md->md_refcount != 0)
80                 return 0;
81
82         if ((md->md_flags & LNET_MD_FLAG_ZOMBIE) != 0)
83                 return 1;
84
85         return ((md->md_flags & LNET_MD_FLAG_AUTO_UNLINK) != 0 &&
86                 lnet_md_exhausted(md));
87 }
88
89 #ifdef __KERNEL__
90 #define LNET_LOCK()        cfs_spin_lock(&the_lnet.ln_lock)
91 #define LNET_UNLOCK()      cfs_spin_unlock(&the_lnet.ln_lock)
92 #define LNET_MUTEX_LOCK(m)   cfs_mutex_lock(m)
93 #define LNET_MUTEX_UNLOCK(m) cfs_mutex_unlock(m)
94 #else
95 # ifndef HAVE_LIBPTHREAD
96 #define LNET_SINGLE_THREADED_LOCK(l)            \
97 do {                                            \
98         LASSERT ((l) == 0);                     \
99         (l) = 1;                                \
100 } while (0)
101
102 #define LNET_SINGLE_THREADED_UNLOCK(l)          \
103 do {                                            \
104         LASSERT ((l) == 1);                     \
105         (l) = 0;                                \
106 } while (0)
107
108 #define LNET_LOCK()        LNET_SINGLE_THREADED_LOCK(the_lnet.ln_lock)
109 #define LNET_UNLOCK()      LNET_SINGLE_THREADED_UNLOCK(the_lnet.ln_lock)
110 #define LNET_MUTEX_LOCK(m)     LNET_SINGLE_THREADED_LOCK(*(m))
111 #define LNET_MUTEX_UNLOCK(m)   LNET_SINGLE_THREADED_UNLOCK(*(m))
112 # else
113 #define LNET_LOCK()        pthread_mutex_lock(&the_lnet.ln_lock)
114 #define LNET_UNLOCK()      pthread_mutex_unlock(&the_lnet.ln_lock)
115 #define LNET_MUTEX_LOCK(m)     pthread_mutex_lock(m)
116 #define LNET_MUTEX_UNLOCK(m)   pthread_mutex_unlock(m)
117 # endif
118 #endif
119
120 #define MAX_PORTALS     64
121
122 /* these are only used by code with LNET_USE_LIB_FREELIST, but we still
123  * exported them to !LNET_USE_LIB_FREELIST for easy implemetation */
124 #define LNET_FL_MAX_MES         2048
125 #define LNET_FL_MAX_MDS         2048
126 #define LNET_FL_MAX_EQS         512
127 #define LNET_FL_MAX_MSGS        2048    /* Outstanding messages */
128
129 #ifdef LNET_USE_LIB_FREELIST
130
131 int lnet_freelist_init(lnet_freelist_t *fl, int n, int size);
132 void lnet_freelist_fini(lnet_freelist_t *fl);
133
134 static inline void *
135 lnet_freelist_alloc (lnet_freelist_t *fl)
136 {
137         /* ALWAYS called with liblock held */
138         lnet_freeobj_t *o;
139
140         if (cfs_list_empty (&fl->fl_list))
141                 return (NULL);
142
143         o = cfs_list_entry (fl->fl_list.next, lnet_freeobj_t, fo_list);
144         cfs_list_del (&o->fo_list);
145         return ((void *)&o->fo_contents);
146 }
147
148 static inline void
149 lnet_freelist_free (lnet_freelist_t *fl, void *obj)
150 {
151         /* ALWAYS called with liblock held */
152         lnet_freeobj_t *o = cfs_list_entry (obj, lnet_freeobj_t, fo_contents);
153
154         cfs_list_add (&o->fo_list, &fl->fl_list);
155 }
156
157
158 static inline lnet_eq_t *
159 lnet_eq_alloc (void)
160 {
161         /* NEVER called with resource lock held */
162         struct lnet_res_container *rec = &the_lnet.ln_eq_container;
163         lnet_eq_t                 *eq;
164
165         LNET_LOCK();
166         eq = (lnet_eq_t *)lnet_freelist_alloc(&rec->rec_freelist);
167         LNET_UNLOCK();
168
169         return eq;
170 }
171
172 static inline void
173 lnet_eq_free_locked(lnet_eq_t *eq)
174 {
175         /* ALWAYS called with resource lock held */
176         struct lnet_res_container *rec = &the_lnet.ln_eq_container;
177
178         lnet_freelist_free(&rec->rec_freelist, eq);
179 }
180
181 static inline void
182 lnet_eq_free(lnet_eq_t *eq)
183 {
184         LNET_LOCK();
185         lnet_eq_free_locked(eq);
186         LNET_UNLOCK();
187 }
188
189 static inline lnet_libmd_t *
190 lnet_md_alloc (lnet_md_t *umd)
191 {
192         /* NEVER called with resource lock held */
193         struct lnet_res_container *rec = &the_lnet.ln_md_container;
194         lnet_libmd_t              *md;
195
196         LNET_LOCK();
197         md = (lnet_libmd_t *)lnet_freelist_alloc(&rec->rec_freelist);
198         LNET_UNLOCK();
199
200         if (md != NULL)
201                 CFS_INIT_LIST_HEAD(&md->md_list);
202
203         return md;
204 }
205
206 static inline void
207 lnet_md_free_locked(lnet_libmd_t *md)
208 {
209         /* ALWAYS called with resource lock held */
210         struct lnet_res_container *rec = &the_lnet.ln_md_container;
211
212         lnet_freelist_free(&rec->rec_freelist, md);
213 }
214
215 static inline void
216 lnet_md_free(lnet_libmd_t *md)
217 {
218         LNET_LOCK();
219         lnet_md_free_locked(md);
220         LNET_UNLOCK();
221 }
222
223 static inline lnet_me_t *
224 lnet_me_alloc(void)
225 {
226         /* NEVER called with resource lock held */
227         struct lnet_res_container *rec = &the_lnet.ln_me_container;
228         lnet_me_t                 *me;
229
230         LNET_LOCK();
231         me = (lnet_me_t *)lnet_freelist_alloc(&rec->rec_freelist);
232         LNET_UNLOCK();
233
234         return me;
235 }
236
237 static inline void
238 lnet_me_free_locked(lnet_me_t *me)
239 {
240         /* ALWAYS called with resource lock held */
241         struct lnet_res_container *rec = &the_lnet.ln_me_container;
242
243         lnet_freelist_free(&rec->rec_freelist, me);
244 }
245
246 static inline void
247 lnet_me_free(lnet_me_t *me)
248 {
249         LNET_LOCK();
250         lnet_me_free_locked(me);
251         LNET_UNLOCK();
252 }
253
254 static inline lnet_msg_t *
255 lnet_msg_alloc (void)
256 {
257         /* NEVER called with network lock held */
258         struct lnet_msg_container *msc = &the_lnet.ln_msg_container;
259         lnet_msg_t                *msg;
260
261         LNET_LOCK();
262         msg = (lnet_msg_t *)lnet_freelist_alloc(&msc->msc_freelist);
263         LNET_UNLOCK();
264
265         if (msg != NULL) {
266                 /* NULL pointers, clear flags etc */
267                 memset(msg, 0, sizeof(*msg));
268 #ifdef CRAY_XT3
269                 msg->msg_ev.uid = LNET_UID_ANY;
270 #endif
271         }
272         return msg;
273 }
274
275 static inline void
276 lnet_msg_free_locked(lnet_msg_t *msg)
277 {
278         /* ALWAYS called with network lock held */
279         struct lnet_msg_container *msc = &the_lnet.ln_msg_container;
280
281         LASSERT(!msg->msg_onactivelist);
282         lnet_freelist_free(&msc->msc_freelist, msg);
283 }
284
285 static inline void
286 lnet_msg_free (lnet_msg_t *msg)
287 {
288         LNET_LOCK();
289         lnet_msg_free_locked(msg);
290         LNET_UNLOCK();
291 }
292
293 #else /* !LNET_USE_LIB_FREELIST */
294
295 static inline lnet_eq_t *
296 lnet_eq_alloc (void)
297 {
298         /* NEVER called with liblock held */
299         lnet_eq_t *eq;
300
301         LIBCFS_ALLOC(eq, sizeof(*eq));
302         return (eq);
303 }
304
305 static inline void
306 lnet_eq_free(lnet_eq_t *eq)
307 {
308         /* ALWAYS called with resource lock held */
309         LIBCFS_FREE(eq, sizeof(*eq));
310 }
311
312 static inline lnet_libmd_t *
313 lnet_md_alloc (lnet_md_t *umd)
314 {
315         /* NEVER called with liblock held */
316         lnet_libmd_t *md;
317         unsigned int  size;
318         unsigned int  niov;
319
320         if ((umd->options & LNET_MD_KIOV) != 0) {
321                 niov = umd->length;
322                 size = offsetof(lnet_libmd_t, md_iov.kiov[niov]);
323         } else {
324                 niov = ((umd->options & LNET_MD_IOVEC) != 0) ?
325                        umd->length : 1;
326                 size = offsetof(lnet_libmd_t, md_iov.iov[niov]);
327         }
328
329         LIBCFS_ALLOC(md, size);
330
331         if (md != NULL) {
332                 /* Set here in case of early free */
333                 md->md_options = umd->options;
334                 md->md_niov = niov;
335                 CFS_INIT_LIST_HEAD(&md->md_list);
336         }
337
338         return (md);
339 }
340
341 static inline void
342 lnet_md_free(lnet_libmd_t *md)
343 {
344         /* ALWAYS called with resource lock held */
345         unsigned int  size;
346
347         if ((md->md_options & LNET_MD_KIOV) != 0)
348                 size = offsetof(lnet_libmd_t, md_iov.kiov[md->md_niov]);
349         else
350                 size = offsetof(lnet_libmd_t, md_iov.iov[md->md_niov]);
351
352         LIBCFS_FREE(md, size);
353 }
354
355 static inline lnet_me_t *
356 lnet_me_alloc (void)
357 {
358         /* NEVER called with liblock held */
359         lnet_me_t *me;
360
361         LIBCFS_ALLOC(me, sizeof(*me));
362         return (me);
363 }
364
365 static inline void
366 lnet_me_free(lnet_me_t *me)
367 {
368         /* ALWAYS called with resource lock held */
369         LIBCFS_FREE(me, sizeof(*me));
370 }
371
372 static inline lnet_msg_t *
373 lnet_msg_alloc(void)
374 {
375         /* NEVER called with liblock held */
376         lnet_msg_t *msg;
377
378         LIBCFS_ALLOC(msg, sizeof(*msg));
379
380         /* no need to zero, LIBCFS_ALLOC does for us */
381
382 #ifdef CRAY_XT3
383         if (msg != NULL) {
384                 msg->msg_ev.uid = LNET_UID_ANY;
385         }
386 #endif
387         return (msg);
388 }
389
390 static inline void
391 lnet_msg_free(lnet_msg_t *msg)
392 {
393         /* ALWAYS called with network lock held */
394         LASSERT(!msg->msg_onactivelist);
395         LIBCFS_FREE(msg, sizeof(*msg));
396 }
397
398 #define lnet_eq_free_locked(eq)         lnet_eq_free(eq)
399 #define lnet_md_free_locked(md)         lnet_md_free(md)
400 #define lnet_me_free_locked(me)         lnet_me_free(me)
401 #define lnet_msg_free_locked(msg)       lnet_msg_free(msg)
402
403 #endif /* LNET_USE_LIB_FREELIST */
404
405 lnet_libhandle_t *lnet_res_lh_lookup(struct lnet_res_container *rec,
406                                      __u64 cookie);
407 void lnet_res_lh_initialize(struct lnet_res_container *rec,
408                             lnet_libhandle_t *lh);
409 static inline void
410 lnet_res_lh_invalidate(lnet_libhandle_t *lh)
411 {
412         /* ALWAYS called with resource lock held */
413         cfs_list_del(&lh->lh_hash_chain);
414 }
415
416 static inline void
417 lnet_eq2handle (lnet_handle_eq_t *handle, lnet_eq_t *eq)
418 {
419         if (eq == NULL) {
420                 LNetInvalidateHandle(handle);
421                 return;
422         }
423
424         handle->cookie = eq->eq_lh.lh_cookie;
425 }
426
427 static inline lnet_eq_t *
428 lnet_handle2eq(lnet_handle_eq_t *handle)
429 {
430         /* ALWAYS called with resource lock held */
431         lnet_libhandle_t *lh;
432
433         lh = lnet_res_lh_lookup(&the_lnet.ln_eq_container, handle->cookie);
434         if (lh == NULL)
435                 return NULL;
436
437         return lh_entry(lh, lnet_eq_t, eq_lh);
438 }
439
440 static inline void
441 lnet_md2handle (lnet_handle_md_t *handle, lnet_libmd_t *md)
442 {
443         handle->cookie = md->md_lh.lh_cookie;
444 }
445
446 static inline lnet_libmd_t *
447 lnet_handle2md(lnet_handle_md_t *handle)
448 {
449         /* ALWAYS called with resource lock held */
450         lnet_libhandle_t *lh;
451
452         lh = lnet_res_lh_lookup(&the_lnet.ln_md_container, handle->cookie);
453         if (lh == NULL)
454                 return NULL;
455
456         return lh_entry(lh, lnet_libmd_t, md_lh);
457 }
458
459 static inline lnet_libmd_t *
460 lnet_wire_handle2md(lnet_handle_wire_t *wh)
461 {
462         /* ALWAYS called with resource lock held */
463         lnet_libhandle_t *lh;
464
465         if (wh->wh_interface_cookie != the_lnet.ln_interface_cookie)
466                 return NULL;
467
468         lh = lnet_res_lh_lookup(&the_lnet.ln_md_container,
469                                 wh->wh_object_cookie);
470         if (lh == NULL)
471                 return NULL;
472
473         return lh_entry(lh, lnet_libmd_t, md_lh);
474 }
475
476 static inline void
477 lnet_me2handle (lnet_handle_me_t *handle, lnet_me_t *me)
478 {
479         handle->cookie = me->me_lh.lh_cookie;
480 }
481
482 static inline lnet_me_t *
483 lnet_handle2me(lnet_handle_me_t *handle)
484 {
485         /* ALWAYS called with resource lock held */
486         lnet_libhandle_t *lh;
487
488         lh = lnet_res_lh_lookup(&the_lnet.ln_me_container, handle->cookie);
489         if (lh == NULL)
490                 return NULL;
491
492         return lh_entry(lh, lnet_me_t, me_lh);
493 }
494
495 static inline void
496 lnet_peer_addref_locked(lnet_peer_t *lp)
497 {
498         LASSERT (lp->lp_refcount > 0);
499         lp->lp_refcount++;
500 }
501
502 extern void lnet_destroy_peer_locked(lnet_peer_t *lp);
503
504 static inline void
505 lnet_peer_decref_locked(lnet_peer_t *lp)
506 {
507         LASSERT (lp->lp_refcount > 0);
508         lp->lp_refcount--;
509         if (lp->lp_refcount == 0)
510                 lnet_destroy_peer_locked(lp);
511 }
512
513 static inline int
514 lnet_isrouter(lnet_peer_t *lp)
515 {
516         return lp->lp_rtr_refcount != 0;
517 }
518
519 static inline void
520 lnet_ni_addref_locked(lnet_ni_t *ni)
521 {
522         LASSERT (ni->ni_refcount > 0);
523         ni->ni_refcount++;
524 }
525
526 static inline void
527 lnet_ni_addref(lnet_ni_t *ni)
528 {
529         LNET_LOCK();
530         lnet_ni_addref_locked(ni);
531         LNET_UNLOCK();
532 }
533
534 static inline void
535 lnet_ni_decref_locked(lnet_ni_t *ni)
536 {
537         LASSERT (ni->ni_refcount > 0);
538         ni->ni_refcount--;
539         if (ni->ni_refcount == 0)
540                 cfs_list_add_tail(&ni->ni_list, &the_lnet.ln_zombie_nis);
541 }
542
543 static inline void
544 lnet_ni_decref(lnet_ni_t *ni)
545 {
546         LNET_LOCK();
547         lnet_ni_decref_locked(ni);
548         LNET_UNLOCK();
549 }
550
551 static inline int
552 lnet_nid2peerhash(lnet_nid_t nid)
553 {
554         return cfs_hash_long(nid, LNET_PEER_HASH_BITS);
555 }
556
557 extern lnd_t the_lolnd;
558
559 #ifndef __KERNEL__
560 /* unconditional registration */
561 #define LNET_REGISTER_ULND(lnd)                 \
562 do {                                            \
563         extern lnd_t lnd;                       \
564                                                 \
565         lnet_register_lnd(&(lnd));              \
566 } while (0)
567
568 /* conditional registration */
569 #define LNET_REGISTER_ULND_IF_PRESENT(lnd)                              \
570 do {                                                                    \
571         extern lnd_t lnd __attribute__ ((weak, alias("the_lolnd")));    \
572                                                                         \
573         if (&(lnd) != &the_lolnd)                                       \
574                 lnet_register_lnd(&(lnd));                              \
575 } while (0)
576 #endif
577
578 #ifdef CRAY_XT3
579 inline static void
580 lnet_set_msg_uid(lnet_ni_t *ni, lnet_msg_t *msg, lnet_uid_t uid)
581 {
582         LASSERT (msg->msg_ev.uid == LNET_UID_ANY);
583         msg->msg_ev.uid = uid;
584 }
585 #endif
586
587 extern lnet_ni_t *lnet_nid2ni_locked (lnet_nid_t nid);
588 extern lnet_ni_t *lnet_net2ni_locked (__u32 net);
589 static inline lnet_ni_t *
590 lnet_net2ni (__u32 net)
591 {
592         lnet_ni_t *ni;
593
594         LNET_LOCK();
595         ni = lnet_net2ni_locked(net);
596         LNET_UNLOCK();
597
598         return ni;
599 }
600
601 int lnet_notify(lnet_ni_t *ni, lnet_nid_t peer, int alive, cfs_time_t when);
602 void lnet_notify_locked(lnet_peer_t *lp, int notifylnd, int alive, cfs_time_t when);
603 int lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway_nid);
604 int lnet_check_routes(void);
605 int lnet_del_route(__u32 net, lnet_nid_t gw_nid);
606 void lnet_destroy_routes(void);
607 int lnet_get_route(int idx, __u32 *net, __u32 *hops,
608                    lnet_nid_t *gateway, __u32 *alive);
609 void lnet_proc_init(void);
610 void lnet_proc_fini(void);
611 void lnet_init_rtrpools(void);
612 int  lnet_alloc_rtrpools(int im_a_router);
613 void lnet_free_rtrpools(void);
614 lnet_remotenet_t *lnet_find_net_locked (__u32 net);
615
616 int lnet_islocalnid(lnet_nid_t nid);
617 int lnet_islocalnet(__u32 net);
618
619 void lnet_msg_attach_md(lnet_msg_t *msg, lnet_libmd_t *md,
620                         unsigned int offset, unsigned int mlen);
621 void lnet_msg_detach_md(lnet_msg_t *msg, int status);
622 void lnet_build_unlink_event(lnet_libmd_t *md, lnet_event_t *ev);
623 void lnet_build_msg_event(lnet_msg_t *msg, lnet_event_kind_t ev_type);
624 void lnet_msg_commit(lnet_msg_t *msg, int sending);
625 void lnet_msg_decommit(lnet_msg_t *msg, int status);
626
627 void lnet_eq_enqueue_event(lnet_eq_t *eq, lnet_event_t *ev);
628 void lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
629                     unsigned int offset, unsigned int len);
630 int lnet_send(lnet_nid_t nid, lnet_msg_t *msg);
631 void lnet_return_tx_credits_locked(lnet_msg_t *msg);
632 void lnet_return_rx_credits_locked(lnet_msg_t *msg);
633
634 /* portals functions */
635 /* portals attributes */
636 static inline int
637 lnet_ptl_is_lazy(lnet_portal_t *ptl)
638 {
639         return !!(ptl->ptl_options & LNET_PTL_LAZY);
640 }
641
642 static inline int
643 lnet_ptl_is_unique(lnet_portal_t *ptl)
644 {
645         return !!(ptl->ptl_options & LNET_PTL_MATCH_UNIQUE);
646 }
647
648 static inline int
649 lnet_ptl_is_wildcard(lnet_portal_t *ptl)
650 {
651         return !!(ptl->ptl_options & LNET_PTL_MATCH_WILDCARD);
652 }
653
654 static inline void
655 lnet_ptl_setopt(lnet_portal_t *ptl, int opt)
656 {
657         ptl->ptl_options |= opt;
658 }
659
660 static inline void
661 lnet_ptl_unsetopt(lnet_portal_t *ptl, int opt)
662 {
663         ptl->ptl_options &= ~opt;
664 }
665
666 /* match-table functions */
667 cfs_list_t *lnet_mt_match_head(struct lnet_match_table *mtable,
668                                lnet_process_id_t id, __u64 mbits);
669 struct lnet_match_table *lnet_mt_of_attach(unsigned int index,
670                                            lnet_process_id_t id, __u64 mbits,
671                                            __u64 ignore_bits,
672                                            lnet_ins_pos_t pos);
673 struct lnet_match_table *lnet_mt_of_match(unsigned int index,
674                                           lnet_process_id_t id, __u64 mbits);
675 int lnet_mt_match_md(struct lnet_match_table *mtable,
676                      int op_mask, lnet_process_id_t src,
677                      unsigned int rlength, unsigned int roffset,
678                      __u64 match_bits, lnet_msg_t *msg);
679
680 /* portals match/attach functions */
681 void lnet_ptl_attach_md(lnet_me_t *me, lnet_libmd_t *md,
682                         cfs_list_t *matches, cfs_list_t *drops);
683 void lnet_ptl_detach_md(lnet_me_t *me, lnet_libmd_t *md);
684 int lnet_ptl_match_md(unsigned int index, int op_mask, lnet_process_id_t src,
685                       unsigned int rlength, unsigned int roffset,
686                       __u64 match_bits, lnet_msg_t *msg);
687
688 /* initialized and finalize portals */
689 int lnet_portals_create(void);
690 void lnet_portals_destroy(void);
691
692 /* message functions */
693 int lnet_parse (lnet_ni_t *ni, lnet_hdr_t *hdr,
694                 lnet_nid_t fromnid, void *private, int rdma_req);
695 void lnet_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
696                unsigned int offset, unsigned int mlen, unsigned int rlen);
697 lnet_msg_t *lnet_create_reply_msg (lnet_ni_t *ni, lnet_msg_t *get_msg);
698 void lnet_set_reply_msg_len(lnet_ni_t *ni, lnet_msg_t *msg, unsigned int len);
699 void lnet_finalize(lnet_ni_t *ni, lnet_msg_t *msg, int rc);
700 void lnet_drop_delayed_msg_list(cfs_list_t *head, char *reason);
701 void lnet_recv_delayed_msg_list(cfs_list_t *head);
702
703 int lnet_msg_container_setup(struct lnet_msg_container *container);
704 void lnet_msg_container_cleanup(struct lnet_msg_container *container);
705
706 char *lnet_msgtyp2str (int type);
707 void lnet_print_hdr (lnet_hdr_t * hdr);
708 int lnet_fail_nid(lnet_nid_t nid, unsigned int threshold);
709
710 unsigned int lnet_iov_nob (unsigned int niov, struct iovec *iov);
711 int lnet_extract_iov (int dst_niov, struct iovec *dst,
712                       int src_niov, struct iovec *src,
713                       unsigned int offset, unsigned int len);
714
715 unsigned int lnet_kiov_nob (unsigned int niov, lnet_kiov_t *iov);
716 int lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
717                       int src_niov, lnet_kiov_t *src,
718                       unsigned int offset, unsigned int len);
719
720 void lnet_copy_iov2iov (unsigned int ndiov, struct iovec *diov,
721                         unsigned int doffset,
722                         unsigned int nsiov, struct iovec *siov,
723                         unsigned int soffset, unsigned int nob);
724 void lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov,
725                          unsigned int iovoffset,
726                          unsigned int nkiov, lnet_kiov_t *kiov,
727                          unsigned int kiovoffset, unsigned int nob);
728 void lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov,
729                          unsigned int kiovoffset,
730                          unsigned int niov, struct iovec *iov,
731                          unsigned int iovoffset, unsigned int nob);
732 void lnet_copy_kiov2kiov (unsigned int ndkiov, lnet_kiov_t *dkiov,
733                           unsigned int doffset,
734                           unsigned int nskiov, lnet_kiov_t *skiov,
735                           unsigned int soffset, unsigned int nob);
736
737 static inline void
738 lnet_copy_iov2flat(int dlen, void *dest, unsigned int doffset,
739                    unsigned int nsiov, struct iovec *siov, unsigned int soffset,
740                    unsigned int nob)
741 {
742         struct iovec diov = {/*.iov_base = */ dest, /*.iov_len = */ dlen};
743
744         lnet_copy_iov2iov(1, &diov, doffset,
745                           nsiov, siov, soffset, nob);
746 }
747
748 static inline void
749 lnet_copy_kiov2flat(int dlen, void *dest, unsigned int doffset,
750                     unsigned int nsiov, lnet_kiov_t *skiov, unsigned int soffset,
751                     unsigned int nob)
752 {
753         struct iovec diov = {/* .iov_base = */ dest, /* .iov_len = */ dlen};
754
755         lnet_copy_kiov2iov(1, &diov, doffset,
756                            nsiov, skiov, soffset, nob);
757 }
758
759 static inline void
760 lnet_copy_flat2iov(unsigned int ndiov, struct iovec *diov, unsigned int doffset,
761                    int slen, void *src, unsigned int soffset, unsigned int nob)
762 {
763         struct iovec siov = {/*.iov_base = */ src, /*.iov_len = */slen};
764         lnet_copy_iov2iov(ndiov, diov, doffset,
765                           1, &siov, soffset, nob);
766 }
767
768 static inline void
769 lnet_copy_flat2kiov(unsigned int ndiov, lnet_kiov_t *dkiov, unsigned int doffset,
770                     int slen, void *src, unsigned int soffset, unsigned int nob)
771 {
772         struct iovec siov = {/* .iov_base = */ src, /* .iov_len = */ slen};
773         lnet_copy_iov2kiov(ndiov, dkiov, doffset,
774                            1, &siov, soffset, nob);
775 }
776
777 void lnet_me_unlink(lnet_me_t *me);
778
779 void lnet_md_unlink(lnet_libmd_t *md);
780 void lnet_md_deconstruct(lnet_libmd_t *lmd, lnet_md_t *umd);
781
782 void lnet_register_lnd(lnd_t *lnd);
783 void lnet_unregister_lnd(lnd_t *lnd);
784 int lnet_set_ip_niaddr (lnet_ni_t *ni);
785
786 #ifdef __KERNEL__
787 int lnet_connect(cfs_socket_t **sockp, lnet_nid_t peer_nid,
788                  __u32 local_ip, __u32 peer_ip, int peer_port);
789 void lnet_connect_console_error(int rc, lnet_nid_t peer_nid,
790                                 __u32 peer_ip, int port);
791 int lnet_count_acceptor_nis(void);
792 int lnet_acceptor_timeout(void);
793 int lnet_acceptor_port(void);
794 #else
795 void lnet_router_checker(void);
796 #endif
797
798 #ifdef HAVE_LIBPTHREAD
799 int lnet_count_acceptor_nis(void);
800 int lnet_acceptor_port(void);
801 #endif
802
803 int lnet_acceptor_start(void);
804 void lnet_acceptor_stop(void);
805
806 void lnet_get_tunables(void);
807 int lnet_peers_start_down(void);
808 int lnet_peer_buffer_credits(lnet_ni_t *ni);
809
810 int lnet_router_checker_start(void);
811 void lnet_router_checker_stop(void);
812 void lnet_swap_pinginfo(lnet_ping_info_t *info);
813
814 int lnet_ping_target_init(void);
815 void lnet_ping_target_fini(void);
816 int lnet_ping(lnet_process_id_t id, int timeout_ms,
817               lnet_process_id_t *ids, int n_ids);
818
819 int lnet_parse_ip2nets (char **networksp, char *ip2nets);
820 int lnet_parse_routes (char *route_str, int *im_a_router);
821 int lnet_parse_networks (cfs_list_t *nilist, char *networks);
822
823 int lnet_nid2peer_locked(lnet_peer_t **lpp, lnet_nid_t nid);
824 lnet_peer_t *lnet_find_peer_locked (lnet_nid_t nid);
825 void lnet_peer_table_cleanup(void);
826 void lnet_peer_table_destroy(void);
827 int lnet_peer_table_create(void);
828 void lnet_debug_peer(lnet_nid_t nid);
829
830 #ifndef __KERNEL__
831 static inline int
832 lnet_parse_int_tunable(int *value, char *name)
833 {
834         char    *env = getenv(name);
835         char    *end;
836
837         if (env == NULL)
838                 return 0;
839
840         *value = strtoull(env, &end, 0);
841         if (*end == 0)
842                 return 0;
843
844         CERROR("Can't parse tunable %s=%s\n", name, env);
845         return -EINVAL;
846 }
847 #endif
848
849 #endif