1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2006 Cluster File Systems, Inc.
5 * Author: Eric Barton <eric@bartonsoftware.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 # define EXPORT_SYMTAB
27 #ifndef AUTOCONF_INCLUDED
28 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/kernel.h>
33 #include <linux/string.h>
34 #include <linux/stat.h>
35 #include <linux/errno.h>
36 #include <linux/smp_lock.h>
37 #include <linux/unistd.h>
38 #include <linux/uio.h>
40 #include <asm/system.h>
41 #include <asm/uaccess.h>
44 #include <linux/init.h>
46 #include <linux/file.h>
47 #include <linux/stat.h>
48 #include <linux/list.h>
49 #include <linux/kmod.h>
50 #include <linux/sysctl.h>
51 #include <linux/random.h>
56 #define DEBUG_SUBSYSTEM S_LND
58 #include <libcfs/kp30.h>
59 #include <lnet/lnet.h>
60 #include <lnet/lib-lnet.h>
66 #include <rdma/rdma_cm.h>
67 #include <rdma/ib_cm.h>
68 #include <rdma/ib_verbs.h>
69 #include <rdma/ib_fmr_pool.h>
71 /* tunables fixed at compile time */
73 # define IBLND_N_SCHED num_online_cpus() /* # schedulers */
75 # define IBLND_N_SCHED 1 /* # schedulers */
78 #define IBLND_PEER_HASH_SIZE 101 /* # peer lists */
79 #define IBLND_RESCHED 100 /* # scheduler loops before reschedule */
80 #define IBLND_MSG_QUEUE_SIZE 8 /* # messages/RDMAs in-flight */
81 #define IBLND_CREDIT_HIGHWATER 7 /* when eagerly to return credits */
82 #define IBLND_MSG_SIZE (4<<10) /* max size of queued messages (inc hdr) */
84 #define IBLND_MAP_ON_DEMAND 0
85 #if IBLND_MAP_ON_DEMAND
86 # define IBLND_MAX_RDMA_FRAGS 1
88 # define IBLND_MAX_RDMA_FRAGS LNET_MAX_IOV
91 /************************/
92 /* derived constants... */
94 /* TX messages (shared by all connections) */
95 #define IBLND_TX_MSGS() (*kiblnd_tunables.kib_ntx)
96 #define IBLND_TX_MSG_BYTES() (IBLND_TX_MSGS() * IBLND_MSG_SIZE)
97 #define IBLND_TX_MSG_PAGES() ((IBLND_TX_MSG_BYTES() + PAGE_SIZE - 1)/PAGE_SIZE)
99 /* RX messages (per connection) */
100 #define IBLND_RX_MSGS (IBLND_MSG_QUEUE_SIZE*2)
101 #define IBLND_RX_MSG_BYTES (IBLND_RX_MSGS * IBLND_MSG_SIZE)
102 #define IBLND_RX_MSG_PAGES ((IBLND_RX_MSG_BYTES + PAGE_SIZE - 1)/PAGE_SIZE)
104 #define IBLND_CQ_ENTRIES() (IBLND_RX_MSGS + \
105 (*kiblnd_tunables.kib_concurrent_sends) * \
106 (1 + IBLND_MAX_RDMA_FRAGS))
110 unsigned int *kib_service; /* IB service number */
111 int *kib_min_reconnect_interval; /* first failed connection retry... */
112 int *kib_max_reconnect_interval; /* ...exponentially increasing to this */
113 int *kib_cksum; /* checksum kib_msg_t? */
114 int *kib_timeout; /* comms timeout (seconds) */
115 int *kib_keepalive; /* keepalive timeout (seconds) */
116 int *kib_ntx; /* # tx descs */
117 int *kib_credits; /* # concurrent sends */
118 int *kib_peercredits; /* # concurrent sends to 1 peer */
119 char **kib_default_ipif; /* default IPoIB interface */
120 int *kib_retry_count;
121 int *kib_rnr_retry_count;
122 int *kib_concurrent_sends; /* send work queue sizing */
123 int *kib_ib_mtu; /* IB MTU */
124 #if IBLND_MAP_ON_DEMAND
125 int *kib_fmr_pool_size; /* # FMRs in pool */
126 int *kib_fmr_flush_trigger; /* When to trigger FMR flush */
127 int *kib_fmr_cache; /* enable FMR pool cache? */
129 #if CONFIG_SYSCTL && !CFS_SYSFS_MODULE_PARM
130 struct ctl_table_header *kib_sysctl; /* sysctl interface */
136 int ibp_npages; /* # pages */
137 struct page *ibp_pages[0];
142 struct list_head ibd_list; /* chain on kib_devs */
143 __u32 ibd_ifip; /* IPoIB interface IP */
144 char ibd_ifname[32]; /* IPoIB interface name */
145 int ibd_nnets; /* # nets extant */
147 struct rdma_cm_id *ibd_cmid; /* IB listener (bound to 1 device) */
148 struct ib_pd *ibd_pd; /* PD for the device */
149 struct ib_mr *ibd_mr; /* MR for non RDMA I/O */
154 __u64 ibn_incarnation; /* my epoch */
155 int ibn_init; /* initialisation state */
156 int ibn_shutdown; /* shutting down? */
158 atomic_t ibn_npeers; /* # peers extant */
159 atomic_t ibn_nconns; /* # connections extant */
161 struct kib_tx *ibn_tx_descs; /* all the tx descriptors */
162 kib_pages_t *ibn_tx_pages; /* premapped tx msg pages */
163 struct list_head ibn_idle_txs; /* idle tx descriptors */
164 spinlock_t ibn_tx_lock; /* serialise */
166 #if IBLND_MAP_ON_DEMAND
167 struct ib_fmr_pool *ibn_fmrpool; /* FMR pool for RDMA I/O */
170 kib_dev_t *ibn_dev; /* underlying IB device */
175 int kib_init; /* initialisation state */
176 int kib_shutdown; /* shut down? */
177 struct list_head kib_devs; /* IB devices extant */
178 atomic_t kib_nthreads; /* # live threads */
179 rwlock_t kib_global_lock; /* stabilize net/dev/peer/conn ops */
181 struct list_head *kib_peers; /* hash table of all my known peers */
182 int kib_peer_hash_size; /* size of kib_peers */
184 void *kib_connd; /* the connd task (serialisation assertions) */
185 struct list_head kib_connd_conns; /* connections to setup/teardown */
186 struct list_head kib_connd_zombies; /* connections with zero refcount */
187 wait_queue_head_t kib_connd_waitq; /* connection daemon sleeps here */
188 spinlock_t kib_connd_lock; /* serialise */
190 wait_queue_head_t kib_sched_waitq; /* schedulers sleep here */
191 struct list_head kib_sched_conns; /* conns to check for rx completions */
192 spinlock_t kib_sched_lock; /* serialise */
194 __u64 kib_next_tx_cookie; /* RDMA completion cookie */
195 struct ib_qp_attr kib_error_qpa; /* QP->ERROR */
198 #define IBLND_INIT_NOTHING 0
199 #define IBLND_INIT_DATA 1
200 #define IBLND_INIT_ALL 2
202 /************************************************************************
203 * IB Wire message format.
204 * These are sent in sender's byte order (i.e. receiver flips).
207 typedef struct kib_connparams
209 __u16 ibcp_queue_depth;
210 __u16 ibcp_max_frags;
211 __u32 ibcp_max_msg_size;
212 } WIRE_ATTR kib_connparams_t;
216 lnet_hdr_t ibim_hdr; /* portals header */
217 char ibim_payload[0]; /* piggy-backed payload */
218 } WIRE_ATTR kib_immediate_msg_t;
220 #if IBLND_MAP_ON_DEMAND
223 __u64 rd_addr; /* IO VMA address */
224 __u32 rd_nob; /* # of bytes */
225 __u32 rd_key; /* remote key */
226 } WIRE_ATTR kib_rdma_desc_t;
230 __u32 rf_nob; /* # bytes this frag */
231 __u64 rf_addr; /* CAVEAT EMPTOR: misaligned!! */
232 } WIRE_ATTR kib_rdma_frag_t;
236 __u32 rd_key; /* local/remote key */
237 __u32 rd_nfrags; /* # fragments */
238 kib_rdma_frag_t rd_frags[0]; /* buffer frags */
239 } WIRE_ATTR kib_rdma_desc_t;
244 lnet_hdr_t ibprm_hdr; /* portals header */
245 __u64 ibprm_cookie; /* opaque completion cookie */
246 } WIRE_ATTR kib_putreq_msg_t;
250 __u64 ibpam_src_cookie; /* reflected completion cookie */
251 __u64 ibpam_dst_cookie; /* opaque completion cookie */
252 kib_rdma_desc_t ibpam_rd; /* sender's sink buffer */
253 } WIRE_ATTR kib_putack_msg_t;
257 lnet_hdr_t ibgm_hdr; /* portals header */
258 __u64 ibgm_cookie; /* opaque completion cookie */
259 kib_rdma_desc_t ibgm_rd; /* rdma descriptor */
260 } WIRE_ATTR kib_get_msg_t;
264 __u64 ibcm_cookie; /* opaque completion cookie */
265 __s32 ibcm_status; /* < 0 failure: >= 0 length */
266 } WIRE_ATTR kib_completion_msg_t;
270 /* First 2 fields fixed FOR ALL TIME */
271 __u32 ibm_magic; /* I'm an openibnal message */
272 __u16 ibm_version; /* this is my version number */
274 __u8 ibm_type; /* msg type */
275 __u8 ibm_credits; /* returned credits */
276 __u32 ibm_nob; /* # bytes in whole message */
277 __u32 ibm_cksum; /* checksum (0 == no checksum) */
278 __u64 ibm_srcnid; /* sender's NID */
279 __u64 ibm_srcstamp; /* sender's incarnation */
280 __u64 ibm_dstnid; /* destination's NID */
281 __u64 ibm_dststamp; /* destination's incarnation */
284 kib_connparams_t connparams;
285 kib_immediate_msg_t immediate;
286 kib_putreq_msg_t putreq;
287 kib_putack_msg_t putack;
289 kib_completion_msg_t completion;
291 } WIRE_ATTR kib_msg_t;
293 #define IBLND_MSG_MAGIC LNET_PROTO_IB_MAGIC /* unique magic */
295 #define IBLND_MSG_VERSION 0x11
297 #define IBLND_MSG_CONNREQ 0xc0 /* connection request */
298 #define IBLND_MSG_CONNACK 0xc1 /* connection acknowledge */
299 #define IBLND_MSG_NOOP 0xd0 /* nothing (just credits) */
300 #define IBLND_MSG_IMMEDIATE 0xd1 /* immediate */
301 #define IBLND_MSG_PUT_REQ 0xd2 /* putreq (src->sink) */
302 #define IBLND_MSG_PUT_NAK 0xd3 /* completion (sink->src) */
303 #define IBLND_MSG_PUT_ACK 0xd4 /* putack (sink->src) */
304 #define IBLND_MSG_PUT_DONE 0xd5 /* completion (src->sink) */
305 #define IBLND_MSG_GET_REQ 0xd6 /* getreq (sink->src) */
306 #define IBLND_MSG_GET_DONE 0xd7 /* completion (src->sink: all OK) */
309 __u32 ibr_magic; /* sender's magic */
310 __u16 ibr_version; /* sender's version */
311 __u8 ibr_why; /* reject reason */
312 } WIRE_ATTR kib_rej_t;
315 /* connection rejection reasons */
316 #define IBLND_REJECT_CONN_RACE 1 /* You lost connection race */
317 #define IBLND_REJECT_NO_RESOURCES 2 /* Out of memory/conns etc */
318 #define IBLND_REJECT_FATAL 3 /* Anything else */
320 /***********************************************************************/
322 typedef struct kib_rx /* receive message */
324 struct list_head rx_list; /* queue for attention */
325 struct kib_conn *rx_conn; /* owning conn */
326 int rx_nob; /* # bytes received (-1 while posted) */
327 enum ib_wc_status rx_status; /* completion status */
328 kib_msg_t *rx_msg; /* message buffer (host vaddr) */
329 __u64 rx_msgaddr; /* message buffer (I/O addr) */
330 DECLARE_PCI_UNMAP_ADDR (rx_msgunmap); /* for dma_unmap_single() */
331 struct ib_recv_wr rx_wrq; /* receive work item... */
332 struct ib_sge rx_sge; /* ...and its memory */
335 #define IBLND_POSTRX_DONT_POST 0 /* don't post */
336 #define IBLND_POSTRX_NO_CREDIT 1 /* post: no credits */
337 #define IBLND_POSTRX_PEER_CREDIT 2 /* post: give peer back 1 credit */
338 #define IBLND_POSTRX_RSRVD_CREDIT 3 /* post: give myself back 1 reserved credit */
340 typedef struct kib_tx /* transmit message */
342 struct list_head tx_list; /* queue on idle_txs ibc_tx_queue etc. */
343 struct kib_conn *tx_conn; /* owning conn */
344 int tx_sending; /* # tx callbacks outstanding */
345 int tx_queued; /* queued for sending */
346 int tx_waiting; /* waiting for peer */
347 int tx_status; /* LNET completion status */
348 unsigned long tx_deadline; /* completion deadline */
349 __u64 tx_cookie; /* completion cookie */
350 lnet_msg_t *tx_lntmsg[2]; /* lnet msgs to finalize on completion */
351 kib_msg_t *tx_msg; /* message buffer (host vaddr) */
352 __u64 tx_msgaddr; /* message buffer (I/O addr) */
353 DECLARE_PCI_UNMAP_ADDR (tx_msgunmap); /* for dma_unmap_single() */
354 int tx_nwrq; /* # send work items */
355 #if IBLND_MAP_ON_DEMAND
356 struct ib_send_wr tx_wrq[2]; /* send work items... */
357 struct ib_sge tx_sge[2]; /* ...and their memory */
358 kib_rdma_desc_t tx_rd[1]; /* rdma descriptor */
359 __u64 *tx_pages; /* rdma phys page addrs */
360 struct ib_pool_fmr *tx_fmr; /* rdma mapping (mapped if != NULL) */
362 struct ib_send_wr *tx_wrq; /* send work items... */
363 struct ib_sge *tx_sge; /* ...and their memory */
364 kib_rdma_desc_t *tx_rd; /* rdma descriptor */
365 int tx_nfrags; /* # entries in... */
366 struct scatterlist *tx_frags; /* dma_map_sg descriptor */
367 int tx_dmadir; /* dma direction */
371 typedef struct kib_connvars
373 /* connection-in-progress variables */
377 typedef struct kib_conn
379 struct kib_peer *ibc_peer; /* owning peer */
380 struct list_head ibc_list; /* stash on peer's conn list */
381 struct list_head ibc_sched_list; /* schedule for attention */
382 __u64 ibc_incarnation; /* which instance of the peer */
383 atomic_t ibc_refcount; /* # users */
384 int ibc_state; /* what's happening */
385 int ibc_nsends_posted; /* # uncompleted sends */
386 int ibc_credits; /* # credits I have */
387 int ibc_outstanding_credits; /* # credits to return */
388 int ibc_reserved_credits;/* # ACK/DONE msg credits */
389 int ibc_comms_error; /* set on comms error */
390 int ibc_nrx:8; /* receive buffers owned */
391 int ibc_scheduled:1; /* scheduled for attention */
392 int ibc_ready:1; /* CQ callback fired */
393 unsigned long ibc_last_send; /* time of last send */
394 struct list_head ibc_early_rxs; /* rxs completed before ESTABLISHED */
395 struct list_head ibc_tx_queue; /* sends that need a credit */
396 struct list_head ibc_tx_queue_nocred;/* sends that don't need a credit */
397 struct list_head ibc_tx_queue_rsrvd; /* sends that need to reserve an ACK/DONE msg */
398 struct list_head ibc_active_txs; /* active tx awaiting completion */
399 spinlock_t ibc_lock; /* serialise */
400 kib_rx_t *ibc_rxs; /* the rx descs */
401 kib_pages_t *ibc_rx_pages; /* premapped rx msg pages */
403 struct rdma_cm_id *ibc_cmid; /* CM id */
404 struct ib_cq *ibc_cq; /* completion queue */
406 kib_connvars_t *ibc_connvars; /* in-progress connection state */
409 #define IBLND_CONN_INIT 0 /* being intialised */
410 #define IBLND_CONN_ACTIVE_CONNECT 1 /* active sending req */
411 #define IBLND_CONN_PASSIVE_WAIT 2 /* passive waiting for rtu */
412 #define IBLND_CONN_ESTABLISHED 3 /* connection established */
413 #define IBLND_CONN_CLOSING 4 /* being closed */
414 #define IBLND_CONN_DISCONNECTED 5 /* disconnected */
416 typedef struct kib_peer
418 struct list_head ibp_list; /* stash on global peer list */
419 lnet_nid_t ibp_nid; /* who's on the other end(s) */
420 lnet_ni_t *ibp_ni; /* LNet interface */
421 atomic_t ibp_refcount; /* # users */
422 struct list_head ibp_conns; /* all active connections */
423 struct list_head ibp_tx_queue; /* msgs waiting for a conn */
424 int ibp_connecting; /* current active connection attempts */
425 int ibp_accepting; /* current passive connection attempts */
426 int ibp_error; /* errno on closing this peer */
427 cfs_time_t ibp_last_alive; /* when (in jiffies) I was last alive */
431 extern kib_data_t kiblnd_data;
432 extern kib_tunables_t kiblnd_tunables;
434 #define kiblnd_conn_addref(conn) \
436 CDEBUG(D_NET, "conn[%p] (%d)++\n", \
437 (conn), atomic_read(&(conn)->ibc_refcount)); \
438 LASSERT(atomic_read(&(conn)->ibc_refcount) > 0); \
439 atomic_inc(&(conn)->ibc_refcount); \
442 #define kiblnd_conn_decref(conn) \
444 unsigned long flags; \
446 CDEBUG(D_NET, "conn[%p] (%d)--\n", \
447 (conn), atomic_read(&(conn)->ibc_refcount)); \
448 LASSERT(atomic_read(&(conn)->ibc_refcount) > 0); \
449 if (atomic_dec_and_test(&(conn)->ibc_refcount)) { \
450 spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags); \
451 list_add_tail(&(conn)->ibc_list, \
452 &kiblnd_data.kib_connd_zombies); \
453 wake_up(&kiblnd_data.kib_connd_waitq); \
454 spin_unlock_irqrestore(&kiblnd_data.kib_connd_lock, flags); \
458 #define kiblnd_peer_addref(peer) \
460 CDEBUG(D_NET, "peer[%p] -> %s (%d)++\n", \
461 (peer), libcfs_nid2str((peer)->ibp_nid), \
462 atomic_read (&(peer)->ibp_refcount)); \
463 LASSERT(atomic_read(&(peer)->ibp_refcount) > 0); \
464 atomic_inc(&(peer)->ibp_refcount); \
467 #define kiblnd_peer_decref(peer) \
469 CDEBUG(D_NET, "peer[%p] -> %s (%d)--\n", \
470 (peer), libcfs_nid2str((peer)->ibp_nid), \
471 atomic_read (&(peer)->ibp_refcount)); \
472 LASSERT(atomic_read(&(peer)->ibp_refcount) > 0); \
473 if (atomic_dec_and_test(&(peer)->ibp_refcount)) \
474 kiblnd_destroy_peer(peer); \
477 static inline struct list_head *
478 kiblnd_nid2peerlist (lnet_nid_t nid)
480 unsigned int hash = ((unsigned int)nid) % kiblnd_data.kib_peer_hash_size;
482 return (&kiblnd_data.kib_peers [hash]);
486 kiblnd_peer_active (kib_peer_t *peer)
488 /* Am I in the peer hash table? */
489 return (!list_empty(&peer->ibp_list));
492 static inline kib_conn_t *
493 kiblnd_get_conn_locked (kib_peer_t *peer)
495 LASSERT (!list_empty(&peer->ibp_conns));
497 /* just return the first connection */
498 return list_entry(peer->ibp_conns.next, kib_conn_t, ibc_list);
502 kiblnd_send_keepalive(kib_conn_t *conn)
504 return (*kiblnd_tunables.kib_keepalive > 0) &&
505 time_after(jiffies, conn->ibc_last_send +
506 *kiblnd_tunables.kib_keepalive*HZ);
510 kiblnd_abort_receives(kib_conn_t *conn)
512 ib_modify_qp(conn->ibc_cmid->qp,
513 &kiblnd_data.kib_error_qpa, IB_QP_STATE);
516 /* CAVEAT EMPTOR: We rely on descriptor alignment to allow us to use the
517 * lowest bits of the work request id to stash the work item type. */
519 #define IBLND_WID_TX 0
520 #define IBLND_WID_RDMA 1
521 #define IBLND_WID_RX 2
522 #define IBLND_WID_MASK 3UL
525 kiblnd_ptr2wreqid (void *ptr, int type)
527 unsigned long lptr = (unsigned long)ptr;
529 LASSERT ((lptr & IBLND_WID_MASK) == 0);
530 LASSERT ((type & ~IBLND_WID_MASK) == 0);
531 return (__u64)(lptr | type);
535 kiblnd_wreqid2ptr (__u64 wreqid)
537 return (void *)(((unsigned long)wreqid) & ~IBLND_WID_MASK);
541 kiblnd_wreqid2type (__u64 wreqid)
543 return (wreqid & IBLND_WID_MASK);
547 kiblnd_set_conn_state (kib_conn_t *conn, int state)
549 conn->ibc_state = state;
553 #if IBLND_MAP_ON_DEMAND
555 kiblnd_rd_size (kib_rdma_desc_t *rd)
561 kiblnd_rd_size (kib_rdma_desc_t *rd)
566 for (i = size = 0; i < rd->rd_nfrags; i++)
567 size += rd->rd_frags[i].rf_nob;
573 #if (IBLND_OFED_VERSION == 102)
575 static inline __u64 kiblnd_dma_map_single(struct ib_device *dev,
576 void *msg, size_t size,
577 enum dma_data_direction direction)
579 return ib_dma_map_single(dev, msg, size, direction);
582 static inline void kiblnd_dma_unmap_single(struct ib_device *dev,
583 __u64 addr, size_t size,
584 enum dma_data_direction direction)
586 ib_dma_unmap_single(dev, addr, size, direction);
589 #define KIBLND_UNMAP_ADDR_SET(p, m, a) do {} while (0)
590 #define KIBLND_UNMAP_ADDR(p, m, a) (a)
592 static inline int kiblnd_dma_map_sg(struct ib_device *dev,
593 struct scatterlist *sg, int nents,
594 enum dma_data_direction direction)
596 return ib_dma_map_sg(dev, sg, nents, direction);
599 static inline void kiblnd_dma_unmap_sg(struct ib_device *dev,
600 struct scatterlist *sg, int nents,
601 enum dma_data_direction direction)
603 ib_dma_unmap_sg(dev, sg, nents, direction);
606 static inline __u64 kiblnd_sg_dma_address(struct ib_device *dev,
607 struct scatterlist *sg)
609 return ib_sg_dma_address(dev, sg);
612 static inline unsigned int kiblnd_sg_dma_len(struct ib_device *dev,
613 struct scatterlist *sg)
615 return ib_sg_dma_len(dev, sg);
618 /* XXX We use KIBLND_CONN_PARAM(e) as writable buffer, it's not strictly
619 * right because OFED1.2 defines it as const, to use it we have to add
620 * (void *) cast to overcome "const" */
622 #define KIBLND_CONN_PARAM(e) ((e)->param.conn.private_data)
623 #define KIBLND_CONN_PARAM_LEN(e) ((e)->param.conn.private_data_len)
625 #elif (IBLND_OFED_VERSION == 101)
627 static inline dma_addr_t kiblnd_dma_map_single(struct ib_device *dev,
628 void *msg, size_t size,
629 enum dma_data_direction direction)
631 return dma_map_single(dev->dma_device, msg, size, direction);
634 static inline void kiblnd_dma_unmap_single(struct ib_device *dev,
635 dma_addr_t addr, size_t size,
636 enum dma_data_direction direction)
638 dma_unmap_single(dev->dma_device, addr, size, direction);
641 #define KIBLND_UNMAP_ADDR_SET(p, m, a) pci_unmap_addr_set(p, m, a)
642 #define KIBLND_UNMAP_ADDR(p, m, a) pci_unmap_addr(p, m)
644 static inline int kiblnd_dma_map_sg(struct ib_device *dev,
645 struct scatterlist *sg, int nents,
646 enum dma_data_direction direction)
648 return dma_map_sg(dev->dma_device, sg, nents, direction);
651 static inline void kiblnd_dma_unmap_sg(struct ib_device *dev,
652 struct scatterlist *sg, int nents,
653 enum dma_data_direction direction)
655 return dma_unmap_sg(dev->dma_device, sg, nents, direction);
659 static inline dma_addr_t kiblnd_sg_dma_address(struct ib_device *dev,
660 struct scatterlist *sg)
662 return sg_dma_address(sg);
666 static inline unsigned int kiblnd_sg_dma_len(struct ib_device *dev,
667 struct scatterlist *sg)
669 return sg_dma_len(sg);
672 #define KIBLND_CONN_PARAM(e) ((e)->private_data)
673 #define KIBLND_CONN_PARAM_LEN(e) ((e)->private_data_len)
677 int kiblnd_startup (lnet_ni_t *ni);
678 void kiblnd_shutdown (lnet_ni_t *ni);
679 int kiblnd_ctl (lnet_ni_t *ni, unsigned int cmd, void *arg);
681 int kiblnd_tunables_init(void);
682 void kiblnd_tunables_fini(void);
684 int kiblnd_connd (void *arg);
685 int kiblnd_scheduler(void *arg);
686 int kiblnd_thread_start (int (*fn)(void *arg), void *arg);
688 int kiblnd_alloc_pages (kib_pages_t **pp, int npages);
689 void kiblnd_free_pages (kib_pages_t *p);
691 int kiblnd_cm_callback(struct rdma_cm_id *cmid,
692 struct rdma_cm_event *event);
694 int kiblnd_create_peer (lnet_ni_t *ni, kib_peer_t **peerp, lnet_nid_t nid);
695 void kiblnd_destroy_peer (kib_peer_t *peer);
696 void kiblnd_destroy_dev (kib_dev_t *dev);
697 void kiblnd_unlink_peer_locked (kib_peer_t *peer);
698 void kiblnd_peer_alive (kib_peer_t *peer);
699 kib_peer_t *kiblnd_find_peer_locked (lnet_nid_t nid);
700 void kiblnd_peer_connect_failed (kib_peer_t *peer, int active, int error);
701 int kiblnd_close_stale_conns_locked (kib_peer_t *peer, __u64 incarnation);
703 void kiblnd_connreq_done(kib_conn_t *conn, int status);
704 kib_conn_t *kiblnd_create_conn (kib_peer_t *peer, struct rdma_cm_id *cmid,
706 void kiblnd_destroy_conn (kib_conn_t *conn);
707 void kiblnd_close_conn (kib_conn_t *conn, int error);
708 void kiblnd_close_conn_locked (kib_conn_t *conn, int error);
710 int kiblnd_init_rdma (lnet_ni_t *ni, kib_tx_t *tx, int type,
711 int nob, kib_rdma_desc_t *dstrd, __u64 dstcookie);
713 void kiblnd_queue_tx_locked (kib_tx_t *tx, kib_conn_t *conn);
714 void kiblnd_queue_tx (kib_tx_t *tx, kib_conn_t *conn);
715 void kiblnd_init_tx_msg (lnet_ni_t *ni, kib_tx_t *tx, int type, int body_nob);
716 void kiblnd_txlist_done (lnet_ni_t *ni, struct list_head *txlist, int status);
717 void kiblnd_check_sends (kib_conn_t *conn);
719 void kiblnd_qp_event(struct ib_event *event, void *arg);
720 void kiblnd_cq_event(struct ib_event *event, void *arg);
721 void kiblnd_cq_completion(struct ib_cq *cq, void *arg);
723 void kiblnd_init_msg (kib_msg_t *msg, int type, int body_nob);
724 void kiblnd_pack_msg (lnet_ni_t *ni, kib_msg_t *msg,
725 int credits, lnet_nid_t dstnid, __u64 dststamp);
726 int kiblnd_unpack_msg(kib_msg_t *msg, int nob);
727 int kiblnd_post_rx (kib_rx_t *rx, int credit);
729 int kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg);
730 int kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
731 unsigned int niov, struct iovec *iov, lnet_kiov_t *kiov,
732 unsigned int offset, unsigned int mlen, unsigned int rlen);