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