Whamcloud - gitweb
303736a6c9c48c0db8e0c89d8381b7ea1ef29f7b
[fs/lustre-release.git] / lnet / include / uapi / linux / lnet / lnet-idl.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31
32 #ifndef __UAPI_LNET_IDL_H__
33 #define __UAPI_LNET_IDL_H__
34
35 #include <linux/types.h>
36
37 /************************************************************************
38  * Core LNet wire message format.
39  * These are sent in sender's byte order (i.e. receiver flips).
40  */
41
42 /** Address of an end-point in an LNet network.
43  *
44  * A node can have multiple end-points and hence multiple addresses.
45  * An LNet network can be a simple network (e.g. tcp0) or a network of
46  * LNet networks connected by LNet routers. Therefore an end-point address
47  * has two parts: network ID, and address within a network.
48  * The most-significant-byte in this format is always 0.  A larger value
49  * would imply a larger nid with a larger address.
50  *
51  * \see LNET_NIDNET, LNET_NIDADDR, and LNET_MKNID.
52  */
53 typedef __u64 lnet_nid_t;
54
55 /*
56  * Address of LNet end-point in extended form
57  *
58  * To support addresses larger than 32bits we have
59  * an extended nid which supports up to 128 bits
60  * of address and is extensible.
61  * If nid_size is 0, then the nid can be stored in an lnet_nid_t,
62  * and the first 8 bytes of the 'struct lnet_nid' are identical to
63  * the lnet_nid_t in big-endian format.
64  * If nid_type == 0xff, then all other fields should be ignored
65  * and this is an ANY wildcard address.  In particular, the nid_size
66  * can be 0xff without making the address too big to fit.
67  */
68 struct lnet_nid {
69         __u8    nid_size;       /* total bytes - 8 */
70         __u8    nid_type;
71         __be16  nid_num;
72         __be32  nid_addr[4];
73 } __attribute__((packed));
74
75 #define NID_BYTES(nid)          ((nid)->nid_size + 8)
76 #define NID_ADDR_BYTES(nid)     ((nid)->nid_size + 4)
77
78 /**
79  * ID of a process in a node. Shortened as PID to distinguish from
80  * lnet_process_id, the global process ID.
81  */
82 typedef __u32 lnet_pid_t;
83
84 /* Packed version of struct lnet_process_id to transfer via network */
85 struct lnet_process_id_packed {
86         lnet_nid_t nid;
87         lnet_pid_t pid; /* node id / process id */
88 } __attribute__((packed));
89
90 /* The wire handle's interface cookie only matches one network interface in
91  * one epoch (i.e. new cookie when the interface restarts or the node
92  * reboots).  The object cookie only matches one object on that interface
93  * during that object's lifetime (i.e. no cookie re-use).
94  */
95 struct lnet_handle_wire {
96         __u64 wh_interface_cookie;
97         __u64 wh_object_cookie;
98 } __attribute__((packed));
99
100 enum lnet_msg_type {
101         LNET_MSG_ACK = 0,
102         LNET_MSG_PUT,
103         LNET_MSG_GET,
104         LNET_MSG_REPLY,
105         LNET_MSG_HELLO,
106 };
107
108 /* The variant fields of the portals message header are aligned on an 8
109  * byte boundary in the message header.  Note that all types used in these
110  * wire structs MUST be fixed size and the smaller types are placed at the
111  * end.
112  */
113 struct lnet_ack {
114         struct lnet_handle_wire dst_wmd;
115         __u64                   match_bits;
116         __u32                   mlength;
117 } __attribute__((packed));
118
119 struct lnet_put {
120         struct lnet_handle_wire ack_wmd;
121         __u64                   match_bits;
122         __u64                   hdr_data;
123         __u32                   ptl_index;
124         __u32                   offset;
125 } __attribute__((packed));
126
127 struct lnet_get {
128         struct lnet_handle_wire return_wmd;
129         __u64                   match_bits;
130         __u32                   ptl_index;
131         __u32                   src_offset;
132         __u32                   sink_length;
133 } __attribute__((packed));
134
135 struct lnet_reply {
136         struct lnet_handle_wire dst_wmd;
137 } __attribute__((packed));
138
139 struct lnet_hello {
140         __u64                   incarnation;
141         __u32                   type;
142 } __attribute__((packed));
143
144 struct lnet_hdr {
145         lnet_nid_t      dest_nid;
146         lnet_nid_t      src_nid;
147         lnet_pid_t      dest_pid;
148         lnet_pid_t      src_pid;
149         __u32           type;           /* enum lnet_msg_type */
150         __u32           payload_length; /* payload data to follow */
151         /*<------__u64 aligned------->*/
152         union {
153                 struct lnet_ack         ack;
154                 struct lnet_put         put;
155                 struct lnet_get         get;
156                 struct lnet_reply       reply;
157                 struct lnet_hello       hello;
158         } msg;
159 } __attribute__((packed));
160
161 /* A HELLO message contains a magic number and protocol version
162  * code in the header's dest_nid, the peer's NID in the src_nid, and
163  * LNET_MSG_HELLO in the type field.  All other common fields are zero
164  * (including payload_size; i.e. no payload).
165  * This is for use by byte-stream LNDs (e.g. TCP/IP) to check the peer is
166  * running the same protocol and to find out its NID. These LNDs should
167  * exchange HELLO messages when a connection is first established.  Individual
168  * LNDs can put whatever else they fancy in lnet_hdr::msg.
169  */
170 struct lnet_magicversion {
171         __u32   magic;          /* LNET_PROTO_TCP_MAGIC */
172         __u16   version_major;  /* increment on incompatible change */
173         __u16   version_minor;  /* increment on compatible change */
174 } __attribute__((packed));
175
176 /* PROTO MAGIC for LNDs */
177 #define LNET_PROTO_IB_MAGIC             0x0be91b91
178 #define LNET_PROTO_GNI_MAGIC            0xb00fbabe /* ask Kim */
179 #define LNET_PROTO_TCP_MAGIC            0xeebc0ded
180 #define LNET_PROTO_ACCEPTOR_MAGIC       0xacce7100
181 #define LNET_PROTO_PING_MAGIC           0x70696E67 /* 'ping' */
182
183 /* Placeholder for a future "unified" protocol across all LNDs */
184 /* Current LNDs that receive a request with this magic will respond
185  * with a "stub" reply using their current protocol */
186 #define LNET_PROTO_MAGIC                0x45726963 /* ! */
187
188 #define LNET_PROTO_TCP_VERSION_MAJOR    1
189 #define LNET_PROTO_TCP_VERSION_MINOR    0
190
191 /* Acceptor connection request */
192 struct lnet_acceptor_connreq {
193         __u32   acr_magic;      /* PTL_ACCEPTOR_PROTO_MAGIC */
194         __u32   acr_version;    /* protocol version */
195         __u64   acr_nid;        /* target NID */
196 } __attribute__((packed));
197
198 #define LNET_PROTO_ACCEPTOR_VERSION     1
199
200 struct lnet_counters_common {
201         __u32   lcc_msgs_alloc;
202         __u32   lcc_msgs_max;
203         __u32   lcc_errors;
204         __u32   lcc_send_count;
205         __u32   lcc_recv_count;
206         __u32   lcc_route_count;
207         __u32   lcc_drop_count;
208         __u64   lcc_send_length;
209         __u64   lcc_recv_length;
210         __u64   lcc_route_length;
211         __u64   lcc_drop_length;
212 } __attribute__((packed));
213
214
215 #define LNET_NI_STATUS_UP       0x15aac0de
216 #define LNET_NI_STATUS_DOWN     0xdeadface
217 #define LNET_NI_STATUS_INVALID  0x00000000
218
219 struct lnet_ni_status {
220         lnet_nid_t ns_nid;
221         __u32      ns_status;
222         __u32      ns_unused;
223 } __attribute__((packed));
224
225 /*
226  * NB: value of these features equal to LNET_PROTO_PING_VERSION_x
227  * of old LNet, so there shouldn't be any compatibility issue
228  */
229 #define LNET_PING_FEAT_INVAL            (0)             /* no feature */
230 #define LNET_PING_FEAT_BASE             (1 << 0)        /* just a ping */
231 #define LNET_PING_FEAT_NI_STATUS        (1 << 1)        /* return NI status */
232 #define LNET_PING_FEAT_RTE_DISABLED     (1 << 2)        /* Routing enabled */
233 #define LNET_PING_FEAT_MULTI_RAIL       (1 << 3)        /* Multi-Rail aware */
234 #define LNET_PING_FEAT_DISCOVERY        (1 << 4)        /* Supports Discovery */
235
236 /*
237  * All ping feature bits fit to hit the wire.
238  * In lnet_assert_wire_constants() this is compared against its open-coded
239  * value, and in lnet_ping_target_update() it is used to verify that no
240  * unknown bits have been set.
241  * New feature bits can be added, just be aware that this does change the
242  * over-the-wire protocol.
243  */
244 #define LNET_PING_FEAT_BITS             (LNET_PING_FEAT_BASE | \
245                                          LNET_PING_FEAT_NI_STATUS | \
246                                          LNET_PING_FEAT_RTE_DISABLED | \
247                                          LNET_PING_FEAT_MULTI_RAIL | \
248                                          LNET_PING_FEAT_DISCOVERY)
249
250 struct lnet_ping_info {
251         __u32                   pi_magic;
252         __u32                   pi_features;
253         lnet_pid_t              pi_pid;
254         __u32                   pi_nnis;
255         struct lnet_ni_status   pi_ni[0];
256 } __attribute__((packed));
257
258 #define LNET_PING_INFO_SIZE(NNIDS) \
259         offsetof(struct lnet_ping_info, pi_ni[NNIDS])
260 #define LNET_PING_INFO_LONI(PINFO)      ((PINFO)->pi_ni[0].ns_nid)
261 #define LNET_PING_INFO_SEQNO(PINFO)     ((PINFO)->pi_ni[0].ns_status)
262
263 #endif