Whamcloud - gitweb
LU-10308 misc: update Intel copyright messages for 2017
[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, 2017, 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
168 /* 2 = LNet msg + Transfer chain */
169 #define IBLND_CQ_ENTRIES(c)     \
170         (IBLND_RECV_WRS(c) + 2 * c->ibc_queue_depth)
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         bool                    fpo_is_fmr; /* True if FMR pools allocated */
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         /* gaps in fragments */
644         bool                    tx_gaps;
645         /* FMR */
646         kib_fmr_t               tx_fmr;
647                                 /* dma direction */
648         int                     tx_dmadir;
649 } kib_tx_t;
650
651 typedef struct kib_connvars
652 {
653         /* connection-in-progress variables */
654         kib_msg_t                 cv_msg;
655 } kib_connvars_t;
656
657 typedef struct kib_conn
658 {
659         /* scheduler information */
660         struct kib_sched_info   *ibc_sched;
661         /* owning peer_ni */
662         struct kib_peer         *ibc_peer;
663         /* HCA bound on */
664         kib_hca_dev_t           *ibc_hdev;
665         /* stash on peer_ni's conn list */
666         struct list_head        ibc_list;
667         /* schedule for attention */
668         struct list_head        ibc_sched_list;
669         /* version of connection */
670         __u16                   ibc_version;
671         /* reconnect later */
672         __u16                   ibc_reconnect:1;
673         /* which instance of the peer */
674         __u64                   ibc_incarnation;
675         /* # users */
676         atomic_t                ibc_refcount;
677         /* what's happening */
678         int                     ibc_state;
679         /* # uncompleted sends */
680         int                     ibc_nsends_posted;
681         /* # uncompleted NOOPs */
682         int                     ibc_noops_posted;
683         /* # credits I have */
684         int                     ibc_credits;
685         /* # credits to return */
686         int                     ibc_outstanding_credits;
687         /* # ACK/DONE msg credits */
688         int                     ibc_reserved_credits;
689         /* set on comms error */
690         int                     ibc_comms_error;
691         /* connections queue depth */
692         __u16                   ibc_queue_depth;
693         /* connections max frags */
694         __u16                   ibc_max_frags;
695         /* receive buffers owned */
696         unsigned int            ibc_nrx:16;
697         /* scheduled for attention */
698         unsigned int            ibc_scheduled:1;
699         /* CQ callback fired */
700         unsigned int            ibc_ready:1;
701         /* time of last send */
702         unsigned long           ibc_last_send;
703         /** link chain for kiblnd_check_conns only */
704         struct list_head        ibc_connd_list;
705         /** rxs completed before ESTABLISHED */
706         struct list_head        ibc_early_rxs;
707         /** IBLND_MSG_NOOPs for IBLND_MSG_VERSION_1 */
708         struct list_head        ibc_tx_noops;
709         /* sends that need a credit */
710         struct list_head        ibc_tx_queue;
711         /* sends that don't need a credit */
712         struct list_head        ibc_tx_queue_nocred;
713         /* sends that need to reserve an ACK/DONE msg */
714         struct list_head        ibc_tx_queue_rsrvd;
715         /* active tx awaiting completion */
716         struct list_head        ibc_active_txs;
717         /* serialise */
718         spinlock_t              ibc_lock;
719         /* the rx descs */
720         kib_rx_t                *ibc_rxs;
721         /* premapped rx msg pages */
722         kib_pages_t             *ibc_rx_pages;
723
724         /* CM id */
725         struct rdma_cm_id       *ibc_cmid;
726         /* completion queue */
727         struct ib_cq            *ibc_cq;
728
729         /* in-progress connection state */
730         kib_connvars_t          *ibc_connvars;
731 } kib_conn_t;
732
733 #define IBLND_CONN_INIT               0         /* being initialised */
734 #define IBLND_CONN_ACTIVE_CONNECT     1         /* active sending req */
735 #define IBLND_CONN_PASSIVE_WAIT       2         /* passive waiting for rtu */
736 #define IBLND_CONN_ESTABLISHED        3         /* connection established */
737 #define IBLND_CONN_CLOSING            4         /* being closed */
738 #define IBLND_CONN_DISCONNECTED       5         /* disconnected */
739
740 typedef struct kib_peer
741 {
742         /* stash on global peer_ni list */
743         struct list_head        ibp_list;
744         /* who's on the other end(s) */
745         lnet_nid_t              ibp_nid;
746         /* LNet interface */
747         struct lnet_ni          *ibp_ni;
748         /* all active connections */
749         struct list_head        ibp_conns;
750         /* next connection to send on for round robin */
751         struct kib_conn         *ibp_next_conn;
752         /* msgs waiting for a conn */
753         struct list_head        ibp_tx_queue;
754         /* incarnation of peer_ni */
755         __u64                   ibp_incarnation;
756         /* when (in jiffies) I was last alive */
757         cfs_time_t              ibp_last_alive;
758         /* # users */
759         atomic_t                ibp_refcount;
760         /* version of peer_ni */
761         __u16                   ibp_version;
762         /* current passive connection attempts */
763         unsigned short          ibp_accepting;
764         /* current active connection attempts */
765         unsigned short          ibp_connecting;
766         /* reconnect this peer_ni later */
767         unsigned char           ibp_reconnecting;
768         /* counter of how many times we triggered a conn race */
769         unsigned char           ibp_races;
770         /* # consecutive reconnection attempts to this peer */
771         unsigned int            ibp_reconnected;
772         /* errno on closing this peer_ni */
773         int                     ibp_error;
774         /* max map_on_demand */
775         __u16                   ibp_max_frags;
776         /* max_peer_credits */
777         __u16                   ibp_queue_depth;
778 } kib_peer_ni_t;
779
780 #ifndef HAVE_IB_INC_RKEY
781 /**
782  * ib_inc_rkey - increments the key portion of the given rkey. Can be used
783  * for calculating a new rkey for type 2 memory windows.
784  * @rkey - the rkey to increment.
785  */
786 static inline u32 ib_inc_rkey(u32 rkey)
787 {
788         const u32 mask = 0x000000ff;
789         return ((rkey + 1) & mask) | (rkey & ~mask);
790 }
791 #endif
792
793 extern kib_data_t      kiblnd_data;
794
795 extern void kiblnd_hdev_destroy(kib_hca_dev_t *hdev);
796
797 int kiblnd_msg_queue_size(int version, struct lnet_ni *ni);
798
799 static inline void
800 kiblnd_hdev_addref_locked(kib_hca_dev_t *hdev)
801 {
802         LASSERT(atomic_read(&hdev->ibh_ref) > 0);
803         atomic_inc(&hdev->ibh_ref);
804 }
805
806 static inline void
807 kiblnd_hdev_decref(kib_hca_dev_t *hdev)
808 {
809         LASSERT(atomic_read(&hdev->ibh_ref) > 0);
810         if (atomic_dec_and_test(&hdev->ibh_ref))
811                 kiblnd_hdev_destroy(hdev);
812 }
813
814 static inline int
815 kiblnd_dev_can_failover(kib_dev_t *dev)
816 {
817         if (!list_empty(&dev->ibd_fail_list)) /* already scheduled */
818                 return 0;
819
820         if (*kiblnd_tunables.kib_dev_failover == 0) /* disabled */
821                 return 0;
822
823         if (*kiblnd_tunables.kib_dev_failover > 1) /* force failover */
824                 return 1;
825
826         return dev->ibd_can_failover;
827 }
828
829 #define kiblnd_conn_addref(conn)                                \
830 do {                                                            \
831         CDEBUG(D_NET, "conn[%p] (%d)++\n",                      \
832                (conn), atomic_read(&(conn)->ibc_refcount)); \
833         atomic_inc(&(conn)->ibc_refcount);                  \
834 } while (0)
835
836 #define kiblnd_conn_decref(conn)                                        \
837 do {                                                                    \
838         unsigned long flags;                                            \
839                                                                         \
840         CDEBUG(D_NET, "conn[%p] (%d)--\n",                              \
841                (conn), atomic_read(&(conn)->ibc_refcount));             \
842         LASSERT_ATOMIC_POS(&(conn)->ibc_refcount);                      \
843         if (atomic_dec_and_test(&(conn)->ibc_refcount)) {               \
844                 spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags);  \
845                 list_add_tail(&(conn)->ibc_list,                        \
846                                   &kiblnd_data.kib_connd_zombies);      \
847                 wake_up(&kiblnd_data.kib_connd_waitq);          \
848                 spin_unlock_irqrestore(&kiblnd_data.kib_connd_lock, flags);\
849         }                                                               \
850 } while (0)
851
852 #define kiblnd_peer_addref(peer_ni)                                \
853 do {                                                            \
854         CDEBUG(D_NET, "peer_ni[%p] -> %s (%d)++\n",                \
855                (peer_ni), libcfs_nid2str((peer_ni)->ibp_nid),         \
856                atomic_read (&(peer_ni)->ibp_refcount));         \
857         atomic_inc(&(peer_ni)->ibp_refcount);                   \
858 } while (0)
859
860 #define kiblnd_peer_decref(peer_ni)                                \
861 do {                                                            \
862         CDEBUG(D_NET, "peer_ni[%p] -> %s (%d)--\n",                \
863                (peer_ni), libcfs_nid2str((peer_ni)->ibp_nid),         \
864                atomic_read (&(peer_ni)->ibp_refcount));         \
865         LASSERT_ATOMIC_POS(&(peer_ni)->ibp_refcount);              \
866         if (atomic_dec_and_test(&(peer_ni)->ibp_refcount))      \
867                 kiblnd_destroy_peer(peer_ni);                      \
868 } while (0)
869
870 static inline bool
871 kiblnd_peer_connecting(kib_peer_ni_t *peer_ni)
872 {
873         return peer_ni->ibp_connecting != 0 ||
874                peer_ni->ibp_reconnecting != 0 ||
875                peer_ni->ibp_accepting != 0;
876 }
877
878 static inline bool
879 kiblnd_peer_idle(kib_peer_ni_t *peer_ni)
880 {
881         return !kiblnd_peer_connecting(peer_ni) && list_empty(&peer_ni->ibp_conns);
882 }
883
884 static inline struct list_head *
885 kiblnd_nid2peerlist (lnet_nid_t nid)
886 {
887         unsigned int hash =
888                 ((unsigned int)nid) % kiblnd_data.kib_peer_hash_size;
889
890         return &kiblnd_data.kib_peers[hash];
891 }
892
893 static inline int
894 kiblnd_peer_active (kib_peer_ni_t *peer_ni)
895 {
896         /* Am I in the peer_ni hash table? */
897         return !list_empty(&peer_ni->ibp_list);
898 }
899
900 static inline struct kib_conn *
901 kiblnd_get_conn_locked (kib_peer_ni_t *peer_ni)
902 {
903         struct list_head *next;
904
905         LASSERT(!list_empty(&peer_ni->ibp_conns));
906
907         /* Advance to next connection, be sure to skip the head node */
908         if (!peer_ni->ibp_next_conn ||
909             peer_ni->ibp_next_conn->ibc_list.next == &peer_ni->ibp_conns)
910                 next = peer_ni->ibp_conns.next;
911         else
912                 next = peer_ni->ibp_next_conn->ibc_list.next;
913         peer_ni->ibp_next_conn = list_entry(next, struct kib_conn, ibc_list);
914
915         return peer_ni->ibp_next_conn;
916 }
917
918 static inline int
919 kiblnd_send_keepalive(kib_conn_t *conn)
920 {
921         return (*kiblnd_tunables.kib_keepalive > 0) &&
922                 cfs_time_after(jiffies, conn->ibc_last_send +
923                                msecs_to_jiffies(*kiblnd_tunables.kib_keepalive *
924                                                 MSEC_PER_SEC));
925 }
926
927 static inline int
928 kiblnd_need_noop(kib_conn_t *conn)
929 {
930         struct lnet_ni *ni = conn->ibc_peer->ibp_ni;
931         struct lnet_ioctl_config_o2iblnd_tunables *tunables;
932
933         LASSERT(conn->ibc_state >= IBLND_CONN_ESTABLISHED);
934         tunables = &ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib;
935
936         if (conn->ibc_outstanding_credits <
937             IBLND_CREDITS_HIGHWATER(tunables, conn->ibc_version) &&
938             !kiblnd_send_keepalive(conn))
939                 return 0; /* No need to send NOOP */
940
941         if (IBLND_OOB_CAPABLE(conn->ibc_version)) {
942                 if (!list_empty(&conn->ibc_tx_queue_nocred))
943                         return 0; /* NOOP can be piggybacked */
944
945                 /* No tx to piggyback NOOP onto or no credit to send a tx */
946                 return (list_empty(&conn->ibc_tx_queue) ||
947                         conn->ibc_credits == 0);
948         }
949
950         if (!list_empty(&conn->ibc_tx_noops) || /* NOOP already queued */
951             !list_empty(&conn->ibc_tx_queue_nocred) || /* piggyback NOOP */
952             conn->ibc_credits == 0)                    /* no credit */
953                 return 0;
954
955         if (conn->ibc_credits == 1 &&      /* last credit reserved for */
956             conn->ibc_outstanding_credits == 0) /* giving back credits */
957                 return 0;
958
959         /* No tx to piggyback NOOP onto or no credit to send a tx */
960         return (list_empty(&conn->ibc_tx_queue) || conn->ibc_credits == 1);
961 }
962
963 static inline void
964 kiblnd_abort_receives(kib_conn_t *conn)
965 {
966         ib_modify_qp(conn->ibc_cmid->qp,
967                      &kiblnd_data.kib_error_qpa, IB_QP_STATE);
968 }
969
970 static inline const char *
971 kiblnd_queue2str(kib_conn_t *conn, struct list_head *q)
972 {
973         if (q == &conn->ibc_tx_queue)
974                 return "tx_queue";
975
976         if (q == &conn->ibc_tx_queue_rsrvd)
977                 return "tx_queue_rsrvd";
978
979         if (q == &conn->ibc_tx_queue_nocred)
980                 return "tx_queue_nocred";
981
982         if (q == &conn->ibc_active_txs)
983                 return "active_txs";
984
985         LBUG();
986         return NULL;
987 }
988
989 /* CAVEAT EMPTOR: We rely on descriptor alignment to allow us to use the
990  * lowest bits of the work request id to stash the work item type. */
991
992 #define IBLND_WID_INVAL 0
993 #define IBLND_WID_TX    1
994 #define IBLND_WID_RX    2
995 #define IBLND_WID_RDMA  3
996 #define IBLND_WID_MR    4
997 #define IBLND_WID_MASK  7UL
998
999 static inline __u64
1000 kiblnd_ptr2wreqid (void *ptr, int type)
1001 {
1002         unsigned long lptr = (unsigned long)ptr;
1003
1004         LASSERT ((lptr & IBLND_WID_MASK) == 0);
1005         LASSERT ((type & ~IBLND_WID_MASK) == 0);
1006         return (__u64)(lptr | type);
1007 }
1008
1009 static inline void *
1010 kiblnd_wreqid2ptr (__u64 wreqid)
1011 {
1012         return (void *)(((unsigned long)wreqid) & ~IBLND_WID_MASK);
1013 }
1014
1015 static inline int
1016 kiblnd_wreqid2type (__u64 wreqid)
1017 {
1018         return (wreqid & IBLND_WID_MASK);
1019 }
1020
1021 static inline void
1022 kiblnd_set_conn_state (kib_conn_t *conn, int state)
1023 {
1024         conn->ibc_state = state;
1025         smp_mb();
1026 }
1027
1028 static inline void
1029 kiblnd_init_msg (kib_msg_t *msg, int type, int body_nob)
1030 {
1031         msg->ibm_type = type;
1032         msg->ibm_nob  = offsetof(kib_msg_t, ibm_u) + body_nob;
1033 }
1034
1035 static inline int
1036 kiblnd_rd_size (kib_rdma_desc_t *rd)
1037 {
1038         int   i;
1039         int   size;
1040
1041         for (i = size = 0; i < rd->rd_nfrags; i++)
1042                 size += rd->rd_frags[i].rf_nob;
1043
1044         return size;
1045 }
1046
1047 static inline __u64
1048 kiblnd_rd_frag_addr(kib_rdma_desc_t *rd, int index)
1049 {
1050         return rd->rd_frags[index].rf_addr;
1051 }
1052
1053 static inline __u32
1054 kiblnd_rd_frag_size(kib_rdma_desc_t *rd, int index)
1055 {
1056         return rd->rd_frags[index].rf_nob;
1057 }
1058
1059 static inline __u32
1060 kiblnd_rd_frag_key(kib_rdma_desc_t *rd, int index)
1061 {
1062         return rd->rd_key;
1063 }
1064
1065 static inline int
1066 kiblnd_rd_consume_frag(kib_rdma_desc_t *rd, int index, __u32 nob)
1067 {
1068         if (nob < rd->rd_frags[index].rf_nob) {
1069                 rd->rd_frags[index].rf_addr += nob;
1070                 rd->rd_frags[index].rf_nob  -= nob;
1071         } else {
1072                 index ++;
1073         }
1074
1075         return index;
1076 }
1077
1078 static inline int
1079 kiblnd_rd_msg_size(kib_rdma_desc_t *rd, int msgtype, int n)
1080 {
1081         LASSERT (msgtype == IBLND_MSG_GET_REQ ||
1082                  msgtype == IBLND_MSG_PUT_ACK);
1083
1084         return msgtype == IBLND_MSG_GET_REQ ?
1085                offsetof(kib_get_msg_t, ibgm_rd.rd_frags[n]) :
1086                offsetof(kib_putack_msg_t, ibpam_rd.rd_frags[n]);
1087 }
1088
1089 static inline __u64
1090 kiblnd_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
1091 {
1092         return ib_dma_mapping_error(dev, dma_addr);
1093 }
1094
1095 static inline __u64 kiblnd_dma_map_single(struct ib_device *dev,
1096                                           void *msg, size_t size,
1097                                           enum dma_data_direction direction)
1098 {
1099         return ib_dma_map_single(dev, msg, size, direction);
1100 }
1101
1102 static inline void kiblnd_dma_unmap_single(struct ib_device *dev,
1103                                            __u64 addr, size_t size,
1104                                           enum dma_data_direction direction)
1105 {
1106         ib_dma_unmap_single(dev, addr, size, direction);
1107 }
1108
1109 #define KIBLND_UNMAP_ADDR_SET(p, m, a)  do {} while (0)
1110 #define KIBLND_UNMAP_ADDR(p, m, a)      (a)
1111
1112 static inline int kiblnd_dma_map_sg(struct ib_device *dev,
1113                                     struct scatterlist *sg, int nents,
1114                                     enum dma_data_direction direction)
1115 {
1116         return ib_dma_map_sg(dev, sg, nents, direction);
1117 }
1118
1119 static inline void kiblnd_dma_unmap_sg(struct ib_device *dev,
1120                                        struct scatterlist *sg, int nents,
1121                                        enum dma_data_direction direction)
1122 {
1123         ib_dma_unmap_sg(dev, sg, nents, direction);
1124 }
1125
1126 static inline __u64 kiblnd_sg_dma_address(struct ib_device *dev,
1127                                           struct scatterlist *sg)
1128 {
1129         return ib_sg_dma_address(dev, sg);
1130 }
1131
1132 static inline unsigned int kiblnd_sg_dma_len(struct ib_device *dev,
1133                                              struct scatterlist *sg)
1134 {
1135         return ib_sg_dma_len(dev, sg);
1136 }
1137
1138 /* XXX We use KIBLND_CONN_PARAM(e) as writable buffer, it's not strictly
1139  * right because OFED1.2 defines it as const, to use it we have to add
1140  * (void *) cast to overcome "const" */
1141
1142 #define KIBLND_CONN_PARAM(e)            ((e)->param.conn.private_data)
1143 #define KIBLND_CONN_PARAM_LEN(e)        ((e)->param.conn.private_data_len)
1144
1145 void kiblnd_map_rx_descs(kib_conn_t *conn);
1146 void kiblnd_unmap_rx_descs(kib_conn_t *conn);
1147 void kiblnd_pool_free_node(kib_pool_t *pool, struct list_head *node);
1148 struct list_head *kiblnd_pool_alloc_node(kib_poolset_t *ps);
1149
1150 int  kiblnd_fmr_pool_map(kib_fmr_poolset_t *fps, kib_tx_t *tx,
1151                          kib_rdma_desc_t *rd, __u32 nob, __u64 iov,
1152                          kib_fmr_t *fmr);
1153 void kiblnd_fmr_pool_unmap(kib_fmr_t *fmr, int status);
1154
1155 int  kiblnd_tunables_setup(struct lnet_ni *ni);
1156 int  kiblnd_tunables_init(void);
1157
1158 int  kiblnd_connd (void *arg);
1159 int  kiblnd_scheduler(void *arg);
1160 int  kiblnd_thread_start(int (*fn)(void *arg), void *arg, char *name);
1161 int  kiblnd_failover_thread (void *arg);
1162
1163 int  kiblnd_alloc_pages(kib_pages_t **pp, int cpt, int npages);
1164
1165 int  kiblnd_cm_callback(struct rdma_cm_id *cmid,
1166                         struct rdma_cm_event *event);
1167 int  kiblnd_translate_mtu(int value);
1168
1169 int  kiblnd_dev_failover(kib_dev_t *dev);
1170 int kiblnd_create_peer(struct lnet_ni *ni, kib_peer_ni_t **peerp,
1171                        lnet_nid_t nid);
1172 void kiblnd_destroy_peer (kib_peer_ni_t *peer);
1173 bool kiblnd_reconnect_peer(kib_peer_ni_t *peer);
1174 void kiblnd_destroy_dev (kib_dev_t *dev);
1175 void kiblnd_unlink_peer_locked (kib_peer_ni_t *peer_ni);
1176 kib_peer_ni_t *kiblnd_find_peer_locked(struct lnet_ni *ni, lnet_nid_t nid);
1177 int  kiblnd_close_stale_conns_locked (kib_peer_ni_t *peer_ni,
1178                                       int version, __u64 incarnation);
1179 int  kiblnd_close_peer_conns_locked (kib_peer_ni_t *peer_ni, int why);
1180
1181 kib_conn_t *kiblnd_create_conn(kib_peer_ni_t *peer_ni, struct rdma_cm_id *cmid,
1182                                int state, int version);
1183 void kiblnd_destroy_conn(kib_conn_t *conn, bool free_conn);
1184 void kiblnd_close_conn (kib_conn_t *conn, int error);
1185 void kiblnd_close_conn_locked (kib_conn_t *conn, int error);
1186
1187 void kiblnd_launch_tx(struct lnet_ni *ni, kib_tx_t *tx, lnet_nid_t nid);
1188 void kiblnd_txlist_done(struct list_head *txlist, int status);
1189
1190 void kiblnd_qp_event(struct ib_event *event, void *arg);
1191 void kiblnd_cq_event(struct ib_event *event, void *arg);
1192 void kiblnd_cq_completion(struct ib_cq *cq, void *arg);
1193
1194 void kiblnd_pack_msg(struct lnet_ni *ni, kib_msg_t *msg, int version,
1195                      int credits, lnet_nid_t dstnid, __u64 dststamp);
1196 int  kiblnd_unpack_msg(kib_msg_t *msg, int nob);
1197 int  kiblnd_post_rx (kib_rx_t *rx, int credit);
1198
1199 int  kiblnd_send(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg);
1200 int kiblnd_recv(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg,
1201                 int delayed, unsigned int niov, struct kvec *iov,
1202                 lnet_kiov_t *kiov, unsigned int offset, unsigned int mlen,
1203                 unsigned int rlen);
1204