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