Whamcloud - gitweb
LU-10129 lnd: set device capabilities
[fs/lustre-release.git] / lnet / klnds / o2iblnd / o2iblnd.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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lnet/klnds/o2iblnd/o2iblnd.h
33  *
34  * Author: Eric Barton <eric@bartonsoftware.com>
35  */
36
37 #ifdef HAVE_COMPAT_RDMA
38 #include <linux/compat-2.6.h>
39
40 #ifdef LINUX_3_17_COMPAT_H
41 #undef NEED_KTIME_GET_REAL_NS
42 #endif
43
44 #endif
45
46 #include <linux/version.h>
47 #include <linux/module.h>
48 #include <linux/kernel.h>
49 #include <linux/kthread.h>
50 #include <linux/mm.h>
51 #include <linux/string.h>
52 #include <linux/stat.h>
53 #include <linux/errno.h>
54 #include <linux/unistd.h>
55 #include <linux/uio.h>
56
57 #include <asm/uaccess.h>
58 #include <asm/io.h>
59
60 #include <linux/init.h>
61 #include <linux/fs.h>
62 #include <linux/file.h>
63 #include <linux/stat.h>
64 #include <linux/list.h>
65 #include <linux/kmod.h>
66 #include <linux/sysctl.h>
67 #include <linux/pci.h>
68 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32)
69 #include <linux/pci-dma.h>
70 #endif
71
72 #include <net/sock.h>
73 #include <linux/in.h>
74
75 #include <rdma/rdma_cm.h>
76 #include <rdma/ib_cm.h>
77 #include <rdma/ib_verbs.h>
78 #include <rdma/ib_fmr_pool.h>
79
80 #define DEBUG_SUBSYSTEM S_LND
81
82 #include <libcfs/libcfs.h>
83 #include <lnet/lib-lnet.h>
84
85 #define IBLND_PEER_HASH_SIZE            101     /* # peer_ni lists */
86 /* # scheduler loops before reschedule */
87 #define IBLND_RESCHED                   100
88
89 #define IBLND_N_SCHED                   2
90 #define IBLND_N_SCHED_HIGH              4
91
92 #define IBLND_DEV_CAPS_FASTREG_ENABLED          0x1
93 #define IBLND_DEV_CAPS_FASTREG_GAPS_SUPPORT     0x2
94 #define IBLND_DEV_CAPS_FMR_ENABLED              0x4
95
96 typedef struct
97 {
98         int              *kib_dev_failover;     /* HCA failover */
99         unsigned int     *kib_service;          /* IB service number */
100         int              *kib_min_reconnect_interval; /* first failed connection retry... */
101         int              *kib_max_reconnect_interval; /* ...exponentially increasing to this */
102         int              *kib_cksum;            /* checksum kib_msg_t? */
103         int              *kib_timeout;          /* comms timeout (seconds) */
104         int              *kib_keepalive;        /* keepalive timeout (seconds) */
105         int              *kib_ntx;              /* # tx descs */
106         char            **kib_default_ipif;     /* default IPoIB interface */
107         int              *kib_retry_count;
108         int              *kib_rnr_retry_count;
109         int              *kib_ib_mtu;           /* IB MTU */
110         int              *kib_require_priv_port;/* accept only privileged ports */
111         int              *kib_use_priv_port;    /* use privileged port for active connect */
112         /* # threads on each CPT */
113         int              *kib_nscheds;
114         int              *kib_wrq_sge;          /* # sg elements per wrq */
115 } kib_tunables_t;
116
117 extern kib_tunables_t  kiblnd_tunables;
118
119 #define IBLND_MSG_QUEUE_SIZE_V1      8          /* V1 only : # messages/RDMAs in-flight */
120 #define IBLND_CREDIT_HIGHWATER_V1    7          /* V1 only : when eagerly to return credits */
121
122 #define IBLND_CREDITS_DEFAULT        8          /* default # of peer_ni credits */
123 #define IBLND_CREDITS_MAX          ((typeof(((kib_msg_t*) 0)->ibm_credits)) - 1)  /* Max # of peer_ni credits */
124
125 /* when eagerly to return credits */
126 #define IBLND_CREDITS_HIGHWATER(t, v) ((v) == IBLND_MSG_VERSION_1 ? \
127                                         IBLND_CREDIT_HIGHWATER_V1 : \
128                                         t->lnd_peercredits_hiw)
129
130 #ifdef HAVE_RDMA_CREATE_ID_5ARG
131 # define kiblnd_rdma_create_id(cb, dev, ps, qpt) rdma_create_id(current->nsproxy->net_ns, \
132                                                                 cb, dev, \
133                                                                 ps, qpt)
134 #else
135 # ifdef HAVE_RDMA_CREATE_ID_4ARG
136 #  define kiblnd_rdma_create_id(cb, dev, ps, qpt) rdma_create_id(cb, dev, \
137                                                                  ps, qpt)
138 # else
139 #  define kiblnd_rdma_create_id(cb, dev, ps, qpt) rdma_create_id(cb, dev, ps)
140 # endif
141 #endif
142
143 /* 2 OOB shall suffice for 1 keepalive and 1 returning credits */
144 #define IBLND_OOB_CAPABLE(v)       ((v) != IBLND_MSG_VERSION_1)
145 #define IBLND_OOB_MSGS(v)           (IBLND_OOB_CAPABLE(v) ? 2 : 0)
146
147 #define IBLND_MSG_SIZE              (4<<10)                 /* max size of queued messages (inc hdr) */
148 #define IBLND_MAX_RDMA_FRAGS         LNET_MAX_IOV           /* max # of fragments supported */
149
150 /************************/
151 /* derived constants... */
152 /* Pools (shared by connections on each CPT) */
153 /* These pools can grow at runtime, so don't need give a very large value */
154 #define IBLND_TX_POOL                   256
155 #define IBLND_FMR_POOL                  256
156 #define IBLND_FMR_POOL_FLUSH            192
157
158 /* RX messages (per connection) */
159 #define IBLND_RX_MSGS(c)        \
160         ((c->ibc_queue_depth) * 2 + IBLND_OOB_MSGS(c->ibc_version))
161 #define IBLND_RX_MSG_BYTES(c)       (IBLND_RX_MSGS(c) * IBLND_MSG_SIZE)
162 #define IBLND_RX_MSG_PAGES(c)   \
163         ((IBLND_RX_MSG_BYTES(c) + PAGE_SIZE - 1) / PAGE_SIZE)
164
165 /* WRs and CQEs (per connection) */
166 #define IBLND_RECV_WRS(c)            IBLND_RX_MSGS(c)
167 #define IBLND_SEND_WRS(c)       \
168         ((c->ibc_max_frags + 1) * kiblnd_concurrent_sends(c->ibc_version, \
169                                                           c->ibc_peer->ibp_ni))
170 #define IBLND_CQ_ENTRIES(c)         (IBLND_RECV_WRS(c) + IBLND_SEND_WRS(c))
171
172 struct kib_hca_dev;
173
174 /* o2iblnd can run over aliased interface */
175 #ifdef IFALIASZ
176 #define KIB_IFNAME_SIZE              IFALIASZ
177 #else
178 #define KIB_IFNAME_SIZE              256
179 #endif
180
181 typedef struct
182 {
183         struct list_head        ibd_list;       /* chain on kib_devs */
184         struct list_head        ibd_fail_list;  /* chain on kib_failed_devs */
185         __u32                   ibd_ifip;       /* IPoIB interface IP */
186         /** IPoIB interface name */
187         char                    ibd_ifname[KIB_IFNAME_SIZE];
188         int                     ibd_nnets;      /* # nets extant */
189
190         cfs_time_t              ibd_next_failover;
191         /* # failover failures */
192         int                     ibd_failed_failover;
193         /* failover in progress */
194         unsigned int            ibd_failover;
195         /* IPoIB interface is a bonding master */
196         unsigned int            ibd_can_failover;
197         struct list_head        ibd_nets;
198         struct kib_hca_dev      *ibd_hdev;
199         __u32                   ibd_dev_caps;
200 } kib_dev_t;
201
202 typedef struct kib_hca_dev
203 {
204         struct rdma_cm_id   *ibh_cmid;          /* listener cmid */
205         struct ib_device    *ibh_ibdev;         /* IB device */
206         int                  ibh_page_shift;    /* page shift of current HCA */
207         int                  ibh_page_size;     /* page size of current HCA */
208         __u64                ibh_page_mask;     /* page mask of current HCA */
209         int                  ibh_mr_shift;      /* bits shift of max MR size */
210         __u64                ibh_mr_size;       /* size of MR */
211 #ifdef HAVE_IB_GET_DMA_MR
212         struct ib_mr        *ibh_mrs;           /* global MR */
213 #endif
214         struct ib_pd        *ibh_pd;            /* PD */
215         kib_dev_t           *ibh_dev;           /* owner */
216         atomic_t             ibh_ref;           /* refcount */
217 } kib_hca_dev_t;
218
219 /** # of seconds to keep pool alive */
220 #define IBLND_POOL_DEADLINE     300
221 /** # of seconds to retry if allocation failed */
222 #define IBLND_POOL_RETRY        1
223
224 typedef struct
225 {
226         int                     ibp_npages;             /* # pages */
227         struct page            *ibp_pages[0];           /* page array */
228 } kib_pages_t;
229
230 struct kib_pool;
231 struct kib_poolset;
232
233 typedef int  (*kib_ps_pool_create_t)(struct kib_poolset *ps,
234                                      int inc, struct kib_pool **pp_po);
235 typedef void (*kib_ps_pool_destroy_t)(struct kib_pool *po);
236 typedef void (*kib_ps_node_init_t)(struct kib_pool *po, struct list_head *node);
237 typedef void (*kib_ps_node_fini_t)(struct kib_pool *po, struct list_head *node);
238
239 struct kib_net;
240
241 #define IBLND_POOL_NAME_LEN     32
242
243 typedef struct kib_poolset
244 {
245         /* serialize */
246         spinlock_t              ps_lock;
247         /* network it belongs to */
248         struct kib_net          *ps_net;
249         /* pool set name */
250         char                    ps_name[IBLND_POOL_NAME_LEN];
251         /* list of pools */
252         struct list_head        ps_pool_list;
253         /* failed pool list */
254         struct list_head        ps_failed_pool_list;
255         /* time stamp for retry if failed to allocate */
256         cfs_time_t              ps_next_retry;
257         /* is allocating new pool */
258         int                     ps_increasing;
259         /* new pool size */
260         int                     ps_pool_size;
261         /* CPT id */
262         int                     ps_cpt;
263
264         /* create a new pool */
265         kib_ps_pool_create_t    ps_pool_create;
266         /* destroy a pool */
267         kib_ps_pool_destroy_t   ps_pool_destroy;
268         /* initialize new allocated node */
269         kib_ps_node_init_t      ps_node_init;
270         /* finalize node */
271         kib_ps_node_fini_t      ps_node_fini;
272 } kib_poolset_t;
273
274 typedef struct kib_pool
275 {
276         /* chain on pool list */
277         struct list_head        po_list;
278         /* pre-allocated node */
279         struct list_head        po_free_list;
280         /* pool_set of this pool */
281         kib_poolset_t          *po_owner;
282         /* deadline of this pool */
283         cfs_time_t              po_deadline;
284         /* # of elements in use */
285         int                     po_allocated;
286         /* pool is created on failed HCA */
287         int                     po_failed;
288         /* # of pre-allocated elements */
289         int                     po_size;
290 } kib_pool_t;
291
292 typedef struct {
293         kib_poolset_t           tps_poolset;            /* pool-set */
294         __u64                   tps_next_tx_cookie;     /* cookie of TX */
295 } kib_tx_poolset_t;
296
297 typedef struct {
298         kib_pool_t              tpo_pool;               /* pool */
299         struct kib_hca_dev     *tpo_hdev;               /* device for this pool */
300         struct kib_tx          *tpo_tx_descs;           /* all the tx descriptors */
301         kib_pages_t            *tpo_tx_pages;           /* premapped tx msg pages */
302 } kib_tx_pool_t;
303
304 typedef struct
305 {
306         spinlock_t              fps_lock;               /* serialize */
307         struct kib_net         *fps_net;                /* IB network */
308         struct list_head        fps_pool_list;          /* FMR pool list */
309         struct list_head        fps_failed_pool_list;   /* FMR pool list */
310         __u64                   fps_version;            /* validity stamp */
311         int                     fps_cpt;                /* CPT id */
312         int                     fps_pool_size;
313         int                     fps_flush_trigger;
314         int                     fps_cache;
315         /* is allocating new pool */
316         int                     fps_increasing;
317         /* time stamp for retry if failed to allocate */
318         cfs_time_t              fps_next_retry;
319 } kib_fmr_poolset_t;
320
321 #ifndef HAVE_IB_RDMA_WR
322 struct ib_rdma_wr {
323         struct ib_send_wr wr;
324 };
325 #endif
326
327 struct kib_fast_reg_descriptor { /* For fast registration */
328         struct list_head                 frd_list;
329         struct ib_rdma_wr                frd_inv_wr;
330 #ifdef HAVE_IB_MAP_MR_SG
331         struct ib_reg_wr                 frd_fastreg_wr;
332 #else
333         struct ib_rdma_wr                frd_fastreg_wr;
334         struct ib_fast_reg_page_list    *frd_frpl;
335 #endif
336         struct ib_mr                    *frd_mr;
337         bool                             frd_valid;
338 };
339
340 typedef struct
341 {
342         struct list_head        fpo_list;       /* chain on pool list */
343         struct kib_hca_dev     *fpo_hdev;       /* device for this pool */
344         kib_fmr_poolset_t      *fpo_owner;      /* owner of this pool */
345         union {
346                 struct {
347                         struct ib_fmr_pool *fpo_fmr_pool; /* IB FMR pool */
348                 } fmr;
349                 struct { /* For fast registration */
350                         struct list_head  fpo_pool_list;
351                         int               fpo_pool_size;
352                 } fast_reg;
353         };
354         cfs_time_t              fpo_deadline;   /* deadline of this pool */
355         int                     fpo_failed;     /* fmr pool is failed */
356         int                     fpo_map_count;  /* # of mapped FMR */
357         int                     fpo_is_fmr;
358 } kib_fmr_pool_t;
359
360 typedef struct {
361         kib_fmr_pool_t                  *fmr_pool;      /* pool of FMR */
362         struct ib_pool_fmr              *fmr_pfmr;      /* IB pool fmr */
363         struct kib_fast_reg_descriptor  *fmr_frd;
364         u32                              fmr_key;
365 } kib_fmr_t;
366
367 typedef struct kib_net
368 {
369         /* chain on kib_dev_t::ibd_nets */
370         struct list_head        ibn_list;
371         __u64                   ibn_incarnation;/* my epoch */
372         int                     ibn_init;       /* initialisation state */
373         int                     ibn_shutdown;   /* shutting down? */
374
375         atomic_t                ibn_npeers;     /* # peers extant */
376         atomic_t                ibn_nconns;     /* # connections extant */
377
378         kib_tx_poolset_t        **ibn_tx_ps;    /* tx pool-set */
379         kib_fmr_poolset_t       **ibn_fmr_ps;   /* fmr pool-set */
380
381         kib_dev_t               *ibn_dev;       /* underlying IB device */
382 } kib_net_t;
383
384 #define KIB_THREAD_SHIFT                16
385 #define KIB_THREAD_ID(cpt, tid)         ((cpt) << KIB_THREAD_SHIFT | (tid))
386 #define KIB_THREAD_CPT(id)              ((id) >> KIB_THREAD_SHIFT)
387 #define KIB_THREAD_TID(id)              ((id) & ((1UL << KIB_THREAD_SHIFT) - 1))
388
389 struct kib_sched_info {
390         /* serialise */
391         spinlock_t              ibs_lock;
392         /* schedulers sleep here */
393         wait_queue_head_t       ibs_waitq;
394         /* conns to check for rx completions */
395         struct list_head        ibs_conns;
396         /* number of scheduler threads */
397         int                     ibs_nthreads;
398         /* max allowed scheduler threads */
399         int                     ibs_nthreads_max;
400         int                     ibs_cpt;        /* CPT id */
401 };
402
403 typedef struct
404 {
405         int                     kib_init;       /* initialisation state */
406         int                     kib_shutdown;   /* shut down? */
407         struct list_head        kib_devs;       /* IB devices extant */
408         /* list head of failed devices */
409         struct list_head        kib_failed_devs;
410         /* schedulers sleep here */
411         wait_queue_head_t       kib_failover_waitq;
412         atomic_t                kib_nthreads;   /* # live threads */
413         /* stabilize net/dev/peer_ni/conn ops */
414         rwlock_t                kib_global_lock;
415         /* hash table of all my known peers */
416         struct list_head        *kib_peers;
417         /* size of kib_peers */
418         int                     kib_peer_hash_size;
419         /* the connd task (serialisation assertions) */
420         void                    *kib_connd;
421         /* connections to setup/teardown */
422         struct list_head        kib_connd_conns;
423         /* connections with zero refcount */
424         struct list_head        kib_connd_zombies;
425         /* connections to reconnect */
426         struct list_head        kib_reconn_list;
427         /* peers wait for reconnection */
428         struct list_head        kib_reconn_wait;
429         /*
430          * The second that peers are pulled out from \a kib_reconn_wait
431          * for reconnection.
432          */
433         time64_t                kib_reconn_sec;
434         /* connection daemon sleeps here */
435         wait_queue_head_t       kib_connd_waitq;
436         spinlock_t              kib_connd_lock; /* serialise */
437         struct ib_qp_attr       kib_error_qpa;  /* QP->ERROR */
438         /* percpt data for schedulers */
439         struct kib_sched_info   **kib_scheds;
440 } kib_data_t;
441
442 #define IBLND_INIT_NOTHING         0
443 #define IBLND_INIT_DATA            1
444 #define IBLND_INIT_ALL             2
445
446 /************************************************************************
447  * IB Wire message format.
448  * These are sent in sender's byte order (i.e. receiver flips).
449  */
450
451 typedef struct kib_connparams
452 {
453         __u16             ibcp_queue_depth;
454         __u16             ibcp_max_frags;
455         __u32             ibcp_max_msg_size;
456 } WIRE_ATTR kib_connparams_t;
457
458 typedef struct
459 {
460         struct lnet_hdr         ibim_hdr;       /* portals header */
461         char                    ibim_payload[0];/* piggy-backed payload */
462 } WIRE_ATTR kib_immediate_msg_t;
463
464 typedef struct
465 {
466         __u32             rf_nob;               /* # bytes this frag */
467         __u64             rf_addr;              /* CAVEAT EMPTOR: misaligned!! */
468 } WIRE_ATTR kib_rdma_frag_t;
469
470 typedef struct
471 {
472         __u32             rd_key;               /* local/remote key */
473         __u32             rd_nfrags;            /* # fragments */
474         kib_rdma_frag_t   rd_frags[0];          /* buffer frags */
475 } WIRE_ATTR kib_rdma_desc_t;
476
477 typedef struct
478 {
479         struct lnet_hdr         ibprm_hdr;      /* portals header */
480         __u64                   ibprm_cookie;   /* opaque completion cookie */
481 } WIRE_ATTR kib_putreq_msg_t;
482
483 typedef struct
484 {
485         __u64             ibpam_src_cookie;     /* reflected completion cookie */
486         __u64             ibpam_dst_cookie;     /* opaque completion cookie */
487         kib_rdma_desc_t   ibpam_rd;             /* sender's sink buffer */
488 } WIRE_ATTR kib_putack_msg_t;
489
490 typedef struct
491 {
492         struct lnet_hdr         ibgm_hdr;       /* portals header */
493         __u64                   ibgm_cookie;    /* opaque completion cookie */
494         kib_rdma_desc_t         ibgm_rd;        /* rdma descriptor */
495 } WIRE_ATTR kib_get_msg_t;
496
497 typedef struct
498 {
499         __u64             ibcm_cookie;          /* opaque completion cookie */
500         __s32             ibcm_status;          /* < 0 failure: >= 0 length */
501 } WIRE_ATTR kib_completion_msg_t;
502
503 typedef struct
504 {
505         /* First 2 fields fixed FOR ALL TIME */
506         __u32             ibm_magic;            /* I'm an ibnal message */
507         __u16             ibm_version;          /* this is my version number */
508
509         __u8              ibm_type;             /* msg type */
510         __u8              ibm_credits;          /* returned credits */
511         __u32             ibm_nob;              /* # bytes in whole message */
512         __u32             ibm_cksum;            /* checksum (0 == no checksum) */
513         __u64             ibm_srcnid;           /* sender's NID */
514         __u64             ibm_srcstamp;         /* sender's incarnation */
515         __u64             ibm_dstnid;           /* destination's NID */
516         __u64             ibm_dststamp;         /* destination's incarnation */
517
518         union {
519                 kib_connparams_t      connparams;
520                 kib_immediate_msg_t   immediate;
521                 kib_putreq_msg_t      putreq;
522                 kib_putack_msg_t      putack;
523                 kib_get_msg_t         get;
524                 kib_completion_msg_t  completion;
525         } WIRE_ATTR ibm_u;
526 } WIRE_ATTR kib_msg_t;
527
528 #define IBLND_MSG_MAGIC LNET_PROTO_IB_MAGIC     /* unique magic */
529
530 #define IBLND_MSG_VERSION_1         0x11
531 #define IBLND_MSG_VERSION_2         0x12
532 #define IBLND_MSG_VERSION           IBLND_MSG_VERSION_2
533
534 #define IBLND_MSG_CONNREQ           0xc0        /* connection request */
535 #define IBLND_MSG_CONNACK           0xc1        /* connection acknowledge */
536 #define IBLND_MSG_NOOP              0xd0        /* nothing (just credits) */
537 #define IBLND_MSG_IMMEDIATE         0xd1        /* immediate */
538 #define IBLND_MSG_PUT_REQ           0xd2        /* putreq (src->sink) */
539 #define IBLND_MSG_PUT_NAK           0xd3        /* completion (sink->src) */
540 #define IBLND_MSG_PUT_ACK           0xd4        /* putack (sink->src) */
541 #define IBLND_MSG_PUT_DONE          0xd5        /* completion (src->sink) */
542 #define IBLND_MSG_GET_REQ           0xd6        /* getreq (sink->src) */
543 #define IBLND_MSG_GET_DONE          0xd7        /* completion (src->sink: all OK) */
544
545 typedef struct {
546         __u32            ibr_magic;             /* sender's magic */
547         __u16            ibr_version;           /* sender's version */
548         __u8             ibr_why;               /* reject reason */
549         __u8             ibr_padding;           /* padding */
550         __u64            ibr_incarnation;       /* incarnation of peer_ni */
551         kib_connparams_t ibr_cp;                /* connection parameters */
552 } WIRE_ATTR kib_rej_t;
553
554 /* connection rejection reasons */
555 #define IBLND_REJECT_CONN_RACE       1          /* You lost connection race */
556 #define IBLND_REJECT_NO_RESOURCES    2          /* Out of memory/conns etc */
557 #define IBLND_REJECT_FATAL           3          /* Anything else */
558
559 #define IBLND_REJECT_CONN_UNCOMPAT   4          /* incompatible version peer_ni */
560 #define IBLND_REJECT_CONN_STALE      5          /* stale peer_ni */
561
562 /* peer_ni's rdma frags doesn't match mine */
563 #define IBLND_REJECT_RDMA_FRAGS      6
564 /* peer_ni's msg queue size doesn't match mine */
565 #define IBLND_REJECT_MSG_QUEUE_SIZE  7
566 #define IBLND_REJECT_INVALID_SRV_ID  8
567
568 /***********************************************************************/
569
570 typedef struct kib_rx                           /* receive message */
571 {
572         /* queue for attention */
573         struct list_head        rx_list;
574         /* owning conn */
575         struct kib_conn        *rx_conn;
576         /* # bytes received (-1 while posted) */
577         int                     rx_nob;
578         /* completion status */
579         enum ib_wc_status       rx_status;
580         /* message buffer (host vaddr) */
581         kib_msg_t              *rx_msg;
582         /* message buffer (I/O addr) */
583         __u64                   rx_msgaddr;
584         /* for dma_unmap_single() */
585         DECLARE_PCI_UNMAP_ADDR(rx_msgunmap);
586         /* receive work item... */
587         struct ib_recv_wr       rx_wrq;
588         /* ...and its memory */
589         struct ib_sge           rx_sge;
590 } kib_rx_t;
591
592 #define IBLND_POSTRX_DONT_POST    0             /* don't post */
593 #define IBLND_POSTRX_NO_CREDIT    1             /* post: no credits */
594 #define IBLND_POSTRX_PEER_CREDIT  2             /* post: give peer_ni back 1 credit */
595 #define IBLND_POSTRX_RSRVD_CREDIT 3             /* post: give myself back 1 reserved credit */
596
597 typedef struct kib_tx                           /* transmit message */
598 {
599         /* queue on idle_txs ibc_tx_queue etc. */
600         struct list_head        tx_list;
601         /* pool I'm from */
602         kib_tx_pool_t           *tx_pool;
603         /* owning conn */
604         struct kib_conn         *tx_conn;
605         /* # tx callbacks outstanding */
606         short                   tx_sending;
607         /* queued for sending */
608         short                   tx_queued;
609         /* waiting for peer_ni */
610         short                   tx_waiting;
611         /* LNET completion status */
612         int                     tx_status;
613         /* completion deadline */
614         unsigned long           tx_deadline;
615         /* completion cookie */
616         __u64                   tx_cookie;
617         /* lnet msgs to finalize on completion */
618         struct lnet_msg         *tx_lntmsg[2];
619         /* message buffer (host vaddr) */
620         kib_msg_t               *tx_msg;
621         /* message buffer (I/O addr) */
622         __u64                   tx_msgaddr;
623         /* for dma_unmap_single() */
624         DECLARE_PCI_UNMAP_ADDR(tx_msgunmap);
625         /** sge for tx_msgaddr */
626         struct ib_sge           tx_msgsge;
627         /* # send work items */
628         int                     tx_nwrq;
629         /* # used scatter/gather elements */
630         int                     tx_nsge;
631         /* send work items... */
632         struct ib_rdma_wr       *tx_wrq;
633         /* ...and their memory */
634         struct ib_sge           *tx_sge;
635         /* rdma descriptor */
636         kib_rdma_desc_t         *tx_rd;
637         /* # entries in... */
638         int                     tx_nfrags;
639         /* dma_map_sg descriptor */
640         struct scatterlist      *tx_frags;
641         /* rdma phys page addrs */
642         __u64                   *tx_pages;
643         /* FMR */
644         kib_fmr_t               fmr;
645                                 /* dma direction */
646         int                     tx_dmadir;
647 } kib_tx_t;
648
649 typedef struct kib_connvars
650 {
651         /* connection-in-progress variables */
652         kib_msg_t                 cv_msg;
653 } kib_connvars_t;
654
655 typedef struct kib_conn
656 {
657         /* scheduler information */
658         struct kib_sched_info   *ibc_sched;
659         /* owning peer_ni */
660         struct kib_peer         *ibc_peer;
661         /* HCA bound on */
662         kib_hca_dev_t           *ibc_hdev;
663         /* stash on peer_ni's conn list */
664         struct list_head        ibc_list;
665         /* schedule for attention */
666         struct list_head        ibc_sched_list;
667         /* version of connection */
668         __u16                   ibc_version;
669         /* reconnect later */
670         __u16                   ibc_reconnect:1;
671         /* which instance of the peer */
672         __u64                   ibc_incarnation;
673         /* # users */
674         atomic_t                ibc_refcount;
675         /* what's happening */
676         int                     ibc_state;
677         /* # uncompleted sends */
678         int                     ibc_nsends_posted;
679         /* # uncompleted NOOPs */
680         int                     ibc_noops_posted;
681         /* # credits I have */
682         int                     ibc_credits;
683         /* # credits to return */
684         int                     ibc_outstanding_credits;
685         /* # ACK/DONE msg credits */
686         int                     ibc_reserved_credits;
687         /* set on comms error */
688         int                     ibc_comms_error;
689         /* connections queue depth */
690         __u16                   ibc_queue_depth;
691         /* connections max frags */
692         __u16                   ibc_max_frags;
693         /* receive buffers owned */
694         unsigned int            ibc_nrx:16;
695         /* scheduled for attention */
696         unsigned int            ibc_scheduled:1;
697         /* CQ callback fired */
698         unsigned int            ibc_ready:1;
699         /* time of last send */
700         unsigned long           ibc_last_send;
701         /** link chain for kiblnd_check_conns only */
702         struct list_head        ibc_connd_list;
703         /** rxs completed before ESTABLISHED */
704         struct list_head        ibc_early_rxs;
705         /** IBLND_MSG_NOOPs for IBLND_MSG_VERSION_1 */
706         struct list_head        ibc_tx_noops;
707         /* sends that need a credit */
708         struct list_head        ibc_tx_queue;
709         /* sends that don't need a credit */
710         struct list_head        ibc_tx_queue_nocred;
711         /* sends that need to reserve an ACK/DONE msg */
712         struct list_head        ibc_tx_queue_rsrvd;
713         /* active tx awaiting completion */
714         struct list_head        ibc_active_txs;
715         /* serialise */
716         spinlock_t              ibc_lock;
717         /* the rx descs */
718         kib_rx_t                *ibc_rxs;
719         /* premapped rx msg pages */
720         kib_pages_t             *ibc_rx_pages;
721
722         /* CM id */
723         struct rdma_cm_id       *ibc_cmid;
724         /* completion queue */
725         struct ib_cq            *ibc_cq;
726
727         /* in-progress connection state */
728         kib_connvars_t          *ibc_connvars;
729 } kib_conn_t;
730
731 #define IBLND_CONN_INIT               0         /* being initialised */
732 #define IBLND_CONN_ACTIVE_CONNECT     1         /* active sending req */
733 #define IBLND_CONN_PASSIVE_WAIT       2         /* passive waiting for rtu */
734 #define IBLND_CONN_ESTABLISHED        3         /* connection established */
735 #define IBLND_CONN_CLOSING            4         /* being closed */
736 #define IBLND_CONN_DISCONNECTED       5         /* disconnected */
737
738 typedef struct kib_peer
739 {
740         /* stash on global peer_ni list */
741         struct list_head        ibp_list;
742         /* who's on the other end(s) */
743         lnet_nid_t              ibp_nid;
744         /* LNet interface */
745         struct lnet_ni          *ibp_ni;
746         /* all active connections */
747         struct list_head        ibp_conns;
748         /* next connection to send on for round robin */
749         struct kib_conn         *ibp_next_conn;
750         /* msgs waiting for a conn */
751         struct list_head        ibp_tx_queue;
752         /* incarnation of peer_ni */
753         __u64                   ibp_incarnation;
754         /* when (in jiffies) I was last alive */
755         cfs_time_t              ibp_last_alive;
756         /* # users */
757         atomic_t                ibp_refcount;
758         /* version of peer_ni */
759         __u16                   ibp_version;
760         /* current passive connection attempts */
761         unsigned short          ibp_accepting;
762         /* current active connection attempts */
763         unsigned short          ibp_connecting;
764         /* reconnect this peer_ni later */
765         unsigned char           ibp_reconnecting;
766         /* counter of how many times we triggered a conn race */
767         unsigned char           ibp_races;
768         /* # consecutive reconnection attempts to this peer */
769         unsigned int            ibp_reconnected;
770         /* errno on closing this peer_ni */
771         int                     ibp_error;
772         /* max map_on_demand */
773         __u16                   ibp_max_frags;
774         /* max_peer_credits */
775         __u16                   ibp_queue_depth;
776 } kib_peer_ni_t;
777
778 #ifndef HAVE_IB_INC_RKEY
779 /**
780  * ib_inc_rkey - increments the key portion of the given rkey. Can be used
781  * for calculating a new rkey for type 2 memory windows.
782  * @rkey - the rkey to increment.
783  */
784 static inline u32 ib_inc_rkey(u32 rkey)
785 {
786         const u32 mask = 0x000000ff;
787         return ((rkey + 1) & mask) | (rkey & ~mask);
788 }
789 #endif
790
791 extern kib_data_t      kiblnd_data;
792
793 extern void kiblnd_hdev_destroy(kib_hca_dev_t *hdev);
794
795 int kiblnd_msg_queue_size(int version, struct lnet_ni *ni);
796
797 /* max # of fragments configured by user */
798 static inline int
799 kiblnd_cfg_rdma_frags(struct lnet_ni *ni)
800 {
801         struct lnet_ioctl_config_o2iblnd_tunables *tunables;
802         int mod;
803
804         tunables = &ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib;
805         mod = tunables->lnd_map_on_demand;
806         return mod != 0 ? mod : IBLND_MAX_RDMA_FRAGS;
807 }
808
809 static inline int
810 kiblnd_rdma_frags(int version, struct lnet_ni *ni)
811 {
812         return version == IBLND_MSG_VERSION_1 ?
813           IBLND_MAX_RDMA_FRAGS :
814           kiblnd_cfg_rdma_frags(ni);
815 }
816
817 static inline int
818 kiblnd_concurrent_sends(int version, struct lnet_ni *ni)
819 {
820         struct lnet_ioctl_config_o2iblnd_tunables *tunables;
821         int concurrent_sends;
822
823         tunables = &ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib;
824         concurrent_sends = tunables->lnd_concurrent_sends;
825
826         if (version == IBLND_MSG_VERSION_1) {
827                 if (concurrent_sends > IBLND_MSG_QUEUE_SIZE_V1 * 2)
828                         return IBLND_MSG_QUEUE_SIZE_V1 * 2;
829
830                 if (concurrent_sends < IBLND_MSG_QUEUE_SIZE_V1 / 2)
831                         return IBLND_MSG_QUEUE_SIZE_V1 / 2;
832         }
833
834         return concurrent_sends;
835 }
836
837 static inline void
838 kiblnd_hdev_addref_locked(kib_hca_dev_t *hdev)
839 {
840         LASSERT(atomic_read(&hdev->ibh_ref) > 0);
841         atomic_inc(&hdev->ibh_ref);
842 }
843
844 static inline void
845 kiblnd_hdev_decref(kib_hca_dev_t *hdev)
846 {
847         LASSERT(atomic_read(&hdev->ibh_ref) > 0);
848         if (atomic_dec_and_test(&hdev->ibh_ref))
849                 kiblnd_hdev_destroy(hdev);
850 }
851
852 static inline int
853 kiblnd_dev_can_failover(kib_dev_t *dev)
854 {
855         if (!list_empty(&dev->ibd_fail_list)) /* already scheduled */
856                 return 0;
857
858         if (*kiblnd_tunables.kib_dev_failover == 0) /* disabled */
859                 return 0;
860
861         if (*kiblnd_tunables.kib_dev_failover > 1) /* force failover */
862                 return 1;
863
864         return dev->ibd_can_failover;
865 }
866
867 #define kiblnd_conn_addref(conn)                                \
868 do {                                                            \
869         CDEBUG(D_NET, "conn[%p] (%d)++\n",                      \
870                (conn), atomic_read(&(conn)->ibc_refcount)); \
871         atomic_inc(&(conn)->ibc_refcount);                  \
872 } while (0)
873
874 #define kiblnd_conn_decref(conn)                                        \
875 do {                                                                    \
876         unsigned long flags;                                            \
877                                                                         \
878         CDEBUG(D_NET, "conn[%p] (%d)--\n",                              \
879                (conn), atomic_read(&(conn)->ibc_refcount));             \
880         LASSERT_ATOMIC_POS(&(conn)->ibc_refcount);                      \
881         if (atomic_dec_and_test(&(conn)->ibc_refcount)) {               \
882                 spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags);  \
883                 list_add_tail(&(conn)->ibc_list,                        \
884                                   &kiblnd_data.kib_connd_zombies);      \
885                 wake_up(&kiblnd_data.kib_connd_waitq);          \
886                 spin_unlock_irqrestore(&kiblnd_data.kib_connd_lock, flags);\
887         }                                                               \
888 } while (0)
889
890 #define kiblnd_peer_addref(peer_ni)                                \
891 do {                                                            \
892         CDEBUG(D_NET, "peer_ni[%p] -> %s (%d)++\n",                \
893                (peer_ni), libcfs_nid2str((peer_ni)->ibp_nid),         \
894                atomic_read (&(peer_ni)->ibp_refcount));         \
895         atomic_inc(&(peer_ni)->ibp_refcount);                   \
896 } while (0)
897
898 #define kiblnd_peer_decref(peer_ni)                                \
899 do {                                                            \
900         CDEBUG(D_NET, "peer_ni[%p] -> %s (%d)--\n",                \
901                (peer_ni), libcfs_nid2str((peer_ni)->ibp_nid),         \
902                atomic_read (&(peer_ni)->ibp_refcount));         \
903         LASSERT_ATOMIC_POS(&(peer_ni)->ibp_refcount);              \
904         if (atomic_dec_and_test(&(peer_ni)->ibp_refcount))      \
905                 kiblnd_destroy_peer(peer_ni);                      \
906 } while (0)
907
908 static inline bool
909 kiblnd_peer_connecting(kib_peer_ni_t *peer_ni)
910 {
911         return peer_ni->ibp_connecting != 0 ||
912                peer_ni->ibp_reconnecting != 0 ||
913                peer_ni->ibp_accepting != 0;
914 }
915
916 static inline bool
917 kiblnd_peer_idle(kib_peer_ni_t *peer_ni)
918 {
919         return !kiblnd_peer_connecting(peer_ni) && list_empty(&peer_ni->ibp_conns);
920 }
921
922 static inline struct list_head *
923 kiblnd_nid2peerlist (lnet_nid_t nid)
924 {
925         unsigned int hash =
926                 ((unsigned int)nid) % kiblnd_data.kib_peer_hash_size;
927
928         return &kiblnd_data.kib_peers[hash];
929 }
930
931 static inline int
932 kiblnd_peer_active (kib_peer_ni_t *peer_ni)
933 {
934         /* Am I in the peer_ni hash table? */
935         return !list_empty(&peer_ni->ibp_list);
936 }
937
938 static inline struct kib_conn *
939 kiblnd_get_conn_locked (kib_peer_ni_t *peer_ni)
940 {
941         struct list_head *next;
942
943         LASSERT(!list_empty(&peer_ni->ibp_conns));
944
945         /* Advance to next connection, be sure to skip the head node */
946         if (!peer_ni->ibp_next_conn ||
947             peer_ni->ibp_next_conn->ibc_list.next == &peer_ni->ibp_conns)
948                 next = peer_ni->ibp_conns.next;
949         else
950                 next = peer_ni->ibp_next_conn->ibc_list.next;
951         peer_ni->ibp_next_conn = list_entry(next, struct kib_conn, ibc_list);
952
953         return peer_ni->ibp_next_conn;
954 }
955
956 static inline int
957 kiblnd_send_keepalive(kib_conn_t *conn)
958 {
959         return (*kiblnd_tunables.kib_keepalive > 0) &&
960                 cfs_time_after(jiffies, conn->ibc_last_send +
961                                msecs_to_jiffies(*kiblnd_tunables.kib_keepalive *
962                                                 MSEC_PER_SEC));
963 }
964
965 static inline int
966 kiblnd_need_noop(kib_conn_t *conn)
967 {
968         struct lnet_ni *ni = conn->ibc_peer->ibp_ni;
969         struct lnet_ioctl_config_o2iblnd_tunables *tunables;
970
971         LASSERT(conn->ibc_state >= IBLND_CONN_ESTABLISHED);
972         tunables = &ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib;
973
974         if (conn->ibc_outstanding_credits <
975             IBLND_CREDITS_HIGHWATER(tunables, conn->ibc_version) &&
976             !kiblnd_send_keepalive(conn))
977                 return 0; /* No need to send NOOP */
978
979         if (IBLND_OOB_CAPABLE(conn->ibc_version)) {
980                 if (!list_empty(&conn->ibc_tx_queue_nocred))
981                         return 0; /* NOOP can be piggybacked */
982
983                 /* No tx to piggyback NOOP onto or no credit to send a tx */
984                 return (list_empty(&conn->ibc_tx_queue) ||
985                         conn->ibc_credits == 0);
986         }
987
988         if (!list_empty(&conn->ibc_tx_noops) || /* NOOP already queued */
989             !list_empty(&conn->ibc_tx_queue_nocred) || /* piggyback NOOP */
990             conn->ibc_credits == 0)                    /* no credit */
991                 return 0;
992
993         if (conn->ibc_credits == 1 &&      /* last credit reserved for */
994             conn->ibc_outstanding_credits == 0) /* giving back credits */
995                 return 0;
996
997         /* No tx to piggyback NOOP onto or no credit to send a tx */
998         return (list_empty(&conn->ibc_tx_queue) || conn->ibc_credits == 1);
999 }
1000
1001 static inline void
1002 kiblnd_abort_receives(kib_conn_t *conn)
1003 {
1004         ib_modify_qp(conn->ibc_cmid->qp,
1005                      &kiblnd_data.kib_error_qpa, IB_QP_STATE);
1006 }
1007
1008 static inline const char *
1009 kiblnd_queue2str(kib_conn_t *conn, struct list_head *q)
1010 {
1011         if (q == &conn->ibc_tx_queue)
1012                 return "tx_queue";
1013
1014         if (q == &conn->ibc_tx_queue_rsrvd)
1015                 return "tx_queue_rsrvd";
1016
1017         if (q == &conn->ibc_tx_queue_nocred)
1018                 return "tx_queue_nocred";
1019
1020         if (q == &conn->ibc_active_txs)
1021                 return "active_txs";
1022
1023         LBUG();
1024         return NULL;
1025 }
1026
1027 /* CAVEAT EMPTOR: We rely on descriptor alignment to allow us to use the
1028  * lowest bits of the work request id to stash the work item type. */
1029
1030 #define IBLND_WID_INVAL 0
1031 #define IBLND_WID_TX    1
1032 #define IBLND_WID_RX    2
1033 #define IBLND_WID_RDMA  3
1034 #define IBLND_WID_MR    4
1035 #define IBLND_WID_MASK  7UL
1036
1037 static inline __u64
1038 kiblnd_ptr2wreqid (void *ptr, int type)
1039 {
1040         unsigned long lptr = (unsigned long)ptr;
1041
1042         LASSERT ((lptr & IBLND_WID_MASK) == 0);
1043         LASSERT ((type & ~IBLND_WID_MASK) == 0);
1044         return (__u64)(lptr | type);
1045 }
1046
1047 static inline void *
1048 kiblnd_wreqid2ptr (__u64 wreqid)
1049 {
1050         return (void *)(((unsigned long)wreqid) & ~IBLND_WID_MASK);
1051 }
1052
1053 static inline int
1054 kiblnd_wreqid2type (__u64 wreqid)
1055 {
1056         return (wreqid & IBLND_WID_MASK);
1057 }
1058
1059 static inline void
1060 kiblnd_set_conn_state (kib_conn_t *conn, int state)
1061 {
1062         conn->ibc_state = state;
1063         smp_mb();
1064 }
1065
1066 static inline void
1067 kiblnd_init_msg (kib_msg_t *msg, int type, int body_nob)
1068 {
1069         msg->ibm_type = type;
1070         msg->ibm_nob  = offsetof(kib_msg_t, ibm_u) + body_nob;
1071 }
1072
1073 static inline int
1074 kiblnd_rd_size (kib_rdma_desc_t *rd)
1075 {
1076         int   i;
1077         int   size;
1078
1079         for (i = size = 0; i < rd->rd_nfrags; i++)
1080                 size += rd->rd_frags[i].rf_nob;
1081
1082         return size;
1083 }
1084
1085 static inline __u64
1086 kiblnd_rd_frag_addr(kib_rdma_desc_t *rd, int index)
1087 {
1088         return rd->rd_frags[index].rf_addr;
1089 }
1090
1091 static inline __u32
1092 kiblnd_rd_frag_size(kib_rdma_desc_t *rd, int index)
1093 {
1094         return rd->rd_frags[index].rf_nob;
1095 }
1096
1097 static inline __u32
1098 kiblnd_rd_frag_key(kib_rdma_desc_t *rd, int index)
1099 {
1100         return rd->rd_key;
1101 }
1102
1103 static inline int
1104 kiblnd_rd_consume_frag(kib_rdma_desc_t *rd, int index, __u32 nob)
1105 {
1106         if (nob < rd->rd_frags[index].rf_nob) {
1107                 rd->rd_frags[index].rf_addr += nob;
1108                 rd->rd_frags[index].rf_nob  -= nob;
1109         } else {
1110                 index ++;
1111         }
1112
1113         return index;
1114 }
1115
1116 static inline int
1117 kiblnd_rd_msg_size(kib_rdma_desc_t *rd, int msgtype, int n)
1118 {
1119         LASSERT (msgtype == IBLND_MSG_GET_REQ ||
1120                  msgtype == IBLND_MSG_PUT_ACK);
1121
1122         return msgtype == IBLND_MSG_GET_REQ ?
1123                offsetof(kib_get_msg_t, ibgm_rd.rd_frags[n]) :
1124                offsetof(kib_putack_msg_t, ibpam_rd.rd_frags[n]);
1125 }
1126
1127 static inline __u64
1128 kiblnd_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
1129 {
1130         return ib_dma_mapping_error(dev, dma_addr);
1131 }
1132
1133 static inline __u64 kiblnd_dma_map_single(struct ib_device *dev,
1134                                           void *msg, size_t size,
1135                                           enum dma_data_direction direction)
1136 {
1137         return ib_dma_map_single(dev, msg, size, direction);
1138 }
1139
1140 static inline void kiblnd_dma_unmap_single(struct ib_device *dev,
1141                                            __u64 addr, size_t size,
1142                                           enum dma_data_direction direction)
1143 {
1144         ib_dma_unmap_single(dev, addr, size, direction);
1145 }
1146
1147 #define KIBLND_UNMAP_ADDR_SET(p, m, a)  do {} while (0)
1148 #define KIBLND_UNMAP_ADDR(p, m, a)      (a)
1149
1150 static inline int kiblnd_dma_map_sg(struct ib_device *dev,
1151                                     struct scatterlist *sg, int nents,
1152                                     enum dma_data_direction direction)
1153 {
1154         return ib_dma_map_sg(dev, sg, nents, direction);
1155 }
1156
1157 static inline void kiblnd_dma_unmap_sg(struct ib_device *dev,
1158                                        struct scatterlist *sg, int nents,
1159                                        enum dma_data_direction direction)
1160 {
1161         ib_dma_unmap_sg(dev, sg, nents, direction);
1162 }
1163
1164 static inline __u64 kiblnd_sg_dma_address(struct ib_device *dev,
1165                                           struct scatterlist *sg)
1166 {
1167         return ib_sg_dma_address(dev, sg);
1168 }
1169
1170 static inline unsigned int kiblnd_sg_dma_len(struct ib_device *dev,
1171                                              struct scatterlist *sg)
1172 {
1173         return ib_sg_dma_len(dev, sg);
1174 }
1175
1176 /* XXX We use KIBLND_CONN_PARAM(e) as writable buffer, it's not strictly
1177  * right because OFED1.2 defines it as const, to use it we have to add
1178  * (void *) cast to overcome "const" */
1179
1180 #define KIBLND_CONN_PARAM(e)            ((e)->param.conn.private_data)
1181 #define KIBLND_CONN_PARAM_LEN(e)        ((e)->param.conn.private_data_len)
1182
1183 #ifdef HAVE_IB_GET_DMA_MR
1184 struct ib_mr *kiblnd_find_rd_dma_mr(struct lnet_ni *ni, kib_rdma_desc_t *rd,
1185                                     int negotiated_nfrags);
1186 #endif
1187 void kiblnd_map_rx_descs(kib_conn_t *conn);
1188 void kiblnd_unmap_rx_descs(kib_conn_t *conn);
1189 void kiblnd_pool_free_node(kib_pool_t *pool, struct list_head *node);
1190 struct list_head *kiblnd_pool_alloc_node(kib_poolset_t *ps);
1191
1192 int  kiblnd_fmr_pool_map(kib_fmr_poolset_t *fps, kib_tx_t *tx,
1193                          kib_rdma_desc_t *rd, __u32 nob, __u64 iov,
1194                          kib_fmr_t *fmr, bool *is_fastreg);
1195 void kiblnd_fmr_pool_unmap(kib_fmr_t *fmr, int status);
1196
1197 int  kiblnd_tunables_setup(struct lnet_ni *ni);
1198 int  kiblnd_tunables_init(void);
1199
1200 int  kiblnd_connd (void *arg);
1201 int  kiblnd_scheduler(void *arg);
1202 int  kiblnd_thread_start(int (*fn)(void *arg), void *arg, char *name);
1203 int  kiblnd_failover_thread (void *arg);
1204
1205 int  kiblnd_alloc_pages(kib_pages_t **pp, int cpt, int npages);
1206
1207 int  kiblnd_cm_callback(struct rdma_cm_id *cmid,
1208                         struct rdma_cm_event *event);
1209 int  kiblnd_translate_mtu(int value);
1210
1211 int  kiblnd_dev_failover(kib_dev_t *dev);
1212 int kiblnd_create_peer(struct lnet_ni *ni, kib_peer_ni_t **peerp,
1213                        lnet_nid_t nid);
1214 void kiblnd_destroy_peer (kib_peer_ni_t *peer);
1215 bool kiblnd_reconnect_peer(kib_peer_ni_t *peer);
1216 void kiblnd_destroy_dev (kib_dev_t *dev);
1217 void kiblnd_unlink_peer_locked (kib_peer_ni_t *peer_ni);
1218 kib_peer_ni_t *kiblnd_find_peer_locked(struct lnet_ni *ni, lnet_nid_t nid);
1219 int  kiblnd_close_stale_conns_locked (kib_peer_ni_t *peer_ni,
1220                                       int version, __u64 incarnation);
1221 int  kiblnd_close_peer_conns_locked (kib_peer_ni_t *peer_ni, int why);
1222
1223 kib_conn_t *kiblnd_create_conn(kib_peer_ni_t *peer_ni, struct rdma_cm_id *cmid,
1224                                int state, int version);
1225 void kiblnd_destroy_conn(kib_conn_t *conn, bool free_conn);
1226 void kiblnd_close_conn (kib_conn_t *conn, int error);
1227 void kiblnd_close_conn_locked (kib_conn_t *conn, int error);
1228
1229 void kiblnd_launch_tx(struct lnet_ni *ni, kib_tx_t *tx, lnet_nid_t nid);
1230 void kiblnd_txlist_done(struct list_head *txlist, int status);
1231
1232 void kiblnd_qp_event(struct ib_event *event, void *arg);
1233 void kiblnd_cq_event(struct ib_event *event, void *arg);
1234 void kiblnd_cq_completion(struct ib_cq *cq, void *arg);
1235
1236 void kiblnd_pack_msg(struct lnet_ni *ni, kib_msg_t *msg, int version,
1237                      int credits, lnet_nid_t dstnid, __u64 dststamp);
1238 int  kiblnd_unpack_msg(kib_msg_t *msg, int nob);
1239 int  kiblnd_post_rx (kib_rx_t *rx, int credit);
1240
1241 int  kiblnd_send(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg);
1242 int kiblnd_recv(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg,
1243                 int delayed, unsigned int niov, struct kvec *iov,
1244                 lnet_kiov_t *kiov, unsigned int offset, unsigned int mlen,
1245                 unsigned int rlen);
1246