Whamcloud - gitweb
LU-17662 osd-zfs: Support for ZFS 2.2.3
[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         /* merge and assign this NID as primary when discovery completes */
1438         struct lnet_nid         lp_merge_primary_nid;
1439 };
1440
1441 /*
1442  * The status flags in lp_state. Their semantics have chosen so that
1443  * lp_state can be zero-initialized.
1444  *
1445  * A peer is marked MULTI_RAIL in two cases: it was configured using DLC
1446  * as multi-rail aware, or the LNET_PING_FEAT_MULTI_RAIL bit was set.
1447  *
1448  * A peer is marked NO_DISCOVERY if the LNET_PING_FEAT_DISCOVERY bit was
1449  * NOT set when the peer was pinged by discovery.
1450  *
1451  * A peer is marked ROUTER if it indicates so in the feature bit.
1452  */
1453 #define LNET_PEER_MULTI_RAIL            BIT(0)  /* Multi-rail aware */
1454 #define LNET_PEER_NO_DISCOVERY          BIT(1)  /* Peer disabled discovery */
1455 #define LNET_PEER_ROUTER_ENABLED        BIT(2)  /* router feature enabled */
1456
1457 /*
1458  * A peer is marked CONFIGURED if it was configured by DLC.
1459  *
1460  * In addition, a peer is marked DISCOVERED if it has fully passed
1461  * through Peer Discovery.
1462  *
1463  * When Peer Discovery is disabled, the discovery thread will mark
1464  * peers REDISCOVER to indicate that they should be re-examined if
1465  * discovery is (re)enabled on the node.
1466  *
1467  * A peer that was created as the result of inbound traffic will not
1468  * be marked at all.
1469  */
1470 #define LNET_PEER_CONFIGURED            BIT(3)  /* Configured via DLC */
1471 #define LNET_PEER_DISCOVERED            BIT(4)  /* Peer was discovered */
1472 #define LNET_PEER_REDISCOVER            BIT(5)  /* Discovery was disabled */
1473 /*
1474  * A peer is marked DISCOVERING when discovery is in progress.
1475  * The other flags below correspond to stages of discovery.
1476  */
1477 #define LNET_PEER_DISCOVERING           BIT(6)  /* Discovering */
1478 #define LNET_PEER_DATA_PRESENT          BIT(7)  /* Remote peer data present */
1479 #define LNET_PEER_NIDS_UPTODATE         BIT(8)  /* Remote peer info uptodate */
1480 #define LNET_PEER_PING_SENT             BIT(9)  /* Waiting for REPLY to Ping */
1481 #define LNET_PEER_PUSH_SENT             BIT(10) /* Waiting for ACK of Push */
1482 #define LNET_PEER_PING_FAILED           BIT(11) /* Ping send failure */
1483 #define LNET_PEER_PUSH_FAILED           BIT(12) /* Push send failure */
1484 /*
1485  * A ping can be forced as a way to fix up state, or as a manual
1486  * intervention by an admin.
1487  * A push can be forced in circumstances that would normally not
1488  * allow for one to happen.
1489  */
1490 #define LNET_PEER_FORCE_PING            BIT(13) /* Forced Ping */
1491 #define LNET_PEER_FORCE_PUSH            BIT(14) /* Forced Push */
1492
1493 /* force delete even if router */
1494 #define LNET_PEER_RTR_NI_FORCE_DEL      BIT(15)
1495
1496 /* gw undergoing alive discovery */
1497 #define LNET_PEER_RTR_DISCOVERY         BIT(16)
1498 /* gw has undergone discovery (does not indicate success or failure) */
1499 #define LNET_PEER_RTR_DISCOVERED        BIT(17)
1500
1501 /* peer is marked for deletion */
1502 #define LNET_PEER_MARK_DELETION         BIT(18)
1503 /* lnet_peer_del()/lnet_peer_del_locked() has been called on the peer */
1504 #define LNET_PEER_MARK_DELETED          BIT(19)
1505 /* lock primary NID to what's requested by ULP */
1506 #define LNET_PEER_LOCK_PRIMARY          BIT(20)
1507 /* this is for informational purposes only. It is set if a peer gets
1508  * configured from Lustre with a primary NID which belongs to another peer
1509  * which is also configured by Lustre as the primary NID.
1510  */
1511 #define LNET_PEER_BAD_CONFIG            BIT(21)
1512
1513 struct lnet_peer_net {
1514         /* chain on lp_peer_nets */
1515         struct list_head        lpn_peer_nets;
1516
1517         /* list of peer_nis on this network */
1518         struct list_head        lpn_peer_nis;
1519
1520         /* pointer to the peer I'm part of */
1521         struct lnet_peer        *lpn_peer;
1522
1523         /* Net ID */
1524         __u32                   lpn_net_id;
1525
1526         /* peer net health */
1527         int                     lpn_healthv;
1528
1529         /* time of next router ping on this net */
1530         time64_t                lpn_next_ping;
1531
1532         /* selection sequence number */
1533         __u32                   lpn_seq;
1534
1535         /* relative peer net selection priority */
1536         __u32                   lpn_sel_priority;
1537
1538         /* reference count */
1539         atomic_t                lpn_refcount;
1540 };
1541
1542 /* peer hash size */
1543 #define LNET_PEER_HASH_BITS     9
1544 #define LNET_PEER_HASH_SIZE     (1 << LNET_PEER_HASH_BITS)
1545
1546 /*
1547  * peer hash table - one per CPT
1548  *
1549  * protected by lnet_net_lock/EX for update
1550  *    pt_version
1551  *    pt_hash[...]
1552  *    pt_peer_list
1553  *    pt_peers
1554  * protected by pt_zombie_lock:
1555  *    pt_zombie_list
1556  *    pt_zombies
1557  *
1558  * pt_zombie lock nests inside lnet_net_lock
1559  */
1560 struct lnet_peer_table {
1561         int                     pt_version;     /* /proc validity stamp */
1562         struct list_head        *pt_hash;       /* NID->peer hash */
1563         struct list_head        pt_peer_list;   /* peers */
1564         int                     pt_peers;       /* # peers */
1565         struct list_head        pt_zombie_list; /* zombie peer_ni */
1566         int                     pt_zombies;     /* # zombie peers_ni */
1567         spinlock_t              pt_zombie_lock; /* protect list and count */
1568 };
1569
1570 /* peer aliveness is enabled only on routers for peers in a network where the
1571  * struct lnet_ni::ni_peertimeout has been set to a positive value
1572  */
1573 #define lnet_peer_aliveness_enabled(lp) (the_lnet.ln_routing != 0 && \
1574                                         ((lp)->lpni_net) && \
1575                                         (lp)->lpni_net->net_tunables.lct_peer_timeout > 0)
1576
1577 struct lnet_route {
1578         struct list_head        lr_list;        /* chain on net */
1579         struct list_head        lr_gwlist;      /* chain on gateway */
1580         struct lnet_peer        *lr_gateway;    /* router node */
1581         struct lnet_nid         lr_nid;         /* NID used to add route */
1582         __u32                   lr_net;         /* remote network number */
1583         __u32                   lr_lnet;        /* local network number */
1584         int                     lr_seq;         /* sequence for round-robin */
1585         __u32                   lr_hops;        /* how far I am */
1586         unsigned int            lr_priority;    /* route priority */
1587         atomic_t                lr_alive;       /* cached route aliveness */
1588         bool                    lr_single_hop;  /* this route is single-hop */
1589 };
1590
1591 #define LNET_REMOTE_NETS_HASH_DEFAULT   (1U << 7)
1592 #define LNET_REMOTE_NETS_HASH_MAX       (1U << 16)
1593 #define LNET_REMOTE_NETS_HASH_SIZE      (1 << the_lnet.ln_remote_nets_hbits)
1594
1595 struct lnet_remotenet {
1596         /* chain on ln_remote_nets_hash */
1597         struct list_head        lrn_list;
1598         /* routes to me */
1599         struct list_head        lrn_routes;
1600         /* my net number */
1601         __u32                   lrn_net;
1602 };
1603
1604 /** lnet message has credit and can be submitted to lnd for send/receive */
1605 #define LNET_CREDIT_OK          0
1606 /** lnet message is waiting for credit */
1607 #define LNET_CREDIT_WAIT        1
1608 /** lnet message is waiting for discovery */
1609 #define LNET_DC_WAIT            2
1610
1611 struct lnet_rtrbufpool {
1612         /* my free buffer pool */
1613         struct list_head        rbp_bufs;
1614         /* messages blocking for a buffer */
1615         struct list_head        rbp_msgs;
1616         /* # pages in each buffer */
1617         int                     rbp_npages;
1618         /* requested number of buffers */
1619         int                     rbp_req_nbuffers;
1620         /* # buffers actually allocated */
1621         int                     rbp_nbuffers;
1622         /* # free buffers / blocked messages */
1623         int                     rbp_credits;
1624         /* low water mark */
1625         int                     rbp_mincredits;
1626 };
1627
1628 struct lnet_rtrbuf {
1629         struct list_head         rb_list;       /* chain on rbp_bufs */
1630         struct lnet_rtrbufpool  *rb_pool;       /* owning pool */
1631         struct bio_vec           rb_kiov[0];    /* the buffer space */
1632 };
1633
1634 #define LNET_PEER_HASHSIZE   503                /* prime! */
1635
1636 enum lnet_match_flags {
1637         /* Didn't match anything */
1638         LNET_MATCHMD_NONE       = BIT(0),
1639         /* Matched OK */
1640         LNET_MATCHMD_OK         = BIT(1),
1641         /* Must be discarded */
1642         LNET_MATCHMD_DROP       = BIT(2),
1643         /* match and buffer is exhausted */
1644         LNET_MATCHMD_EXHAUSTED  = BIT(3),
1645         /* match or drop */
1646         LNET_MATCHMD_FINISH     = (LNET_MATCHMD_OK | LNET_MATCHMD_DROP),
1647 };
1648
1649 /* Options for struct lnet_portal::ptl_options */
1650 #define LNET_PTL_LAZY           BIT(0)
1651 #define LNET_PTL_MATCH_UNIQUE   BIT(1)  /* unique match, for RDMA */
1652 #define LNET_PTL_MATCH_WILDCARD BIT(2)  /* wildcard match, request portal */
1653
1654 /* parameter for matching operations (GET, PUT) */
1655 struct lnet_match_info {
1656         __u64                   mi_mbits;
1657         struct lnet_processid   mi_id;
1658         unsigned int            mi_cpt;
1659         unsigned int            mi_opc;
1660         unsigned int            mi_portal;
1661         unsigned int            mi_rlength;
1662         unsigned int            mi_roffset;
1663 };
1664
1665 /* ME hash of RDMA portal */
1666 #define LNET_MT_HASH_BITS               8
1667 #define LNET_MT_HASH_SIZE               (1 << LNET_MT_HASH_BITS)
1668 #define LNET_MT_HASH_MASK               (LNET_MT_HASH_SIZE - 1)
1669 /* we allocate (LNET_MT_HASH_SIZE + 1) entries for lnet_match_table::mt_hash,
1670  * the last entry is reserved for MEs with ignore-bits */
1671 #define LNET_MT_HASH_IGNORE             LNET_MT_HASH_SIZE
1672 /* __u64 has 2^6 bits, so need 2^(LNET_MT_HASH_BITS - LNET_MT_BITS_U64) which
1673  * is 4 __u64s as bit-map, and add an extra __u64 (only use one bit) for the
1674  * ME-list with ignore-bits, which is mtable::mt_hash[LNET_MT_HASH_IGNORE] */
1675 #define LNET_MT_BITS_U64                6       /* 2^6 bits */
1676 #define LNET_MT_EXHAUSTED_BITS          (LNET_MT_HASH_BITS - LNET_MT_BITS_U64)
1677 #define LNET_MT_EXHAUSTED_BMAP          ((1 << LNET_MT_EXHAUSTED_BITS) + 1)
1678
1679 /* portal match table */
1680 struct lnet_match_table {
1681         /* reserved for upcoming patches, CPU partition ID */
1682         unsigned int            mt_cpt;
1683         unsigned int            mt_portal;      /* portal index */
1684         /* match table is set as "enabled" if there's non-exhausted MD
1685          * attached on mt_mhash, it's only valid for wildcard portal */
1686         unsigned int            mt_enabled;
1687         /* bitmap to flag whether MEs on mt_hash are exhausted or not */
1688         __u64                   mt_exhausted[LNET_MT_EXHAUSTED_BMAP];
1689         struct list_head        *mt_mhash;      /* matching hash */
1690 };
1691
1692 /* these are only useful for wildcard portal */
1693 /* Turn off message rotor for wildcard portals */
1694 #define LNET_PTL_ROTOR_OFF      0
1695 /* round-robin dispatch all PUT messages for wildcard portals */
1696 #define LNET_PTL_ROTOR_ON       1
1697 /* round-robin dispatch routed PUT message for wildcard portals */
1698 #define LNET_PTL_ROTOR_RR_RT    2
1699 /* dispatch routed PUT message by hashing source NID for wildcard portals */
1700 #define LNET_PTL_ROTOR_HASH_RT  3
1701
1702 struct lnet_portal {
1703         spinlock_t              ptl_lock;
1704         unsigned int            ptl_index;      /* portal ID, reserved */
1705         /* flags on this portal: lazy, unique... */
1706         unsigned int            ptl_options;
1707         /* list of messages which are stealing buffer */
1708         struct list_head        ptl_msg_stealing;
1709         /* messages blocking for MD */
1710         struct list_head        ptl_msg_delayed;
1711         /* Match table for each CPT */
1712         struct lnet_match_table **ptl_mtables;
1713         /* spread rotor of incoming "PUT" */
1714         unsigned int            ptl_rotor;
1715         /* # active entries for this portal */
1716         int                     ptl_mt_nmaps;
1717         /* array of active entries' cpu-partition-id */
1718         int                     ptl_mt_maps[0];
1719 };
1720
1721 #define LNET_LH_HASH_BITS       12
1722 #define LNET_LH_HASH_SIZE       (1ULL << LNET_LH_HASH_BITS)
1723 #define LNET_LH_HASH_MASK       (LNET_LH_HASH_SIZE - 1)
1724
1725 /* resource container (ME, MD, EQ) */
1726 struct lnet_res_container {
1727         unsigned int            rec_type;       /* container type */
1728         __u64                   rec_lh_cookie;  /* cookie generator */
1729         struct list_head        rec_active;     /* active resource list */
1730         struct list_head        *rec_lh_hash;   /* handle hash */
1731 };
1732
1733 /* message container */
1734 struct lnet_msg_container {
1735         int                     msc_init;       /* initialized or not */
1736         /* max # threads finalizing */
1737         int                     msc_nfinalizers;
1738         /* msgs waiting to complete finalizing */
1739         struct list_head        msc_finalizing;
1740         /* msgs waiting to be resent */
1741         struct list_head        msc_resending;
1742         struct list_head        msc_active;     /* active message list */
1743         /* threads doing finalization */
1744         void                    **msc_finalizers;
1745         /* threads doing resends */
1746         void                    **msc_resenders;
1747 };
1748
1749 /* This UDSP structures need to match the user space liblnetconfig structures
1750  * in order for the marshall and unmarshall functions to be common.
1751  */
1752
1753 /* Net is described as a
1754  *  1. net type
1755  *  2. num range
1756  */
1757 struct lnet_ud_net_descr {
1758         __u32 udn_net_type;
1759         struct list_head udn_net_num_range;
1760 };
1761
1762 /* each NID range is defined as
1763  *  1. net descriptor
1764  *  2. address range descriptor
1765  */
1766 struct lnet_ud_nid_descr {
1767         struct lnet_ud_net_descr ud_net_id;
1768         struct list_head ud_addr_range;
1769         __u32 ud_mem_size;
1770 };
1771
1772 /* a UDSP rule can have up to three user defined NID descriptors
1773  *      - src: defines the local NID range for the rule
1774  *      - dst: defines the peer NID range for the rule
1775  *      - rte: defines the router NID range for the rule
1776  *
1777  * An action union defines the action to take when the rule
1778  * is matched
1779  */
1780 struct lnet_udsp {
1781         struct list_head udsp_on_list;
1782         __u32 udsp_idx;
1783         struct lnet_ud_nid_descr udsp_src;
1784         struct lnet_ud_nid_descr udsp_dst;
1785         struct lnet_ud_nid_descr udsp_rte;
1786         enum lnet_udsp_action_type udsp_action_type;
1787         union {
1788                 __u32 udsp_priority;
1789         } udsp_action;
1790 };
1791
1792 /* Peer Discovery states */
1793 #define LNET_DC_STATE_SHUTDOWN          0       /* not started */
1794 #define LNET_DC_STATE_RUNNING           1       /* started up OK */
1795 #define LNET_DC_STATE_STOPPING          2       /* telling thread to stop */
1796
1797 /* Router Checker states */
1798 #define LNET_MT_STATE_SHUTDOWN          0       /* not started */
1799 #define LNET_MT_STATE_RUNNING           1       /* started up OK */
1800 #define LNET_MT_STATE_STOPPING          2       /* telling thread to stop */
1801
1802 /* LNet states */
1803 #define LNET_STATE_SHUTDOWN             0       /* not started */
1804 #define LNET_STATE_RUNNING              1       /* started up OK */
1805 #define LNET_STATE_STOPPING             2       /* telling thread to stop */
1806
1807 struct lnet {
1808         /* CPU partition table of LNet */
1809         struct cfs_cpt_table            *ln_cpt_table;
1810         /* number of CPTs in ln_cpt_table */
1811         unsigned int                    ln_cpt_number;
1812         unsigned int                    ln_cpt_bits;
1813
1814         /* protect LNet resources (ME/MD/EQ) */
1815         struct cfs_percpt_lock          *ln_res_lock;
1816         /* # portals */
1817         int                             ln_nportals;
1818         /* the vector of portals */
1819         struct lnet_portal              **ln_portals;
1820         /* percpt MD container */
1821         struct lnet_res_container       **ln_md_containers;
1822
1823         /* Event Queue container */
1824         struct lnet_res_container       ln_eq_container;
1825         spinlock_t                      ln_eq_wait_lock;
1826
1827         unsigned int                    ln_remote_nets_hbits;
1828
1829         /* protect NI, peer table, credits, routers, rtrbuf... */
1830         struct cfs_percpt_lock          *ln_net_lock;
1831         /* percpt message containers for active/finalizing/freed message */
1832         struct lnet_msg_container       **ln_msg_containers;
1833         struct lnet_counters            **ln_counters;
1834         struct lnet_peer_table          **ln_peer_tables;
1835         /* list of peer nis not on a local network */
1836         struct list_head                ln_remote_peer_ni_list;
1837         /* failure simulation */
1838         struct list_head                ln_test_peers;
1839         struct list_head                ln_drop_rules;
1840         struct list_head                ln_delay_rules;
1841         /* LND instances */
1842         struct list_head                ln_nets;
1843         /* Sequence number used to round robin sends across all nets */
1844         __u32                           ln_net_seq;
1845         /* the loopback NI */
1846         struct lnet_ni                  *ln_loni;
1847         /* network zombie list */
1848         struct list_head                ln_net_zombie;
1849         /* resend messages list */
1850         struct list_head                ln_msg_resend;
1851         /* spin lock to protect the msg resend list */
1852         spinlock_t                      ln_msg_resend_lock;
1853
1854         /* remote networks with routes to them */
1855         struct list_head                *ln_remote_nets_hash;
1856         /* validity stamp */
1857         __u64                           ln_remote_nets_version;
1858         /* list of all known routers */
1859         struct list_head                ln_routers;
1860         /* validity stamp */
1861         __u64                           ln_routers_version;
1862         /* percpt router buffer pools */
1863         struct lnet_rtrbufpool          **ln_rtrpools;
1864
1865         /*
1866          * Ping target / Push source
1867          *
1868          * The ping target and push source share a single buffer. The
1869          * ln_ping_target is protected against concurrent updates by
1870          * ln_api_mutex.
1871          */
1872         struct lnet_handle_md           ln_ping_target_md;
1873         lnet_handler_t                  ln_ping_target_handler;
1874         struct lnet_ping_buffer         *ln_ping_target;
1875         atomic_t                        ln_ping_target_seqno;
1876
1877         /*
1878          * Push Target
1879          *
1880          * ln_push_nnis contains the desired size of the push target.
1881          * The lnet_net_lock is used to handle update races. The old
1882          * buffer may linger a while after it has been unlinked, in
1883          * which case the event handler cleans up.
1884          */
1885         lnet_handler_t                  ln_push_target_handler;
1886         struct lnet_handle_md           ln_push_target_md;
1887         struct lnet_ping_buffer         *ln_push_target;
1888         /* bytes needed for pb_info to receive push */
1889         int                             ln_push_target_nbytes;
1890
1891         /* discovery event queue handle */
1892         lnet_handler_t                  ln_dc_handler;
1893         /* discovery requests */
1894         struct list_head                ln_dc_request;
1895         /* discovery working list */
1896         struct list_head                ln_dc_working;
1897         /* discovery expired list */
1898         struct list_head                ln_dc_expired;
1899         /* discovery thread wait queue */
1900         wait_queue_head_t               ln_dc_waitq;
1901         /* discovery startup/shutdown state */
1902         int                             ln_dc_state;
1903
1904         /* monitor thread startup/shutdown state */
1905         int                             ln_mt_state;
1906         /* serialise startup/shutdown */
1907         struct semaphore                ln_mt_signal;
1908
1909         struct mutex                    ln_api_mutex;
1910         struct mutex                    ln_lnd_mutex;
1911         /* Have I called LNetNIInit myself? */
1912         int                             ln_niinit_self;
1913         /* LNetNIInit/LNetNIFini counter */
1914         int                             ln_refcount;
1915         /* SHUTDOWN/RUNNING/STOPPING */
1916         int                             ln_state;
1917
1918         int                             ln_routing;     /* am I a router? */
1919         lnet_pid_t                      ln_pid;         /* requested pid */
1920         /* uniquely identifies this ni in this epoch */
1921         __u64                           ln_interface_cookie;
1922         /* registered LNDs */
1923         const struct lnet_lnd           *ln_lnds[NUM_LNDS];
1924
1925         /* test protocol compatibility flags */
1926         unsigned long                   ln_testprotocompat;
1927
1928         /* 0 - load the NIs from the mod params
1929          * 1 - do not load the NIs from the mod params
1930          * Reverse logic to ensure that other calls to LNetNIInit
1931          * need no change
1932          */
1933         bool                            ln_nis_from_mod_params;
1934
1935         /* Switch to test large NIDs */
1936         bool                            ln_nis_use_large_nids;
1937
1938         /*
1939          * completion for the monitor thread. The monitor thread takes care of
1940          * checking routes, timedout messages and resending messages.
1941          */
1942         struct completion               ln_mt_wait_complete;
1943
1944         /* per-cpt resend queues */
1945         struct list_head                **ln_mt_resendqs;
1946         /* local NIs to recover */
1947         struct list_head                ln_mt_localNIRecovq;
1948         /* local NIs to recover */
1949         struct list_head                ln_mt_peerNIRecovq;
1950         /*
1951          * An array of queues for GET/PUT waiting for REPLY/ACK respectively.
1952          * There are CPT number of queues. Since response trackers will be
1953          * added on the fast path we can't afford to grab the exclusive
1954          * net lock to protect these queues. The CPT will be calculated
1955          * based on the mdh cookie.
1956          */
1957         struct list_head                **ln_mt_rstq;
1958         /*
1959          * A response tracker becomes a zombie when the associated MD is queued
1960          * for unlink before the response tracker is detached from the MD. An
1961          * entry on a zombie list can be freed when either the remaining
1962          * operations on the MD complete or when LNet has shut down.
1963          */
1964         struct list_head                **ln_mt_zombie_rstqs;
1965         /* recovery handler */
1966         lnet_handler_t                  ln_mt_handler;
1967
1968         /*
1969          * Completed when the discovery and monitor threads can enter their
1970          * work loops
1971          */
1972         struct completion               ln_started;
1973         /* UDSP list */
1974         struct list_head                ln_udsp_list;
1975
1976         /* Number of messages that have exceeded their message deadline */
1977         atomic_t                        ln_late_msg_count;
1978         /* Total amount of time past their deadline for all late ^ messages */
1979         atomic64_t                      ln_late_msg_nsecs;
1980
1981         /* for LNDs to signal that ping buffer needs updating */
1982         atomic_t                        ln_update_ping_buf;
1983
1984         /* workqueue for serving lnd ping buffer update requests */
1985         struct workqueue_struct         *ln_pb_update_wq;
1986         struct work_struct              ln_pb_update_work;
1987
1988         atomic_t                        ln_pb_update_ready;
1989 };
1990
1991 struct genl_filter_list {
1992         struct list_head         lp_list;
1993         void                    *lp_cursor;
1994         bool                     lp_first;
1995 };
1996
1997 static const struct nla_policy scalar_attr_policy[LN_SCALAR_MAX + 1] = {
1998         [LN_SCALAR_ATTR_LIST]           = { .type = NLA_NESTED },
1999         [LN_SCALAR_ATTR_LIST_SIZE]      = { .type = NLA_U16 },
2000         [LN_SCALAR_ATTR_INDEX]          = { .type = NLA_U16 },
2001         [LN_SCALAR_ATTR_NLA_TYPE]       = { .type = NLA_U16 },
2002         [LN_SCALAR_ATTR_VALUE]          = { .type = NLA_STRING },
2003         [LN_SCALAR_ATTR_KEY_FORMAT]     = { .type = NLA_U16 },
2004 };
2005
2006 int lnet_genl_send_scalar_list(struct sk_buff *msg, u32 portid, u32 seq,
2007                                const struct genl_family *family, int flags,
2008                                u8 cmd, const struct ln_key_list *data[]);
2009
2010 /* Special workaround for pre-4.19 kernels to send error messages
2011  * from dumpit routines. Newer kernels will send message with
2012  * NL_SET_ERR_MSG information by default if NETLINK_EXT_ACK is set.
2013  */
2014 static inline int lnet_nl_send_error(struct sk_buff *msg, int portid, int seq,
2015                                      int error)
2016 {
2017 #ifndef HAVE_NL_DUMP_WITH_EXT_ACK
2018         struct nlmsghdr *nlh;
2019
2020         if (!error)
2021                 return 0;
2022
2023         nlh = nlmsg_put(msg, portid, seq, NLMSG_ERROR, sizeof(error), 0);
2024         if (!nlh)
2025                 return -ENOMEM;
2026 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
2027         netlink_ack(msg, nlh, error, NULL);
2028 #else
2029         netlink_ack(msg, nlh, error);
2030 #endif
2031         return nlmsg_len(nlh);
2032 #else
2033         return error;
2034 #endif
2035 }
2036
2037 #endif