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