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>
52 #include <linux/pci.h>
57 #define DEBUG_SUBSYSTEM S_LND
59 #include <libcfs/kp30.h>
60 #include <lnet/lnet.h>
61 #include <lnet/lib-lnet.h>
67 #include <rdma/rdma_cm.h>
68 #include <rdma/ib_cm.h>
69 #include <rdma/ib_verbs.h>
70 #include <rdma/ib_fmr_pool.h>
72 /* tunables fixed at compile time */
74 # define IBLND_N_SCHED num_online_cpus() /* # schedulers */
76 # define IBLND_N_SCHED 1 /* # schedulers */
79 #define IBLND_PEER_HASH_SIZE 101 /* # peer lists */
80 #define IBLND_RESCHED 100 /* # scheduler loops before reschedule */
81 #define IBLND_MSG_QUEUE_SIZE 8 /* # messages/RDMAs in-flight */
82 #define IBLND_CREDIT_HIGHWATER 7 /* when eagerly to return credits */
83 #define IBLND_MSG_SIZE (4<<10) /* max size of queued messages (inc hdr) */
85 #define IBLND_MAP_ON_DEMAND 0
86 #if IBLND_MAP_ON_DEMAND
87 # define IBLND_MAX_RDMA_FRAGS 1
89 # define IBLND_MAX_RDMA_FRAGS LNET_MAX_IOV
92 /************************/
93 /* derived constants... */
95 /* TX messages (shared by all connections) */
96 #define IBLND_TX_MSGS() (*kiblnd_tunables.kib_ntx)
97 #define IBLND_TX_MSG_BYTES() (IBLND_TX_MSGS() * IBLND_MSG_SIZE)
98 #define IBLND_TX_MSG_PAGES() ((IBLND_TX_MSG_BYTES() + PAGE_SIZE - 1)/PAGE_SIZE)
100 /* RX messages (per connection) */
101 #define IBLND_RX_MSGS (IBLND_MSG_QUEUE_SIZE*2)
102 #define IBLND_RX_MSG_BYTES (IBLND_RX_MSGS * IBLND_MSG_SIZE)
103 #define IBLND_RX_MSG_PAGES ((IBLND_RX_MSG_BYTES + PAGE_SIZE - 1)/PAGE_SIZE)
105 #define IBLND_CQ_ENTRIES() (IBLND_RX_MSGS + \
106 (*kiblnd_tunables.kib_concurrent_sends) * \
107 (1 + IBLND_MAX_RDMA_FRAGS))
111 unsigned int *kib_service; /* IB service number */
112 int *kib_min_reconnect_interval; /* first failed connection retry... */
113 int *kib_max_reconnect_interval; /* ...exponentially increasing to this */
114 int *kib_cksum; /* checksum kib_msg_t? */
115 int *kib_timeout; /* comms timeout (seconds) */
116 int *kib_keepalive; /* keepalive timeout (seconds) */
117 int *kib_ntx; /* # tx descs */
118 int *kib_credits; /* # concurrent sends */
119 int *kib_peercredits; /* # concurrent sends to 1 peer */
120 char **kib_default_ipif; /* default IPoIB interface */
121 int *kib_retry_count;
122 int *kib_rnr_retry_count;
123 int *kib_concurrent_sends; /* send work queue sizing */
124 int *kib_ib_mtu; /* IB MTU */
125 #if IBLND_MAP_ON_DEMAND
126 int *kib_fmr_pool_size; /* # FMRs in pool */
127 int *kib_fmr_flush_trigger; /* When to trigger FMR flush */
128 int *kib_fmr_cache; /* enable FMR pool cache? */
130 #if defined(CONFIG_SYSCTL) && !CFS_SYSFS_MODULE_PARM
131 cfs_sysctl_table_header_t *kib_sysctl; /* sysctl interface */
137 int ibp_npages; /* # pages */
138 struct page *ibp_pages[0];
143 struct list_head ibd_list; /* chain on kib_devs */
144 __u32 ibd_ifip; /* IPoIB interface IP */
145 char ibd_ifname[32]; /* IPoIB interface name */
146 int ibd_nnets; /* # nets extant */
148 struct rdma_cm_id *ibd_cmid; /* IB listener (bound to 1 device) */
149 struct ib_pd *ibd_pd; /* PD for the device */
150 struct ib_mr *ibd_mr; /* MR for non RDMA I/O */
155 __u64 ibn_incarnation; /* my epoch */
156 int ibn_init; /* initialisation state */
157 int ibn_shutdown; /* shutting down? */
159 atomic_t ibn_npeers; /* # peers extant */
160 atomic_t ibn_nconns; /* # connections extant */
162 struct kib_tx *ibn_tx_descs; /* all the tx descriptors */
163 kib_pages_t *ibn_tx_pages; /* premapped tx msg pages */
164 struct list_head ibn_idle_txs; /* idle tx descriptors */
165 spinlock_t ibn_tx_lock; /* serialise */
167 #if IBLND_MAP_ON_DEMAND
168 struct ib_fmr_pool *ibn_fmrpool; /* FMR pool for RDMA I/O */
171 kib_dev_t *ibn_dev; /* underlying IB device */
176 int kib_init; /* initialisation state */
177 int kib_shutdown; /* shut down? */
178 struct list_head kib_devs; /* IB devices extant */
179 atomic_t kib_nthreads; /* # live threads */
180 rwlock_t kib_global_lock; /* stabilize net/dev/peer/conn ops */
182 struct list_head *kib_peers; /* hash table of all my known peers */
183 int kib_peer_hash_size; /* size of kib_peers */
185 void *kib_connd; /* the connd task (serialisation assertions) */
186 struct list_head kib_connd_conns; /* connections to setup/teardown */
187 struct list_head kib_connd_zombies; /* connections with zero refcount */
188 wait_queue_head_t kib_connd_waitq; /* connection daemon sleeps here */
189 spinlock_t kib_connd_lock; /* serialise */
191 wait_queue_head_t kib_sched_waitq; /* schedulers sleep here */
192 struct list_head kib_sched_conns; /* conns to check for rx completions */
193 spinlock_t kib_sched_lock; /* serialise */
195 __u64 kib_next_tx_cookie; /* RDMA completion cookie */
196 struct ib_qp_attr kib_error_qpa; /* QP->ERROR */
199 #define IBLND_INIT_NOTHING 0
200 #define IBLND_INIT_DATA 1
201 #define IBLND_INIT_ALL 2
203 /************************************************************************
204 * IB Wire message format.
205 * These are sent in sender's byte order (i.e. receiver flips).
208 typedef struct kib_connparams
210 __u16 ibcp_queue_depth;
211 __u16 ibcp_max_frags;
212 __u32 ibcp_max_msg_size;
213 } WIRE_ATTR kib_connparams_t;
217 lnet_hdr_t ibim_hdr; /* portals header */
218 char ibim_payload[0]; /* piggy-backed payload */
219 } WIRE_ATTR kib_immediate_msg_t;
221 #if IBLND_MAP_ON_DEMAND
224 __u64 rd_addr; /* IO VMA address */
225 __u32 rd_nob; /* # of bytes */
226 __u32 rd_key; /* remote key */
227 } WIRE_ATTR kib_rdma_desc_t;
231 __u32 rf_nob; /* # bytes this frag */
232 __u64 rf_addr; /* CAVEAT EMPTOR: misaligned!! */
233 } WIRE_ATTR kib_rdma_frag_t;
237 __u32 rd_key; /* local/remote key */
238 __u32 rd_nfrags; /* # fragments */
239 kib_rdma_frag_t rd_frags[0]; /* buffer frags */
240 } WIRE_ATTR kib_rdma_desc_t;
245 lnet_hdr_t ibprm_hdr; /* portals header */
246 __u64 ibprm_cookie; /* opaque completion cookie */
247 } WIRE_ATTR kib_putreq_msg_t;
251 __u64 ibpam_src_cookie; /* reflected completion cookie */
252 __u64 ibpam_dst_cookie; /* opaque completion cookie */
253 kib_rdma_desc_t ibpam_rd; /* sender's sink buffer */
254 } WIRE_ATTR kib_putack_msg_t;
258 lnet_hdr_t ibgm_hdr; /* portals header */
259 __u64 ibgm_cookie; /* opaque completion cookie */
260 kib_rdma_desc_t ibgm_rd; /* rdma descriptor */
261 } WIRE_ATTR kib_get_msg_t;
265 __u64 ibcm_cookie; /* opaque completion cookie */
266 __s32 ibcm_status; /* < 0 failure: >= 0 length */
267 } WIRE_ATTR kib_completion_msg_t;
271 /* First 2 fields fixed FOR ALL TIME */
272 __u32 ibm_magic; /* I'm an openibnal message */
273 __u16 ibm_version; /* this is my version number */
275 __u8 ibm_type; /* msg type */
276 __u8 ibm_credits; /* returned credits */
277 __u32 ibm_nob; /* # bytes in whole message */
278 __u32 ibm_cksum; /* checksum (0 == no checksum) */
279 __u64 ibm_srcnid; /* sender's NID */
280 __u64 ibm_srcstamp; /* sender's incarnation */
281 __u64 ibm_dstnid; /* destination's NID */
282 __u64 ibm_dststamp; /* destination's incarnation */
285 kib_connparams_t connparams;
286 kib_immediate_msg_t immediate;
287 kib_putreq_msg_t putreq;
288 kib_putack_msg_t putack;
290 kib_completion_msg_t completion;
292 } WIRE_ATTR kib_msg_t;
294 #define IBLND_MSG_MAGIC LNET_PROTO_IB_MAGIC /* unique magic */
296 #define IBLND_MSG_VERSION 0x11
298 #define IBLND_MSG_CONNREQ 0xc0 /* connection request */
299 #define IBLND_MSG_CONNACK 0xc1 /* connection acknowledge */
300 #define IBLND_MSG_NOOP 0xd0 /* nothing (just credits) */
301 #define IBLND_MSG_IMMEDIATE 0xd1 /* immediate */
302 #define IBLND_MSG_PUT_REQ 0xd2 /* putreq (src->sink) */
303 #define IBLND_MSG_PUT_NAK 0xd3 /* completion (sink->src) */
304 #define IBLND_MSG_PUT_ACK 0xd4 /* putack (sink->src) */
305 #define IBLND_MSG_PUT_DONE 0xd5 /* completion (src->sink) */
306 #define IBLND_MSG_GET_REQ 0xd6 /* getreq (sink->src) */
307 #define IBLND_MSG_GET_DONE 0xd7 /* completion (src->sink: all OK) */
310 __u32 ibr_magic; /* sender's magic */
311 __u16 ibr_version; /* sender's version */
312 __u8 ibr_why; /* reject reason */
313 } WIRE_ATTR kib_rej_t;
316 /* connection rejection reasons */
317 #define IBLND_REJECT_CONN_RACE 1 /* You lost connection race */
318 #define IBLND_REJECT_NO_RESOURCES 2 /* Out of memory/conns etc */
319 #define IBLND_REJECT_FATAL 3 /* Anything else */
321 /***********************************************************************/
323 typedef struct kib_rx /* receive message */
325 struct list_head rx_list; /* queue for attention */
326 struct kib_conn *rx_conn; /* owning conn */
327 int rx_nob; /* # bytes received (-1 while posted) */
328 enum ib_wc_status rx_status; /* completion status */
329 kib_msg_t *rx_msg; /* message buffer (host vaddr) */
330 __u64 rx_msgaddr; /* message buffer (I/O addr) */
331 DECLARE_PCI_UNMAP_ADDR (rx_msgunmap); /* for dma_unmap_single() */
332 struct ib_recv_wr rx_wrq; /* receive work item... */
333 struct ib_sge rx_sge; /* ...and its memory */
336 #define IBLND_POSTRX_DONT_POST 0 /* don't post */
337 #define IBLND_POSTRX_NO_CREDIT 1 /* post: no credits */
338 #define IBLND_POSTRX_PEER_CREDIT 2 /* post: give peer back 1 credit */
339 #define IBLND_POSTRX_RSRVD_CREDIT 3 /* post: give myself back 1 reserved credit */
341 typedef struct kib_tx /* transmit message */
343 struct list_head tx_list; /* queue on idle_txs ibc_tx_queue etc. */
344 struct kib_conn *tx_conn; /* owning conn */
345 int tx_sending; /* # tx callbacks outstanding */
346 int tx_queued; /* queued for sending */
347 int tx_waiting; /* waiting for peer */
348 int tx_status; /* LNET completion status */
349 unsigned long tx_deadline; /* completion deadline */
350 __u64 tx_cookie; /* completion cookie */
351 lnet_msg_t *tx_lntmsg[2]; /* lnet msgs to finalize on completion */
352 kib_msg_t *tx_msg; /* message buffer (host vaddr) */
353 __u64 tx_msgaddr; /* message buffer (I/O addr) */
354 DECLARE_PCI_UNMAP_ADDR (tx_msgunmap); /* for dma_unmap_single() */
355 int tx_nwrq; /* # send work items */
356 #if IBLND_MAP_ON_DEMAND
357 struct ib_send_wr tx_wrq[2]; /* send work items... */
358 struct ib_sge tx_sge[2]; /* ...and their memory */
359 kib_rdma_desc_t tx_rd[1]; /* rdma descriptor */
360 __u64 *tx_pages; /* rdma phys page addrs */
361 struct ib_pool_fmr *tx_fmr; /* rdma mapping (mapped if != NULL) */
363 struct ib_send_wr *tx_wrq; /* send work items... */
364 struct ib_sge *tx_sge; /* ...and their memory */
365 kib_rdma_desc_t *tx_rd; /* rdma descriptor */
366 int tx_nfrags; /* # entries in... */
367 struct scatterlist *tx_frags; /* dma_map_sg descriptor */
368 int tx_dmadir; /* dma direction */
372 typedef struct kib_connvars
374 /* connection-in-progress variables */
378 typedef struct kib_conn
380 struct kib_peer *ibc_peer; /* owning peer */
381 struct list_head ibc_list; /* stash on peer's conn list */
382 struct list_head ibc_sched_list; /* schedule for attention */
383 __u64 ibc_incarnation; /* which instance of the peer */
384 atomic_t ibc_refcount; /* # users */
385 int ibc_state; /* what's happening */
386 int ibc_nsends_posted; /* # uncompleted sends */
387 int ibc_credits; /* # credits I have */
388 int ibc_outstanding_credits; /* # credits to return */
389 int ibc_reserved_credits;/* # ACK/DONE msg credits */
390 int ibc_comms_error; /* set on comms error */
391 int ibc_nrx:8; /* receive buffers owned */
392 int ibc_scheduled:1; /* scheduled for attention */
393 int ibc_ready:1; /* CQ callback fired */
394 unsigned long ibc_last_send; /* time of last send */
395 struct list_head ibc_early_rxs; /* rxs completed before ESTABLISHED */
396 struct list_head ibc_tx_queue; /* sends that need a credit */
397 struct list_head ibc_tx_queue_nocred;/* sends that don't need a credit */
398 struct list_head ibc_tx_queue_rsrvd; /* sends that need to reserve an ACK/DONE msg */
399 struct list_head ibc_active_txs; /* active tx awaiting completion */
400 spinlock_t ibc_lock; /* serialise */
401 kib_rx_t *ibc_rxs; /* the rx descs */
402 kib_pages_t *ibc_rx_pages; /* premapped rx msg pages */
404 struct rdma_cm_id *ibc_cmid; /* CM id */
405 struct ib_cq *ibc_cq; /* completion queue */
407 kib_connvars_t *ibc_connvars; /* in-progress connection state */
410 #define IBLND_CONN_INIT 0 /* being intialised */
411 #define IBLND_CONN_ACTIVE_CONNECT 1 /* active sending req */
412 #define IBLND_CONN_PASSIVE_WAIT 2 /* passive waiting for rtu */
413 #define IBLND_CONN_ESTABLISHED 3 /* connection established */
414 #define IBLND_CONN_CLOSING 4 /* being closed */
415 #define IBLND_CONN_DISCONNECTED 5 /* disconnected */
417 typedef struct kib_peer
419 struct list_head ibp_list; /* stash on global peer list */
420 lnet_nid_t ibp_nid; /* who's on the other end(s) */
421 lnet_ni_t *ibp_ni; /* LNet interface */
422 atomic_t ibp_refcount; /* # users */
423 struct list_head ibp_conns; /* all active connections */
424 struct list_head ibp_tx_queue; /* msgs waiting for a conn */
425 int ibp_connecting; /* current active connection attempts */
426 int ibp_accepting; /* current passive connection attempts */
427 int ibp_error; /* errno on closing this peer */
428 cfs_time_t ibp_last_alive; /* when (in jiffies) I was last alive */
432 extern kib_data_t kiblnd_data;
433 extern kib_tunables_t kiblnd_tunables;
435 #define kiblnd_conn_addref(conn) \
437 CDEBUG(D_NET, "conn[%p] (%d)++\n", \
438 (conn), atomic_read(&(conn)->ibc_refcount)); \
439 LASSERT(atomic_read(&(conn)->ibc_refcount) > 0); \
440 atomic_inc(&(conn)->ibc_refcount); \
443 #define kiblnd_conn_decref(conn) \
445 unsigned long flags; \
447 CDEBUG(D_NET, "conn[%p] (%d)--\n", \
448 (conn), atomic_read(&(conn)->ibc_refcount)); \
449 LASSERT(atomic_read(&(conn)->ibc_refcount) > 0); \
450 if (atomic_dec_and_test(&(conn)->ibc_refcount)) { \
451 spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags); \
452 list_add_tail(&(conn)->ibc_list, \
453 &kiblnd_data.kib_connd_zombies); \
454 wake_up(&kiblnd_data.kib_connd_waitq); \
455 spin_unlock_irqrestore(&kiblnd_data.kib_connd_lock, flags); \
459 #define kiblnd_peer_addref(peer) \
461 CDEBUG(D_NET, "peer[%p] -> %s (%d)++\n", \
462 (peer), libcfs_nid2str((peer)->ibp_nid), \
463 atomic_read (&(peer)->ibp_refcount)); \
464 LASSERT(atomic_read(&(peer)->ibp_refcount) > 0); \
465 atomic_inc(&(peer)->ibp_refcount); \
468 #define kiblnd_peer_decref(peer) \
470 CDEBUG(D_NET, "peer[%p] -> %s (%d)--\n", \
471 (peer), libcfs_nid2str((peer)->ibp_nid), \
472 atomic_read (&(peer)->ibp_refcount)); \
473 LASSERT(atomic_read(&(peer)->ibp_refcount) > 0); \
474 if (atomic_dec_and_test(&(peer)->ibp_refcount)) \
475 kiblnd_destroy_peer(peer); \
478 static inline struct list_head *
479 kiblnd_nid2peerlist (lnet_nid_t nid)
481 unsigned int hash = ((unsigned int)nid) % kiblnd_data.kib_peer_hash_size;
483 return (&kiblnd_data.kib_peers [hash]);
487 kiblnd_peer_active (kib_peer_t *peer)
489 /* Am I in the peer hash table? */
490 return (!list_empty(&peer->ibp_list));
493 static inline kib_conn_t *
494 kiblnd_get_conn_locked (kib_peer_t *peer)
496 LASSERT (!list_empty(&peer->ibp_conns));
498 /* just return the first connection */
499 return list_entry(peer->ibp_conns.next, kib_conn_t, ibc_list);
503 kiblnd_send_keepalive(kib_conn_t *conn)
505 return (*kiblnd_tunables.kib_keepalive > 0) &&
506 time_after(jiffies, conn->ibc_last_send +
507 *kiblnd_tunables.kib_keepalive*HZ);
511 kiblnd_abort_receives(kib_conn_t *conn)
513 ib_modify_qp(conn->ibc_cmid->qp,
514 &kiblnd_data.kib_error_qpa, IB_QP_STATE);
517 /* CAVEAT EMPTOR: We rely on descriptor alignment to allow us to use the
518 * lowest bits of the work request id to stash the work item type. */
520 #define IBLND_WID_TX 0
521 #define IBLND_WID_RDMA 1
522 #define IBLND_WID_RX 2
523 #define IBLND_WID_MASK 3UL
526 kiblnd_ptr2wreqid (void *ptr, int type)
528 unsigned long lptr = (unsigned long)ptr;
530 LASSERT ((lptr & IBLND_WID_MASK) == 0);
531 LASSERT ((type & ~IBLND_WID_MASK) == 0);
532 return (__u64)(lptr | type);
536 kiblnd_wreqid2ptr (__u64 wreqid)
538 return (void *)(((unsigned long)wreqid) & ~IBLND_WID_MASK);
542 kiblnd_wreqid2type (__u64 wreqid)
544 return (wreqid & IBLND_WID_MASK);
548 kiblnd_set_conn_state (kib_conn_t *conn, int state)
550 conn->ibc_state = state;
554 #if IBLND_MAP_ON_DEMAND
556 kiblnd_rd_size (kib_rdma_desc_t *rd)
562 kiblnd_rd_size (kib_rdma_desc_t *rd)
567 for (i = size = 0; i < rd->rd_nfrags; i++)
568 size += rd->rd_frags[i].rf_nob;
574 #if (IBLND_OFED_VERSION == 1020) || (IBLND_OFED_VERSION == 1025)
576 static inline __u64 kiblnd_dma_map_single(struct ib_device *dev,
577 void *msg, size_t size,
578 enum dma_data_direction direction)
580 return ib_dma_map_single(dev, msg, size, direction);
583 static inline void kiblnd_dma_unmap_single(struct ib_device *dev,
584 __u64 addr, size_t size,
585 enum dma_data_direction direction)
587 ib_dma_unmap_single(dev, addr, size, direction);
590 #define KIBLND_UNMAP_ADDR_SET(p, m, a) do {} while (0)
591 #define KIBLND_UNMAP_ADDR(p, m, a) (a)
593 static inline int kiblnd_dma_map_sg(struct ib_device *dev,
594 struct scatterlist *sg, int nents,
595 enum dma_data_direction direction)
597 return ib_dma_map_sg(dev, sg, nents, direction);
600 static inline void kiblnd_dma_unmap_sg(struct ib_device *dev,
601 struct scatterlist *sg, int nents,
602 enum dma_data_direction direction)
604 ib_dma_unmap_sg(dev, sg, nents, direction);
607 static inline __u64 kiblnd_sg_dma_address(struct ib_device *dev,
608 struct scatterlist *sg)
610 return ib_sg_dma_address(dev, sg);
613 static inline unsigned int kiblnd_sg_dma_len(struct ib_device *dev,
614 struct scatterlist *sg)
616 return ib_sg_dma_len(dev, sg);
619 /* XXX We use KIBLND_CONN_PARAM(e) as writable buffer, it's not strictly
620 * right because OFED1.2 defines it as const, to use it we have to add
621 * (void *) cast to overcome "const" */
623 #define KIBLND_CONN_PARAM(e) ((e)->param.conn.private_data)
624 #define KIBLND_CONN_PARAM_LEN(e) ((e)->param.conn.private_data_len)
626 #elif (IBLND_OFED_VERSION == 1010)
628 static inline dma_addr_t kiblnd_dma_map_single(struct ib_device *dev,
629 void *msg, size_t size,
630 enum dma_data_direction direction)
632 return dma_map_single(dev->dma_device, msg, size, direction);
635 static inline void kiblnd_dma_unmap_single(struct ib_device *dev,
636 dma_addr_t addr, size_t size,
637 enum dma_data_direction direction)
639 dma_unmap_single(dev->dma_device, addr, size, direction);
642 #define KIBLND_UNMAP_ADDR_SET(p, m, a) pci_unmap_addr_set(p, m, a)
643 #define KIBLND_UNMAP_ADDR(p, m, a) pci_unmap_addr(p, m)
645 static inline int kiblnd_dma_map_sg(struct ib_device *dev,
646 struct scatterlist *sg, int nents,
647 enum dma_data_direction direction)
649 return dma_map_sg(dev->dma_device, sg, nents, direction);
652 static inline void kiblnd_dma_unmap_sg(struct ib_device *dev,
653 struct scatterlist *sg, int nents,
654 enum dma_data_direction direction)
656 return dma_unmap_sg(dev->dma_device, sg, nents, direction);
660 static inline dma_addr_t kiblnd_sg_dma_address(struct ib_device *dev,
661 struct scatterlist *sg)
663 return sg_dma_address(sg);
667 static inline unsigned int kiblnd_sg_dma_len(struct ib_device *dev,
668 struct scatterlist *sg)
670 return sg_dma_len(sg);
673 #define KIBLND_CONN_PARAM(e) ((e)->private_data)
674 #define KIBLND_CONN_PARAM_LEN(e) ((e)->private_data_len)
678 int kiblnd_startup (lnet_ni_t *ni);
679 void kiblnd_shutdown (lnet_ni_t *ni);
680 int kiblnd_ctl (lnet_ni_t *ni, unsigned int cmd, void *arg);
682 int kiblnd_tunables_init(void);
683 void kiblnd_tunables_fini(void);
685 int kiblnd_connd (void *arg);
686 int kiblnd_scheduler(void *arg);
687 int kiblnd_thread_start (int (*fn)(void *arg), void *arg);
689 int kiblnd_alloc_pages (kib_pages_t **pp, int npages);
690 void kiblnd_free_pages (kib_pages_t *p);
692 int kiblnd_cm_callback(struct rdma_cm_id *cmid,
693 struct rdma_cm_event *event);
695 int kiblnd_create_peer (lnet_ni_t *ni, kib_peer_t **peerp, lnet_nid_t nid);
696 void kiblnd_destroy_peer (kib_peer_t *peer);
697 void kiblnd_destroy_dev (kib_dev_t *dev);
698 void kiblnd_unlink_peer_locked (kib_peer_t *peer);
699 void kiblnd_peer_alive (kib_peer_t *peer);
700 kib_peer_t *kiblnd_find_peer_locked (lnet_nid_t nid);
701 void kiblnd_peer_connect_failed (kib_peer_t *peer, int active, int error);
702 int kiblnd_close_stale_conns_locked (kib_peer_t *peer, __u64 incarnation);
704 void kiblnd_connreq_done(kib_conn_t *conn, int status);
705 kib_conn_t *kiblnd_create_conn (kib_peer_t *peer, struct rdma_cm_id *cmid,
707 void kiblnd_destroy_conn (kib_conn_t *conn);
708 void kiblnd_close_conn (kib_conn_t *conn, int error);
709 void kiblnd_close_conn_locked (kib_conn_t *conn, int error);
711 int kiblnd_init_rdma (lnet_ni_t *ni, kib_tx_t *tx, int type,
712 int nob, kib_rdma_desc_t *dstrd, __u64 dstcookie);
714 void kiblnd_queue_tx_locked (kib_tx_t *tx, kib_conn_t *conn);
715 void kiblnd_queue_tx (kib_tx_t *tx, kib_conn_t *conn);
716 void kiblnd_init_tx_msg (lnet_ni_t *ni, kib_tx_t *tx, int type, int body_nob);
717 void kiblnd_txlist_done (lnet_ni_t *ni, struct list_head *txlist, int status);
718 void kiblnd_check_sends (kib_conn_t *conn);
720 void kiblnd_qp_event(struct ib_event *event, void *arg);
721 void kiblnd_cq_event(struct ib_event *event, void *arg);
722 void kiblnd_cq_completion(struct ib_cq *cq, void *arg);
724 void kiblnd_init_msg (kib_msg_t *msg, int type, int body_nob);
725 void kiblnd_pack_msg (lnet_ni_t *ni, kib_msg_t *msg,
726 int credits, lnet_nid_t dstnid, __u64 dststamp);
727 int kiblnd_unpack_msg(kib_msg_t *msg, int nob);
728 int kiblnd_post_rx (kib_rx_t *rx, int credit);
730 int kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg);
731 int kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
732 unsigned int niov, struct iovec *iov, lnet_kiov_t *kiov,
733 unsigned int offset, unsigned int mlen, unsigned int rlen);