Whamcloud - gitweb
db29f2d9bcbc246d61b18f5a73a3710ed8f7e010
[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  * Copyright (c) 2012, 2014, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lnet/include/lnet/lib-lnet.h
37  *
38  * Top level include for library side routines
39  */
40
41 #ifndef __LNET_LIB_LNET_H__
42 #define __LNET_LIB_LNET_H__
43
44 #include <libcfs/libcfs.h>
45 #include <lnet/types.h>
46 #include <lnet/lnet.h>
47 #include <lnet/lib-types.h>
48 #include <lnet/lib-dlc.h>
49
50 extern lnet_t  the_lnet;                        /* THE network */
51
52 #if (BITS_PER_LONG == 32)
53 /* 2 CPTs, allowing more CPTs might make us under memory pressure */
54 # define LNET_CPT_MAX_BITS     1
55
56 #else /* 64-bit system */
57 /*
58  * 256 CPTs for thousands of CPUs, allowing more CPTs might make us
59  * under risk of consuming all lh_cookie.
60  */
61 # define LNET_CPT_MAX_BITS     8
62 #endif /* BITS_PER_LONG == 32 */
63
64 /* max allowed CPT number */
65 #define LNET_CPT_MAX            (1 << LNET_CPT_MAX_BITS)
66
67 #define LNET_CPT_NUMBER         (the_lnet.ln_cpt_number)
68 #define LNET_CPT_BITS           (the_lnet.ln_cpt_bits)
69 #define LNET_CPT_MASK           ((1ULL << LNET_CPT_BITS) - 1)
70
71 /** exclusive lock */
72 #define LNET_LOCK_EX            CFS_PERCPT_LOCK_EX
73
74 static inline int lnet_is_route_alive(lnet_route_t *route)
75 {
76         if (!route->lr_gateway->lp_alive)
77                 return 0; /* gateway is down */
78         if ((route->lr_gateway->lp_ping_feats &
79              LNET_PING_FEAT_NI_STATUS) == 0)
80                 return 1; /* no NI status, assume it's alive */
81         /* has NI status, check # down NIs */
82         return route->lr_downis == 0;
83 }
84
85 static inline int lnet_is_wire_handle_none (lnet_handle_wire_t *wh)
86 {
87         return (wh->wh_interface_cookie == LNET_WIRE_HANDLE_COOKIE_NONE &&
88                 wh->wh_object_cookie == LNET_WIRE_HANDLE_COOKIE_NONE);
89 }
90
91 static inline int lnet_md_exhausted (lnet_libmd_t *md)
92 {
93         return (md->md_threshold == 0 ||
94                 ((md->md_options & LNET_MD_MAX_SIZE) != 0 &&
95                  md->md_offset + md->md_max_size > md->md_length));
96 }
97
98 static inline int lnet_md_unlinkable (lnet_libmd_t *md)
99 {
100         /* Should unlink md when its refcount is 0 and either:
101          *  - md has been flagged for deletion (by auto unlink or LNetM[DE]Unlink,
102          *    in the latter case md may not be exhausted).
103          *  - auto unlink is on and md is exhausted.
104          */
105         if (md->md_refcount != 0)
106                 return 0;
107
108         if ((md->md_flags & LNET_MD_FLAG_ZOMBIE) != 0)
109                 return 1;
110
111         return ((md->md_flags & LNET_MD_FLAG_AUTO_UNLINK) != 0 &&
112                 lnet_md_exhausted(md));
113 }
114
115 #define lnet_cpt_table()        (the_lnet.ln_cpt_table)
116 #define lnet_cpt_current()      cfs_cpt_current(the_lnet.ln_cpt_table, 1)
117
118 static inline int
119 lnet_cpt_of_cookie(__u64 cookie)
120 {
121         unsigned int cpt = (cookie >> LNET_COOKIE_TYPE_BITS) & LNET_CPT_MASK;
122
123         /* LNET_CPT_NUMBER doesn't have to be power2, which means we can
124          * get illegal cpt from it's invalid cookie */
125         return cpt < LNET_CPT_NUMBER ? cpt : cpt % LNET_CPT_NUMBER;
126 }
127
128 static inline void
129 lnet_res_lock(int cpt)
130 {
131         cfs_percpt_lock(the_lnet.ln_res_lock, cpt);
132 }
133
134 static inline void
135 lnet_res_unlock(int cpt)
136 {
137         cfs_percpt_unlock(the_lnet.ln_res_lock, cpt);
138 }
139
140 static inline int
141 lnet_res_lock_current(void)
142 {
143         int cpt = lnet_cpt_current();
144
145         lnet_res_lock(cpt);
146         return cpt;
147 }
148
149 static inline void
150 lnet_net_lock(int cpt)
151 {
152         cfs_percpt_lock(the_lnet.ln_net_lock, cpt);
153 }
154
155 static inline void
156 lnet_net_unlock(int cpt)
157 {
158         cfs_percpt_unlock(the_lnet.ln_net_lock, cpt);
159 }
160
161 static inline int
162 lnet_net_lock_current(void)
163 {
164         int cpt = lnet_cpt_current();
165
166         lnet_net_lock(cpt);
167         return cpt;
168 }
169
170 #define LNET_LOCK()             lnet_net_lock(LNET_LOCK_EX)
171 #define LNET_UNLOCK()           lnet_net_unlock(LNET_LOCK_EX)
172
173 #define lnet_ptl_lock(ptl)      spin_lock(&(ptl)->ptl_lock)
174 #define lnet_ptl_unlock(ptl)    spin_unlock(&(ptl)->ptl_lock)
175 #define lnet_eq_wait_lock()     spin_lock(&the_lnet.ln_eq_wait_lock)
176 #define lnet_eq_wait_unlock()   spin_unlock(&the_lnet.ln_eq_wait_lock)
177 #define lnet_ni_lock(ni)        spin_lock(&(ni)->ni_lock)
178 #define lnet_ni_unlock(ni)      spin_unlock(&(ni)->ni_lock)
179 #define LNET_MUTEX_LOCK(m)      mutex_lock(m)
180 #define LNET_MUTEX_UNLOCK(m)    mutex_unlock(m)
181
182 #define MAX_PORTALS     64
183
184 static inline lnet_eq_t *
185 lnet_eq_alloc (void)
186 {
187         lnet_eq_t *eq;
188
189         LIBCFS_ALLOC(eq, sizeof(*eq));
190         return (eq);
191 }
192
193 static inline void
194 lnet_eq_free(lnet_eq_t *eq)
195 {
196         LIBCFS_FREE(eq, sizeof(*eq));
197 }
198
199 static inline lnet_libmd_t *
200 lnet_md_alloc (lnet_md_t *umd)
201 {
202         lnet_libmd_t *md;
203         unsigned int  size;
204         unsigned int  niov;
205
206         if ((umd->options & LNET_MD_KIOV) != 0) {
207                 niov = umd->length;
208                 size = offsetof(lnet_libmd_t, md_iov.kiov[niov]);
209         } else {
210                 niov = ((umd->options & LNET_MD_IOVEC) != 0) ?
211                        umd->length : 1;
212                 size = offsetof(lnet_libmd_t, md_iov.iov[niov]);
213         }
214
215         LIBCFS_ALLOC(md, size);
216
217         if (md != NULL) {
218                 /* Set here in case of early free */
219                 md->md_options = umd->options;
220                 md->md_niov = niov;
221                 INIT_LIST_HEAD(&md->md_list);
222         }
223
224         return md;
225 }
226
227 static inline void
228 lnet_md_free(lnet_libmd_t *md)
229 {
230         unsigned int  size;
231
232         if ((md->md_options & LNET_MD_KIOV) != 0)
233                 size = offsetof(lnet_libmd_t, md_iov.kiov[md->md_niov]);
234         else
235                 size = offsetof(lnet_libmd_t, md_iov.iov[md->md_niov]);
236
237         LIBCFS_FREE(md, size);
238 }
239
240 static inline lnet_me_t *
241 lnet_me_alloc (void)
242 {
243         lnet_me_t *me;
244
245         LIBCFS_ALLOC(me, sizeof(*me));
246         return (me);
247 }
248
249 static inline void
250 lnet_me_free(lnet_me_t *me)
251 {
252         LIBCFS_FREE(me, sizeof(*me));
253 }
254
255 static inline lnet_msg_t *
256 lnet_msg_alloc(void)
257 {
258         lnet_msg_t *msg;
259
260         LIBCFS_ALLOC(msg, sizeof(*msg));
261
262         /* no need to zero, LIBCFS_ALLOC does for us */
263         return (msg);
264 }
265
266 static inline void
267 lnet_msg_free(lnet_msg_t *msg)
268 {
269         LASSERT(!msg->msg_onactivelist);
270         LIBCFS_FREE(msg, sizeof(*msg));
271 }
272
273 lnet_libhandle_t *lnet_res_lh_lookup(struct lnet_res_container *rec,
274                                      __u64 cookie);
275 void lnet_res_lh_initialize(struct lnet_res_container *rec,
276                             lnet_libhandle_t *lh);
277 static inline void
278 lnet_res_lh_invalidate(lnet_libhandle_t *lh)
279 {
280         /* ALWAYS called with resource lock held */
281         /* NB: cookie is still useful, don't reset it */
282         list_del(&lh->lh_hash_chain);
283 }
284
285 static inline void
286 lnet_eq2handle (lnet_handle_eq_t *handle, lnet_eq_t *eq)
287 {
288         if (eq == NULL) {
289                 LNetInvalidateHandle(handle);
290                 return;
291         }
292
293         handle->cookie = eq->eq_lh.lh_cookie;
294 }
295
296 static inline lnet_eq_t *
297 lnet_handle2eq(lnet_handle_eq_t *handle)
298 {
299         /* ALWAYS called with resource lock held */
300         lnet_libhandle_t *lh;
301
302         lh = lnet_res_lh_lookup(&the_lnet.ln_eq_container, handle->cookie);
303         if (lh == NULL)
304                 return NULL;
305
306         return lh_entry(lh, lnet_eq_t, eq_lh);
307 }
308
309 static inline void
310 lnet_md2handle (lnet_handle_md_t *handle, lnet_libmd_t *md)
311 {
312         handle->cookie = md->md_lh.lh_cookie;
313 }
314
315 static inline lnet_libmd_t *
316 lnet_handle2md(lnet_handle_md_t *handle)
317 {
318         /* ALWAYS called with resource lock held */
319         lnet_libhandle_t *lh;
320         int              cpt;
321
322         cpt = lnet_cpt_of_cookie(handle->cookie);
323         lh = lnet_res_lh_lookup(the_lnet.ln_md_containers[cpt],
324                                 handle->cookie);
325         if (lh == NULL)
326                 return NULL;
327
328         return lh_entry(lh, lnet_libmd_t, md_lh);
329 }
330
331 static inline lnet_libmd_t *
332 lnet_wire_handle2md(lnet_handle_wire_t *wh)
333 {
334         /* ALWAYS called with resource lock held */
335         lnet_libhandle_t *lh;
336         int              cpt;
337
338         if (wh->wh_interface_cookie != the_lnet.ln_interface_cookie)
339                 return NULL;
340
341         cpt = lnet_cpt_of_cookie(wh->wh_object_cookie);
342         lh = lnet_res_lh_lookup(the_lnet.ln_md_containers[cpt],
343                                 wh->wh_object_cookie);
344         if (lh == NULL)
345                 return NULL;
346
347         return lh_entry(lh, lnet_libmd_t, md_lh);
348 }
349
350 static inline void
351 lnet_me2handle (lnet_handle_me_t *handle, lnet_me_t *me)
352 {
353         handle->cookie = me->me_lh.lh_cookie;
354 }
355
356 static inline lnet_me_t *
357 lnet_handle2me(lnet_handle_me_t *handle)
358 {
359         /* ALWAYS called with resource lock held */
360         lnet_libhandle_t *lh;
361         int              cpt;
362
363         cpt = lnet_cpt_of_cookie(handle->cookie);
364         lh = lnet_res_lh_lookup(the_lnet.ln_me_containers[cpt],
365                                 handle->cookie);
366         if (lh == NULL)
367                 return NULL;
368
369         return lh_entry(lh, lnet_me_t, me_lh);
370 }
371
372 static inline void
373 lnet_peer_addref_locked(lnet_peer_t *lp)
374 {
375         LASSERT (lp->lp_refcount > 0);
376         lp->lp_refcount++;
377 }
378
379 extern void lnet_destroy_peer_locked(lnet_peer_t *lp);
380
381 static inline void
382 lnet_peer_decref_locked(lnet_peer_t *lp)
383 {
384         LASSERT (lp->lp_refcount > 0);
385         lp->lp_refcount--;
386         if (lp->lp_refcount == 0)
387                 lnet_destroy_peer_locked(lp);
388 }
389
390 static inline int
391 lnet_isrouter(lnet_peer_t *lp)
392 {
393         return lp->lp_rtr_refcount != 0;
394 }
395
396 static inline void
397 lnet_ni_addref_locked(lnet_ni_t *ni, int cpt)
398 {
399         LASSERT(cpt >= 0 && cpt < LNET_CPT_NUMBER);
400         LASSERT(*ni->ni_refs[cpt] >= 0);
401
402         (*ni->ni_refs[cpt])++;
403 }
404
405 static inline void
406 lnet_ni_addref(lnet_ni_t *ni)
407 {
408         lnet_net_lock(0);
409         lnet_ni_addref_locked(ni, 0);
410         lnet_net_unlock(0);
411 }
412
413 static inline void
414 lnet_ni_decref_locked(lnet_ni_t *ni, int cpt)
415 {
416         LASSERT(cpt >= 0 && cpt < LNET_CPT_NUMBER);
417         LASSERT(*ni->ni_refs[cpt] > 0);
418
419         (*ni->ni_refs[cpt])--;
420 }
421
422 static inline void
423 lnet_ni_decref(lnet_ni_t *ni)
424 {
425         lnet_net_lock(0);
426         lnet_ni_decref_locked(ni, 0);
427         lnet_net_unlock(0);
428 }
429
430 void lnet_ni_free(lnet_ni_t *ni);
431 lnet_ni_t *
432 lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist);
433
434 static inline int
435 lnet_nid2peerhash(lnet_nid_t nid)
436 {
437         return hash_long(nid, LNET_PEER_HASH_BITS);
438 }
439
440 static inline struct list_head *
441 lnet_net2rnethash(__u32 net)
442 {
443         return &the_lnet.ln_remote_nets_hash[(LNET_NETNUM(net) +
444                 LNET_NETTYP(net)) &
445                 ((1U << the_lnet.ln_remote_nets_hbits) - 1)];
446 }
447
448 extern lnd_t the_lolnd;
449 extern int avoid_asym_router_failure;
450
451 extern int lnet_cpt_of_nid_locked(lnet_nid_t nid);
452 extern int lnet_cpt_of_nid(lnet_nid_t nid);
453 extern lnet_ni_t *lnet_nid2ni_locked(lnet_nid_t nid, int cpt);
454 extern lnet_ni_t *lnet_net2ni_locked(__u32 net, int cpt);
455 extern lnet_ni_t *lnet_net2ni(__u32 net);
456
457 int lnet_init(void);
458 void lnet_fini(void);
459
460 extern int portal_rotor;
461
462 int lnet_notify(lnet_ni_t *ni, lnet_nid_t peer, int alive, cfs_time_t when);
463 void lnet_notify_locked(lnet_peer_t *lp, int notifylnd, int alive, cfs_time_t when);
464 int lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway_nid,
465                    unsigned int priority);
466 int lnet_check_routes(void);
467 int lnet_del_route(__u32 net, lnet_nid_t gw_nid);
468 void lnet_destroy_routes(void);
469 int lnet_get_route(int idx, __u32 *net, __u32 *hops,
470                    lnet_nid_t *gateway, __u32 *alive, __u32 *priority);
471 int lnet_get_net_config(int idx,
472                         __u32 *cpt_count,
473                         __u64 *nid,
474                         int *peer_timeout,
475                         int *peer_tx_credits,
476                         int *peer_rtr_cr,
477                         int *max_tx_credits,
478                         struct lnet_ioctl_net_config *net_config);
479 int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg);
480
481 void lnet_proc_init(void);
482 void lnet_proc_fini(void);
483 int  lnet_rtrpools_alloc(int im_a_router);
484 void lnet_destroy_rtrbuf(lnet_rtrbuf_t *rb, int npages);
485 int  lnet_rtrpools_adjust(int tiny, int small, int large);
486 int lnet_rtrpools_enable(void);
487 void lnet_rtrpools_disable(void);
488 void lnet_rtrpools_free(int keep_pools);
489 lnet_remotenet_t *lnet_find_net_locked (__u32 net);
490 int lnet_dyn_add_ni(lnet_pid_t requested_pid, char *nets,
491                     __s32 peer_timeout, __s32 peer_cr, __s32 peer_buf_cr,
492                     __s32 credits);
493 int lnet_dyn_del_ni(__u32 net);
494 int lnet_clear_lazy_portal(struct lnet_ni *ni, int portal, char *reason);
495
496 int lnet_islocalnid(lnet_nid_t nid);
497 int lnet_islocalnet(__u32 net);
498
499 void lnet_msg_attach_md(lnet_msg_t *msg, lnet_libmd_t *md,
500                         unsigned int offset, unsigned int mlen);
501 void lnet_msg_detach_md(lnet_msg_t *msg, int status);
502 void lnet_build_unlink_event(lnet_libmd_t *md, lnet_event_t *ev);
503 void lnet_build_msg_event(lnet_msg_t *msg, lnet_event_kind_t ev_type);
504 void lnet_msg_commit(lnet_msg_t *msg, int cpt);
505 void lnet_msg_decommit(lnet_msg_t *msg, int cpt, int status);
506
507 void lnet_eq_enqueue_event(lnet_eq_t *eq, lnet_event_t *ev);
508 void lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
509                     unsigned int offset, unsigned int len);
510 int lnet_send(lnet_nid_t nid, lnet_msg_t *msg, lnet_nid_t rtr_nid);
511 void lnet_return_tx_credits_locked(lnet_msg_t *msg);
512 void lnet_return_rx_credits_locked(lnet_msg_t *msg);
513 void lnet_schedule_blocked_locked(lnet_rtrbufpool_t *rbp);
514 void lnet_drop_routed_msgs_locked(struct list_head *list, int cpt);
515
516 /* portals functions */
517 /* portals attributes */
518 static inline int
519 lnet_ptl_is_lazy(lnet_portal_t *ptl)
520 {
521         return !!(ptl->ptl_options & LNET_PTL_LAZY);
522 }
523
524 static inline int
525 lnet_ptl_is_unique(lnet_portal_t *ptl)
526 {
527         return !!(ptl->ptl_options & LNET_PTL_MATCH_UNIQUE);
528 }
529
530 static inline int
531 lnet_ptl_is_wildcard(lnet_portal_t *ptl)
532 {
533         return !!(ptl->ptl_options & LNET_PTL_MATCH_WILDCARD);
534 }
535
536 static inline void
537 lnet_ptl_setopt(lnet_portal_t *ptl, int opt)
538 {
539         ptl->ptl_options |= opt;
540 }
541
542 static inline void
543 lnet_ptl_unsetopt(lnet_portal_t *ptl, int opt)
544 {
545         ptl->ptl_options &= ~opt;
546 }
547
548 /* match-table functions */
549 struct list_head *lnet_mt_match_head(struct lnet_match_table *mtable,
550                                lnet_process_id_t id, __u64 mbits);
551 struct lnet_match_table *lnet_mt_of_attach(unsigned int index,
552                                            lnet_process_id_t id, __u64 mbits,
553                                            __u64 ignore_bits,
554                                            lnet_ins_pos_t pos);
555 int lnet_mt_match_md(struct lnet_match_table *mtable,
556                      struct lnet_match_info *info, struct lnet_msg *msg);
557
558 /* portals match/attach functions */
559 void lnet_ptl_attach_md(lnet_me_t *me, lnet_libmd_t *md,
560                         struct list_head *matches, struct list_head *drops);
561 void lnet_ptl_detach_md(lnet_me_t *me, lnet_libmd_t *md);
562 int lnet_ptl_match_md(struct lnet_match_info *info, struct lnet_msg *msg);
563
564 /* initialized and finalize portals */
565 int lnet_portals_create(void);
566 void lnet_portals_destroy(void);
567
568 /* message functions */
569 int lnet_parse (lnet_ni_t *ni, lnet_hdr_t *hdr,
570                 lnet_nid_t fromnid, void *private, int rdma_req);
571 int lnet_parse_local(lnet_ni_t *ni, lnet_msg_t *msg);
572 int lnet_parse_forward_locked(lnet_ni_t *ni, lnet_msg_t *msg);
573
574 void lnet_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
575                unsigned int offset, unsigned int mlen, unsigned int rlen);
576 void lnet_ni_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg,
577                   int delayed, unsigned int offset,
578                   unsigned int mlen, unsigned int rlen);
579
580 lnet_msg_t *lnet_create_reply_msg (lnet_ni_t *ni, lnet_msg_t *get_msg);
581 void lnet_set_reply_msg_len(lnet_ni_t *ni, lnet_msg_t *msg, unsigned int len);
582
583 void lnet_finalize(lnet_ni_t *ni, lnet_msg_t *msg, int rc);
584
585 void lnet_drop_message(lnet_ni_t *ni, int cpt, void *private,
586                        unsigned int nob);
587 void lnet_drop_delayed_msg_list(struct list_head *head, char *reason);
588 void lnet_recv_delayed_msg_list(struct list_head *head);
589
590 int lnet_msg_container_setup(struct lnet_msg_container *container, int cpt);
591 void lnet_msg_container_cleanup(struct lnet_msg_container *container);
592 void lnet_msg_containers_destroy(void);
593 int lnet_msg_containers_create(void);
594
595 char *lnet_msgtyp2str (int type);
596 void lnet_print_hdr (lnet_hdr_t * hdr);
597 int lnet_fail_nid(lnet_nid_t nid, unsigned int threshold);
598
599 /** \addtogroup lnet_fault_simulation @{ */
600
601 int lnet_fault_ctl(int cmd, struct libcfs_ioctl_data *data);
602 int lnet_fault_init(void);
603 void lnet_fault_fini(void);
604
605 bool lnet_drop_rule_match(lnet_hdr_t *hdr);
606
607 int lnet_delay_rule_add(struct lnet_fault_attr *attr);
608 int lnet_delay_rule_del(lnet_nid_t src, lnet_nid_t dst, bool shutdown);
609 int lnet_delay_rule_list(int pos, struct lnet_fault_attr *attr,
610                          struct lnet_fault_stat *stat);
611 void lnet_delay_rule_reset(void);
612 void lnet_delay_rule_check(void);
613 bool lnet_delay_rule_match_locked(lnet_hdr_t *hdr, struct lnet_msg *msg);
614
615 /** @} lnet_fault_simulation */
616
617 void lnet_counters_get(lnet_counters_t *counters);
618 void lnet_counters_reset(void);
619
620 unsigned int lnet_iov_nob (unsigned int niov, struct iovec *iov);
621 int lnet_extract_iov (int dst_niov, struct iovec *dst,
622                       int src_niov, struct iovec *src,
623                       unsigned int offset, unsigned int len);
624
625 unsigned int lnet_kiov_nob (unsigned int niov, lnet_kiov_t *iov);
626 int lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
627                       int src_niov, lnet_kiov_t *src,
628                       unsigned int offset, unsigned int len);
629
630 void lnet_copy_iov2iov (unsigned int ndiov, struct iovec *diov,
631                         unsigned int doffset,
632                         unsigned int nsiov, struct iovec *siov,
633                         unsigned int soffset, unsigned int nob);
634 void lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov,
635                          unsigned int iovoffset,
636                          unsigned int nkiov, lnet_kiov_t *kiov,
637                          unsigned int kiovoffset, unsigned int nob);
638 void lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov,
639                          unsigned int kiovoffset,
640                          unsigned int niov, struct iovec *iov,
641                          unsigned int iovoffset, unsigned int nob);
642 void lnet_copy_kiov2kiov (unsigned int ndkiov, lnet_kiov_t *dkiov,
643                           unsigned int doffset,
644                           unsigned int nskiov, lnet_kiov_t *skiov,
645                           unsigned int soffset, unsigned int nob);
646
647 static inline void
648 lnet_copy_iov2flat(int dlen, __user void *dest, unsigned int doffset,
649                    unsigned int nsiov, struct iovec *siov, unsigned int soffset,
650                    unsigned int nob)
651 {
652         struct iovec diov = {/*.iov_base = */ dest, /*.iov_len = */ dlen};
653
654         lnet_copy_iov2iov(1, &diov, doffset,
655                           nsiov, siov, soffset, nob);
656 }
657
658 static inline void
659 lnet_copy_kiov2flat(int dlen, void __user *dest, unsigned int doffset,
660                     unsigned int nsiov, lnet_kiov_t *skiov,
661                     unsigned int soffset, unsigned int nob)
662 {
663         struct iovec diov = {/* .iov_base = */ dest, /* .iov_len = */ dlen};
664
665         lnet_copy_kiov2iov(1, &diov, doffset,
666                            nsiov, skiov, soffset, nob);
667 }
668
669 static inline void
670 lnet_copy_flat2iov(unsigned int ndiov, struct iovec *diov, unsigned int doffset,
671                    int slen, void __user *src, unsigned int soffset,
672                    unsigned int nob)
673 {
674         struct iovec siov = {/*.iov_base = */ src, /*.iov_len = */slen};
675         lnet_copy_iov2iov(ndiov, diov, doffset,
676                           1, &siov, soffset, nob);
677 }
678
679 static inline void
680 lnet_copy_flat2kiov(unsigned int ndiov, lnet_kiov_t *dkiov,
681                     unsigned int doffset, int slen, void __user *src,
682                     unsigned int soffset, unsigned int nob)
683 {
684         struct iovec siov = {/* .iov_base = */ src, /* .iov_len = */ slen};
685         lnet_copy_iov2kiov(ndiov, dkiov, doffset,
686                            1, &siov, soffset, nob);
687 }
688
689 void lnet_me_unlink(lnet_me_t *me);
690
691 void lnet_md_unlink(lnet_libmd_t *md);
692 void lnet_md_deconstruct(lnet_libmd_t *lmd, lnet_md_t *umd);
693
694 void lnet_register_lnd(lnd_t *lnd);
695 void lnet_unregister_lnd(lnd_t *lnd);
696
697 int lnet_connect(cfs_socket_t **sockp, lnet_nid_t peer_nid,
698                  __u32 local_ip, __u32 peer_ip, int peer_port);
699 void lnet_connect_console_error(int rc, lnet_nid_t peer_nid,
700                                 __u32 peer_ip, int port);
701 int lnet_count_acceptor_nis(void);
702 int lnet_acceptor_timeout(void);
703 int lnet_acceptor_port(void);
704 int lnet_acceptor_start(void);
705 void lnet_acceptor_stop(void);
706
707 int lnet_peers_start_down(void);
708 int lnet_peer_buffer_credits(lnet_ni_t *ni);
709
710 int lnet_router_checker_start(void);
711 void lnet_router_checker_stop(void);
712 void lnet_router_ni_update_locked(lnet_peer_t *gw, __u32 net);
713 void lnet_swap_pinginfo(lnet_ping_info_t *info);
714
715 int lnet_parse_ip2nets(char **networksp, char *ip2nets);
716 int lnet_parse_routes(char *route_str, int *im_a_router);
717 int lnet_parse_networks(struct list_head *nilist, char *networks);
718 int lnet_net_unique(__u32 net, struct list_head *nilist);
719
720 int lnet_nid2peer_locked(lnet_peer_t **lpp, lnet_nid_t nid, int cpt);
721 lnet_peer_t *lnet_find_peer_locked(struct lnet_peer_table *ptable,
722                                    lnet_nid_t nid);
723 void lnet_peer_tables_cleanup(lnet_ni_t *ni);
724 void lnet_peer_tables_destroy(void);
725 int lnet_peer_tables_create(void);
726 void lnet_debug_peer(lnet_nid_t nid);
727 int lnet_get_peer_info(__u32 peer_index, __u64 *nid,
728                        char alivness[LNET_MAX_STR_LEN],
729                        __u32 *cpt_iter, __u32 *refcount,
730                        __u32 *ni_peer_tx_credits, __u32 *peer_tx_credits,
731                        __u32 *peer_rtr_credits, __u32 *peer_min_rtr_credtis,
732                        __u32 *peer_tx_qnob);
733
734 static inline void
735 lnet_peer_set_alive(lnet_peer_t *lp)
736 {
737         lp->lp_last_alive = lp->lp_last_query = cfs_time_current();
738         if (!lp->lp_alive)
739                 lnet_notify_locked(lp, 0, 1, lp->lp_last_alive);
740 }
741
742 #endif