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