4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lnet/include/lnet/lib-types.h
34 * Types used by the library side routines that do not need to be
35 * exposed to the user application
38 #ifndef __LNET_LIB_TYPES_H__
39 #define __LNET_LIB_TYPES_H__
42 # error This include is only for kernel use.
45 #include <linux/kthread.h>
46 #include <linux/uio.h>
47 #include <linux/types.h>
49 #include <uapi/linux/lnet/lnet-dlc.h>
50 #include <uapi/linux/lnet/lnetctl.h>
52 /* Max payload size */
53 #ifndef CONFIG_LNET_MAX_PAYLOAD
54 # error "CONFIG_LNET_MAX_PAYLOAD must be defined in config.h"
57 #define LNET_MAX_PAYLOAD CONFIG_LNET_MAX_PAYLOAD
58 #if (LNET_MAX_PAYLOAD < LNET_MTU)
59 # error "LNET_MAX_PAYLOAD too small - error in configure --with-max-payload-mb"
60 #elif (LNET_MAX_PAYLOAD > (PAGE_SIZE * LNET_MAX_IOV))
61 # error "LNET_MAX_PAYLOAD too large - error in configure --with-max-payload-mb"
67 typedef struct lnet_msg {
68 struct list_head msg_activelist;
69 struct list_head msg_list; /* Q for credits/MD */
71 struct lnet_process_id msg_target;
72 /* Primary NID of the source. */
73 lnet_nid_t msg_initiator;
74 /* where is it from, it's only for building event */
79 * hold parameters in case message is with held due
82 lnet_nid_t msg_src_nid_param;
83 lnet_nid_t msg_rtr_nid_param;
85 /* committed for sending */
86 unsigned int msg_tx_committed:1;
87 /* CPT # this message committed for sending */
88 unsigned int msg_tx_cpt:15;
89 /* committed for receiving */
90 unsigned int msg_rx_committed:1;
91 /* CPT # this message committed for receiving */
92 unsigned int msg_rx_cpt:15;
93 /* queued for tx credit */
94 unsigned int msg_tx_delayed:1;
95 /* queued for RX buffer */
96 unsigned int msg_rx_delayed:1;
97 /* ready for pending on RX delay list */
98 unsigned int msg_rx_ready_delay:1;
100 unsigned int msg_vmflush:1; /* VM trying to free memory */
101 unsigned int msg_target_is_router:1; /* sending to a router */
102 unsigned int msg_routing:1; /* being forwarded */
103 unsigned int msg_ack:1; /* ack on finalize (PUT) */
104 unsigned int msg_sending:1; /* outgoing message */
105 unsigned int msg_receiving:1; /* being received */
106 unsigned int msg_txcredit:1; /* taken an NI send credit */
107 unsigned int msg_peertxcredit:1; /* taken a peer send credit */
108 unsigned int msg_rtrcredit:1; /* taken a globel router credit */
109 unsigned int msg_peerrtrcredit:1; /* taken a peer router credit */
110 unsigned int msg_onactivelist:1; /* on the activelist */
111 unsigned int msg_rdma_get:1;
113 struct lnet_peer_ni *msg_txpeer; /* peer I'm sending to */
114 struct lnet_peer_ni *msg_rxpeer; /* peer I received from */
117 struct lnet_libmd *msg_md;
118 /* the NI the message was sent or received over */
119 struct lnet_ni *msg_txni;
120 struct lnet_ni *msg_rxni;
122 unsigned int msg_len;
123 unsigned int msg_wanted;
124 unsigned int msg_offset;
125 unsigned int msg_niov;
126 struct kvec *msg_iov;
127 lnet_kiov_t *msg_kiov;
129 struct lnet_event msg_ev;
130 struct lnet_hdr msg_hdr;
133 typedef struct lnet_libhandle {
134 struct list_head lh_hash_chain;
138 #define lh_entry(ptr, type, member) \
139 ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
141 typedef struct lnet_eq {
142 struct list_head eq_list;
143 struct lnet_libhandle eq_lh;
144 unsigned long eq_enq_seq;
145 unsigned long eq_deq_seq;
146 unsigned int eq_size;
147 lnet_eq_handler_t eq_callback;
148 struct lnet_event *eq_events;
149 int **eq_refs; /* percpt refcount for EQ */
152 typedef struct lnet_me {
153 struct list_head me_list;
154 struct lnet_libhandle me_lh;
155 struct lnet_process_id me_match_id;
156 unsigned int me_portal;
157 unsigned int me_pos; /* hash offset in mt_hash */
159 __u64 me_ignore_bits;
160 enum lnet_unlink me_unlink;
161 struct lnet_libmd *me_md;
164 typedef struct lnet_libmd {
165 struct list_head md_list;
166 struct lnet_libhandle md_lh;
167 struct lnet_me *md_me;
169 unsigned int md_offset;
170 unsigned int md_length;
171 unsigned int md_max_size;
174 unsigned int md_options;
175 unsigned int md_flags;
176 unsigned int md_niov; /* # frags at end of struct */
178 struct lnet_eq *md_eq;
179 struct lnet_handle_md md_bulk_handle;
181 struct kvec iov[LNET_MAX_IOV];
182 lnet_kiov_t kiov[LNET_MAX_IOV];
186 #define LNET_MD_FLAG_ZOMBIE (1 << 0)
187 #define LNET_MD_FLAG_AUTO_UNLINK (1 << 1)
188 #define LNET_MD_FLAG_ABORTED (1 << 2)
190 typedef struct lnet_test_peer {
191 /* info about peers we are trying to fail */
192 struct list_head tp_list; /* ln_test_peers */
193 lnet_nid_t tp_nid; /* matching nid */
194 unsigned int tp_threshold; /* # failures to simulate */
197 #define LNET_COOKIE_TYPE_MD 1
198 #define LNET_COOKIE_TYPE_ME 2
199 #define LNET_COOKIE_TYPE_EQ 3
200 #define LNET_COOKIE_TYPE_BITS 2
201 #define LNET_COOKIE_MASK ((1ULL << LNET_COOKIE_TYPE_BITS) - 1ULL)
203 struct lnet_ni; /* forward ref */
206 typedef struct lnet_lnd {
207 /* fields managed by portals */
208 struct list_head lnd_list; /* stash in the LND table */
209 int lnd_refcount; /* # active instances */
211 /* fields initialized by the LND */
214 int (*lnd_startup)(struct lnet_ni *ni);
215 void (*lnd_shutdown)(struct lnet_ni *ni);
216 int (*lnd_ctl)(struct lnet_ni *ni, unsigned int cmd, void *arg);
218 /* In data movement APIs below, payload buffers are described as a set
219 * of 'niov' fragments which are...
221 * in virtual memory (struct kvec *iov != NULL)
223 * in pages (kernel only: plt_kiov_t *kiov != NULL).
224 * The LND may NOT overwrite these fragment descriptors.
225 * An 'offset' and may specify a byte offset within the set of
226 * fragments to start from
229 /* Start sending a preformatted message. 'private' is NULL for PUT and
230 * GET messages; otherwise this is a response to an incoming message
231 * and 'private' is the 'private' passed to lnet_parse(). Return
232 * non-zero for immediate failure, otherwise complete later with
234 int (*lnd_send)(struct lnet_ni *ni, void *private,
235 struct lnet_msg *msg);
237 /* Start receiving 'mlen' bytes of payload data, skipping the following
238 * 'rlen' - 'mlen' bytes. 'private' is the 'private' passed to
239 * lnet_parse(). Return non-zero for immedaite failure, otherwise
240 * complete later with lnet_finalize(). This also gives back a receive
241 * credit if the LND does flow control. */
242 int (*lnd_recv)(struct lnet_ni *ni, void *private, struct lnet_msg *msg,
243 int delayed, unsigned int niov,
244 struct kvec *iov, lnet_kiov_t *kiov,
245 unsigned int offset, unsigned int mlen, unsigned int rlen);
247 /* lnet_parse() has had to delay processing of this message
248 * (e.g. waiting for a forwarding buffer or send credits). Give the
249 * LND a chance to free urgently needed resources. If called, return 0
250 * for success and do NOT give back a receive credit; that has to wait
251 * until lnd_recv() gets called. On failure return < 0 and
252 * release resources; lnd_recv() will not be called. */
253 int (*lnd_eager_recv)(struct lnet_ni *ni, void *private,
254 struct lnet_msg *msg, void **new_privatep);
256 /* notification of peer health */
257 void (*lnd_notify)(struct lnet_ni *ni, lnet_nid_t peer, int alive);
259 /* query of peer aliveness */
260 void (*lnd_query)(struct lnet_ni *ni, lnet_nid_t peer, cfs_time_t *when);
262 /* accept a new connection */
263 int (*lnd_accept)(struct lnet_ni *ni, struct socket *sock);
266 struct lnet_tx_queue {
267 int tq_credits; /* # tx credits free */
268 int tq_credits_min; /* lowest it's been */
269 int tq_credits_max; /* total # tx credits */
270 struct list_head tq_delayed; /* delayed TXs */
273 enum lnet_net_state {
274 /* set when net block is allocated */
275 LNET_NET_STATE_INIT = 0,
276 /* set when NIs in net are started successfully */
277 LNET_NET_STATE_ACTIVE,
278 /* set if all NIs in net are in FAILED state */
279 LNET_NET_STATE_INACTIVE,
280 /* set when shutting down a NET */
281 LNET_NET_STATE_DELETING
285 /* set when NI block is allocated */
286 LNET_NI_STATE_INIT = 0,
287 /* set when NI is started successfully */
288 LNET_NI_STATE_ACTIVE,
289 /* set when LND notifies NI failed */
290 LNET_NI_STATE_FAILED,
291 /* set when LND notifies NI degraded */
292 LNET_NI_STATE_DEGRADED,
293 /* set when shuttding down NI */
294 LNET_NI_STATE_DELETING
297 struct lnet_element_stats {
304 /* chain on the ln_nets */
305 struct list_head net_list;
307 /* net ID, which is composed of
308 * (net_type << 16) | net_num.
309 * net_type can be one of the enumerated types defined in
310 * lnet/include/lnet/nidstr.h */
313 /* priority of the network */
316 /* total number of CPTs in the array */
319 /* cumulative CPTs of all NIs in this net */
322 /* network tunables */
323 struct lnet_ioctl_config_lnd_cmn_tunables net_tunables;
326 * boolean to indicate that the tunables have been set and
329 bool net_tunables_set;
331 /* procedural interface */
332 struct lnet_lnd *net_lnd;
334 /* list of NIs on this net */
335 struct list_head net_ni_list;
337 /* list of NIs being added, but not started yet */
338 struct list_head net_ni_added;
340 /* dying LND instances */
341 struct list_head net_ni_zombie;
344 enum lnet_net_state net_state;
347 typedef struct lnet_ni {
348 /* chain on the lnet_net structure */
349 struct list_head ni_netlist;
351 /* chain on net_ni_cpt */
352 struct list_head ni_cptlist;
359 /* bond NI on some CPTs */
362 /* interface's NID */
365 /* instance-specific data */
369 atomic_t ni_tx_credits;
371 /* percpt TX queues */
372 struct lnet_tx_queue **ni_tx_queues;
374 /* percpt reference count */
377 /* when I was last alive */
380 /* pointer to parent network */
381 struct lnet_net *ni_net;
383 /* my health status */
384 struct lnet_ni_status *ni_status;
387 enum lnet_ni_state ni_state;
389 /* per NI LND tunables */
390 struct lnet_lnd_tunables ni_lnd_tunables;
392 /* lnd tunables set explicitly */
393 bool ni_lnd_tunables_set;
396 struct lnet_element_stats ni_stats;
398 /* physical device CPT */
401 /* sequence number used to round robin over nis within a net */
405 * equivalent interfaces to use
406 * This is an array because socklnd bonding can still be configured
408 char *ni_interfaces[LNET_INTERFACES_NUM];
409 struct net *ni_net_ns; /* original net namespace */
412 #define LNET_PROTO_PING_MATCHBITS 0x8000000000000000LL
415 * Descriptor of a ping info buffer: keep a separate indicator of the
416 * size and a reference count. The type is used both as a source and
417 * sink of data, so we need to keep some information outside of the
418 * area that may be overwritten by network data.
420 struct lnet_ping_buffer {
423 struct lnet_ping_info pb_info;
426 #define LNET_PING_BUFFER_SIZE(NNIDS) \
427 offsetof(struct lnet_ping_buffer, pb_info.pi_ni[NNIDS])
428 #define LNET_PING_BUFFER_LONI(PBUF) ((PBUF)->pb_info.pi_ni[0].ns_nid)
429 #define LNET_PING_BUFFER_SEQNO(PBUF) ((PBUF)->pb_info.pi_ni[0].ns_status)
431 #define LNET_PING_INFO_TO_BUFFER(PINFO) \
432 container_of((PINFO), struct lnet_ping_buffer, pb_info)
434 /* router checker data, per router */
435 typedef struct lnet_rc_data {
436 /* chain on the_lnet.ln_zombie_rcd or ln_deathrow_rcd */
437 struct list_head rcd_list;
438 struct lnet_handle_md rcd_mdh; /* ping buffer MD */
439 struct lnet_peer_ni *rcd_gateway; /* reference to gateway */
440 struct lnet_ping_buffer *rcd_pingbuffer;/* ping buffer */
441 int rcd_nnis; /* desired size of buffer */
444 struct lnet_peer_ni {
445 /* chain on lpn_peer_nis */
446 struct list_head lpni_peer_nis;
447 /* chain on remote peer list */
448 struct list_head lpni_on_remote_peer_ni_list;
449 /* chain on peer hash */
450 struct list_head lpni_hashlist;
451 /* messages blocking for tx credits */
452 struct list_head lpni_txq;
453 /* messages blocking for router credits */
454 struct list_head lpni_rtrq;
455 /* chain on router list */
456 struct list_head lpni_rtr_list;
457 /* pointer to peer net I'm part of */
458 struct lnet_peer_net *lpni_peer_net;
459 /* statistics kept on each peer NI */
460 struct lnet_element_stats lpni_stats;
461 /* spin lock protecting credits and lpni_txq / lpni_rtrq */
462 spinlock_t lpni_lock;
463 /* # tx credits available */
466 int lpni_mintxcredits;
467 /* # router credits */
470 int lpni_minrtrcredits;
471 /* bytes queued for sending */
475 /* notification outstanding? */
477 /* outstanding notification for LND? */
479 /* some thread is handling notification */
481 /* SEND event outstanding from ping */
482 bool lpni_ping_notsent;
483 /* # times router went dead<->alive. Protected with lpni_lock */
484 int lpni_alive_count;
485 /* time of last aliveness news */
486 cfs_time_t lpni_timestamp;
487 /* time of last ping attempt */
488 cfs_time_t lpni_ping_timestamp;
489 /* != 0 if ping reply expected */
490 cfs_time_t lpni_ping_deadline;
491 /* when I was last alive */
492 cfs_time_t lpni_last_alive;
493 /* when lpni_ni was queried last time */
494 cfs_time_t lpni_last_query;
495 /* network peer is on */
496 struct lnet_net *lpni_net;
500 atomic_t lpni_refcount;
501 /* CPT this peer attached on */
503 /* state flags -- protected by lpni_lock */
505 /* # refs from lnet_route_t::lr_gateway */
506 int lpni_rtr_refcount;
507 /* sequence number used to round robin over peer nis within a net */
509 /* sequence number used to round robin over gateways */
513 /* returned RC ping features. Protected with lpni_lock */
514 unsigned int lpni_ping_feats;
515 /* routes on this peer */
516 struct list_head lpni_routes;
517 /* preferred local nids: if only one, use lpni_pref.nid */
522 /* number of preferred NIDs in lnpi_pref_nids */
523 __u32 lpni_pref_nnids;
524 /* router checker state */
525 struct lnet_rc_data *lpni_rcd;
528 /* Preferred path added due to traffic on non-MR peer_ni */
529 #define LNET_PEER_NI_NON_MR_PREF (1 << 0)
532 /* chain on pt_peer_list */
533 struct list_head lp_peer_list;
535 /* list of peer nets */
536 struct list_head lp_peer_nets;
538 /* list of messages pending discovery*/
539 struct list_head lp_dc_pendq;
541 /* primary NID of the peer */
542 lnet_nid_t lp_primary_nid;
544 /* CPT of peer_table */
547 /* number of NIDs on this peer */
550 /* reference count */
551 atomic_t lp_refcount;
553 /* lock protecting peer state flags */
556 /* peer state flags */
559 /* buffer for data pushed by peer */
560 struct lnet_ping_buffer *lp_data;
562 /* MD handle for ping in progress */
563 lnet_handle_md_t lp_ping_mdh;
565 /* MD handle for push in progress */
566 lnet_handle_md_t lp_push_mdh;
568 /* number of NIDs for sizing push data */
571 /* NI config sequence number of peer */
574 /* Local NI config sequence number acked by peer */
577 /* Local NI config sequence number sent to peer */
578 __u32 lp_node_seqno_sent;
580 /* Ping error encountered during discovery. */
583 /* Push error encountered during discovery. */
586 /* Error encountered during discovery. */
589 /* time it was put on the ln_dc_working queue */
590 time64_t lp_last_queued;
592 /* link on discovery-related lists */
593 struct list_head lp_dc_list;
595 /* tasks waiting on discovery of this peer */
596 wait_queue_head_t lp_dc_waitq;
600 * The status flags in lp_state. Their semantics have chosen so that
601 * lp_state can be zero-initialized.
603 * A peer is marked MULTI_RAIL in two cases: it was configured using DLC
604 * as multi-rail aware, or the LNET_PING_FEAT_MULTI_RAIL bit was set.
606 * A peer is marked NO_DISCOVERY if the LNET_PING_FEAT_DISCOVERY bit was
607 * NOT set when the peer was pinged by discovery.
609 #define LNET_PEER_MULTI_RAIL (1 << 0) /* Multi-rail aware */
610 #define LNET_PEER_NO_DISCOVERY (1 << 1) /* Peer disabled discovery */
612 * A peer is marked CONFIGURED if it was configured by DLC.
614 * In addition, a peer is marked DISCOVERED if it has fully passed
615 * through Peer Discovery.
617 * When Peer Discovery is disabled, the discovery thread will mark
618 * peers REDISCOVER to indicate that they should be re-examined if
619 * discovery is (re)enabled on the node.
621 * A peer that was created as the result of inbound traffic will not
624 #define LNET_PEER_CONFIGURED (1 << 2) /* Configured via DLC */
625 #define LNET_PEER_DISCOVERED (1 << 3) /* Peer was discovered */
626 #define LNET_PEER_REDISCOVER (1 << 4) /* Discovery was disabled */
628 * A peer is marked DISCOVERING when discovery is in progress.
629 * The other flags below correspond to stages of discovery.
631 #define LNET_PEER_DISCOVERING (1 << 5) /* Discovering */
632 #define LNET_PEER_DATA_PRESENT (1 << 6) /* Remote peer data present */
633 #define LNET_PEER_NIDS_UPTODATE (1 << 7) /* Remote peer info uptodate */
634 #define LNET_PEER_PING_SENT (1 << 8) /* Waiting for REPLY to Ping */
635 #define LNET_PEER_PUSH_SENT (1 << 9) /* Waiting for ACK of Push */
636 #define LNET_PEER_PING_FAILED (1 << 10) /* Ping send failure */
637 #define LNET_PEER_PUSH_FAILED (1 << 11) /* Push send failure */
639 * A ping can be forced as a way to fix up state, or as a manual
640 * intervention by an admin.
641 * A push can be forced in circumstances that would normally not
642 * allow for one to happen.
644 #define LNET_PEER_FORCE_PING (1 << 12) /* Forced Ping */
645 #define LNET_PEER_FORCE_PUSH (1 << 13) /* Forced Push */
647 struct lnet_peer_net {
648 /* chain on lp_peer_nets */
649 struct list_head lpn_peer_nets;
651 /* list of peer_nis on this network */
652 struct list_head lpn_peer_nis;
654 /* pointer to the peer I'm part of */
655 struct lnet_peer *lpn_peer;
660 /* reference count */
661 atomic_t lpn_refcount;
665 #define LNET_PEER_HASH_BITS 9
666 #define LNET_PEER_HASH_SIZE (1 << LNET_PEER_HASH_BITS)
669 * peer hash table - one per CPT
671 * protected by lnet_net_lock/EX for update
677 * protected by pt_zombie_lock:
681 * pt_zombie lock nests inside lnet_net_lock
683 struct lnet_peer_table {
684 int pt_version; /* /proc validity stamp */
685 int pt_number; /* # peers_ni extant */
686 struct list_head *pt_hash; /* NID->peer hash */
687 struct list_head pt_peer_list; /* peers */
688 int pt_peers; /* # peers */
689 struct list_head pt_zombie_list; /* zombie peer_ni */
690 int pt_zombies; /* # zombie peers_ni */
691 spinlock_t pt_zombie_lock; /* protect list and count */
694 /* peer aliveness is enabled only on routers for peers in a network where the
695 * struct lnet_ni::ni_peertimeout has been set to a positive value
697 #define lnet_peer_aliveness_enabled(lp) (the_lnet.ln_routing != 0 && \
698 ((lp)->lpni_net) && \
699 (lp)->lpni_net->net_tunables.lct_peer_timeout > 0)
701 typedef struct lnet_route {
702 struct list_head lr_list; /* chain on net */
703 struct list_head lr_gwlist; /* chain on gateway */
704 struct lnet_peer_ni *lr_gateway; /* router node */
705 __u32 lr_net; /* remote network number */
706 int lr_seq; /* sequence for round-robin */
707 unsigned int lr_downis; /* number of down NIs */
708 __u32 lr_hops; /* how far I am */
709 unsigned int lr_priority; /* route priority */
712 #define LNET_REMOTE_NETS_HASH_DEFAULT (1U << 7)
713 #define LNET_REMOTE_NETS_HASH_MAX (1U << 16)
714 #define LNET_REMOTE_NETS_HASH_SIZE (1 << the_lnet.ln_remote_nets_hbits)
716 typedef struct lnet_remotenet {
717 /* chain on ln_remote_nets_hash */
718 struct list_head lrn_list;
720 struct list_head lrn_routes;
725 /** lnet message has credit and can be submitted to lnd for send/receive */
726 #define LNET_CREDIT_OK 0
727 /** lnet message is waiting for credit */
728 #define LNET_CREDIT_WAIT 1
729 /** lnet message is waiting for discovery */
730 #define LNET_DC_WAIT 2
732 typedef struct lnet_rtrbufpool {
733 /* my free buffer pool */
734 struct list_head rbp_bufs;
735 /* messages blocking for a buffer */
736 struct list_head rbp_msgs;
737 /* # pages in each buffer */
739 /* requested number of buffers */
740 int rbp_req_nbuffers;
741 /* # buffers actually allocated */
743 /* # free buffers / blocked messages */
749 typedef struct lnet_rtrbuf {
750 struct list_head rb_list; /* chain on rbp_bufs */
751 struct lnet_rtrbufpool *rb_pool; /* owning pool */
752 lnet_kiov_t rb_kiov[0]; /* the buffer space */
755 #define LNET_PEER_HASHSIZE 503 /* prime! */
757 enum lnet_match_flags {
758 /* Didn't match anything */
759 LNET_MATCHMD_NONE = (1 << 0),
761 LNET_MATCHMD_OK = (1 << 1),
762 /* Must be discarded */
763 LNET_MATCHMD_DROP = (1 << 2),
764 /* match and buffer is exhausted */
765 LNET_MATCHMD_EXHAUSTED = (1 << 3),
767 LNET_MATCHMD_FINISH = (LNET_MATCHMD_OK | LNET_MATCHMD_DROP),
770 /* Options for struct lnet_portal::ptl_options */
771 #define LNET_PTL_LAZY (1 << 0)
772 #define LNET_PTL_MATCH_UNIQUE (1 << 1) /* unique match, for RDMA */
773 #define LNET_PTL_MATCH_WILDCARD (1 << 2) /* wildcard match, request portal */
775 /* parameter for matching operations (GET, PUT) */
776 struct lnet_match_info {
778 struct lnet_process_id mi_id;
781 unsigned int mi_portal;
782 unsigned int mi_rlength;
783 unsigned int mi_roffset;
786 /* ME hash of RDMA portal */
787 #define LNET_MT_HASH_BITS 8
788 #define LNET_MT_HASH_SIZE (1 << LNET_MT_HASH_BITS)
789 #define LNET_MT_HASH_MASK (LNET_MT_HASH_SIZE - 1)
790 /* we allocate (LNET_MT_HASH_SIZE + 1) entries for lnet_match_table::mt_hash,
791 * the last entry is reserved for MEs with ignore-bits */
792 #define LNET_MT_HASH_IGNORE LNET_MT_HASH_SIZE
793 /* __u64 has 2^6 bits, so need 2^(LNET_MT_HASH_BITS - LNET_MT_BITS_U64) which
794 * is 4 __u64s as bit-map, and add an extra __u64 (only use one bit) for the
795 * ME-list with ignore-bits, which is mtable::mt_hash[LNET_MT_HASH_IGNORE] */
796 #define LNET_MT_BITS_U64 6 /* 2^6 bits */
797 #define LNET_MT_EXHAUSTED_BITS (LNET_MT_HASH_BITS - LNET_MT_BITS_U64)
798 #define LNET_MT_EXHAUSTED_BMAP ((1 << LNET_MT_EXHAUSTED_BITS) + 1)
800 /* portal match table */
801 struct lnet_match_table {
802 /* reserved for upcoming patches, CPU partition ID */
804 unsigned int mt_portal; /* portal index */
805 /* match table is set as "enabled" if there's non-exhausted MD
806 * attached on mt_mhash, it's only valid for wildcard portal */
807 unsigned int mt_enabled;
808 /* bitmap to flag whether MEs on mt_hash are exhausted or not */
809 __u64 mt_exhausted[LNET_MT_EXHAUSTED_BMAP];
810 struct list_head *mt_mhash; /* matching hash */
813 /* these are only useful for wildcard portal */
814 /* Turn off message rotor for wildcard portals */
815 #define LNET_PTL_ROTOR_OFF 0
816 /* round-robin dispatch all PUT messages for wildcard portals */
817 #define LNET_PTL_ROTOR_ON 1
818 /* round-robin dispatch routed PUT message for wildcard portals */
819 #define LNET_PTL_ROTOR_RR_RT 2
820 /* dispatch routed PUT message by hashing source NID for wildcard portals */
821 #define LNET_PTL_ROTOR_HASH_RT 3
823 typedef struct lnet_portal {
825 unsigned int ptl_index; /* portal ID, reserved */
826 /* flags on this portal: lazy, unique... */
827 unsigned int ptl_options;
828 /* list of messages which are stealing buffer */
829 struct list_head ptl_msg_stealing;
830 /* messages blocking for MD */
831 struct list_head ptl_msg_delayed;
832 /* Match table for each CPT */
833 struct lnet_match_table **ptl_mtables;
834 /* spread rotor of incoming "PUT" */
835 unsigned int ptl_rotor;
836 /* # active entries for this portal */
838 /* array of active entries' cpu-partition-id */
842 #define LNET_LH_HASH_BITS 12
843 #define LNET_LH_HASH_SIZE (1ULL << LNET_LH_HASH_BITS)
844 #define LNET_LH_HASH_MASK (LNET_LH_HASH_SIZE - 1)
846 /* resource container (ME, MD, EQ) */
847 struct lnet_res_container {
848 unsigned int rec_type; /* container type */
849 __u64 rec_lh_cookie; /* cookie generator */
850 struct list_head rec_active; /* active resource list */
851 struct list_head *rec_lh_hash; /* handle hash */
854 /* message container */
855 struct lnet_msg_container {
856 int msc_init; /* initialized or not */
857 /* max # threads finalizing */
859 /* msgs waiting to complete finalizing */
860 struct list_head msc_finalizing;
861 struct list_head msc_active; /* active message list */
862 /* threads doing finalization */
863 void **msc_finalizers;
866 /* Peer Discovery states */
867 #define LNET_DC_STATE_SHUTDOWN 0 /* not started */
868 #define LNET_DC_STATE_RUNNING 1 /* started up OK */
869 #define LNET_DC_STATE_STOPPING 2 /* telling thread to stop */
871 /* Router Checker states */
872 #define LNET_RC_STATE_SHUTDOWN 0 /* not started */
873 #define LNET_RC_STATE_RUNNING 1 /* started up OK */
874 #define LNET_RC_STATE_STOPPING 2 /* telling thread to stop */
877 #define LNET_STATE_SHUTDOWN 0 /* not started */
878 #define LNET_STATE_RUNNING 1 /* started up OK */
879 #define LNET_STATE_STOPPING 2 /* telling thread to stop */
881 typedef struct lnet {
882 /* CPU partition table of LNet */
883 struct cfs_cpt_table *ln_cpt_table;
884 /* number of CPTs in ln_cpt_table */
885 unsigned int ln_cpt_number;
886 unsigned int ln_cpt_bits;
888 /* protect LNet resources (ME/MD/EQ) */
889 struct cfs_percpt_lock *ln_res_lock;
892 /* the vector of portals */
893 struct lnet_portal **ln_portals;
894 /* percpt ME containers */
895 struct lnet_res_container **ln_me_containers;
896 /* percpt MD container */
897 struct lnet_res_container **ln_md_containers;
899 /* Event Queue container */
900 struct lnet_res_container ln_eq_container;
901 wait_queue_head_t ln_eq_waitq;
902 spinlock_t ln_eq_wait_lock;
904 unsigned int ln_remote_nets_hbits;
906 /* protect NI, peer table, credits, routers, rtrbuf... */
907 struct cfs_percpt_lock *ln_net_lock;
908 /* percpt message containers for active/finalizing/freed message */
909 struct lnet_msg_container **ln_msg_containers;
910 struct lnet_counters **ln_counters;
911 struct lnet_peer_table **ln_peer_tables;
912 /* list of peer nis not on a local network */
913 struct list_head ln_remote_peer_ni_list;
914 /* failure simulation */
915 struct list_head ln_test_peers;
916 struct list_head ln_drop_rules;
917 struct list_head ln_delay_rules;
919 struct list_head ln_nets;
920 /* the loopback NI */
921 struct lnet_ni *ln_loni;
922 /* network zombie list */
923 struct list_head ln_net_zombie;
925 /* remote networks with routes to them */
926 struct list_head *ln_remote_nets_hash;
928 __u64 ln_remote_nets_version;
929 /* list of all known routers */
930 struct list_head ln_routers;
932 __u64 ln_routers_version;
933 /* percpt router buffer pools */
934 struct lnet_rtrbufpool **ln_rtrpools;
937 * Ping target / Push source
939 * The ping target and push source share a single buffer. The
940 * ln_ping_target is protected against concurrent updates by
943 struct lnet_handle_md ln_ping_target_md;
944 struct lnet_handle_eq ln_ping_target_eq;
945 struct lnet_ping_buffer *ln_ping_target;
946 atomic_t ln_ping_target_seqno;
951 * ln_push_nnis contains the desired size of the push target.
952 * The lnet_net_lock is used to handle update races. The old
953 * buffer may linger a while after it has been unlinked, in
954 * which case the event handler cleans up.
956 lnet_handle_eq_t ln_push_target_eq;
957 lnet_handle_md_t ln_push_target_md;
958 struct lnet_ping_buffer *ln_push_target;
959 int ln_push_target_nnis;
961 /* discovery event queue handle */
962 lnet_handle_eq_t ln_dc_eqh;
963 /* discovery requests */
964 struct list_head ln_dc_request;
965 /* discovery working list */
966 struct list_head ln_dc_working;
967 /* discovery expired list */
968 struct list_head ln_dc_expired;
969 /* discovery thread wait queue */
970 wait_queue_head_t ln_dc_waitq;
971 /* discovery startup/shutdown state */
974 /* router checker startup/shutdown state */
976 /* router checker's event queue */
977 struct lnet_handle_eq ln_rc_eqh;
978 /* rcd still pending on net */
979 struct list_head ln_rcd_deathrow;
980 /* rcd ready for free */
981 struct list_head ln_rcd_zombie;
982 /* serialise startup/shutdown */
983 struct semaphore ln_rc_signal;
985 struct mutex ln_api_mutex;
986 struct mutex ln_lnd_mutex;
987 /* Have I called LNetNIInit myself? */
989 /* LNetNIInit/LNetNIFini counter */
991 /* SHUTDOWN/RUNNING/STOPPING */
994 int ln_routing; /* am I a router? */
995 lnet_pid_t ln_pid; /* requested pid */
996 /* uniquely identifies this ni in this epoch */
997 __u64 ln_interface_cookie;
998 /* registered LNDs */
999 struct list_head ln_lnds;
1001 /* test protocol compatibility flags */
1002 int ln_testprotocompat;
1004 /* 0 - load the NIs from the mod params
1005 * 1 - do not load the NIs from the mod params
1006 * Reverse logic to ensure that other calls to LNetNIInit
1009 bool ln_nis_from_mod_params;
1011 /* waitq for router checker. As long as there are no routes in
1012 * the list, the router checker will sleep on this queue. when
1013 * routes are added the thread will wake up */
1014 wait_queue_head_t ln_rc_waitq;