]> git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/rpmem_common/rpmem_proto.h
import ceph 16.2.7
[ceph.git] / ceph / src / pmdk / src / rpmem_common / rpmem_proto.h
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright 2016-2020, Intel Corporation */
3
4 /*
5 * rpmem_proto.h -- rpmem protocol definitions
6 */
7
8 #ifndef RPMEM_PROTO_H
9 #define RPMEM_PROTO_H 1
10
11 #include <stdint.h>
12 #include <endian.h>
13
14 #include "librpmem.h"
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #define PACKED __attribute__((packed))
21
22 #define RPMEM_PROTO "tcp"
23 #define RPMEM_PROTO_MAJOR 0
24 #define RPMEM_PROTO_MINOR 1
25 #define RPMEM_SIG_SIZE 8
26 #define RPMEM_UUID_SIZE 16
27 #define RPMEM_PROV_SIZE 32
28 #define RPMEM_USER_SIZE 16
29
30 /*
31 * rpmem_msg_type -- type of messages
32 */
33 enum rpmem_msg_type {
34 RPMEM_MSG_TYPE_CREATE = 1, /* create request */
35 RPMEM_MSG_TYPE_CREATE_RESP = 2, /* create request response */
36 RPMEM_MSG_TYPE_OPEN = 3, /* open request */
37 RPMEM_MSG_TYPE_OPEN_RESP = 4, /* open request response */
38 RPMEM_MSG_TYPE_CLOSE = 5, /* close request */
39 RPMEM_MSG_TYPE_CLOSE_RESP = 6, /* close request response */
40 RPMEM_MSG_TYPE_SET_ATTR = 7, /* set attributes request */
41 /* set attributes request response */
42 RPMEM_MSG_TYPE_SET_ATTR_RESP = 8,
43 MAX_RPMEM_MSG_TYPE,
44 };
45
46 /*
47 * rpmem_pool_attr_packed -- a packed version
48 */
49 struct rpmem_pool_attr_packed {
50 char signature[RPMEM_POOL_HDR_SIG_LEN]; /* pool signature */
51 uint32_t major; /* format major version number */
52 uint32_t compat_features; /* mask: compatible "may" features */
53 uint32_t incompat_features; /* mask: "must support" features */
54 uint32_t ro_compat_features; /* mask: force RO if unsupported */
55 unsigned char poolset_uuid[RPMEM_POOL_HDR_UUID_LEN]; /* pool uuid */
56 unsigned char uuid[RPMEM_POOL_HDR_UUID_LEN]; /* first part uuid */
57 unsigned char next_uuid[RPMEM_POOL_HDR_UUID_LEN]; /* next pool uuid */
58 unsigned char prev_uuid[RPMEM_POOL_HDR_UUID_LEN]; /* prev pool uuid */
59 unsigned char user_flags[RPMEM_POOL_USER_FLAGS_LEN]; /* user flags */
60 } PACKED;
61
62 /*
63 * rpmem_msg_ibc_attr -- in-band connection attributes
64 *
65 * Used by create request response and open request response.
66 * Contains essential information to proceed with in-band connection
67 * initialization.
68 */
69 struct rpmem_msg_ibc_attr {
70 uint32_t port; /* RDMA connection port */
71 uint32_t persist_method; /* persist method */
72 uint64_t rkey; /* remote key */
73 uint64_t raddr; /* remote address */
74 uint32_t nlanes; /* number of lanes */
75 } PACKED;
76
77 /*
78 * rpmem_msg_pool_desc -- remote pool descriptor
79 */
80 struct rpmem_msg_pool_desc {
81 uint32_t size; /* size of pool descriptor */
82 uint8_t desc[0]; /* pool descriptor, null-terminated string */
83 } PACKED;
84
85 /*
86 * rpmem_msg_hdr -- message header which consists of type and size of message
87 *
88 * The type must be one of the rpmem_msg_type values.
89 */
90 struct rpmem_msg_hdr {
91 uint32_t type; /* type of message */
92 uint64_t size; /* size of message */
93 uint8_t body[0];
94 } PACKED;
95
96 /*
97 * rpmem_msg_hdr_resp -- message response header which consists of type, size
98 * and status.
99 *
100 * The type must be one of the rpmem_msg_type values.
101 */
102 struct rpmem_msg_hdr_resp {
103 uint32_t status; /* response status */
104 uint32_t type; /* type of message */
105 uint64_t size; /* size of message */
106 } PACKED;
107
108 /*
109 * rpmem_msg_common -- common fields for open/create messages
110 */
111 struct rpmem_msg_common {
112 uint16_t major; /* protocol version major number */
113 uint16_t minor; /* protocol version minor number */
114 uint64_t pool_size; /* minimum required size of a pool */
115 uint32_t nlanes; /* number of lanes used by initiator */
116 uint32_t provider; /* provider */
117 uint64_t buff_size; /* buffer size for inline persist */
118 } PACKED;
119
120 /*
121 * rpmem_msg_create -- create request message
122 *
123 * The type of message must be set to RPMEM_MSG_TYPE_CREATE.
124 * The size of message must be set to
125 * sizeof(struct rpmem_msg_create) + pool_desc_size
126 */
127 struct rpmem_msg_create {
128 struct rpmem_msg_hdr hdr; /* message header */
129 struct rpmem_msg_common c;
130 struct rpmem_pool_attr_packed pool_attr; /* pool attributes */
131 struct rpmem_msg_pool_desc pool_desc; /* pool descriptor */
132 } PACKED;
133
134 /*
135 * rpmem_msg_create_resp -- create request response message
136 *
137 * The type of message must be set to RPMEM_MSG_TYPE_CREATE_RESP.
138 * The size of message must be set to sizeof(struct rpmem_msg_create_resp).
139 */
140 struct rpmem_msg_create_resp {
141 struct rpmem_msg_hdr_resp hdr; /* message header */
142 struct rpmem_msg_ibc_attr ibc; /* in-band connection attributes */
143 } PACKED;
144
145 /*
146 * rpmem_msg_open -- open request message
147 *
148 * The type of message must be set to RPMEM_MSG_TYPE_OPEN.
149 * The size of message must be set to
150 * sizeof(struct rpmem_msg_open) + pool_desc_size
151 */
152 struct rpmem_msg_open {
153 struct rpmem_msg_hdr hdr; /* message header */
154 struct rpmem_msg_common c;
155 struct rpmem_msg_pool_desc pool_desc; /* pool descriptor */
156 } PACKED;
157
158 /*
159 * rpmem_msg_open_resp -- open request response message
160 *
161 * The type of message must be set to RPMEM_MSG_TYPE_OPEN_RESP.
162 * The size of message must be set to sizeof(struct rpmem_msg_open_resp)
163 */
164 struct rpmem_msg_open_resp {
165 struct rpmem_msg_hdr_resp hdr; /* message header */
166 struct rpmem_msg_ibc_attr ibc; /* in-band connection attributes */
167 struct rpmem_pool_attr_packed pool_attr; /* pool attributes */
168 } PACKED;
169
170 /*
171 * rpmem_msg_close -- close request message
172 *
173 * The type of message must be set to RPMEM_MSG_TYPE_CLOSE
174 * The size of message must be set to sizeof(struct rpmem_msg_close)
175 */
176 struct rpmem_msg_close {
177 struct rpmem_msg_hdr hdr; /* message header */
178 uint32_t flags; /* flags */
179 } PACKED;
180
181 /*
182 * rpmem_msg_close_resp -- close request response message
183 *
184 * The type of message must be set to RPMEM_MSG_TYPE_CLOSE_RESP
185 * The size of message must be set to sizeof(struct rpmem_msg_close_resp)
186 */
187 struct rpmem_msg_close_resp {
188 struct rpmem_msg_hdr_resp hdr; /* message header */
189 /* no more fields */
190 } PACKED;
191
192 #define RPMEM_FLUSH_WRITE 0U /* flush / persist using RDMA WRITE */
193 #define RPMEM_DEEP_PERSIST 1U /* deep persist operation */
194 #define RPMEM_PERSIST_SEND 2U /* persist using RDMA SEND */
195 #define RPMEM_COMPLETION 4U /* schedule command with a completion */
196
197 /* the two least significant bits are reserved for mode of persist */
198 #define RPMEM_FLUSH_PERSIST_MASK 0x3U
199
200 #define RPMEM_PERSIST_MAX 2U /* maximum valid persist value */
201
202 /*
203 * rpmem_msg_persist -- remote persist message
204 */
205 struct rpmem_msg_persist {
206 uint32_t flags; /* lane flags */
207 uint32_t lane; /* lane identifier */
208 uint64_t addr; /* remote memory address */
209 uint64_t size; /* remote memory size */
210 uint8_t data[];
211 };
212
213 /*
214 * rpmem_msg_persist_resp -- remote persist response message
215 */
216 struct rpmem_msg_persist_resp {
217 uint32_t flags; /* lane flags */
218 uint32_t lane; /* lane identifier */
219 };
220
221 /*
222 * rpmem_msg_set_attr -- set attributes request message
223 *
224 * The type of message must be set to RPMEM_MSG_TYPE_SET_ATTR.
225 * The size of message must be set to sizeof(struct rpmem_msg_set_attr)
226 */
227 struct rpmem_msg_set_attr {
228 struct rpmem_msg_hdr hdr; /* message header */
229 struct rpmem_pool_attr_packed pool_attr; /* pool attributes */
230 } PACKED;
231
232 /*
233 * rpmem_msg_set_attr_resp -- set attributes request response message
234 *
235 * The type of message must be set to RPMEM_MSG_TYPE_SET_ATTR_RESP.
236 * The size of message must be set to sizeof(struct rpmem_msg_set_attr_resp).
237 */
238 struct rpmem_msg_set_attr_resp {
239 struct rpmem_msg_hdr_resp hdr; /* message header */
240 } PACKED;
241
242 /*
243 * XXX Begin: Suppress gcc conversion warnings for FreeBSD be*toh macros.
244 */
245 #pragma GCC diagnostic push
246 #pragma GCC diagnostic ignored "-Wconversion"
247 /*
248 * rpmem_ntoh_msg_ibc_attr -- convert rpmem_msg_ibc attr to host byte order
249 */
250 static inline void
251 rpmem_ntoh_msg_ibc_attr(struct rpmem_msg_ibc_attr *ibc)
252 {
253 ibc->port = be32toh(ibc->port);
254 ibc->persist_method = be32toh(ibc->persist_method);
255 ibc->rkey = be64toh(ibc->rkey);
256 ibc->raddr = be64toh(ibc->raddr);
257 }
258
259 /*
260 * rpmem_ntoh_msg_pool_desc -- convert rpmem_msg_pool_desc to host byte order
261 */
262 static inline void
263 rpmem_ntoh_msg_pool_desc(struct rpmem_msg_pool_desc *pool_desc)
264 {
265 pool_desc->size = be32toh(pool_desc->size);
266 }
267
268 /*
269 * rpmem_ntoh_pool_attr -- convert rpmem_pool_attr to host byte order
270 */
271 static inline void
272 rpmem_ntoh_pool_attr(struct rpmem_pool_attr_packed *attr)
273 {
274 attr->major = be32toh(attr->major);
275 attr->ro_compat_features = be32toh(attr->ro_compat_features);
276 attr->incompat_features = be32toh(attr->incompat_features);
277 attr->compat_features = be32toh(attr->compat_features);
278 }
279
280 /*
281 * rpmem_ntoh_msg_hdr -- convert rpmem_msg_hdr to host byte order
282 */
283 static inline void
284 rpmem_ntoh_msg_hdr(struct rpmem_msg_hdr *hdrp)
285 {
286 hdrp->type = be32toh(hdrp->type);
287 hdrp->size = be64toh(hdrp->size);
288 }
289
290 /*
291 * rpmem_hton_msg_hdr -- convert rpmem_msg_hdr to network byte order
292 */
293 static inline void
294 rpmem_hton_msg_hdr(struct rpmem_msg_hdr *hdrp)
295 {
296 rpmem_ntoh_msg_hdr(hdrp);
297 }
298
299 /*
300 * rpmem_ntoh_msg_hdr_resp -- convert rpmem_msg_hdr_resp to host byte order
301 */
302 static inline void
303 rpmem_ntoh_msg_hdr_resp(struct rpmem_msg_hdr_resp *hdrp)
304 {
305 hdrp->status = be32toh(hdrp->status);
306 hdrp->type = be32toh(hdrp->type);
307 hdrp->size = be64toh(hdrp->size);
308 }
309
310 /*
311 * rpmem_hton_msg_hdr_resp -- convert rpmem_msg_hdr_resp to network byte order
312 */
313 static inline void
314 rpmem_hton_msg_hdr_resp(struct rpmem_msg_hdr_resp *hdrp)
315 {
316 rpmem_ntoh_msg_hdr_resp(hdrp);
317 }
318
319 /*
320 * rpmem_ntoh_msg_common -- convert rpmem_msg_common to host byte order
321 */
322 static inline void
323 rpmem_ntoh_msg_common(struct rpmem_msg_common *msg)
324 {
325 msg->major = be16toh(msg->major);
326 msg->minor = be16toh(msg->minor);
327 msg->pool_size = be64toh(msg->pool_size);
328 msg->nlanes = be32toh(msg->nlanes);
329 msg->provider = be32toh(msg->provider);
330 msg->buff_size = be64toh(msg->buff_size);
331 }
332
333 /*
334 * rpmem_hton_msg_common -- convert rpmem_msg_common to network byte order
335 */
336 static inline void
337 rpmem_hton_msg_common(struct rpmem_msg_common *msg)
338 {
339 rpmem_ntoh_msg_common(msg);
340 }
341
342 /*
343 * rpmem_ntoh_msg_create -- convert rpmem_msg_create to host byte order
344 */
345 static inline void
346 rpmem_ntoh_msg_create(struct rpmem_msg_create *msg)
347 {
348 rpmem_ntoh_msg_hdr(&msg->hdr);
349 rpmem_ntoh_msg_common(&msg->c);
350 rpmem_ntoh_pool_attr(&msg->pool_attr);
351 rpmem_ntoh_msg_pool_desc(&msg->pool_desc);
352 }
353
354 /*
355 * rpmem_hton_msg_create -- convert rpmem_msg_create to network byte order
356 */
357 static inline void
358 rpmem_hton_msg_create(struct rpmem_msg_create *msg)
359 {
360 rpmem_ntoh_msg_create(msg);
361 }
362
363 /*
364 * rpmem_ntoh_msg_create_resp -- convert rpmem_msg_create_resp to host byte
365 * order
366 */
367 static inline void
368 rpmem_ntoh_msg_create_resp(struct rpmem_msg_create_resp *msg)
369 {
370 rpmem_ntoh_msg_hdr_resp(&msg->hdr);
371 rpmem_ntoh_msg_ibc_attr(&msg->ibc);
372 }
373
374 /*
375 * rpmem_hton_msg_create_resp -- convert rpmem_msg_create_resp to network byte
376 * order
377 */
378 static inline void
379 rpmem_hton_msg_create_resp(struct rpmem_msg_create_resp *msg)
380 {
381 rpmem_ntoh_msg_create_resp(msg);
382 }
383
384 /*
385 * rpmem_ntoh_msg_open -- convert rpmem_msg_open to host byte order
386 */
387 static inline void
388 rpmem_ntoh_msg_open(struct rpmem_msg_open *msg)
389 {
390 rpmem_ntoh_msg_hdr(&msg->hdr);
391 rpmem_ntoh_msg_common(&msg->c);
392 rpmem_ntoh_msg_pool_desc(&msg->pool_desc);
393 }
394 /*
395 * XXX End: Suppress gcc conversion warnings for FreeBSD be*toh macros
396 */
397 #pragma GCC diagnostic pop
398 /*
399 * rpmem_hton_msg_open -- convert rpmem_msg_open to network byte order
400 */
401 static inline void
402 rpmem_hton_msg_open(struct rpmem_msg_open *msg)
403 {
404 rpmem_ntoh_msg_open(msg);
405 }
406
407 /*
408 * rpmem_ntoh_msg_open_resp -- convert rpmem_msg_open_resp to host byte order
409 */
410 static inline void
411 rpmem_ntoh_msg_open_resp(struct rpmem_msg_open_resp *msg)
412 {
413 rpmem_ntoh_msg_hdr_resp(&msg->hdr);
414 rpmem_ntoh_msg_ibc_attr(&msg->ibc);
415 rpmem_ntoh_pool_attr(&msg->pool_attr);
416 }
417
418 /*
419 * rpmem_hton_msg_open_resp -- convert rpmem_msg_open_resp to network byte order
420 */
421 static inline void
422 rpmem_hton_msg_open_resp(struct rpmem_msg_open_resp *msg)
423 {
424 rpmem_ntoh_msg_open_resp(msg);
425 }
426
427 /*
428 * rpmem_ntoh_msg_set_attr -- convert rpmem_msg_set_attr to host byte order
429 */
430 static inline void
431 rpmem_ntoh_msg_set_attr(struct rpmem_msg_set_attr *msg)
432 {
433 rpmem_ntoh_msg_hdr(&msg->hdr);
434 rpmem_ntoh_pool_attr(&msg->pool_attr);
435 }
436
437 /*
438 * rpmem_hton_msg_set_attr -- convert rpmem_msg_set_attr to network byte order
439 */
440 static inline void
441 rpmem_hton_msg_set_attr(struct rpmem_msg_set_attr *msg)
442 {
443 rpmem_ntoh_msg_set_attr(msg);
444 }
445
446 /*
447 * rpmem_ntoh_msg_set_attr_resp -- convert rpmem_msg_set_attr_resp to host byte
448 * order
449 */
450 static inline void
451 rpmem_ntoh_msg_set_attr_resp(struct rpmem_msg_set_attr_resp *msg)
452 {
453 rpmem_ntoh_msg_hdr_resp(&msg->hdr);
454 }
455
456 /*
457 * rpmem_hton_msg_set_attr_resp -- convert rpmem_msg_set_attr_resp to network
458 * byte order
459 */
460 static inline void
461 rpmem_hton_msg_set_attr_resp(struct rpmem_msg_set_attr_resp *msg)
462 {
463 rpmem_hton_msg_hdr_resp(&msg->hdr);
464 }
465
466 /*
467 * rpmem_ntoh_msg_close -- convert rpmem_msg_close to host byte order
468 */
469 static inline void
470 rpmem_ntoh_msg_close(struct rpmem_msg_close *msg)
471 {
472 rpmem_ntoh_msg_hdr(&msg->hdr);
473 }
474
475 /*
476 * rpmem_hton_msg_close -- convert rpmem_msg_close to network byte order
477 */
478 static inline void
479 rpmem_hton_msg_close(struct rpmem_msg_close *msg)
480 {
481 rpmem_ntoh_msg_close(msg);
482 }
483
484 /*
485 * rpmem_ntoh_msg_close_resp -- convert rpmem_msg_close_resp to host byte order
486 */
487 static inline void
488 rpmem_ntoh_msg_close_resp(struct rpmem_msg_close_resp *msg)
489 {
490 rpmem_ntoh_msg_hdr_resp(&msg->hdr);
491 }
492
493 /*
494 * rpmem_hton_msg_close_resp -- convert rpmem_msg_close_resp to network byte
495 * order
496 */
497 static inline void
498 rpmem_hton_msg_close_resp(struct rpmem_msg_close_resp *msg)
499 {
500 rpmem_ntoh_msg_close_resp(msg);
501 }
502
503 /*
504 * pack_rpmem_pool_attr -- copy pool attributes to a packed structure
505 */
506 static inline void
507 pack_rpmem_pool_attr(const struct rpmem_pool_attr *src,
508 struct rpmem_pool_attr_packed *dst)
509 {
510 memcpy(dst->signature, src->signature, sizeof(src->signature));
511 dst->major = src->major;
512 dst->compat_features = src->compat_features;
513 dst->incompat_features = src->incompat_features;
514 dst->ro_compat_features = src->ro_compat_features;
515 memcpy(dst->poolset_uuid, src->poolset_uuid, sizeof(dst->poolset_uuid));
516 memcpy(dst->uuid, src->uuid, sizeof(dst->uuid));
517 memcpy(dst->next_uuid, src->next_uuid, sizeof(dst->next_uuid));
518 memcpy(dst->prev_uuid, src->prev_uuid, sizeof(dst->prev_uuid));
519 memcpy(dst->user_flags, src->user_flags, sizeof(dst->user_flags));
520 }
521
522 /*
523 * unpack_rpmem_pool_attr -- copy pool attributes to an unpacked structure
524 */
525 static inline void
526 unpack_rpmem_pool_attr(const struct rpmem_pool_attr_packed *src,
527 struct rpmem_pool_attr *dst)
528 {
529 memcpy(dst->signature, src->signature, sizeof(src->signature));
530 dst->major = src->major;
531 dst->compat_features = src->compat_features;
532 dst->incompat_features = src->incompat_features;
533 dst->ro_compat_features = src->ro_compat_features;
534 memcpy(dst->poolset_uuid, src->poolset_uuid, sizeof(dst->poolset_uuid));
535 memcpy(dst->uuid, src->uuid, sizeof(dst->uuid));
536 memcpy(dst->next_uuid, src->next_uuid, sizeof(dst->next_uuid));
537 memcpy(dst->prev_uuid, src->prev_uuid, sizeof(dst->prev_uuid));
538 memcpy(dst->user_flags, src->user_flags, sizeof(dst->user_flags));
539 }
540
541 #ifdef __cplusplus
542 }
543 #endif
544
545 #endif