Whamcloud - gitweb
LU-7734 lnet: Primary NID and traffic distribution
[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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lnet/include/lnet/lib-types.h
33  *
34  * Types used by the library side routines that do not need to be
35  * exposed to the user application
36  */
37
38 #ifndef __LNET_LIB_TYPES_H__
39 #define __LNET_LIB_TYPES_H__
40
41 #ifndef __KERNEL__
42 # error This include is only for kernel use.
43 #endif
44
45 #include <linux/kthread.h>
46 #include <linux/uio.h>
47 #include <linux/types.h>
48
49 #include <lnet/lnetctl.h>
50
51 /* Max payload size */
52 #ifndef CONFIG_LNET_MAX_PAYLOAD
53 # error "CONFIG_LNET_MAX_PAYLOAD must be defined in config.h"
54 #endif
55
56 #define LNET_MAX_PAYLOAD       CONFIG_LNET_MAX_PAYLOAD
57 #if (LNET_MAX_PAYLOAD < LNET_MTU)
58 # error "LNET_MAX_PAYLOAD too small - error in configure --with-max-payload-mb"
59 #elif (LNET_MAX_PAYLOAD > (PAGE_SIZE * LNET_MAX_IOV))
60 # error "LNET_MAX_PAYLOAD too large - error in configure --with-max-payload-mb"
61 #endif
62
63 /* forward refs */
64 struct lnet_libmd;
65
66 typedef struct lnet_msg {
67         struct list_head        msg_activelist;
68         struct list_head        msg_list;       /* Q for credits/MD */
69
70         lnet_process_id_t       msg_target;
71         /* Primary NID of the source. */
72         lnet_nid_t              msg_initiator;
73         /* where is it from, it's only for building event */
74         lnet_nid_t              msg_from;
75         __u32                   msg_type;
76
77         /* committed for sending */
78         unsigned int            msg_tx_committed:1;
79         /* CPT # this message committed for sending */
80         unsigned int            msg_tx_cpt:15;
81         /* committed for receiving */
82         unsigned int            msg_rx_committed:1;
83         /* CPT # this message committed for receiving */
84         unsigned int            msg_rx_cpt:15;
85         /* queued for tx credit */
86         unsigned int            msg_tx_delayed:1;
87         /* queued for RX buffer */
88         unsigned int            msg_rx_delayed:1;
89         /* ready for pending on RX delay list */
90         unsigned int            msg_rx_ready_delay:1;
91
92         unsigned int          msg_vmflush:1;      /* VM trying to free memory */
93         unsigned int          msg_target_is_router:1; /* sending to a router */
94         unsigned int          msg_routing:1;      /* being forwarded */
95         unsigned int          msg_ack:1;          /* ack on finalize (PUT) */
96         unsigned int          msg_sending:1;      /* outgoing message */
97         unsigned int          msg_receiving:1;    /* being received */
98         unsigned int          msg_txcredit:1;     /* taken an NI send credit */
99         unsigned int          msg_peertxcredit:1; /* taken a peer send credit */
100         unsigned int          msg_rtrcredit:1;    /* taken a globel router credit */
101         unsigned int          msg_peerrtrcredit:1; /* taken a peer router credit */
102         unsigned int          msg_onactivelist:1; /* on the activelist */
103         unsigned int          msg_rdma_get:1;
104
105         struct lnet_peer_ni  *msg_txpeer;         /* peer I'm sending to */
106         struct lnet_peer_ni  *msg_rxpeer;         /* peer I received from */
107
108         void                 *msg_private;
109         struct lnet_libmd    *msg_md;
110         /* the NI the message was sent or received over */
111         struct lnet_ni       *msg_txni;
112         struct lnet_ni       *msg_rxni;
113
114         unsigned int          msg_len;
115         unsigned int          msg_wanted;
116         unsigned int          msg_offset;
117         unsigned int          msg_niov;
118         struct kvec          *msg_iov;
119         lnet_kiov_t          *msg_kiov;
120
121         lnet_event_t          msg_ev;
122         lnet_hdr_t            msg_hdr;
123 } lnet_msg_t;
124
125
126 typedef struct lnet_libhandle {
127         struct list_head        lh_hash_chain;
128         __u64                   lh_cookie;
129 } lnet_libhandle_t;
130
131 #define lh_entry(ptr, type, member) \
132         ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
133
134 typedef struct lnet_eq {
135         struct list_head        eq_list;
136         lnet_libhandle_t        eq_lh;
137         lnet_seq_t              eq_enq_seq;
138         lnet_seq_t              eq_deq_seq;
139         unsigned int            eq_size;
140         lnet_eq_handler_t       eq_callback;
141         lnet_event_t            *eq_events;
142         int                     **eq_refs;      /* percpt refcount for EQ */
143 } lnet_eq_t;
144
145 typedef struct lnet_me {
146         struct list_head        me_list;
147         lnet_libhandle_t        me_lh;
148         lnet_process_id_t       me_match_id;
149         unsigned int            me_portal;
150         unsigned int            me_pos;         /* hash offset in mt_hash */
151         __u64                   me_match_bits;
152         __u64                   me_ignore_bits;
153         lnet_unlink_t           me_unlink;
154         struct lnet_libmd      *me_md;
155 } lnet_me_t;
156
157 typedef struct lnet_libmd {
158         struct list_head        md_list;
159         lnet_libhandle_t        md_lh;
160         lnet_me_t              *md_me;
161         char                   *md_start;
162         unsigned int            md_offset;
163         unsigned int            md_length;
164         unsigned int            md_max_size;
165         int                     md_threshold;
166         int                     md_refcount;
167         unsigned int            md_options;
168         unsigned int            md_flags;
169         unsigned int            md_niov;        /* # frags at end of struct */
170         void                   *md_user_ptr;
171         lnet_eq_t              *md_eq;
172         union {
173                 struct kvec     iov[LNET_MAX_IOV];
174                 lnet_kiov_t     kiov[LNET_MAX_IOV];
175         } md_iov;
176 } lnet_libmd_t;
177
178 #define LNET_MD_FLAG_ZOMBIE      (1 << 0)
179 #define LNET_MD_FLAG_AUTO_UNLINK (1 << 1)
180 #define LNET_MD_FLAG_ABORTED     (1 << 2)
181
182 typedef struct {
183         /* info about peers we are trying to fail */
184         struct list_head        tp_list;        /* ln_test_peers */
185         lnet_nid_t              tp_nid;         /* matching nid */
186         unsigned int            tp_threshold;   /* # failures to simulate */
187 } lnet_test_peer_t;
188
189 #define LNET_COOKIE_TYPE_MD    1
190 #define LNET_COOKIE_TYPE_ME    2
191 #define LNET_COOKIE_TYPE_EQ    3
192 #define LNET_COOKIE_TYPE_BITS  2
193 #define LNET_COOKIE_MASK        ((1ULL << LNET_COOKIE_TYPE_BITS) - 1ULL)
194
195 struct lnet_ni;                                  /* forward ref */
196 struct socket;
197
198 typedef struct lnet_lnd
199 {
200         /* fields managed by portals */
201         struct list_head        lnd_list;       /* stash in the LND table */
202         int                     lnd_refcount;   /* # active instances */
203
204         /* fields initialized by the LND */
205         __u32                   lnd_type;
206
207         int  (*lnd_startup)(struct lnet_ni *ni);
208         void (*lnd_shutdown)(struct lnet_ni *ni);
209         int  (*lnd_ctl)(struct lnet_ni *ni, unsigned int cmd, void *arg);
210
211         /* In data movement APIs below, payload buffers are described as a set
212          * of 'niov' fragments which are...
213          * EITHER
214          *    in virtual memory (struct kvec *iov != NULL)
215          * OR
216          *    in pages (kernel only: plt_kiov_t *kiov != NULL).
217          * The LND may NOT overwrite these fragment descriptors.
218          * An 'offset' and may specify a byte offset within the set of
219          * fragments to start from
220          */
221
222         /* Start sending a preformatted message.  'private' is NULL for PUT and
223          * GET messages; otherwise this is a response to an incoming message
224          * and 'private' is the 'private' passed to lnet_parse().  Return
225          * non-zero for immediate failure, otherwise complete later with
226          * lnet_finalize() */
227         int (*lnd_send)(struct lnet_ni *ni, void *private, lnet_msg_t *msg);
228
229         /* Start receiving 'mlen' bytes of payload data, skipping the following
230          * 'rlen' - 'mlen' bytes. 'private' is the 'private' passed to
231          * lnet_parse().  Return non-zero for immedaite failure, otherwise
232          * complete later with lnet_finalize().  This also gives back a receive
233          * credit if the LND does flow control. */
234         int (*lnd_recv)(struct lnet_ni *ni, void *private, lnet_msg_t *msg,
235                         int delayed, unsigned int niov,
236                         struct kvec *iov, lnet_kiov_t *kiov,
237                         unsigned int offset, unsigned int mlen, unsigned int rlen);
238
239         /* lnet_parse() has had to delay processing of this message
240          * (e.g. waiting for a forwarding buffer or send credits).  Give the
241          * LND a chance to free urgently needed resources.  If called, return 0
242          * for success and do NOT give back a receive credit; that has to wait
243          * until lnd_recv() gets called.  On failure return < 0 and
244          * release resources; lnd_recv() will not be called. */
245         int (*lnd_eager_recv)(struct lnet_ni *ni, void *private, lnet_msg_t *msg,
246                               void **new_privatep);
247
248         /* notification of peer health */
249         void (*lnd_notify)(struct lnet_ni *ni, lnet_nid_t peer, int alive);
250
251         /* query of peer aliveness */
252         void (*lnd_query)(struct lnet_ni *ni, lnet_nid_t peer, cfs_time_t *when);
253
254         /* accept a new connection */
255         int (*lnd_accept)(struct lnet_ni *ni, struct socket *sock);
256 } lnd_t;
257
258 typedef struct lnet_ni_status {
259         lnet_nid_t ns_nid;
260         __u32      ns_status;
261         __u32      ns_unused;
262 } WIRE_ATTR lnet_ni_status_t;
263
264 struct lnet_tx_queue {
265         int                     tq_credits;     /* # tx credits free */
266         int                     tq_credits_min; /* lowest it's been */
267         int                     tq_credits_max; /* total # tx credits */
268         struct list_head        tq_delayed;     /* delayed TXs */
269 };
270
271 enum lnet_net_state {
272         /* set when net block is allocated */
273         LNET_NET_STATE_INIT = 0,
274         /* set when NIs in net are started successfully */
275         LNET_NET_STATE_ACTIVE,
276         /* set if all NIs in net are in FAILED state */
277         LNET_NET_STATE_INACTIVE,
278         /* set when shutting down a NET */
279         LNET_NET_STATE_DELETING
280 };
281
282 enum lnet_ni_state {
283         /* set when NI block is allocated */
284         LNET_NI_STATE_INIT = 0,
285         /* set when NI is started successfully */
286         LNET_NI_STATE_ACTIVE,
287         /* set when LND notifies NI failed */
288         LNET_NI_STATE_FAILED,
289         /* set when LND notifies NI degraded */
290         LNET_NI_STATE_DEGRADED,
291         /* set when shuttding down NI */
292         LNET_NI_STATE_DELETING
293 };
294
295 struct lnet_net {
296         /* chain on the ln_nets */
297         struct list_head        net_list;
298
299         /* net ID, which is compoed of
300          * (net_type << 16) | net_num.
301          * net_type can be one of the enumarated types defined in
302          * lnet/include/lnet/nidstr.h */
303         __u32                   net_id;
304
305         /* priority of the network */
306         __u32                   net_prio;
307
308         /* total number of CPTs in the array */
309         __u32                   net_ncpts;
310
311         /* cumulative CPTs of all NIs in this net */
312         __u32                   *net_cpts;
313
314         /* network tunables */
315         struct lnet_ioctl_config_lnd_cmn_tunables net_tunables;
316
317         /*
318          * boolean to indicate that the tunables have been set and
319          * shouldn't be reset
320          */
321         bool                    net_tunables_set;
322
323         /* procedural interface */
324         lnd_t                   *net_lnd;
325
326         /* list of NIs on this net */
327         struct list_head        net_ni_list;
328
329         /* list of NIs being added, but not started yet */
330         struct list_head        net_ni_added;
331
332         /* dying LND instances */
333         struct list_head        net_ni_zombie;
334
335         /* network state */
336         enum lnet_net_state     net_state;
337 };
338
339 typedef struct lnet_ni {
340         /* chain on the lnet_net structure */
341         struct list_head        ni_netlist;
342
343         /* chain on net_ni_cpt */
344         struct list_head        ni_cptlist;
345
346         spinlock_t              ni_lock;
347
348         /* number of CPTs */
349         int                     ni_ncpts;
350
351         /* bond NI on some CPTs */
352         __u32                   *ni_cpts;
353
354         /* interface's NID */
355         lnet_nid_t              ni_nid;
356
357         /* instance-specific data */
358         void                    *ni_data;
359
360         /* percpt TX queues */
361         struct lnet_tx_queue    **ni_tx_queues;
362
363         /* percpt reference count */
364         int                     **ni_refs;
365
366         /* when I was last alive */
367         long                    ni_last_alive;
368
369         /* pointer to parent network */
370         struct lnet_net         *ni_net;
371
372         /* my health status */
373         lnet_ni_status_t        *ni_status;
374
375         /* NI FSM */
376         enum lnet_ni_state      ni_state;
377
378         /* per NI LND tunables */
379         struct lnet_lnd_tunables ni_lnd_tunables;
380
381         /* lnd tunables set explicitly */
382         bool ni_lnd_tunables_set;
383
384         /* physical device CPT */
385         int                     dev_cpt;
386
387         /* sequence number used to round robin over nis within a net */
388         __u32                   ni_seq;
389
390         /*
391          * equivalent interfaces to use
392          * This is an array because socklnd bonding can still be configured
393          */
394         char                    *ni_interfaces[LNET_MAX_INTERFACES];
395         struct net              *ni_net_ns;     /* original net namespace */
396 } lnet_ni_t;
397
398 #define LNET_PROTO_PING_MATCHBITS       0x8000000000000000LL
399
400 /* NB: value of these features equal to LNET_PROTO_PING_VERSION_x
401  * of old LNet, so there shouldn't be any compatibility issue */
402 #define LNET_PING_FEAT_INVAL            (0)             /* no feature */
403 #define LNET_PING_FEAT_BASE             (1 << 0)        /* just a ping */
404 #define LNET_PING_FEAT_NI_STATUS        (1 << 1)        /* return NI status */
405 #define LNET_PING_FEAT_RTE_DISABLED     (1 << 2)        /* Routing enabled */
406
407 #define LNET_PING_FEAT_MASK             (LNET_PING_FEAT_BASE | \
408                                          LNET_PING_FEAT_NI_STATUS)
409
410 typedef struct lnet_ping_info {
411         __u32                   pi_magic;
412         __u32                   pi_features;
413         lnet_pid_t              pi_pid;
414         __u32                   pi_nnis;
415         struct lnet_ni_status   pi_ni[0];
416 } WIRE_ATTR lnet_ping_info_t;
417
418 /* router checker data, per router */
419 #define LNET_MAX_RTR_NIS   16
420 #define LNET_PINGINFO_SIZE offsetof(struct lnet_ping_info, pi_ni[LNET_MAX_RTR_NIS])
421 typedef struct {
422         /* chain on the_lnet.ln_zombie_rcd or ln_deathrow_rcd */
423         struct list_head        rcd_list;
424         lnet_handle_md_t        rcd_mdh;        /* ping buffer MD */
425         struct lnet_peer_ni     *rcd_gateway;   /* reference to gateway */
426         struct lnet_ping_info   *rcd_pinginfo;  /* ping buffer */
427 } lnet_rc_data_t;
428
429 struct lnet_peer_ni {
430         /* cahian on peer_net */
431         struct list_head        lpni_on_peer_net_list;
432         /* chain on remote peer list */
433         struct list_head        lpni_on_remote_peer_ni_list;
434         /* chain on peer hash */
435         struct list_head        lpni_hashlist;
436         /* messages blocking for tx credits */
437         struct list_head        lpni_txq;
438         /* messages blocking for router credits */
439         struct list_head        lpni_rtrq;
440         /* chain on router list */
441         struct list_head        lpni_rtr_list;
442         /* pointer to peer net I'm part of */
443         struct lnet_peer_net    *lpni_peer_net;
444         /* # tx credits available */
445         int                     lpni_txcredits;
446         /* low water mark */
447         int                     lpni_mintxcredits;
448         /* # router credits */
449         int                     lpni_rtrcredits;
450         /* low water mark */
451         int                     lpni_minrtrcredits;
452         /* alive/dead? */
453         unsigned int            lpni_alive:1;
454         /* notification outstanding? */
455         unsigned int            lpni_notify:1;
456         /* outstanding notification for LND? */
457         unsigned int            lpni_notifylnd:1;
458         /* some thread is handling notification */
459         unsigned int            lpni_notifying:1;
460         /* SEND event outstanding from ping */
461         unsigned int            lpni_ping_notsent;
462         /* # times router went dead<->alive */
463         int                     lpni_alive_count;
464         /* bytes queued for sending */
465         long                    lpni_txqnob;
466         /* time of last aliveness news */
467         cfs_time_t              lpni_timestamp;
468         /* time of last ping attempt */
469         cfs_time_t              lpni_ping_timestamp;
470         /* != 0 if ping reply expected */
471         cfs_time_t              lpni_ping_deadline;
472         /* when I was last alive */
473         cfs_time_t              lpni_last_alive;
474         /* when lpni_ni was queried last time */
475         cfs_time_t              lpni_last_query;
476         /* network peer is on */
477         struct lnet_net         *lpni_net;
478         /* peer's NID */
479         lnet_nid_t              lpni_nid;
480         /* # refs */
481         atomic_t                lpni_refcount;
482         /* CPT this peer attached on */
483         int                     lpni_cpt;
484         /* # refs from lnet_route_t::lr_gateway */
485         int                     lpni_rtr_refcount;
486         /* sequence number used to round robin over peer nis within a net */
487         __u32                   lpni_seq;
488         /* health flag */
489         bool                    lpni_healthy;
490         /* returned RC ping features */
491         unsigned int            lpni_ping_feats;
492         /* routes on this peer */
493         struct list_head        lpni_routes;
494         /* array of preferred local nids */
495         lnet_nid_t              *lpni_pref_nids;
496         /* number of preferred NIDs in lnpi_pref_nids */
497         __u32                   lpni_pref_nnids;
498         /* router checker state */
499         lnet_rc_data_t          *lpni_rcd;
500 };
501
502 struct lnet_peer {
503         /* chain on global peer list */
504         struct list_head        lp_on_lnet_peer_list;
505
506         /* list of peer nets */
507         struct list_head        lp_peer_nets;
508
509         /* primary NID of the peer */
510         lnet_nid_t              lp_primary_nid;
511
512         /* peer is Multi-Rail enabled peer */
513         bool                    lp_multi_rail;
514 };
515
516 struct lnet_peer_net {
517         /* chain on peer block */
518         struct list_head        lpn_on_peer_list;
519
520         /* list of peer_nis on this network */
521         struct list_head        lpn_peer_nis;
522
523         /* pointer to the peer I'm part of */
524         struct lnet_peer        *lpn_peer;
525
526         /* Net ID */
527         __u32                   lpn_net_id;
528
529         /* health flag */
530         bool                    lpn_healthy;
531 };
532
533 /* peer hash size */
534 #define LNET_PEER_HASH_BITS     9
535 #define LNET_PEER_HASH_SIZE     (1 << LNET_PEER_HASH_BITS)
536
537 /* peer hash table */
538 struct lnet_peer_table {
539         int                     pt_version;     /* /proc validity stamp */
540         int                     pt_number;      /* # peers extant */
541         int                     pt_zombies;     /* # zombies to go to deathrow
542                                                  * (and not there yet) */
543         struct list_head        pt_deathrow;    /* zombie peers */
544         struct list_head        *pt_hash;       /* NID->peer hash */
545 };
546
547 /* peer aliveness is enabled only on routers for peers in a network where the
548  * lnet_ni_t::ni_peertimeout has been set to a positive value */
549 #define lnet_peer_aliveness_enabled(lp) (the_lnet.ln_routing != 0 && \
550                                          (lp)->lpni_net->net_tunables.lct_peer_timeout > 0)
551
552 typedef struct {
553         struct list_head        lr_list;        /* chain on net */
554         struct list_head        lr_gwlist;      /* chain on gateway */
555         struct lnet_peer_ni     *lr_gateway;    /* router node */
556         __u32                   lr_net;         /* remote network number */
557         int                     lr_seq;         /* sequence for round-robin */
558         unsigned int            lr_downis;      /* number of down NIs */
559         __u32                   lr_hops;        /* how far I am */
560         unsigned int            lr_priority;    /* route priority */
561 } lnet_route_t;
562
563 #define LNET_REMOTE_NETS_HASH_DEFAULT   (1U << 7)
564 #define LNET_REMOTE_NETS_HASH_MAX       (1U << 16)
565 #define LNET_REMOTE_NETS_HASH_SIZE      (1 << the_lnet.ln_remote_nets_hbits)
566
567 typedef struct {
568         /* chain on ln_remote_nets_hash */
569         struct list_head        lrn_list;
570         /* routes to me */
571         struct list_head        lrn_routes;
572         /* my net number */
573         __u32                   lrn_net;
574 } lnet_remotenet_t;
575
576 /** lnet message has credit and can be submitted to lnd for send/receive */
577 #define LNET_CREDIT_OK          0
578 /** lnet message is waiting for credit */
579 #define LNET_CREDIT_WAIT        1
580
581 typedef struct {
582         /* my free buffer pool */
583         struct list_head        rbp_bufs;
584         /* messages blocking for a buffer */
585         struct list_head        rbp_msgs;
586         /* # pages in each buffer */
587         int                     rbp_npages;
588         /* requested number of buffers */
589         int                     rbp_req_nbuffers;
590         /* # buffers actually allocated */
591         int                     rbp_nbuffers;
592         /* # free buffers / blocked messages */
593         int                     rbp_credits;
594         /* low water mark */
595         int                     rbp_mincredits;
596 } lnet_rtrbufpool_t;
597
598 typedef struct {
599         struct list_head         rb_list;       /* chain on rbp_bufs */
600         lnet_rtrbufpool_t       *rb_pool;       /* owning pool */
601         lnet_kiov_t              rb_kiov[0];    /* the buffer space */
602 } lnet_rtrbuf_t;
603
604 #define LNET_PEER_HASHSIZE   503                /* prime! */
605
606 enum {
607         /* Didn't match anything */
608         LNET_MATCHMD_NONE       = (1 << 0),
609         /* Matched OK */
610         LNET_MATCHMD_OK         = (1 << 1),
611         /* Must be discarded */
612         LNET_MATCHMD_DROP       = (1 << 2),
613         /* match and buffer is exhausted */
614         LNET_MATCHMD_EXHAUSTED  = (1 << 3),
615         /* match or drop */
616         LNET_MATCHMD_FINISH     = (LNET_MATCHMD_OK | LNET_MATCHMD_DROP),
617 };
618
619 /* Options for lnet_portal_t::ptl_options */
620 #define LNET_PTL_LAZY               (1 << 0)
621 #define LNET_PTL_MATCH_UNIQUE       (1 << 1)    /* unique match, for RDMA */
622 #define LNET_PTL_MATCH_WILDCARD     (1 << 2)    /* wildcard match, request portal */
623
624 /* parameter for matching operations (GET, PUT) */
625 struct lnet_match_info {
626         __u64                   mi_mbits;
627         lnet_process_id_t       mi_id;
628         unsigned int            mi_cpt;
629         unsigned int            mi_opc;
630         unsigned int            mi_portal;
631         unsigned int            mi_rlength;
632         unsigned int            mi_roffset;
633 };
634
635 /* ME hash of RDMA portal */
636 #define LNET_MT_HASH_BITS               8
637 #define LNET_MT_HASH_SIZE               (1 << LNET_MT_HASH_BITS)
638 #define LNET_MT_HASH_MASK               (LNET_MT_HASH_SIZE - 1)
639 /* we allocate (LNET_MT_HASH_SIZE + 1) entries for lnet_match_table::mt_hash,
640  * the last entry is reserved for MEs with ignore-bits */
641 #define LNET_MT_HASH_IGNORE             LNET_MT_HASH_SIZE
642 /* __u64 has 2^6 bits, so need 2^(LNET_MT_HASH_BITS - LNET_MT_BITS_U64) which
643  * is 4 __u64s as bit-map, and add an extra __u64 (only use one bit) for the
644  * ME-list with ignore-bits, which is mtable::mt_hash[LNET_MT_HASH_IGNORE] */
645 #define LNET_MT_BITS_U64                6       /* 2^6 bits */
646 #define LNET_MT_EXHAUSTED_BITS          (LNET_MT_HASH_BITS - LNET_MT_BITS_U64)
647 #define LNET_MT_EXHAUSTED_BMAP          ((1 << LNET_MT_EXHAUSTED_BITS) + 1)
648
649 /* portal match table */
650 struct lnet_match_table {
651         /* reserved for upcoming patches, CPU partition ID */
652         unsigned int            mt_cpt;
653         unsigned int            mt_portal;      /* portal index */
654         /* match table is set as "enabled" if there's non-exhausted MD
655          * attached on mt_mhash, it's only valid for wildcard portal */
656         unsigned int            mt_enabled;
657         /* bitmap to flag whether MEs on mt_hash are exhausted or not */
658         __u64                   mt_exhausted[LNET_MT_EXHAUSTED_BMAP];
659         struct list_head        *mt_mhash;      /* matching hash */
660 };
661
662 /* these are only useful for wildcard portal */
663 /* Turn off message rotor for wildcard portals */
664 #define LNET_PTL_ROTOR_OFF      0
665 /* round-robin dispatch all PUT messages for wildcard portals */
666 #define LNET_PTL_ROTOR_ON       1
667 /* round-robin dispatch routed PUT message for wildcard portals */
668 #define LNET_PTL_ROTOR_RR_RT    2
669 /* dispatch routed PUT message by hashing source NID for wildcard portals */
670 #define LNET_PTL_ROTOR_HASH_RT  3
671
672 typedef struct lnet_portal {
673         spinlock_t              ptl_lock;
674         unsigned int            ptl_index;      /* portal ID, reserved */
675         /* flags on this portal: lazy, unique... */
676         unsigned int            ptl_options;
677         /* list of messages which are stealing buffer */
678         struct list_head        ptl_msg_stealing;
679         /* messages blocking for MD */
680         struct list_head        ptl_msg_delayed;
681         /* Match table for each CPT */
682         struct lnet_match_table **ptl_mtables;
683         /* spread rotor of incoming "PUT" */
684         unsigned int            ptl_rotor;
685         /* # active entries for this portal */
686         int                     ptl_mt_nmaps;
687         /* array of active entries' cpu-partition-id */
688         int                     ptl_mt_maps[0];
689 } lnet_portal_t;
690
691 #define LNET_LH_HASH_BITS       12
692 #define LNET_LH_HASH_SIZE       (1ULL << LNET_LH_HASH_BITS)
693 #define LNET_LH_HASH_MASK       (LNET_LH_HASH_SIZE - 1)
694
695 /* resource container (ME, MD, EQ) */
696 struct lnet_res_container {
697         unsigned int            rec_type;       /* container type */
698         __u64                   rec_lh_cookie;  /* cookie generator */
699         struct list_head        rec_active;     /* active resource list */
700         struct list_head        *rec_lh_hash;   /* handle hash */
701 };
702
703 /* message container */
704 struct lnet_msg_container {
705         int                     msc_init;       /* initialized or not */
706         /* max # threads finalizing */
707         int                     msc_nfinalizers;
708         /* msgs waiting to complete finalizing */
709         struct list_head        msc_finalizing;
710         struct list_head        msc_active;     /* active message list */
711         /* threads doing finalization */
712         void                    **msc_finalizers;
713 };
714
715 /* Router Checker states */
716 #define LNET_RC_STATE_SHUTDOWN          0       /* not started */
717 #define LNET_RC_STATE_RUNNING           1       /* started up OK */
718 #define LNET_RC_STATE_STOPPING          2       /* telling thread to stop */
719
720 typedef struct
721 {
722         /* CPU partition table of LNet */
723         struct cfs_cpt_table            *ln_cpt_table;
724         /* number of CPTs in ln_cpt_table */
725         unsigned int                    ln_cpt_number;
726         unsigned int                    ln_cpt_bits;
727
728         /* protect LNet resources (ME/MD/EQ) */
729         struct cfs_percpt_lock          *ln_res_lock;
730         /* # portals */
731         int                             ln_nportals;
732         /* the vector of portals */
733         lnet_portal_t                   **ln_portals;
734         /* percpt ME containers */
735         struct lnet_res_container       **ln_me_containers;
736         /* percpt MD container */
737         struct lnet_res_container       **ln_md_containers;
738
739         /* Event Queue container */
740         struct lnet_res_container       ln_eq_container;
741         wait_queue_head_t               ln_eq_waitq;
742         spinlock_t                      ln_eq_wait_lock;
743
744         unsigned int                    ln_remote_nets_hbits;
745
746         /* protect NI, peer table, credits, routers, rtrbuf... */
747         struct cfs_percpt_lock          *ln_net_lock;
748         /* percpt message containers for active/finalizing/freed message */
749         struct lnet_msg_container       **ln_msg_containers;
750         lnet_counters_t                 **ln_counters;
751         struct lnet_peer_table          **ln_peer_tables;
752         /* list of configured or discovered peers */
753         struct list_head                ln_peers;
754         /* list of peer nis not on a local network */
755         struct list_head                ln_remote_peer_ni_list;
756         /* failure simulation */
757         struct list_head                ln_test_peers;
758         struct list_head                ln_drop_rules;
759         struct list_head                ln_delay_rules;
760         /* LND instances */
761         struct list_head                ln_nets;
762         /* the loopback NI */
763         struct lnet_ni                  *ln_loni;
764         /* network zombie list */
765         struct list_head                ln_net_zombie;
766
767         /* remote networks with routes to them */
768         struct list_head                *ln_remote_nets_hash;
769         /* validity stamp */
770         __u64                           ln_remote_nets_version;
771         /* list of all known routers */
772         struct list_head                ln_routers;
773         /* validity stamp */
774         __u64                           ln_routers_version;
775         /* percpt router buffer pools */
776         lnet_rtrbufpool_t               **ln_rtrpools;
777
778         lnet_handle_md_t                ln_ping_target_md;
779         lnet_handle_eq_t                ln_ping_target_eq;
780         struct lnet_ping_info           *ln_ping_info;
781
782         /* router checker startup/shutdown state */
783         int                             ln_rc_state;
784         /* router checker's event queue */
785         lnet_handle_eq_t                ln_rc_eqh;
786         /* rcd still pending on net */
787         struct list_head                ln_rcd_deathrow;
788         /* rcd ready for free */
789         struct list_head                ln_rcd_zombie;
790         /* serialise startup/shutdown */
791         struct semaphore                ln_rc_signal;
792
793         struct mutex                    ln_api_mutex;
794         struct mutex                    ln_lnd_mutex;
795         /* Have I called LNetNIInit myself? */
796         int                             ln_niinit_self;
797         /* LNetNIInit/LNetNIFini counter */
798         int                             ln_refcount;
799         /* shutdown in progress */
800         int                             ln_shutdown;
801
802         int                             ln_routing;     /* am I a router? */
803         lnet_pid_t                      ln_pid;         /* requested pid */
804         /* uniquely identifies this ni in this epoch */
805         __u64                           ln_interface_cookie;
806         /* registered LNDs */
807         struct list_head                ln_lnds;
808
809         /* test protocol compatibility flags */
810         int                             ln_testprotocompat;
811
812         /* 0 - load the NIs from the mod params
813          * 1 - do not load the NIs from the mod params
814          * Reverse logic to ensure that other calls to LNetNIInit
815          * need no change
816          */
817         bool                            ln_nis_from_mod_params;
818
819         /* waitq for router checker.  As long as there are no routes in
820          * the list, the router checker will sleep on this queue.  when
821          * routes are added the thread will wake up */
822         wait_queue_head_t               ln_rc_waitq;
823 } lnet_t;
824
825 #endif