Whamcloud - gitweb
- back out peer_buffer_credits changes, as requested by rread.
[fs/lustre-release.git] / lnet / klnds / ptllnd / ptllnd.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
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.
11  *
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).
17  *
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
21  *
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
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lnet/klnds/ptllnd/ptllnd.h
37  *
38  * Author: PJ Kirner <pjkirner@clusterfs.com>
39  */
40
41 #ifndef EXPORT_SYMTAB
42 # define EXPORT_SYMTAB
43 #endif
44 #ifndef AUTOCONF_INCLUDED
45 #include <linux/config.h>
46 #endif
47 #include <linux/module.h>
48 #include <linux/kernel.h>
49 #include <linux/mm.h>
50 #include <linux/string.h>
51 #include <linux/stat.h>
52 #include <linux/errno.h>
53 #include <linux/smp_lock.h>
54 #include <linux/unistd.h>
55 #include <linux/uio.h>
56
57 #include <asm/system.h>
58 #include <asm/uaccess.h>
59 #include <asm/io.h>
60
61 #include <linux/init.h>
62 #include <linux/fs.h>
63 #include <linux/file.h>
64 #include <linux/stat.h>
65 #include <linux/list.h>
66 #include <linux/kmod.h>
67 #include <linux/sysctl.h>
68 #include <linux/random.h>
69
70 #include <net/sock.h>
71 #include <linux/in.h>
72
73
74 #define DEBUG_SUBSYSTEM S_LND
75
76 #include <libcfs/libcfs.h>
77 #include <lnet/lnet.h>
78 #include <lnet/lib-lnet.h>
79 #include <lnet/lnet-sysctl.h>
80 #include <portals/p30.h>
81 #ifdef CRAY_XT3
82 #include <portals/ptltrace.h>
83 #endif
84 #include <lnet/ptllnd.h>        /* Depends on portals/p30.h */
85
86 /*
87  * Define this to enable console debug logging
88  * and simulation
89  */
90 //#define PJK_DEBUGGING
91
92 #ifdef CONFIG_SMP
93 # define PTLLND_N_SCHED         num_online_cpus()   /* # schedulers */
94 #else
95 # define PTLLND_N_SCHED         1                   /* # schedulers */
96 #endif
97
98 #define PTLLND_CREDIT_HIGHWATER ((*kptllnd_tunables.kptl_peercredits)-1)
99   /* when eagerly to return credits */
100
101 typedef struct
102 {
103         int             *kptl_ntx;              /* # tx descs to pre-allocate */
104         int             *kptl_max_nodes;        /* max # nodes all talking to me */
105         int             *kptl_max_procs_per_node; /* max # processes per node */
106         int             *kptl_checksum;         /* checksum kptl_msg_t? */
107         int             *kptl_timeout;          /* comms timeout (seconds) */
108         int             *kptl_portal;           /* portal number */
109         int             *kptl_pid;              /* portals PID (self + kernel peers) */
110         int             *kptl_rxb_npages;       /* number of pages for rx buffer */
111         int             *kptl_rxb_nspare;       /* number of spare rx buffers */
112         int             *kptl_credits;          /* number of credits */
113         int             *kptl_peercredits;      /* number of credits */
114         int             *kptl_max_msg_size;     /* max immd message size*/
115         int             *kptl_peer_hash_table_size; /* # slots in peer hash table */
116         int             *kptl_reschedule_loops; /* scheduler yield loops */
117         int             *kptl_ack_puts;         /* make portals ack PUTs */
118 #ifdef CRAY_XT3
119         int             *kptl_ptltrace_on_timeout; /* dump pltrace on timeout? */
120         int             *kptl_ptltrace_on_fail;    /* dump pltrace on PTL_NAL_FAILED? */
121         char           **kptl_ptltrace_basename;  /* ptltrace dump file basename */
122 #endif
123 #ifdef PJK_DEBUGGING
124         int             *kptl_simulation_bitmap;/* simulation bitmap */
125 #endif
126
127 #if defined(CONFIG_SYSCTL) && !CFS_SYSFS_MODULE_PARM
128         cfs_sysctl_table_header_t *kptl_sysctl; /* sysctl interface */
129 #endif
130 } kptl_tunables_t;
131
132 #include "lnet/ptllnd_wire.h"
133
134 /***********************************************************************/
135
136 typedef struct kptl_data kptl_data_t;
137 typedef struct kptl_rx_buffer kptl_rx_buffer_t;
138 typedef struct kptl_peer kptl_peer_t;
139
140 typedef struct {
141         char      eva_type;
142 } kptl_eventarg_t;
143
144 #define PTLLND_EVENTARG_TYPE_MSG    0x1
145 #define PTLLND_EVENTARG_TYPE_RDMA   0x2
146 #define PTLLND_EVENTARG_TYPE_BUF    0x3
147
148 typedef struct kptl_rx                          /* receive message */
149 {
150         struct list_head        rx_list;        /* queue for attention */
151         kptl_rx_buffer_t       *rx_rxb;         /* the rx buffer pointer */
152         kptl_msg_t             *rx_msg;         /* received message */
153         int                     rx_nob;         /* received message size */
154         unsigned long           rx_treceived;   /* time received */
155         ptl_process_id_t        rx_initiator;   /* sender's address */
156 #ifdef CRAY_XT3
157         ptl_uid_t               rx_uid;         /* sender's uid */
158 #endif
159         kptl_peer_t            *rx_peer;        /* pointer to peer */
160         char                    rx_space[0];    /* copy of incoming request */
161 } kptl_rx_t;
162
163 #define PTLLND_POSTRX_DONT_POST    0            /* don't post */
164 #define PTLLND_POSTRX_NO_CREDIT    1            /* post: no credits */
165 #define PTLLND_POSTRX_PEER_CREDIT  2            /* post: give peer back 1 credit */
166
167 typedef struct kptl_rx_buffer_pool
168 {
169         spinlock_t              rxbp_lock;
170         struct list_head        rxbp_list;      /* all allocated buffers */
171         int                     rxbp_count;     /* # allocated buffers */
172         int                     rxbp_reserved;  /* # requests to buffer */
173         int                     rxbp_shutdown;  /* shutdown flag */
174 } kptl_rx_buffer_pool_t;
175
176 struct kptl_rx_buffer
177 {
178         kptl_rx_buffer_pool_t  *rxb_pool;
179         struct list_head        rxb_list;       /* for the rxb_pool list */
180         struct list_head        rxb_repost_list;/* for the kptl_sched_rxbq list */
181         int                     rxb_posted:1;   /* on the net */
182         int                     rxb_idle:1;     /* all done */
183         kptl_eventarg_t         rxb_eventarg;   /* event->md.user_ptr */
184         int                     rxb_refcount;   /* reference count */
185         ptl_handle_md_t         rxb_mdh;        /* the portals memory descriptor (MD) handle */
186         char                   *rxb_buffer;     /* the buffer */
187
188 };
189
190 enum kptl_tx_type
191 {
192         TX_TYPE_RESERVED                = 0,
193         TX_TYPE_SMALL_MESSAGE           = 1,
194         TX_TYPE_PUT_REQUEST             = 2,
195         TX_TYPE_GET_REQUEST             = 3,
196         TX_TYPE_PUT_RESPONSE            = 4,
197         TX_TYPE_GET_RESPONSE            = 5,
198 };
199
200 typedef union {
201 #ifdef _USING_LUSTRE_PORTALS_
202         struct iovec iov[PTL_MD_MAX_IOV];
203         lnet_kiov_t kiov[PTL_MD_MAX_IOV];
204 #else
205         ptl_md_iovec_t iov[PTL_MD_MAX_IOV];
206 #endif
207 } kptl_fragvec_t;
208
209 typedef struct kptl_tx                           /* transmit message */
210 {
211         struct list_head        tx_list;      /* queue on idle_txs etc */
212         atomic_t                tx_refcount;  /* reference count*/
213         enum kptl_tx_type       tx_type;      /* small msg/{put,get}{req,resp} */
214         int                     tx_active:1;  /* queued on the peer */
215         int                     tx_idle:1;    /* on the free list */
216         int                     tx_acked:1;   /* portals ACK wanted (for debug only) */
217         kptl_eventarg_t         tx_msg_eventarg; /* event->md.user_ptr */
218         kptl_eventarg_t         tx_rdma_eventarg; /* event->md.user_ptr */
219         int                     tx_status;    /* the status of this tx descriptor */
220         ptl_handle_md_t         tx_rdma_mdh;  /* RDMA buffer */
221         ptl_handle_md_t         tx_msg_mdh;   /* the portals MD handle for the initial message */
222         lnet_msg_t             *tx_lnet_msg;  /* LNET message to finalize */
223         lnet_msg_t             *tx_lnet_replymsg; /* LNET reply message to finalize */
224         kptl_msg_t             *tx_msg;       /* the message data */
225         kptl_peer_t            *tx_peer;      /* the peer this is waiting on */
226         unsigned long           tx_deadline;  /* deadline */
227         unsigned long           tx_tposted;   /* time posted */
228         ptl_md_t                tx_rdma_md;   /* rdma descriptor */
229         kptl_fragvec_t         *tx_frags;     /* buffer fragments */
230 } kptl_tx_t;
231
232 enum kptllnd_peer_state
233 {
234         PEER_STATE_UNINITIALIZED        = 0,
235         PEER_STATE_ALLOCATED            = 1,
236         PEER_STATE_WAITING_HELLO        = 2,
237         PEER_STATE_ACTIVE               = 3,
238         PEER_STATE_CLOSING              = 4,
239         PEER_STATE_ZOMBIE               = 5,
240 };
241
242 struct kptl_peer
243 {
244         struct list_head        peer_list;
245         atomic_t                peer_refcount;          /* The current refrences */
246         enum kptllnd_peer_state peer_state;
247         spinlock_t              peer_lock;              /* serialize */
248         struct list_head        peer_noops;             /* PTLLND_MSG_TYPE_NOOP txs */
249         struct list_head        peer_sendq;             /* txs waiting for mh handles */
250         struct list_head        peer_activeq;           /* txs awaiting completion */
251         lnet_process_id_t       peer_id;                /* Peer's LNET id */
252         ptl_process_id_t        peer_ptlid;             /* Peer's portals id */
253         __u64                   peer_incarnation;       /* peer's incarnation */
254         __u64                   peer_myincarnation;     /* my incarnation at HELLO */
255         int                     peer_sent_hello;        /* have I sent HELLO? */
256         int                     peer_credits;           /* number of send credits */
257         int                     peer_outstanding_credits;/* number of peer credits to return */
258         int                     peer_sent_credits;      /* #msg buffers posted for peer */
259         int                     peer_max_msg_size;      /* peer's rx buffer size */
260         int                     peer_error;             /* errno on closing this peer */
261         int                     peer_retry_noop;        /* need to retry returning credits */
262         int                     peer_check_stamp;       /* watchdog check stamp */
263         cfs_time_t              peer_last_alive;        /* when (in jiffies) I was last alive */
264         __u64                   peer_next_matchbits;    /* Next value to register RDMA from peer */
265         __u64                   peer_last_matchbits_seen; /* last matchbits used to RDMA to peer */
266 };
267
268 struct kptl_data
269 {
270         int                     kptl_init;             /* initialisation state */
271         volatile int            kptl_shutdown;         /* shut down? */
272         atomic_t                kptl_nthreads;         /* # live threads */
273         lnet_ni_t              *kptl_ni;               /* _the_ LND instance */
274         ptl_handle_ni_t         kptl_nih;              /* network inteface handle */
275         ptl_process_id_t        kptl_portals_id;       /* Portals ID of interface */
276         __u64                   kptl_incarnation;      /* which one am I */
277         ptl_handle_eq_t         kptl_eqh;              /* Event Queue (EQ) */
278
279         spinlock_t              kptl_sched_lock;       /* serialise... */
280         wait_queue_head_t       kptl_sched_waitq;      /* schedulers sleep here */
281         struct list_head        kptl_sched_txq;        /* tx requiring attention */
282         struct list_head        kptl_sched_rxq;        /* rx requiring attention */
283         struct list_head        kptl_sched_rxbq;       /* rxb requiring reposting */
284
285         wait_queue_head_t       kptl_watchdog_waitq;   /* watchdog sleeps here */
286         atomic_t                kptl_needs_ptltrace;   /* watchdog thread to dump ptltrace */
287
288         kptl_rx_buffer_pool_t   kptl_rx_buffer_pool;   /* rx buffer pool */
289         cfs_mem_cache_t*        kptl_rx_cache;         /* rx descripter cache */
290
291         atomic_t                kptl_ntx;              /* # tx descs allocated */
292         spinlock_t              kptl_tx_lock;          /* serialise idle tx list*/
293         struct list_head        kptl_idle_txs;         /* idle tx descriptors */
294
295         rwlock_t                kptl_peer_rw_lock;     /* lock for peer table */
296         struct list_head       *kptl_peers;            /* hash table of all my known peers */
297         struct list_head        kptl_closing_peers;    /* peers being closed */
298         struct list_head        kptl_zombie_peers;     /* peers waiting for refs to drain */
299         int                     kptl_peer_hash_size;   /* size of kptl_peers */
300         int                     kptl_npeers;           /* # peers extant */
301         int                     kptl_n_active_peers;   /* # active peers */
302         int                     kptl_expected_peers;   /* # peers I can buffer HELLOs from */
303
304         kptl_msg_t             *kptl_nak_msg;          /* common NAK message */
305         spinlock_t              kptl_ptlid2str_lock;   /* serialise str ops */
306 };
307
308 enum 
309 {
310         PTLLND_INIT_NOTHING = 0,
311         PTLLND_INIT_DATA,
312         PTLLND_INIT_ALL,
313 };
314
315 extern kptl_tunables_t  kptllnd_tunables;
316 extern kptl_data_t      kptllnd_data;
317
318 static inline lnet_nid_t 
319 kptllnd_ptl2lnetnid(ptl_nid_t ptl_nid)
320 {
321 #ifdef _USING_LUSTRE_PORTALS_
322         return LNET_MKNID(LNET_NIDNET(kptllnd_data.kptl_ni->ni_nid), 
323                           LNET_NIDADDR(ptl_nid));
324 #else
325         return LNET_MKNID(LNET_NIDNET(kptllnd_data.kptl_ni->ni_nid), 
326                           ptl_nid);
327 #endif
328 }
329
330 static inline ptl_nid_t 
331 kptllnd_lnet2ptlnid(lnet_nid_t lnet_nid)
332 {
333 #ifdef _USING_LUSTRE_PORTALS_
334         return LNET_MKNID(LNET_NIDNET(kptllnd_data.kptl_portals_id.nid),
335                           LNET_NIDADDR(lnet_nid));
336 #else
337         return LNET_NIDADDR(lnet_nid);
338 #endif
339 }
340
341 static inline void
342 kptllnd_schedule_ptltrace_dump (void)
343 {
344 #ifdef CRAY_XT3
345         if (*kptllnd_tunables.kptl_ptltrace_on_fail) {
346                 atomic_inc(&kptllnd_data.kptl_needs_ptltrace);
347                 wake_up(&kptllnd_data.kptl_watchdog_waitq);
348         }
349 #endif
350 }
351
352 int  kptllnd_startup(lnet_ni_t *ni);
353 void kptllnd_shutdown(lnet_ni_t *ni);
354 int  kptllnd_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg);
355 void kptllnd_query (struct lnet_ni *ni, lnet_nid_t nid, time_t *when);
356 int  kptllnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg);
357 int  kptllnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg,
358                   int delayed, unsigned int niov, 
359                   struct iovec *iov, lnet_kiov_t *kiov,
360                   unsigned int offset, unsigned int mlen, unsigned int rlen);
361 int  kptllnd_eager_recv(struct lnet_ni *ni, void *private, 
362                         lnet_msg_t *msg, void **new_privatep);
363 void kptllnd_eq_callback(ptl_event_t *evp);
364 int  kptllnd_scheduler(void *arg);
365 int  kptllnd_watchdog(void *arg);
366 int  kptllnd_thread_start(int (*fn)(void *arg), void *arg);
367 int  kptllnd_tunables_init(void);
368 void kptllnd_tunables_fini(void);
369
370 const char *kptllnd_evtype2str(int evtype);
371 const char *kptllnd_msgtype2str(int msgtype);
372 const char *kptllnd_errtype2str(int errtype);
373
374 static inline void *
375 kptllnd_eventarg2obj (kptl_eventarg_t *eva)
376 {
377         switch (eva->eva_type) {
378         default:
379                 LBUG();
380         case PTLLND_EVENTARG_TYPE_BUF:
381                 return list_entry(eva, kptl_rx_buffer_t, rxb_eventarg);
382         case PTLLND_EVENTARG_TYPE_RDMA:
383                 return list_entry(eva, kptl_tx_t, tx_rdma_eventarg);
384         case PTLLND_EVENTARG_TYPE_MSG:
385                 return list_entry(eva, kptl_tx_t, tx_msg_eventarg);
386         }
387 }
388
389 /*
390  * RX BUFFER SUPPORT FUNCTIONS
391  */
392 void kptllnd_rx_buffer_pool_init(kptl_rx_buffer_pool_t *rxbp);
393 void kptllnd_rx_buffer_pool_fini(kptl_rx_buffer_pool_t *rxbp);
394 int  kptllnd_rx_buffer_pool_reserve(kptl_rx_buffer_pool_t *rxbp, int count);
395 void kptllnd_rx_buffer_pool_unreserve(kptl_rx_buffer_pool_t *rxbp, int count);
396 void kptllnd_rx_buffer_callback(ptl_event_t *ev);
397 void kptllnd_rx_buffer_post(kptl_rx_buffer_t *rxb);
398
399 static inline int
400 kptllnd_rx_buffer_size(void)
401 {
402         return PAGE_SIZE * (*kptllnd_tunables.kptl_rxb_npages);
403 }
404
405 static inline void
406 kptllnd_rx_buffer_addref(kptl_rx_buffer_t *rxb)
407 {
408         unsigned long flags;
409         
410         spin_lock_irqsave(&rxb->rxb_pool->rxbp_lock, flags);
411         rxb->rxb_refcount++;
412         spin_unlock_irqrestore(&rxb->rxb_pool->rxbp_lock, flags);
413 }
414
415 static inline void
416 kptllnd_rx_buffer_decref_locked(kptl_rx_buffer_t *rxb)
417 {
418         if (--(rxb->rxb_refcount) == 0) {
419                 spin_lock(&kptllnd_data.kptl_sched_lock);
420         
421                 list_add_tail(&rxb->rxb_repost_list,
422                               &kptllnd_data.kptl_sched_rxbq);
423                 wake_up(&kptllnd_data.kptl_sched_waitq);
424
425                 spin_unlock(&kptllnd_data.kptl_sched_lock);
426         }
427 }
428
429 static inline void
430 kptllnd_rx_buffer_decref(kptl_rx_buffer_t *rxb)
431 {
432         unsigned long flags;
433         int           count;
434         
435         spin_lock_irqsave(&rxb->rxb_pool->rxbp_lock, flags);
436         count = --(rxb->rxb_refcount);
437         spin_unlock_irqrestore(&rxb->rxb_pool->rxbp_lock, flags);
438
439         if (count == 0)
440                 kptllnd_rx_buffer_post(rxb);
441 }
442
443 /*
444  * RX SUPPORT FUNCTIONS
445  */
446 void kptllnd_rx_parse(kptl_rx_t *rx);
447 void kptllnd_rx_done(kptl_rx_t *rx, int post_credit);
448
449 /*
450  * PEER SUPPORT FUNCTIONS
451  */
452 int kptllnd_get_peer_info(int index,
453                           lnet_process_id_t *id, 
454                           int *state, int *sent_hello,
455                           int *refcount, __u64 *incarnation,
456                           __u64 *next_matchbits, __u64 *last_matchbits_seen,
457                           int *nsendq, int *nactiveq,
458                           int *credits, int *outstanding_credits);
459 void kptllnd_peer_destroy(kptl_peer_t *peer);
460 int  kptllnd_peer_del(lnet_process_id_t id);
461 void kptllnd_peer_close_locked(kptl_peer_t *peer, int why);
462 void kptllnd_peer_close(kptl_peer_t *peer, int why);
463 void kptllnd_handle_closing_peers(void);
464 int  kptllnd_peer_connect(kptl_tx_t *tx, lnet_nid_t nid);
465 void kptllnd_peer_check_sends(kptl_peer_t *peer);
466 void kptllnd_peer_check_bucket(int idx, int stamp);
467 void kptllnd_tx_launch(kptl_peer_t *peer, kptl_tx_t *tx, int nfrag);
468 int  kptllnd_find_target(kptl_peer_t **peerp, lnet_process_id_t target);
469 kptl_peer_t *kptllnd_peer_handle_hello(ptl_process_id_t initiator,
470                                        kptl_msg_t *msg);
471 kptl_peer_t *kptllnd_id2peer_locked(lnet_process_id_t id);
472 void kptllnd_peer_alive(kptl_peer_t *peer);
473
474 static inline void
475 kptllnd_peer_addref (kptl_peer_t *peer)
476 {
477         atomic_inc(&peer->peer_refcount);
478 }
479
480 static inline void
481 kptllnd_peer_decref (kptl_peer_t *peer)
482 {
483         if (atomic_dec_and_test(&peer->peer_refcount))
484                 kptllnd_peer_destroy(peer);
485 }
486
487 static inline void
488 kptllnd_set_tx_peer(kptl_tx_t *tx, kptl_peer_t *peer) 
489 {
490         LASSERT (tx->tx_peer == NULL);
491         
492         kptllnd_peer_addref(peer);
493         tx->tx_peer = peer;
494 }
495
496 static inline struct list_head *
497 kptllnd_nid2peerlist(lnet_nid_t nid)
498 {
499         unsigned int hash = ((unsigned int)nid) %
500                             kptllnd_data.kptl_peer_hash_size;
501
502         return &kptllnd_data.kptl_peers[hash];
503 }
504
505 static inline kptl_peer_t *
506 kptllnd_id2peer(lnet_process_id_t id)
507 {
508         kptl_peer_t   *peer;
509         unsigned long  flags;
510
511         read_lock_irqsave(&kptllnd_data.kptl_peer_rw_lock, flags);
512         peer = kptllnd_id2peer_locked(id);
513         read_unlock_irqrestore(&kptllnd_data.kptl_peer_rw_lock, flags);
514
515         return peer;
516 }
517
518 static inline int
519 kptllnd_reserve_buffers(int n)
520 {
521         return kptllnd_rx_buffer_pool_reserve(&kptllnd_data.kptl_rx_buffer_pool,
522                                               n);
523 }
524
525 static inline int
526 kptllnd_peer_reserve_buffers(void)
527 {
528         return kptllnd_reserve_buffers(*kptllnd_tunables.kptl_peercredits);
529 }
530
531 static inline void
532 kptllnd_peer_unreserve_buffers(void)
533 {
534         kptllnd_rx_buffer_pool_unreserve(&kptllnd_data.kptl_rx_buffer_pool,
535                                          *kptllnd_tunables.kptl_peercredits);
536 }
537
538 /*
539  * TX SUPPORT FUNCTIONS
540  */
541 int  kptllnd_setup_tx_descs(void);
542 void kptllnd_cleanup_tx_descs(void);
543 void kptllnd_tx_fini(kptl_tx_t *tx);
544 kptl_tx_t *kptllnd_get_idle_tx(enum kptl_tx_type purpose);
545 void kptllnd_tx_callback(ptl_event_t *ev);
546 const char *kptllnd_tx_typestr(int type);
547
548 static inline void
549 kptllnd_tx_addref(kptl_tx_t *tx)
550 {
551         atomic_inc(&tx->tx_refcount);
552 }
553
554 static inline void 
555 kptllnd_tx_decref(kptl_tx_t *tx)
556 {
557         LASSERT (!in_interrupt());        /* Thread context only */
558
559         if (atomic_dec_and_test(&tx->tx_refcount))
560                 kptllnd_tx_fini(tx);
561 }
562
563 /*
564  * MESSAGE SUPPORT FUNCTIONS
565  */
566 void kptllnd_init_msg(kptl_msg_t *msg, int type, int body_nob);
567 void kptllnd_msg_pack(kptl_msg_t *msg, kptl_peer_t *peer);
568 int  kptllnd_msg_unpack(kptl_msg_t *msg, int nob);
569
570 /*
571  * MISC SUPPORT FUNCTIONS
572  */
573 void kptllnd_init_rdma_md(kptl_tx_t *tx, unsigned int niov,
574                           struct iovec *iov, lnet_kiov_t *kiov,
575                           unsigned int offset, unsigned int nob);
576 char *kptllnd_ptlid2str(ptl_process_id_t id);
577
578 void kptllnd_init_ptltrace(void);
579 void kptllnd_dump_ptltrace(void);
580
581 #ifdef PJK_DEBUGGING
582 #define SIMULATION_FAIL_TX_PUT_ALLOC   0       /* 0x00000001 */
583 #define SIMULATION_FAIL_TX_GET_ALLOC   1       /* 0x00000002 */
584 #define SIMULATION_FAIL_TX             2       /* 0x00000004 */
585 #define SIMULATION_FAIL_RX_ALLOC       3       /* 0x00000008 */
586
587 #define IS_SIMULATION_ENABLED(x) \
588         (((*kptllnd_tunables.kptl_simulation_bitmap) & 1<< SIMULATION_##x) != 0)
589 #else
590 #define IS_SIMULATION_ENABLED(x)       0
591 #endif