Whamcloud - gitweb
Landing b_hd_newconfig on HEAD
[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
28 #define PTLLND_DEBUG_TIMING 0
29
30 #define PTLLND_MSGS_PER_BUFFER     64
31 #define PTLLND_MSGS_SPARE          256
32 #define PTLLND_PEER_HASH_SIZE      101
33 #define PTLLND_EQ_SIZE             1024
34 #if PTLLND_DEBUG_TIMING
35 # define PTLLND_TX_HISTORY         1024
36 #else
37 # define PTLLND_TX_HISTORY         0
38 #endif
39 #define PTLLND_WARN_LONG_WAIT      5 /* seconds */
40 #define PTLLND_ABORT_ON_NAK        1 /* abort app on protocol version mismatch */
41
42 #define PTLLND_MD_OPTIONS        (PTL_MD_LUSTRE_COMPLETION_SEMANTICS |\
43                                   PTL_MD_EVENT_START_DISABLE)
44 typedef struct
45 {
46         int                        plni_portal;
47         ptl_pid_t                  plni_ptllnd_pid; /* Portals PID of peers I may connect to */
48         int                        plni_peer_credits;
49         int                        plni_max_msg_size;
50         int                        plni_buffer_size;
51         int                        plni_msgs_spare;
52         int                        plni_peer_hash_size;
53         int                        plni_eq_size;
54         int                        plni_checksum;
55         int                        plni_max_tx_history;
56         int                        plni_abort_on_nak;
57
58         __u64                      plni_stamp;
59         struct list_head           plni_active_txs;
60         struct list_head           plni_zombie_txs;
61         int                        plni_ntxs;
62         int                        plni_nrxs;
63
64         ptl_handle_ni_t            plni_nih;
65         ptl_handle_eq_t            plni_eqh;
66         ptl_process_id_t           plni_portals_id;   /* Portals ID of interface */
67
68         struct list_head          *plni_peer_hash;
69         int                        plni_npeers;
70
71         struct list_head           plni_tx_history;
72         int                        plni_ntx_history;
73
74         struct list_head           plni_buffers;
75         int                        plni_nbuffers;
76         int                        plni_nposted_buffers;
77 } ptllnd_ni_t;
78
79 #define PTLLND_CREDIT_HIGHWATER(plni) ((plni)->plni_peer_credits - 1)
80
81 typedef struct
82 {
83         struct list_head           plp_list;
84         lnet_ni_t                 *plp_ni;
85         lnet_process_id_t          plp_id;
86         ptl_process_id_t           plp_ptlid;
87         int                        plp_credits;
88         int                        plp_max_credits;
89         int                        plp_outstanding_credits;
90         int                        plp_max_msg_size;
91         int                        plp_refcount;
92         int                        plp_recvd_hello:1;
93         int                        plp_closing:1;
94         __u64                      plp_match;
95         __u64                      plp_stamp;
96         struct list_head           plp_txq;
97         struct list_head           plp_activeq;
98 } ptllnd_peer_t;
99
100 typedef struct
101 {
102         struct list_head           plb_list;
103         lnet_ni_t                 *plb_ni;
104         int                        plb_posted;
105         ptl_handle_md_t            plb_md;
106         char                      *plb_buffer;
107 } ptllnd_buffer_t;
108
109 typedef struct
110 {
111         ptllnd_peer_t             *rx_peer;
112         kptl_msg_t                *rx_msg;
113         int                        rx_nob;
114 } ptllnd_rx_t;
115
116 typedef struct
117 {
118         struct list_head           tx_list;
119         int                        tx_type;
120         int                        tx_status;
121         ptllnd_peer_t             *tx_peer;
122         lnet_msg_t                *tx_lnetmsg;
123         lnet_msg_t                *tx_lnetreplymsg;
124         unsigned int               tx_niov;
125         ptl_md_iovec_t            *tx_iov;
126         ptl_handle_md_t            tx_bulkmdh;
127         ptl_handle_md_t            tx_reqmdh;
128 #if PTLLND_DEBUG_TIMING
129         struct timeval             tx_bulk_posted;
130         struct timeval             tx_bulk_done;
131         struct timeval             tx_req_posted;
132         struct timeval             tx_req_done;
133 #endif
134         int                        tx_completing; /* someone already completing */
135         int                        tx_msgsize;  /* # bytes in tx_msg */
136         kptl_msg_t                 tx_msg;      /* message to send */
137 } ptllnd_tx_t;
138
139 #define PTLLND_RDMA_WRITE           0x100       /* pseudo message type */
140 #define PTLLND_RDMA_READ            0x101       /* (no msg actually sent) */
141
142 /* Hack to extract object type from event's user_ptr relies on (and checks)
143  * that structs are somewhat aligned. */
144 #define PTLLND_EVENTARG_TYPE_TX     0x1
145 #define PTLLND_EVENTARG_TYPE_BUF    0x2
146 #define PTLLND_EVENTARG_TYPE_MASK   0x3
147
148 static inline void *
149 ptllnd_obj2eventarg (void *obj, int type)
150 {
151         unsigned long ptr = (unsigned long)obj;
152
153         LASSERT ((ptr & PTLLND_EVENTARG_TYPE_MASK) == 0);
154         LASSERT ((type & ~PTLLND_EVENTARG_TYPE_MASK) == 0);
155
156         return (void *)(ptr | type);
157 }
158
159 static inline int
160 ptllnd_eventarg2type (void *arg)
161 {
162         unsigned long ptr = (unsigned long)arg;
163
164         return (ptr & PTLLND_EVENTARG_TYPE_MASK);
165 }
166
167 static inline void *
168 ptllnd_eventarg2obj (void *arg)
169 {
170         unsigned long ptr = (unsigned long)arg;
171
172         return (void *)(ptr & ~PTLLND_EVENTARG_TYPE_MASK);
173 }
174
175 #if PTLLND_DEBUG_TIMING
176 # define PTLLND_DBGT_INIT(tv)  memset(&(tv), 0, sizeof(tv))
177 # define PTLLND_DBGT_STAMP(tv) gettimeofday(&(tv), NULL)
178 # define DBGT_FMT              "%ld.%06ld"
179 # define DBGT_ARGS(tv)         , (long)((tv).tv_sec), (long)((tv).tv_usec)
180 #else
181 # define PTLLND_DBGT_INIT(tv)
182 # define PTLLND_DBGT_STAMP(tv)
183 # define DBGT_FMT              "-"
184 # define DBGT_ARGS(tv)
185 #endif
186
187 void ptllnd_cull_tx_history(ptllnd_ni_t *plni);
188 int ptllnd_startup(lnet_ni_t *ni);
189 void ptllnd_shutdown(lnet_ni_t *ni);
190 int ptllnd_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg);
191 int ptllnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *msg);
192 int ptllnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg,
193                 int delayed, unsigned int niov,
194                 struct iovec *iov, lnet_kiov_t *kiov,
195                 unsigned int offset, unsigned int mlen, unsigned int rlen);
196 int ptllnd_eager_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg,
197                       void **new_privatep);
198
199 ptllnd_tx_t *ptllnd_new_tx(ptllnd_peer_t *peer, int type, int payload_nob);
200 void ptllnd_notify(lnet_ni_t *ni, lnet_nid_t nid, int alive);
201 void ptllnd_wait(lnet_ni_t *ni, int milliseconds);
202 void ptllnd_check_sends(ptllnd_peer_t *peer);
203 void ptllnd_debug_peer(lnet_ni_t *ni, lnet_process_id_t id);
204 void ptllnd_destroy_peer(ptllnd_peer_t *peer);
205 void ptllnd_close_peer(ptllnd_peer_t *peer, int error);
206 int ptllnd_post_buffer(ptllnd_buffer_t *buf);
207 int ptllnd_grow_buffers (lnet_ni_t *ni);
208 const char *ptllnd_evtype2str(int type);
209 const char *ptllnd_msgtype2str(int type);
210 char *ptllnd_ptlid2str(ptl_process_id_t id);
211
212 static inline void
213 ptllnd_peer_addref (ptllnd_peer_t *peer)
214 {
215         LASSERT (peer->plp_refcount > 0);
216         peer->plp_refcount++;
217 }
218
219 static inline void
220 ptllnd_peer_decref (ptllnd_peer_t *peer)
221 {
222         LASSERT (peer->plp_refcount > 0);
223         peer->plp_refcount--;
224         if (peer->plp_refcount == 0)
225                 ptllnd_destroy_peer(peer);
226 }
227
228 static inline void
229 ptllnd_post_tx(ptllnd_tx_t *tx)
230 {
231         ptllnd_peer_t *peer = tx->tx_peer;
232         LASSERT(tx->tx_peer != NULL);
233         list_add_tail(&tx->tx_list, &peer->plp_txq);
234         ptllnd_check_sends(peer);
235 }
236
237 static inline lnet_nid_t
238 ptllnd_ptl2lnetnid(lnet_ni_t *ni, ptl_nid_t portals_nid)
239 {
240         return LNET_MKNID(LNET_NIDNET(ni->ni_nid), portals_nid);
241 }
242
243 static inline ptl_nid_t
244 ptllnd_lnet2ptlnid(lnet_nid_t lnet_nid)
245 {
246         return LNET_NIDADDR(lnet_nid);
247 }
248
249 /*
250  * A note about lprintf():
251  *  Normally printf() is redirected to stdout of the console
252  *  from which yod launched the catamount application.  However
253  *  there is a lot of initilziation code that runs before this
254  *  redirection is hooked up, and printf() seems to go to the bit bucket
255  *
256  *  To get any kind of debug output and init time lprintf() can
257  *  be used to output to the console from which bookqk was used to
258  *  boot the catamount node.  This works for debugging some simple
259  *  cases.
260  */
261
262