Whamcloud - gitweb
LU-4423 lnet: free a struct kib_conn outside of the kiblnd_destroy_conn()
[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_time.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         int              *kib_use_fastreg_gaps; /* enable discontiguous fastreg fragment support */
116 } kib_tunables_t;
117
118 extern kib_tunables_t  kiblnd_tunables;
119
120 #define IBLND_MSG_QUEUE_SIZE_V1      8          /* V1 only : # messages/RDMAs in-flight */
121 #define IBLND_CREDIT_HIGHWATER_V1    7          /* V1 only : when eagerly to return credits */
122
123 #define IBLND_CREDITS_DEFAULT        8          /* default # of peer_ni credits */
124 #define IBLND_CREDITS_MAX          ((typeof(((kib_msg_t*) 0)->ibm_credits)) - 1)  /* Max # of peer_ni credits */
125
126 /* when eagerly to return credits */
127 #define IBLND_CREDITS_HIGHWATER(t, v) ((v) == IBLND_MSG_VERSION_1 ? \
128                                         IBLND_CREDIT_HIGHWATER_V1 : \
129                                         t->lnd_peercredits_hiw)
130
131 #ifdef HAVE_RDMA_CREATE_ID_5ARG
132 # define kiblnd_rdma_create_id(cb, dev, ps, qpt) rdma_create_id(current->nsproxy->net_ns, \
133                                                                 cb, dev, \
134                                                                 ps, qpt)
135 #else
136 # ifdef HAVE_RDMA_CREATE_ID_4ARG
137 #  define kiblnd_rdma_create_id(cb, dev, ps, qpt) rdma_create_id(cb, dev, \
138                                                                  ps, qpt)
139 # else
140 #  define kiblnd_rdma_create_id(cb, dev, ps, qpt) rdma_create_id(cb, dev, ps)
141 # endif
142 #endif
143
144 /* 2 OOB shall suffice for 1 keepalive and 1 returning credits */
145 #define IBLND_OOB_CAPABLE(v)       ((v) != IBLND_MSG_VERSION_1)
146 #define IBLND_OOB_MSGS(v)           (IBLND_OOB_CAPABLE(v) ? 2 : 0)
147
148 #define IBLND_MSG_SIZE              (4<<10)                 /* max size of queued messages (inc hdr) */
149 #define IBLND_MAX_RDMA_FRAGS         LNET_MAX_IOV           /* max # of fragments supported */
150
151 /************************/
152 /* derived constants... */
153 /* Pools (shared by connections on each CPT) */
154 /* These pools can grow at runtime, so don't need give a very large value */
155 #define IBLND_TX_POOL                   256
156 #define IBLND_FMR_POOL                  256
157 #define IBLND_FMR_POOL_FLUSH            192
158
159 /* RX messages (per connection) */
160 #define IBLND_RX_MSGS(c)        \
161         ((c->ibc_queue_depth) * 2 + IBLND_OOB_MSGS(c->ibc_version))
162 #define IBLND_RX_MSG_BYTES(c)       (IBLND_RX_MSGS(c) * IBLND_MSG_SIZE)
163 #define IBLND_RX_MSG_PAGES(c)   \
164         ((IBLND_RX_MSG_BYTES(c) + PAGE_SIZE - 1) / PAGE_SIZE)
165
166 /* WRs and CQEs (per connection) */
167 #define IBLND_RECV_WRS(c)            IBLND_RX_MSGS(c)
168
169 /* 2 = LNet msg + Transfer chain */
170 #define IBLND_CQ_ENTRIES(c)     \
171         (IBLND_RECV_WRS(c) + 2 * c->ibc_queue_depth)
172
173 struct kib_hca_dev;
174
175 /* o2iblnd can run over aliased interface */
176 #ifdef IFALIASZ
177 #define KIB_IFNAME_SIZE              IFALIASZ
178 #else
179 #define KIB_IFNAME_SIZE              256
180 #endif
181
182 typedef struct
183 {
184         struct list_head        ibd_list;       /* chain on kib_devs */
185         struct list_head        ibd_fail_list;  /* chain on kib_failed_devs */
186         __u32                   ibd_ifip;       /* IPoIB interface IP */
187         /** IPoIB interface name */
188         char                    ibd_ifname[KIB_IFNAME_SIZE];
189         int                     ibd_nnets;      /* # nets extant */
190
191         time64_t                ibd_next_failover;
192         /* # failover failures */
193         int                     ibd_failed_failover;
194         /* failover in progress */
195         unsigned int            ibd_failover;
196         /* IPoIB interface is a bonding master */
197         unsigned int            ibd_can_failover;
198         struct list_head        ibd_nets;
199         struct kib_hca_dev      *ibd_hdev;
200         __u32                   ibd_dev_caps;
201 } kib_dev_t;
202
203 typedef struct kib_hca_dev
204 {
205         struct rdma_cm_id   *ibh_cmid;          /* listener cmid */
206         struct ib_device    *ibh_ibdev;         /* IB device */
207         int                  ibh_page_shift;    /* page shift of current HCA */
208         int                  ibh_page_size;     /* page size of current HCA */
209         __u64                ibh_page_mask;     /* page mask of current HCA */
210         int                  ibh_mr_shift;      /* bits shift of max MR size */
211         __u64                ibh_mr_size;       /* size of MR */
212 #ifdef HAVE_IB_GET_DMA_MR
213         struct ib_mr        *ibh_mrs;           /* global MR */
214 #endif
215         struct ib_pd        *ibh_pd;            /* PD */
216         kib_dev_t           *ibh_dev;           /* owner */
217         atomic_t             ibh_ref;           /* refcount */
218 } kib_hca_dev_t;
219
220 /** # of seconds to keep pool alive */
221 #define IBLND_POOL_DEADLINE     300
222 /** # of seconds to retry if allocation failed */
223 #define IBLND_POOL_RETRY        1
224
225 typedef struct
226 {
227         int                     ibp_npages;             /* # pages */
228         struct page            *ibp_pages[0];           /* page array */
229 } kib_pages_t;
230
231 struct kib_pool;
232 struct kib_poolset;
233
234 typedef int  (*kib_ps_pool_create_t)(struct kib_poolset *ps,
235                                      int inc, struct kib_pool **pp_po);
236 typedef void (*kib_ps_pool_destroy_t)(struct kib_pool *po);
237 typedef void (*kib_ps_node_init_t)(struct kib_pool *po, struct list_head *node);
238 typedef void (*kib_ps_node_fini_t)(struct kib_pool *po, struct list_head *node);
239
240 struct kib_net;
241
242 #define IBLND_POOL_NAME_LEN     32
243
244 typedef struct kib_poolset
245 {
246         /* serialize */
247         spinlock_t              ps_lock;
248         /* network it belongs to */
249         struct kib_net          *ps_net;
250         /* pool set name */
251         char                    ps_name[IBLND_POOL_NAME_LEN];
252         /* list of pools */
253         struct list_head        ps_pool_list;
254         /* failed pool list */
255         struct list_head        ps_failed_pool_list;
256         /* time stamp for retry if failed to allocate */
257         time64_t                ps_next_retry;
258         /* is allocating new pool */
259         int                     ps_increasing;
260         /* new pool size */
261         int                     ps_pool_size;
262         /* CPT id */
263         int                     ps_cpt;
264
265         /* create a new pool */
266         kib_ps_pool_create_t    ps_pool_create;
267         /* destroy a pool */
268         kib_ps_pool_destroy_t   ps_pool_destroy;
269         /* initialize new allocated node */
270         kib_ps_node_init_t      ps_node_init;
271         /* finalize node */
272         kib_ps_node_fini_t      ps_node_fini;
273 } kib_poolset_t;
274
275 typedef struct kib_pool
276 {
277         /* chain on pool list */
278         struct list_head        po_list;
279         /* pre-allocated node */
280         struct list_head        po_free_list;
281         /* pool_set of this pool */
282         kib_poolset_t          *po_owner;
283         /* deadline of this pool */
284         time64_t                po_deadline;
285         /* # of elements in use */
286         int                     po_allocated;
287         /* pool is created on failed HCA */
288         int                     po_failed;
289         /* # of pre-allocated elements */
290         int                     po_size;
291 } kib_pool_t;
292
293 typedef struct {
294         kib_poolset_t           tps_poolset;            /* pool-set */
295         __u64                   tps_next_tx_cookie;     /* cookie of TX */
296 } kib_tx_poolset_t;
297
298 typedef struct {
299         kib_pool_t              tpo_pool;               /* pool */
300         struct kib_hca_dev     *tpo_hdev;               /* device for this pool */
301         struct kib_tx          *tpo_tx_descs;           /* all the tx descriptors */
302         kib_pages_t            *tpo_tx_pages;           /* premapped tx msg pages */
303 } kib_tx_pool_t;
304
305 typedef struct
306 {
307         spinlock_t              fps_lock;               /* serialize */
308         struct kib_net         *fps_net;                /* IB network */
309         struct list_head        fps_pool_list;          /* FMR pool list */
310         struct list_head        fps_failed_pool_list;   /* FMR pool list */
311         __u64                   fps_version;            /* validity stamp */
312         int                     fps_cpt;                /* CPT id */
313         int                     fps_pool_size;
314         int                     fps_flush_trigger;
315         int                     fps_cache;
316         /* is allocating new pool */
317         int                     fps_increasing;
318         /* time stamp for retry if failed to allocate */
319         time64_t                fps_next_retry;
320 } kib_fmr_poolset_t;
321
322 #ifndef HAVE_IB_RDMA_WR
323 struct ib_rdma_wr {
324         struct ib_send_wr wr;
325 };
326 #endif
327
328 struct kib_fast_reg_descriptor { /* For fast registration */
329         struct list_head                 frd_list;
330         struct ib_rdma_wr                frd_inv_wr;
331 #ifdef HAVE_IB_MAP_MR_SG
332         struct ib_reg_wr                 frd_fastreg_wr;
333 #else
334         struct ib_rdma_wr                frd_fastreg_wr;
335         struct ib_fast_reg_page_list    *frd_frpl;
336 #endif
337         struct ib_mr                    *frd_mr;
338         bool                             frd_valid;
339 };
340
341 typedef struct
342 {
343         struct list_head        fpo_list;       /* chain on pool list */
344         struct kib_hca_dev     *fpo_hdev;       /* device for this pool */
345         kib_fmr_poolset_t      *fpo_owner;      /* owner of this pool */
346         union {
347                 struct {
348                         struct ib_fmr_pool *fpo_fmr_pool; /* IB FMR pool */
349                 } fmr;
350                 struct { /* For fast registration */
351                         struct list_head  fpo_pool_list;
352                         int               fpo_pool_size;
353                 } fast_reg;
354         };
355         time64_t                fpo_deadline;   /* deadline of this pool */
356         int                     fpo_failed;     /* fmr pool is failed */
357         int                     fpo_map_count;  /* # of mapped FMR */
358         bool                    fpo_is_fmr; /* True if FMR pools allocated */
359 } kib_fmr_pool_t;
360
361 typedef struct {
362         kib_fmr_pool_t                  *fmr_pool;      /* pool of FMR */
363         struct ib_pool_fmr              *fmr_pfmr;      /* IB pool fmr */
364         struct kib_fast_reg_descriptor  *fmr_frd;
365         u32                              fmr_key;
366 } kib_fmr_t;
367
368 typedef struct kib_net
369 {
370         /* chain on kib_dev_t::ibd_nets */
371         struct list_head        ibn_list;
372         __u64                   ibn_incarnation;/* my epoch */
373         int                     ibn_init;       /* initialisation state */
374         int                     ibn_shutdown;   /* shutting down? */
375
376         atomic_t                ibn_npeers;     /* # peers extant */
377         atomic_t                ibn_nconns;     /* # connections extant */
378
379         kib_tx_poolset_t        **ibn_tx_ps;    /* tx pool-set */
380         kib_fmr_poolset_t       **ibn_fmr_ps;   /* fmr pool-set */
381
382         kib_dev_t               *ibn_dev;       /* underlying IB device */
383 } kib_net_t;
384
385 #define KIB_THREAD_SHIFT                16
386 #define KIB_THREAD_ID(cpt, tid)         ((cpt) << KIB_THREAD_SHIFT | (tid))
387 #define KIB_THREAD_CPT(id)              ((id) >> KIB_THREAD_SHIFT)
388 #define KIB_THREAD_TID(id)              ((id) & ((1UL << KIB_THREAD_SHIFT) - 1))
389
390 struct kib_sched_info {
391         /* serialise */
392         spinlock_t              ibs_lock;
393         /* schedulers sleep here */
394         wait_queue_head_t       ibs_waitq;
395         /* conns to check for rx completions */
396         struct list_head        ibs_conns;
397         /* number of scheduler threads */
398         int                     ibs_nthreads;
399         /* max allowed scheduler threads */
400         int                     ibs_nthreads_max;
401         int                     ibs_cpt;        /* CPT id */
402 };
403
404 typedef struct
405 {
406         int                     kib_init;       /* initialisation state */
407         int                     kib_shutdown;   /* shut down? */
408         struct list_head        kib_devs;       /* IB devices extant */
409         /* list head of failed devices */
410         struct list_head        kib_failed_devs;
411         /* schedulers sleep here */
412         wait_queue_head_t       kib_failover_waitq;
413         atomic_t                kib_nthreads;   /* # live threads */
414         /* stabilize net/dev/peer_ni/conn ops */
415         rwlock_t                kib_global_lock;
416         /* hash table of all my known peers */
417         struct list_head        *kib_peers;
418         /* size of kib_peers */
419         int                     kib_peer_hash_size;
420         /* the connd task (serialisation assertions) */
421         void                    *kib_connd;
422         /* connections to setup/teardown */
423         struct list_head        kib_connd_conns;
424         /* connections with zero refcount */
425         struct list_head        kib_connd_zombies;
426         /* connections to reconnect */
427         struct list_head        kib_reconn_list;
428         /* peers wait for reconnection */
429         struct list_head        kib_reconn_wait;
430         /*
431          * The second that peers are pulled out from \a kib_reconn_wait
432          * for reconnection.
433          */
434         time64_t                kib_reconn_sec;
435         /* connection daemon sleeps here */
436         wait_queue_head_t       kib_connd_waitq;
437         spinlock_t              kib_connd_lock; /* serialise */
438         struct ib_qp_attr       kib_error_qpa;  /* QP->ERROR */
439         /* percpt data for schedulers */
440         struct kib_sched_info   **kib_scheds;
441 } kib_data_t;
442
443 #define IBLND_INIT_NOTHING         0
444 #define IBLND_INIT_DATA            1
445 #define IBLND_INIT_ALL             2
446
447 /************************************************************************
448  * IB Wire message format.
449  * These are sent in sender's byte order (i.e. receiver flips).
450  */
451
452 typedef struct kib_connparams
453 {
454         __u16             ibcp_queue_depth;
455         __u16             ibcp_max_frags;
456         __u32             ibcp_max_msg_size;
457 } WIRE_ATTR kib_connparams_t;
458
459 typedef struct
460 {
461         struct lnet_hdr         ibim_hdr;       /* portals header */
462         char                    ibim_payload[0];/* piggy-backed payload */
463 } WIRE_ATTR kib_immediate_msg_t;
464
465 typedef struct
466 {
467         __u32             rf_nob;               /* # bytes this frag */
468         __u64             rf_addr;              /* CAVEAT EMPTOR: misaligned!! */
469 } WIRE_ATTR kib_rdma_frag_t;
470
471 typedef struct
472 {
473         __u32             rd_key;               /* local/remote key */
474         __u32             rd_nfrags;            /* # fragments */
475         kib_rdma_frag_t   rd_frags[0];          /* buffer frags */
476 } WIRE_ATTR kib_rdma_desc_t;
477
478 typedef struct
479 {
480         struct lnet_hdr         ibprm_hdr;      /* portals header */
481         __u64                   ibprm_cookie;   /* opaque completion cookie */
482 } WIRE_ATTR kib_putreq_msg_t;
483
484 typedef struct
485 {
486         __u64             ibpam_src_cookie;     /* reflected completion cookie */
487         __u64             ibpam_dst_cookie;     /* opaque completion cookie */
488         kib_rdma_desc_t   ibpam_rd;             /* sender's sink buffer */
489 } WIRE_ATTR kib_putack_msg_t;
490
491 typedef struct
492 {
493         struct lnet_hdr         ibgm_hdr;       /* portals header */
494         __u64                   ibgm_cookie;    /* opaque completion cookie */
495         kib_rdma_desc_t         ibgm_rd;        /* rdma descriptor */
496 } WIRE_ATTR kib_get_msg_t;
497
498 typedef struct
499 {
500         __u64             ibcm_cookie;          /* opaque completion cookie */
501         __s32             ibcm_status;          /* < 0 failure: >= 0 length */
502 } WIRE_ATTR kib_completion_msg_t;
503
504 typedef struct
505 {
506         /* First 2 fields fixed FOR ALL TIME */
507         __u32             ibm_magic;            /* I'm an ibnal message */
508         __u16             ibm_version;          /* this is my version number */
509
510         __u8              ibm_type;             /* msg type */
511         __u8              ibm_credits;          /* returned credits */
512         __u32             ibm_nob;              /* # bytes in whole message */
513         __u32             ibm_cksum;            /* checksum (0 == no checksum) */
514         __u64             ibm_srcnid;           /* sender's NID */
515         __u64             ibm_srcstamp;         /* sender's incarnation */
516         __u64             ibm_dstnid;           /* destination's NID */
517         __u64             ibm_dststamp;         /* destination's incarnation */
518
519         union {
520                 kib_connparams_t      connparams;
521                 kib_immediate_msg_t   immediate;
522                 kib_putreq_msg_t      putreq;
523                 kib_putack_msg_t      putack;
524                 kib_get_msg_t         get;
525                 kib_completion_msg_t  completion;
526         } WIRE_ATTR ibm_u;
527 } WIRE_ATTR kib_msg_t;
528
529 #define IBLND_MSG_MAGIC LNET_PROTO_IB_MAGIC     /* unique magic */
530
531 #define IBLND_MSG_VERSION_1         0x11
532 #define IBLND_MSG_VERSION_2         0x12
533 #define IBLND_MSG_VERSION           IBLND_MSG_VERSION_2
534
535 #define IBLND_MSG_CONNREQ           0xc0        /* connection request */
536 #define IBLND_MSG_CONNACK           0xc1        /* connection acknowledge */
537 #define IBLND_MSG_NOOP              0xd0        /* nothing (just credits) */
538 #define IBLND_MSG_IMMEDIATE         0xd1        /* immediate */
539 #define IBLND_MSG_PUT_REQ           0xd2        /* putreq (src->sink) */
540 #define IBLND_MSG_PUT_NAK           0xd3        /* completion (sink->src) */
541 #define IBLND_MSG_PUT_ACK           0xd4        /* putack (sink->src) */
542 #define IBLND_MSG_PUT_DONE          0xd5        /* completion (src->sink) */
543 #define IBLND_MSG_GET_REQ           0xd6        /* getreq (sink->src) */
544 #define IBLND_MSG_GET_DONE          0xd7        /* completion (src->sink: all OK) */
545
546 typedef struct {
547         __u32            ibr_magic;             /* sender's magic */
548         __u16            ibr_version;           /* sender's version */
549         __u8             ibr_why;               /* reject reason */
550         __u8             ibr_padding;           /* padding */
551         __u64            ibr_incarnation;       /* incarnation of peer_ni */
552         kib_connparams_t ibr_cp;                /* connection parameters */
553 } WIRE_ATTR kib_rej_t;
554
555 /* connection rejection reasons */
556 #define IBLND_REJECT_CONN_RACE       1          /* You lost connection race */
557 #define IBLND_REJECT_NO_RESOURCES    2          /* Out of memory/conns etc */
558 #define IBLND_REJECT_FATAL           3          /* Anything else */
559
560 #define IBLND_REJECT_CONN_UNCOMPAT   4          /* incompatible version peer_ni */
561 #define IBLND_REJECT_CONN_STALE      5          /* stale peer_ni */
562
563 /* peer_ni's rdma frags doesn't match mine */
564 #define IBLND_REJECT_RDMA_FRAGS      6
565 /* peer_ni's msg queue size doesn't match mine */
566 #define IBLND_REJECT_MSG_QUEUE_SIZE  7
567 #define IBLND_REJECT_INVALID_SRV_ID  8
568
569 /***********************************************************************/
570
571 typedef struct kib_rx                           /* receive message */
572 {
573         /* queue for attention */
574         struct list_head        rx_list;
575         /* owning conn */
576         struct kib_conn        *rx_conn;
577         /* # bytes received (-1 while posted) */
578         int                     rx_nob;
579         /* completion status */
580         enum ib_wc_status       rx_status;
581         /* message buffer (host vaddr) */
582         kib_msg_t              *rx_msg;
583         /* message buffer (I/O addr) */
584         __u64                   rx_msgaddr;
585         /* for dma_unmap_single() */
586         DECLARE_PCI_UNMAP_ADDR(rx_msgunmap);
587         /* receive work item... */
588         struct ib_recv_wr       rx_wrq;
589         /* ...and its memory */
590         struct ib_sge           rx_sge;
591 } kib_rx_t;
592
593 #define IBLND_POSTRX_DONT_POST    0             /* don't post */
594 #define IBLND_POSTRX_NO_CREDIT    1             /* post: no credits */
595 #define IBLND_POSTRX_PEER_CREDIT  2             /* post: give peer_ni back 1 credit */
596 #define IBLND_POSTRX_RSRVD_CREDIT 3             /* post: give myself back 1 reserved credit */
597
598 typedef struct kib_tx                           /* transmit message */
599 {
600         /* queue on idle_txs ibc_tx_queue etc. */
601         struct list_head        tx_list;
602         /* pool I'm from */
603         kib_tx_pool_t           *tx_pool;
604         /* owning conn */
605         struct kib_conn         *tx_conn;
606         /* # tx callbacks outstanding */
607         short                   tx_sending;
608         /* queued for sending */
609         short                   tx_queued;
610         /* waiting for peer_ni */
611         short                   tx_waiting;
612         /* LNET completion status */
613         int                     tx_status;
614         /* completion deadline */
615         ktime_t                 tx_deadline;
616         /* completion cookie */
617         __u64                   tx_cookie;
618         /* lnet msgs to finalize on completion */
619         struct lnet_msg         *tx_lntmsg[2];
620         /* message buffer (host vaddr) */
621         kib_msg_t               *tx_msg;
622         /* message buffer (I/O addr) */
623         __u64                   tx_msgaddr;
624         /* for dma_unmap_single() */
625         DECLARE_PCI_UNMAP_ADDR(tx_msgunmap);
626         /** sge for tx_msgaddr */
627         struct ib_sge           tx_msgsge;
628         /* # send work items */
629         int                     tx_nwrq;
630         /* # used scatter/gather elements */
631         int                     tx_nsge;
632         /* send work items... */
633         struct ib_rdma_wr       *tx_wrq;
634         /* ...and their memory */
635         struct ib_sge           *tx_sge;
636         /* rdma descriptor */
637         kib_rdma_desc_t         *tx_rd;
638         /* # entries in... */
639         int                     tx_nfrags;
640         /* dma_map_sg descriptor */
641         struct scatterlist      *tx_frags;
642         /* rdma phys page addrs */
643         __u64                   *tx_pages;
644         /* gaps in fragments */
645         bool                    tx_gaps;
646         /* FMR */
647         kib_fmr_t               tx_fmr;
648                                 /* dma direction */
649         int                     tx_dmadir;
650 } kib_tx_t;
651
652 typedef struct kib_connvars
653 {
654         /* connection-in-progress variables */
655         kib_msg_t                 cv_msg;
656 } kib_connvars_t;
657
658 typedef struct kib_conn
659 {
660         /* scheduler information */
661         struct kib_sched_info   *ibc_sched;
662         /* owning peer_ni */
663         struct kib_peer         *ibc_peer;
664         /* HCA bound on */
665         kib_hca_dev_t           *ibc_hdev;
666         /* stash on peer_ni's conn list */
667         struct list_head        ibc_list;
668         /* schedule for attention */
669         struct list_head        ibc_sched_list;
670         /* version of connection */
671         __u16                   ibc_version;
672         /* reconnect later */
673         __u16                   ibc_reconnect:1;
674         /* which instance of the peer */
675         __u64                   ibc_incarnation;
676         /* # users */
677         atomic_t                ibc_refcount;
678         /* what's happening */
679         int                     ibc_state;
680         /* # uncompleted sends */
681         int                     ibc_nsends_posted;
682         /* # uncompleted NOOPs */
683         int                     ibc_noops_posted;
684         /* # credits I have */
685         int                     ibc_credits;
686         /* # credits to return */
687         int                     ibc_outstanding_credits;
688         /* # ACK/DONE msg credits */
689         int                     ibc_reserved_credits;
690         /* set on comms error */
691         int                     ibc_comms_error;
692         /* connections queue depth */
693         __u16                   ibc_queue_depth;
694         /* connections max frags */
695         __u16                   ibc_max_frags;
696         /* receive buffers owned */
697         unsigned int            ibc_nrx:16;
698         /* scheduled for attention */
699         unsigned int            ibc_scheduled:1;
700         /* CQ callback fired */
701         unsigned int            ibc_ready:1;
702         /* time of last send */
703         ktime_t                 ibc_last_send;
704         /** link chain for kiblnd_check_conns only */
705         struct list_head        ibc_connd_list;
706         /** IBLND_MSG_NOOPs for IBLND_MSG_VERSION_1 */
707         struct list_head        ibc_tx_noops;
708         /* sends that need a credit */
709         struct list_head        ibc_tx_queue;
710         /* sends that don't need a credit */
711         struct list_head        ibc_tx_queue_nocred;
712         /* sends that need to reserve an ACK/DONE msg */
713         struct list_head        ibc_tx_queue_rsrvd;
714         /* active tx awaiting completion */
715         struct list_head        ibc_active_txs;
716         /* serialise */
717         spinlock_t              ibc_lock;
718         /* the rx descs */
719         kib_rx_t                *ibc_rxs;
720         /* premapped rx msg pages */
721         kib_pages_t             *ibc_rx_pages;
722
723         /* CM id */
724         struct rdma_cm_id       *ibc_cmid;
725         /* completion queue */
726         struct ib_cq            *ibc_cq;
727
728         /* in-progress connection state */
729         kib_connvars_t          *ibc_connvars;
730 } kib_conn_t;
731
732 #define IBLND_CONN_INIT               0         /* being initialised */
733 #define IBLND_CONN_ACTIVE_CONNECT     1         /* active sending req */
734 #define IBLND_CONN_PASSIVE_WAIT       2         /* passive waiting for rtu */
735 #define IBLND_CONN_ESTABLISHED        3         /* connection established */
736 #define IBLND_CONN_CLOSING            4         /* being closed */
737 #define IBLND_CONN_DISCONNECTED       5         /* disconnected */
738
739 typedef struct kib_peer
740 {
741         /* stash on global peer_ni list */
742         struct list_head        ibp_list;
743         /* who's on the other end(s) */
744         lnet_nid_t              ibp_nid;
745         /* LNet interface */
746         struct lnet_ni          *ibp_ni;
747         /* all active connections */
748         struct list_head        ibp_conns;
749         /* next connection to send on for round robin */
750         struct kib_conn         *ibp_next_conn;
751         /* msgs waiting for a conn */
752         struct list_head        ibp_tx_queue;
753         /* incarnation of peer_ni */
754         __u64                   ibp_incarnation;
755         /* when (in seconds) I was last alive */
756         time64_t                ibp_last_alive;
757         /* # users */
758         atomic_t                ibp_refcount;
759         /* version of peer_ni */
760         __u16                   ibp_version;
761         /* current passive connection attempts */
762         unsigned short          ibp_accepting;
763         /* current active connection attempts */
764         unsigned short          ibp_connecting;
765         /* reconnect this peer_ni later */
766         unsigned char           ibp_reconnecting;
767         /* counter of how many times we triggered a conn race */
768         unsigned char           ibp_races;
769         /* # consecutive reconnection attempts to this peer */
770         unsigned int            ibp_reconnected;
771         /* errno on closing this peer_ni */
772         int                     ibp_error;
773         /* max map_on_demand */
774         __u16                   ibp_max_frags;
775         /* max_peer_credits */
776         __u16                   ibp_queue_depth;
777 } kib_peer_ni_t;
778
779 #ifndef HAVE_IB_INC_RKEY
780 /**
781  * ib_inc_rkey - increments the key portion of the given rkey. Can be used
782  * for calculating a new rkey for type 2 memory windows.
783  * @rkey - the rkey to increment.
784  */
785 static inline u32 ib_inc_rkey(u32 rkey)
786 {
787         const u32 mask = 0x000000ff;
788         return ((rkey + 1) & mask) | (rkey & ~mask);
789 }
790 #endif
791
792 extern kib_data_t      kiblnd_data;
793
794 extern void kiblnd_hdev_destroy(kib_hca_dev_t *hdev);
795
796 int kiblnd_msg_queue_size(int version, struct lnet_ni *ni);
797
798 static inline void
799 kiblnd_hdev_addref_locked(kib_hca_dev_t *hdev)
800 {
801         LASSERT(atomic_read(&hdev->ibh_ref) > 0);
802         atomic_inc(&hdev->ibh_ref);
803 }
804
805 static inline void
806 kiblnd_hdev_decref(kib_hca_dev_t *hdev)
807 {
808         LASSERT(atomic_read(&hdev->ibh_ref) > 0);
809         if (atomic_dec_and_test(&hdev->ibh_ref))
810                 kiblnd_hdev_destroy(hdev);
811 }
812
813 static inline int
814 kiblnd_dev_can_failover(kib_dev_t *dev)
815 {
816         if (!list_empty(&dev->ibd_fail_list)) /* already scheduled */
817                 return 0;
818
819         if (*kiblnd_tunables.kib_dev_failover == 0) /* disabled */
820                 return 0;
821
822         if (*kiblnd_tunables.kib_dev_failover > 1) /* force failover */
823                 return 1;
824
825         return dev->ibd_can_failover;
826 }
827
828 #define kiblnd_conn_addref(conn)                                \
829 do {                                                            \
830         CDEBUG(D_NET, "conn[%p] (%d)++\n",                      \
831                (conn), atomic_read(&(conn)->ibc_refcount)); \
832         atomic_inc(&(conn)->ibc_refcount);                  \
833 } while (0)
834
835 #define kiblnd_conn_decref(conn)                                        \
836 do {                                                                    \
837         unsigned long flags;                                            \
838                                                                         \
839         CDEBUG(D_NET, "conn[%p] (%d)--\n",                              \
840                (conn), atomic_read(&(conn)->ibc_refcount));             \
841         LASSERT_ATOMIC_POS(&(conn)->ibc_refcount);                      \
842         if (atomic_dec_and_test(&(conn)->ibc_refcount)) {               \
843                 spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags);  \
844                 list_add_tail(&(conn)->ibc_list,                        \
845                                   &kiblnd_data.kib_connd_zombies);      \
846                 wake_up(&kiblnd_data.kib_connd_waitq);          \
847                 spin_unlock_irqrestore(&kiblnd_data.kib_connd_lock, flags);\
848         }                                                               \
849 } while (0)
850
851 #define kiblnd_peer_addref(peer_ni)                                \
852 do {                                                            \
853         CDEBUG(D_NET, "peer_ni[%p] -> %s (%d)++\n",                \
854                (peer_ni), libcfs_nid2str((peer_ni)->ibp_nid),         \
855                atomic_read (&(peer_ni)->ibp_refcount));         \
856         atomic_inc(&(peer_ni)->ibp_refcount);                   \
857 } while (0)
858
859 #define kiblnd_peer_decref(peer_ni)                                \
860 do {                                                            \
861         CDEBUG(D_NET, "peer_ni[%p] -> %s (%d)--\n",                \
862                (peer_ni), libcfs_nid2str((peer_ni)->ibp_nid),         \
863                atomic_read (&(peer_ni)->ibp_refcount));         \
864         LASSERT_ATOMIC_POS(&(peer_ni)->ibp_refcount);              \
865         if (atomic_dec_and_test(&(peer_ni)->ibp_refcount))      \
866                 kiblnd_destroy_peer(peer_ni);                      \
867 } while (0)
868
869 static inline bool
870 kiblnd_peer_connecting(kib_peer_ni_t *peer_ni)
871 {
872         return peer_ni->ibp_connecting != 0 ||
873                peer_ni->ibp_reconnecting != 0 ||
874                peer_ni->ibp_accepting != 0;
875 }
876
877 static inline bool
878 kiblnd_peer_idle(kib_peer_ni_t *peer_ni)
879 {
880         return !kiblnd_peer_connecting(peer_ni) && list_empty(&peer_ni->ibp_conns);
881 }
882
883 static inline struct list_head *
884 kiblnd_nid2peerlist (lnet_nid_t nid)
885 {
886         unsigned int hash =
887                 ((unsigned int)nid) % kiblnd_data.kib_peer_hash_size;
888
889         return &kiblnd_data.kib_peers[hash];
890 }
891
892 static inline int
893 kiblnd_peer_active (kib_peer_ni_t *peer_ni)
894 {
895         /* Am I in the peer_ni hash table? */
896         return !list_empty(&peer_ni->ibp_list);
897 }
898
899 static inline struct kib_conn *
900 kiblnd_get_conn_locked (kib_peer_ni_t *peer_ni)
901 {
902         struct list_head *next;
903
904         LASSERT(!list_empty(&peer_ni->ibp_conns));
905
906         /* Advance to next connection, be sure to skip the head node */
907         if (!peer_ni->ibp_next_conn ||
908             peer_ni->ibp_next_conn->ibc_list.next == &peer_ni->ibp_conns)
909                 next = peer_ni->ibp_conns.next;
910         else
911                 next = peer_ni->ibp_next_conn->ibc_list.next;
912         peer_ni->ibp_next_conn = list_entry(next, struct kib_conn, ibc_list);
913
914         return peer_ni->ibp_next_conn;
915 }
916
917 static inline int
918 kiblnd_send_keepalive(kib_conn_t *conn)
919 {
920         s64 keepalive_ns = *kiblnd_tunables.kib_keepalive * NSEC_PER_SEC;
921
922         return (*kiblnd_tunables.kib_keepalive > 0) &&
923                 ktime_after(ktime_get(),
924                             ktime_add_ns(conn->ibc_last_send, keepalive_ns));
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);
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