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