1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright 2016-2020, Intel Corporation */
5 * rpmem_proto.h -- rpmem protocol definitions
9 #define RPMEM_PROTO_H 1
20 #define PACKED __attribute__((packed))
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
31 * rpmem_msg_type -- type of messages
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,
47 * rpmem_pool_attr_packed -- a packed version
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 */
63 * rpmem_msg_ibc_attr -- in-band connection attributes
65 * Used by create request response and open request response.
66 * Contains essential information to proceed with in-band connection
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 */
78 * rpmem_msg_pool_desc -- remote pool descriptor
80 struct rpmem_msg_pool_desc
{
81 uint32_t size
; /* size of pool descriptor */
82 uint8_t desc
[0]; /* pool descriptor, null-terminated string */
86 * rpmem_msg_hdr -- message header which consists of type and size of message
88 * The type must be one of the rpmem_msg_type values.
90 struct rpmem_msg_hdr
{
91 uint32_t type
; /* type of message */
92 uint64_t size
; /* size of message */
97 * rpmem_msg_hdr_resp -- message response header which consists of type, size
100 * The type must be one of the rpmem_msg_type values.
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 */
109 * rpmem_msg_common -- common fields for open/create messages
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 */
121 * rpmem_msg_create -- create request message
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
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 */
135 * rpmem_msg_create_resp -- create request response message
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).
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 */
146 * rpmem_msg_open -- open request message
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
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 */
159 * rpmem_msg_open_resp -- open request response message
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)
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 */
171 * rpmem_msg_close -- close request message
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)
176 struct rpmem_msg_close
{
177 struct rpmem_msg_hdr hdr
; /* message header */
178 uint32_t flags
; /* flags */
182 * rpmem_msg_close_resp -- close request response message
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)
187 struct rpmem_msg_close_resp
{
188 struct rpmem_msg_hdr_resp hdr
; /* message header */
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 */
197 /* the two least significant bits are reserved for mode of persist */
198 #define RPMEM_FLUSH_PERSIST_MASK 0x3U
200 #define RPMEM_PERSIST_MAX 2U /* maximum valid persist value */
203 * rpmem_msg_persist -- remote persist message
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 */
214 * rpmem_msg_persist_resp -- remote persist response message
216 struct rpmem_msg_persist_resp
{
217 uint32_t flags
; /* lane flags */
218 uint32_t lane
; /* lane identifier */
222 * rpmem_msg_set_attr -- set attributes request message
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)
227 struct rpmem_msg_set_attr
{
228 struct rpmem_msg_hdr hdr
; /* message header */
229 struct rpmem_pool_attr_packed pool_attr
; /* pool attributes */
233 * rpmem_msg_set_attr_resp -- set attributes request response message
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).
238 struct rpmem_msg_set_attr_resp
{
239 struct rpmem_msg_hdr_resp hdr
; /* message header */
243 * XXX Begin: Suppress gcc conversion warnings for FreeBSD be*toh macros.
245 #pragma GCC diagnostic push
246 #pragma GCC diagnostic ignored "-Wconversion"
248 * rpmem_ntoh_msg_ibc_attr -- convert rpmem_msg_ibc attr to host byte order
251 rpmem_ntoh_msg_ibc_attr(struct rpmem_msg_ibc_attr
*ibc
)
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
);
260 * rpmem_ntoh_msg_pool_desc -- convert rpmem_msg_pool_desc to host byte order
263 rpmem_ntoh_msg_pool_desc(struct rpmem_msg_pool_desc
*pool_desc
)
265 pool_desc
->size
= be32toh(pool_desc
->size
);
269 * rpmem_ntoh_pool_attr -- convert rpmem_pool_attr to host byte order
272 rpmem_ntoh_pool_attr(struct rpmem_pool_attr_packed
*attr
)
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
);
281 * rpmem_ntoh_msg_hdr -- convert rpmem_msg_hdr to host byte order
284 rpmem_ntoh_msg_hdr(struct rpmem_msg_hdr
*hdrp
)
286 hdrp
->type
= be32toh(hdrp
->type
);
287 hdrp
->size
= be64toh(hdrp
->size
);
291 * rpmem_hton_msg_hdr -- convert rpmem_msg_hdr to network byte order
294 rpmem_hton_msg_hdr(struct rpmem_msg_hdr
*hdrp
)
296 rpmem_ntoh_msg_hdr(hdrp
);
300 * rpmem_ntoh_msg_hdr_resp -- convert rpmem_msg_hdr_resp to host byte order
303 rpmem_ntoh_msg_hdr_resp(struct rpmem_msg_hdr_resp
*hdrp
)
305 hdrp
->status
= be32toh(hdrp
->status
);
306 hdrp
->type
= be32toh(hdrp
->type
);
307 hdrp
->size
= be64toh(hdrp
->size
);
311 * rpmem_hton_msg_hdr_resp -- convert rpmem_msg_hdr_resp to network byte order
314 rpmem_hton_msg_hdr_resp(struct rpmem_msg_hdr_resp
*hdrp
)
316 rpmem_ntoh_msg_hdr_resp(hdrp
);
320 * rpmem_ntoh_msg_common -- convert rpmem_msg_common to host byte order
323 rpmem_ntoh_msg_common(struct rpmem_msg_common
*msg
)
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
);
334 * rpmem_hton_msg_common -- convert rpmem_msg_common to network byte order
337 rpmem_hton_msg_common(struct rpmem_msg_common
*msg
)
339 rpmem_ntoh_msg_common(msg
);
343 * rpmem_ntoh_msg_create -- convert rpmem_msg_create to host byte order
346 rpmem_ntoh_msg_create(struct rpmem_msg_create
*msg
)
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
);
355 * rpmem_hton_msg_create -- convert rpmem_msg_create to network byte order
358 rpmem_hton_msg_create(struct rpmem_msg_create
*msg
)
360 rpmem_ntoh_msg_create(msg
);
364 * rpmem_ntoh_msg_create_resp -- convert rpmem_msg_create_resp to host byte
368 rpmem_ntoh_msg_create_resp(struct rpmem_msg_create_resp
*msg
)
370 rpmem_ntoh_msg_hdr_resp(&msg
->hdr
);
371 rpmem_ntoh_msg_ibc_attr(&msg
->ibc
);
375 * rpmem_hton_msg_create_resp -- convert rpmem_msg_create_resp to network byte
379 rpmem_hton_msg_create_resp(struct rpmem_msg_create_resp
*msg
)
381 rpmem_ntoh_msg_create_resp(msg
);
385 * rpmem_ntoh_msg_open -- convert rpmem_msg_open to host byte order
388 rpmem_ntoh_msg_open(struct rpmem_msg_open
*msg
)
390 rpmem_ntoh_msg_hdr(&msg
->hdr
);
391 rpmem_ntoh_msg_common(&msg
->c
);
392 rpmem_ntoh_msg_pool_desc(&msg
->pool_desc
);
395 * XXX End: Suppress gcc conversion warnings for FreeBSD be*toh macros
397 #pragma GCC diagnostic pop
399 * rpmem_hton_msg_open -- convert rpmem_msg_open to network byte order
402 rpmem_hton_msg_open(struct rpmem_msg_open
*msg
)
404 rpmem_ntoh_msg_open(msg
);
408 * rpmem_ntoh_msg_open_resp -- convert rpmem_msg_open_resp to host byte order
411 rpmem_ntoh_msg_open_resp(struct rpmem_msg_open_resp
*msg
)
413 rpmem_ntoh_msg_hdr_resp(&msg
->hdr
);
414 rpmem_ntoh_msg_ibc_attr(&msg
->ibc
);
415 rpmem_ntoh_pool_attr(&msg
->pool_attr
);
419 * rpmem_hton_msg_open_resp -- convert rpmem_msg_open_resp to network byte order
422 rpmem_hton_msg_open_resp(struct rpmem_msg_open_resp
*msg
)
424 rpmem_ntoh_msg_open_resp(msg
);
428 * rpmem_ntoh_msg_set_attr -- convert rpmem_msg_set_attr to host byte order
431 rpmem_ntoh_msg_set_attr(struct rpmem_msg_set_attr
*msg
)
433 rpmem_ntoh_msg_hdr(&msg
->hdr
);
434 rpmem_ntoh_pool_attr(&msg
->pool_attr
);
438 * rpmem_hton_msg_set_attr -- convert rpmem_msg_set_attr to network byte order
441 rpmem_hton_msg_set_attr(struct rpmem_msg_set_attr
*msg
)
443 rpmem_ntoh_msg_set_attr(msg
);
447 * rpmem_ntoh_msg_set_attr_resp -- convert rpmem_msg_set_attr_resp to host byte
451 rpmem_ntoh_msg_set_attr_resp(struct rpmem_msg_set_attr_resp
*msg
)
453 rpmem_ntoh_msg_hdr_resp(&msg
->hdr
);
457 * rpmem_hton_msg_set_attr_resp -- convert rpmem_msg_set_attr_resp to network
461 rpmem_hton_msg_set_attr_resp(struct rpmem_msg_set_attr_resp
*msg
)
463 rpmem_hton_msg_hdr_resp(&msg
->hdr
);
467 * rpmem_ntoh_msg_close -- convert rpmem_msg_close to host byte order
470 rpmem_ntoh_msg_close(struct rpmem_msg_close
*msg
)
472 rpmem_ntoh_msg_hdr(&msg
->hdr
);
476 * rpmem_hton_msg_close -- convert rpmem_msg_close to network byte order
479 rpmem_hton_msg_close(struct rpmem_msg_close
*msg
)
481 rpmem_ntoh_msg_close(msg
);
485 * rpmem_ntoh_msg_close_resp -- convert rpmem_msg_close_resp to host byte order
488 rpmem_ntoh_msg_close_resp(struct rpmem_msg_close_resp
*msg
)
490 rpmem_ntoh_msg_hdr_resp(&msg
->hdr
);
494 * rpmem_hton_msg_close_resp -- convert rpmem_msg_close_resp to network byte
498 rpmem_hton_msg_close_resp(struct rpmem_msg_close_resp
*msg
)
500 rpmem_ntoh_msg_close_resp(msg
);
504 * pack_rpmem_pool_attr -- copy pool attributes to a packed structure
507 pack_rpmem_pool_attr(const struct rpmem_pool_attr
*src
,
508 struct rpmem_pool_attr_packed
*dst
)
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
));
523 * unpack_rpmem_pool_attr -- copy pool attributes to an unpacked structure
526 unpack_rpmem_pool_attr(const struct rpmem_pool_attr_packed
*src
,
527 struct rpmem_pool_attr
*dst
)
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
));