Whamcloud - gitweb
LU-10391 lnet: change ni_status in lnet_ni to u32*
[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, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * lnet/include/lnet/lib-types.h
32  *
33  * Types used by the library side routines that do not need to be
34  * exposed to the user application
35  */
36
37 #ifndef __LNET_LIB_TYPES_H__
38 #define __LNET_LIB_TYPES_H__
39
40 #ifndef __KERNEL__
41 # error This include is only for kernel use.
42 #endif
43
44 #include <linux/kthread.h>
45 #include <linux/uio.h>
46 #include <linux/semaphore.h>
47 #include <linux/types.h>
48 #include <linux/kref.h>
49 #include <net/genetlink.h>
50
51 #include <uapi/linux/lnet/lnet-nl.h>
52 #include <uapi/linux/lnet/lnet-dlc.h>
53 #include <uapi/linux/lnet/lnetctl.h>
54 #include <uapi/linux/lnet/nidstr.h>
55
56 char *libcfs_nidstr_r(const struct lnet_nid *nid,
57                       char *buf, size_t buf_size);
58
59 static inline char *libcfs_nidstr(const struct lnet_nid *nid)
60 {
61         return libcfs_nidstr_r(nid, libcfs_next_nidstring(),
62                                LNET_NIDSTR_SIZE);
63 }
64
65 int libcfs_strnid(struct lnet_nid *nid, const char *str);
66 char *libcfs_idstr(struct lnet_processid *id);
67
68 int cfs_match_nid_net(struct lnet_nid *nid, u32 net,
69                       struct list_head *net_num_list,
70                       struct list_head *addr);
71
72 /* Max payload size */
73 #define LNET_MAX_PAYLOAD        LNET_MTU
74
75 /** limit on the number of fragments in discontiguous MDs */
76 #define LNET_MAX_IOV    256
77
78 /*
79  * This is the maximum health value.
80  * All local and peer NIs created have their health default to this value.
81  */
82 #define LNET_MAX_HEALTH_VALUE 1000
83 #define LNET_MAX_SELECTION_PRIORITY UINT_MAX
84
85 /* forward refs */
86 struct lnet_libmd;
87
88 enum lnet_msg_hstatus {
89         LNET_MSG_STATUS_OK = 0,
90         LNET_MSG_STATUS_LOCAL_INTERRUPT,
91         LNET_MSG_STATUS_LOCAL_DROPPED,
92         LNET_MSG_STATUS_LOCAL_ABORTED,
93         LNET_MSG_STATUS_LOCAL_NO_ROUTE,
94         LNET_MSG_STATUS_LOCAL_ERROR,
95         LNET_MSG_STATUS_LOCAL_TIMEOUT,
96         LNET_MSG_STATUS_REMOTE_ERROR,
97         LNET_MSG_STATUS_REMOTE_DROPPED,
98         LNET_MSG_STATUS_REMOTE_TIMEOUT,
99         LNET_MSG_STATUS_NETWORK_TIMEOUT,
100         LNET_MSG_STATUS_END,
101 };
102
103 struct lnet_rsp_tracker {
104         /* chain on the waiting list */
105         struct list_head rspt_on_list;
106         /* cpt to lock */
107         int rspt_cpt;
108         /* nid of next hop */
109         struct lnet_nid rspt_next_hop_nid;
110         /* deadline of the REPLY/ACK */
111         ktime_t rspt_deadline;
112         /* parent MD */
113         struct lnet_handle_md rspt_mdh;
114 };
115
116 struct lnet_msg {
117         struct list_head        msg_activelist;
118         struct list_head        msg_list;       /* Q for credits/MD */
119
120         struct lnet_processid   msg_target;
121         /* Primary NID of the source. */
122         struct lnet_nid         msg_initiator;
123         /* where is it from, it's only for building event */
124         struct lnet_nid         msg_from;
125         __u32                   msg_type;
126
127         /*
128          * hold parameters in case message is with held due
129          * to discovery
130          */
131         struct lnet_nid         msg_src_nid_param;
132         struct lnet_nid         msg_rtr_nid_param;
133
134         /*
135          * Deadline for the message after which it will be finalized if it
136          * has not completed.
137          */
138         ktime_t                 msg_deadline;
139
140         /* The message health status. */
141         enum lnet_msg_hstatus   msg_health_status;
142         /* This is a recovery message */
143         bool                    msg_recovery;
144         /* the number of times a transmission has been retried */
145         int                     msg_retry_count;
146         /* flag to indicate that we do not want to resend this message */
147         bool                    msg_no_resend;
148
149         /* committed for sending */
150         unsigned int            msg_tx_committed:1;
151         /* CPT # this message committed for sending */
152         unsigned int            msg_tx_cpt:15;
153         /* committed for receiving */
154         unsigned int            msg_rx_committed:1;
155         /* CPT # this message committed for receiving */
156         unsigned int            msg_rx_cpt:15;
157         /* queued for tx credit */
158         unsigned int            msg_tx_delayed:1;
159         /* queued for RX buffer */
160         unsigned int            msg_rx_delayed:1;
161         /* ready for pending on RX delay list */
162         unsigned int            msg_rx_ready_delay:1;
163
164         unsigned int          msg_vmflush:1;      /* VM trying to free memory */
165         unsigned int          msg_target_is_router:1; /* sending to a router */
166         unsigned int          msg_routing:1;      /* being forwarded */
167         unsigned int          msg_ack:1;          /* ack on finalize (PUT) */
168         unsigned int          msg_sending:1;      /* outgoing message */
169         unsigned int          msg_receiving:1;    /* being received */
170         unsigned int          msg_txcredit:1;     /* taken an NI send credit */
171         unsigned int          msg_peertxcredit:1; /* taken a peer send credit */
172         unsigned int          msg_rtrcredit:1;    /* taken a globel router credit */
173         unsigned int          msg_peerrtrcredit:1; /* taken a peer router credit */
174         unsigned int          msg_onactivelist:1; /* on the activelist */
175         unsigned int          msg_rdma_get:1;
176
177         struct lnet_peer_ni  *msg_txpeer;         /* peer I'm sending to */
178         struct lnet_peer_ni  *msg_rxpeer;         /* peer I received from */
179
180         void                 *msg_private;
181         struct lnet_libmd    *msg_md;
182         /* the NI the message was sent or received over */
183         struct lnet_ni       *msg_txni;
184         struct lnet_ni       *msg_rxni;
185
186         unsigned int          msg_len;
187         unsigned int          msg_wanted;
188         unsigned int          msg_offset;
189         unsigned int          msg_niov;
190         struct bio_vec       *msg_kiov;
191
192         struct lnet_event       msg_ev;
193         struct lnet_hdr         msg_hdr;
194 };
195
196 struct lnet_libhandle {
197         struct list_head        lh_hash_chain;
198         __u64                   lh_cookie;
199 };
200
201 #define lh_entry(ptr, type, member) \
202         ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
203
204 struct lnet_me {
205         struct list_head        me_list;
206         int                     me_cpt;
207         struct lnet_processid   me_match_id;
208         unsigned int            me_portal;
209         unsigned int            me_pos;         /* hash offset in mt_hash */
210         __u64                   me_match_bits;
211         __u64                   me_ignore_bits;
212         enum lnet_unlink        me_unlink;
213         struct lnet_libmd      *me_md;
214 };
215
216 struct lnet_libmd {
217         struct list_head         md_list;
218         struct lnet_libhandle    md_lh;
219         struct lnet_me          *md_me;
220         char                    *md_start;
221         unsigned int             md_offset;
222         unsigned int             md_length;
223         unsigned int             md_max_size;
224         int                      md_threshold;
225         int                      md_refcount;
226         unsigned int             md_options;
227         unsigned int             md_flags;
228         unsigned int             md_niov;       /* # frags at end of struct */
229         void                    *md_user_ptr;
230         struct lnet_rsp_tracker *md_rspt_ptr;
231         lnet_handler_t           md_handler;
232         struct lnet_handle_md    md_bulk_handle;
233         struct bio_vec           md_kiov[LNET_MAX_IOV];
234 };
235
236 #define LNET_MD_FLAG_ZOMBIE      BIT(0)
237 #define LNET_MD_FLAG_AUTO_UNLINK BIT(1)
238 #define LNET_MD_FLAG_ABORTED     BIT(2)
239 /* LNET_MD_FLAG_HANDLING is set when a non-unlink event handler
240  * is being called for an event relating to the md.
241  * It ensures only one such handler runs at a time.
242  * The final "unlink" event is only called once the
243  * md_refcount has reached zero, and this flag has been cleared,
244  * ensuring that it doesn't race with any other event handler
245  * call.
246  */
247 #define LNET_MD_FLAG_HANDLING    BIT(3)
248 #define LNET_MD_FLAG_DISCARD     BIT(4)
249 #define LNET_MD_FLAG_GPU         BIT(5) /**< Special mapping needs */
250
251 struct lnet_test_peer {
252         /* info about peers we are trying to fail */
253         struct list_head        tp_list;        /* ln_test_peers */
254         struct lnet_nid         tp_nid;         /* matching nid */
255         unsigned int            tp_threshold;   /* # failures to simulate */
256 };
257
258 #define LNET_COOKIE_TYPE_MD    1
259 #define LNET_COOKIE_TYPE_ME    2
260 #define LNET_COOKIE_TYPE_EQ    3
261 #define LNET_COOKIE_TYPE_BITS  2
262 #define LNET_COOKIE_MASK        ((1ULL << LNET_COOKIE_TYPE_BITS) - 1ULL)
263
264 struct netstrfns {
265         u32     nf_type;
266         char    *nf_name;
267         char    *nf_modname;
268         void    (*nf_addr2str)(u32 addr, char *str, size_t size);
269         void    (*nf_addr2str_size)(const __be32 *addr, size_t asize,
270                                     char *str, size_t size);
271         int     (*nf_str2addr)(const char *str, int nob, u32 *addr);
272         int     (*nf_str2addr_size)(const char *str, int nob,
273                                     __be32 *addr, size_t *asize);
274         int     (*nf_parse_addrlist)(char *str, int len,
275                                      struct list_head *list);
276         int     (*nf_print_addrlist)(char *buffer, int count,
277                                      struct list_head *list);
278         int     (*nf_match_addr)(u32 addr, struct list_head *list);
279         int     (*nf_min_max)(struct list_head *nidlist, u32 *min_nid,
280                               u32 *max_nid);
281 };
282
283 struct lnet_ni;                                  /* forward ref */
284 struct socket;
285
286 struct lnet_lnd {
287         /* fields initialized by the LND */
288         __u32                   lnd_type;
289
290         int  (*lnd_startup)(struct lnet_ni *ni);
291         void (*lnd_shutdown)(struct lnet_ni *ni);
292         int  (*lnd_ctl)(struct lnet_ni *ni, unsigned int cmd, void *arg);
293
294         /* In data movement APIs below, payload buffers are described as a set
295          * of 'niov' fragments which are in pages.
296          * The LND may NOT overwrite these fragment descriptors.
297          * An 'offset' and may specify a byte offset within the set of
298          * fragments to start from
299          */
300
301         /* Start sending a preformatted message.  'private' is NULL for PUT and
302          * GET messages; otherwise this is a response to an incoming message
303          * and 'private' is the 'private' passed to lnet_parse().  Return
304          * non-zero for immediate failure, otherwise complete later with
305          * lnet_finalize() */
306         int (*lnd_send)(struct lnet_ni *ni, void *private,
307                         struct lnet_msg *msg);
308
309         /* Start receiving 'mlen' bytes of payload data, skipping the following
310          * 'rlen' - 'mlen' bytes. 'private' is the 'private' passed to
311          * lnet_parse().  Return non-zero for immedaite failure, otherwise
312          * complete later with lnet_finalize().  This also gives back a receive
313          * credit if the LND does flow control. */
314         int (*lnd_recv)(struct lnet_ni *ni, void *private, struct lnet_msg *msg,
315                         int delayed, unsigned int niov,
316                         struct bio_vec *kiov,
317                         unsigned int offset, unsigned int mlen, unsigned int rlen);
318
319         /* lnet_parse() has had to delay processing of this message
320          * (e.g. waiting for a forwarding buffer or send credits).  Give the
321          * LND a chance to free urgently needed resources.  If called, return 0
322          * for success and do NOT give back a receive credit; that has to wait
323          * until lnd_recv() gets called.  On failure return < 0 and
324          * release resources; lnd_recv() will not be called. */
325         int (*lnd_eager_recv)(struct lnet_ni *ni, void *private,
326                               struct lnet_msg *msg, void **new_privatep);
327
328         /* notification of peer down */
329         void (*lnd_notify_peer_down)(struct lnet_nid *peer);
330
331         /* accept a new connection */
332         int (*lnd_accept)(struct lnet_ni *ni, struct socket *sock);
333
334         /* get dma_dev priority */
335         unsigned int (*lnd_get_dev_prio)(struct lnet_ni *ni,
336                                          unsigned int dev_idx);
337 };
338
339 struct lnet_tx_queue {
340         int                     tq_credits;     /* # tx credits free */
341         int                     tq_credits_min; /* lowest it's been */
342         int                     tq_credits_max; /* total # tx credits */
343         struct list_head        tq_delayed;     /* delayed TXs */
344 };
345
346 enum lnet_net_state {
347         /* set when net block is allocated */
348         LNET_NET_STATE_INIT = 0,
349         /* set when NIs in net are started successfully */
350         LNET_NET_STATE_ACTIVE,
351         /* set if all NIs in net are in FAILED state */
352         LNET_NET_STATE_INACTIVE,
353         /* set when shutting down a NET */
354         LNET_NET_STATE_DELETING
355 };
356
357 enum lnet_ni_state {
358         /* initial state when NI is created */
359         LNET_NI_STATE_INIT = 0,
360         /* set when NI is brought up */
361         LNET_NI_STATE_ACTIVE,
362         /* set when NI is being shutdown */
363         LNET_NI_STATE_DELETING,
364 };
365
366 #define LNET_NI_RECOVERY_PENDING        BIT(0)
367 #define LNET_NI_RECOVERY_FAILED         BIT(1)
368
369 enum lnet_stats_type {
370         LNET_STATS_TYPE_SEND = 0,
371         LNET_STATS_TYPE_RECV,
372         LNET_STATS_TYPE_DROP
373 };
374
375 struct lnet_comm_count {
376         atomic_t co_get_count;
377         atomic_t co_put_count;
378         atomic_t co_reply_count;
379         atomic_t co_ack_count;
380         atomic_t co_hello_count;
381 };
382
383 struct lnet_element_stats {
384         struct lnet_comm_count el_send_stats;
385         struct lnet_comm_count el_recv_stats;
386         struct lnet_comm_count el_drop_stats;
387 };
388
389 struct lnet_health_local_stats {
390         atomic_t hlt_local_interrupt;
391         atomic_t hlt_local_dropped;
392         atomic_t hlt_local_aborted;
393         atomic_t hlt_local_no_route;
394         atomic_t hlt_local_timeout;
395         atomic_t hlt_local_error;
396 };
397
398 struct lnet_health_remote_stats {
399         atomic_t hlt_remote_dropped;
400         atomic_t hlt_remote_timeout;
401         atomic_t hlt_remote_error;
402         atomic_t hlt_network_timeout;
403 };
404
405 struct lnet_net {
406         /* chain on the ln_nets */
407         struct list_head        net_list;
408
409         /* net ID, which is composed of
410          * (net_type << 16) | net_num.
411          * net_type can be one of the enumerated types defined in
412          * lnet/include/lnet/nidstr.h */
413         __u32                   net_id;
414
415         /* round robin selection */
416         __u32                   net_seq;
417
418         /* total number of CPTs in the array */
419         __u32                   net_ncpts;
420
421         /* cumulative CPTs of all NIs in this net */
422         __u32                   *net_cpts;
423
424         /* relative net selection priority */
425         __u32                   net_sel_priority;
426
427         /* network tunables */
428         struct lnet_ioctl_config_lnd_cmn_tunables net_tunables;
429
430         /*
431          * boolean to indicate that the tunables have been set and
432          * shouldn't be reset
433          */
434         bool                    net_tunables_set;
435
436         /* procedural interface */
437         const struct lnet_lnd   *net_lnd;
438
439         /* list of NIs on this net */
440         struct list_head        net_ni_list;
441
442         /* list of NIs being added, but not started yet */
443         struct list_head        net_ni_added;
444
445         /* dying LND instances */
446         struct list_head        net_ni_zombie;
447
448         /* when I was last alive */
449         time64_t                net_last_alive;
450
451         /* protects access to net_last_alive */
452         spinlock_t              net_lock;
453
454         /* list of router nids preferred for this network */
455         struct list_head        net_rtr_pref_nids;
456 };
457
458 struct lnet_ni {
459         /* chain on the lnet_net structure */
460         struct list_head        ni_netlist;
461
462         /* chain on the recovery queue */
463         struct list_head        ni_recovery;
464
465         /* MD handle for recovery ping */
466         struct lnet_handle_md   ni_ping_mdh;
467
468         spinlock_t              ni_lock;
469
470         /* number of CPTs */
471         int                     ni_ncpts;
472
473         /* bond NI on some CPTs */
474         __u32                   *ni_cpts;
475
476         /* interface's NID */
477         struct lnet_nid         ni_nid;
478
479         /* instance-specific data */
480         void                    *ni_data;
481
482         /* per ni credits */
483         atomic_t                ni_tx_credits;
484
485         /* percpt TX queues */
486         struct lnet_tx_queue    **ni_tx_queues;
487
488         /* percpt reference count */
489         int                     **ni_refs;
490
491         /* pointer to parent network */
492         struct lnet_net         *ni_net;
493
494         /* my health status */
495         u32                     *ni_status;
496
497         /* NI FSM. Protected by lnet_ni_lock() */
498         enum lnet_ni_state      ni_state;
499
500         /* Recovery state. Protected by lnet_ni_lock() */
501         __u32                   ni_recovery_state;
502
503         /* When to send the next recovery ping */
504         time64_t                ni_next_ping;
505         /* How many pings sent during current recovery period did not receive
506          * a reply. NB: reset whenever _any_ message arrives on this NI
507          */
508         unsigned int            ni_ping_count;
509
510         /* per NI LND tunables */
511         struct lnet_lnd_tunables ni_lnd_tunables;
512
513         /* lnd tunables set explicitly */
514         bool ni_lnd_tunables_set;
515
516         /* NI statistics */
517         struct lnet_element_stats ni_stats;
518         struct lnet_health_local_stats ni_hstats;
519
520         /* physical device CPT */
521         int                     ni_dev_cpt;
522
523         /* sequence number used to round robin over nis within a net */
524         __u32                   ni_seq;
525
526         /*
527          * health value
528          *      initialized to LNET_MAX_HEALTH_VALUE
529          * Value is decremented every time we fail to send a message over
530          * this NI because of a NI specific failure.
531          * Value is incremented if we successfully send a message.
532          */
533         atomic_t                ni_healthv;
534
535         /*
536          * Set to 1 by the LND when it receives an event telling it the device
537          * has gone into a fatal state. Set to 0 when the LND receives an
538          * even telling it the device is back online.
539          */
540         atomic_t                ni_fatal_error_on;
541
542         /* the relative selection priority of this NI */
543         __u32                   ni_sel_priority;
544
545         /*
546          * equivalent interface to use
547          */
548         char                    *ni_interface;
549         struct net              *ni_net_ns;     /* original net namespace */
550 };
551
552 #define LNET_PROTO_PING_MATCHBITS       0x8000000000000000LL
553
554 /*
555  * Descriptor of a ping info buffer: keep a separate indicator of the
556  * size and a reference count. The type is used both as a source and
557  * sink of data, so we need to keep some information outside of the
558  * area that may be overwritten by network data.
559  */
560 struct lnet_ping_buffer {
561         int                     pb_nnis;
562         atomic_t                pb_refcnt;
563         bool                    pb_needs_post;
564         struct lnet_ping_info   pb_info;
565 };
566
567 #define LNET_PING_BUFFER_SIZE(NNIDS) \
568         offsetof(struct lnet_ping_buffer, pb_info.pi_ni[NNIDS])
569 #define LNET_PING_BUFFER_LONI(PBUF)     ((PBUF)->pb_info.pi_ni[0].ns_nid)
570 #define LNET_PING_BUFFER_SEQNO(PBUF)    ((PBUF)->pb_info.pi_ni[0].ns_status)
571
572 #define LNET_PING_INFO_TO_BUFFER(PINFO) \
573         container_of((PINFO), struct lnet_ping_buffer, pb_info)
574
575 struct lnet_nid_list {
576         struct list_head nl_list;
577         struct lnet_nid nl_nid;
578 };
579
580 struct lnet_peer_ni {
581         /* chain on lpn_peer_nis */
582         struct list_head        lpni_peer_nis;
583         /* chain on remote peer list */
584         struct list_head        lpni_on_remote_peer_ni_list;
585         /* chain on recovery queue */
586         struct list_head        lpni_recovery;
587         /* chain on peer hash */
588         struct list_head        lpni_hashlist;
589         /* messages blocking for tx credits */
590         struct list_head        lpni_txq;
591         /* pointer to peer net I'm part of */
592         struct lnet_peer_net    *lpni_peer_net;
593         /* statistics kept on each peer NI */
594         struct lnet_element_stats lpni_stats;
595         struct lnet_health_remote_stats lpni_hstats;
596         /* spin lock protecting credits and lpni_txq */
597         spinlock_t              lpni_lock;
598         /* # tx credits available */
599         int                     lpni_txcredits;
600         /* low water mark */
601         int                     lpni_mintxcredits;
602         /*
603          * Each peer_ni in a gateway maintains its own credits. This
604          * allows more traffic to gateways that have multiple interfaces.
605          */
606         /* # router credits */
607         int                     lpni_rtrcredits;
608         /* low water mark */
609         int                     lpni_minrtrcredits;
610         /* bytes queued for sending */
611         long                    lpni_txqnob;
612         /* network peer is on */
613         struct lnet_net         *lpni_net;
614         /* peer's NID */
615         struct lnet_nid         lpni_nid;
616         /* # refs */
617         struct kref             lpni_kref;
618         /* health value for the peer */
619         atomic_t                lpni_healthv;
620         /* recovery ping mdh */
621         struct lnet_handle_md   lpni_recovery_ping_mdh;
622         /* When to send the next recovery ping */
623         time64_t                lpni_next_ping;
624         /* How many pings sent during current recovery period did not receive
625          * a reply. NB: reset whenever _any_ message arrives from this peer NI
626          */
627         unsigned int            lpni_ping_count;
628         /* CPT this peer attached on */
629         int                     lpni_cpt;
630         /* state flags -- protected by lpni_lock */
631         unsigned                lpni_state;
632         /* status of the peer NI as reported by the peer */
633         __u32                   lpni_ns_status;
634         /* sequence number used to round robin over peer nis within a net */
635         __u32                   lpni_seq;
636         /* sequence number used to round robin over gateways */
637         __u32                   lpni_gw_seq;
638         /* returned RC ping features. Protected with lpni_lock */
639         unsigned int            lpni_ping_feats;
640         /* time last message was received from the peer */
641         time64_t                lpni_last_alive;
642         /* preferred local nids: if only one, use lpni_pref.nid */
643         union lpni_pref {
644                 struct lnet_nid nid;
645                 struct list_head nids;
646         } lpni_pref;
647         /* list of router nids preferred for this peer NI */
648         struct list_head        lpni_rtr_pref_nids;
649         /* The relative selection priority of this peer NI */
650         __u32                   lpni_sel_priority;
651         /* number of preferred NIDs in lnpi_pref_nids */
652         __u32                   lpni_pref_nnids;
653 };
654
655 /* Preferred path added due to traffic on non-MR peer_ni */
656 #define LNET_PEER_NI_NON_MR_PREF        BIT(0)
657 /* peer is being recovered. */
658 #define LNET_PEER_NI_RECOVERY_PENDING   BIT(1)
659 /* recovery ping failed */
660 #define LNET_PEER_NI_RECOVERY_FAILED    BIT(2)
661 /* peer is being deleted */
662 #define LNET_PEER_NI_DELETING           BIT(3)
663
664 struct lnet_peer {
665         /* chain on pt_peer_list */
666         struct list_head        lp_peer_list;
667
668         /* list of peer nets */
669         struct list_head        lp_peer_nets;
670
671         /* list of messages pending discovery*/
672         struct list_head        lp_dc_pendq;
673
674         /* chain on router list */
675         struct list_head        lp_rtr_list;
676
677         /* primary NID of the peer */
678         struct lnet_nid         lp_primary_nid;
679
680         /* source NID to use during discovery */
681         struct lnet_nid         lp_disc_src_nid;
682         /* destination NID to use during discovery */
683         struct lnet_nid         lp_disc_dst_nid;
684
685         /* net to perform discovery on */
686         __u32                   lp_disc_net_id;
687
688         /* CPT of peer_table */
689         int                     lp_cpt;
690
691         /* number of NIDs on this peer */
692         int                     lp_nnis;
693
694         /* # refs from lnet_route::lr_gateway */
695         int                     lp_rtr_refcount;
696
697         /*
698          * peer specific health sensitivity value to decrement peer nis in
699          * this peer with if set to something other than 0
700          */
701         __u32                   lp_health_sensitivity;
702
703         /* messages blocking for router credits */
704         struct list_head        lp_rtrq;
705
706         /* routes on this peer */
707         struct list_head        lp_routes;
708
709         /* reference count */
710         atomic_t                lp_refcount;
711
712         /* lock protecting peer state flags and lpni_rtrq */
713         spinlock_t              lp_lock;
714
715         /* peer state flags */
716         unsigned                lp_state;
717
718         /* buffer for data pushed by peer */
719         struct lnet_ping_buffer *lp_data;
720
721         /* MD handle for ping in progress */
722         struct lnet_handle_md   lp_ping_mdh;
723
724         /* MD handle for push in progress */
725         struct lnet_handle_md   lp_push_mdh;
726
727         /* number of NIDs for sizing push data */
728         int                     lp_data_nnis;
729
730         /* NI config sequence number of peer */
731         __u32                   lp_peer_seqno;
732
733         /* Local NI config sequence number acked by peer */
734         __u32                   lp_node_seqno;
735
736         /* Local NI config sequence number sent to peer */
737         __u32                   lp_node_seqno_sent;
738
739         /* Ping error encountered during discovery. */
740         int                     lp_ping_error;
741
742         /* Push error encountered during discovery. */
743         int                     lp_push_error;
744
745         /* Error encountered during discovery. */
746         int                     lp_dc_error;
747
748         /* time it was put on the ln_dc_working queue */
749         time64_t                lp_last_queued;
750
751         /* link on discovery-related lists */
752         struct list_head        lp_dc_list;
753
754         /* tasks waiting on discovery of this peer */
755         wait_queue_head_t       lp_dc_waitq;
756
757         /* cached peer aliveness */
758         bool                    lp_alive;
759
760         /* sequence number used to round robin traffic to this peer's
761          * nets/NIs
762          */
763         __u32                   lp_send_seq;
764 };
765
766 /*
767  * The status flags in lp_state. Their semantics have chosen so that
768  * lp_state can be zero-initialized.
769  *
770  * A peer is marked MULTI_RAIL in two cases: it was configured using DLC
771  * as multi-rail aware, or the LNET_PING_FEAT_MULTI_RAIL bit was set.
772  *
773  * A peer is marked NO_DISCOVERY if the LNET_PING_FEAT_DISCOVERY bit was
774  * NOT set when the peer was pinged by discovery.
775  *
776  * A peer is marked ROUTER if it indicates so in the feature bit.
777  */
778 #define LNET_PEER_MULTI_RAIL            BIT(0)  /* Multi-rail aware */
779 #define LNET_PEER_NO_DISCOVERY          BIT(1)  /* Peer disabled discovery */
780 #define LNET_PEER_ROUTER_ENABLED        BIT(2)  /* router feature enabled */
781
782 /*
783  * A peer is marked CONFIGURED if it was configured by DLC.
784  *
785  * In addition, a peer is marked DISCOVERED if it has fully passed
786  * through Peer Discovery.
787  *
788  * When Peer Discovery is disabled, the discovery thread will mark
789  * peers REDISCOVER to indicate that they should be re-examined if
790  * discovery is (re)enabled on the node.
791  *
792  * A peer that was created as the result of inbound traffic will not
793  * be marked at all.
794  */
795 #define LNET_PEER_CONFIGURED            BIT(3)  /* Configured via DLC */
796 #define LNET_PEER_DISCOVERED            BIT(4)  /* Peer was discovered */
797 #define LNET_PEER_REDISCOVER            BIT(5)  /* Discovery was disabled */
798 /*
799  * A peer is marked DISCOVERING when discovery is in progress.
800  * The other flags below correspond to stages of discovery.
801  */
802 #define LNET_PEER_DISCOVERING           BIT(6)  /* Discovering */
803 #define LNET_PEER_DATA_PRESENT          BIT(7)  /* Remote peer data present */
804 #define LNET_PEER_NIDS_UPTODATE         BIT(8)  /* Remote peer info uptodate */
805 #define LNET_PEER_PING_SENT             BIT(9)  /* Waiting for REPLY to Ping */
806 #define LNET_PEER_PUSH_SENT             BIT(10) /* Waiting for ACK of Push */
807 #define LNET_PEER_PING_FAILED           BIT(11) /* Ping send failure */
808 #define LNET_PEER_PUSH_FAILED           BIT(12) /* Push send failure */
809 /*
810  * A ping can be forced as a way to fix up state, or as a manual
811  * intervention by an admin.
812  * A push can be forced in circumstances that would normally not
813  * allow for one to happen.
814  */
815 #define LNET_PEER_FORCE_PING            BIT(13) /* Forced Ping */
816 #define LNET_PEER_FORCE_PUSH            BIT(14) /* Forced Push */
817
818 /* force delete even if router */
819 #define LNET_PEER_RTR_NI_FORCE_DEL      BIT(15)
820
821 /* gw undergoing alive discovery */
822 #define LNET_PEER_RTR_DISCOVERY         BIT(16)
823 /* gw has undergone discovery (does not indicate success or failure) */
824 #define LNET_PEER_RTR_DISCOVERED        BIT(17)
825
826 /* peer is marked for deletion */
827 #define LNET_PEER_MARK_DELETION         BIT(18)
828 /* lnet_peer_del()/lnet_peer_del_locked() has been called on the peer */
829 #define LNET_PEER_MARK_DELETED          BIT(19)
830 /* lock primary NID to what's requested by ULP */
831 #define LNET_PEER_LOCK_PRIMARY          BIT(20)
832 /* this is for informational purposes only. It is set if a peer gets
833  * configured from Lustre with a primary NID which belongs to another peer
834  * which is also configured by Lustre as the primary NID.
835  */
836 #define LNET_PEER_BAD_CONFIG            BIT(21)
837
838 struct lnet_peer_net {
839         /* chain on lp_peer_nets */
840         struct list_head        lpn_peer_nets;
841
842         /* list of peer_nis on this network */
843         struct list_head        lpn_peer_nis;
844
845         /* pointer to the peer I'm part of */
846         struct lnet_peer        *lpn_peer;
847
848         /* Net ID */
849         __u32                   lpn_net_id;
850
851         /* peer net health */
852         int                     lpn_healthv;
853
854         /* time of next router ping on this net */
855         time64_t                lpn_next_ping;
856
857         /* selection sequence number */
858         __u32                   lpn_seq;
859
860         /* relative peer net selection priority */
861         __u32                   lpn_sel_priority;
862
863         /* reference count */
864         atomic_t                lpn_refcount;
865 };
866
867 /* peer hash size */
868 #define LNET_PEER_HASH_BITS     9
869 #define LNET_PEER_HASH_SIZE     (1 << LNET_PEER_HASH_BITS)
870
871 /*
872  * peer hash table - one per CPT
873  *
874  * protected by lnet_net_lock/EX for update
875  *    pt_version
876  *    pt_hash[...]
877  *    pt_peer_list
878  *    pt_peers
879  * protected by pt_zombie_lock:
880  *    pt_zombie_list
881  *    pt_zombies
882  *
883  * pt_zombie lock nests inside lnet_net_lock
884  */
885 struct lnet_peer_table {
886         int                     pt_version;     /* /proc validity stamp */
887         struct list_head        *pt_hash;       /* NID->peer hash */
888         struct list_head        pt_peer_list;   /* peers */
889         int                     pt_peers;       /* # peers */
890         struct list_head        pt_zombie_list; /* zombie peer_ni */
891         int                     pt_zombies;     /* # zombie peers_ni */
892         spinlock_t              pt_zombie_lock; /* protect list and count */
893 };
894
895 /* peer aliveness is enabled only on routers for peers in a network where the
896  * struct lnet_ni::ni_peertimeout has been set to a positive value
897  */
898 #define lnet_peer_aliveness_enabled(lp) (the_lnet.ln_routing != 0 && \
899                                         ((lp)->lpni_net) && \
900                                         (lp)->lpni_net->net_tunables.lct_peer_timeout > 0)
901
902 struct lnet_route {
903         struct list_head        lr_list;        /* chain on net */
904         struct list_head        lr_gwlist;      /* chain on gateway */
905         struct lnet_peer        *lr_gateway;    /* router node */
906         struct lnet_nid         lr_nid;         /* NID used to add route */
907         __u32                   lr_net;         /* remote network number */
908         __u32                   lr_lnet;        /* local network number */
909         int                     lr_seq;         /* sequence for round-robin */
910         __u32                   lr_hops;        /* how far I am */
911         unsigned int            lr_priority;    /* route priority */
912         atomic_t                lr_alive;       /* cached route aliveness */
913         bool                    lr_single_hop;  /* this route is single-hop */
914 };
915
916 #define LNET_REMOTE_NETS_HASH_DEFAULT   (1U << 7)
917 #define LNET_REMOTE_NETS_HASH_MAX       (1U << 16)
918 #define LNET_REMOTE_NETS_HASH_SIZE      (1 << the_lnet.ln_remote_nets_hbits)
919
920 struct lnet_remotenet {
921         /* chain on ln_remote_nets_hash */
922         struct list_head        lrn_list;
923         /* routes to me */
924         struct list_head        lrn_routes;
925         /* my net number */
926         __u32                   lrn_net;
927 };
928
929 /** lnet message has credit and can be submitted to lnd for send/receive */
930 #define LNET_CREDIT_OK          0
931 /** lnet message is waiting for credit */
932 #define LNET_CREDIT_WAIT        1
933 /** lnet message is waiting for discovery */
934 #define LNET_DC_WAIT            2
935
936 struct lnet_rtrbufpool {
937         /* my free buffer pool */
938         struct list_head        rbp_bufs;
939         /* messages blocking for a buffer */
940         struct list_head        rbp_msgs;
941         /* # pages in each buffer */
942         int                     rbp_npages;
943         /* requested number of buffers */
944         int                     rbp_req_nbuffers;
945         /* # buffers actually allocated */
946         int                     rbp_nbuffers;
947         /* # free buffers / blocked messages */
948         int                     rbp_credits;
949         /* low water mark */
950         int                     rbp_mincredits;
951 };
952
953 struct lnet_rtrbuf {
954         struct list_head         rb_list;       /* chain on rbp_bufs */
955         struct lnet_rtrbufpool  *rb_pool;       /* owning pool */
956         struct bio_vec           rb_kiov[0];    /* the buffer space */
957 };
958
959 #define LNET_PEER_HASHSIZE   503                /* prime! */
960
961 enum lnet_match_flags {
962         /* Didn't match anything */
963         LNET_MATCHMD_NONE       = BIT(0),
964         /* Matched OK */
965         LNET_MATCHMD_OK         = BIT(1),
966         /* Must be discarded */
967         LNET_MATCHMD_DROP       = BIT(2),
968         /* match and buffer is exhausted */
969         LNET_MATCHMD_EXHAUSTED  = BIT(3),
970         /* match or drop */
971         LNET_MATCHMD_FINISH     = (LNET_MATCHMD_OK | LNET_MATCHMD_DROP),
972 };
973
974 /* Options for struct lnet_portal::ptl_options */
975 #define LNET_PTL_LAZY           BIT(0)
976 #define LNET_PTL_MATCH_UNIQUE   BIT(1)  /* unique match, for RDMA */
977 #define LNET_PTL_MATCH_WILDCARD BIT(2)  /* wildcard match, request portal */
978
979 /* parameter for matching operations (GET, PUT) */
980 struct lnet_match_info {
981         __u64                   mi_mbits;
982         struct lnet_processid   mi_id;
983         unsigned int            mi_cpt;
984         unsigned int            mi_opc;
985         unsigned int            mi_portal;
986         unsigned int            mi_rlength;
987         unsigned int            mi_roffset;
988 };
989
990 /* ME hash of RDMA portal */
991 #define LNET_MT_HASH_BITS               8
992 #define LNET_MT_HASH_SIZE               (1 << LNET_MT_HASH_BITS)
993 #define LNET_MT_HASH_MASK               (LNET_MT_HASH_SIZE - 1)
994 /* we allocate (LNET_MT_HASH_SIZE + 1) entries for lnet_match_table::mt_hash,
995  * the last entry is reserved for MEs with ignore-bits */
996 #define LNET_MT_HASH_IGNORE             LNET_MT_HASH_SIZE
997 /* __u64 has 2^6 bits, so need 2^(LNET_MT_HASH_BITS - LNET_MT_BITS_U64) which
998  * is 4 __u64s as bit-map, and add an extra __u64 (only use one bit) for the
999  * ME-list with ignore-bits, which is mtable::mt_hash[LNET_MT_HASH_IGNORE] */
1000 #define LNET_MT_BITS_U64                6       /* 2^6 bits */
1001 #define LNET_MT_EXHAUSTED_BITS          (LNET_MT_HASH_BITS - LNET_MT_BITS_U64)
1002 #define LNET_MT_EXHAUSTED_BMAP          ((1 << LNET_MT_EXHAUSTED_BITS) + 1)
1003
1004 /* portal match table */
1005 struct lnet_match_table {
1006         /* reserved for upcoming patches, CPU partition ID */
1007         unsigned int            mt_cpt;
1008         unsigned int            mt_portal;      /* portal index */
1009         /* match table is set as "enabled" if there's non-exhausted MD
1010          * attached on mt_mhash, it's only valid for wildcard portal */
1011         unsigned int            mt_enabled;
1012         /* bitmap to flag whether MEs on mt_hash are exhausted or not */
1013         __u64                   mt_exhausted[LNET_MT_EXHAUSTED_BMAP];
1014         struct list_head        *mt_mhash;      /* matching hash */
1015 };
1016
1017 /* these are only useful for wildcard portal */
1018 /* Turn off message rotor for wildcard portals */
1019 #define LNET_PTL_ROTOR_OFF      0
1020 /* round-robin dispatch all PUT messages for wildcard portals */
1021 #define LNET_PTL_ROTOR_ON       1
1022 /* round-robin dispatch routed PUT message for wildcard portals */
1023 #define LNET_PTL_ROTOR_RR_RT    2
1024 /* dispatch routed PUT message by hashing source NID for wildcard portals */
1025 #define LNET_PTL_ROTOR_HASH_RT  3
1026
1027 struct lnet_portal {
1028         spinlock_t              ptl_lock;
1029         unsigned int            ptl_index;      /* portal ID, reserved */
1030         /* flags on this portal: lazy, unique... */
1031         unsigned int            ptl_options;
1032         /* list of messages which are stealing buffer */
1033         struct list_head        ptl_msg_stealing;
1034         /* messages blocking for MD */
1035         struct list_head        ptl_msg_delayed;
1036         /* Match table for each CPT */
1037         struct lnet_match_table **ptl_mtables;
1038         /* spread rotor of incoming "PUT" */
1039         unsigned int            ptl_rotor;
1040         /* # active entries for this portal */
1041         int                     ptl_mt_nmaps;
1042         /* array of active entries' cpu-partition-id */
1043         int                     ptl_mt_maps[0];
1044 };
1045
1046 #define LNET_LH_HASH_BITS       12
1047 #define LNET_LH_HASH_SIZE       (1ULL << LNET_LH_HASH_BITS)
1048 #define LNET_LH_HASH_MASK       (LNET_LH_HASH_SIZE - 1)
1049
1050 /* resource container (ME, MD, EQ) */
1051 struct lnet_res_container {
1052         unsigned int            rec_type;       /* container type */
1053         __u64                   rec_lh_cookie;  /* cookie generator */
1054         struct list_head        rec_active;     /* active resource list */
1055         struct list_head        *rec_lh_hash;   /* handle hash */
1056 };
1057
1058 /* message container */
1059 struct lnet_msg_container {
1060         int                     msc_init;       /* initialized or not */
1061         /* max # threads finalizing */
1062         int                     msc_nfinalizers;
1063         /* msgs waiting to complete finalizing */
1064         struct list_head        msc_finalizing;
1065         /* msgs waiting to be resent */
1066         struct list_head        msc_resending;
1067         struct list_head        msc_active;     /* active message list */
1068         /* threads doing finalization */
1069         void                    **msc_finalizers;
1070         /* threads doing resends */
1071         void                    **msc_resenders;
1072 };
1073
1074 /* This UDSP structures need to match the user space liblnetconfig structures
1075  * in order for the marshall and unmarshall functions to be common.
1076  */
1077
1078 /* Net is described as a
1079  *  1. net type
1080  *  2. num range
1081  */
1082 struct lnet_ud_net_descr {
1083         __u32 udn_net_type;
1084         struct list_head udn_net_num_range;
1085 };
1086
1087 /* each NID range is defined as
1088  *  1. net descriptor
1089  *  2. address range descriptor
1090  */
1091 struct lnet_ud_nid_descr {
1092         struct lnet_ud_net_descr ud_net_id;
1093         struct list_head ud_addr_range;
1094         __u32 ud_mem_size;
1095 };
1096
1097 /* a UDSP rule can have up to three user defined NID descriptors
1098  *      - src: defines the local NID range for the rule
1099  *      - dst: defines the peer NID range for the rule
1100  *      - rte: defines the router NID range for the rule
1101  *
1102  * An action union defines the action to take when the rule
1103  * is matched
1104  */
1105 struct lnet_udsp {
1106         struct list_head udsp_on_list;
1107         __u32 udsp_idx;
1108         struct lnet_ud_nid_descr udsp_src;
1109         struct lnet_ud_nid_descr udsp_dst;
1110         struct lnet_ud_nid_descr udsp_rte;
1111         enum lnet_udsp_action_type udsp_action_type;
1112         union {
1113                 __u32 udsp_priority;
1114         } udsp_action;
1115 };
1116
1117 /* Peer Discovery states */
1118 #define LNET_DC_STATE_SHUTDOWN          0       /* not started */
1119 #define LNET_DC_STATE_RUNNING           1       /* started up OK */
1120 #define LNET_DC_STATE_STOPPING          2       /* telling thread to stop */
1121
1122 /* Router Checker states */
1123 #define LNET_MT_STATE_SHUTDOWN          0       /* not started */
1124 #define LNET_MT_STATE_RUNNING           1       /* started up OK */
1125 #define LNET_MT_STATE_STOPPING          2       /* telling thread to stop */
1126
1127 /* LNet states */
1128 #define LNET_STATE_SHUTDOWN             0       /* not started */
1129 #define LNET_STATE_RUNNING              1       /* started up OK */
1130 #define LNET_STATE_STOPPING             2       /* telling thread to stop */
1131
1132 struct lnet {
1133         /* CPU partition table of LNet */
1134         struct cfs_cpt_table            *ln_cpt_table;
1135         /* number of CPTs in ln_cpt_table */
1136         unsigned int                    ln_cpt_number;
1137         unsigned int                    ln_cpt_bits;
1138
1139         /* protect LNet resources (ME/MD/EQ) */
1140         struct cfs_percpt_lock          *ln_res_lock;
1141         /* # portals */
1142         int                             ln_nportals;
1143         /* the vector of portals */
1144         struct lnet_portal              **ln_portals;
1145         /* percpt MD container */
1146         struct lnet_res_container       **ln_md_containers;
1147
1148         /* Event Queue container */
1149         struct lnet_res_container       ln_eq_container;
1150         spinlock_t                      ln_eq_wait_lock;
1151
1152         unsigned int                    ln_remote_nets_hbits;
1153
1154         /* protect NI, peer table, credits, routers, rtrbuf... */
1155         struct cfs_percpt_lock          *ln_net_lock;
1156         /* percpt message containers for active/finalizing/freed message */
1157         struct lnet_msg_container       **ln_msg_containers;
1158         struct lnet_counters            **ln_counters;
1159         struct lnet_peer_table          **ln_peer_tables;
1160         /* list of peer nis not on a local network */
1161         struct list_head                ln_remote_peer_ni_list;
1162         /* failure simulation */
1163         struct list_head                ln_test_peers;
1164         struct list_head                ln_drop_rules;
1165         struct list_head                ln_delay_rules;
1166         /* LND instances */
1167         struct list_head                ln_nets;
1168         /* Sequence number used to round robin sends across all nets */
1169         __u32                           ln_net_seq;
1170         /* the loopback NI */
1171         struct lnet_ni                  *ln_loni;
1172         /* network zombie list */
1173         struct list_head                ln_net_zombie;
1174         /* resend messages list */
1175         struct list_head                ln_msg_resend;
1176         /* spin lock to protect the msg resend list */
1177         spinlock_t                      ln_msg_resend_lock;
1178
1179         /* remote networks with routes to them */
1180         struct list_head                *ln_remote_nets_hash;
1181         /* validity stamp */
1182         __u64                           ln_remote_nets_version;
1183         /* list of all known routers */
1184         struct list_head                ln_routers;
1185         /* validity stamp */
1186         __u64                           ln_routers_version;
1187         /* percpt router buffer pools */
1188         struct lnet_rtrbufpool          **ln_rtrpools;
1189
1190         /*
1191          * Ping target / Push source
1192          *
1193          * The ping target and push source share a single buffer. The
1194          * ln_ping_target is protected against concurrent updates by
1195          * ln_api_mutex.
1196          */
1197         struct lnet_handle_md           ln_ping_target_md;
1198         lnet_handler_t                  ln_ping_target_handler;
1199         struct lnet_ping_buffer         *ln_ping_target;
1200         atomic_t                        ln_ping_target_seqno;
1201
1202         /*
1203          * Push Target
1204          *
1205          * ln_push_nnis contains the desired size of the push target.
1206          * The lnet_net_lock is used to handle update races. The old
1207          * buffer may linger a while after it has been unlinked, in
1208          * which case the event handler cleans up.
1209          */
1210         lnet_handler_t                  ln_push_target_handler;
1211         struct lnet_handle_md           ln_push_target_md;
1212         struct lnet_ping_buffer         *ln_push_target;
1213         int                             ln_push_target_nnis;
1214
1215         /* discovery event queue handle */
1216         lnet_handler_t                  ln_dc_handler;
1217         /* discovery requests */
1218         struct list_head                ln_dc_request;
1219         /* discovery working list */
1220         struct list_head                ln_dc_working;
1221         /* discovery expired list */
1222         struct list_head                ln_dc_expired;
1223         /* discovery thread wait queue */
1224         wait_queue_head_t               ln_dc_waitq;
1225         /* discovery startup/shutdown state */
1226         int                             ln_dc_state;
1227
1228         /* monitor thread startup/shutdown state */
1229         int                             ln_mt_state;
1230         /* serialise startup/shutdown */
1231         struct semaphore                ln_mt_signal;
1232
1233         struct mutex                    ln_api_mutex;
1234         struct mutex                    ln_lnd_mutex;
1235         /* Have I called LNetNIInit myself? */
1236         int                             ln_niinit_self;
1237         /* LNetNIInit/LNetNIFini counter */
1238         int                             ln_refcount;
1239         /* SHUTDOWN/RUNNING/STOPPING */
1240         int                             ln_state;
1241
1242         int                             ln_routing;     /* am I a router? */
1243         lnet_pid_t                      ln_pid;         /* requested pid */
1244         /* uniquely identifies this ni in this epoch */
1245         __u64                           ln_interface_cookie;
1246         /* registered LNDs */
1247         const struct lnet_lnd           *ln_lnds[NUM_LNDS];
1248
1249         /* test protocol compatibility flags */
1250         unsigned long                   ln_testprotocompat;
1251
1252         /* 0 - load the NIs from the mod params
1253          * 1 - do not load the NIs from the mod params
1254          * Reverse logic to ensure that other calls to LNetNIInit
1255          * need no change
1256          */
1257         bool                            ln_nis_from_mod_params;
1258
1259         /*
1260          * completion for the monitor thread. The monitor thread takes care of
1261          * checking routes, timedout messages and resending messages.
1262          */
1263         struct completion               ln_mt_wait_complete;
1264
1265         /* per-cpt resend queues */
1266         struct list_head                **ln_mt_resendqs;
1267         /* local NIs to recover */
1268         struct list_head                ln_mt_localNIRecovq;
1269         /* local NIs to recover */
1270         struct list_head                ln_mt_peerNIRecovq;
1271         /*
1272          * An array of queues for GET/PUT waiting for REPLY/ACK respectively.
1273          * There are CPT number of queues. Since response trackers will be
1274          * added on the fast path we can't afford to grab the exclusive
1275          * net lock to protect these queues. The CPT will be calculated
1276          * based on the mdh cookie.
1277          */
1278         struct list_head                **ln_mt_rstq;
1279         /*
1280          * A response tracker becomes a zombie when the associated MD is queued
1281          * for unlink before the response tracker is detached from the MD. An
1282          * entry on a zombie list can be freed when either the remaining
1283          * operations on the MD complete or when LNet has shut down.
1284          */
1285         struct list_head                **ln_mt_zombie_rstqs;
1286         /* recovery handler */
1287         lnet_handler_t                  ln_mt_handler;
1288
1289         /*
1290          * Completed when the discovery and monitor threads can enter their
1291          * work loops
1292          */
1293         struct completion               ln_started;
1294         /* UDSP list */
1295         struct list_head                ln_udsp_list;
1296 };
1297
1298 struct genl_filter_list {
1299         struct list_head         lp_list;
1300         void                    *lp_cursor;
1301         bool                     lp_first;
1302 };
1303
1304 static const struct nla_policy scalar_attr_policy[LN_SCALAR_MAX + 1] = {
1305         [LN_SCALAR_ATTR_LIST]           = { .type = NLA_NESTED },
1306         [LN_SCALAR_ATTR_LIST_SIZE]      = { .type = NLA_U16 },
1307         [LN_SCALAR_ATTR_INDEX]          = { .type = NLA_U16 },
1308         [LN_SCALAR_ATTR_NLA_TYPE]       = { .type = NLA_U16 },
1309         [LN_SCALAR_ATTR_VALUE]          = { .type = NLA_STRING },
1310         [LN_SCALAR_ATTR_KEY_FORMAT]     = { .type = NLA_U16 },
1311 };
1312
1313 int lnet_genl_send_scalar_list(struct sk_buff *msg, u32 portid, u32 seq,
1314                                const struct genl_family *family, int flags,
1315                                u8 cmd, const struct ln_key_list *data[]);
1316
1317 /* Special workaround for pre-4.19 kernels to send error messages
1318  * from dumpit routines. Newer kernels will send message with
1319  * NL_SET_ERR_MSG information by default if NETLINK_EXT_ACK is set.
1320  */
1321 static inline int lnet_nl_send_error(struct sk_buff *msg, int portid, int seq,
1322                                      int error)
1323 {
1324 #ifndef HAVE_NL_DUMP_WITH_EXT_ACK
1325         struct nlmsghdr *nlh;
1326
1327         if (!error)
1328                 return 0;
1329
1330         nlh = nlmsg_put(msg, portid, seq, NLMSG_ERROR, sizeof(error), 0);
1331         if (!nlh)
1332                 return -ENOMEM;
1333 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
1334         netlink_ack(msg, nlh, error, NULL);
1335 #else
1336         netlink_ack(msg, nlh, error);
1337 #endif
1338         return nlmsg_len(nlh);
1339 #else
1340         return error;
1341 #endif
1342 }
1343
1344 #endif