1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/klnds/o2iblnd/o2iblnd.h
38 * Author: Eric Barton <eric@bartonsoftware.com>
42 # define EXPORT_SYMTAB
44 #ifndef AUTOCONF_INCLUDED
45 #include <linux/config.h>
47 #include <linux/module.h>
48 #include <linux/kernel.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>
57 #include <asm/system.h>
58 #include <asm/uaccess.h>
61 #include <linux/init.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/random.h>
69 #include <linux/pci.h>
74 #define DEBUG_SUBSYSTEM S_LND
76 #include <libcfs/libcfs.h>
77 #include <lnet/lnet.h>
78 #include <lnet/lib-lnet.h>
84 #include <rdma/rdma_cm.h>
85 #include <rdma/ib_cm.h>
86 #include <rdma/ib_verbs.h>
87 #include <rdma/ib_fmr_pool.h>
89 /* tunables fixed at compile time */
91 # define IBLND_N_SCHED num_online_cpus() /* # schedulers */
93 # define IBLND_N_SCHED 1 /* # schedulers */
96 #define IBLND_PEER_HASH_SIZE 101 /* # peer lists */
97 #define IBLND_RESCHED 100 /* # scheduler loops before reschedule */
98 #define IBLND_MSG_QUEUE_SIZE 8 /* # messages/RDMAs in-flight */
99 #define IBLND_CREDIT_HIGHWATER 7 /* when eagerly to return credits */
100 #define IBLND_MSG_SIZE (4<<10) /* max size of queued messages (inc hdr) */
102 #define IBLND_MAP_ON_DEMAND 0
103 #if IBLND_MAP_ON_DEMAND
104 # define IBLND_MAX_RDMA_FRAGS 1
106 # define IBLND_MAX_RDMA_FRAGS LNET_MAX_IOV
109 /************************/
110 /* derived constants... */
112 /* TX messages (shared by all connections) */
113 #define IBLND_TX_MSGS() (*kiblnd_tunables.kib_ntx)
114 #define IBLND_TX_MSG_BYTES() (IBLND_TX_MSGS() * IBLND_MSG_SIZE)
115 #define IBLND_TX_MSG_PAGES() ((IBLND_TX_MSG_BYTES() + PAGE_SIZE - 1)/PAGE_SIZE)
117 /* RX messages (per connection) */
118 #define IBLND_RX_MSGS (IBLND_MSG_QUEUE_SIZE * 2)
119 #define IBLND_RX_MSG_BYTES (IBLND_RX_MSGS * IBLND_MSG_SIZE)
120 #define IBLND_RX_MSG_PAGES ((IBLND_RX_MSG_BYTES + PAGE_SIZE - 1)/PAGE_SIZE)
122 /* WRs and CQEs (per connection) */
123 #define IBLND_RECV_WRS IBLND_RX_MSGS
124 #define IBLND_SEND_WRS ((*kiblnd_tunables.kib_concurrent_sends) * \
125 (1 + IBLND_MAX_RDMA_FRAGS))
126 #define IBLND_CQ_ENTRIES() (IBLND_RECV_WRS + IBLND_SEND_WRS)
130 unsigned int *kib_service; /* IB service number */
131 int *kib_min_reconnect_interval; /* first failed connection retry... */
132 int *kib_max_reconnect_interval; /* ...exponentially increasing to this */
133 int *kib_cksum; /* checksum kib_msg_t? */
134 int *kib_timeout; /* comms timeout (seconds) */
135 int *kib_keepalive; /* keepalive timeout (seconds) */
136 int *kib_ntx; /* # tx descs */
137 int *kib_credits; /* # concurrent sends */
138 int *kib_peercredits; /* # concurrent sends to 1 peer */
139 char **kib_default_ipif; /* default IPoIB interface */
140 int *kib_retry_count;
141 int *kib_rnr_retry_count;
142 int *kib_concurrent_sends; /* send work queue sizing */
143 int *kib_ib_mtu; /* IB MTU */
144 #if IBLND_MAP_ON_DEMAND
145 int *kib_fmr_pool_size; /* # FMRs in pool */
146 int *kib_fmr_flush_trigger; /* When to trigger FMR flush */
147 int *kib_fmr_cache; /* enable FMR pool cache? */
149 #if defined(CONFIG_SYSCTL) && !CFS_SYSFS_MODULE_PARM
150 cfs_sysctl_table_header_t *kib_sysctl; /* sysctl interface */
156 int ibp_npages; /* # pages */
157 struct page *ibp_pages[0];
162 struct list_head ibd_list; /* chain on kib_devs */
163 __u32 ibd_ifip; /* IPoIB interface IP */
164 char ibd_ifname[32]; /* IPoIB interface name */
165 int ibd_nnets; /* # nets extant */
167 struct rdma_cm_id *ibd_cmid; /* IB listener (bound to 1 device) */
168 struct ib_pd *ibd_pd; /* PD for the device */
169 struct ib_mr *ibd_mr; /* MR for non RDMA I/O */
174 __u64 ibn_incarnation; /* my epoch */
175 int ibn_init; /* initialisation state */
176 int ibn_shutdown; /* shutting down? */
178 atomic_t ibn_npeers; /* # peers extant */
179 atomic_t ibn_nconns; /* # connections extant */
181 struct kib_tx *ibn_tx_descs; /* all the tx descriptors */
182 kib_pages_t *ibn_tx_pages; /* premapped tx msg pages */
183 struct list_head ibn_idle_txs; /* idle tx descriptors */
184 spinlock_t ibn_tx_lock; /* serialise */
186 #if IBLND_MAP_ON_DEMAND
187 struct ib_fmr_pool *ibn_fmrpool; /* FMR pool for RDMA I/O */
190 kib_dev_t *ibn_dev; /* underlying IB device */
195 int kib_init; /* initialisation state */
196 int kib_shutdown; /* shut down? */
197 struct list_head kib_devs; /* IB devices extant */
198 atomic_t kib_nthreads; /* # live threads */
199 rwlock_t kib_global_lock; /* stabilize net/dev/peer/conn ops */
201 struct list_head *kib_peers; /* hash table of all my known peers */
202 int kib_peer_hash_size; /* size of kib_peers */
204 void *kib_connd; /* the connd task (serialisation assertions) */
205 struct list_head kib_connd_conns; /* connections to setup/teardown */
206 struct list_head kib_connd_zombies; /* connections with zero refcount */
207 wait_queue_head_t kib_connd_waitq; /* connection daemon sleeps here */
208 spinlock_t kib_connd_lock; /* serialise */
210 wait_queue_head_t kib_sched_waitq; /* schedulers sleep here */
211 struct list_head kib_sched_conns; /* conns to check for rx completions */
212 spinlock_t kib_sched_lock; /* serialise */
214 __u64 kib_next_tx_cookie; /* RDMA completion cookie */
215 struct ib_qp_attr kib_error_qpa; /* QP->ERROR */
218 #define IBLND_INIT_NOTHING 0
219 #define IBLND_INIT_DATA 1
220 #define IBLND_INIT_ALL 2
222 /************************************************************************
223 * IB Wire message format.
224 * These are sent in sender's byte order (i.e. receiver flips).
227 typedef struct kib_connparams
229 __u16 ibcp_queue_depth;
230 __u16 ibcp_max_frags;
231 __u32 ibcp_max_msg_size;
232 } WIRE_ATTR kib_connparams_t;
236 lnet_hdr_t ibim_hdr; /* portals header */
237 char ibim_payload[0]; /* piggy-backed payload */
238 } WIRE_ATTR kib_immediate_msg_t;
240 #if IBLND_MAP_ON_DEMAND
243 __u64 rd_addr; /* IO VMA address */
244 __u32 rd_nob; /* # of bytes */
245 __u32 rd_key; /* remote key */
246 } WIRE_ATTR kib_rdma_desc_t;
250 __u32 rf_nob; /* # bytes this frag */
251 __u64 rf_addr; /* CAVEAT EMPTOR: misaligned!! */
252 } WIRE_ATTR kib_rdma_frag_t;
256 __u32 rd_key; /* local/remote key */
257 __u32 rd_nfrags; /* # fragments */
258 kib_rdma_frag_t rd_frags[0]; /* buffer frags */
259 } WIRE_ATTR kib_rdma_desc_t;
264 lnet_hdr_t ibprm_hdr; /* portals header */
265 __u64 ibprm_cookie; /* opaque completion cookie */
266 } WIRE_ATTR kib_putreq_msg_t;
270 __u64 ibpam_src_cookie; /* reflected completion cookie */
271 __u64 ibpam_dst_cookie; /* opaque completion cookie */
272 kib_rdma_desc_t ibpam_rd; /* sender's sink buffer */
273 } WIRE_ATTR kib_putack_msg_t;
277 lnet_hdr_t ibgm_hdr; /* portals header */
278 __u64 ibgm_cookie; /* opaque completion cookie */
279 kib_rdma_desc_t ibgm_rd; /* rdma descriptor */
280 } WIRE_ATTR kib_get_msg_t;
284 __u64 ibcm_cookie; /* opaque completion cookie */
285 __s32 ibcm_status; /* < 0 failure: >= 0 length */
286 } WIRE_ATTR kib_completion_msg_t;
290 /* First 2 fields fixed FOR ALL TIME */
291 __u32 ibm_magic; /* I'm an openibnal message */
292 __u16 ibm_version; /* this is my version number */
294 __u8 ibm_type; /* msg type */
295 __u8 ibm_credits; /* returned credits */
296 __u32 ibm_nob; /* # bytes in whole message */
297 __u32 ibm_cksum; /* checksum (0 == no checksum) */
298 __u64 ibm_srcnid; /* sender's NID */
299 __u64 ibm_srcstamp; /* sender's incarnation */
300 __u64 ibm_dstnid; /* destination's NID */
301 __u64 ibm_dststamp; /* destination's incarnation */
304 kib_connparams_t connparams;
305 kib_immediate_msg_t immediate;
306 kib_putreq_msg_t putreq;
307 kib_putack_msg_t putack;
309 kib_completion_msg_t completion;
311 } WIRE_ATTR kib_msg_t;
313 #define IBLND_MSG_MAGIC LNET_PROTO_IB_MAGIC /* unique magic */
315 #define IBLND_MSG_VERSION 0x11
317 #define IBLND_MSG_CONNREQ 0xc0 /* connection request */
318 #define IBLND_MSG_CONNACK 0xc1 /* connection acknowledge */
319 #define IBLND_MSG_NOOP 0xd0 /* nothing (just credits) */
320 #define IBLND_MSG_IMMEDIATE 0xd1 /* immediate */
321 #define IBLND_MSG_PUT_REQ 0xd2 /* putreq (src->sink) */
322 #define IBLND_MSG_PUT_NAK 0xd3 /* completion (sink->src) */
323 #define IBLND_MSG_PUT_ACK 0xd4 /* putack (sink->src) */
324 #define IBLND_MSG_PUT_DONE 0xd5 /* completion (src->sink) */
325 #define IBLND_MSG_GET_REQ 0xd6 /* getreq (sink->src) */
326 #define IBLND_MSG_GET_DONE 0xd7 /* completion (src->sink: all OK) */
329 __u32 ibr_magic; /* sender's magic */
330 __u16 ibr_version; /* sender's version */
331 __u8 ibr_why; /* reject reason */
332 } WIRE_ATTR kib_rej_t;
335 /* connection rejection reasons */
336 #define IBLND_REJECT_CONN_RACE 1 /* You lost connection race */
337 #define IBLND_REJECT_NO_RESOURCES 2 /* Out of memory/conns etc */
338 #define IBLND_REJECT_FATAL 3 /* Anything else */
340 /***********************************************************************/
342 typedef struct kib_rx /* receive message */
344 struct list_head rx_list; /* queue for attention */
345 struct kib_conn *rx_conn; /* owning conn */
346 int rx_nob; /* # bytes received (-1 while posted) */
347 enum ib_wc_status rx_status; /* completion status */
348 kib_msg_t *rx_msg; /* message buffer (host vaddr) */
349 __u64 rx_msgaddr; /* message buffer (I/O addr) */
350 DECLARE_PCI_UNMAP_ADDR (rx_msgunmap); /* for dma_unmap_single() */
351 struct ib_recv_wr rx_wrq; /* receive work item... */
352 struct ib_sge rx_sge; /* ...and its memory */
355 #define IBLND_POSTRX_DONT_POST 0 /* don't post */
356 #define IBLND_POSTRX_NO_CREDIT 1 /* post: no credits */
357 #define IBLND_POSTRX_PEER_CREDIT 2 /* post: give peer back 1 credit */
358 #define IBLND_POSTRX_RSRVD_CREDIT 3 /* post: give myself back 1 reserved credit */
360 typedef struct kib_tx /* transmit message */
362 struct list_head tx_list; /* queue on idle_txs ibc_tx_queue etc. */
363 struct kib_conn *tx_conn; /* owning conn */
364 int tx_sending; /* # tx callbacks outstanding */
365 int tx_queued; /* queued for sending */
366 int tx_waiting; /* waiting for peer */
367 int tx_status; /* LNET completion status */
368 unsigned long tx_deadline; /* completion deadline */
369 __u64 tx_cookie; /* completion cookie */
370 lnet_msg_t *tx_lntmsg[2]; /* lnet msgs to finalize on completion */
371 kib_msg_t *tx_msg; /* message buffer (host vaddr) */
372 __u64 tx_msgaddr; /* message buffer (I/O addr) */
373 DECLARE_PCI_UNMAP_ADDR (tx_msgunmap); /* for dma_unmap_single() */
374 int tx_nwrq; /* # send work items */
375 #if IBLND_MAP_ON_DEMAND
376 struct ib_send_wr tx_wrq[2]; /* send work items... */
377 struct ib_sge tx_sge[2]; /* ...and their memory */
378 kib_rdma_desc_t tx_rd[1]; /* rdma descriptor */
379 __u64 *tx_pages; /* rdma phys page addrs */
380 struct ib_pool_fmr *tx_fmr; /* rdma mapping (mapped if != NULL) */
382 struct ib_send_wr *tx_wrq; /* send work items... */
383 struct ib_sge *tx_sge; /* ...and their memory */
384 kib_rdma_desc_t *tx_rd; /* rdma descriptor */
385 int tx_nfrags; /* # entries in... */
386 struct scatterlist *tx_frags; /* dma_map_sg descriptor */
387 int tx_dmadir; /* dma direction */
391 typedef struct kib_connvars
393 /* connection-in-progress variables */
397 typedef struct kib_conn
399 struct kib_peer *ibc_peer; /* owning peer */
400 struct list_head ibc_list; /* stash on peer's conn list */
401 struct list_head ibc_sched_list; /* schedule for attention */
402 __u64 ibc_incarnation; /* which instance of the peer */
403 atomic_t ibc_refcount; /* # users */
404 int ibc_state; /* what's happening */
405 int ibc_nsends_posted; /* # uncompleted sends */
406 int ibc_credits; /* # credits I have */
407 int ibc_outstanding_credits; /* # credits to return */
408 int ibc_reserved_credits;/* # ACK/DONE msg credits */
409 int ibc_comms_error; /* set on comms error */
410 int ibc_nrx:8; /* receive buffers owned */
411 int ibc_scheduled:1; /* scheduled for attention */
412 int ibc_ready:1; /* CQ callback fired */
413 unsigned long ibc_last_send; /* time of last send */
414 struct list_head ibc_early_rxs; /* rxs completed before ESTABLISHED */
415 struct list_head ibc_tx_noops; /* IBLND_MSG_NOOPs */
416 struct list_head ibc_tx_queue; /* sends that need a credit */
417 struct list_head ibc_tx_queue_nocred;/* sends that don't need a credit */
418 struct list_head ibc_tx_queue_rsrvd; /* sends that need to reserve an ACK/DONE msg */
419 struct list_head ibc_active_txs; /* active tx awaiting completion */
420 spinlock_t ibc_lock; /* serialise */
421 kib_rx_t *ibc_rxs; /* the rx descs */
422 kib_pages_t *ibc_rx_pages; /* premapped rx msg pages */
424 struct rdma_cm_id *ibc_cmid; /* CM id */
425 struct ib_cq *ibc_cq; /* completion queue */
427 kib_connvars_t *ibc_connvars; /* in-progress connection state */
430 #define IBLND_CONN_INIT 0 /* being intialised */
431 #define IBLND_CONN_ACTIVE_CONNECT 1 /* active sending req */
432 #define IBLND_CONN_PASSIVE_WAIT 2 /* passive waiting for rtu */
433 #define IBLND_CONN_ESTABLISHED 3 /* connection established */
434 #define IBLND_CONN_CLOSING 4 /* being closed */
435 #define IBLND_CONN_DISCONNECTED 5 /* disconnected */
437 typedef struct kib_peer
439 struct list_head ibp_list; /* stash on global peer list */
440 lnet_nid_t ibp_nid; /* who's on the other end(s) */
441 lnet_ni_t *ibp_ni; /* LNet interface */
442 atomic_t ibp_refcount; /* # users */
443 struct list_head ibp_conns; /* all active connections */
444 struct list_head ibp_tx_queue; /* msgs waiting for a conn */
445 int ibp_connecting; /* current active connection attempts */
446 int ibp_accepting; /* current passive connection attempts */
447 int ibp_error; /* errno on closing this peer */
448 cfs_time_t ibp_last_alive; /* when (in jiffies) I was last alive */
452 extern kib_data_t kiblnd_data;
453 extern kib_tunables_t kiblnd_tunables;
455 #define kiblnd_conn_addref(conn) \
457 CDEBUG(D_NET, "conn[%p] (%d)++\n", \
458 (conn), atomic_read(&(conn)->ibc_refcount)); \
459 LASSERT(atomic_read(&(conn)->ibc_refcount) > 0); \
460 atomic_inc(&(conn)->ibc_refcount); \
463 #define kiblnd_conn_decref(conn) \
465 unsigned long flags; \
467 CDEBUG(D_NET, "conn[%p] (%d)--\n", \
468 (conn), atomic_read(&(conn)->ibc_refcount)); \
469 LASSERT(atomic_read(&(conn)->ibc_refcount) > 0); \
470 if (atomic_dec_and_test(&(conn)->ibc_refcount)) { \
471 spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags); \
472 list_add_tail(&(conn)->ibc_list, \
473 &kiblnd_data.kib_connd_zombies); \
474 wake_up(&kiblnd_data.kib_connd_waitq); \
475 spin_unlock_irqrestore(&kiblnd_data.kib_connd_lock, flags); \
479 #define kiblnd_peer_addref(peer) \
481 CDEBUG(D_NET, "peer[%p] -> %s (%d)++\n", \
482 (peer), libcfs_nid2str((peer)->ibp_nid), \
483 atomic_read (&(peer)->ibp_refcount)); \
484 LASSERT(atomic_read(&(peer)->ibp_refcount) > 0); \
485 atomic_inc(&(peer)->ibp_refcount); \
488 #define kiblnd_peer_decref(peer) \
490 CDEBUG(D_NET, "peer[%p] -> %s (%d)--\n", \
491 (peer), libcfs_nid2str((peer)->ibp_nid), \
492 atomic_read (&(peer)->ibp_refcount)); \
493 LASSERT(atomic_read(&(peer)->ibp_refcount) > 0); \
494 if (atomic_dec_and_test(&(peer)->ibp_refcount)) \
495 kiblnd_destroy_peer(peer); \
498 static inline struct list_head *
499 kiblnd_nid2peerlist (lnet_nid_t nid)
501 unsigned int hash = ((unsigned int)nid) % kiblnd_data.kib_peer_hash_size;
503 return (&kiblnd_data.kib_peers [hash]);
507 kiblnd_peer_active (kib_peer_t *peer)
509 /* Am I in the peer hash table? */
510 return (!list_empty(&peer->ibp_list));
513 static inline kib_conn_t *
514 kiblnd_get_conn_locked (kib_peer_t *peer)
516 LASSERT (!list_empty(&peer->ibp_conns));
518 /* just return the first connection */
519 return list_entry(peer->ibp_conns.next, kib_conn_t, ibc_list);
523 kiblnd_send_keepalive(kib_conn_t *conn)
525 return (*kiblnd_tunables.kib_keepalive > 0) &&
526 time_after(jiffies, conn->ibc_last_send +
527 *kiblnd_tunables.kib_keepalive*HZ);
531 kiblnd_send_noop(kib_conn_t *conn)
533 LASSERT (conn->ibc_state >= IBLND_CONN_ESTABLISHED);
535 if (conn->ibc_outstanding_credits < IBLND_CREDIT_HIGHWATER &&
536 !kiblnd_send_keepalive(conn))
537 return 0; /* No need to send NOOP */
539 if (!list_empty(&conn->ibc_tx_noops) || /* NOOP already queued */
540 !list_empty(&conn->ibc_tx_queue_nocred) || /* can be piggybacked */
541 conn->ibc_credits == 0) /* no credit */
544 if (conn->ibc_credits == 1 && /* last credit reserved for */
545 conn->ibc_outstanding_credits == 0) /* giving back credits */
548 /* No tx to piggyback NOOP onto or no credit to send a tx */
549 return (list_empty(&conn->ibc_tx_queue) || conn->ibc_credits == 1);
553 kiblnd_abort_receives(kib_conn_t *conn)
555 ib_modify_qp(conn->ibc_cmid->qp,
556 &kiblnd_data.kib_error_qpa, IB_QP_STATE);
559 /* CAVEAT EMPTOR: We rely on descriptor alignment to allow us to use the
560 * lowest bits of the work request id to stash the work item type. */
562 #define IBLND_WID_TX 0
563 #define IBLND_WID_RDMA 1
564 #define IBLND_WID_RX 2
565 #define IBLND_WID_MASK 3UL
568 kiblnd_ptr2wreqid (void *ptr, int type)
570 unsigned long lptr = (unsigned long)ptr;
572 LASSERT ((lptr & IBLND_WID_MASK) == 0);
573 LASSERT ((type & ~IBLND_WID_MASK) == 0);
574 return (__u64)(lptr | type);
578 kiblnd_wreqid2ptr (__u64 wreqid)
580 return (void *)(((unsigned long)wreqid) & ~IBLND_WID_MASK);
584 kiblnd_wreqid2type (__u64 wreqid)
586 return (wreqid & IBLND_WID_MASK);
590 kiblnd_set_conn_state (kib_conn_t *conn, int state)
592 conn->ibc_state = state;
596 #if IBLND_MAP_ON_DEMAND
598 kiblnd_rd_size (kib_rdma_desc_t *rd)
604 kiblnd_rd_size (kib_rdma_desc_t *rd)
609 for (i = size = 0; i < rd->rd_nfrags; i++)
610 size += rd->rd_frags[i].rf_nob;
616 #ifdef HAVE_OFED_IB_DMA_MAP
618 static inline __u64 kiblnd_dma_map_single(struct ib_device *dev,
619 void *msg, size_t size,
620 enum dma_data_direction direction)
622 return ib_dma_map_single(dev, msg, size, direction);
625 static inline void kiblnd_dma_unmap_single(struct ib_device *dev,
626 __u64 addr, size_t size,
627 enum dma_data_direction direction)
629 ib_dma_unmap_single(dev, addr, size, direction);
632 #define KIBLND_UNMAP_ADDR_SET(p, m, a) do {} while (0)
633 #define KIBLND_UNMAP_ADDR(p, m, a) (a)
635 static inline int kiblnd_dma_map_sg(struct ib_device *dev,
636 struct scatterlist *sg, int nents,
637 enum dma_data_direction direction)
639 return ib_dma_map_sg(dev, sg, nents, direction);
642 static inline void kiblnd_dma_unmap_sg(struct ib_device *dev,
643 struct scatterlist *sg, int nents,
644 enum dma_data_direction direction)
646 ib_dma_unmap_sg(dev, sg, nents, direction);
649 static inline __u64 kiblnd_sg_dma_address(struct ib_device *dev,
650 struct scatterlist *sg)
652 return ib_sg_dma_address(dev, sg);
655 static inline unsigned int kiblnd_sg_dma_len(struct ib_device *dev,
656 struct scatterlist *sg)
658 return ib_sg_dma_len(dev, sg);
661 /* XXX We use KIBLND_CONN_PARAM(e) as writable buffer, it's not strictly
662 * right because OFED1.2 defines it as const, to use it we have to add
663 * (void *) cast to overcome "const" */
665 #define KIBLND_CONN_PARAM(e) ((e)->param.conn.private_data)
666 #define KIBLND_CONN_PARAM_LEN(e) ((e)->param.conn.private_data_len)
670 static inline dma_addr_t kiblnd_dma_map_single(struct ib_device *dev,
671 void *msg, size_t size,
672 enum dma_data_direction direction)
674 return dma_map_single(dev->dma_device, msg, size, direction);
677 static inline void kiblnd_dma_unmap_single(struct ib_device *dev,
678 dma_addr_t addr, size_t size,
679 enum dma_data_direction direction)
681 dma_unmap_single(dev->dma_device, addr, size, direction);
684 #define KIBLND_UNMAP_ADDR_SET(p, m, a) pci_unmap_addr_set(p, m, a)
685 #define KIBLND_UNMAP_ADDR(p, m, a) pci_unmap_addr(p, m)
687 static inline int kiblnd_dma_map_sg(struct ib_device *dev,
688 struct scatterlist *sg, int nents,
689 enum dma_data_direction direction)
691 return dma_map_sg(dev->dma_device, sg, nents, direction);
694 static inline void kiblnd_dma_unmap_sg(struct ib_device *dev,
695 struct scatterlist *sg, int nents,
696 enum dma_data_direction direction)
698 return dma_unmap_sg(dev->dma_device, sg, nents, direction);
702 static inline dma_addr_t kiblnd_sg_dma_address(struct ib_device *dev,
703 struct scatterlist *sg)
705 return sg_dma_address(sg);
709 static inline unsigned int kiblnd_sg_dma_len(struct ib_device *dev,
710 struct scatterlist *sg)
712 return sg_dma_len(sg);
715 #define KIBLND_CONN_PARAM(e) ((e)->private_data)
716 #define KIBLND_CONN_PARAM_LEN(e) ((e)->private_data_len)
720 int kiblnd_startup (lnet_ni_t *ni);
721 void kiblnd_shutdown (lnet_ni_t *ni);
722 int kiblnd_ctl (lnet_ni_t *ni, unsigned int cmd, void *arg);
724 int kiblnd_tunables_init(void);
725 void kiblnd_tunables_fini(void);
727 int kiblnd_connd (void *arg);
728 int kiblnd_scheduler(void *arg);
729 int kiblnd_thread_start (int (*fn)(void *arg), void *arg);
731 int kiblnd_alloc_pages (kib_pages_t **pp, int npages);
732 void kiblnd_free_pages (kib_pages_t *p);
734 int kiblnd_cm_callback(struct rdma_cm_id *cmid,
735 struct rdma_cm_event *event);
737 int kiblnd_create_peer (lnet_ni_t *ni, kib_peer_t **peerp, lnet_nid_t nid);
738 void kiblnd_destroy_peer (kib_peer_t *peer);
739 void kiblnd_destroy_dev (kib_dev_t *dev);
740 void kiblnd_unlink_peer_locked (kib_peer_t *peer);
741 void kiblnd_peer_alive (kib_peer_t *peer);
742 kib_peer_t *kiblnd_find_peer_locked (lnet_nid_t nid);
743 void kiblnd_peer_connect_failed (kib_peer_t *peer, int active, int error);
744 int kiblnd_close_stale_conns_locked (kib_peer_t *peer, __u64 incarnation);
746 void kiblnd_connreq_done(kib_conn_t *conn, int status);
747 kib_conn_t *kiblnd_create_conn (kib_peer_t *peer, struct rdma_cm_id *cmid,
749 void kiblnd_destroy_conn (kib_conn_t *conn);
750 void kiblnd_close_conn (kib_conn_t *conn, int error);
751 void kiblnd_close_conn_locked (kib_conn_t *conn, int error);
753 int kiblnd_init_rdma (lnet_ni_t *ni, kib_tx_t *tx, int type,
754 int nob, kib_rdma_desc_t *dstrd, __u64 dstcookie);
756 void kiblnd_queue_tx_locked (kib_tx_t *tx, kib_conn_t *conn);
757 void kiblnd_queue_tx (kib_tx_t *tx, kib_conn_t *conn);
758 void kiblnd_init_tx_msg (lnet_ni_t *ni, kib_tx_t *tx, int type, int body_nob);
759 void kiblnd_txlist_done (lnet_ni_t *ni, struct list_head *txlist, int status);
760 void kiblnd_check_sends (kib_conn_t *conn);
762 void kiblnd_qp_event(struct ib_event *event, void *arg);
763 void kiblnd_cq_event(struct ib_event *event, void *arg);
764 void kiblnd_cq_completion(struct ib_cq *cq, void *arg);
766 void kiblnd_init_msg (kib_msg_t *msg, int type, int body_nob);
767 void kiblnd_pack_msg (lnet_ni_t *ni, kib_msg_t *msg,
768 int credits, lnet_nid_t dstnid, __u64 dststamp);
769 int kiblnd_unpack_msg(kib_msg_t *msg, int nob);
770 int kiblnd_post_rx (kib_rx_t *rx, int credit);
772 int kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg);
773 int kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
774 unsigned int niov, struct iovec *iov, lnet_kiov_t *kiov,
775 unsigned int offset, unsigned int mlen, unsigned int rlen);