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