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, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Seagate, Inc.
32 * lnet/include/lnet/lib-types.h
35 #ifndef __LNET_LIB_TYPES_H__
36 #define __LNET_LIB_TYPES_H__
38 #include <linux/kthread.h>
39 #include <linux/uio.h>
40 #include <linux/types.h>
41 #include <linux/completion.h>
43 #include <uapi/linux/lnet/lnet-types.h>
44 #include <uapi/linux/lnet/lnetctl.h>
46 /* Max payload size */
47 #define LNET_MAX_PAYLOAD CONFIG_LNET_MAX_PAYLOAD
48 #if (LNET_MAX_PAYLOAD < LNET_MTU)
49 # error "LNET_MAX_PAYLOAD too small - error in configure --with-max-payload-mb"
50 #elif (LNET_MAX_PAYLOAD > (PAGE_SIZE * LNET_MAX_IOV))
51 # error "LNET_MAX_PAYLOAD too large - error in configure --with-max-payload-mb"
58 struct list_head msg_activelist;
59 struct list_head msg_list; /* Q for credits/MD */
61 struct lnet_process_id msg_target;
62 /* where is it from, it's only for building event */
66 /* committed for sending */
67 unsigned int msg_tx_committed:1;
68 /* CPT # this message committed for sending */
69 unsigned int msg_tx_cpt:15;
70 /* committed for receiving */
71 unsigned int msg_rx_committed:1;
72 /* CPT # this message committed for receiving */
73 unsigned int msg_rx_cpt:15;
74 /* queued for tx credit */
75 unsigned int msg_tx_delayed:1;
76 /* queued for RX buffer */
77 unsigned int msg_rx_delayed:1;
78 /* ready for pending on RX delay list */
79 unsigned int msg_rx_ready_delay:1;
81 unsigned int msg_vmflush:1; /* VM trying to free memory */
82 unsigned int msg_target_is_router:1; /* sending to a router */
83 unsigned int msg_routing:1; /* being forwarded */
84 unsigned int msg_ack:1; /* ack on finalize (PUT) */
85 unsigned int msg_sending:1; /* outgoing message */
86 unsigned int msg_receiving:1; /* being received */
87 unsigned int msg_txcredit:1; /* taken an NI send credit */
88 unsigned int msg_peertxcredit:1; /* taken a peer send credit */
89 unsigned int msg_rtrcredit:1; /* taken a global router credit */
90 unsigned int msg_peerrtrcredit:1; /* taken a peer router credit */
91 unsigned int msg_onactivelist:1; /* on the activelist */
92 unsigned int msg_rdma_get:1;
94 struct lnet_peer *msg_txpeer; /* peer I'm sending to */
95 struct lnet_peer *msg_rxpeer; /* peer I received from */
98 struct lnet_libmd *msg_md;
100 unsigned int msg_len;
101 unsigned int msg_wanted;
102 unsigned int msg_offset;
103 unsigned int msg_niov;
104 struct kvec *msg_iov;
105 struct bio_vec *msg_kiov;
107 struct lnet_event msg_ev;
108 struct lnet_hdr msg_hdr;
111 struct lnet_libhandle {
112 struct list_head lh_hash_chain;
116 #define lh_entry(ptr, type, member) \
117 ((type *)((char *)(ptr) - (char *)(&((type *)0)->member)))
120 struct list_head eq_list;
121 struct lnet_libhandle eq_lh;
122 unsigned long eq_enq_seq;
123 unsigned long eq_deq_seq;
124 unsigned int eq_size;
125 lnet_eq_handler_t eq_callback;
126 struct lnet_event *eq_events;
127 int **eq_refs; /* percpt refcount for EQ */
131 struct list_head me_list;
132 struct lnet_libhandle me_lh;
133 struct lnet_process_id me_match_id;
134 unsigned int me_portal;
135 unsigned int me_pos; /* hash offset in mt_hash */
137 __u64 me_ignore_bits;
138 enum lnet_unlink me_unlink;
139 struct lnet_libmd *me_md;
143 struct list_head md_list;
144 struct lnet_libhandle md_lh;
145 struct lnet_me *md_me;
147 unsigned int md_offset;
148 unsigned int md_length;
149 unsigned int md_max_size;
152 unsigned int md_options;
153 unsigned int md_flags;
155 struct lnet_eq *md_eq;
156 unsigned int md_niov; /* # frags */
158 struct kvec iov[LNET_MAX_IOV];
159 struct bio_vec kiov[LNET_MAX_IOV];
163 #define LNET_MD_FLAG_ZOMBIE (1 << 0)
164 #define LNET_MD_FLAG_AUTO_UNLINK (1 << 1)
165 #define LNET_MD_FLAG_ABORTED (1 << 2)
167 struct lnet_test_peer {
168 /* info about peers we are trying to fail */
169 struct list_head tp_list; /* ln_test_peers */
170 lnet_nid_t tp_nid; /* matching nid */
171 unsigned int tp_threshold; /* # failures to simulate */
174 #define LNET_COOKIE_TYPE_MD 1
175 #define LNET_COOKIE_TYPE_ME 2
176 #define LNET_COOKIE_TYPE_EQ 3
177 #define LNET_COOKIE_TYPE_BITS 2
178 #define LNET_COOKIE_MASK ((1ULL << LNET_COOKIE_TYPE_BITS) - 1ULL)
180 struct lnet_ni; /* forward ref */
183 /* fields managed by portals */
184 struct list_head lnd_list; /* stash in the LND table */
185 int lnd_refcount; /* # active instances */
187 /* fields initialised by the LND */
190 int (*lnd_startup)(struct lnet_ni *ni);
191 void (*lnd_shutdown)(struct lnet_ni *ni);
192 int (*lnd_ctl)(struct lnet_ni *ni, unsigned int cmd, void *arg);
195 * In data movement APIs below, payload buffers are described as a set
196 * of 'niov' fragments which are...
198 * in virtual memory (struct iovec *iov != NULL)
200 * in pages (kernel only: plt_kiov_t *kiov != NULL).
201 * The LND may NOT overwrite these fragment descriptors.
202 * An 'offset' and may specify a byte offset within the set of
203 * fragments to start from
207 * Start sending a preformatted message. 'private' is NULL for PUT and
208 * GET messages; otherwise this is a response to an incoming message
209 * and 'private' is the 'private' passed to lnet_parse(). Return
210 * non-zero for immediate failure, otherwise complete later with
213 int (*lnd_send)(struct lnet_ni *ni, void *private,
214 struct lnet_msg *msg);
217 * Start receiving 'mlen' bytes of payload data, skipping the following
218 * 'rlen' - 'mlen' bytes. 'private' is the 'private' passed to
219 * lnet_parse(). Return non-zero for immediate failure, otherwise
220 * complete later with lnet_finalize(). This also gives back a receive
221 * credit if the LND does flow control.
223 int (*lnd_recv)(struct lnet_ni *ni, void *private, struct lnet_msg *msg,
224 int delayed, struct iov_iter *to, unsigned int rlen);
227 * lnet_parse() has had to delay processing of this message
228 * (e.g. waiting for a forwarding buffer or send credits). Give the
229 * LND a chance to free urgently needed resources. If called, return 0
230 * for success and do NOT give back a receive credit; that has to wait
231 * until lnd_recv() gets called. On failure return < 0 and
232 * release resources; lnd_recv() will not be called.
234 int (*lnd_eager_recv)(struct lnet_ni *ni, void *private,
235 struct lnet_msg *msg, void **new_privatep);
237 /* notification of peer health */
238 void (*lnd_notify)(struct lnet_ni *ni, lnet_nid_t peer, int alive);
240 /* query of peer aliveness */
241 void (*lnd_query)(struct lnet_ni *ni, lnet_nid_t peer,
242 unsigned long *when);
244 /* accept a new connection */
245 int (*lnd_accept)(struct lnet_ni *ni, struct socket *sock);
248 struct lnet_tx_queue {
249 int tq_credits; /* # tx credits free */
250 int tq_credits_min; /* lowest it's been */
251 int tq_credits_max; /* total # tx credits */
252 struct list_head tq_delayed; /* delayed TXs */
257 struct list_head ni_list; /* chain on ln_nis */
258 struct list_head ni_cptlist; /* chain on ln_nis_cpt */
259 int ni_maxtxcredits; /* # tx credits */
260 /* # per-peer send credits */
261 int ni_peertxcredits;
262 /* # per-peer router buffer credits */
263 int ni_peerrtrcredits;
264 /* seconds to consider peer dead */
266 int ni_ncpts; /* number of CPTs */
267 __u32 *ni_cpts; /* bond NI on some CPTs */
268 lnet_nid_t ni_nid; /* interface's NID */
269 void *ni_data; /* instance-specific data */
270 struct lnet_lnd *ni_lnd; /* procedural interface */
271 struct lnet_tx_queue **ni_tx_queues; /* percpt TX queues */
272 int **ni_refs; /* percpt reference count */
273 time64_t ni_last_alive;/* when I was last alive */
274 struct lnet_ni_status *ni_status; /* my health status */
275 /* per NI LND tunables */
276 struct lnet_ioctl_config_lnd_tunables *ni_lnd_tunables;
277 /* equivalent interfaces to use */
278 char *ni_interfaces[LNET_MAX_INTERFACES];
279 /* original net namespace */
280 struct net *ni_net_ns;
283 #define LNET_PROTO_PING_MATCHBITS 0x8000000000000000LL
286 * NB: value of these features equal to LNET_PROTO_PING_VERSION_x
287 * of old LNet, so there shouldn't be any compatibility issue
289 #define LNET_PING_FEAT_INVAL (0) /* no feature */
290 #define LNET_PING_FEAT_BASE (1 << 0) /* just a ping */
291 #define LNET_PING_FEAT_NI_STATUS (1 << 1) /* return NI status */
292 #define LNET_PING_FEAT_RTE_DISABLED (1 << 2) /* Routing enabled */
294 #define LNET_PING_FEAT_MASK (LNET_PING_FEAT_BASE | \
295 LNET_PING_FEAT_NI_STATUS)
297 /* router checker data, per router */
298 #define LNET_MAX_RTR_NIS 16
299 #define LNET_PINGINFO_SIZE offsetof(struct lnet_ping_info, pi_ni[LNET_MAX_RTR_NIS])
300 struct lnet_rc_data {
301 /* chain on the_lnet.ln_zombie_rcd or ln_deathrow_rcd */
302 struct list_head rcd_list;
303 struct lnet_handle_md rcd_mdh; /* ping buffer MD */
304 struct lnet_peer *rcd_gateway; /* reference to gateway */
305 struct lnet_ping_info *rcd_pinginfo; /* ping buffer */
309 struct list_head lp_hashlist; /* chain on peer hash */
310 struct list_head lp_txq; /* messages blocking for
313 struct list_head lp_rtrq; /* messages blocking for
316 struct list_head lp_rtr_list; /* chain on router list */
317 int lp_txcredits; /* # tx credits available */
318 int lp_mintxcredits; /* low water mark */
319 int lp_rtrcredits; /* # router credits */
320 int lp_minrtrcredits; /* low water mark */
321 unsigned int lp_alive:1; /* alive/dead? */
322 unsigned int lp_notify:1; /* notification outstanding? */
323 unsigned int lp_notifylnd:1;/* outstanding notification
326 unsigned int lp_notifying:1; /* some thread is handling
329 unsigned int lp_ping_notsent;/* SEND event outstanding
332 int lp_alive_count; /* # times router went
335 long lp_txqnob; /* ytes queued for sending */
336 unsigned long lp_timestamp; /* time of last aliveness
339 unsigned long lp_ping_timestamp;/* time of last ping
342 unsigned long lp_ping_deadline; /* != 0 if ping reply
345 unsigned long lp_last_alive; /* when I was last alive */
346 unsigned long lp_last_query; /* when lp_ni was queried
349 struct lnet_ni *lp_ni; /* interface peer is on */
350 lnet_nid_t lp_nid; /* peer's NID */
351 int lp_refcount; /* # refs */
352 int lp_cpt; /* CPT this peer attached on */
353 /* # refs from lnet_route::lr_gateway */
355 /* returned RC ping features */
356 unsigned int lp_ping_feats;
357 struct list_head lp_routes; /* routers on this peer */
358 struct lnet_rc_data *lp_rcd; /* router checker state */
362 #define LNET_PEER_HASH_BITS 9
363 #define LNET_PEER_HASH_SIZE (1 << LNET_PEER_HASH_BITS)
365 /* peer hash table */
366 struct lnet_peer_table {
367 int pt_version; /* /proc validity stamp */
368 int pt_number; /* # peers extant */
369 /* # zombies to go to deathrow (and not there yet) */
371 struct list_head pt_deathrow; /* zombie peers */
372 struct list_head *pt_hash; /* NID->peer hash */
376 * peer aliveness is enabled only on routers for peers in a network where the
377 * lnet_ni::ni_peertimeout has been set to a positive value
379 #define lnet_peer_aliveness_enabled(lp) (the_lnet.ln_routing && \
380 (lp)->lp_ni->ni_peertimeout > 0)
383 struct list_head lr_list; /* chain on net */
384 struct list_head lr_gwlist; /* chain on gateway */
385 struct lnet_peer *lr_gateway; /* router node */
386 __u32 lr_net; /* remote network number */
387 int lr_seq; /* sequence for round-robin */
388 unsigned int lr_downis; /* number of down NIs */
389 __u32 lr_hops; /* how far I am */
390 unsigned int lr_priority; /* route priority */
393 #define LNET_REMOTE_NETS_HASH_DEFAULT (1U << 7)
394 #define LNET_REMOTE_NETS_HASH_MAX (1U << 16)
395 #define LNET_REMOTE_NETS_HASH_SIZE (1 << the_lnet.ln_remote_nets_hbits)
397 struct lnet_remotenet {
398 struct list_head lrn_list; /* chain on
399 * ln_remote_nets_hash
401 struct list_head lrn_routes; /* routes to me */
402 __u32 lrn_net; /* my net number */
405 /** lnet message has credit and can be submitted to lnd for send/receive */
406 #define LNET_CREDIT_OK 0
407 /** lnet message is waiting for credit */
408 #define LNET_CREDIT_WAIT 1
410 struct lnet_rtrbufpool {
411 struct list_head rbp_bufs; /* my free buffer pool */
412 struct list_head rbp_msgs; /* messages blocking
415 int rbp_npages; /* # pages in each buffer */
416 /* requested number of buffers */
417 int rbp_req_nbuffers;
418 /* # buffers actually allocated */
420 int rbp_credits; /* # free buffers
423 int rbp_mincredits; /* low water mark */
427 struct list_head rb_list; /* chain on rbp_bufs */
428 struct lnet_rtrbufpool *rb_pool; /* owning pool */
429 struct bio_vec rb_kiov[0]; /* the buffer space */
432 #define LNET_PEER_HASHSIZE 503 /* prime! */
434 #define LNET_TINY_BUF_IDX 0
435 #define LNET_SMALL_BUF_IDX 1
436 #define LNET_LARGE_BUF_IDX 2
438 /* # different router buffer pools */
439 #define LNET_NRBPOOLS (LNET_LARGE_BUF_IDX + 1)
441 enum lnet_match_flags {
442 /* Didn't match anything */
443 LNET_MATCHMD_NONE = (1 << 0),
445 LNET_MATCHMD_OK = (1 << 1),
446 /* Must be discarded */
447 LNET_MATCHMD_DROP = (1 << 2),
448 /* match and buffer is exhausted */
449 LNET_MATCHMD_EXHAUSTED = (1 << 3),
451 LNET_MATCHMD_FINISH = (LNET_MATCHMD_OK | LNET_MATCHMD_DROP),
454 /* Options for lnet_portal::ptl_options */
455 #define LNET_PTL_LAZY (1 << 0)
456 #define LNET_PTL_MATCH_UNIQUE (1 << 1) /* unique match, for RDMA */
457 #define LNET_PTL_MATCH_WILDCARD (1 << 2) /* wildcard match,
461 /* parameter for matching operations (GET, PUT) */
462 struct lnet_match_info {
464 struct lnet_process_id mi_id;
466 unsigned int mi_portal;
467 unsigned int mi_rlength;
468 unsigned int mi_roffset;
471 /* ME hash of RDMA portal */
472 #define LNET_MT_HASH_BITS 8
473 #define LNET_MT_HASH_SIZE (1 << LNET_MT_HASH_BITS)
474 #define LNET_MT_HASH_MASK (LNET_MT_HASH_SIZE - 1)
476 * we allocate (LNET_MT_HASH_SIZE + 1) entries for lnet_match_table::mt_hash,
477 * the last entry is reserved for MEs with ignore-bits
479 #define LNET_MT_HASH_IGNORE LNET_MT_HASH_SIZE
481 * __u64 has 2^6 bits, so need 2^(LNET_MT_HASH_BITS - LNET_MT_BITS_U64) which
482 * is 4 __u64s as bit-map, and add an extra __u64 (only use one bit) for the
483 * ME-list with ignore-bits, which is mtable::mt_hash[LNET_MT_HASH_IGNORE]
485 #define LNET_MT_BITS_U64 6 /* 2^6 bits */
486 #define LNET_MT_EXHAUSTED_BITS (LNET_MT_HASH_BITS - LNET_MT_BITS_U64)
487 #define LNET_MT_EXHAUSTED_BMAP ((1 << LNET_MT_EXHAUSTED_BITS) + 1)
489 /* portal match table */
490 struct lnet_match_table {
491 /* reserved for upcoming patches, CPU partition ID */
493 unsigned int mt_portal; /* portal index */
495 * match table is set as "enabled" if there's non-exhausted MD
496 * attached on mt_mhash, it's only valid for wildcard portal
498 unsigned int mt_enabled;
499 /* bitmap to flag whether MEs on mt_hash are exhausted or not */
500 __u64 mt_exhausted[LNET_MT_EXHAUSTED_BMAP];
501 struct list_head *mt_mhash; /* matching hash */
504 /* these are only useful for wildcard portal */
505 /* Turn off message rotor for wildcard portals */
506 #define LNET_PTL_ROTOR_OFF 0
507 /* round-robin dispatch all PUT messages for wildcard portals */
508 #define LNET_PTL_ROTOR_ON 1
509 /* round-robin dispatch routed PUT message for wildcard portals */
510 #define LNET_PTL_ROTOR_RR_RT 2
511 /* dispatch routed PUT message by hashing source NID for wildcard portals */
512 #define LNET_PTL_ROTOR_HASH_RT 3
516 unsigned int ptl_index; /* portal ID, reserved */
517 /* flags on this portal: lazy, unique... */
518 unsigned int ptl_options;
519 /* list of messages which are stealing buffer */
520 struct list_head ptl_msg_stealing;
521 /* messages blocking for MD */
522 struct list_head ptl_msg_delayed;
523 /* Match table for each CPT */
524 struct lnet_match_table **ptl_mtables;
525 /* spread rotor of incoming "PUT" */
526 unsigned int ptl_rotor;
527 /* # active entries for this portal */
529 /* array of active entries' cpu-partition-id */
533 #define LNET_LH_HASH_BITS 12
534 #define LNET_LH_HASH_SIZE (1ULL << LNET_LH_HASH_BITS)
535 #define LNET_LH_HASH_MASK (LNET_LH_HASH_SIZE - 1)
537 /* resource container (ME, MD, EQ) */
538 struct lnet_res_container {
539 unsigned int rec_type; /* container type */
540 __u64 rec_lh_cookie; /* cookie generator */
541 struct list_head rec_active; /* active resource list */
542 struct list_head *rec_lh_hash; /* handle hash */
545 /* message container */
546 struct lnet_msg_container {
547 int msc_init; /* initialized or not */
548 /* max # threads finalizing */
550 /* msgs waiting to complete finalizing */
551 struct list_head msc_finalizing;
552 struct list_head msc_active; /* active message list */
553 /* threads doing finalization */
554 void **msc_finalizers;
557 /* Router Checker states */
558 #define LNET_RC_STATE_SHUTDOWN 0 /* not started */
559 #define LNET_RC_STATE_RUNNING 1 /* started up OK */
560 #define LNET_RC_STATE_STOPPING 2 /* telling thread to stop */
563 /* CPU partition table of LNet */
564 struct cfs_cpt_table *ln_cpt_table;
565 /* number of CPTs in ln_cpt_table */
566 unsigned int ln_cpt_number;
567 unsigned int ln_cpt_bits;
569 /* protect LNet resources (ME/MD/EQ) */
570 struct cfs_percpt_lock *ln_res_lock;
573 /* the vector of portals */
574 struct lnet_portal **ln_portals;
575 /* percpt ME containers */
576 struct lnet_res_container **ln_me_containers;
577 /* percpt MD container */
578 struct lnet_res_container **ln_md_containers;
580 /* Event Queue container */
581 struct lnet_res_container ln_eq_container;
582 wait_queue_head_t ln_eq_waitq;
583 spinlock_t ln_eq_wait_lock;
584 unsigned int ln_remote_nets_hbits;
586 /* protect NI, peer table, credits, routers, rtrbuf... */
587 struct cfs_percpt_lock *ln_net_lock;
588 /* percpt message containers for active/finalizing/freed message */
589 struct lnet_msg_container **ln_msg_containers;
590 struct lnet_counters **ln_counters;
591 struct lnet_peer_table **ln_peer_tables;
592 /* failure simulation */
593 struct list_head ln_test_peers;
594 struct list_head ln_drop_rules;
595 struct list_head ln_delay_rules;
597 struct list_head ln_nis; /* LND instances */
598 /* NIs bond on specific CPT(s) */
599 struct list_head ln_nis_cpt;
600 /* dying LND instances */
601 struct list_head ln_nis_zombie;
602 struct lnet_ni *ln_loni; /* the loopback NI */
604 /* remote networks with routes to them */
605 struct list_head *ln_remote_nets_hash;
607 __u64 ln_remote_nets_version;
608 /* list of all known routers */
609 struct list_head ln_routers;
611 __u64 ln_routers_version;
612 /* percpt router buffer pools */
613 struct lnet_rtrbufpool **ln_rtrpools;
615 struct lnet_handle_md ln_ping_target_md;
616 struct lnet_handle_eq ln_ping_target_eq;
617 struct lnet_ping_info *ln_ping_info;
619 /* router checker startup/shutdown state */
621 /* router checker's event queue */
622 struct lnet_handle_eq ln_rc_eqh;
623 /* rcd still pending on net */
624 struct list_head ln_rcd_deathrow;
625 /* rcd ready for free */
626 struct list_head ln_rcd_zombie;
627 /* serialise startup/shutdown */
628 struct completion ln_rc_signal;
630 struct mutex ln_api_mutex;
631 struct mutex ln_lnd_mutex;
632 struct mutex ln_delay_mutex;
633 /* Have I called LNetNIInit myself? */
635 /* LNetNIInit/LNetNIFini counter */
637 /* shutdown in progress */
640 int ln_routing; /* am I a router? */
641 lnet_pid_t ln_pid; /* requested pid */
642 /* uniquely identifies this ni in this epoch */
643 __u64 ln_interface_cookie;
644 /* registered LNDs */
645 struct list_head ln_lnds;
647 /* test protocol compatibility flags */
648 int ln_testprotocompat;
651 * 0 - load the NIs from the mod params
652 * 1 - do not load the NIs from the mod params
653 * Reverse logic to ensure that other calls to LNetNIInit
656 bool ln_nis_from_mod_params;
659 * waitq for router checker. As long as there are no routes in
660 * the list, the router checker will sleep on this queue. when
661 * routes are added the thread will wake up
663 wait_queue_head_t ln_rc_waitq;