1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * Types used by the library side routines that do not need to be
7 * exposed to the user application
10 #ifndef __LNET_LIB_TYPES_H__
11 #define __LNET_LIB_TYPES_H__
13 #if defined(__linux__)
14 #include <lnet/linux/lib-types.h>
15 #elif defined(__APPLE__)
16 #include <lnet/darwin/lib-types.h>
17 #elif defined(__WINNT__)
18 #include <lnet/winnt/lib-types.h>
20 #error Unsupported Operating System
23 #include <libcfs/libcfs.h>
24 #include <libcfs/list.h>
25 #include <lnet/types.h>
27 #define WIRE_ATTR __attribute__((packed))
29 /* The wire handle's interface cookie only matches one network interface in
30 * one epoch (i.e. new cookie when the interface restarts or the node
31 * reboots). The object cookie only matches one object on that interface
32 * during that object's lifetime (i.e. no cookie re-use). */
34 __u64 wh_interface_cookie;
35 __u64 wh_object_cookie;
36 } WIRE_ATTR lnet_handle_wire_t;
38 /* byte-flip insensitive! */
39 #define LNET_WIRE_HANDLE_NONE \
40 ((const lnet_handle_wire_t) {.wh_interface_cookie = -1, .wh_object_cookie = -1})
50 /* The variant fields of the portals message header are aligned on an 8
51 * byte boundary in the message header. Note that all types used in these
52 * wire structs MUST be fixed size and the smaller types are placed at the
54 typedef struct lnet_ack {
55 lnet_handle_wire_t dst_wmd;
58 } WIRE_ATTR lnet_ack_t;
60 typedef struct lnet_put {
61 lnet_handle_wire_t ack_wmd;
66 } WIRE_ATTR lnet_put_t;
68 typedef struct lnet_get {
69 lnet_handle_wire_t return_wmd;
74 } WIRE_ATTR lnet_get_t;
76 typedef struct lnet_reply {
77 lnet_handle_wire_t dst_wmd;
78 } WIRE_ATTR lnet_reply_t;
80 typedef struct lnet_hello {
83 } WIRE_ATTR lnet_hello_t;
90 __u32 type; /* lnet_msg_type_t */
91 __u32 payload_length; /* payload data to follow */
92 /*<------__u64 aligned------->*/
100 } WIRE_ATTR lnet_hdr_t;
102 /* A HELLO message contains a magic number and protocol version
103 * code in the header's dest_nid, the peer's NID in the src_nid, and
104 * LNET_MSG_HELLO in the type field. All other common fields are zero
105 * (including payload_size; i.e. no payload).
106 * This is for use by byte-stream LNDs (e.g. TCP/IP) to check the peer is
107 * running the same protocol and to find out its NID. These LNDs should
108 * exchange HELLO messages when a connection is first established. Individual
109 * LNDs can put whatever else they fancy in lnet_hdr_t::msg.
112 __u32 magic; /* LNET_PROTO_TCP_MAGIC */
113 __u16 version_major; /* increment on incompatible change */
114 __u16 version_minor; /* increment on compatible change */
115 } WIRE_ATTR lnet_magicversion_t;
117 /* PROTO MAGIC for LNDs */
118 #define LNET_PROTO_IB_MAGIC 0x0be91b91
119 #define LNET_PROTO_OPENIB_MAGIC LNET_PROTO_IB_MAGIC
120 #define LNET_PROTO_IIB_MAGIC LNET_PROTO_IB_MAGIC
121 #define LNET_PROTO_VIB_MAGIC LNET_PROTO_IB_MAGIC
122 #define LNET_PROTO_RA_MAGIC 0x0be91b92
123 #define LNET_PROTO_QSW_MAGIC 0x0be91b93
124 #define LNET_PROTO_TCP_MAGIC 0xeebc0ded
125 #define LNET_PROTO_PTL_MAGIC 0x50746C4E /* 'PtlN' unique magic */
126 #define LNET_PROTO_GM_MAGIC 0x6d797269 /* 'myri'! */
127 #define LNET_PROTO_MX_MAGIC 0x4d583130 /* 'MX10'! */
128 #define LNET_PROTO_ACCEPTOR_MAGIC 0xacce7100
129 #define LNET_PROTO_PING_MAGIC 0x70696E67 /* 'ping' */
131 /* Placeholder for a future "unified" protocol across all LNDs */
132 /* Current LNDs that receive a request with this magic will respond with a
133 * "stub" reply using their current protocol */
134 #define LNET_PROTO_MAGIC 0x45726963 /* ! */
137 #define LNET_PROTO_TCP_VERSION_MAJOR 1
138 #define LNET_PROTO_TCP_VERSION_MINOR 0
140 /* Acceptor connection request */
142 __u32 acr_magic; /* PTL_ACCEPTOR_PROTO_MAGIC */
143 __u32 acr_version; /* protocol version */
144 __u64 acr_nid; /* target NID */
145 } WIRE_ATTR lnet_acceptor_connreq_t;
147 #define LNET_PROTO_ACCEPTOR_VERSION 1
152 typedef struct lnet_msg {
153 struct list_head msg_activelist;
154 struct list_head msg_list; /* Q for credits/MD */
156 lnet_process_id_t msg_target;
159 unsigned int msg_target_is_router:1; /* sending to a router */
160 unsigned int msg_routing:1; /* being forwarded */
161 unsigned int msg_ack:1; /* ack on finalize (PUT) */
162 unsigned int msg_sending:1; /* outgoing message */
163 unsigned int msg_receiving:1; /* being received */
164 unsigned int msg_delayed:1; /* had to Q for buffer or tx credit */
165 unsigned int msg_txcredit:1; /* taken an NI send credit */
166 unsigned int msg_peertxcredit:1; /* taken a peer send credit */
167 unsigned int msg_rtrcredit:1; /* taken a globel router credit */
168 unsigned int msg_peerrtrcredit:1; /* taken a peer router credit */
169 unsigned int msg_onactivelist:1; /* on the activelist */
171 struct lnet_peer *msg_txpeer; /* peer I'm sending to */
172 struct lnet_peer *msg_rxpeer; /* peer I received from */
175 struct lnet_libmd *msg_md;
177 unsigned int msg_len;
178 unsigned int msg_wanted;
179 unsigned int msg_offset;
180 unsigned int msg_niov;
181 struct iovec *msg_iov;
182 lnet_kiov_t *msg_kiov;
189 typedef struct lnet_libhandle {
190 struct list_head lh_hash_chain;
194 #define lh_entry(ptr, type, member) \
195 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
197 typedef struct lnet_eq {
198 struct list_head eq_list;
199 lnet_libhandle_t eq_lh;
200 lnet_seq_t eq_enq_seq;
201 lnet_seq_t eq_deq_seq;
202 unsigned int eq_size;
203 lnet_event_t *eq_events;
205 lnet_eq_handler_t eq_callback;
208 typedef struct lnet_me {
209 struct list_head me_list;
210 lnet_libhandle_t me_lh;
211 lnet_process_id_t me_match_id;
212 unsigned int me_portal;
214 __u64 me_ignore_bits;
215 lnet_unlink_t me_unlink;
216 struct lnet_libmd *me_md;
219 typedef struct lnet_libmd {
220 struct list_head md_list;
221 lnet_libhandle_t md_lh;
224 unsigned int md_offset;
225 unsigned int md_length;
226 unsigned int md_max_size;
229 unsigned int md_options;
230 unsigned int md_flags;
234 unsigned int md_niov; /* # frags */
236 struct iovec iov[LNET_MAX_IOV];
237 lnet_kiov_t kiov[LNET_MAX_IOV];
241 #define LNET_MD_FLAG_ZOMBIE (1 << 0)
242 #define LNET_MD_FLAG_AUTO_UNLINK (1 << 1)
244 #ifdef LNET_USE_LIB_FREELIST
247 void *fl_objs; /* single contiguous array of objects */
248 int fl_nobjs; /* the number of them */
249 int fl_objsize; /* the size (including overhead) of each of them */
250 struct list_head fl_list; /* where they are enqueued */
255 struct list_head fo_list; /* enqueue on fl_list */
256 void *fo_contents; /* aligned contents */
261 /* info about peers we are trying to fail */
262 struct list_head tp_list; /* ln_test_peers */
263 lnet_nid_t tp_nid; /* matching nid */
264 unsigned int tp_threshold; /* # failures to simulate */
267 #define LNET_COOKIE_TYPE_MD 1
268 #define LNET_COOKIE_TYPE_ME 2
269 #define LNET_COOKIE_TYPE_EQ 3
270 #define LNET_COOKIE_TYPES 4
271 /* LNET_COOKIE_TYPES must be a power of 2, so the cookie type can be
272 * extracted by masking with (LNET_COOKIE_TYPES - 1) */
274 struct lnet_ni; /* forward ref */
276 typedef struct lnet_lnd
278 /* fields managed by portals */
279 struct list_head lnd_list; /* stash in the LND table */
280 int lnd_refcount; /* # active instances */
282 /* fields initialised by the LND */
283 unsigned int lnd_type;
285 int (*lnd_startup) (struct lnet_ni *ni);
286 void (*lnd_shutdown) (struct lnet_ni *ni);
287 int (*lnd_ctl)(struct lnet_ni *ni, unsigned int cmd, void *arg);
289 /* In data movement APIs below, payload buffers are described as a set
290 * of 'niov' fragments which are...
292 * in virtual memory (struct iovec *iov != NULL)
294 * in pages (kernel only: plt_kiov_t *kiov != NULL).
295 * The LND may NOT overwrite these fragment descriptors.
296 * An 'offset' and may specify a byte offset within the set of
297 * fragments to start from
300 /* Start sending a preformatted message. 'private' is NULL for PUT and
301 * GET messages; otherwise this is a response to an incoming message
302 * and 'private' is the 'private' passed to lnet_parse(). Return
303 * non-zero for immediate failure, otherwise complete later with
305 int (*lnd_send)(struct lnet_ni *ni, void *private, lnet_msg_t *msg);
307 /* Start receiving 'mlen' bytes of payload data, skipping the following
308 * 'rlen' - 'mlen' bytes. 'private' is the 'private' passed to
309 * lnet_parse(). Return non-zero for immedaite failure, otherwise
310 * complete later with lnet_finalize(). This also gives back a receive
311 * credit if the LND does flow control. */
312 int (*lnd_recv)(struct lnet_ni *ni, void *private, lnet_msg_t *msg,
313 int delayed, unsigned int niov,
314 struct iovec *iov, lnet_kiov_t *kiov,
315 unsigned int offset, unsigned int mlen, unsigned int rlen);
317 /* lnet_parse() has had to delay processing of this message
318 * (e.g. waiting for a forwarding buffer or send credits). Give the
319 * LND a chance to free urgently needed resources. If called, return 0
320 * for success and do NOT give back a receive credit; that has to wait
321 * until lnd_recv() gets called. On failure return < 0 and
322 * release resources; lnd_recv() will not be called. */
323 int (*lnd_eager_recv)(struct lnet_ni *ni, void *private, lnet_msg_t *msg,
324 void **new_privatep);
326 /* notification of peer health */
327 void (*lnd_notify)(struct lnet_ni *ni, lnet_nid_t peer, int alive);
330 /* accept a new connection */
331 int (*lnd_accept)(struct lnet_ni *ni, cfs_socket_t *sock);
333 /* wait for something to happen */
334 void (*lnd_wait)(struct lnet_ni *ni, int milliseconds);
338 #define LNET_MAX_INTERFACES 16
340 typedef struct lnet_ni {
341 struct list_head ni_list; /* chain on ln_nis */
342 struct list_head ni_txq; /* messages waiting for tx credits */
343 int ni_maxtxcredits; /* # tx credits */
344 int ni_txcredits; /* # tx credits free */
345 int ni_mintxcredits; /* lowest it's been */
346 int ni_peertxcredits; /* # per-peer send credits */
347 lnet_nid_t ni_nid; /* interface's NID */
348 void *ni_data; /* instance-specific data */
349 lnd_t *ni_lnd; /* procedural interface */
350 int ni_refcount; /* reference count */
351 char *ni_interfaces[LNET_MAX_INTERFACES]; /* equivalent interfaces to use */
354 typedef struct lnet_peer {
355 struct list_head lp_hashlist; /* chain on peer hash */
356 struct list_head lp_txq; /* messages blocking for tx credits */
357 struct list_head lp_rtrq; /* messages blocking for router credits */
358 struct list_head lp_rtr_list; /* chain on router list */
359 int lp_txcredits; /* # tx credits available */
360 int lp_mintxcredits; /* low water mark */
361 int lp_rtrcredits; /* # router credits */
362 int lp_minrtrcredits; /* low water mark */
363 unsigned int lp_alive:1; /* alive/dead? */
364 unsigned int lp_notify:1; /* notification outstanding? */
365 unsigned int lp_notifylnd:1; /* outstanding notification for LND? */
366 unsigned int lp_notifying:1; /* some thread is handling notification */
367 unsigned int lp_ping_notsent; /* SEND event outstanding from ping */
368 int lp_alive_count; /* # times router went dead<->alive */
369 long lp_txqnob; /* bytes queued for sending */
370 time_t lp_timestamp; /* time of last aliveness news */
371 time_t lp_ping_timestamp; /* time of last ping attempt */
372 time_t lp_ping_deadline; /* != 0 if ping reply expected */
373 lnet_ni_t *lp_ni; /* interface peer is on */
374 lnet_nid_t lp_nid; /* peer's NID */
375 int lp_refcount; /* # refs */
376 int lp_rtr_refcount; /* # refs from lnet_route_t::lr_gateway */
380 struct list_head lr_list; /* chain on net */
381 lnet_peer_t *lr_gateway; /* router node */
385 struct list_head lrn_list; /* chain on ln_remote_nets */
386 struct list_head lrn_routes; /* routes to me */
387 __u32 lrn_net; /* my net number */
388 unsigned int lrn_hops; /* how far I am */
392 struct list_head rbp_bufs; /* my free buffer pool */
393 struct list_head rbp_msgs; /* messages blocking for a buffer */
394 int rbp_npages; /* # pages in each buffer */
395 int rbp_nbuffers; /* # buffers */
396 int rbp_credits; /* # free buffers / blocked messages */
397 int rbp_mincredits; /* low water mark */
401 struct list_head rb_list; /* chain on rbp_bufs */
402 lnet_rtrbufpool_t *rb_pool; /* owning pool */
403 lnet_kiov_t rb_kiov[0]; /* the buffer space */
420 #define LNET_PEER_HASHSIZE 503 /* prime! */
422 #define LNET_NRBPOOLS 3 /* # different router buffer pools */
424 #define LNET_PROTO_PING_MATCHBITS 0x8000000000000000LL
425 #define LNET_PROTO_PING_VERSION 1
431 lnet_nid_t pi_nid[0];
432 } WIRE_ATTR lnet_ping_info_t;
434 /* Options for lnet_portal_t::ptl_options */
435 #define LNET_PTL_LAZY (1 << 0)
437 struct list_head ptl_ml; /* match list */
438 struct list_head ptl_msgq; /* messages blocking for MD */
439 __u64 ptl_msgq_version; /* validity stamp */
440 unsigned int ptl_options;
444 /* < 0 == startup error */
445 #define LNET_RC_STATE_SHUTDOWN 0 /* not started */
446 #define LNET_RC_STATE_RUNNING 1 /* started up OK */
447 #define LNET_RC_STATE_STOPTHREAD 2 /* telling thread to stop */
448 #define LNET_RC_STATE_UNLINKING 3 /* unlinking RC MD */
449 #define LNET_RC_STATE_UNLINKED 4 /* RC's MD has been unlinked */
453 /* Stuff initialised at LNetInit() */
454 int ln_init; /* LNetInit() called? */
455 int ln_refcount; /* LNetNIInit/LNetNIFini counter */
456 int ln_niinit_self; /* Have I called LNetNIInit myself? */
458 int ln_ptlcompat; /* do I support talking to portals? */
460 struct list_head ln_lnds; /* registered LNDs */
464 cfs_waitq_t ln_waitq;
465 struct semaphore ln_api_mutex;
466 struct semaphore ln_lnd_mutex;
468 # if !HAVE_LIBPTHREAD
473 pthread_cond_t ln_cond;
474 pthread_mutex_t ln_lock;
475 pthread_mutex_t ln_api_mutex;
476 pthread_mutex_t ln_lnd_mutex;
480 /* Stuff initialised at LNetNIInit() */
482 int ln_shutdown; /* shutdown in progress */
483 int ln_nportals; /* # portals */
484 lnet_portal_t *ln_portals; /* the vector of portals */
486 lnet_pid_t ln_pid; /* requested pid */
488 struct list_head ln_nis; /* LND instances */
489 lnet_ni_t *ln_loni; /* the loopback NI */
490 lnet_ni_t *ln_eqwaitni; /* NI to wait for events in */
491 struct list_head ln_zombie_nis; /* dying LND instances */
492 int ln_nzombie_nis; /* # of NIs to wait for */
494 struct list_head ln_remote_nets; /* remote networks with routes to them */
495 __u64 ln_remote_nets_version; /* validity stamp */
497 struct list_head ln_routers; /* list of all known routers */
498 __u64 ln_routers_version; /* validity stamp */
500 struct list_head *ln_peer_hash; /* NID->peer hash */
501 int ln_npeers; /* # peers extant */
502 int ln_peertable_version; /* /proc validity stamp */
504 int ln_routing; /* am I a router? */
505 lnet_rtrbufpool_t ln_rtrpools[LNET_NRBPOOLS]; /* router buffer pools */
507 int ln_lh_hash_size; /* size of lib handle hash table */
508 struct list_head *ln_lh_hash_table; /* all extant lib handles, this interface */
509 __u64 ln_next_object_cookie; /* cookie generator */
510 __u64 ln_interface_cookie; /* uniquely identifies this ni in this epoch */
512 char *ln_network_tokens; /* space for network names */
513 int ln_network_tokens_nob;
515 int ln_testprotocompat; /* test protocol compatibility flags */
517 struct list_head ln_finalizeq; /* msgs waiting to complete finalizing */
519 void **ln_finalizers; /* threads doing finalization */
520 int ln_nfinalizers; /* max # threads finalizing */
524 struct list_head ln_test_peers; /* failure simulation */
526 lnet_handle_md_t ln_ping_target_md;
527 lnet_handle_eq_t ln_ping_target_eq;
528 lnet_ping_info_t *ln_ping_info;
531 int ln_rc_state; /* router checker startup/shutdown state */
532 struct semaphore ln_rc_signal; /* serialise startup/shutdown */
533 lnet_handle_eq_t ln_rc_eqh; /* router checker's event queue */
536 #ifdef LNET_USE_LIB_FREELIST
537 lnet_freelist_t ln_free_mes;
538 lnet_freelist_t ln_free_msgs;
539 lnet_freelist_t ln_free_mds;
540 lnet_freelist_t ln_free_eqs;
542 struct list_head ln_active_msgs;
543 struct list_head ln_active_mds;
544 struct list_head ln_active_eqs;
546 lnet_counters_t ln_counters;