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