Whamcloud - gitweb
* userspace (catamount) ptllnd changes
[fs/lustre-release.git] / lnet / ulnds / ptllnd / ptllnd.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2005 Cluster File Systems, Inc. All rights reserved.
5  *   Author: Eric Barton <eeb@bartonsoftware.com>
6  *
7  *   This file is part of the Lustre file system, http://www.lustre.org
8  *   Lustre is a trademark of Cluster File Systems, Inc.
9  *
10  *   This file is confidential source code owned by Cluster File Systems.
11  *   No viewing, modification, compilation, redistribution, or any other
12  *   form of use is permitted except through a signed license agreement.
13  *
14  *   If you have not signed such an agreement, then you have no rights to
15  *   this file.  Please destroy it immediately and contact CFS.
16  *
17  */
18
19
20 #define DEBUG_SUBSYSTEM S_LND
21
22 #include <lnet/lib-lnet.h>
23 #include <lnet/ptllnd_wire.h>
24
25 #include <portals/p30.h>
26 #include <lnet/ptllnd.h>           /* Depends on portals/p30.h */
27 #include <stdarg.h>
28
29 /* Hack to record history 
30  * This should really be done by CDEBUG(D_NETTRACE...  */
31
32 typedef struct {
33         struct list_head          he_list;
34         struct timeval            he_time;
35         const char               *he_fn;
36         const char               *he_file;
37         int                       he_seq;
38         int                       he_line;
39         char                      he_msg[80];
40 } ptllnd_he_t;
41
42 void ptllnd_dump_history();
43 void ptllnd_history(const char *fn, const char *file, const int line,
44                     const char *fmt, ...);
45 #define PTLLND_HISTORY(fmt, a...) \
46         ptllnd_history(__FUNCTION__, __FILE__, __LINE__, fmt, ## a)
47
48         
49 #define PTLLND_MD_OPTIONS        (PTL_MD_LUSTRE_COMPLETION_SEMANTICS |\
50                                   PTL_MD_EVENT_START_DISABLE)
51 typedef struct
52 {
53         int                        plni_portal;
54         ptl_pid_t                  plni_ptllnd_pid; /* Portals PID of peers I may connect to */
55         int                        plni_peer_credits;
56         int                        plni_max_msg_size;
57         int                        plni_buffer_size;
58         int                        plni_msgs_spare;
59         int                        plni_peer_hash_size;
60         int                        plni_eq_size;
61         int                        plni_checksum;
62         int                        plni_max_tx_history;
63         int                        plni_abort_on_protocol_mismatch;
64         int                        plni_abort_on_nak;
65         int                        plni_dump_on_nak;
66         int                        plni_debug;
67         int                        plni_long_wait;
68         int                        plni_watchdog_interval;
69         int                        plni_timeout;
70
71         __u64                      plni_stamp;
72         struct list_head           plni_active_txs;
73         struct list_head           plni_zombie_txs;
74         int                        plni_ntxs;
75         int                        plni_nrxs;
76
77         ptl_handle_ni_t            plni_nih;
78         ptl_handle_eq_t            plni_eqh;
79         ptl_process_id_t           plni_portals_id;   /* Portals ID of interface */
80
81         struct list_head          *plni_peer_hash;
82         int                        plni_npeers;
83
84         int                        plni_watchdog_nextt;
85         int                        plni_watchdog_peeridx;
86
87         struct list_head           plni_tx_history;
88         int                        plni_ntx_history;
89
90         struct list_head           plni_buffers;
91         int                        plni_nbuffers;
92         int                        plni_nposted_buffers;
93         int                        plni_nmsgs;
94 } ptllnd_ni_t;
95
96 #define PTLLND_CREDIT_HIGHWATER(plni) ((plni)->plni_peer_credits - 1)
97
98 typedef struct
99 {
100         struct list_head           plp_list;
101         lnet_ni_t                 *plp_ni;
102         lnet_process_id_t          plp_id;
103         ptl_process_id_t           plp_ptlid;
104         int                        plp_credits; /* # msg buffers reserved for me at peer */
105
106         /* credits for msg buffers I've posted for this peer...
107          * outstanding - free buffers I've still to inform my peer about
108          * sent        - free buffers I've told my peer about
109          * lazy        - additional buffers (over and above plni_peer_credits)
110          *               posted to prevent peer blocking on sending a non-RDMA
111          *               messages to me when LNET isn't eagerly responsive to
112          *               the network (i.e. liblustre doesn't have control). 
113          * extra_lazy  - lazy credits not required any more. */
114         int                        plp_outstanding_credits;
115         int                        plp_sent_credits;
116         int                        plp_lazy_credits;
117         int                        plp_extra_lazy_credits;
118
119         int                        plp_max_msg_size;
120         int                        plp_refcount;
121         int                        plp_recvd_hello:1;
122         int                        plp_closing:1;
123         __u64                      plp_match;
124         __u64                      plp_stamp;
125         struct list_head           plp_txq;
126         struct list_head           plp_activeq;
127 } ptllnd_peer_t;
128
129 typedef struct
130 {
131         struct list_head           plb_list;
132         lnet_ni_t                 *plb_ni;
133         int                        plb_posted;
134         ptl_handle_md_t            plb_md;
135         char                      *plb_buffer;
136 } ptllnd_buffer_t;
137
138 typedef struct
139 {
140         ptllnd_peer_t             *rx_peer;
141         kptl_msg_t                *rx_msg;
142         int                        rx_nob;
143 } ptllnd_rx_t;
144
145 typedef struct
146 {
147         struct list_head           tx_list;
148         int                        tx_type;
149         int                        tx_status;
150         ptllnd_peer_t             *tx_peer;
151         lnet_msg_t                *tx_lnetmsg;
152         lnet_msg_t                *tx_lnetreplymsg;
153         unsigned int               tx_niov;
154         ptl_md_iovec_t            *tx_iov;
155         ptl_handle_md_t            tx_bulkmdh;
156         ptl_handle_md_t            tx_reqmdh;
157         struct timeval             tx_bulk_posted;
158         struct timeval             tx_bulk_done;
159         struct timeval             tx_req_posted;
160         struct timeval             tx_req_done;
161         int                        tx_completing; /* someone already completing */
162         int                        tx_msgsize;  /* # bytes in tx_msg */
163         time_t                     tx_deadline; /* time to complete by */
164         kptl_msg_t                 tx_msg;      /* message to send */
165 } ptllnd_tx_t;
166
167 #define PTLLND_RDMA_WRITE           0x100       /* pseudo message type */
168 #define PTLLND_RDMA_READ            0x101       /* (no msg actually sent) */
169
170 /* Hack to extract object type from event's user_ptr relies on (and checks)
171  * that structs are somewhat aligned. */
172 #define PTLLND_EVENTARG_TYPE_TX     0x1
173 #define PTLLND_EVENTARG_TYPE_BUF    0x2
174 #define PTLLND_EVENTARG_TYPE_MASK   0x3
175
176 static inline void *
177 ptllnd_obj2eventarg (void *obj, int type)
178 {
179         unsigned long ptr = (unsigned long)obj;
180
181         LASSERT ((ptr & PTLLND_EVENTARG_TYPE_MASK) == 0);
182         LASSERT ((type & ~PTLLND_EVENTARG_TYPE_MASK) == 0);
183
184         return (void *)(ptr | type);
185 }
186
187 static inline int
188 ptllnd_eventarg2type (void *arg)
189 {
190         unsigned long ptr = (unsigned long)arg;
191
192         return (ptr & PTLLND_EVENTARG_TYPE_MASK);
193 }
194
195 static inline void *
196 ptllnd_eventarg2obj (void *arg)
197 {
198         unsigned long ptr = (unsigned long)arg;
199
200         return (void *)(ptr & ~PTLLND_EVENTARG_TYPE_MASK);
201 }
202
203 int ptllnd_parse_int_tunable(int *value, char *name, int dflt);
204 void ptllnd_cull_tx_history(ptllnd_ni_t *plni);
205 int ptllnd_startup(lnet_ni_t *ni);
206 void ptllnd_shutdown(lnet_ni_t *ni);
207 int ptllnd_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg);
208 int ptllnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *msg);
209 int ptllnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg,
210                 int delayed, unsigned int niov,
211                 struct iovec *iov, lnet_kiov_t *kiov,
212                 unsigned int offset, unsigned int mlen, unsigned int rlen);
213 int ptllnd_eager_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg,
214                       void **new_privatep);
215
216 ptllnd_tx_t *ptllnd_new_tx(ptllnd_peer_t *peer, int type, int payload_nob);
217 void ptllnd_notify(lnet_ni_t *ni, lnet_nid_t nid, int alive);
218 int  ptllnd_setasync(lnet_ni_t *ni, lnet_process_id_t id, int n);
219 void ptllnd_wait(lnet_ni_t *ni, int milliseconds);
220 void ptllnd_check_sends(ptllnd_peer_t *peer);
221 void ptllnd_debug_peer(lnet_ni_t *ni, lnet_process_id_t id);
222 void ptllnd_destroy_peer(ptllnd_peer_t *peer);
223 void ptllnd_close_peer(ptllnd_peer_t *peer, int error);
224 int ptllnd_post_buffer(ptllnd_buffer_t *buf);
225 int ptllnd_size_buffers (lnet_ni_t *ni, int delta);
226 const char *ptllnd_evtype2str(int type);
227 const char *ptllnd_msgtype2str(int type);
228 const char *ptllnd_errtype2str(int type);
229 char *ptllnd_ptlid2str(ptl_process_id_t id);
230 void ptllnd_dump_debug(lnet_ni_t *ni, lnet_process_id_t id);
231
232
233 static inline void
234 ptllnd_peer_addref (ptllnd_peer_t *peer)
235 {
236         LASSERT (peer->plp_refcount > 0);
237         peer->plp_refcount++;
238 }
239
240 static inline void
241 ptllnd_peer_decref (ptllnd_peer_t *peer)
242 {
243         LASSERT (peer->plp_refcount > 0);
244         peer->plp_refcount--;
245         if (peer->plp_refcount == 0)
246                 ptllnd_destroy_peer(peer);
247 }
248
249 static inline lnet_nid_t
250 ptllnd_ptl2lnetnid(lnet_ni_t *ni, ptl_nid_t portals_nid)
251 {
252         return LNET_MKNID(LNET_NIDNET(ni->ni_nid), portals_nid);
253 }
254
255 static inline ptl_nid_t
256 ptllnd_lnet2ptlnid(lnet_nid_t lnet_nid)
257 {
258         return LNET_NIDADDR(lnet_nid);
259 }
260
261 /*
262  * A note about lprintf():
263  *  Normally printf() is redirected to stdout of the console
264  *  from which yod launched the catamount application.  However
265  *  there is a lot of initilziation code that runs before this
266  *  redirection is hooked up, and printf() seems to go to the bit bucket
267  *
268  *  To get any kind of debug output and init time lprintf() can
269  *  be used to output to the console from which bookqk was used to
270  *  boot the catamount node.  This works for debugging some simple
271  *  cases.
272  */
273
274