Whamcloud - gitweb
bc8a8d092c9d157c811fbfbf0d1e61375c3be1bc
[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 int libcfs_strid(struct lnet_processid *id, const char *str);
57
58 int cfs_match_nid_net(struct lnet_nid *nid, u32 net,
59                       struct list_head *net_num_list,
60                       struct list_head *addr);
61
62 /* Max payload size */
63 #define LNET_MAX_PAYLOAD        LNET_MTU
64
65 /** limit on the number of fragments in discontiguous MDs */
66 #define LNET_MAX_IOV    256
67
68 /*
69  * This is the maximum health value.
70  * All local and peer NIs created have their health default to this value.
71  */
72 #define LNET_MAX_HEALTH_VALUE 1000
73 #define LNET_MAX_SELECTION_PRIORITY UINT_MAX
74
75 /* forward refs */
76 struct lnet_libmd;
77
78 enum lnet_msg_hstatus {
79         LNET_MSG_STATUS_OK = 0,
80         LNET_MSG_STATUS_LOCAL_INTERRUPT,
81         LNET_MSG_STATUS_LOCAL_DROPPED,
82         LNET_MSG_STATUS_LOCAL_ABORTED,
83         LNET_MSG_STATUS_LOCAL_NO_ROUTE,
84         LNET_MSG_STATUS_LOCAL_ERROR,
85         LNET_MSG_STATUS_LOCAL_TIMEOUT,
86         LNET_MSG_STATUS_REMOTE_ERROR,
87         LNET_MSG_STATUS_REMOTE_DROPPED,
88         LNET_MSG_STATUS_REMOTE_TIMEOUT,
89         LNET_MSG_STATUS_NETWORK_TIMEOUT,
90         LNET_MSG_STATUS_END,
91 };
92
93 struct lnet_rsp_tracker {
94         /* chain on the waiting list */
95         struct list_head rspt_on_list;
96         /* cpt to lock */
97         int rspt_cpt;
98         /* nid of next hop */
99         struct lnet_nid rspt_next_hop_nid;
100         /* deadline of the REPLY/ACK */
101         ktime_t rspt_deadline;
102         /* parent MD */
103         struct lnet_handle_md rspt_mdh;
104 };
105
106 struct lnet_msg {
107         struct list_head        msg_activelist;
108         struct list_head        msg_list;       /* Q for credits/MD */
109
110         struct lnet_processid   msg_target;
111         /* Primary NID of the source. */
112         struct lnet_nid         msg_initiator;
113         /* where is it from, it's only for building event */
114         struct lnet_nid         msg_from;
115         __u32                   msg_type;
116
117         /*
118          * hold parameters in case message is with held due
119          * to discovery
120          */
121         struct lnet_nid         msg_src_nid_param;
122         struct lnet_nid         msg_rtr_nid_param;
123
124         /*
125          * Deadline for the message after which it will be finalized if it
126          * has not completed.
127          */
128         ktime_t                 msg_deadline;
129
130         /* The message health status. */
131         enum lnet_msg_hstatus   msg_health_status;
132         /* This is a recovery message */
133         bool                    msg_recovery;
134         /* the number of times a transmission has been retried */
135         int                     msg_retry_count;
136         /* flag to indicate that we do not want to resend this message */
137         bool                    msg_no_resend;
138
139         /* committed for sending */
140         unsigned int            msg_tx_committed:1;
141         /* CPT # this message committed for sending */
142         unsigned int            msg_tx_cpt:15;
143         /* committed for receiving */
144         unsigned int            msg_rx_committed:1;
145         /* CPT # this message committed for receiving */
146         unsigned int            msg_rx_cpt:15;
147         /* queued for tx credit */
148         unsigned int            msg_tx_delayed:1;
149         /* queued for RX buffer */
150         unsigned int            msg_rx_delayed:1;
151         /* ready for pending on RX delay list */
152         unsigned int            msg_rx_ready_delay:1;
153
154         unsigned int          msg_vmflush:1;      /* VM trying to free memory */
155         unsigned int          msg_target_is_router:1; /* sending to a router */
156         unsigned int          msg_routing:1;      /* being forwarded */
157         unsigned int          msg_ack:1;          /* ack on finalize (PUT) */
158         unsigned int          msg_sending:1;      /* outgoing message */
159         unsigned int          msg_receiving:1;    /* being received */
160         unsigned int          msg_txcredit:1;     /* taken an NI send credit */
161         unsigned int          msg_peertxcredit:1; /* taken a peer send credit */
162         unsigned int          msg_rtrcredit:1;    /* taken a globel router credit */
163         unsigned int          msg_peerrtrcredit:1; /* taken a peer router credit */
164         unsigned int          msg_onactivelist:1; /* on the activelist */
165         unsigned int          msg_rdma_get:1;
166
167         struct lnet_peer_ni  *msg_txpeer;         /* peer I'm sending to */
168         struct lnet_peer_ni  *msg_rxpeer;         /* peer I received from */
169
170         void                 *msg_private;
171         struct lnet_libmd    *msg_md;
172         /* the NI the message was sent or received over */
173         struct lnet_ni       *msg_txni;
174         struct lnet_ni       *msg_rxni;
175
176         unsigned int          msg_len;
177         unsigned int          msg_wanted;
178         unsigned int          msg_offset;
179         unsigned int          msg_niov;
180         struct bio_vec       *msg_kiov;
181
182         struct lnet_event       msg_ev;
183         struct lnet_hdr         msg_hdr;
184 };
185
186 struct lnet_libhandle {
187         struct list_head        lh_hash_chain;
188         __u64                   lh_cookie;
189 };
190
191 #define lh_entry(ptr, type, member) \
192         ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
193
194 struct lnet_me {
195         struct list_head        me_list;
196         int                     me_cpt;
197         struct lnet_processid   me_match_id;
198         unsigned int            me_portal;
199         unsigned int            me_pos;         /* hash offset in mt_hash */
200         __u64                   me_match_bits;
201         __u64                   me_ignore_bits;
202         enum lnet_unlink        me_unlink;
203         struct lnet_libmd      *me_md;
204 };
205
206 struct lnet_libmd {
207         struct list_head         md_list;
208         struct lnet_libhandle    md_lh;
209         struct lnet_me          *md_me;
210         char                    *md_start;
211         unsigned int             md_offset;
212         unsigned int             md_length;
213         unsigned int             md_max_size;
214         int                      md_threshold;
215         int                      md_refcount;
216         unsigned int             md_options;
217         unsigned int             md_flags;
218         unsigned int             md_niov;       /* # frags at end of struct */
219         void                    *md_user_ptr;
220         struct lnet_rsp_tracker *md_rspt_ptr;
221         lnet_handler_t           md_handler;
222         struct lnet_handle_md    md_bulk_handle;
223         struct bio_vec           md_kiov[LNET_MAX_IOV];
224 };
225
226 #define LNET_MD_FLAG_ZOMBIE      BIT(0)
227 #define LNET_MD_FLAG_AUTO_UNLINK BIT(1)
228 #define LNET_MD_FLAG_ABORTED     BIT(2)
229 /* LNET_MD_FLAG_HANDLING is set when a non-unlink event handler
230  * is being called for an event relating to the md.
231  * It ensures only one such handler runs at a time.
232  * The final "unlink" event is only called once the
233  * md_refcount has reached zero, and this flag has been cleared,
234  * ensuring that it doesn't race with any other event handler
235  * call.
236  */
237 #define LNET_MD_FLAG_HANDLING    BIT(3)
238 #define LNET_MD_FLAG_DISCARD     BIT(4)
239 #define LNET_MD_FLAG_GPU         BIT(5) /**< Special mapping needs */
240
241 struct lnet_test_peer {
242         /* info about peers we are trying to fail */
243         struct list_head        tp_list;        /* ln_test_peers */
244         struct lnet_nid         tp_nid;         /* matching nid */
245         unsigned int            tp_threshold;   /* # failures to simulate */
246 };
247
248 #define LNET_COOKIE_TYPE_MD    1
249 #define LNET_COOKIE_TYPE_ME    2
250 #define LNET_COOKIE_TYPE_EQ    3
251 #define LNET_COOKIE_TYPE_BITS  2
252 #define LNET_COOKIE_MASK        ((1ULL << LNET_COOKIE_TYPE_BITS) - 1ULL)
253
254 struct netstrfns {
255         u32     nf_type;
256         char    *nf_name;
257         char    *nf_modname;
258         void    (*nf_addr2str)(u32 addr, char *str, size_t size);
259         void    (*nf_addr2str_size)(const __be32 *addr, size_t asize,
260                                     char *str, size_t size);
261         int     (*nf_str2addr)(const char *str, int nob, u32 *addr);
262         int     (*nf_str2addr_size)(const char *str, int nob,
263                                     __be32 *addr, size_t *asize);
264         int     (*nf_parse_addrlist)(char *str, int len,
265                                      struct list_head *list);
266         int     (*nf_print_addrlist)(char *buffer, int count,
267                                      struct list_head *list);
268         int     (*nf_match_addr)(u32 addr, struct list_head *list);
269         int     (*nf_min_max)(struct list_head *nidlist, u32 *min_nid,
270                               u32 *max_nid);
271 };
272
273 struct lnet_ni;                                  /* forward ref */
274 struct socket;
275
276 struct lnet_lnd {
277         /* fields initialized by the LND */
278         __u32                   lnd_type;
279
280         int  (*lnd_startup)(struct lnet_ni *ni);
281         void (*lnd_shutdown)(struct lnet_ni *ni);
282         int  (*lnd_ctl)(struct lnet_ni *ni, unsigned int cmd, void *arg);
283
284         /* In data movement APIs below, payload buffers are described as a set
285          * of 'niov' fragments which are in pages.
286          * The LND may NOT overwrite these fragment descriptors.
287          * An 'offset' and may specify a byte offset within the set of
288          * fragments to start from
289          */
290
291         /* Start sending a preformatted message.  'private' is NULL for PUT and
292          * GET messages; otherwise this is a response to an incoming message
293          * and 'private' is the 'private' passed to lnet_parse().  Return
294          * non-zero for immediate failure, otherwise complete later with
295          * lnet_finalize() */
296         int (*lnd_send)(struct lnet_ni *ni, void *private,
297                         struct lnet_msg *msg);
298
299         /* Start receiving 'mlen' bytes of payload data, skipping the following
300          * 'rlen' - 'mlen' bytes. 'private' is the 'private' passed to
301          * lnet_parse().  Return non-zero for immedaite failure, otherwise
302          * complete later with lnet_finalize().  This also gives back a receive
303          * credit if the LND does flow control. */
304         int (*lnd_recv)(struct lnet_ni *ni, void *private, struct lnet_msg *msg,
305                         int delayed, unsigned int niov,
306                         struct bio_vec *kiov,
307                         unsigned int offset, unsigned int mlen, unsigned int rlen);
308
309         /* lnet_parse() has had to delay processing of this message
310          * (e.g. waiting for a forwarding buffer or send credits).  Give the
311          * LND a chance to free urgently needed resources.  If called, return 0
312          * for success and do NOT give back a receive credit; that has to wait
313          * until lnd_recv() gets called.  On failure return < 0 and
314          * release resources; lnd_recv() will not be called. */
315         int (*lnd_eager_recv)(struct lnet_ni *ni, void *private,
316                               struct lnet_msg *msg, void **new_privatep);
317
318         /* notification of peer down */
319         void (*lnd_notify_peer_down)(struct lnet_nid *peer);
320
321         /* accept a new connection */
322         int (*lnd_accept)(struct lnet_ni *ni, struct socket *sock);
323
324         /* get dma_dev priority */
325         unsigned int (*lnd_get_dev_prio)(struct lnet_ni *ni,
326                                          unsigned int dev_idx);
327
328         /* Handle LND specific Netlink handling */
329         int (*lnd_nl_get)(int cmd, struct sk_buff *msg, int type, void *data);
330         int (*lnd_nl_set)(int cmd, struct nlattr *attr, int type, void *data);
331
332         const struct ln_key_list *lnd_keys;
333 };
334
335 struct lnet_tx_queue {
336         int                     tq_credits;     /* # tx credits free */
337         int                     tq_credits_min; /* lowest it's been */
338         int                     tq_credits_max; /* total # tx credits */
339         struct list_head        tq_delayed;     /* delayed TXs */
340 };
341
342 enum lnet_net_state {
343         /* set when net block is allocated */
344         LNET_NET_STATE_INIT = 0,
345         /* set when NIs in net are started successfully */
346         LNET_NET_STATE_ACTIVE,
347         /* set if all NIs in net are in FAILED state */
348         LNET_NET_STATE_INACTIVE,
349         /* set when shutting down a NET */
350         LNET_NET_STATE_DELETING
351 };
352
353 enum lnet_ni_state {
354         /* initial state when NI is created */
355         LNET_NI_STATE_INIT = 0,
356         /* set when NI is brought up */
357         LNET_NI_STATE_ACTIVE,
358         /* set when NI is being shutdown */
359         LNET_NI_STATE_DELETING,
360 };
361
362 #define LNET_NI_RECOVERY_PENDING        BIT(0)
363 #define LNET_NI_RECOVERY_FAILED         BIT(1)
364
365 enum lnet_stats_type {
366         LNET_STATS_TYPE_SEND = 0,
367         LNET_STATS_TYPE_RECV,
368         LNET_STATS_TYPE_DROP
369 };
370
371 struct lnet_comm_count {
372         atomic_t co_get_count;
373         atomic_t co_put_count;
374         atomic_t co_reply_count;
375         atomic_t co_ack_count;
376         atomic_t co_hello_count;
377 };
378
379 struct lnet_element_stats {
380         struct lnet_comm_count el_send_stats;
381         struct lnet_comm_count el_recv_stats;
382         struct lnet_comm_count el_drop_stats;
383 };
384
385 struct lnet_health_local_stats {
386         atomic_t hlt_local_interrupt;
387         atomic_t hlt_local_dropped;
388         atomic_t hlt_local_aborted;
389         atomic_t hlt_local_no_route;
390         atomic_t hlt_local_timeout;
391         atomic_t hlt_local_error;
392 };
393
394 struct lnet_health_remote_stats {
395         atomic_t hlt_remote_dropped;
396         atomic_t hlt_remote_timeout;
397         atomic_t hlt_remote_error;
398         atomic_t hlt_network_timeout;
399 };
400
401 struct lnet_net {
402         /* chain on the ln_nets */
403         struct list_head        net_list;
404
405         /* net ID, which is composed of
406          * (net_type << 16) | net_num.
407          * net_type can be one of the enumerated types defined in
408          * lnet/include/lnet/nidstr.h */
409         __u32                   net_id;
410
411         /* round robin selection */
412         __u32                   net_seq;
413
414         /* total number of CPTs in the array */
415         __u32                   net_ncpts;
416
417         /* cumulative CPTs of all NIs in this net */
418         __u32                   *net_cpts;
419
420         /* relative net selection priority */
421         __u32                   net_sel_priority;
422
423         /* network tunables */
424         struct lnet_ioctl_config_lnd_cmn_tunables net_tunables;
425
426         /*
427          * boolean to indicate that the tunables have been set and
428          * shouldn't be reset
429          */
430         bool                    net_tunables_set;
431
432         /* procedural interface */
433         const struct lnet_lnd   *net_lnd;
434
435         /* list of NIs on this net */
436         struct list_head        net_ni_list;
437
438         /* list of NIs being added, but not started yet */
439         struct list_head        net_ni_added;
440
441         /* dying LND instances */
442         struct list_head        net_ni_zombie;
443
444         /* when I was last alive */
445         time64_t                net_last_alive;
446
447         /* protects access to net_last_alive */
448         spinlock_t              net_lock;
449
450         /* list of router nids preferred for this network */
451         struct list_head        net_rtr_pref_nids;
452 };
453
454 /* Normally Netlink atttributes are defined in UAPI headers but Lustre is
455  * different in that the ABI is in a constant state of change unlike other
456  * Netlink interfaces. LNet sends a special header to help user land handle
457  * the differences.
458  */
459
460 /** enum lnet_err_atrrs               - LNet error netlink properties
461  *                                      For LNet request of multiple items
462  *                                      sometimes those items exist and
463  *                                      others don't. In the case the item
464  *                                      item doesn't exist we return the
465  *                                      error state.
466  *
467  * @LNET_ERR_ATTR_UNSPEC:               unspecified attribute to catch errors
468  *
469  * @LNET_ERR_ATTR_HDR:                  Name of the error header
470  *                                      (NLA_NUL_STRING)
471  * @LNET_ERR_ATTR_TYPE:                 Which LNet function since error is for
472  *                                      (NLA_STRING)
473  * @LNET_ERR_TYPE_ERRNO:                Error code for failure (NLA_S16)
474  * @LNET_ERR_DESCR:                     Complete error message (NLA_STRING)
475  */
476 enum lnet_err_attrs {
477         LNET_ERR_ATTR_UNSPEC = 0,
478
479         LNET_ERR_ATTR_HDR,
480         LNET_ERR_ATTR_TYPE,
481         LNET_ERR_ATTR_ERRNO,
482         LNET_ERR_ATTR_DESCR,
483         __LNET_ERR_ATTR_MAX_PLUS_ONE,
484 };
485
486 #define LNET_ERR_ATTR_MAX (__LNET_ERR_ATTR_MAX_PLUS_ONE - 1)
487
488 /** enum lnet_net_attrs               - LNet NI netlink properties
489  *                                      attributes that describe LNet 'NI'
490  *                                      These values are used to piece together
491  *                                      messages for sending and receiving.
492  *
493  * @LNET_NET_ATTR_UNSPEC:               unspecified attribute to catch errors
494  *
495  * @LNET_NET_ATTR_HDR:                  grouping for LNet net data (NLA_NUL_STRING)
496  * @LNET_NET_ATTR_TYPE:                 LNet net this NI belongs to (NLA_STRING)
497  * @LNET_NET_ATTR_LOCAL:                Local NI information (NLA_NESTED)
498  */
499 enum lnet_net_attrs {
500         LNET_NET_ATTR_UNSPEC = 0,
501
502         LNET_NET_ATTR_HDR,
503         LNET_NET_ATTR_TYPE,
504         LNET_NET_ATTR_LOCAL,
505
506         __LNET_NET_ATTR_MAX_PLUS_ONE,
507 };
508
509 #define LNET_NET_ATTR_MAX (__LNET_NET_ATTR_MAX_PLUS_ONE - 1)
510
511 /** enum lnet_net_local_ni_attrs              - LNet local NI netlink properties
512  *                                              attributes that describe local
513  *                                              NI
514  *
515  * @LNET_NET_LOCAL_NI_ATTR_UNSPEC:              unspecified attribute to catch
516  *                                              errors
517  *
518  * @LNET_NET_LOCAL_NI_ATTR_NID:                 NID that represents this NI
519  *                                              (NLA_STRING)
520  * @LNET_NET_LOCAL_NI_ATTR_STATUS:              State of this NI (NLA_STRING)
521  * @LNET_NET_LOCAL_NI_ATTR_INTERFACE:           Defines physical devices. used
522  *                                              to be many devices but no longer
523  *                                              (NLA_NESTED)
524  *
525  * @LNET_NET_LOCAL_NI_ATTR_STATS:               NI general msg stats (NLA_NESTED)
526  * @LNET_NET_LOCAL_NI_ATTR_UDSP_INFO:           NI UDSP state (NLA_NESTED)
527  * @LNET_NET_LOCAL_NI_ATTR_SEND_STATS:          NI send stats (NLA_NESTED)
528  * @LNET_NET_LOCAL_NI_ATTR_RECV_STATS:          NI recieved stats (NLA_NESTED)
529  * @LNET_NET_LOCAL_NI_ATTR_DROPPED_STATS:       NI dropped stats (NLA_NESTED)
530  * @LNET_NET_LOCAL_NI_ATTR_HEALTH_STATS:        NI health stats (NLA_NESTED)
531  * @LNET_NET_LOCAL_NI_ATTR_TUNABLES:            NI tunables (NLA_NESTED)
532  * @LNET_NET_LOCAL_NI_ATTR_LND_TUNABLES:        NI LND tunables (NLA_NESTED)
533  * @LNET_NET_LOCAL_NI_ATTR_DEV_CPT:             NI CPT interface bound to
534  *                                              (NLA_S32)
535  * @LNET_NET_LOCAL_NI_ATTR_CPTS:                CPT core used by this NI
536  *                                              (NLA_STRING)
537  */
538 enum lnet_net_local_ni_attrs {
539         LNET_NET_LOCAL_NI_ATTR_UNSPEC = 0,
540
541         LNET_NET_LOCAL_NI_ATTR_NID,
542         LNET_NET_LOCAL_NI_ATTR_STATUS,
543         LNET_NET_LOCAL_NI_ATTR_INTERFACE,
544
545         LNET_NET_LOCAL_NI_ATTR_STATS,
546         LNET_NET_LOCAL_NI_ATTR_UDSP_INFO,
547         LNET_NET_LOCAL_NI_ATTR_SEND_STATS,
548         LNET_NET_LOCAL_NI_ATTR_RECV_STATS,
549         LNET_NET_LOCAL_NI_ATTR_DROPPED_STATS,
550         LNET_NET_LOCAL_NI_ATTR_HEALTH_STATS,
551         LNET_NET_LOCAL_NI_ATTR_TUNABLES,
552         LNET_NET_LOCAL_NI_ATTR_LND_TUNABLES,
553         LNET_NET_LOCAL_NI_DEV_CPT,
554         LNET_NET_LOCAL_NI_CPTS,
555
556         __LNET_NET_LOCAL_NI_ATTR_MAX_PLUS_ONE,
557 };
558
559 #define LNET_NET_LOCAL_NI_ATTR_MAX (__LNET_NET_LOCAL_NI_ATTR_MAX_PLUS_ONE - 1)
560
561 /** enum lnet_net_local_ni_intf_attrs - LNet NI device netlink properties
562  *                                      attribute that reports the device
563  *                                      in use
564  *
565  * @LNET_NET_LOCAL_NI_INTF_ATTR_UNSPEC: unspecified attribute to catch errors
566  *
567  * @LNET_NET_LOCAL_NI_INTF_ATTR_TYPE:   Physcial device interface (NLA_STRING)
568  */
569 enum lnet_net_local_ni_intf_attrs {
570         LNET_NET_LOCAL_NI_INTF_ATTR_UNSPEC = 0,
571
572         LNET_NET_LOCAL_NI_INTF_ATTR_TYPE,
573
574         __LNET_NET_LOCAL_NI_INTF_ATTR_MAX_PLUS_ONE,
575 };
576
577 #define LNET_NET_LOCAL_NI_INTF_ATTR_MAX (__LNET_NET_LOCAL_NI_INTF_ATTR_MAX_PLUS_ONE - 1)
578
579 /** enum lnet_net_local_ni_stats_attrs        - LNet NI netlink properties
580  *                                              attributes that reports the
581  *                                              network traffic stats
582  *
583  * @LNET_NET_LOCAL_NI_STATS_ATTR_UNSPEC:        unspecified attribute to catch
584  *                                              errors
585  *
586  * @LNET_NET_LOCAL_NI_STATS_ATTR_SEND_COUNT:    Number of sent messages
587  *                                              (NLA_U32)
588  * @LNET_NET_LOCAL_NI_STATS_ATTR_RECV_COUNT:    Number of recieved messages
589  *                                              (NLA_U32)
590  * @LNET_NET_LOCAL_NI_STATS_ATTR_DROP_COUNT:    Number of dropped messages
591  *                                              (NLA_U32)
592  */
593 enum lnet_net_local_ni_stats_attrs {
594         LNET_NET_LOCAL_NI_STATS_ATTR_UNSPEC = 0,
595
596         LNET_NET_LOCAL_NI_STATS_ATTR_SEND_COUNT,
597         LNET_NET_LOCAL_NI_STATS_ATTR_RECV_COUNT,
598         LNET_NET_LOCAL_NI_STATS_ATTR_DROP_COUNT,
599         __LNET_NET_LOCAL_NI_STATS_ATTR_MAX_PLUS_ONE,
600 };
601
602 #define LNET_NET_LOCAL_NI_STATS_ATTR_MAX (__LNET_NET_LOCAL_NI_STATS_ATTR_MAX_PLUS_ONE - 1)
603
604 /** enum lnet_net_local_ni_msg_stats_attrs            - LNet NI netlink
605  *                                                      properties attributes
606  *                                                      that reports the message
607  *                                                      type traffic stats
608  *
609  * @LNET_NET_LOCAL_NI_MSG_STATS_ATTR_UNSPEC:            unspecified attribute
610  *                                                      to catch errors
611  *
612  * @LNET_NET_LOCAL_NI_MSG_STATS_ATTR_PUT_COUNT:         Number of PUT messages
613  *                                                      (NLA_U32)
614  * @LNET_NET_LOCAL_NI_MSG_STATS_ATTR_GET_COUNT:         Number of GET messages
615  *                                                      (NLA_U32)
616  * @LNET_NET_LOCAL_NI_MSG_STATS_ATTR_REPLY_COUNT:       Number of REPLY messages
617  *                                                      (NLA_U32)
618  * @LNET_NET_LOCAL_NI_MSG_STATS_ATTR_ACK_COUNT:         Number of ACK messages
619  *                                                      (NLA_U32)
620  * @LNET_NET_LOCAL_NI_MSG_STATS_ATTR_HELLO_COUNT:       Number of HELLO messages
621  *                                                      (NLA_U32)
622  */
623 enum lnet_net_local_ni_msg_stats_attrs {
624         LNET_NET_LOCAL_NI_MSG_STATS_ATTR_UNSPEC = 0,
625
626         LNET_NET_LOCAL_NI_MSG_STATS_ATTR_PUT_COUNT,
627         LNET_NET_LOCAL_NI_MSG_STATS_ATTR_GET_COUNT,
628         LNET_NET_LOCAL_NI_MSG_STATS_ATTR_REPLY_COUNT,
629         LNET_NET_LOCAL_NI_MSG_STATS_ATTR_ACK_COUNT,
630         LNET_NET_LOCAL_NI_MSG_STATS_ATTR_HELLO_COUNT,
631         __LNET_NET_LOCAL_NI_MSG_STATS_ATTR_MAX_PLUS_ONE,
632 };
633
634 #define LNET_NET_LOCAL_NI_MSG_STATS_ATTR_MAX (__LNET_NET_LOCAL_NI_MSG_STATS_ATTR_MAX_PLUS_ONE - 1)
635
636 /** enum lnet_net_local_ni_health_stats_attrs         - LNet NI netlink
637  *                                                      properties attributes
638  *                                                      that reports how
639  *                                                      healthly it is.
640  *
641  * @LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_UNSPEC:         unspecified attribute
642  *                                                      to catch errors
643  *
644  * @LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_FATAL_ERRORS:   How many fatal errors
645  *                                                      (NLA_S32)
646  * @LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_LEVEL:          How healthly is NI
647  *                                                      (NLA_S32)
648  * @LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_INTERRUPTS:     How many interrupts
649  *                                                      happened (NLA_U32)
650  * @LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_DROPPED:        How much traffic has
651  *                                                      been dropped (NLA_U32)
652  * @LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ABORTED:        How many aborts
653  *                                                      happened (NLA_U32)
654  * @LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NO_ROUTE:       How often routing broke
655  *                                                      (NLA_U32)
656  * @LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_TIMEOUTS:       How often timeouts
657  *                                                      occurred (NLA_U32)
658  * @LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ERROR:          The number of errors
659  *                                                      reported (NLA_U32)
660  * @LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_PING_COUNT:     Number of successful
661  *                                                      ping (NLA_U32)
662  * @LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NEXT_PING:      Number of next pings
663  *                                                      (NLA_U64)
664  */
665 enum lnet_net_local_ni_health_stats_attrs {
666         LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_UNSPEC = 0,
667         LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_PAD = LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_UNSPEC,
668
669         LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_FATAL_ERRORS,
670         LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_LEVEL,
671         LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_INTERRUPTS,
672         LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_DROPPED,
673         LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ABORTED,
674         LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NO_ROUTE,
675         LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_TIMEOUTS,
676         LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_ERROR,
677         LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_PING_COUNT,
678         LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_NEXT_PING,
679         __LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_MAX_PLUS_ONE,
680 };
681 #define LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_MAX (__LNET_NET_LOCAL_NI_HEALTH_STATS_ATTR_MAX_PLUS_ONE - 1)
682
683 /** enum lnet_net_local_ni_tunables_attrs             - LNet NI tunables
684  *                                                      netlink properties.
685  *                                                      Performance options
686  *                                                      for your NI.
687  *
688  * @LNET_NET_LOCAL_NI_TUNABLES_ATTR_UNSPEC:             unspecified attribute
689  *                                                      to catch errors
690  *
691  * @LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_TIMEOUT:       Timeout for LNet peer.
692  *                                                      (NLA_S32)
693  * @LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_CREDITS:       Credits for LNet peer.
694  *                                                      (NLA_S32)
695  * @LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_BUFFER_CREDITS: Buffer credits for
696  *                                                       LNet peer. (NLA_S32)
697  * @LNET_NET_LOCAL_NI_TUNABLES_ATTR_CREDITS:            Credits for LNet peer
698  *                                                      TX. (NLA_S32)
699  */
700 enum lnet_net_local_ni_tunables_attr {
701         LNET_NET_LOCAL_NI_TUNABLES_ATTR_UNSPEC = 0,
702
703         LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_TIMEOUT,
704         LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_CREDITS,
705         LNET_NET_LOCAL_NI_TUNABLES_ATTR_PEER_BUFFER_CREDITS,
706         LNET_NET_LOCAL_NI_TUNABLES_ATTR_CREDITS,
707         __LNET_NET_LOCAL_NI_TUNABLES_ATTR_MAX_PLUS_ONE,
708 };
709
710 #define LNET_NET_LOCAL_NI_TUNABLES_ATTR_MAX (__LNET_NET_LOCAL_NI_TUNABLES_ATTR_MAX_PLUS_ONE - 1)
711
712 /** enum lnet_route_attrs                     - LNet route netlink
713  *                                              attributes that describe
714  *                                              LNet routes
715  *
716  * @LNET_ROUTE_ATTR_UNSPEC:                     unspecified attribute to
717  *                                              catch errors
718  *
719  * @LNET_ROUTE_ATTR_HDR:                        grouping for LNet route data
720  *                                              (NLA_NUL_STRING)
721  * @LNET_ROUTE_ATTR_NET:                        LNet remote network reached
722  *                                              by the route (NLA_STRING)
723  * @LNET_ROUTE_ATTR_GATEWAY:                    gateway for the route
724  *                                              (NLA_STRING)
725  * @LNET_ROUTE_ATTR_HOP:                        route hop count (NLA_S32)
726  *
727  * @LNET_ROUTE_ATTR_PRIORITY:                   rank of this network path
728  *                                              (NLA_U32)
729  * @LNET_ROUTE_ATTR_HEALTH_SENSITIVITY:         rate of health value change
730  *                                              for the route (NLA_U32)
731  * @LNET_ROUTE_ATTR_STATE:                      state of route (NLA_STRING)
732  *
733  * @LNET_ROUTE_ATTR_TYPE:                       Report if we support multi-hop
734  *                                              (NLA_STRING)
735  */
736 enum lnet_route_attrs {
737         LNET_ROUTE_ATTR_UNSPEC = 0,
738
739         LNET_ROUTE_ATTR_HDR,
740         LNET_ROUTE_ATTR_NET,
741         LNET_ROUTE_ATTR_GATEWAY,
742         LNET_ROUTE_ATTR_HOP,
743         LNET_ROUTE_ATTR_PRIORITY,
744         LNET_ROUTE_ATTR_HEALTH_SENSITIVITY,
745         LNET_ROUTE_ATTR_STATE,
746         LNET_ROUTE_ATTR_TYPE,
747         __LNET_ROUTE_ATTR_MAX_PLUS_ONE,
748 };
749
750 #define LNET_ROUTE_ATTR_MAX (__LNET_ROUTE_ATTR_MAX_PLUS_ONE - 1)
751
752 /** enum lnet_peer_ni_attrs           - LNet peer NI netlink properties
753  *                                      attributes that describe LNet peer 'NI'.
754  *                                      These values are used to piece together
755  *                                      messages for sending and receiving.
756  *
757  * @LNET_PEER_NI_ATTR_UNSPEC:           unspecified attribute to catch errors
758  *
759  * @LNET_PEER_NI_ATTR_HDR:              grouping for LNet peer data
760  *                                      (NLA_NUL_STRING)
761  * @LNET_PEER_NI_ATTR_PRIMARY_NID:      primary NID of this peer (NLA_STRING)
762  * @LNET_PEER_NI_ATTR_MULTIRAIL:        Do we support MultiRail ? (NLA_FLAG)
763  * @LNET_PEER_NI_ATTR_STATE:            Bitfields of the peer state (NLA_U32)
764  * @LNET_PEER_NI_ATTR_PEER_NI_LIST:     List of remote peers we can reach
765  *                                      (NLA_NESTED)
766  */
767 enum lnet_peer_ni_attrs {
768         LNET_PEER_NI_ATTR_UNSPEC = 0,
769
770         LNET_PEER_NI_ATTR_HDR,
771         LNET_PEER_NI_ATTR_PRIMARY_NID,
772         LNET_PEER_NI_ATTR_MULTIRAIL,
773         LNET_PEER_NI_ATTR_STATE,
774         LNET_PEER_NI_ATTR_PEER_NI_LIST,
775         __LNET_PEER_NI_ATTR_MAX_PLUS_ONE,
776 };
777
778 #define LNET_PEER_NI_ATTR_MAX (__LNET_PEER_NI_ATTR_MAX_PLUS_ONE - 1)
779
780 /** enum lnet_peer_ni_list_attrs              - LNet remote peer netlink
781  *                                              properties attributes that
782  *                                              describe remote LNet peer 'NI'.
783  *                                              These values are used to piece
784  *                                              together messages for sending
785  *                                              and receiving.
786  *
787  * @LNET_PEER_NI_LIST_ATTR_UNSPEC:              unspecified attribute to catch
788  *                                              errors
789  *
790  * @LNET_PEER_NI_LIST_ATTR_NID:                 remote peer's NID (NLA_STRING)
791  * @LNET_PEER_NI_LIST_ATTR_UDSP_INFO:           remote peer's UDSP info
792  *                                              (NLA_NESTED)
793  * @LNET_PEER_NI_LIST_ATTR_STATE:               state of remote peer
794  *                                              (NLA_STRING)
795  *
796  * @LNET_PEER_NI_LIST_ATTR_MAX_TX_CREDITS:      Maximum TX credits for remote
797  *                                              peer (NLA_U32)
798  * @LNET_PEER_NI_LIST_ATTR_CUR_TX_CREDITS:      Current TX credits for remote
799  *                                              peer (NLA_U32)
800  * @LNET_PEER_NI_LIST_ATTR_MIN_TX_CREDITS:      Minimum TX credits for remote
801  *                                              peer (NLA_U32)
802  * @LNET_PEER_NI_LIST_ATTR_QUEUE_BUF_COUNT:     Size of TX queue buffer
803  *                                              (NLA_U32)
804  * @LNET_PEER_NI_LIST_ATTR_CUR_RTR_CREDITS:     Current router credits for
805  *                                              remote peer (NLA_U32)
806  * @LNET_PEER_NI_LIST_ATTR_MIN_RTR_CREDITS:     Minimum router credits for
807  *                                              remote peer (NLA_U32)
808  * @LNET_PEER_NI_LIST_ATTR_REFCOUNT:            Remote peer reference count
809  *                                              (NLA_U32)
810  * @LNET_PEER_NI_LIST_ATTR_STATS_COUNT:         Remote peer general stats,
811  *                                              reports sent, recieved, and
812  *                                              dropped packets. (NLA_NESTED)
813  *
814  * @LNET_PEER_NI_LIST_ATTR_SENT_STATS:          Remote peer sent stats,
815  *                                              reports gets, puts, acks, and
816  *                                              hello packets. (NLA_NESTED)
817  * @LNET_PEER_NI_LIST_ATTR_RECV_STATS:          Remote peer recieved stats,
818  *                                              reports gets, puts, acks, and
819  *                                              hello packets. (NLA_NESTED)
820  * @LNET_PEER_NI_LIST_ATTR_DROP_STATS:          Remote peer dropped stats,
821  *                                              reports gets, puts, acks, and
822  *                                              hello packets. (NLA_NESTED)
823  * @LNET_PEER_NI_LIST_ATTR_HEALTH_STATS:        Report the stats about the
824  *                                              health of the remote peer.
825  *                                              (NLA_NESTED)
826  */
827 enum lnet_peer_ni_list_attr {
828         LNET_PEER_NI_LIST_ATTR_UNSPEC = 0,
829
830         LNET_PEER_NI_LIST_ATTR_NID,
831         LNET_PEER_NI_LIST_ATTR_UDSP_INFO,
832         LNET_PEER_NI_LIST_ATTR_STATE,
833
834         LNET_PEER_NI_LIST_ATTR_MAX_TX_CREDITS,
835         LNET_PEER_NI_LIST_ATTR_CUR_TX_CREDITS,
836         LNET_PEER_NI_LIST_ATTR_MIN_TX_CREDITS,
837         LNET_PEER_NI_LIST_ATTR_QUEUE_BUF_COUNT,
838         LNET_PEER_NI_LIST_ATTR_CUR_RTR_CREDITS,
839         LNET_PEER_NI_LIST_ATTR_MIN_RTR_CREDITS,
840         LNET_PEER_NI_LIST_ATTR_REFCOUNT,
841         LNET_PEER_NI_LIST_ATTR_STATS_COUNT,
842
843         LNET_PEER_NI_LIST_ATTR_SENT_STATS,
844         LNET_PEER_NI_LIST_ATTR_RECV_STATS,
845         LNET_PEER_NI_LIST_ATTR_DROP_STATS,
846         LNET_PEER_NI_LIST_ATTR_HEALTH_STATS,
847
848         __LNET_PEER_NI_LIST_ATTR_MAX_PLUS_ONE,
849 };
850
851 #define LNET_PEER_NI_LIST_ATTR_MAX (__LNET_PEER_NI_LIST_ATTR_MAX_PLUS_ONE - 1)
852
853 /** enum lnet_peer_ni_list_stats_count                - LNet remote peer traffic
854  *                                                      stats netlink properties
855  *                                                      attributes that provide
856  *                                                      traffic stats on the
857  *                                                      remote LNet peer 'NI'.
858  *                                                      These values are used to
859  *                                                      piece together messages
860  *                                                      for sending and receiving.
861  *
862  * @LNET_PEER_NI_LIST_STATS_COUNT_ATTR_UNSPEC:          unspecified attribute to
863  *                                                      catch errors
864  *
865  * @LNET_PEER_NI_LIST_STATS_COUNT_ATTR_SEND_COUNT:      Number of sent packets for
866  *                                                      remote peer (NLA_U32)
867  * @LNET_PEER_NI_LIST_STATS_COUNT_ATTR_RECV_COUNT:      Numebr of recieved packets
868  *                                                      for remote peer (NLA_U32)
869  * @LNET_PEER_NI_LIST_STATS_COUNT_ATTR_DROP_COUNT:      Number of dropped packets
870  *                                                      for remote peer (NLA_U32)
871  */
872 enum lnet_peer_ni_list_stats_count {
873         LNET_PEER_NI_LIST_STATS_COUNT_ATTR_UNSPEC = 0,
874
875         LNET_PEER_NI_LIST_STATS_COUNT_ATTR_SEND_COUNT,
876         LNET_PEER_NI_LIST_STATS_COUNT_ATTR_RECV_COUNT,
877         LNET_PEER_NI_LIST_STATS_COUNT_ATTR_DROP_COUNT,
878         __LNET_PEER_NI_LIST_STATS_COUNT_ATTR_MAX_PLUS_ONE,
879 };
880
881 #define LNET_PEER_NI_LIST_STATS_COUNT_ATTR_MAX (__LNET_PEER_NI_LIST_STATS_COUNT_ATTR_MAX_PLUS_ONE - 1)
882
883 /** enum lnet_peer_ni_list_stats              - LNet remote peer stats netlink
884  *                                              properties attributes that
885  *                                              provide stats on the remote
886  *                                              LNet peer 'NI'. These values are
887  *                                              used to piece together messages
888  *                                              for sending and receiving.
889  *
890  * @LNET_PEER_NI_LIST_STATS_ATTR_UNSPEC:        unspecified attribute to catch
891  *                                              errors
892  *
893  * @LNET_PEER_NI_LIST_STATS_ATTR_PUT:           PUT message count for remote
894  *                                              peer (NLA_U32)
895  * @LNET_PEER_NI_LIST_STATS_ATTR_GET:           GET message count for remote
896  *                                              peer (NLA_U32)
897  * @LNET_PEER_NI_LIST_STATS_ATTR_REPLY:         REPLY message count for remote
898  *                                              peer (NLA_U32)
899  * @LNET_PEER_NI_LIST_STATS_ATTR_ACK:           ACK message count for remote
900  *                                              peer (NLA_U32)
901  * @LNET_PEER_NI_LIST_STATS_ATTR_HEALTH:        HELLO message count for remote
902  *                                              peer (NLA_U32)
903  */
904 enum lnet_peer_ni_list_stats {
905         LNET_PEER_NI_LIST_STATS_ATTR_UNSPEC = 0,
906
907         LNET_PEER_NI_LIST_STATS_ATTR_PUT,
908         LNET_PEER_NI_LIST_STATS_ATTR_GET,
909         LNET_PEER_NI_LIST_STATS_ATTR_REPLY,
910         LNET_PEER_NI_LIST_STATS_ATTR_ACK,
911         LNET_PEER_NI_LIST_STATS_ATTR_HELLO,
912         __LNET_PEER_NI_LIST_STATS_ATTR_MAX_PLUS_ONE,
913 };
914
915 #define LNET_PEER_NI_LIST_STATS_ATTR_MAX (__LNET_PEER_NI_LIST_STATS_ATTR_MAX_PLUS_ONE - 1)
916
917 /** enum lnet_peer_ni_list_health_stats               - LNet remote peer health
918  *                                                      stats netlink properties
919  *                                                      attributes that provide
920  *                                                      stats on the health of a
921  *                                                      remote LNet peer 'NI'.
922  *                                                      These values are used to
923  *                                                      piece together messages
924  *                                                      for sending and receiving.
925  *
926  * @LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_UNSPEC:         unspecified attribute to
927  *                                                      catch errors
928  *
929  * @LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_VALUE:          Health level of remote
930  *                                                      peer (NLA_S32)
931  * @LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_DROP:           drop message state for
932  *                                                      remote peer (NLA_U32)
933  * @LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_TIMEOUT:        timeout set for remote
934  *                                                      peer (NLA_U32)
935  * @LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_ERROR:          total errors for remote
936  *                                                      peer (NLA_U32)
937  * @LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NETWORK_TIMEOUT: network timeout for
938  *                                                       remote peer (NLA_U32)
939  * @LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_PING_COUNT:     number of pings for
940  *                                                      remote peer (NLA_U32)
941  * @LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NEXT_PING:      timestamp for next ping
942  *                                                      sent by remote peer
943  *                                                      (NLA_S64)
944  */
945 enum lnet_peer_ni_list_health_stats {
946         LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_UNSPEC = 0,
947         LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_PAD = LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_UNSPEC,
948
949         LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_VALUE,
950         LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_DROPPED,
951         LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_TIMEOUT,
952         LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_ERROR,
953         LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NETWORK_TIMEOUT,
954         LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_PING_COUNT,
955         LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_NEXT_PING,
956
957         __LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_MAX_PLUS_ONE,
958 };
959
960 #define LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_MAX (__LNET_PEER_NI_LIST_HEALTH_STATS_ATTR_MAX_PLUS_ONE - 1)
961
962 /** LNet netlink ping API */
963
964 /** enum lnet_ping_attr                               - LNet ping netlink properties
965  *                                                      attributes to describe ping format
966  *                                                      These values are used to piece together
967  *                                                      messages for sending and receiving.
968  *
969  * @LNET_PING_ATTR_UNSPEC:                              unspecified attribute to catch errors
970  *
971  * @LNET_PING_ATTR_HDR:                                 grouping for LNet ping  data (NLA_NUL_STRING)
972  * @LNET_PING_ATTR_PRIMARY_NID:                         Source NID for ping request (NLA_STRING)
973  * @LNET_PING_ATTR_ERRNO:                               error code if we fail to ping (NLA_S16)
974  * @LNET_PING_ATTR_MULTIRAIL:                           Report if MR is supported (NLA_FLAG)
975  * @LNET_PING_ATTR_PEER_NI_LIST:                        List of peer NI's (NLA_NESTED)
976  */
977 enum lnet_ping_attr {
978         LNET_PING_ATTR_UNSPEC = 0,
979
980         LNET_PING_ATTR_HDR,
981         LNET_PING_ATTR_PRIMARY_NID,
982         LNET_PING_ATTR_ERRNO,
983         LNET_PING_ATTR_MULTIRAIL,
984         LNET_PING_ATTR_PEER_NI_LIST,
985         __LNET_PING_ATTR_MAX_PLUS_ONE,
986 };
987
988 #define LNET_PING_ATTR_MAX (__LNET_PING_ATTR_MAX_PLUS_ONE - 1)
989
990 /** enum lnet_ping_peer_ni_attr               - LNet peer ni information reported by
991  *                                                      ping command. A list of these are
992  *                                                      returned with a ping request.
993  *
994  * @LNET_PING_PEER_NI_ATTR_UNSPEC:                      unspecified attribute to catch errrors
995  *
996  * @LNET_PING_PEER_NI_ATTR_NID:                         NID address of peer NI. (NLA_STRING)
997  */
998 enum lnet_ping_peer_ni_attr {
999         LNET_PING_PEER_NI_ATTR_UNSPEC = 0,
1000
1001         LNET_PING_PEER_NI_ATTR_NID,
1002         __LNET_PING_PEER_NI_ATTR_MAX_PLUS_ONE,
1003 };
1004
1005 #define LNET_PING_PEER_NI_ATTR_MAX (__LNET_PING_PEER_NI_ATTR_MAX_PLUS_ONE - 1)
1006
1007 /** enum lnet_udsp_info_attr                          - LNet UDSP information reported for
1008  *                                                      some subsystem that tracks it.
1009  *
1010  * @LNET_UDSP_INFO_ATTR_UNSPEC:                         unspecified attribute to catch errors
1011  *
1012  * @LNET_UDSP_INFO_ATTR_NET_PRIORITY,                   LNet net priority in selection.
1013  *                                                      (NLA_S32)
1014  * @LNET_UDSP_INFO_ATTR_NID_PRIORITY,                   NID's priority in selection.
1015  *                                                      (NLA_S32)
1016  * @LNET_UDSP_INFO_ATTR_PREF_RTR_NIDS_LIST:             Which gateway's are preferred.
1017  *                                                      (NLA_NESTED)
1018  * @LNET_UDSP_INFO_ATTR_PREF_NIDS_LIST:                 Which NIDs are preferred.
1019  *                                                      (NLA_NESTED)
1020  */
1021 enum lnet_udsp_info_attr {
1022         LNET_UDSP_INFO_ATTR_UNSPEC = 0,
1023
1024         LNET_UDSP_INFO_ATTR_NET_PRIORITY,
1025         LNET_UDSP_INFO_ATTR_NID_PRIORITY,
1026         LNET_UDSP_INFO_ATTR_PREF_RTR_NIDS_LIST,
1027         LNET_UDSP_INFO_ATTR_PREF_NIDS_LIST,
1028         __LNET_UDSP_INFO_ATTR_MAX_PLUS_ONE,
1029 };
1030
1031 #define LNET_UDSP_INFO_ATTR_MAX (__LNET_UDSP_INFO_ATTR_MAX_PLUS_ONE - 1)
1032
1033 /** enum lnet_udsp_info_pref_nids_attr                - LNet UDSP information reported for
1034  *                                                      some subsystem that tracks it.
1035  *
1036  * @LNET_UDSP_INFO_PREF_NIDS_ATTR_UNSPEC:               unspecified attribute to catch errors
1037  *
1038  * @LNET_UDSP_INFO_PREF_NIDS_ATTR_INDEX,                UDSP prority NIDs label
1039  *                                                      (NLA_NUL_STRING)
1040  * @LNET_UDSP_INFO_PREF_NIDS_ATTR_NID,                  UDSP prority NID (NLA_STRING)
1041  */
1042 enum lnet_udsp_info_pref_nids_attr {
1043         LNET_UDSP_INFO_PREF_NIDS_ATTR_UNSPEC = 0,
1044
1045         LNET_UDSP_INFO_PREF_NIDS_ATTR_INDEX,
1046         LNET_UDSP_INFO_PREF_NIDS_ATTR_NID,
1047         __LNET_UDSP_INFO_PREF_NIDS_ATTR_MAX_PLUS_ONE,
1048 };
1049
1050 #define LNET_UDSP_INFO_PREF_NIDS_ATTR_MAX (__LNET_UDSP_INFO_PREF_NIDS_ATTR_MAX_PLUS_ONE - 1)
1051
1052 /** enum lnet_cpt_of_nid_attr                   - Attributes to support
1053  *                                                lnetctl cpt-of-nid command
1054  *
1055  * @LNET_CPT_OF_NID_ATTR_UNSPEC                   unspecified attribute to catch
1056  *                                                errors
1057  * @LNET_CPT_OF_NID_ATTR_HDR                      Grouping for cpt-of-nid
1058  *                                                (NLA_NUL_STRING)
1059  * @LNET_CPT_OF_NID_ATTR_NID                      The NID whose CPT we want to
1060  *                                                calculate (NLA_STRING)
1061  * LNET_CPT_OF_NID_ATTR_CPT                       The CPT for the specified NID
1062  *                                                (NLA_U32)
1063  */
1064 enum lnet_cpt_of_nid_attr {
1065         LNET_CPT_OF_NID_ATTR_UNSPEC = 0,
1066
1067         LNET_CPT_OF_NID_ATTR_HDR,
1068         LNET_CPT_OF_NID_ATTR_NID,
1069         LNET_CPT_OF_NID_ATTR_CPT,
1070         __LNET_CPT_OF_NID_ATTR_MAX_PLUS_ONE,
1071 };
1072
1073 #define LNET_CPT_OF_NID_ATTR_MAX (__LNET_CPT_OF_NID_ATTR_MAX_PLUS_ONE - 1)
1074
1075 /** enum lnet_peer_dist_attr                  - Attributes to support
1076  *                                              reporting distance for peers
1077  *
1078  * @LNET_PEER_DIST_ATTR_UNSPEC                  unspecified attribute to catch
1079  *                                              errors
1080  * @LNET_PEER_DIST_ATTR_HDR                     Grouping which we just use peer
1081  *                                              (NLA_NUL_STRING)
1082  * @LNET_PEER_DIST_ATTR_NID                     The NID we collect data for
1083  *                                              (NLA_STRING)
1084  * @LNET_PEER_DIST_ATTR_DIST                    The distance for the specified
1085  *                                              NID (NLA_U32)
1086  * @LNET_PEER_DIST_ATTR_ORDER                   The order for the specified NID
1087  *                                              (NLA_U32)
1088  */
1089 enum lnet_peer_dist_attr {
1090         LNET_PEER_DIST_ATTR_UNSPEC = 0,
1091
1092         LNET_PEER_DIST_ATTR_HDR,
1093         LNET_PEER_DIST_ATTR_NID,
1094         LNET_PEER_DIST_ATTR_DIST,
1095         LNET_PEER_DIST_ATTR_ORDER,
1096         __LNET_PEER_DIST_ATTR_MAX_PLUS_ONE,
1097 };
1098
1099 #define LNET_PEER_DIST_ATTR_MAX (__LNET_PEER_DIST_ATTR_MAX_PLUS_ONE - 1)
1100
1101 struct lnet_ni {
1102         /* chain on the lnet_net structure */
1103         struct list_head        ni_netlist;
1104
1105         /* chain on the recovery queue */
1106         struct list_head        ni_recovery;
1107
1108         /* MD handle for recovery ping */
1109         struct lnet_handle_md   ni_ping_mdh;
1110
1111         spinlock_t              ni_lock;
1112
1113         /* number of CPTs */
1114         int                     ni_ncpts;
1115
1116         /* bond NI on some CPTs */
1117         __u32                   *ni_cpts;
1118
1119         /* interface's NID */
1120         struct lnet_nid         ni_nid;
1121
1122         /* instance-specific data */
1123         void                    *ni_data;
1124
1125         /* per ni credits */
1126         atomic_t                ni_tx_credits;
1127
1128         /* percpt TX queues */
1129         struct lnet_tx_queue    **ni_tx_queues;
1130
1131         /* percpt reference count */
1132         int                     **ni_refs;
1133
1134         /* pointer to parent network */
1135         struct lnet_net         *ni_net;
1136
1137         /* my health status */
1138         u32                     *ni_status;
1139
1140         /* NI FSM. Protected by lnet_ni_lock() */
1141         enum lnet_ni_state      ni_state;
1142
1143         /* Recovery state. Protected by lnet_ni_lock() */
1144         __u32                   ni_recovery_state;
1145
1146         /* When to send the next recovery ping */
1147         time64_t                ni_next_ping;
1148         /* How many pings sent during current recovery period did not receive
1149          * a reply. NB: reset whenever _any_ message arrives on this NI
1150          */
1151         unsigned int            ni_ping_count;
1152
1153         /* per NI LND tunables */
1154         struct lnet_lnd_tunables ni_lnd_tunables;
1155
1156         /* lnd tunables set explicitly */
1157         bool ni_lnd_tunables_set;
1158
1159         /* NI statistics */
1160         struct lnet_element_stats ni_stats;
1161         struct lnet_health_local_stats ni_hstats;
1162
1163         /* physical device CPT */
1164         int                     ni_dev_cpt;
1165
1166         /* sequence number used to round robin over nis within a net */
1167         __u32                   ni_seq;
1168
1169         /*
1170          * health value
1171          *      initialized to LNET_MAX_HEALTH_VALUE
1172          * Value is decremented every time we fail to send a message over
1173          * this NI because of a NI specific failure.
1174          * Value is incremented if we successfully send a message.
1175          */
1176         atomic_t                ni_healthv;
1177
1178         /*
1179          * Set to 1 by the LND when it receives an event telling it the device
1180          * has gone into a fatal state. Set to 0 when the LND receives an
1181          * even telling it the device is back online.
1182          */
1183         atomic_t                ni_fatal_error_on;
1184
1185         /* the relative selection priority of this NI */
1186         __u32                   ni_sel_priority;
1187
1188         /*
1189          * equivalent interface to use
1190          */
1191         char                    *ni_interface;
1192         struct net              *ni_net_ns;     /* original net namespace */
1193 };
1194
1195 #define LNET_PROTO_PING_MATCHBITS       0x8000000000000000LL
1196
1197 /*
1198  * Descriptor of a ping info buffer: keep a separate indicator of the
1199  * size and a reference count. The type is used both as a source and
1200  * sink of data, so we need to keep some information outside of the
1201  * area that may be overwritten by network data.
1202  */
1203 struct lnet_ping_buffer {
1204         int                     pb_nbytes;      /* sizeof pb_info */
1205         atomic_t                pb_refcnt;
1206         bool                    pb_needs_post;
1207         struct lnet_ping_info   pb_info;
1208 };
1209
1210 #define LNET_PING_BUFFER_SIZE(bytes) \
1211         (offsetof(struct lnet_ping_buffer, pb_info) + bytes)
1212 #define LNET_PING_BUFFER_LONI(PBUF)     ((PBUF)->pb_info.pi_ni[0].ns_nid)
1213 #define LNET_PING_BUFFER_SEQNO(PBUF)    ((PBUF)->pb_info.pi_ni[0].ns_status)
1214
1215 #define LNET_PING_INFO_TO_BUFFER(PINFO) \
1216         container_of((PINFO), struct lnet_ping_buffer, pb_info)
1217
1218 static inline int
1219 lnet_ping_sts_size(const struct lnet_nid *nid)
1220 {
1221         int size;
1222
1223         if (nid_is_nid4(nid))
1224                 return sizeof(struct lnet_ni_status);
1225
1226         size = offsetof(struct lnet_ni_large_status, ns_nid) +
1227                NID_BYTES(nid);
1228
1229         return round_up(size, 4);
1230 }
1231
1232 static inline struct lnet_ni_large_status *
1233 lnet_ping_sts_next(const struct lnet_ni_large_status *nis)
1234 {
1235         return (void *)nis + lnet_ping_sts_size(&nis->ns_nid);
1236 }
1237
1238 static inline bool
1239 lnet_ping_at_least_two_entries(const struct lnet_ping_info *pi)
1240 {
1241         /* Return true if we have at lease two entries.  There is always a
1242          * least one, a 4-byte lo0 interface.
1243          */
1244         struct lnet_ni_large_status *lns;
1245
1246         if ((pi->pi_features & LNET_PING_FEAT_LARGE_ADDR) == 0)
1247                 return pi->pi_nnis <= 2;
1248         /* There is at least 1 large-address entry */
1249         if (pi->pi_nnis != 1)
1250                 return false;
1251         lns = (void *)&pi->pi_ni[1];
1252         lns = lnet_ping_sts_next(lns);
1253
1254         return ((void *)pi + lnet_ping_info_size(pi) <= (void *)lns);
1255 }
1256
1257 struct lnet_nid_list {
1258         struct list_head nl_list;
1259         struct lnet_nid nl_nid;
1260 };
1261
1262 struct lnet_peer_ni {
1263         /* chain on lpn_peer_nis */
1264         struct list_head        lpni_peer_nis;
1265         /* chain on remote peer list */
1266         struct list_head        lpni_on_remote_peer_ni_list;
1267         /* chain on recovery queue */
1268         struct list_head        lpni_recovery;
1269         /* chain on peer hash */
1270         struct list_head        lpni_hashlist;
1271         /* messages blocking for tx credits */
1272         struct list_head        lpni_txq;
1273         /* pointer to peer net I'm part of */
1274         struct lnet_peer_net    *lpni_peer_net;
1275         /* statistics kept on each peer NI */
1276         struct lnet_element_stats lpni_stats;
1277         struct lnet_health_remote_stats lpni_hstats;
1278         /* spin lock protecting credits and lpni_txq */
1279         spinlock_t              lpni_lock;
1280         /* # tx credits available */
1281         int                     lpni_txcredits;
1282         /* low water mark */
1283         int                     lpni_mintxcredits;
1284         /*
1285          * Each peer_ni in a gateway maintains its own credits. This
1286          * allows more traffic to gateways that have multiple interfaces.
1287          */
1288         /* # router credits */
1289         int                     lpni_rtrcredits;
1290         /* low water mark */
1291         int                     lpni_minrtrcredits;
1292         /* bytes queued for sending */
1293         long                    lpni_txqnob;
1294         /* network peer is on */
1295         struct lnet_net         *lpni_net;
1296         /* peer's NID */
1297         struct lnet_nid         lpni_nid;
1298         /* # refs */
1299         struct kref             lpni_kref;
1300         /* health value for the peer */
1301         atomic_t                lpni_healthv;
1302         /* recovery ping mdh */
1303         struct lnet_handle_md   lpni_recovery_ping_mdh;
1304         /* When to send the next recovery ping */
1305         time64_t                lpni_next_ping;
1306         /* How many pings sent during current recovery period did not receive
1307          * a reply. NB: reset whenever _any_ message arrives from this peer NI
1308          */
1309         unsigned int            lpni_ping_count;
1310         /* CPT this peer attached on */
1311         int                     lpni_cpt;
1312         /* state flags -- protected by lpni_lock */
1313         unsigned                lpni_state;
1314         /* status of the peer NI as reported by the peer */
1315         __u32                   lpni_ns_status;
1316         /* sequence number used to round robin over peer nis within a net */
1317         __u32                   lpni_seq;
1318         /* sequence number used to round robin over gateways */
1319         __u32                   lpni_gw_seq;
1320         /* returned RC ping features. Protected with lpni_lock */
1321         unsigned int            lpni_ping_feats;
1322         /* time last message was received from the peer */
1323         time64_t                lpni_last_alive;
1324         /* preferred local nids: if only one, use lpni_pref.nid */
1325         union lpni_pref {
1326                 struct lnet_nid nid;
1327                 struct list_head nids;
1328         } lpni_pref;
1329         /* list of router nids preferred for this peer NI */
1330         struct list_head        lpni_rtr_pref_nids;
1331         /* The relative selection priority of this peer NI */
1332         __u32                   lpni_sel_priority;
1333         /* number of preferred NIDs in lnpi_pref_nids */
1334         __u32                   lpni_pref_nnids;
1335 };
1336
1337 /* Preferred path added due to traffic on non-MR peer_ni */
1338 #define LNET_PEER_NI_NON_MR_PREF        BIT(0)
1339 /* peer is being recovered. */
1340 #define LNET_PEER_NI_RECOVERY_PENDING   BIT(1)
1341 /* recovery ping failed */
1342 #define LNET_PEER_NI_RECOVERY_FAILED    BIT(2)
1343 /* peer is being deleted */
1344 #define LNET_PEER_NI_DELETING           BIT(3)
1345
1346 struct lnet_peer {
1347         /* chain on pt_peer_list */
1348         struct list_head        lp_peer_list;
1349
1350         /* list of peer nets */
1351         struct list_head        lp_peer_nets;
1352
1353         /* list of messages pending discovery*/
1354         struct list_head        lp_dc_pendq;
1355
1356         /* chain on router list */
1357         struct list_head        lp_rtr_list;
1358
1359         /* primary NID of the peer */
1360         struct lnet_nid         lp_primary_nid;
1361
1362         /* source NID to use during discovery */
1363         struct lnet_nid         lp_disc_src_nid;
1364         /* destination NID to use during discovery */
1365         struct lnet_nid         lp_disc_dst_nid;
1366
1367         /* net to perform discovery on */
1368         __u32                   lp_disc_net_id;
1369
1370         /* CPT of peer_table */
1371         int                     lp_cpt;
1372
1373         /* number of NIDs on this peer */
1374         int                     lp_nnis;
1375
1376         /* # refs from lnet_route::lr_gateway */
1377         int                     lp_rtr_refcount;
1378
1379         /*
1380          * peer specific health sensitivity value to decrement peer nis in
1381          * this peer with if set to something other than 0
1382          */
1383         __u32                   lp_health_sensitivity;
1384
1385         /* messages blocking for router credits */
1386         struct list_head        lp_rtrq;
1387
1388         /* routes on this peer */
1389         struct list_head        lp_routes;
1390
1391         /* reference count */
1392         atomic_t                lp_refcount;
1393
1394         /* lock protecting peer state flags and lpni_rtrq */
1395         spinlock_t              lp_lock;
1396
1397         /* peer state flags */
1398         unsigned                lp_state;
1399
1400         /* buffer for data pushed by peer */
1401         struct lnet_ping_buffer *lp_data;
1402
1403         /* MD handle for ping in progress */
1404         struct lnet_handle_md   lp_ping_mdh;
1405
1406         /* MD handle for push in progress */
1407         struct lnet_handle_md   lp_push_mdh;
1408
1409         /* number of bytes for sizing pb_info in push data */
1410         int                     lp_data_bytes;
1411
1412         /* NI config sequence number of peer */
1413         __u32                   lp_peer_seqno;
1414
1415         /* Local NI config sequence number acked by peer */
1416         __u32                   lp_node_seqno;
1417
1418         /* Local NI config sequence number sent to peer */
1419         __u32                   lp_node_seqno_sent;
1420
1421         /* Ping error encountered during discovery. */
1422         int                     lp_ping_error;
1423
1424         /* Push error encountered during discovery. */
1425         int                     lp_push_error;
1426
1427         /* Error encountered during discovery. */
1428         int                     lp_dc_error;
1429
1430         /* time it was put on the ln_dc_working queue */
1431         time64_t                lp_last_queued;
1432
1433         /* link on discovery-related lists */
1434         struct list_head        lp_dc_list;
1435
1436         /* tasks waiting on discovery of this peer */
1437         wait_queue_head_t       lp_dc_waitq;
1438
1439         /* cached peer aliveness */
1440         bool                    lp_alive;
1441
1442         /* sequence number used to round robin traffic to this peer's
1443          * nets/NIs
1444          */
1445         __u32                   lp_send_seq;
1446
1447         /* timestamp of primary nid lock */
1448         __u64                   lp_prim_lock_ts;
1449 };
1450
1451 /*
1452  * The status flags in lp_state. Their semantics have chosen so that
1453  * lp_state can be zero-initialized.
1454  *
1455  * A peer is marked MULTI_RAIL in two cases: it was configured using DLC
1456  * as multi-rail aware, or the LNET_PING_FEAT_MULTI_RAIL bit was set.
1457  *
1458  * A peer is marked NO_DISCOVERY if the LNET_PING_FEAT_DISCOVERY bit was
1459  * NOT set when the peer was pinged by discovery.
1460  *
1461  * A peer is marked ROUTER if it indicates so in the feature bit.
1462  */
1463 #define LNET_PEER_MULTI_RAIL            BIT(0)  /* Multi-rail aware */
1464 #define LNET_PEER_NO_DISCOVERY          BIT(1)  /* Peer disabled discovery */
1465 #define LNET_PEER_ROUTER_ENABLED        BIT(2)  /* router feature enabled */
1466
1467 /*
1468  * A peer is marked CONFIGURED if it was configured by DLC.
1469  *
1470  * In addition, a peer is marked DISCOVERED if it has fully passed
1471  * through Peer Discovery.
1472  *
1473  * When Peer Discovery is disabled, the discovery thread will mark
1474  * peers REDISCOVER to indicate that they should be re-examined if
1475  * discovery is (re)enabled on the node.
1476  *
1477  * A peer that was created as the result of inbound traffic will not
1478  * be marked at all.
1479  */
1480 #define LNET_PEER_CONFIGURED            BIT(3)  /* Configured via DLC */
1481 #define LNET_PEER_DISCOVERED            BIT(4)  /* Peer was discovered */
1482 #define LNET_PEER_REDISCOVER            BIT(5)  /* Discovery was disabled */
1483 /*
1484  * A peer is marked DISCOVERING when discovery is in progress.
1485  * The other flags below correspond to stages of discovery.
1486  */
1487 #define LNET_PEER_DISCOVERING           BIT(6)  /* Discovering */
1488 #define LNET_PEER_DATA_PRESENT          BIT(7)  /* Remote peer data present */
1489 #define LNET_PEER_NIDS_UPTODATE         BIT(8)  /* Remote peer info uptodate */
1490 #define LNET_PEER_PING_SENT             BIT(9)  /* Waiting for REPLY to Ping */
1491 #define LNET_PEER_PUSH_SENT             BIT(10) /* Waiting for ACK of Push */
1492 #define LNET_PEER_PING_FAILED           BIT(11) /* Ping send failure */
1493 #define LNET_PEER_PUSH_FAILED           BIT(12) /* Push send failure */
1494 /*
1495  * A ping can be forced as a way to fix up state, or as a manual
1496  * intervention by an admin.
1497  * A push can be forced in circumstances that would normally not
1498  * allow for one to happen.
1499  */
1500 #define LNET_PEER_FORCE_PING            BIT(13) /* Forced Ping */
1501 #define LNET_PEER_FORCE_PUSH            BIT(14) /* Forced Push */
1502
1503 /* force delete even if router */
1504 #define LNET_PEER_RTR_NI_FORCE_DEL      BIT(15)
1505
1506 /* gw undergoing alive discovery */
1507 #define LNET_PEER_RTR_DISCOVERY         BIT(16)
1508 /* gw has undergone discovery (does not indicate success or failure) */
1509 #define LNET_PEER_RTR_DISCOVERED        BIT(17)
1510
1511 /* peer is marked for deletion */
1512 #define LNET_PEER_MARK_DELETION         BIT(18)
1513 /* lnet_peer_del()/lnet_peer_del_locked() has been called on the peer */
1514 #define LNET_PEER_MARK_DELETED          BIT(19)
1515 /* lock primary NID to what's requested by ULP */
1516 #define LNET_PEER_LOCK_PRIMARY          BIT(20)
1517 /* this is for informational purposes only. It is set if a peer gets
1518  * configured from Lustre with a primary NID which belongs to another peer
1519  * which is also configured by Lustre as the primary NID.
1520  */
1521 #define LNET_PEER_BAD_CONFIG            BIT(21)
1522
1523 struct lnet_peer_net {
1524         /* chain on lp_peer_nets */
1525         struct list_head        lpn_peer_nets;
1526
1527         /* list of peer_nis on this network */
1528         struct list_head        lpn_peer_nis;
1529
1530         /* pointer to the peer I'm part of */
1531         struct lnet_peer        *lpn_peer;
1532
1533         /* Net ID */
1534         __u32                   lpn_net_id;
1535
1536         /* peer net health */
1537         int                     lpn_healthv;
1538
1539         /* time of next router ping on this net */
1540         time64_t                lpn_next_ping;
1541
1542         /* selection sequence number */
1543         __u32                   lpn_seq;
1544
1545         /* relative peer net selection priority */
1546         __u32                   lpn_sel_priority;
1547
1548         /* reference count */
1549         atomic_t                lpn_refcount;
1550 };
1551
1552 /* peer hash size */
1553 #define LNET_PEER_HASH_BITS     9
1554 #define LNET_PEER_HASH_SIZE     (1 << LNET_PEER_HASH_BITS)
1555
1556 /*
1557  * peer hash table - one per CPT
1558  *
1559  * protected by lnet_net_lock/EX for update
1560  *    pt_version
1561  *    pt_hash[...]
1562  *    pt_peer_list
1563  *    pt_peers
1564  * protected by pt_zombie_lock:
1565  *    pt_zombie_list
1566  *    pt_zombies
1567  *
1568  * pt_zombie lock nests inside lnet_net_lock
1569  */
1570 struct lnet_peer_table {
1571         int                     pt_version;     /* /proc validity stamp */
1572         struct list_head        *pt_hash;       /* NID->peer hash */
1573         struct list_head        pt_peer_list;   /* peers */
1574         int                     pt_peers;       /* # peers */
1575         struct list_head        pt_zombie_list; /* zombie peer_ni */
1576         int                     pt_zombies;     /* # zombie peers_ni */
1577         spinlock_t              pt_zombie_lock; /* protect list and count */
1578 };
1579
1580 /* peer aliveness is enabled only on routers for peers in a network where the
1581  * struct lnet_ni::ni_peertimeout has been set to a positive value
1582  */
1583 #define lnet_peer_aliveness_enabled(lp) (the_lnet.ln_routing != 0 && \
1584                                         ((lp)->lpni_net) && \
1585                                         (lp)->lpni_net->net_tunables.lct_peer_timeout > 0)
1586
1587 struct lnet_route {
1588         struct list_head        lr_list;        /* chain on net */
1589         struct list_head        lr_gwlist;      /* chain on gateway */
1590         struct lnet_peer        *lr_gateway;    /* router node */
1591         struct lnet_nid         lr_nid;         /* NID used to add route */
1592         __u32                   lr_net;         /* remote network number */
1593         __u32                   lr_lnet;        /* local network number */
1594         int                     lr_seq;         /* sequence for round-robin */
1595         __u32                   lr_hops;        /* how far I am */
1596         unsigned int            lr_priority;    /* route priority */
1597         atomic_t                lr_alive;       /* cached route aliveness */
1598         bool                    lr_single_hop;  /* this route is single-hop */
1599 };
1600
1601 #define LNET_REMOTE_NETS_HASH_DEFAULT   (1U << 7)
1602 #define LNET_REMOTE_NETS_HASH_MAX       (1U << 16)
1603 #define LNET_REMOTE_NETS_HASH_SIZE      (1 << the_lnet.ln_remote_nets_hbits)
1604
1605 struct lnet_remotenet {
1606         /* chain on ln_remote_nets_hash */
1607         struct list_head        lrn_list;
1608         /* routes to me */
1609         struct list_head        lrn_routes;
1610         /* my net number */
1611         __u32                   lrn_net;
1612 };
1613
1614 /** lnet message has credit and can be submitted to lnd for send/receive */
1615 #define LNET_CREDIT_OK          0
1616 /** lnet message is waiting for credit */
1617 #define LNET_CREDIT_WAIT        1
1618 /** lnet message is waiting for discovery */
1619 #define LNET_DC_WAIT            2
1620
1621 struct lnet_rtrbufpool {
1622         /* my free buffer pool */
1623         struct list_head        rbp_bufs;
1624         /* messages blocking for a buffer */
1625         struct list_head        rbp_msgs;
1626         /* # pages in each buffer */
1627         int                     rbp_npages;
1628         /* requested number of buffers */
1629         int                     rbp_req_nbuffers;
1630         /* # buffers actually allocated */
1631         int                     rbp_nbuffers;
1632         /* # free buffers / blocked messages */
1633         int                     rbp_credits;
1634         /* low water mark */
1635         int                     rbp_mincredits;
1636 };
1637
1638 struct lnet_rtrbuf {
1639         struct list_head         rb_list;       /* chain on rbp_bufs */
1640         struct lnet_rtrbufpool  *rb_pool;       /* owning pool */
1641         struct bio_vec           rb_kiov[0];    /* the buffer space */
1642 };
1643
1644 #define LNET_PEER_HASHSIZE   503                /* prime! */
1645
1646 enum lnet_match_flags {
1647         /* Didn't match anything */
1648         LNET_MATCHMD_NONE       = BIT(0),
1649         /* Matched OK */
1650         LNET_MATCHMD_OK         = BIT(1),
1651         /* Must be discarded */
1652         LNET_MATCHMD_DROP       = BIT(2),
1653         /* match and buffer is exhausted */
1654         LNET_MATCHMD_EXHAUSTED  = BIT(3),
1655         /* match or drop */
1656         LNET_MATCHMD_FINISH     = (LNET_MATCHMD_OK | LNET_MATCHMD_DROP),
1657 };
1658
1659 /* Options for struct lnet_portal::ptl_options */
1660 #define LNET_PTL_LAZY           BIT(0)
1661 #define LNET_PTL_MATCH_UNIQUE   BIT(1)  /* unique match, for RDMA */
1662 #define LNET_PTL_MATCH_WILDCARD BIT(2)  /* wildcard match, request portal */
1663
1664 /* parameter for matching operations (GET, PUT) */
1665 struct lnet_match_info {
1666         __u64                   mi_mbits;
1667         struct lnet_processid   mi_id;
1668         unsigned int            mi_cpt;
1669         unsigned int            mi_opc;
1670         unsigned int            mi_portal;
1671         unsigned int            mi_rlength;
1672         unsigned int            mi_roffset;
1673 };
1674
1675 /* ME hash of RDMA portal */
1676 #define LNET_MT_HASH_BITS               8
1677 #define LNET_MT_HASH_SIZE               (1 << LNET_MT_HASH_BITS)
1678 #define LNET_MT_HASH_MASK               (LNET_MT_HASH_SIZE - 1)
1679 /* we allocate (LNET_MT_HASH_SIZE + 1) entries for lnet_match_table::mt_hash,
1680  * the last entry is reserved for MEs with ignore-bits */
1681 #define LNET_MT_HASH_IGNORE             LNET_MT_HASH_SIZE
1682 /* __u64 has 2^6 bits, so need 2^(LNET_MT_HASH_BITS - LNET_MT_BITS_U64) which
1683  * is 4 __u64s as bit-map, and add an extra __u64 (only use one bit) for the
1684  * ME-list with ignore-bits, which is mtable::mt_hash[LNET_MT_HASH_IGNORE] */
1685 #define LNET_MT_BITS_U64                6       /* 2^6 bits */
1686 #define LNET_MT_EXHAUSTED_BITS          (LNET_MT_HASH_BITS - LNET_MT_BITS_U64)
1687 #define LNET_MT_EXHAUSTED_BMAP          ((1 << LNET_MT_EXHAUSTED_BITS) + 1)
1688
1689 /* portal match table */
1690 struct lnet_match_table {
1691         /* reserved for upcoming patches, CPU partition ID */
1692         unsigned int            mt_cpt;
1693         unsigned int            mt_portal;      /* portal index */
1694         /* match table is set as "enabled" if there's non-exhausted MD
1695          * attached on mt_mhash, it's only valid for wildcard portal */
1696         unsigned int            mt_enabled;
1697         /* bitmap to flag whether MEs on mt_hash are exhausted or not */
1698         __u64                   mt_exhausted[LNET_MT_EXHAUSTED_BMAP];
1699         struct list_head        *mt_mhash;      /* matching hash */
1700 };
1701
1702 /* these are only useful for wildcard portal */
1703 /* Turn off message rotor for wildcard portals */
1704 #define LNET_PTL_ROTOR_OFF      0
1705 /* round-robin dispatch all PUT messages for wildcard portals */
1706 #define LNET_PTL_ROTOR_ON       1
1707 /* round-robin dispatch routed PUT message for wildcard portals */
1708 #define LNET_PTL_ROTOR_RR_RT    2
1709 /* dispatch routed PUT message by hashing source NID for wildcard portals */
1710 #define LNET_PTL_ROTOR_HASH_RT  3
1711
1712 struct lnet_portal {
1713         spinlock_t              ptl_lock;
1714         unsigned int            ptl_index;      /* portal ID, reserved */
1715         /* flags on this portal: lazy, unique... */
1716         unsigned int            ptl_options;
1717         /* list of messages which are stealing buffer */
1718         struct list_head        ptl_msg_stealing;
1719         /* messages blocking for MD */
1720         struct list_head        ptl_msg_delayed;
1721         /* Match table for each CPT */
1722         struct lnet_match_table **ptl_mtables;
1723         /* spread rotor of incoming "PUT" */
1724         unsigned int            ptl_rotor;
1725         /* # active entries for this portal */
1726         int                     ptl_mt_nmaps;
1727         /* array of active entries' cpu-partition-id */
1728         int                     ptl_mt_maps[0];
1729 };
1730
1731 #define LNET_LH_HASH_BITS       12
1732 #define LNET_LH_HASH_SIZE       (1ULL << LNET_LH_HASH_BITS)
1733 #define LNET_LH_HASH_MASK       (LNET_LH_HASH_SIZE - 1)
1734
1735 /* resource container (ME, MD, EQ) */
1736 struct lnet_res_container {
1737         unsigned int            rec_type;       /* container type */
1738         __u64                   rec_lh_cookie;  /* cookie generator */
1739         struct list_head        rec_active;     /* active resource list */
1740         struct list_head        *rec_lh_hash;   /* handle hash */
1741 };
1742
1743 /* message container */
1744 struct lnet_msg_container {
1745         int                     msc_init;       /* initialized or not */
1746         /* max # threads finalizing */
1747         int                     msc_nfinalizers;
1748         /* msgs waiting to complete finalizing */
1749         struct list_head        msc_finalizing;
1750         /* msgs waiting to be resent */
1751         struct list_head        msc_resending;
1752         struct list_head        msc_active;     /* active message list */
1753         /* threads doing finalization */
1754         void                    **msc_finalizers;
1755         /* threads doing resends */
1756         void                    **msc_resenders;
1757 };
1758
1759 /* This UDSP structures need to match the user space liblnetconfig structures
1760  * in order for the marshall and unmarshall functions to be common.
1761  */
1762
1763 /* Net is described as a
1764  *  1. net type
1765  *  2. num range
1766  */
1767 struct lnet_ud_net_descr {
1768         __u32 udn_net_type;
1769         struct list_head udn_net_num_range;
1770 };
1771
1772 /* each NID range is defined as
1773  *  1. net descriptor
1774  *  2. address range descriptor
1775  */
1776 struct lnet_ud_nid_descr {
1777         struct lnet_ud_net_descr ud_net_id;
1778         struct list_head ud_addr_range;
1779         __u32 ud_mem_size;
1780 };
1781
1782 /* a UDSP rule can have up to three user defined NID descriptors
1783  *      - src: defines the local NID range for the rule
1784  *      - dst: defines the peer NID range for the rule
1785  *      - rte: defines the router NID range for the rule
1786  *
1787  * An action union defines the action to take when the rule
1788  * is matched
1789  */
1790 struct lnet_udsp {
1791         struct list_head udsp_on_list;
1792         __u32 udsp_idx;
1793         struct lnet_ud_nid_descr udsp_src;
1794         struct lnet_ud_nid_descr udsp_dst;
1795         struct lnet_ud_nid_descr udsp_rte;
1796         enum lnet_udsp_action_type udsp_action_type;
1797         union {
1798                 __u32 udsp_priority;
1799         } udsp_action;
1800 };
1801
1802 /* Peer Discovery states */
1803 #define LNET_DC_STATE_SHUTDOWN          0       /* not started */
1804 #define LNET_DC_STATE_RUNNING           1       /* started up OK */
1805 #define LNET_DC_STATE_STOPPING          2       /* telling thread to stop */
1806
1807 /* Router Checker states */
1808 #define LNET_MT_STATE_SHUTDOWN          0       /* not started */
1809 #define LNET_MT_STATE_RUNNING           1       /* started up OK */
1810 #define LNET_MT_STATE_STOPPING          2       /* telling thread to stop */
1811
1812 /* LNet states */
1813 #define LNET_STATE_SHUTDOWN             0       /* not started */
1814 #define LNET_STATE_RUNNING              1       /* started up OK */
1815 #define LNET_STATE_STOPPING             2       /* telling thread to stop */
1816
1817 struct lnet {
1818         /* CPU partition table of LNet */
1819         struct cfs_cpt_table            *ln_cpt_table;
1820         /* number of CPTs in ln_cpt_table */
1821         unsigned int                    ln_cpt_number;
1822         unsigned int                    ln_cpt_bits;
1823
1824         /* protect LNet resources (ME/MD/EQ) */
1825         struct cfs_percpt_lock          *ln_res_lock;
1826         /* # portals */
1827         int                             ln_nportals;
1828         /* the vector of portals */
1829         struct lnet_portal              **ln_portals;
1830         /* percpt MD container */
1831         struct lnet_res_container       **ln_md_containers;
1832
1833         /* Event Queue container */
1834         struct lnet_res_container       ln_eq_container;
1835         spinlock_t                      ln_eq_wait_lock;
1836
1837         unsigned int                    ln_remote_nets_hbits;
1838
1839         /* protect NI, peer table, credits, routers, rtrbuf... */
1840         struct cfs_percpt_lock          *ln_net_lock;
1841         /* percpt message containers for active/finalizing/freed message */
1842         struct lnet_msg_container       **ln_msg_containers;
1843         struct lnet_counters            **ln_counters;
1844         struct lnet_peer_table          **ln_peer_tables;
1845         /* list of peer nis not on a local network */
1846         struct list_head                ln_remote_peer_ni_list;
1847         /* failure simulation */
1848         struct list_head                ln_test_peers;
1849         struct list_head                ln_drop_rules;
1850         struct list_head                ln_delay_rules;
1851         /* LND instances */
1852         struct list_head                ln_nets;
1853         /* Sequence number used to round robin sends across all nets */
1854         __u32                           ln_net_seq;
1855         /* the loopback NI */
1856         struct lnet_ni                  *ln_loni;
1857         /* network zombie list */
1858         struct list_head                ln_net_zombie;
1859         /* resend messages list */
1860         struct list_head                ln_msg_resend;
1861         /* spin lock to protect the msg resend list */
1862         spinlock_t                      ln_msg_resend_lock;
1863
1864         /* remote networks with routes to them */
1865         struct list_head                *ln_remote_nets_hash;
1866         /* validity stamp */
1867         __u64                           ln_remote_nets_version;
1868         /* list of all known routers */
1869         struct list_head                ln_routers;
1870         /* validity stamp */
1871         __u64                           ln_routers_version;
1872         /* percpt router buffer pools */
1873         struct lnet_rtrbufpool          **ln_rtrpools;
1874
1875         /*
1876          * Ping target / Push source
1877          *
1878          * The ping target and push source share a single buffer. The
1879          * ln_ping_target is protected against concurrent updates by
1880          * ln_api_mutex.
1881          */
1882         struct lnet_handle_md           ln_ping_target_md;
1883         lnet_handler_t                  ln_ping_target_handler;
1884         struct lnet_ping_buffer         *ln_ping_target;
1885         atomic_t                        ln_ping_target_seqno;
1886
1887         /*
1888          * Push Target
1889          *
1890          * ln_push_nnis contains the desired size of the push target.
1891          * The lnet_net_lock is used to handle update races. The old
1892          * buffer may linger a while after it has been unlinked, in
1893          * which case the event handler cleans up.
1894          */
1895         lnet_handler_t                  ln_push_target_handler;
1896         struct lnet_handle_md           ln_push_target_md;
1897         struct lnet_ping_buffer         *ln_push_target;
1898         /* bytes needed for pb_info to receive push */
1899         int                             ln_push_target_nbytes;
1900
1901         /* discovery event queue handle */
1902         lnet_handler_t                  ln_dc_handler;
1903         /* discovery requests */
1904         struct list_head                ln_dc_request;
1905         /* discovery working list */
1906         struct list_head                ln_dc_working;
1907         /* discovery expired list */
1908         struct list_head                ln_dc_expired;
1909         /* discovery thread wait queue */
1910         wait_queue_head_t               ln_dc_waitq;
1911         /* discovery startup/shutdown state */
1912         int                             ln_dc_state;
1913
1914         /* monitor thread startup/shutdown state */
1915         int                             ln_mt_state;
1916         /* serialise startup/shutdown */
1917         struct semaphore                ln_mt_signal;
1918
1919         struct mutex                    ln_api_mutex;
1920         struct mutex                    ln_lnd_mutex;
1921         /* Have I called LNetNIInit myself? */
1922         int                             ln_niinit_self;
1923         /* LNetNIInit/LNetNIFini counter */
1924         int                             ln_refcount;
1925         /* SHUTDOWN/RUNNING/STOPPING */
1926         int                             ln_state;
1927
1928         int                             ln_routing;     /* am I a router? */
1929         lnet_pid_t                      ln_pid;         /* requested pid */
1930         /* uniquely identifies this ni in this epoch */
1931         __u64                           ln_interface_cookie;
1932         /* registered LNDs */
1933         const struct lnet_lnd           *ln_lnds[NUM_LNDS];
1934
1935         /* test protocol compatibility flags */
1936         unsigned long                   ln_testprotocompat;
1937
1938         /* 0 - load the NIs from the mod params
1939          * 1 - do not load the NIs from the mod params
1940          * Reverse logic to ensure that other calls to LNetNIInit
1941          * need no change
1942          */
1943         bool                            ln_nis_from_mod_params;
1944
1945         /*
1946          * completion for the monitor thread. The monitor thread takes care of
1947          * checking routes, timedout messages and resending messages.
1948          */
1949         struct completion               ln_mt_wait_complete;
1950
1951         /* per-cpt resend queues */
1952         struct list_head                **ln_mt_resendqs;
1953         /* local NIs to recover */
1954         struct list_head                ln_mt_localNIRecovq;
1955         /* local NIs to recover */
1956         struct list_head                ln_mt_peerNIRecovq;
1957         /*
1958          * An array of queues for GET/PUT waiting for REPLY/ACK respectively.
1959          * There are CPT number of queues. Since response trackers will be
1960          * added on the fast path we can't afford to grab the exclusive
1961          * net lock to protect these queues. The CPT will be calculated
1962          * based on the mdh cookie.
1963          */
1964         struct list_head                **ln_mt_rstq;
1965         /*
1966          * A response tracker becomes a zombie when the associated MD is queued
1967          * for unlink before the response tracker is detached from the MD. An
1968          * entry on a zombie list can be freed when either the remaining
1969          * operations on the MD complete or when LNet has shut down.
1970          */
1971         struct list_head                **ln_mt_zombie_rstqs;
1972         /* recovery handler */
1973         lnet_handler_t                  ln_mt_handler;
1974
1975         /*
1976          * Completed when the discovery and monitor threads can enter their
1977          * work loops
1978          */
1979         struct completion               ln_started;
1980         /* UDSP list */
1981         struct list_head                ln_udsp_list;
1982
1983         /* Number of messages that have exceeded their message deadline */
1984         atomic_t                        ln_late_msg_count;
1985         /* Total amount of time past their deadline for all late ^ messages */
1986         atomic64_t                      ln_late_msg_nsecs;
1987
1988         /* for LNDs to signal that ping buffer needs updating */
1989         atomic_t                        ln_update_ping_buf;
1990
1991         /* workqueue for serving lnd ping buffer update requests */
1992         struct workqueue_struct         *ln_pb_update_wq;
1993         struct work_struct              ln_pb_update_work;
1994
1995         atomic_t                        ln_pb_update_ready;
1996 };
1997
1998 struct genl_filter_list {
1999         struct list_head         lp_list;
2000         void                    *lp_cursor;
2001         bool                     lp_first;
2002 };
2003
2004 static const struct nla_policy scalar_attr_policy[LN_SCALAR_MAX + 1] = {
2005         [LN_SCALAR_ATTR_LIST]           = { .type = NLA_NESTED },
2006         [LN_SCALAR_ATTR_LIST_SIZE]      = { .type = NLA_U16 },
2007         [LN_SCALAR_ATTR_INDEX]          = { .type = NLA_U16 },
2008         [LN_SCALAR_ATTR_NLA_TYPE]       = { .type = NLA_U16 },
2009         [LN_SCALAR_ATTR_VALUE]          = { .type = NLA_STRING },
2010         [LN_SCALAR_ATTR_KEY_FORMAT]     = { .type = NLA_U16 },
2011 };
2012
2013 int lnet_genl_send_scalar_list(struct sk_buff *msg, u32 portid, u32 seq,
2014                                const struct genl_family *family, int flags,
2015                                u8 cmd, const struct ln_key_list *data[]);
2016
2017 /* Special workaround for pre-4.19 kernels to send error messages
2018  * from dumpit routines. Newer kernels will send message with
2019  * NL_SET_ERR_MSG information by default if NETLINK_EXT_ACK is set.
2020  */
2021 static inline int lnet_nl_send_error(struct sk_buff *msg, int portid, int seq,
2022                                      int error)
2023 {
2024 #ifndef HAVE_NL_DUMP_WITH_EXT_ACK
2025         struct nlmsghdr *nlh;
2026
2027         if (!error)
2028                 return 0;
2029
2030         nlh = nlmsg_put(msg, portid, seq, NLMSG_ERROR, sizeof(error), 0);
2031         if (!nlh)
2032                 return -ENOMEM;
2033 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
2034         netlink_ack(msg, nlh, error, NULL);
2035 #else
2036         netlink_ack(msg, nlh, error);
2037 #endif
2038         return nlmsg_len(nlh);
2039 #else
2040         return error;
2041 #endif
2042 }
2043
2044 #endif