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