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 <lnet/lnetctl.h>
51 /* Max payload size */
52 #ifndef CONFIG_LNET_MAX_PAYLOAD
53 # error "CONFIG_LNET_MAX_PAYLOAD must be defined in config.h"
56 #define LNET_MAX_PAYLOAD CONFIG_LNET_MAX_PAYLOAD
57 #if (LNET_MAX_PAYLOAD < LNET_MTU)
58 # error "LNET_MAX_PAYLOAD too small - error in configure --with-max-payload-mb"
59 #elif (LNET_MAX_PAYLOAD > (PAGE_SIZE * LNET_MAX_IOV))
60 # error "LNET_MAX_PAYLOAD too large - error in configure --with-max-payload-mb"
66 typedef struct lnet_msg {
67 struct list_head msg_activelist;
68 struct list_head msg_list; /* Q for credits/MD */
70 lnet_process_id_t msg_target;
71 /* where is it from, it's only for building event */
75 /* committed for sending */
76 unsigned int msg_tx_committed:1;
77 /* CPT # this message committed for sending */
78 unsigned int msg_tx_cpt:15;
79 /* committed for receiving */
80 unsigned int msg_rx_committed:1;
81 /* CPT # this message committed for receiving */
82 unsigned int msg_rx_cpt:15;
83 /* queued for tx credit */
84 unsigned int msg_tx_delayed:1;
85 /* queued for RX buffer */
86 unsigned int msg_rx_delayed:1;
87 /* ready for pending on RX delay list */
88 unsigned int msg_rx_ready_delay:1;
90 unsigned int msg_vmflush:1; /* VM trying to free memory */
91 unsigned int msg_target_is_router:1; /* sending to a router */
92 unsigned int msg_routing:1; /* being forwarded */
93 unsigned int msg_ack:1; /* ack on finalize (PUT) */
94 unsigned int msg_sending:1; /* outgoing message */
95 unsigned int msg_receiving:1; /* being received */
96 unsigned int msg_txcredit:1; /* taken an NI send credit */
97 unsigned int msg_peertxcredit:1; /* taken a peer send credit */
98 unsigned int msg_rtrcredit:1; /* taken a globel router credit */
99 unsigned int msg_peerrtrcredit:1; /* taken a peer router credit */
100 unsigned int msg_onactivelist:1; /* on the activelist */
101 unsigned int msg_rdma_get:1;
103 struct lnet_peer *msg_txpeer; /* peer I'm sending to */
104 struct lnet_peer *msg_rxpeer; /* peer I received from */
107 struct lnet_libmd *msg_md;
109 unsigned int msg_len;
110 unsigned int msg_wanted;
111 unsigned int msg_offset;
112 unsigned int msg_niov;
113 struct kvec *msg_iov;
114 lnet_kiov_t *msg_kiov;
121 typedef struct lnet_libhandle {
122 struct list_head lh_hash_chain;
126 #define lh_entry(ptr, type, member) \
127 ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
129 typedef struct lnet_eq {
130 struct list_head eq_list;
131 lnet_libhandle_t eq_lh;
132 lnet_seq_t eq_enq_seq;
133 lnet_seq_t eq_deq_seq;
134 unsigned int eq_size;
135 lnet_eq_handler_t eq_callback;
136 lnet_event_t *eq_events;
137 int **eq_refs; /* percpt refcount for EQ */
140 typedef struct lnet_me {
141 struct list_head me_list;
142 lnet_libhandle_t me_lh;
143 lnet_process_id_t me_match_id;
144 unsigned int me_portal;
145 unsigned int me_pos; /* hash offset in mt_hash */
147 __u64 me_ignore_bits;
148 lnet_unlink_t me_unlink;
149 struct lnet_libmd *me_md;
152 typedef struct lnet_libmd {
153 struct list_head md_list;
154 lnet_libhandle_t md_lh;
157 unsigned int md_offset;
158 unsigned int md_length;
159 unsigned int md_max_size;
162 unsigned int md_options;
163 unsigned int md_flags;
164 unsigned int md_niov; /* # frags at end of struct */
168 struct kvec iov[LNET_MAX_IOV];
169 lnet_kiov_t kiov[LNET_MAX_IOV];
173 #define LNET_MD_FLAG_ZOMBIE (1 << 0)
174 #define LNET_MD_FLAG_AUTO_UNLINK (1 << 1)
175 #define LNET_MD_FLAG_ABORTED (1 << 2)
178 /* info about peers we are trying to fail */
179 struct list_head tp_list; /* ln_test_peers */
180 lnet_nid_t tp_nid; /* matching nid */
181 unsigned int tp_threshold; /* # failures to simulate */
184 #define LNET_COOKIE_TYPE_MD 1
185 #define LNET_COOKIE_TYPE_ME 2
186 #define LNET_COOKIE_TYPE_EQ 3
187 #define LNET_COOKIE_TYPE_BITS 2
188 #define LNET_COOKIE_MASK ((1ULL << LNET_COOKIE_TYPE_BITS) - 1ULL)
190 struct lnet_ni; /* forward ref */
193 typedef struct lnet_lnd
195 /* fields managed by portals */
196 struct list_head lnd_list; /* stash in the LND table */
197 int lnd_refcount; /* # active instances */
199 /* fields initialized by the LND */
202 int (*lnd_startup)(struct lnet_ni *ni);
203 void (*lnd_shutdown)(struct lnet_ni *ni);
204 int (*lnd_ctl)(struct lnet_ni *ni, unsigned int cmd, void *arg);
206 /* In data movement APIs below, payload buffers are described as a set
207 * of 'niov' fragments which are...
209 * in virtual memory (struct kvec *iov != NULL)
211 * in pages (kernel only: plt_kiov_t *kiov != NULL).
212 * The LND may NOT overwrite these fragment descriptors.
213 * An 'offset' and may specify a byte offset within the set of
214 * fragments to start from
217 /* Start sending a preformatted message. 'private' is NULL for PUT and
218 * GET messages; otherwise this is a response to an incoming message
219 * and 'private' is the 'private' passed to lnet_parse(). Return
220 * non-zero for immediate failure, otherwise complete later with
222 int (*lnd_send)(struct lnet_ni *ni, void *private, lnet_msg_t *msg);
224 /* Start receiving 'mlen' bytes of payload data, skipping the following
225 * 'rlen' - 'mlen' bytes. 'private' is the 'private' passed to
226 * lnet_parse(). Return non-zero for immedaite failure, otherwise
227 * complete later with lnet_finalize(). This also gives back a receive
228 * credit if the LND does flow control. */
229 int (*lnd_recv)(struct lnet_ni *ni, void *private, lnet_msg_t *msg,
230 int delayed, unsigned int niov,
231 struct kvec *iov, lnet_kiov_t *kiov,
232 unsigned int offset, unsigned int mlen, unsigned int rlen);
234 /* lnet_parse() has had to delay processing of this message
235 * (e.g. waiting for a forwarding buffer or send credits). Give the
236 * LND a chance to free urgently needed resources. If called, return 0
237 * for success and do NOT give back a receive credit; that has to wait
238 * until lnd_recv() gets called. On failure return < 0 and
239 * release resources; lnd_recv() will not be called. */
240 int (*lnd_eager_recv)(struct lnet_ni *ni, void *private, lnet_msg_t *msg,
241 void **new_privatep);
243 /* notification of peer health */
244 void (*lnd_notify)(struct lnet_ni *ni, lnet_nid_t peer, int alive);
246 /* query of peer aliveness */
247 void (*lnd_query)(struct lnet_ni *ni, lnet_nid_t peer, cfs_time_t *when);
249 /* accept a new connection */
250 int (*lnd_accept)(struct lnet_ni *ni, struct socket *sock);
253 typedef struct lnet_ni_status {
257 } WIRE_ATTR lnet_ni_status_t;
259 struct lnet_tx_queue {
260 int tq_credits; /* # tx credits free */
261 int tq_credits_min; /* lowest it's been */
262 int tq_credits_max; /* total # tx credits */
263 struct list_head tq_delayed; /* delayed TXs */
266 typedef struct lnet_ni {
268 struct list_head ni_list; /* chain on ln_nis */
269 struct list_head ni_cptlist; /* chain on ln_nis_cpt */
270 int ni_maxtxcredits; /* # tx credits */
271 /* # per-peer send credits */
272 int ni_peertxcredits;
273 /* # per-peer router buffer credits */
274 int ni_peerrtrcredits;
275 /* seconds to consider peer dead */
277 int ni_ncpts; /* number of CPTs */
278 __u32 *ni_cpts; /* bond NI on some CPTs */
279 lnet_nid_t ni_nid; /* interface's NID */
280 void *ni_data; /* instance-specific data */
281 lnd_t *ni_lnd; /* procedural interface */
282 struct lnet_tx_queue **ni_tx_queues; /* percpt TX queues */
283 int **ni_refs; /* percpt reference count */
284 time64_t ni_last_alive; /* when I was last alive */
285 struct lnet_ni_status *ni_status; /* my health status */
286 /* per NI LND tunables */
287 struct lnet_ioctl_config_lnd_tunables *ni_lnd_tunables;
288 /* equivalent interfaces to use */
289 char *ni_interfaces[LNET_MAX_INTERFACES];
290 struct net *ni_net_ns; /* original net namespace */
293 #define LNET_PROTO_PING_MATCHBITS 0x8000000000000000LL
295 /* NB: value of these features equal to LNET_PROTO_PING_VERSION_x
296 * of old LNet, so there shouldn't be any compatibility issue */
297 #define LNET_PING_FEAT_INVAL (0) /* no feature */
298 #define LNET_PING_FEAT_BASE (1 << 0) /* just a ping */
299 #define LNET_PING_FEAT_NI_STATUS (1 << 1) /* return NI status */
300 #define LNET_PING_FEAT_RTE_DISABLED (1 << 2) /* Routing enabled */
302 #define LNET_PING_FEAT_MASK (LNET_PING_FEAT_BASE | \
303 LNET_PING_FEAT_NI_STATUS)
305 typedef struct lnet_ping_info {
310 struct lnet_ni_status pi_ni[0];
311 } WIRE_ATTR lnet_ping_info_t;
313 /* router checker data, per router */
314 #define LNET_MAX_RTR_NIS 16
315 #define LNET_PINGINFO_SIZE offsetof(struct lnet_ping_info, pi_ni[LNET_MAX_RTR_NIS])
317 /* chain on the_lnet.ln_zombie_rcd or ln_deathrow_rcd */
318 struct list_head rcd_list;
319 lnet_handle_md_t rcd_mdh; /* ping buffer MD */
320 struct lnet_peer *rcd_gateway; /* reference to gateway */
321 struct lnet_ping_info *rcd_pinginfo; /* ping buffer */
324 typedef struct lnet_peer {
325 /* chain on peer hash */
326 struct list_head lp_hashlist;
327 /* messages blocking for tx credits */
328 struct list_head lp_txq;
329 /* messages blocking for router credits */
330 struct list_head lp_rtrq;
331 /* chain on router list */
332 struct list_head lp_rtr_list;
333 /* # tx credits available */
337 /* # router credits */
340 int lp_minrtrcredits;
342 unsigned int lp_alive:1;
343 /* notification outstanding? */
344 unsigned int lp_notify:1;
345 /* outstanding notification for LND? */
346 unsigned int lp_notifylnd:1;
347 /* some thread is handling notification */
348 unsigned int lp_notifying:1;
349 /* SEND event outstanding from ping */
350 unsigned int lp_ping_notsent;
351 /* # times router went dead<->alive */
353 /* bytes queued for sending */
355 /* time of last aliveness news */
356 cfs_time_t lp_timestamp;
357 /* time of last ping attempt */
358 cfs_time_t lp_ping_timestamp;
359 /* != 0 if ping reply expected */
360 cfs_time_t lp_ping_deadline;
361 /* when I was last alive */
362 cfs_time_t lp_last_alive;
363 /* when lp_ni was queried last time */
364 cfs_time_t lp_last_query;
365 /* interface peer is on */
367 lnet_nid_t lp_nid; /* peer's NID */
368 int lp_refcount; /* # refs */
369 int lp_cpt; /* CPT this peer attached on */
370 /* # refs from lnet_route_t::lr_gateway */
372 /* returned RC ping features */
373 unsigned int lp_ping_feats;
374 struct list_head lp_routes; /* routers on this peer */
375 lnet_rc_data_t *lp_rcd; /* router checker state */
379 #define LNET_PEER_HASH_BITS 9
380 #define LNET_PEER_HASH_SIZE (1 << LNET_PEER_HASH_BITS)
382 /* peer hash table */
383 struct lnet_peer_table {
384 int pt_version; /* /proc validity stamp */
385 int pt_number; /* # peers extant */
386 int pt_zombies; /* # zombies to go to deathrow
387 * (and not there yet) */
388 struct list_head pt_deathrow; /* zombie peers */
389 struct list_head *pt_hash; /* NID->peer hash */
392 /* peer aliveness is enabled only on routers for peers in a network where the
393 * lnet_ni_t::ni_peertimeout has been set to a positive value */
394 #define lnet_peer_aliveness_enabled(lp) (the_lnet.ln_routing != 0 && \
395 (lp)->lp_ni->ni_peertimeout > 0)
398 struct list_head lr_list; /* chain on net */
399 struct list_head lr_gwlist; /* chain on gateway */
400 lnet_peer_t *lr_gateway; /* router node */
401 __u32 lr_net; /* remote network number */
402 int lr_seq; /* sequence for round-robin */
403 unsigned int lr_downis; /* number of down NIs */
404 __u32 lr_hops; /* how far I am */
405 unsigned int lr_priority; /* route priority */
408 #define LNET_REMOTE_NETS_HASH_DEFAULT (1U << 7)
409 #define LNET_REMOTE_NETS_HASH_MAX (1U << 16)
410 #define LNET_REMOTE_NETS_HASH_SIZE (1 << the_lnet.ln_remote_nets_hbits)
413 /* chain on ln_remote_nets_hash */
414 struct list_head lrn_list;
416 struct list_head lrn_routes;
421 /** lnet message has credit and can be submitted to lnd for send/receive */
422 #define LNET_CREDIT_OK 0
423 /** lnet message is waiting for credit */
424 #define LNET_CREDIT_WAIT 1
427 /* my free buffer pool */
428 struct list_head rbp_bufs;
429 /* messages blocking for a buffer */
430 struct list_head rbp_msgs;
431 /* # pages in each buffer */
433 /* requested number of buffers */
434 int rbp_req_nbuffers;
435 /* # buffers actually allocated */
437 /* # free buffers / blocked messages */
444 struct list_head rb_list; /* chain on rbp_bufs */
445 lnet_rtrbufpool_t *rb_pool; /* owning pool */
446 lnet_kiov_t rb_kiov[0]; /* the buffer space */
449 #define LNET_PEER_HASHSIZE 503 /* prime! */
452 /* Didn't match anything */
453 LNET_MATCHMD_NONE = (1 << 0),
455 LNET_MATCHMD_OK = (1 << 1),
456 /* Must be discarded */
457 LNET_MATCHMD_DROP = (1 << 2),
458 /* match and buffer is exhausted */
459 LNET_MATCHMD_EXHAUSTED = (1 << 3),
461 LNET_MATCHMD_FINISH = (LNET_MATCHMD_OK | LNET_MATCHMD_DROP),
464 /* Options for lnet_portal_t::ptl_options */
465 #define LNET_PTL_LAZY (1 << 0)
466 #define LNET_PTL_MATCH_UNIQUE (1 << 1) /* unique match, for RDMA */
467 #define LNET_PTL_MATCH_WILDCARD (1 << 2) /* wildcard match, request portal */
469 /* parameter for matching operations (GET, PUT) */
470 struct lnet_match_info {
472 lnet_process_id_t mi_id;
474 unsigned int mi_portal;
475 unsigned int mi_rlength;
476 unsigned int mi_roffset;
479 /* ME hash of RDMA portal */
480 #define LNET_MT_HASH_BITS 8
481 #define LNET_MT_HASH_SIZE (1 << LNET_MT_HASH_BITS)
482 #define LNET_MT_HASH_MASK (LNET_MT_HASH_SIZE - 1)
483 /* we allocate (LNET_MT_HASH_SIZE + 1) entries for lnet_match_table::mt_hash,
484 * the last entry is reserved for MEs with ignore-bits */
485 #define LNET_MT_HASH_IGNORE LNET_MT_HASH_SIZE
486 /* __u64 has 2^6 bits, so need 2^(LNET_MT_HASH_BITS - LNET_MT_BITS_U64) which
487 * is 4 __u64s as bit-map, and add an extra __u64 (only use one bit) for the
488 * ME-list with ignore-bits, which is mtable::mt_hash[LNET_MT_HASH_IGNORE] */
489 #define LNET_MT_BITS_U64 6 /* 2^6 bits */
490 #define LNET_MT_EXHAUSTED_BITS (LNET_MT_HASH_BITS - LNET_MT_BITS_U64)
491 #define LNET_MT_EXHAUSTED_BMAP ((1 << LNET_MT_EXHAUSTED_BITS) + 1)
493 /* portal match table */
494 struct lnet_match_table {
495 /* reserved for upcoming patches, CPU partition ID */
497 unsigned int mt_portal; /* portal index */
498 /* match table is set as "enabled" if there's non-exhausted MD
499 * attached on mt_mhash, it's only valid for wildcard portal */
500 unsigned int mt_enabled;
501 /* bitmap to flag whether MEs on mt_hash are exhausted or not */
502 __u64 mt_exhausted[LNET_MT_EXHAUSTED_BMAP];
503 struct list_head *mt_mhash; /* matching hash */
506 /* these are only useful for wildcard portal */
507 /* Turn off message rotor for wildcard portals */
508 #define LNET_PTL_ROTOR_OFF 0
509 /* round-robin dispatch all PUT messages for wildcard portals */
510 #define LNET_PTL_ROTOR_ON 1
511 /* round-robin dispatch routed PUT message for wildcard portals */
512 #define LNET_PTL_ROTOR_RR_RT 2
513 /* dispatch routed PUT message by hashing source NID for wildcard portals */
514 #define LNET_PTL_ROTOR_HASH_RT 3
516 typedef struct lnet_portal {
518 unsigned int ptl_index; /* portal ID, reserved */
519 /* flags on this portal: lazy, unique... */
520 unsigned int ptl_options;
521 /* list of messages which are stealing buffer */
522 struct list_head ptl_msg_stealing;
523 /* messages blocking for MD */
524 struct list_head ptl_msg_delayed;
525 /* Match table for each CPT */
526 struct lnet_match_table **ptl_mtables;
527 /* spread rotor of incoming "PUT" */
528 unsigned int ptl_rotor;
529 /* # active entries for this portal */
531 /* array of active entries' cpu-partition-id */
535 #define LNET_LH_HASH_BITS 12
536 #define LNET_LH_HASH_SIZE (1ULL << LNET_LH_HASH_BITS)
537 #define LNET_LH_HASH_MASK (LNET_LH_HASH_SIZE - 1)
539 /* resource container (ME, MD, EQ) */
540 struct lnet_res_container {
541 unsigned int rec_type; /* container type */
542 __u64 rec_lh_cookie; /* cookie generator */
543 struct list_head rec_active; /* active resource list */
544 struct list_head *rec_lh_hash; /* handle hash */
547 /* message container */
548 struct lnet_msg_container {
549 int msc_init; /* initialized or not */
550 /* max # threads finalizing */
552 /* msgs waiting to complete finalizing */
553 struct list_head msc_finalizing;
554 struct list_head msc_active; /* active message list */
555 /* threads doing finalization */
556 void **msc_finalizers;
559 /* Router Checker states */
560 #define LNET_RC_STATE_SHUTDOWN 0 /* not started */
561 #define LNET_RC_STATE_RUNNING 1 /* started up OK */
562 #define LNET_RC_STATE_STOPPING 2 /* telling thread to stop */
566 /* CPU partition table of LNet */
567 struct cfs_cpt_table *ln_cpt_table;
568 /* number of CPTs in ln_cpt_table */
569 unsigned int ln_cpt_number;
570 unsigned int ln_cpt_bits;
572 /* protect LNet resources (ME/MD/EQ) */
573 struct cfs_percpt_lock *ln_res_lock;
576 /* the vector of portals */
577 lnet_portal_t **ln_portals;
578 /* percpt ME containers */
579 struct lnet_res_container **ln_me_containers;
580 /* percpt MD container */
581 struct lnet_res_container **ln_md_containers;
583 /* Event Queue container */
584 struct lnet_res_container ln_eq_container;
585 wait_queue_head_t ln_eq_waitq;
586 spinlock_t ln_eq_wait_lock;
588 unsigned int ln_remote_nets_hbits;
590 /* protect NI, peer table, credits, routers, rtrbuf... */
591 struct cfs_percpt_lock *ln_net_lock;
592 /* percpt message containers for active/finalizing/freed message */
593 struct lnet_msg_container **ln_msg_containers;
594 lnet_counters_t **ln_counters;
595 struct lnet_peer_table **ln_peer_tables;
596 /* failure simulation */
597 struct list_head ln_test_peers;
598 struct list_head ln_drop_rules;
599 struct list_head ln_delay_rules;
601 struct list_head ln_nis; /* LND instances */
602 /* NIs bond on specific CPT(s) */
603 struct list_head ln_nis_cpt;
604 /* dying LND instances */
605 struct list_head ln_nis_zombie;
606 lnet_ni_t *ln_loni; /* the loopback NI */
608 /* remote networks with routes to them */
609 struct list_head *ln_remote_nets_hash;
611 __u64 ln_remote_nets_version;
612 /* list of all known routers */
613 struct list_head ln_routers;
615 __u64 ln_routers_version;
616 /* percpt router buffer pools */
617 lnet_rtrbufpool_t **ln_rtrpools;
619 lnet_handle_md_t ln_ping_target_md;
620 lnet_handle_eq_t ln_ping_target_eq;
621 struct lnet_ping_info *ln_ping_info;
623 /* router checker startup/shutdown state */
625 /* router checker's event queue */
626 lnet_handle_eq_t ln_rc_eqh;
627 /* rcd still pending on net */
628 struct list_head ln_rcd_deathrow;
629 /* rcd ready for free */
630 struct list_head ln_rcd_zombie;
631 /* serialise startup/shutdown */
632 struct semaphore ln_rc_signal;
634 struct mutex ln_api_mutex;
635 struct mutex ln_lnd_mutex;
636 /* Have I called LNetNIInit myself? */
638 /* LNetNIInit/LNetNIFini counter */
640 /* shutdown in progress */
643 int ln_routing; /* am I a router? */
644 lnet_pid_t ln_pid; /* requested pid */
645 /* uniquely identifies this ni in this epoch */
646 __u64 ln_interface_cookie;
647 /* registered LNDs */
648 struct list_head ln_lnds;
650 /* test protocol compatibility flags */
651 int ln_testprotocompat;
653 /* 0 - load the NIs from the mod params
654 * 1 - do not load the NIs from the mod params
655 * Reverse logic to ensure that other calls to LNetNIInit
658 bool ln_nis_from_mod_params;
660 /* waitq for router checker. As long as there are no routes in
661 * the list, the router checker will sleep on this queue. when
662 * routes are added the thread will wake up */
663 wait_queue_head_t ln_rc_waitq;