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