Whamcloud - gitweb
8781feb85de9c839d752cc01536a3730371f6acb
[fs/lustre-release.git] / lnet / include / lnet / lib-types.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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2015, Intel Corporation.
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/include/lnet/lib-types.h
37  *
38  * Types used by the library side routines that do not need to be
39  * exposed to the user application
40  */
41
42 #ifndef __LNET_LIB_TYPES_H__
43 #define __LNET_LIB_TYPES_H__
44
45 #ifndef __KERNEL__
46 # error This include is only for kernel use.
47 #endif
48
49 #include <linux/kthread.h>
50 #include <linux/uio.h>
51 #include <linux/types.h>
52
53 #include <lnet/lnetctl.h>
54
55 /* Max payload size */
56 #ifndef CONFIG_LNET_MAX_PAYLOAD
57 # error "CONFIG_LNET_MAX_PAYLOAD must be defined in config.h"
58 #endif
59
60 #define LNET_MAX_PAYLOAD       CONFIG_LNET_MAX_PAYLOAD
61 #if (LNET_MAX_PAYLOAD < LNET_MTU)
62 # error "LNET_MAX_PAYLOAD too small - error in configure --with-max-payload-mb"
63 #elif (LNET_MAX_PAYLOAD > (PAGE_SIZE * LNET_MAX_IOV))
64 # error "LNET_MAX_PAYLOAD too large - error in configure --with-max-payload-mb"
65 #endif
66
67 /* forward refs */
68 struct lnet_libmd;
69
70 typedef struct lnet_msg {
71         struct list_head        msg_activelist;
72         struct list_head        msg_list;       /* Q for credits/MD */
73
74         lnet_process_id_t       msg_target;
75         /* where is it from, it's only for building event */
76         lnet_nid_t              msg_from;
77         __u32                   msg_type;
78
79         /* committed for sending */
80         unsigned int            msg_tx_committed:1;
81         /* CPT # this message committed for sending */
82         unsigned int            msg_tx_cpt:15;
83         /* committed for receiving */
84         unsigned int            msg_rx_committed:1;
85         /* CPT # this message committed for receiving */
86         unsigned int            msg_rx_cpt:15;
87         /* queued for tx credit */
88         unsigned int            msg_tx_delayed:1;
89         /* queued for RX buffer */
90         unsigned int            msg_rx_delayed:1;
91         /* ready for pending on RX delay list */
92         unsigned int            msg_rx_ready_delay:1;
93
94         unsigned int          msg_vmflush:1;      /* VM trying to free memory */
95         unsigned int          msg_target_is_router:1; /* sending to a router */
96         unsigned int          msg_routing:1;      /* being forwarded */
97         unsigned int          msg_ack:1;          /* ack on finalize (PUT) */
98         unsigned int          msg_sending:1;      /* outgoing message */
99         unsigned int          msg_receiving:1;    /* being received */
100         unsigned int          msg_txcredit:1;     /* taken an NI send credit */
101         unsigned int          msg_peertxcredit:1; /* taken a peer send credit */
102         unsigned int          msg_rtrcredit:1;    /* taken a globel router credit */
103         unsigned int          msg_peerrtrcredit:1; /* taken a peer router credit */
104         unsigned int          msg_onactivelist:1; /* on the activelist */
105         unsigned int          msg_rdma_get:1;
106
107         struct lnet_peer     *msg_txpeer;         /* peer I'm sending to */
108         struct lnet_peer     *msg_rxpeer;         /* peer I received from */
109
110         void                 *msg_private;
111         struct lnet_libmd    *msg_md;
112
113         unsigned int          msg_len;
114         unsigned int          msg_wanted;
115         unsigned int          msg_offset;
116         unsigned int          msg_niov;
117         struct kvec          *msg_iov;
118         lnet_kiov_t          *msg_kiov;
119
120         lnet_event_t          msg_ev;
121         lnet_hdr_t            msg_hdr;
122 } lnet_msg_t;
123
124
125 typedef struct lnet_libhandle {
126         struct list_head        lh_hash_chain;
127         __u64                   lh_cookie;
128 } lnet_libhandle_t;
129
130 #define lh_entry(ptr, type, member) \
131         ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
132
133 typedef struct lnet_eq {
134         struct list_head        eq_list;
135         lnet_libhandle_t        eq_lh;
136         lnet_seq_t              eq_enq_seq;
137         lnet_seq_t              eq_deq_seq;
138         unsigned int            eq_size;
139         lnet_eq_handler_t       eq_callback;
140         lnet_event_t            *eq_events;
141         int                     **eq_refs;      /* percpt refcount for EQ */
142 } lnet_eq_t;
143
144 typedef struct lnet_me {
145         struct list_head        me_list;
146         lnet_libhandle_t        me_lh;
147         lnet_process_id_t       me_match_id;
148         unsigned int            me_portal;
149         unsigned int            me_pos;         /* hash offset in mt_hash */
150         __u64                   me_match_bits;
151         __u64                   me_ignore_bits;
152         lnet_unlink_t           me_unlink;
153         struct lnet_libmd      *me_md;
154 } lnet_me_t;
155
156 typedef struct lnet_libmd {
157         struct list_head        md_list;
158         lnet_libhandle_t        md_lh;
159         lnet_me_t              *md_me;
160         char                   *md_start;
161         unsigned int            md_offset;
162         unsigned int            md_length;
163         unsigned int            md_max_size;
164         int                     md_threshold;
165         int                     md_refcount;
166         unsigned int            md_options;
167         unsigned int            md_flags;
168         unsigned int            md_niov;        /* # frags at end of struct */
169         void                   *md_user_ptr;
170         lnet_eq_t              *md_eq;
171         union {
172                 struct kvec     iov[LNET_MAX_IOV];
173                 lnet_kiov_t     kiov[LNET_MAX_IOV];
174         } md_iov;
175 } lnet_libmd_t;
176
177 #define LNET_MD_FLAG_ZOMBIE      (1 << 0)
178 #define LNET_MD_FLAG_AUTO_UNLINK (1 << 1)
179 #define LNET_MD_FLAG_ABORTED     (1 << 2)
180
181 typedef struct {
182         /* info about peers we are trying to fail */
183         struct list_head        tp_list;        /* ln_test_peers */
184         lnet_nid_t              tp_nid;         /* matching nid */
185         unsigned int            tp_threshold;   /* # failures to simulate */
186 } lnet_test_peer_t;
187
188 #define LNET_COOKIE_TYPE_MD    1
189 #define LNET_COOKIE_TYPE_ME    2
190 #define LNET_COOKIE_TYPE_EQ    3
191 #define LNET_COOKIE_TYPE_BITS  2
192 #define LNET_COOKIE_MASK        ((1ULL << LNET_COOKIE_TYPE_BITS) - 1ULL)
193
194 struct lnet_ni;                                  /* forward ref */
195 struct socket;
196
197 typedef struct lnet_lnd
198 {
199         /* fields managed by portals */
200         struct list_head        lnd_list;       /* stash in the LND table */
201         int                     lnd_refcount;   /* # active instances */
202
203         /* fields initialized by the LND */
204         __u32                   lnd_type;
205
206         int  (*lnd_startup)(struct lnet_ni *ni);
207         void (*lnd_shutdown)(struct lnet_ni *ni);
208         int  (*lnd_ctl)(struct lnet_ni *ni, unsigned int cmd, void *arg);
209
210         /* In data movement APIs below, payload buffers are described as a set
211          * of 'niov' fragments which are...
212          * EITHER
213          *    in virtual memory (struct kvec *iov != NULL)
214          * OR
215          *    in pages (kernel only: plt_kiov_t *kiov != NULL).
216          * The LND may NOT overwrite these fragment descriptors.
217          * An 'offset' and may specify a byte offset within the set of
218          * fragments to start from
219          */
220
221         /* Start sending a preformatted message.  'private' is NULL for PUT and
222          * GET messages; otherwise this is a response to an incoming message
223          * and 'private' is the 'private' passed to lnet_parse().  Return
224          * non-zero for immediate failure, otherwise complete later with
225          * lnet_finalize() */
226         int (*lnd_send)(struct lnet_ni *ni, void *private, lnet_msg_t *msg);
227
228         /* Start receiving 'mlen' bytes of payload data, skipping the following
229          * 'rlen' - 'mlen' bytes. 'private' is the 'private' passed to
230          * lnet_parse().  Return non-zero for immedaite failure, otherwise
231          * complete later with lnet_finalize().  This also gives back a receive
232          * credit if the LND does flow control. */
233         int (*lnd_recv)(struct lnet_ni *ni, void *private, lnet_msg_t *msg,
234                         int delayed, unsigned int niov,
235                         struct kvec *iov, lnet_kiov_t *kiov,
236                         unsigned int offset, unsigned int mlen, unsigned int rlen);
237
238         /* lnet_parse() has had to delay processing of this message
239          * (e.g. waiting for a forwarding buffer or send credits).  Give the
240          * LND a chance to free urgently needed resources.  If called, return 0
241          * for success and do NOT give back a receive credit; that has to wait
242          * until lnd_recv() gets called.  On failure return < 0 and
243          * release resources; lnd_recv() will not be called. */
244         int (*lnd_eager_recv)(struct lnet_ni *ni, void *private, lnet_msg_t *msg,
245                               void **new_privatep);
246
247         /* notification of peer health */
248         void (*lnd_notify)(struct lnet_ni *ni, lnet_nid_t peer, int alive);
249
250         /* query of peer aliveness */
251         void (*lnd_query)(struct lnet_ni *ni, lnet_nid_t peer, cfs_time_t *when);
252
253         /* accept a new connection */
254         int (*lnd_accept)(struct lnet_ni *ni, struct socket *sock);
255 } lnd_t;
256
257 typedef struct {
258         lnet_nid_t ns_nid;
259         __u32      ns_status;
260         __u32      ns_unused;
261 } WIRE_ATTR lnet_ni_status_t;
262
263 struct lnet_tx_queue {
264         int                     tq_credits;     /* # tx credits free */
265         int                     tq_credits_min; /* lowest it's been */
266         int                     tq_credits_max; /* total # tx credits */
267         struct list_head        tq_delayed;     /* delayed TXs */
268 };
269
270 typedef struct lnet_ni {
271         spinlock_t              ni_lock;
272         struct list_head        ni_list;        /* chain on ln_nis */
273         struct list_head        ni_cptlist;     /* chain on ln_nis_cpt */
274         int                     ni_maxtxcredits; /* # tx credits  */
275         /* # per-peer send credits */
276         int                     ni_peertxcredits;
277         /* # per-peer router buffer credits */
278         int                     ni_peerrtrcredits;
279         /* seconds to consider peer dead */
280         int                     ni_peertimeout;
281         int                     ni_ncpts;       /* number of CPTs */
282         __u32                   *ni_cpts;       /* bond NI on some CPTs */
283         lnet_nid_t              ni_nid;         /* interface's NID */
284         void                    *ni_data;       /* instance-specific data */
285         lnd_t                   *ni_lnd;        /* procedural interface */
286         struct lnet_tx_queue    **ni_tx_queues; /* percpt TX queues */
287         int                     **ni_refs;      /* percpt reference count */
288         long                    ni_last_alive;  /* when I was last alive */
289         lnet_ni_status_t        *ni_status;     /* my health status */
290         /* per NI LND tunables */
291         struct lnet_ioctl_config_lnd_tunables *ni_lnd_tunables;
292         /* equivalent interfaces to use */
293         char                    *ni_interfaces[LNET_MAX_INTERFACES];
294         struct net              *ni_net_ns;     /* original net namespace */
295 } lnet_ni_t;
296
297 #define LNET_PROTO_PING_MATCHBITS       0x8000000000000000LL
298
299 /* NB: value of these features equal to LNET_PROTO_PING_VERSION_x
300  * of old LNet, so there shouldn't be any compatibility issue */
301 #define LNET_PING_FEAT_INVAL            (0)             /* no feature */
302 #define LNET_PING_FEAT_BASE             (1 << 0)        /* just a ping */
303 #define LNET_PING_FEAT_NI_STATUS        (1 << 1)        /* return NI status */
304 #define LNET_PING_FEAT_RTE_DISABLED     (1 << 2)        /* Routing enabled */
305
306 #define LNET_PING_FEAT_MASK             (LNET_PING_FEAT_BASE | \
307                                          LNET_PING_FEAT_NI_STATUS)
308
309 typedef struct {
310         __u32                   pi_magic;
311         __u32                   pi_features;
312         lnet_pid_t              pi_pid;
313         __u32                   pi_nnis;
314         lnet_ni_status_t        pi_ni[0];
315 } WIRE_ATTR lnet_ping_info_t;
316
317 /* router checker data, per router */
318 #define LNET_MAX_RTR_NIS   16
319 #define LNET_PINGINFO_SIZE offsetof(lnet_ping_info_t, pi_ni[LNET_MAX_RTR_NIS])
320 typedef struct {
321         /* chain on the_lnet.ln_zombie_rcd or ln_deathrow_rcd */
322         struct list_head        rcd_list;
323         lnet_handle_md_t        rcd_mdh;        /* ping buffer MD */
324         struct lnet_peer        *rcd_gateway;   /* reference to gateway */
325         lnet_ping_info_t        *rcd_pinginfo;  /* ping buffer */
326 } lnet_rc_data_t;
327
328 typedef struct lnet_peer {
329         /* chain on peer hash */
330         struct list_head        lp_hashlist;
331         /* messages blocking for tx credits */
332         struct list_head        lp_txq;
333         /* messages blocking for router credits */
334         struct list_head        lp_rtrq;
335         /* chain on router list */
336         struct list_head        lp_rtr_list;
337         /* # tx credits available */
338         int                     lp_txcredits;
339         /* low water mark */
340         int                     lp_mintxcredits;
341         /* # router credits */
342         int                     lp_rtrcredits;
343         /* low water mark */
344         int                     lp_minrtrcredits;
345         /* alive/dead? */
346         unsigned int            lp_alive:1;
347         /* notification outstanding? */
348         unsigned int            lp_notify:1;
349         /* outstanding notification for LND? */
350         unsigned int            lp_notifylnd:1;
351         /* some thread is handling notification */
352         unsigned int            lp_notifying:1;
353         /* SEND event outstanding from ping */
354         unsigned int            lp_ping_notsent;
355         /* # times router went dead<->alive */
356         int                     lp_alive_count;
357         /* bytes queued for sending */
358         long                    lp_txqnob;
359         /* time of last aliveness news */
360         cfs_time_t              lp_timestamp;
361         /* time of last ping attempt */
362         cfs_time_t              lp_ping_timestamp;
363         /* != 0 if ping reply expected */
364         cfs_time_t              lp_ping_deadline;
365         /* when I was last alive */
366         cfs_time_t              lp_last_alive;
367         /* when lp_ni was queried last time */
368         cfs_time_t              lp_last_query;
369         /* interface peer is on */
370         lnet_ni_t               *lp_ni;
371         lnet_nid_t              lp_nid;         /* peer's NID */
372         int                     lp_refcount;    /* # refs */
373         int                     lp_cpt;         /* CPT this peer attached on */
374         /* # refs from lnet_route_t::lr_gateway */
375         int                     lp_rtr_refcount;
376         /* returned RC ping features */
377         unsigned int            lp_ping_feats;
378         struct list_head        lp_routes;      /* routers on this peer */
379         lnet_rc_data_t          *lp_rcd;        /* router checker state */
380 } lnet_peer_t;
381
382 /* peer hash size */
383 #define LNET_PEER_HASH_BITS     9
384 #define LNET_PEER_HASH_SIZE     (1 << LNET_PEER_HASH_BITS)
385
386 /* peer hash table */
387 struct lnet_peer_table {
388         int                     pt_version;     /* /proc validity stamp */
389         int                     pt_number;      /* # peers extant */
390         int                     pt_zombies;     /* # zombies to go to deathrow
391                                                  * (and not there yet) */
392         struct list_head        pt_deathrow;    /* zombie peers */
393         struct list_head        *pt_hash;       /* NID->peer hash */
394 };
395
396 /* peer aliveness is enabled only on routers for peers in a network where the
397  * lnet_ni_t::ni_peertimeout has been set to a positive value */
398 #define lnet_peer_aliveness_enabled(lp) (the_lnet.ln_routing != 0 && \
399                                          (lp)->lp_ni->ni_peertimeout > 0)
400
401 typedef struct {
402         struct list_head        lr_list;        /* chain on net */
403         struct list_head        lr_gwlist;      /* chain on gateway */
404         lnet_peer_t             *lr_gateway;    /* router node */
405         __u32                   lr_net;         /* remote network number */
406         int                     lr_seq;         /* sequence for round-robin */
407         unsigned int            lr_downis;      /* number of down NIs */
408         __u32                   lr_hops;        /* how far I am */
409         unsigned int            lr_priority;    /* route priority */
410 } lnet_route_t;
411
412 #define LNET_REMOTE_NETS_HASH_DEFAULT   (1U << 7)
413 #define LNET_REMOTE_NETS_HASH_MAX       (1U << 16)
414 #define LNET_REMOTE_NETS_HASH_SIZE      (1 << the_lnet.ln_remote_nets_hbits)
415
416 typedef struct {
417         /* chain on ln_remote_nets_hash */
418         struct list_head        lrn_list;
419         /* routes to me */
420         struct list_head        lrn_routes;
421         /* my net number */
422         __u32                   lrn_net;
423 } lnet_remotenet_t;
424
425 /** lnet message has credit and can be submitted to lnd for send/receive */
426 #define LNET_CREDIT_OK          0
427 /** lnet message is waiting for credit */
428 #define LNET_CREDIT_WAIT        1
429
430 typedef struct {
431         /* my free buffer pool */
432         struct list_head        rbp_bufs;
433         /* messages blocking for a buffer */
434         struct list_head        rbp_msgs;
435         /* # pages in each buffer */
436         int                     rbp_npages;
437         /* requested number of buffers */
438         int                     rbp_req_nbuffers;
439         /* # buffers actually allocated */
440         int                     rbp_nbuffers;
441         /* # free buffers / blocked messages */
442         int                     rbp_credits;
443         /* low water mark */
444         int                     rbp_mincredits;
445 } lnet_rtrbufpool_t;
446
447 typedef struct {
448         struct list_head         rb_list;       /* chain on rbp_bufs */
449         lnet_rtrbufpool_t       *rb_pool;       /* owning pool */
450         lnet_kiov_t              rb_kiov[0];    /* the buffer space */
451 } lnet_rtrbuf_t;
452
453 #define LNET_PEER_HASHSIZE   503                /* prime! */
454
455 enum {
456         /* Didn't match anything */
457         LNET_MATCHMD_NONE       = (1 << 0),
458         /* Matched OK */
459         LNET_MATCHMD_OK         = (1 << 1),
460         /* Must be discarded */
461         LNET_MATCHMD_DROP       = (1 << 2),
462         /* match and buffer is exhausted */
463         LNET_MATCHMD_EXHAUSTED  = (1 << 3),
464         /* match or drop */
465         LNET_MATCHMD_FINISH     = (LNET_MATCHMD_OK | LNET_MATCHMD_DROP),
466 };
467
468 /* Options for lnet_portal_t::ptl_options */
469 #define LNET_PTL_LAZY               (1 << 0)
470 #define LNET_PTL_MATCH_UNIQUE       (1 << 1)    /* unique match, for RDMA */
471 #define LNET_PTL_MATCH_WILDCARD     (1 << 2)    /* wildcard match, request portal */
472
473 /* parameter for matching operations (GET, PUT) */
474 struct lnet_match_info {
475         __u64                   mi_mbits;
476         lnet_process_id_t       mi_id;
477         unsigned int            mi_opc;
478         unsigned int            mi_portal;
479         unsigned int            mi_rlength;
480         unsigned int            mi_roffset;
481 };
482
483 /* ME hash of RDMA portal */
484 #define LNET_MT_HASH_BITS               8
485 #define LNET_MT_HASH_SIZE               (1 << LNET_MT_HASH_BITS)
486 #define LNET_MT_HASH_MASK               (LNET_MT_HASH_SIZE - 1)
487 /* we allocate (LNET_MT_HASH_SIZE + 1) entries for lnet_match_table::mt_hash,
488  * the last entry is reserved for MEs with ignore-bits */
489 #define LNET_MT_HASH_IGNORE             LNET_MT_HASH_SIZE
490 /* __u64 has 2^6 bits, so need 2^(LNET_MT_HASH_BITS - LNET_MT_BITS_U64) which
491  * is 4 __u64s as bit-map, and add an extra __u64 (only use one bit) for the
492  * ME-list with ignore-bits, which is mtable::mt_hash[LNET_MT_HASH_IGNORE] */
493 #define LNET_MT_BITS_U64                6       /* 2^6 bits */
494 #define LNET_MT_EXHAUSTED_BITS          (LNET_MT_HASH_BITS - LNET_MT_BITS_U64)
495 #define LNET_MT_EXHAUSTED_BMAP          ((1 << LNET_MT_EXHAUSTED_BITS) + 1)
496
497 /* portal match table */
498 struct lnet_match_table {
499         /* reserved for upcoming patches, CPU partition ID */
500         unsigned int            mt_cpt;
501         unsigned int            mt_portal;      /* portal index */
502         /* match table is set as "enabled" if there's non-exhausted MD
503          * attached on mt_mhash, it's only valid for wildcard portal */
504         unsigned int            mt_enabled;
505         /* bitmap to flag whether MEs on mt_hash are exhausted or not */
506         __u64                   mt_exhausted[LNET_MT_EXHAUSTED_BMAP];
507         struct list_head        *mt_mhash;      /* matching hash */
508 };
509
510 /* these are only useful for wildcard portal */
511 /* Turn off message rotor for wildcard portals */
512 #define LNET_PTL_ROTOR_OFF      0
513 /* round-robin dispatch all PUT messages for wildcard portals */
514 #define LNET_PTL_ROTOR_ON       1
515 /* round-robin dispatch routed PUT message for wildcard portals */
516 #define LNET_PTL_ROTOR_RR_RT    2
517 /* dispatch routed PUT message by hashing source NID for wildcard portals */
518 #define LNET_PTL_ROTOR_HASH_RT  3
519
520 typedef struct lnet_portal {
521         spinlock_t              ptl_lock;
522         unsigned int            ptl_index;      /* portal ID, reserved */
523         /* flags on this portal: lazy, unique... */
524         unsigned int            ptl_options;
525         /* list of messages which are stealing buffer */
526         struct list_head        ptl_msg_stealing;
527         /* messages blocking for MD */
528         struct list_head        ptl_msg_delayed;
529         /* Match table for each CPT */
530         struct lnet_match_table **ptl_mtables;
531         /* spread rotor of incoming "PUT" */
532         unsigned int            ptl_rotor;
533         /* # active entries for this portal */
534         int                     ptl_mt_nmaps;
535         /* array of active entries' cpu-partition-id */
536         int                     ptl_mt_maps[0];
537 } lnet_portal_t;
538
539 #define LNET_LH_HASH_BITS       12
540 #define LNET_LH_HASH_SIZE       (1ULL << LNET_LH_HASH_BITS)
541 #define LNET_LH_HASH_MASK       (LNET_LH_HASH_SIZE - 1)
542
543 /* resource container (ME, MD, EQ) */
544 struct lnet_res_container {
545         unsigned int            rec_type;       /* container type */
546         __u64                   rec_lh_cookie;  /* cookie generator */
547         struct list_head        rec_active;     /* active resource list */
548         struct list_head        *rec_lh_hash;   /* handle hash */
549 };
550
551 /* message container */
552 struct lnet_msg_container {
553         int                     msc_init;       /* initialized or not */
554         /* max # threads finalizing */
555         int                     msc_nfinalizers;
556         /* msgs waiting to complete finalizing */
557         struct list_head        msc_finalizing;
558         struct list_head        msc_active;     /* active message list */
559         /* threads doing finalization */
560         void                    **msc_finalizers;
561 };
562
563 /* Router Checker states */
564 #define LNET_RC_STATE_SHUTDOWN          0       /* not started */
565 #define LNET_RC_STATE_RUNNING           1       /* started up OK */
566 #define LNET_RC_STATE_STOPPING          2       /* telling thread to stop */
567
568 typedef struct
569 {
570         /* CPU partition table of LNet */
571         struct cfs_cpt_table            *ln_cpt_table;
572         /* number of CPTs in ln_cpt_table */
573         unsigned int                    ln_cpt_number;
574         unsigned int                    ln_cpt_bits;
575
576         /* protect LNet resources (ME/MD/EQ) */
577         struct cfs_percpt_lock          *ln_res_lock;
578         /* # portals */
579         int                             ln_nportals;
580         /* the vector of portals */
581         lnet_portal_t                   **ln_portals;
582         /* percpt ME containers */
583         struct lnet_res_container       **ln_me_containers;
584         /* percpt MD container */
585         struct lnet_res_container       **ln_md_containers;
586
587         /* Event Queue container */
588         struct lnet_res_container       ln_eq_container;
589         wait_queue_head_t               ln_eq_waitq;
590         spinlock_t                      ln_eq_wait_lock;
591
592         unsigned int                    ln_remote_nets_hbits;
593
594         /* protect NI, peer table, credits, routers, rtrbuf... */
595         struct cfs_percpt_lock          *ln_net_lock;
596         /* percpt message containers for active/finalizing/freed message */
597         struct lnet_msg_container       **ln_msg_containers;
598         lnet_counters_t                 **ln_counters;
599         struct lnet_peer_table          **ln_peer_tables;
600         /* failure simulation */
601         struct list_head                ln_test_peers;
602         struct list_head                ln_drop_rules;
603         struct list_head                ln_delay_rules;
604
605         struct list_head                ln_nis;         /* LND instances */
606         /* NIs bond on specific CPT(s) */
607         struct list_head                ln_nis_cpt;
608         /* dying LND instances */
609         struct list_head                ln_nis_zombie;
610         lnet_ni_t                       *ln_loni;       /* the loopback NI */
611
612         /* remote networks with routes to them */
613         struct list_head                *ln_remote_nets_hash;
614         /* validity stamp */
615         __u64                           ln_remote_nets_version;
616         /* list of all known routers */
617         struct list_head                ln_routers;
618         /* validity stamp */
619         __u64                           ln_routers_version;
620         /* percpt router buffer pools */
621         lnet_rtrbufpool_t               **ln_rtrpools;
622
623         lnet_handle_md_t                ln_ping_target_md;
624         lnet_handle_eq_t                ln_ping_target_eq;
625         lnet_ping_info_t                *ln_ping_info;
626
627         /* router checker startup/shutdown state */
628         int                             ln_rc_state;
629         /* router checker's event queue */
630         lnet_handle_eq_t                ln_rc_eqh;
631         /* rcd still pending on net */
632         struct list_head                ln_rcd_deathrow;
633         /* rcd ready for free */
634         struct list_head                ln_rcd_zombie;
635         /* serialise startup/shutdown */
636         struct semaphore                ln_rc_signal;
637
638         struct mutex                    ln_api_mutex;
639         struct mutex                    ln_lnd_mutex;
640         /* Have I called LNetNIInit myself? */
641         int                             ln_niinit_self;
642         /* LNetNIInit/LNetNIFini counter */
643         int                             ln_refcount;
644         /* shutdown in progress */
645         int                             ln_shutdown;
646
647         int                             ln_routing;     /* am I a router? */
648         lnet_pid_t                      ln_pid;         /* requested pid */
649         /* uniquely identifies this ni in this epoch */
650         __u64                           ln_interface_cookie;
651         /* registered LNDs */
652         struct list_head                ln_lnds;
653
654         /* test protocol compatibility flags */
655         int                             ln_testprotocompat;
656
657         /* 0 - load the NIs from the mod params
658          * 1 - do not load the NIs from the mod params
659          * Reverse logic to ensure that other calls to LNetNIInit
660          * need no change
661          */
662         bool                            ln_nis_from_mod_params;
663
664         /* waitq for router checker.  As long as there are no routes in
665          * the list, the router checker will sleep on this queue.  when
666          * routes are added the thread will wake up */
667         wait_queue_head_t               ln_rc_waitq;
668 } lnet_t;
669
670 #endif