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/libcfs.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 /* WRs and CQEs (per connection) */
106 #define IBLND_RECV_WRS IBLND_RX_MSGS
107 #define IBLND_SEND_WRS ((*kiblnd_tunables.kib_concurrent_sends) * \
108 (1 + IBLND_MAX_RDMA_FRAGS))
109 #define IBLND_CQ_ENTRIES() (IBLND_RECV_WRS + IBLND_SEND_WRS)
113 unsigned int *kib_service; /* IB service number */
114 int *kib_min_reconnect_interval; /* first failed connection retry... */
115 int *kib_max_reconnect_interval; /* ...exponentially increasing to this */
116 int *kib_cksum; /* checksum kib_msg_t? */
117 int *kib_timeout; /* comms timeout (seconds) */
118 int *kib_keepalive; /* keepalive timeout (seconds) */
119 int *kib_ntx; /* # tx descs */
120 int *kib_credits; /* # concurrent sends */
121 int *kib_peercredits; /* # concurrent sends to 1 peer */
122 char **kib_default_ipif; /* default IPoIB interface */
123 int *kib_retry_count;
124 int *kib_rnr_retry_count;
125 int *kib_concurrent_sends; /* send work queue sizing */
126 int *kib_ib_mtu; /* IB MTU */
127 #if IBLND_MAP_ON_DEMAND
128 int *kib_fmr_pool_size; /* # FMRs in pool */
129 int *kib_fmr_flush_trigger; /* When to trigger FMR flush */
130 int *kib_fmr_cache; /* enable FMR pool cache? */
132 #if defined(CONFIG_SYSCTL) && !CFS_SYSFS_MODULE_PARM
133 cfs_sysctl_table_header_t *kib_sysctl; /* sysctl interface */
139 int ibp_npages; /* # pages */
140 struct page *ibp_pages[0];
145 struct list_head ibd_list; /* chain on kib_devs */
146 __u32 ibd_ifip; /* IPoIB interface IP */
147 char ibd_ifname[32]; /* IPoIB interface name */
148 int ibd_nnets; /* # nets extant */
150 struct rdma_cm_id *ibd_cmid; /* IB listener (bound to 1 device) */
151 struct ib_pd *ibd_pd; /* PD for the device */
152 struct ib_mr *ibd_mr; /* MR for non RDMA I/O */
157 __u64 ibn_incarnation; /* my epoch */
158 int ibn_init; /* initialisation state */
159 int ibn_shutdown; /* shutting down? */
161 atomic_t ibn_npeers; /* # peers extant */
162 atomic_t ibn_nconns; /* # connections extant */
164 struct kib_tx *ibn_tx_descs; /* all the tx descriptors */
165 kib_pages_t *ibn_tx_pages; /* premapped tx msg pages */
166 struct list_head ibn_idle_txs; /* idle tx descriptors */
167 spinlock_t ibn_tx_lock; /* serialise */
169 #if IBLND_MAP_ON_DEMAND
170 struct ib_fmr_pool *ibn_fmrpool; /* FMR pool for RDMA I/O */
173 kib_dev_t *ibn_dev; /* underlying IB device */
178 int kib_init; /* initialisation state */
179 int kib_shutdown; /* shut down? */
180 struct list_head kib_devs; /* IB devices extant */
181 atomic_t kib_nthreads; /* # live threads */
182 rwlock_t kib_global_lock; /* stabilize net/dev/peer/conn ops */
184 struct list_head *kib_peers; /* hash table of all my known peers */
185 int kib_peer_hash_size; /* size of kib_peers */
187 void *kib_connd; /* the connd task (serialisation assertions) */
188 struct list_head kib_connd_conns; /* connections to setup/teardown */
189 struct list_head kib_connd_zombies; /* connections with zero refcount */
190 wait_queue_head_t kib_connd_waitq; /* connection daemon sleeps here */
191 spinlock_t kib_connd_lock; /* serialise */
193 wait_queue_head_t kib_sched_waitq; /* schedulers sleep here */
194 struct list_head kib_sched_conns; /* conns to check for rx completions */
195 spinlock_t kib_sched_lock; /* serialise */
197 __u64 kib_next_tx_cookie; /* RDMA completion cookie */
198 struct ib_qp_attr kib_error_qpa; /* QP->ERROR */
201 #define IBLND_INIT_NOTHING 0
202 #define IBLND_INIT_DATA 1
203 #define IBLND_INIT_ALL 2
205 /************************************************************************
206 * IB Wire message format.
207 * These are sent in sender's byte order (i.e. receiver flips).
210 typedef struct kib_connparams
212 __u16 ibcp_queue_depth;
213 __u16 ibcp_max_frags;
214 __u32 ibcp_max_msg_size;
215 } WIRE_ATTR kib_connparams_t;
219 lnet_hdr_t ibim_hdr; /* portals header */
220 char ibim_payload[0]; /* piggy-backed payload */
221 } WIRE_ATTR kib_immediate_msg_t;
223 #if IBLND_MAP_ON_DEMAND
226 __u64 rd_addr; /* IO VMA address */
227 __u32 rd_nob; /* # of bytes */
228 __u32 rd_key; /* remote key */
229 } WIRE_ATTR kib_rdma_desc_t;
233 __u32 rf_nob; /* # bytes this frag */
234 __u64 rf_addr; /* CAVEAT EMPTOR: misaligned!! */
235 } WIRE_ATTR kib_rdma_frag_t;
239 __u32 rd_key; /* local/remote key */
240 __u32 rd_nfrags; /* # fragments */
241 kib_rdma_frag_t rd_frags[0]; /* buffer frags */
242 } WIRE_ATTR kib_rdma_desc_t;
247 lnet_hdr_t ibprm_hdr; /* portals header */
248 __u64 ibprm_cookie; /* opaque completion cookie */
249 } WIRE_ATTR kib_putreq_msg_t;
253 __u64 ibpam_src_cookie; /* reflected completion cookie */
254 __u64 ibpam_dst_cookie; /* opaque completion cookie */
255 kib_rdma_desc_t ibpam_rd; /* sender's sink buffer */
256 } WIRE_ATTR kib_putack_msg_t;
260 lnet_hdr_t ibgm_hdr; /* portals header */
261 __u64 ibgm_cookie; /* opaque completion cookie */
262 kib_rdma_desc_t ibgm_rd; /* rdma descriptor */
263 } WIRE_ATTR kib_get_msg_t;
267 __u64 ibcm_cookie; /* opaque completion cookie */
268 __s32 ibcm_status; /* < 0 failure: >= 0 length */
269 } WIRE_ATTR kib_completion_msg_t;
273 /* First 2 fields fixed FOR ALL TIME */
274 __u32 ibm_magic; /* I'm an openibnal message */
275 __u16 ibm_version; /* this is my version number */
277 __u8 ibm_type; /* msg type */
278 __u8 ibm_credits; /* returned credits */
279 __u32 ibm_nob; /* # bytes in whole message */
280 __u32 ibm_cksum; /* checksum (0 == no checksum) */
281 __u64 ibm_srcnid; /* sender's NID */
282 __u64 ibm_srcstamp; /* sender's incarnation */
283 __u64 ibm_dstnid; /* destination's NID */
284 __u64 ibm_dststamp; /* destination's incarnation */
287 kib_connparams_t connparams;
288 kib_immediate_msg_t immediate;
289 kib_putreq_msg_t putreq;
290 kib_putack_msg_t putack;
292 kib_completion_msg_t completion;
294 } WIRE_ATTR kib_msg_t;
296 #define IBLND_MSG_MAGIC LNET_PROTO_IB_MAGIC /* unique magic */
298 #define IBLND_MSG_VERSION 0x11
300 #define IBLND_MSG_CONNREQ 0xc0 /* connection request */
301 #define IBLND_MSG_CONNACK 0xc1 /* connection acknowledge */
302 #define IBLND_MSG_NOOP 0xd0 /* nothing (just credits) */
303 #define IBLND_MSG_IMMEDIATE 0xd1 /* immediate */
304 #define IBLND_MSG_PUT_REQ 0xd2 /* putreq (src->sink) */
305 #define IBLND_MSG_PUT_NAK 0xd3 /* completion (sink->src) */
306 #define IBLND_MSG_PUT_ACK 0xd4 /* putack (sink->src) */
307 #define IBLND_MSG_PUT_DONE 0xd5 /* completion (src->sink) */
308 #define IBLND_MSG_GET_REQ 0xd6 /* getreq (sink->src) */
309 #define IBLND_MSG_GET_DONE 0xd7 /* completion (src->sink: all OK) */
312 __u32 ibr_magic; /* sender's magic */
313 __u16 ibr_version; /* sender's version */
314 __u8 ibr_why; /* reject reason */
315 } WIRE_ATTR kib_rej_t;
318 /* connection rejection reasons */
319 #define IBLND_REJECT_CONN_RACE 1 /* You lost connection race */
320 #define IBLND_REJECT_NO_RESOURCES 2 /* Out of memory/conns etc */
321 #define IBLND_REJECT_FATAL 3 /* Anything else */
323 /***********************************************************************/
325 typedef struct kib_rx /* receive message */
327 struct list_head rx_list; /* queue for attention */
328 struct kib_conn *rx_conn; /* owning conn */
329 int rx_nob; /* # bytes received (-1 while posted) */
330 enum ib_wc_status rx_status; /* completion status */
331 kib_msg_t *rx_msg; /* message buffer (host vaddr) */
332 __u64 rx_msgaddr; /* message buffer (I/O addr) */
333 DECLARE_PCI_UNMAP_ADDR (rx_msgunmap); /* for dma_unmap_single() */
334 struct ib_recv_wr rx_wrq; /* receive work item... */
335 struct ib_sge rx_sge; /* ...and its memory */
338 #define IBLND_POSTRX_DONT_POST 0 /* don't post */
339 #define IBLND_POSTRX_NO_CREDIT 1 /* post: no credits */
340 #define IBLND_POSTRX_PEER_CREDIT 2 /* post: give peer back 1 credit */
341 #define IBLND_POSTRX_RSRVD_CREDIT 3 /* post: give myself back 1 reserved credit */
343 typedef struct kib_tx /* transmit message */
345 struct list_head tx_list; /* queue on idle_txs ibc_tx_queue etc. */
346 struct kib_conn *tx_conn; /* owning conn */
347 int tx_sending; /* # tx callbacks outstanding */
348 int tx_queued; /* queued for sending */
349 int tx_waiting; /* waiting for peer */
350 int tx_status; /* LNET completion status */
351 unsigned long tx_deadline; /* completion deadline */
352 __u64 tx_cookie; /* completion cookie */
353 lnet_msg_t *tx_lntmsg[2]; /* lnet msgs to finalize on completion */
354 kib_msg_t *tx_msg; /* message buffer (host vaddr) */
355 __u64 tx_msgaddr; /* message buffer (I/O addr) */
356 DECLARE_PCI_UNMAP_ADDR (tx_msgunmap); /* for dma_unmap_single() */
357 int tx_nwrq; /* # send work items */
358 #if IBLND_MAP_ON_DEMAND
359 struct ib_send_wr tx_wrq[2]; /* send work items... */
360 struct ib_sge tx_sge[2]; /* ...and their memory */
361 kib_rdma_desc_t tx_rd[1]; /* rdma descriptor */
362 __u64 *tx_pages; /* rdma phys page addrs */
363 struct ib_pool_fmr *tx_fmr; /* rdma mapping (mapped if != NULL) */
365 struct ib_send_wr *tx_wrq; /* send work items... */
366 struct ib_sge *tx_sge; /* ...and their memory */
367 kib_rdma_desc_t *tx_rd; /* rdma descriptor */
368 int tx_nfrags; /* # entries in... */
369 struct scatterlist *tx_frags; /* dma_map_sg descriptor */
370 int tx_dmadir; /* dma direction */
374 typedef struct kib_connvars
376 /* connection-in-progress variables */
380 typedef struct kib_conn
382 struct kib_peer *ibc_peer; /* owning peer */
383 struct list_head ibc_list; /* stash on peer's conn list */
384 struct list_head ibc_sched_list; /* schedule for attention */
385 __u64 ibc_incarnation; /* which instance of the peer */
386 atomic_t ibc_refcount; /* # users */
387 int ibc_state; /* what's happening */
388 int ibc_nsends_posted; /* # uncompleted sends */
389 int ibc_credits; /* # credits I have */
390 int ibc_outstanding_credits; /* # credits to return */
391 int ibc_reserved_credits;/* # ACK/DONE msg credits */
392 int ibc_comms_error; /* set on comms error */
393 int ibc_nrx:8; /* receive buffers owned */
394 int ibc_scheduled:1; /* scheduled for attention */
395 int ibc_ready:1; /* CQ callback fired */
396 unsigned long ibc_last_send; /* time of last send */
397 struct list_head ibc_early_rxs; /* rxs completed before ESTABLISHED */
398 struct list_head ibc_tx_noops; /* IBLND_MSG_NOOPs */
399 struct list_head ibc_tx_queue; /* sends that need a credit */
400 struct list_head ibc_tx_queue_nocred;/* sends that don't need a credit */
401 struct list_head ibc_tx_queue_rsrvd; /* sends that need to reserve an ACK/DONE msg */
402 struct list_head ibc_active_txs; /* active tx awaiting completion */
403 spinlock_t ibc_lock; /* serialise */
404 kib_rx_t *ibc_rxs; /* the rx descs */
405 kib_pages_t *ibc_rx_pages; /* premapped rx msg pages */
407 struct rdma_cm_id *ibc_cmid; /* CM id */
408 struct ib_cq *ibc_cq; /* completion queue */
410 kib_connvars_t *ibc_connvars; /* in-progress connection state */
413 #define IBLND_CONN_INIT 0 /* being intialised */
414 #define IBLND_CONN_ACTIVE_CONNECT 1 /* active sending req */
415 #define IBLND_CONN_PASSIVE_WAIT 2 /* passive waiting for rtu */
416 #define IBLND_CONN_ESTABLISHED 3 /* connection established */
417 #define IBLND_CONN_CLOSING 4 /* being closed */
418 #define IBLND_CONN_DISCONNECTED 5 /* disconnected */
420 typedef struct kib_peer
422 struct list_head ibp_list; /* stash on global peer list */
423 lnet_nid_t ibp_nid; /* who's on the other end(s) */
424 lnet_ni_t *ibp_ni; /* LNet interface */
425 atomic_t ibp_refcount; /* # users */
426 struct list_head ibp_conns; /* all active connections */
427 struct list_head ibp_tx_queue; /* msgs waiting for a conn */
428 int ibp_connecting; /* current active connection attempts */
429 int ibp_accepting; /* current passive connection attempts */
430 int ibp_error; /* errno on closing this peer */
431 cfs_time_t ibp_last_alive; /* when (in jiffies) I was last alive */
435 extern kib_data_t kiblnd_data;
436 extern kib_tunables_t kiblnd_tunables;
438 #define kiblnd_conn_addref(conn) \
440 CDEBUG(D_NET, "conn[%p] (%d)++\n", \
441 (conn), atomic_read(&(conn)->ibc_refcount)); \
442 LASSERT(atomic_read(&(conn)->ibc_refcount) > 0); \
443 atomic_inc(&(conn)->ibc_refcount); \
446 #define kiblnd_conn_decref(conn) \
448 unsigned long flags; \
450 CDEBUG(D_NET, "conn[%p] (%d)--\n", \
451 (conn), atomic_read(&(conn)->ibc_refcount)); \
452 LASSERT(atomic_read(&(conn)->ibc_refcount) > 0); \
453 if (atomic_dec_and_test(&(conn)->ibc_refcount)) { \
454 spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags); \
455 list_add_tail(&(conn)->ibc_list, \
456 &kiblnd_data.kib_connd_zombies); \
457 wake_up(&kiblnd_data.kib_connd_waitq); \
458 spin_unlock_irqrestore(&kiblnd_data.kib_connd_lock, flags); \
462 #define kiblnd_peer_addref(peer) \
464 CDEBUG(D_NET, "peer[%p] -> %s (%d)++\n", \
465 (peer), libcfs_nid2str((peer)->ibp_nid), \
466 atomic_read (&(peer)->ibp_refcount)); \
467 LASSERT(atomic_read(&(peer)->ibp_refcount) > 0); \
468 atomic_inc(&(peer)->ibp_refcount); \
471 #define kiblnd_peer_decref(peer) \
473 CDEBUG(D_NET, "peer[%p] -> %s (%d)--\n", \
474 (peer), libcfs_nid2str((peer)->ibp_nid), \
475 atomic_read (&(peer)->ibp_refcount)); \
476 LASSERT(atomic_read(&(peer)->ibp_refcount) > 0); \
477 if (atomic_dec_and_test(&(peer)->ibp_refcount)) \
478 kiblnd_destroy_peer(peer); \
481 static inline struct list_head *
482 kiblnd_nid2peerlist (lnet_nid_t nid)
484 unsigned int hash = ((unsigned int)nid) % kiblnd_data.kib_peer_hash_size;
486 return (&kiblnd_data.kib_peers [hash]);
490 kiblnd_peer_active (kib_peer_t *peer)
492 /* Am I in the peer hash table? */
493 return (!list_empty(&peer->ibp_list));
496 static inline kib_conn_t *
497 kiblnd_get_conn_locked (kib_peer_t *peer)
499 LASSERT (!list_empty(&peer->ibp_conns));
501 /* just return the first connection */
502 return list_entry(peer->ibp_conns.next, kib_conn_t, ibc_list);
506 kiblnd_send_keepalive(kib_conn_t *conn)
508 return (*kiblnd_tunables.kib_keepalive > 0) &&
509 time_after(jiffies, conn->ibc_last_send +
510 *kiblnd_tunables.kib_keepalive*HZ);
514 kiblnd_send_noop(kib_conn_t *conn)
516 LASSERT (conn->ibc_state >= IBLND_CONN_ESTABLISHED);
518 if (conn->ibc_outstanding_credits < IBLND_CREDIT_HIGHWATER &&
519 !kiblnd_send_keepalive(conn))
520 return 0; /* No need to send NOOP */
522 if (!list_empty(&conn->ibc_tx_noops) || /* NOOP already queued */
523 !list_empty(&conn->ibc_tx_queue_nocred) || /* can be piggybacked */
524 conn->ibc_credits == 0) /* no credit */
527 if (conn->ibc_credits == 1 && /* last credit reserved for */
528 conn->ibc_outstanding_credits == 0) /* giving back credits */
531 /* No tx to piggyback NOOP onto or no credit to send a tx */
532 return (list_empty(&conn->ibc_tx_queue) || conn->ibc_credits == 1);
536 kiblnd_abort_receives(kib_conn_t *conn)
538 ib_modify_qp(conn->ibc_cmid->qp,
539 &kiblnd_data.kib_error_qpa, IB_QP_STATE);
542 /* CAVEAT EMPTOR: We rely on descriptor alignment to allow us to use the
543 * lowest bits of the work request id to stash the work item type. */
545 #define IBLND_WID_TX 0
546 #define IBLND_WID_RDMA 1
547 #define IBLND_WID_RX 2
548 #define IBLND_WID_MASK 3UL
551 kiblnd_ptr2wreqid (void *ptr, int type)
553 unsigned long lptr = (unsigned long)ptr;
555 LASSERT ((lptr & IBLND_WID_MASK) == 0);
556 LASSERT ((type & ~IBLND_WID_MASK) == 0);
557 return (__u64)(lptr | type);
561 kiblnd_wreqid2ptr (__u64 wreqid)
563 return (void *)(((unsigned long)wreqid) & ~IBLND_WID_MASK);
567 kiblnd_wreqid2type (__u64 wreqid)
569 return (wreqid & IBLND_WID_MASK);
573 kiblnd_set_conn_state (kib_conn_t *conn, int state)
575 conn->ibc_state = state;
579 #if IBLND_MAP_ON_DEMAND
581 kiblnd_rd_size (kib_rdma_desc_t *rd)
587 kiblnd_rd_size (kib_rdma_desc_t *rd)
592 for (i = size = 0; i < rd->rd_nfrags; i++)
593 size += rd->rd_frags[i].rf_nob;
599 #if (IBLND_OFED_VERSION == 1020) || (IBLND_OFED_VERSION == 1025)
601 static inline __u64 kiblnd_dma_map_single(struct ib_device *dev,
602 void *msg, size_t size,
603 enum dma_data_direction direction)
605 return ib_dma_map_single(dev, msg, size, direction);
608 static inline void kiblnd_dma_unmap_single(struct ib_device *dev,
609 __u64 addr, size_t size,
610 enum dma_data_direction direction)
612 ib_dma_unmap_single(dev, addr, size, direction);
615 #define KIBLND_UNMAP_ADDR_SET(p, m, a) do {} while (0)
616 #define KIBLND_UNMAP_ADDR(p, m, a) (a)
618 static inline int kiblnd_dma_map_sg(struct ib_device *dev,
619 struct scatterlist *sg, int nents,
620 enum dma_data_direction direction)
622 return ib_dma_map_sg(dev, sg, nents, direction);
625 static inline void kiblnd_dma_unmap_sg(struct ib_device *dev,
626 struct scatterlist *sg, int nents,
627 enum dma_data_direction direction)
629 ib_dma_unmap_sg(dev, sg, nents, direction);
632 static inline __u64 kiblnd_sg_dma_address(struct ib_device *dev,
633 struct scatterlist *sg)
635 return ib_sg_dma_address(dev, sg);
638 static inline unsigned int kiblnd_sg_dma_len(struct ib_device *dev,
639 struct scatterlist *sg)
641 return ib_sg_dma_len(dev, sg);
644 /* XXX We use KIBLND_CONN_PARAM(e) as writable buffer, it's not strictly
645 * right because OFED1.2 defines it as const, to use it we have to add
646 * (void *) cast to overcome "const" */
648 #define KIBLND_CONN_PARAM(e) ((e)->param.conn.private_data)
649 #define KIBLND_CONN_PARAM_LEN(e) ((e)->param.conn.private_data_len)
651 #elif (IBLND_OFED_VERSION == 1010)
653 static inline dma_addr_t kiblnd_dma_map_single(struct ib_device *dev,
654 void *msg, size_t size,
655 enum dma_data_direction direction)
657 return dma_map_single(dev->dma_device, msg, size, direction);
660 static inline void kiblnd_dma_unmap_single(struct ib_device *dev,
661 dma_addr_t addr, size_t size,
662 enum dma_data_direction direction)
664 dma_unmap_single(dev->dma_device, addr, size, direction);
667 #define KIBLND_UNMAP_ADDR_SET(p, m, a) pci_unmap_addr_set(p, m, a)
668 #define KIBLND_UNMAP_ADDR(p, m, a) pci_unmap_addr(p, m)
670 static inline int kiblnd_dma_map_sg(struct ib_device *dev,
671 struct scatterlist *sg, int nents,
672 enum dma_data_direction direction)
674 return dma_map_sg(dev->dma_device, sg, nents, direction);
677 static inline void kiblnd_dma_unmap_sg(struct ib_device *dev,
678 struct scatterlist *sg, int nents,
679 enum dma_data_direction direction)
681 return dma_unmap_sg(dev->dma_device, sg, nents, direction);
685 static inline dma_addr_t kiblnd_sg_dma_address(struct ib_device *dev,
686 struct scatterlist *sg)
688 return sg_dma_address(sg);
692 static inline unsigned int kiblnd_sg_dma_len(struct ib_device *dev,
693 struct scatterlist *sg)
695 return sg_dma_len(sg);
698 #define KIBLND_CONN_PARAM(e) ((e)->private_data)
699 #define KIBLND_CONN_PARAM_LEN(e) ((e)->private_data_len)
703 int kiblnd_startup (lnet_ni_t *ni);
704 void kiblnd_shutdown (lnet_ni_t *ni);
705 int kiblnd_ctl (lnet_ni_t *ni, unsigned int cmd, void *arg);
707 int kiblnd_tunables_init(void);
708 void kiblnd_tunables_fini(void);
710 int kiblnd_connd (void *arg);
711 int kiblnd_scheduler(void *arg);
712 int kiblnd_thread_start (int (*fn)(void *arg), void *arg);
714 int kiblnd_alloc_pages (kib_pages_t **pp, int npages);
715 void kiblnd_free_pages (kib_pages_t *p);
717 int kiblnd_cm_callback(struct rdma_cm_id *cmid,
718 struct rdma_cm_event *event);
720 int kiblnd_create_peer (lnet_ni_t *ni, kib_peer_t **peerp, lnet_nid_t nid);
721 void kiblnd_destroy_peer (kib_peer_t *peer);
722 void kiblnd_destroy_dev (kib_dev_t *dev);
723 void kiblnd_unlink_peer_locked (kib_peer_t *peer);
724 void kiblnd_peer_alive (kib_peer_t *peer);
725 kib_peer_t *kiblnd_find_peer_locked (lnet_nid_t nid);
726 void kiblnd_peer_connect_failed (kib_peer_t *peer, int active, int error);
727 int kiblnd_close_stale_conns_locked (kib_peer_t *peer, __u64 incarnation);
729 void kiblnd_connreq_done(kib_conn_t *conn, int status);
730 kib_conn_t *kiblnd_create_conn (kib_peer_t *peer, struct rdma_cm_id *cmid,
732 void kiblnd_destroy_conn (kib_conn_t *conn);
733 void kiblnd_close_conn (kib_conn_t *conn, int error);
734 void kiblnd_close_conn_locked (kib_conn_t *conn, int error);
736 int kiblnd_init_rdma (lnet_ni_t *ni, kib_tx_t *tx, int type,
737 int nob, kib_rdma_desc_t *dstrd, __u64 dstcookie);
739 void kiblnd_queue_tx_locked (kib_tx_t *tx, kib_conn_t *conn);
740 void kiblnd_queue_tx (kib_tx_t *tx, kib_conn_t *conn);
741 void kiblnd_init_tx_msg (lnet_ni_t *ni, kib_tx_t *tx, int type, int body_nob);
742 void kiblnd_txlist_done (lnet_ni_t *ni, struct list_head *txlist, int status);
743 void kiblnd_check_sends (kib_conn_t *conn);
745 void kiblnd_qp_event(struct ib_event *event, void *arg);
746 void kiblnd_cq_event(struct ib_event *event, void *arg);
747 void kiblnd_cq_completion(struct ib_cq *cq, void *arg);
749 void kiblnd_init_msg (kib_msg_t *msg, int type, int body_nob);
750 void kiblnd_pack_msg (lnet_ni_t *ni, kib_msg_t *msg,
751 int credits, lnet_nid_t dstnid, __u64 dststamp);
752 int kiblnd_unpack_msg(kib_msg_t *msg, int nob);
753 int kiblnd_post_rx (kib_rx_t *rx, int credit);
755 int kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg);
756 int kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
757 unsigned int niov, struct iovec *iov, lnet_kiov_t *kiov,
758 unsigned int offset, unsigned int mlen, unsigned int rlen);