162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci#ifndef __DRBD_PROTOCOL_H
362306a36Sopenharmony_ci#define __DRBD_PROTOCOL_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_cienum drbd_packet {
662306a36Sopenharmony_ci	/* receiver (data socket) */
762306a36Sopenharmony_ci	P_DATA		      = 0x00,
862306a36Sopenharmony_ci	P_DATA_REPLY	      = 0x01, /* Response to P_DATA_REQUEST */
962306a36Sopenharmony_ci	P_RS_DATA_REPLY	      = 0x02, /* Response to P_RS_DATA_REQUEST */
1062306a36Sopenharmony_ci	P_BARRIER	      = 0x03,
1162306a36Sopenharmony_ci	P_BITMAP	      = 0x04,
1262306a36Sopenharmony_ci	P_BECOME_SYNC_TARGET  = 0x05,
1362306a36Sopenharmony_ci	P_BECOME_SYNC_SOURCE  = 0x06,
1462306a36Sopenharmony_ci	P_UNPLUG_REMOTE	      = 0x07, /* Used at various times to hint the peer */
1562306a36Sopenharmony_ci	P_DATA_REQUEST	      = 0x08, /* Used to ask for a data block */
1662306a36Sopenharmony_ci	P_RS_DATA_REQUEST     = 0x09, /* Used to ask for a data block for resync */
1762306a36Sopenharmony_ci	P_SYNC_PARAM	      = 0x0a,
1862306a36Sopenharmony_ci	P_PROTOCOL	      = 0x0b,
1962306a36Sopenharmony_ci	P_UUIDS		      = 0x0c,
2062306a36Sopenharmony_ci	P_SIZES		      = 0x0d,
2162306a36Sopenharmony_ci	P_STATE		      = 0x0e,
2262306a36Sopenharmony_ci	P_SYNC_UUID	      = 0x0f,
2362306a36Sopenharmony_ci	P_AUTH_CHALLENGE      = 0x10,
2462306a36Sopenharmony_ci	P_AUTH_RESPONSE	      = 0x11,
2562306a36Sopenharmony_ci	P_STATE_CHG_REQ	      = 0x12,
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci	/* (meta socket) */
2862306a36Sopenharmony_ci	P_PING		      = 0x13,
2962306a36Sopenharmony_ci	P_PING_ACK	      = 0x14,
3062306a36Sopenharmony_ci	P_RECV_ACK	      = 0x15, /* Used in protocol B */
3162306a36Sopenharmony_ci	P_WRITE_ACK	      = 0x16, /* Used in protocol C */
3262306a36Sopenharmony_ci	P_RS_WRITE_ACK	      = 0x17, /* Is a P_WRITE_ACK, additionally call set_in_sync(). */
3362306a36Sopenharmony_ci	P_SUPERSEDED	      = 0x18, /* Used in proto C, two-primaries conflict detection */
3462306a36Sopenharmony_ci	P_NEG_ACK	      = 0x19, /* Sent if local disk is unusable */
3562306a36Sopenharmony_ci	P_NEG_DREPLY	      = 0x1a, /* Local disk is broken... */
3662306a36Sopenharmony_ci	P_NEG_RS_DREPLY	      = 0x1b, /* Local disk is broken... */
3762306a36Sopenharmony_ci	P_BARRIER_ACK	      = 0x1c,
3862306a36Sopenharmony_ci	P_STATE_CHG_REPLY     = 0x1d,
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci	/* "new" commands, no longer fitting into the ordering scheme above */
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci	P_OV_REQUEST	      = 0x1e, /* data socket */
4362306a36Sopenharmony_ci	P_OV_REPLY	      = 0x1f,
4462306a36Sopenharmony_ci	P_OV_RESULT	      = 0x20, /* meta socket */
4562306a36Sopenharmony_ci	P_CSUM_RS_REQUEST     = 0x21, /* data socket */
4662306a36Sopenharmony_ci	P_RS_IS_IN_SYNC	      = 0x22, /* meta socket */
4762306a36Sopenharmony_ci	P_SYNC_PARAM89	      = 0x23, /* data socket, protocol version 89 replacement for P_SYNC_PARAM */
4862306a36Sopenharmony_ci	P_COMPRESSED_BITMAP   = 0x24, /* compressed or otherwise encoded bitmap transfer */
4962306a36Sopenharmony_ci	/* P_CKPT_FENCE_REQ      = 0x25, * currently reserved for protocol D */
5062306a36Sopenharmony_ci	/* P_CKPT_DISABLE_REQ    = 0x26, * currently reserved for protocol D */
5162306a36Sopenharmony_ci	P_DELAY_PROBE         = 0x27, /* is used on BOTH sockets */
5262306a36Sopenharmony_ci	P_OUT_OF_SYNC         = 0x28, /* Mark as out of sync (Outrunning), data socket */
5362306a36Sopenharmony_ci	P_RS_CANCEL           = 0x29, /* meta: Used to cancel RS_DATA_REQUEST packet by SyncSource */
5462306a36Sopenharmony_ci	P_CONN_ST_CHG_REQ     = 0x2a, /* data sock: Connection wide state request */
5562306a36Sopenharmony_ci	P_CONN_ST_CHG_REPLY   = 0x2b, /* meta sock: Connection side state req reply */
5662306a36Sopenharmony_ci	P_RETRY_WRITE	      = 0x2c, /* Protocol C: retry conflicting write request */
5762306a36Sopenharmony_ci	P_PROTOCOL_UPDATE     = 0x2d, /* data sock: is used in established connections */
5862306a36Sopenharmony_ci        /* 0x2e to 0x30 reserved, used in drbd 9 */
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci	/* REQ_OP_DISCARD. We used "discard" in different contexts before,
6162306a36Sopenharmony_ci	 * which is why I chose TRIM here, to disambiguate. */
6262306a36Sopenharmony_ci	P_TRIM                = 0x31,
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci	/* Only use these two if both support FF_THIN_RESYNC */
6562306a36Sopenharmony_ci	P_RS_THIN_REQ         = 0x32, /* Request a block for resync or reply P_RS_DEALLOCATED */
6662306a36Sopenharmony_ci	P_RS_DEALLOCATED      = 0x33, /* Contains only zeros on sync source node */
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci	/* REQ_WRITE_SAME.
6962306a36Sopenharmony_ci	 * On a receiving side without REQ_WRITE_SAME,
7062306a36Sopenharmony_ci	 * we may fall back to an opencoded loop instead. */
7162306a36Sopenharmony_ci	P_WSAME               = 0x34,
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci	/* 0x35 already claimed in DRBD 9 */
7462306a36Sopenharmony_ci	P_ZEROES              = 0x36, /* data sock: zero-out, WRITE_ZEROES */
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci	/* 0x40 .. 0x48 already claimed in DRBD 9 */
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci	P_MAY_IGNORE	      = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */
7962306a36Sopenharmony_ci	P_MAX_OPT_CMD	      = 0x101,
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci	/* special command ids for handshake */
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci	P_INITIAL_META	      = 0xfff1, /* First Packet on the MetaSock */
8462306a36Sopenharmony_ci	P_INITIAL_DATA	      = 0xfff2, /* First Packet on the Socket */
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci	P_CONNECTION_FEATURES = 0xfffe	/* FIXED for the next century! */
8762306a36Sopenharmony_ci};
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#ifndef __packed
9062306a36Sopenharmony_ci#define __packed __attribute__((packed))
9162306a36Sopenharmony_ci#endif
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci/* This is the layout for a packet on the wire.
9462306a36Sopenharmony_ci * The byteorder is the network byte order.
9562306a36Sopenharmony_ci *     (except block_id and barrier fields.
9662306a36Sopenharmony_ci *	these are pointers to local structs
9762306a36Sopenharmony_ci *	and have no relevance for the partner,
9862306a36Sopenharmony_ci *	which just echoes them as received.)
9962306a36Sopenharmony_ci *
10062306a36Sopenharmony_ci * NOTE that the payload starts at a long aligned offset,
10162306a36Sopenharmony_ci * regardless of 32 or 64 bit arch!
10262306a36Sopenharmony_ci */
10362306a36Sopenharmony_cistruct p_header80 {
10462306a36Sopenharmony_ci	u32	  magic;
10562306a36Sopenharmony_ci	u16	  command;
10662306a36Sopenharmony_ci	u16	  length;	/* bytes of data after this header */
10762306a36Sopenharmony_ci} __packed;
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci/* Header for big packets, Used for data packets exceeding 64kB */
11062306a36Sopenharmony_cistruct p_header95 {
11162306a36Sopenharmony_ci	u16	  magic;	/* use DRBD_MAGIC_BIG here */
11262306a36Sopenharmony_ci	u16	  command;
11362306a36Sopenharmony_ci	u32	  length;
11462306a36Sopenharmony_ci} __packed;
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_cistruct p_header100 {
11762306a36Sopenharmony_ci	u32	  magic;
11862306a36Sopenharmony_ci	u16	  volume;
11962306a36Sopenharmony_ci	u16	  command;
12062306a36Sopenharmony_ci	u32	  length;
12162306a36Sopenharmony_ci	u32	  pad;
12262306a36Sopenharmony_ci} __packed;
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci/* These defines must not be changed without changing the protocol version.
12562306a36Sopenharmony_ci * New defines may only be introduced together with protocol version bump or
12662306a36Sopenharmony_ci * new protocol feature flags.
12762306a36Sopenharmony_ci */
12862306a36Sopenharmony_ci#define DP_HARDBARRIER	      1 /* no longer used */
12962306a36Sopenharmony_ci#define DP_RW_SYNC	      2 /* equals REQ_SYNC    */
13062306a36Sopenharmony_ci#define DP_MAY_SET_IN_SYNC    4
13162306a36Sopenharmony_ci#define DP_UNPLUG             8 /* not used anymore   */
13262306a36Sopenharmony_ci#define DP_FUA               16 /* equals REQ_FUA     */
13362306a36Sopenharmony_ci#define DP_FLUSH             32 /* equals REQ_PREFLUSH   */
13462306a36Sopenharmony_ci#define DP_DISCARD           64 /* equals REQ_OP_DISCARD */
13562306a36Sopenharmony_ci#define DP_SEND_RECEIVE_ACK 128 /* This is a proto B write request */
13662306a36Sopenharmony_ci#define DP_SEND_WRITE_ACK   256 /* This is a proto C write request */
13762306a36Sopenharmony_ci#define DP_WSAME            512 /* equiv. REQ_WRITE_SAME */
13862306a36Sopenharmony_ci#define DP_ZEROES          1024 /* equiv. REQ_OP_WRITE_ZEROES */
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci/* possible combinations:
14162306a36Sopenharmony_ci * REQ_OP_WRITE_ZEROES:  DP_DISCARD | DP_ZEROES
14262306a36Sopenharmony_ci * REQ_OP_WRITE_ZEROES + REQ_NOUNMAP: DP_ZEROES
14362306a36Sopenharmony_ci */
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_cistruct p_data {
14662306a36Sopenharmony_ci	u64	    sector;    /* 64 bits sector number */
14762306a36Sopenharmony_ci	u64	    block_id;  /* to identify the request in protocol B&C */
14862306a36Sopenharmony_ci	u32	    seq_num;
14962306a36Sopenharmony_ci	u32	    dp_flags;
15062306a36Sopenharmony_ci} __packed;
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_cistruct p_trim {
15362306a36Sopenharmony_ci	struct p_data p_data;
15462306a36Sopenharmony_ci	u32	    size;	/* == bio->bi_size */
15562306a36Sopenharmony_ci} __packed;
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_cistruct p_wsame {
15862306a36Sopenharmony_ci	struct p_data p_data;
15962306a36Sopenharmony_ci	u32           size;     /* == bio->bi_size */
16062306a36Sopenharmony_ci} __packed;
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ci/*
16362306a36Sopenharmony_ci * commands which share a struct:
16462306a36Sopenharmony_ci *  p_block_ack:
16562306a36Sopenharmony_ci *   P_RECV_ACK (proto B), P_WRITE_ACK (proto C),
16662306a36Sopenharmony_ci *   P_SUPERSEDED (proto C, two-primaries conflict detection)
16762306a36Sopenharmony_ci *  p_block_req:
16862306a36Sopenharmony_ci *   P_DATA_REQUEST, P_RS_DATA_REQUEST
16962306a36Sopenharmony_ci */
17062306a36Sopenharmony_cistruct p_block_ack {
17162306a36Sopenharmony_ci	u64	    sector;
17262306a36Sopenharmony_ci	u64	    block_id;
17362306a36Sopenharmony_ci	u32	    blksize;
17462306a36Sopenharmony_ci	u32	    seq_num;
17562306a36Sopenharmony_ci} __packed;
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_cistruct p_block_req {
17862306a36Sopenharmony_ci	u64 sector;
17962306a36Sopenharmony_ci	u64 block_id;
18062306a36Sopenharmony_ci	u32 blksize;
18162306a36Sopenharmony_ci	u32 pad;	/* to multiple of 8 Byte */
18262306a36Sopenharmony_ci} __packed;
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci/*
18562306a36Sopenharmony_ci * commands with their own struct for additional fields:
18662306a36Sopenharmony_ci *   P_CONNECTION_FEATURES
18762306a36Sopenharmony_ci *   P_BARRIER
18862306a36Sopenharmony_ci *   P_BARRIER_ACK
18962306a36Sopenharmony_ci *   P_SYNC_PARAM
19062306a36Sopenharmony_ci *   ReportParams
19162306a36Sopenharmony_ci */
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci/* supports TRIM/DISCARD on the "wire" protocol */
19462306a36Sopenharmony_ci#define DRBD_FF_TRIM 1
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci/* Detect all-zeros during resync, and rather TRIM/UNMAP/DISCARD those blocks
19762306a36Sopenharmony_ci * instead of fully allocate a supposedly thin volume on initial resync */
19862306a36Sopenharmony_ci#define DRBD_FF_THIN_RESYNC 2
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_ci/* supports REQ_WRITE_SAME on the "wire" protocol.
20162306a36Sopenharmony_ci * Note: this flag is overloaded,
20262306a36Sopenharmony_ci * its presence also
20362306a36Sopenharmony_ci *   - indicates support for 128 MiB "batch bios",
20462306a36Sopenharmony_ci *     max discard size of 128 MiB
20562306a36Sopenharmony_ci *     instead of 4M before that.
20662306a36Sopenharmony_ci *   - indicates that we exchange additional settings in p_sizes
20762306a36Sopenharmony_ci *     drbd_send_sizes()/receive_sizes()
20862306a36Sopenharmony_ci */
20962306a36Sopenharmony_ci#define DRBD_FF_WSAME 4
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci/* supports REQ_OP_WRITE_ZEROES on the "wire" protocol.
21262306a36Sopenharmony_ci *
21362306a36Sopenharmony_ci * We used to map that to "discard" on the sending side, and if we cannot
21462306a36Sopenharmony_ci * guarantee that discard zeroes data, the receiving side would map discard
21562306a36Sopenharmony_ci * back to zero-out.
21662306a36Sopenharmony_ci *
21762306a36Sopenharmony_ci * With the introduction of REQ_OP_WRITE_ZEROES,
21862306a36Sopenharmony_ci * we started to use that for both WRITE_ZEROES and DISCARDS,
21962306a36Sopenharmony_ci * hoping that WRITE_ZEROES would "do what we want",
22062306a36Sopenharmony_ci * UNMAP if possible, zero-out the rest.
22162306a36Sopenharmony_ci *
22262306a36Sopenharmony_ci * The example scenario is some LVM "thin" backend.
22362306a36Sopenharmony_ci *
22462306a36Sopenharmony_ci * While an un-allocated block on dm-thin reads as zeroes, on a dm-thin
22562306a36Sopenharmony_ci * with "skip_block_zeroing=true", after a partial block write allocated
22662306a36Sopenharmony_ci * that block, that same block may well map "undefined old garbage" from
22762306a36Sopenharmony_ci * the backends on LBAs that have not yet been written to.
22862306a36Sopenharmony_ci *
22962306a36Sopenharmony_ci * If we cannot distinguish between zero-out and discard on the receiving
23062306a36Sopenharmony_ci * side, to avoid "undefined old garbage" to pop up randomly at later times
23162306a36Sopenharmony_ci * on supposedly zero-initialized blocks, we'd need to map all discards to
23262306a36Sopenharmony_ci * zero-out on the receiving side.  But that would potentially do a full
23362306a36Sopenharmony_ci * alloc on thinly provisioned backends, even when the expectation was to
23462306a36Sopenharmony_ci * unmap/trim/discard/de-allocate.
23562306a36Sopenharmony_ci *
23662306a36Sopenharmony_ci * We need to distinguish on the protocol level, whether we need to guarantee
23762306a36Sopenharmony_ci * zeroes (and thus use zero-out, potentially doing the mentioned full-alloc),
23862306a36Sopenharmony_ci * or if we want to put the emphasis on discard, and only do a "best effort
23962306a36Sopenharmony_ci * zeroing" (by "discarding" blocks aligned to discard-granularity, and zeroing
24062306a36Sopenharmony_ci * only potential unaligned head and tail clippings), to at least *try* to
24162306a36Sopenharmony_ci * avoid "false positives" in an online-verify later, hoping that someone
24262306a36Sopenharmony_ci * set skip_block_zeroing=false.
24362306a36Sopenharmony_ci */
24462306a36Sopenharmony_ci#define DRBD_FF_WZEROES 8
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_ci
24762306a36Sopenharmony_cistruct p_connection_features {
24862306a36Sopenharmony_ci	u32 protocol_min;
24962306a36Sopenharmony_ci	u32 feature_flags;
25062306a36Sopenharmony_ci	u32 protocol_max;
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci	/* should be more than enough for future enhancements
25362306a36Sopenharmony_ci	 * for now, feature_flags and the reserved array shall be zero.
25462306a36Sopenharmony_ci	 */
25562306a36Sopenharmony_ci
25662306a36Sopenharmony_ci	u32 _pad;
25762306a36Sopenharmony_ci	u64 reserved[7];
25862306a36Sopenharmony_ci} __packed;
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_cistruct p_barrier {
26162306a36Sopenharmony_ci	u32 barrier;	/* barrier number _handle_ only */
26262306a36Sopenharmony_ci	u32 pad;	/* to multiple of 8 Byte */
26362306a36Sopenharmony_ci} __packed;
26462306a36Sopenharmony_ci
26562306a36Sopenharmony_cistruct p_barrier_ack {
26662306a36Sopenharmony_ci	u32 barrier;
26762306a36Sopenharmony_ci	u32 set_size;
26862306a36Sopenharmony_ci} __packed;
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_cistruct p_rs_param {
27162306a36Sopenharmony_ci	u32 resync_rate;
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ci	      /* Since protocol version 88 and higher. */
27462306a36Sopenharmony_ci	char verify_alg[];
27562306a36Sopenharmony_ci} __packed;
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_cistruct p_rs_param_89 {
27862306a36Sopenharmony_ci	u32 resync_rate;
27962306a36Sopenharmony_ci	/* protocol version 89: */
28062306a36Sopenharmony_ci	char verify_alg[SHARED_SECRET_MAX];
28162306a36Sopenharmony_ci	char csums_alg[SHARED_SECRET_MAX];
28262306a36Sopenharmony_ci} __packed;
28362306a36Sopenharmony_ci
28462306a36Sopenharmony_cistruct p_rs_param_95 {
28562306a36Sopenharmony_ci	u32 resync_rate;
28662306a36Sopenharmony_ci	struct_group(algs,
28762306a36Sopenharmony_ci		char verify_alg[SHARED_SECRET_MAX];
28862306a36Sopenharmony_ci		char csums_alg[SHARED_SECRET_MAX];
28962306a36Sopenharmony_ci	);
29062306a36Sopenharmony_ci	u32 c_plan_ahead;
29162306a36Sopenharmony_ci	u32 c_delay_target;
29262306a36Sopenharmony_ci	u32 c_fill_target;
29362306a36Sopenharmony_ci	u32 c_max_rate;
29462306a36Sopenharmony_ci} __packed;
29562306a36Sopenharmony_ci
29662306a36Sopenharmony_cienum drbd_conn_flags {
29762306a36Sopenharmony_ci	CF_DISCARD_MY_DATA = 1,
29862306a36Sopenharmony_ci	CF_DRY_RUN = 2,
29962306a36Sopenharmony_ci};
30062306a36Sopenharmony_ci
30162306a36Sopenharmony_cistruct p_protocol {
30262306a36Sopenharmony_ci	u32 protocol;
30362306a36Sopenharmony_ci	u32 after_sb_0p;
30462306a36Sopenharmony_ci	u32 after_sb_1p;
30562306a36Sopenharmony_ci	u32 after_sb_2p;
30662306a36Sopenharmony_ci	u32 conn_flags;
30762306a36Sopenharmony_ci	u32 two_primaries;
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ci	/* Since protocol version 87 and higher. */
31062306a36Sopenharmony_ci	char integrity_alg[];
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_ci} __packed;
31362306a36Sopenharmony_ci
31462306a36Sopenharmony_cistruct p_uuids {
31562306a36Sopenharmony_ci	u64 uuid[UI_EXTENDED_SIZE];
31662306a36Sopenharmony_ci} __packed;
31762306a36Sopenharmony_ci
31862306a36Sopenharmony_cistruct p_rs_uuid {
31962306a36Sopenharmony_ci	u64	    uuid;
32062306a36Sopenharmony_ci} __packed;
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_ci/* optional queue_limits if (agreed_features & DRBD_FF_WSAME)
32362306a36Sopenharmony_ci * see also struct queue_limits, as of late 2015 */
32462306a36Sopenharmony_cistruct o_qlim {
32562306a36Sopenharmony_ci	/* we don't need it yet, but we may as well communicate it now */
32662306a36Sopenharmony_ci	u32 physical_block_size;
32762306a36Sopenharmony_ci
32862306a36Sopenharmony_ci	/* so the original in struct queue_limits is unsigned short,
32962306a36Sopenharmony_ci	 * but I'd have to put in padding anyways. */
33062306a36Sopenharmony_ci	u32 logical_block_size;
33162306a36Sopenharmony_ci
33262306a36Sopenharmony_ci	/* One incoming bio becomes one DRBD request,
33362306a36Sopenharmony_ci	 * which may be translated to several bio on the receiving side.
33462306a36Sopenharmony_ci	 * We don't need to communicate chunk/boundary/segment ... limits.
33562306a36Sopenharmony_ci	 */
33662306a36Sopenharmony_ci
33762306a36Sopenharmony_ci	/* various IO hints may be useful with "diskless client" setups */
33862306a36Sopenharmony_ci	u32 alignment_offset;
33962306a36Sopenharmony_ci	u32 io_min;
34062306a36Sopenharmony_ci	u32 io_opt;
34162306a36Sopenharmony_ci
34262306a36Sopenharmony_ci	/* We may need to communicate integrity stuff at some point,
34362306a36Sopenharmony_ci	 * but let's not get ahead of ourselves. */
34462306a36Sopenharmony_ci
34562306a36Sopenharmony_ci	/* Backend discard capabilities.
34662306a36Sopenharmony_ci	 * Receiving side uses "blkdev_issue_discard()", no need to communicate
34762306a36Sopenharmony_ci	 * more specifics.  If the backend cannot do discards, the DRBD peer
34862306a36Sopenharmony_ci	 * may fall back to blkdev_issue_zeroout().
34962306a36Sopenharmony_ci	 */
35062306a36Sopenharmony_ci	u8 discard_enabled;
35162306a36Sopenharmony_ci	u8 discard_zeroes_data;
35262306a36Sopenharmony_ci	u8 write_same_capable;
35362306a36Sopenharmony_ci	u8 _pad;
35462306a36Sopenharmony_ci} __packed;
35562306a36Sopenharmony_ci
35662306a36Sopenharmony_cistruct p_sizes {
35762306a36Sopenharmony_ci	u64	    d_size;  /* size of disk */
35862306a36Sopenharmony_ci	u64	    u_size;  /* user requested size */
35962306a36Sopenharmony_ci	u64	    c_size;  /* current exported size */
36062306a36Sopenharmony_ci	u32	    max_bio_size;  /* Maximal size of a BIO */
36162306a36Sopenharmony_ci	u16	    queue_order_type;  /* not yet implemented in DRBD*/
36262306a36Sopenharmony_ci	u16	    dds_flags; /* use enum dds_flags here. */
36362306a36Sopenharmony_ci
36462306a36Sopenharmony_ci	/* optional queue_limits if (agreed_features & DRBD_FF_WSAME) */
36562306a36Sopenharmony_ci	struct o_qlim qlim[];
36662306a36Sopenharmony_ci} __packed;
36762306a36Sopenharmony_ci
36862306a36Sopenharmony_cistruct p_state {
36962306a36Sopenharmony_ci	u32	    state;
37062306a36Sopenharmony_ci} __packed;
37162306a36Sopenharmony_ci
37262306a36Sopenharmony_cistruct p_req_state {
37362306a36Sopenharmony_ci	u32	    mask;
37462306a36Sopenharmony_ci	u32	    val;
37562306a36Sopenharmony_ci} __packed;
37662306a36Sopenharmony_ci
37762306a36Sopenharmony_cistruct p_req_state_reply {
37862306a36Sopenharmony_ci	u32	    retcode;
37962306a36Sopenharmony_ci} __packed;
38062306a36Sopenharmony_ci
38162306a36Sopenharmony_cistruct p_drbd06_param {
38262306a36Sopenharmony_ci	u64	  size;
38362306a36Sopenharmony_ci	u32	  state;
38462306a36Sopenharmony_ci	u32	  blksize;
38562306a36Sopenharmony_ci	u32	  protocol;
38662306a36Sopenharmony_ci	u32	  version;
38762306a36Sopenharmony_ci	u32	  gen_cnt[5];
38862306a36Sopenharmony_ci	u32	  bit_map_gen[5];
38962306a36Sopenharmony_ci} __packed;
39062306a36Sopenharmony_ci
39162306a36Sopenharmony_cistruct p_block_desc {
39262306a36Sopenharmony_ci	u64 sector;
39362306a36Sopenharmony_ci	u32 blksize;
39462306a36Sopenharmony_ci	u32 pad;	/* to multiple of 8 Byte */
39562306a36Sopenharmony_ci} __packed;
39662306a36Sopenharmony_ci
39762306a36Sopenharmony_ci/* Valid values for the encoding field.
39862306a36Sopenharmony_ci * Bump proto version when changing this. */
39962306a36Sopenharmony_cienum drbd_bitmap_code {
40062306a36Sopenharmony_ci	/* RLE_VLI_Bytes = 0,
40162306a36Sopenharmony_ci	 * and other bit variants had been defined during
40262306a36Sopenharmony_ci	 * algorithm evaluation. */
40362306a36Sopenharmony_ci	RLE_VLI_Bits = 2,
40462306a36Sopenharmony_ci};
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_cistruct p_compressed_bm {
40762306a36Sopenharmony_ci	/* (encoding & 0x0f): actual encoding, see enum drbd_bitmap_code
40862306a36Sopenharmony_ci	 * (encoding & 0x80): polarity (set/unset) of first runlength
40962306a36Sopenharmony_ci	 * ((encoding >> 4) & 0x07): pad_bits, number of trailing zero bits
41062306a36Sopenharmony_ci	 * used to pad up to head.length bytes
41162306a36Sopenharmony_ci	 */
41262306a36Sopenharmony_ci	u8 encoding;
41362306a36Sopenharmony_ci
41462306a36Sopenharmony_ci	u8 code[];
41562306a36Sopenharmony_ci} __packed;
41662306a36Sopenharmony_ci
41762306a36Sopenharmony_cistruct p_delay_probe93 {
41862306a36Sopenharmony_ci	u32     seq_num; /* sequence number to match the two probe packets */
41962306a36Sopenharmony_ci	u32     offset;  /* usecs the probe got sent after the reference time point */
42062306a36Sopenharmony_ci} __packed;
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ci/*
42362306a36Sopenharmony_ci * Bitmap packets need to fit within a single page on the sender and receiver,
42462306a36Sopenharmony_ci * so we are limited to 4 KiB (and not to PAGE_SIZE, which can be bigger).
42562306a36Sopenharmony_ci */
42662306a36Sopenharmony_ci#define DRBD_SOCKET_BUFFER_SIZE 4096
42762306a36Sopenharmony_ci
42862306a36Sopenharmony_ci#endif  /* __DRBD_PROTOCOL_H */
429