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