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