162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
262306a36Sopenharmony_ci#ifndef USER_BLK_DRV_CMD_INC_H
362306a36Sopenharmony_ci#define USER_BLK_DRV_CMD_INC_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/types.h>
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci/* ublk server command definition */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci/*
1062306a36Sopenharmony_ci * Admin commands, issued by ublk server, and handled by ublk driver.
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci * Legacy command definition, don't use in new application, and don't
1362306a36Sopenharmony_ci * add new such definition any more
1462306a36Sopenharmony_ci */
1562306a36Sopenharmony_ci#define	UBLK_CMD_GET_QUEUE_AFFINITY	0x01
1662306a36Sopenharmony_ci#define	UBLK_CMD_GET_DEV_INFO	0x02
1762306a36Sopenharmony_ci#define	UBLK_CMD_ADD_DEV		0x04
1862306a36Sopenharmony_ci#define	UBLK_CMD_DEL_DEV		0x05
1962306a36Sopenharmony_ci#define	UBLK_CMD_START_DEV	0x06
2062306a36Sopenharmony_ci#define	UBLK_CMD_STOP_DEV	0x07
2162306a36Sopenharmony_ci#define	UBLK_CMD_SET_PARAMS	0x08
2262306a36Sopenharmony_ci#define	UBLK_CMD_GET_PARAMS	0x09
2362306a36Sopenharmony_ci#define	UBLK_CMD_START_USER_RECOVERY	0x10
2462306a36Sopenharmony_ci#define	UBLK_CMD_END_USER_RECOVERY	0x11
2562306a36Sopenharmony_ci#define	UBLK_CMD_GET_DEV_INFO2		0x12
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci/* Any new ctrl command should encode by __IO*() */
2862306a36Sopenharmony_ci#define UBLK_U_CMD_GET_QUEUE_AFFINITY	\
2962306a36Sopenharmony_ci	_IOR('u', UBLK_CMD_GET_QUEUE_AFFINITY, struct ublksrv_ctrl_cmd)
3062306a36Sopenharmony_ci#define UBLK_U_CMD_GET_DEV_INFO		\
3162306a36Sopenharmony_ci	_IOR('u', UBLK_CMD_GET_DEV_INFO, struct ublksrv_ctrl_cmd)
3262306a36Sopenharmony_ci#define UBLK_U_CMD_ADD_DEV		\
3362306a36Sopenharmony_ci	_IOWR('u', UBLK_CMD_ADD_DEV, struct ublksrv_ctrl_cmd)
3462306a36Sopenharmony_ci#define UBLK_U_CMD_DEL_DEV		\
3562306a36Sopenharmony_ci	_IOWR('u', UBLK_CMD_DEL_DEV, struct ublksrv_ctrl_cmd)
3662306a36Sopenharmony_ci#define UBLK_U_CMD_START_DEV		\
3762306a36Sopenharmony_ci	_IOWR('u', UBLK_CMD_START_DEV, struct ublksrv_ctrl_cmd)
3862306a36Sopenharmony_ci#define UBLK_U_CMD_STOP_DEV		\
3962306a36Sopenharmony_ci	_IOWR('u', UBLK_CMD_STOP_DEV, struct ublksrv_ctrl_cmd)
4062306a36Sopenharmony_ci#define UBLK_U_CMD_SET_PARAMS		\
4162306a36Sopenharmony_ci	_IOWR('u', UBLK_CMD_SET_PARAMS, struct ublksrv_ctrl_cmd)
4262306a36Sopenharmony_ci#define UBLK_U_CMD_GET_PARAMS		\
4362306a36Sopenharmony_ci	_IOR('u', UBLK_CMD_GET_PARAMS, struct ublksrv_ctrl_cmd)
4462306a36Sopenharmony_ci#define UBLK_U_CMD_START_USER_RECOVERY	\
4562306a36Sopenharmony_ci	_IOWR('u', UBLK_CMD_START_USER_RECOVERY, struct ublksrv_ctrl_cmd)
4662306a36Sopenharmony_ci#define UBLK_U_CMD_END_USER_RECOVERY	\
4762306a36Sopenharmony_ci	_IOWR('u', UBLK_CMD_END_USER_RECOVERY, struct ublksrv_ctrl_cmd)
4862306a36Sopenharmony_ci#define UBLK_U_CMD_GET_DEV_INFO2	\
4962306a36Sopenharmony_ci	_IOR('u', UBLK_CMD_GET_DEV_INFO2, struct ublksrv_ctrl_cmd)
5062306a36Sopenharmony_ci#define UBLK_U_CMD_GET_FEATURES	\
5162306a36Sopenharmony_ci	_IOR('u', 0x13, struct ublksrv_ctrl_cmd)
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci/*
5462306a36Sopenharmony_ci * 64bits are enough now, and it should be easy to extend in case of
5562306a36Sopenharmony_ci * running out of feature flags
5662306a36Sopenharmony_ci */
5762306a36Sopenharmony_ci#define UBLK_FEATURES_LEN  8
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci/*
6062306a36Sopenharmony_ci * IO commands, issued by ublk server, and handled by ublk driver.
6162306a36Sopenharmony_ci *
6262306a36Sopenharmony_ci * FETCH_REQ: issued via sqe(URING_CMD) beforehand for fetching IO request
6362306a36Sopenharmony_ci *      from ublk driver, should be issued only when starting device. After
6462306a36Sopenharmony_ci *      the associated cqe is returned, request's tag can be retrieved via
6562306a36Sopenharmony_ci *      cqe->userdata.
6662306a36Sopenharmony_ci *
6762306a36Sopenharmony_ci * COMMIT_AND_FETCH_REQ: issued via sqe(URING_CMD) after ublkserver handled
6862306a36Sopenharmony_ci *      this IO request, request's handling result is committed to ublk
6962306a36Sopenharmony_ci *      driver, meantime FETCH_REQ is piggyback, and FETCH_REQ has to be
7062306a36Sopenharmony_ci *      handled before completing io request.
7162306a36Sopenharmony_ci *
7262306a36Sopenharmony_ci * NEED_GET_DATA: only used for write requests to set io addr and copy data
7362306a36Sopenharmony_ci *      When NEED_GET_DATA is set, ublksrv has to issue UBLK_IO_NEED_GET_DATA
7462306a36Sopenharmony_ci *      command after ublk driver returns UBLK_IO_RES_NEED_GET_DATA.
7562306a36Sopenharmony_ci *
7662306a36Sopenharmony_ci *      It is only used if ublksrv set UBLK_F_NEED_GET_DATA flag
7762306a36Sopenharmony_ci *      while starting a ublk device.
7862306a36Sopenharmony_ci */
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci/*
8162306a36Sopenharmony_ci * Legacy IO command definition, don't use in new application, and don't
8262306a36Sopenharmony_ci * add new such definition any more
8362306a36Sopenharmony_ci */
8462306a36Sopenharmony_ci#define	UBLK_IO_FETCH_REQ		0x20
8562306a36Sopenharmony_ci#define	UBLK_IO_COMMIT_AND_FETCH_REQ	0x21
8662306a36Sopenharmony_ci#define	UBLK_IO_NEED_GET_DATA	0x22
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci/* Any new IO command should encode by __IOWR() */
8962306a36Sopenharmony_ci#define	UBLK_U_IO_FETCH_REQ		\
9062306a36Sopenharmony_ci	_IOWR('u', UBLK_IO_FETCH_REQ, struct ublksrv_io_cmd)
9162306a36Sopenharmony_ci#define	UBLK_U_IO_COMMIT_AND_FETCH_REQ	\
9262306a36Sopenharmony_ci	_IOWR('u', UBLK_IO_COMMIT_AND_FETCH_REQ, struct ublksrv_io_cmd)
9362306a36Sopenharmony_ci#define	UBLK_U_IO_NEED_GET_DATA		\
9462306a36Sopenharmony_ci	_IOWR('u', UBLK_IO_NEED_GET_DATA, struct ublksrv_io_cmd)
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci/* only ABORT means that no re-fetch */
9762306a36Sopenharmony_ci#define UBLK_IO_RES_OK			0
9862306a36Sopenharmony_ci#define UBLK_IO_RES_NEED_GET_DATA	1
9962306a36Sopenharmony_ci#define UBLK_IO_RES_ABORT		(-ENODEV)
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci#define UBLKSRV_CMD_BUF_OFFSET	0
10262306a36Sopenharmony_ci#define UBLKSRV_IO_BUF_OFFSET	0x80000000
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci/* tag bit is 16bit, so far limit at most 4096 IOs for each queue */
10562306a36Sopenharmony_ci#define UBLK_MAX_QUEUE_DEPTH	4096
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci/* single IO buffer max size is 32MB */
10862306a36Sopenharmony_ci#define UBLK_IO_BUF_OFF		0
10962306a36Sopenharmony_ci#define UBLK_IO_BUF_BITS	25
11062306a36Sopenharmony_ci#define UBLK_IO_BUF_BITS_MASK	((1ULL << UBLK_IO_BUF_BITS) - 1)
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci/* so at most 64K IOs for each queue */
11362306a36Sopenharmony_ci#define UBLK_TAG_OFF		UBLK_IO_BUF_BITS
11462306a36Sopenharmony_ci#define UBLK_TAG_BITS		16
11562306a36Sopenharmony_ci#define UBLK_TAG_BITS_MASK	((1ULL << UBLK_TAG_BITS) - 1)
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci/* max 4096 queues */
11862306a36Sopenharmony_ci#define UBLK_QID_OFF		(UBLK_TAG_OFF + UBLK_TAG_BITS)
11962306a36Sopenharmony_ci#define UBLK_QID_BITS		12
12062306a36Sopenharmony_ci#define UBLK_QID_BITS_MASK	((1ULL << UBLK_QID_BITS) - 1)
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci#define UBLK_MAX_NR_QUEUES	(1U << UBLK_QID_BITS)
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci#define UBLKSRV_IO_BUF_TOTAL_BITS	(UBLK_QID_OFF + UBLK_QID_BITS)
12562306a36Sopenharmony_ci#define UBLKSRV_IO_BUF_TOTAL_SIZE	(1ULL << UBLKSRV_IO_BUF_TOTAL_BITS)
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci/*
12862306a36Sopenharmony_ci * zero copy requires 4k block size, and can remap ublk driver's io
12962306a36Sopenharmony_ci * request into ublksrv's vm space
13062306a36Sopenharmony_ci */
13162306a36Sopenharmony_ci#define UBLK_F_SUPPORT_ZERO_COPY	(1ULL << 0)
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci/*
13462306a36Sopenharmony_ci * Force to complete io cmd via io_uring_cmd_complete_in_task so that
13562306a36Sopenharmony_ci * performance comparison is done easily with using task_work_add
13662306a36Sopenharmony_ci */
13762306a36Sopenharmony_ci#define UBLK_F_URING_CMD_COMP_IN_TASK	(1ULL << 1)
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci/*
14062306a36Sopenharmony_ci * User should issue io cmd again for write requests to
14162306a36Sopenharmony_ci * set io buffer address and copy data from bio vectors
14262306a36Sopenharmony_ci * to the userspace io buffer.
14362306a36Sopenharmony_ci *
14462306a36Sopenharmony_ci * In this mode, task_work is not used.
14562306a36Sopenharmony_ci */
14662306a36Sopenharmony_ci#define UBLK_F_NEED_GET_DATA (1UL << 2)
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci#define UBLK_F_USER_RECOVERY	(1UL << 3)
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci#define UBLK_F_USER_RECOVERY_REISSUE	(1UL << 4)
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci/*
15362306a36Sopenharmony_ci * Unprivileged user can create /dev/ublkcN and /dev/ublkbN.
15462306a36Sopenharmony_ci *
15562306a36Sopenharmony_ci * /dev/ublk-control needs to be available for unprivileged user, and it
15662306a36Sopenharmony_ci * can be done via udev rule to make all control commands available to
15762306a36Sopenharmony_ci * unprivileged user. Except for the command of UBLK_CMD_ADD_DEV, all
15862306a36Sopenharmony_ci * other commands are only allowed for the owner of the specified device.
15962306a36Sopenharmony_ci *
16062306a36Sopenharmony_ci * When userspace sends UBLK_CMD_ADD_DEV, the device pair's owner_uid and
16162306a36Sopenharmony_ci * owner_gid are stored to ublksrv_ctrl_dev_info by kernel, so far only
16262306a36Sopenharmony_ci * the current user's uid/gid is stored, that said owner of the created
16362306a36Sopenharmony_ci * device is always the current user.
16462306a36Sopenharmony_ci *
16562306a36Sopenharmony_ci * We still need udev rule to apply OWNER/GROUP with the stored owner_uid
16662306a36Sopenharmony_ci * and owner_gid.
16762306a36Sopenharmony_ci *
16862306a36Sopenharmony_ci * Then ublk server can be run as unprivileged user, and /dev/ublkbN can
16962306a36Sopenharmony_ci * be accessed and managed by its owner represented by owner_uid/owner_gid.
17062306a36Sopenharmony_ci */
17162306a36Sopenharmony_ci#define UBLK_F_UNPRIVILEGED_DEV	(1UL << 5)
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci/* use ioctl encoding for uring command */
17462306a36Sopenharmony_ci#define UBLK_F_CMD_IOCTL_ENCODE	(1UL << 6)
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci/* Copy between request and user buffer by pread()/pwrite() */
17762306a36Sopenharmony_ci#define UBLK_F_USER_COPY	(1UL << 7)
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci/*
18062306a36Sopenharmony_ci * User space sets this flag when setting up the device to request zoned storage support. Kernel may
18162306a36Sopenharmony_ci * deny the request by returning an error.
18262306a36Sopenharmony_ci */
18362306a36Sopenharmony_ci#define UBLK_F_ZONED (1ULL << 8)
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci/* device state */
18662306a36Sopenharmony_ci#define UBLK_S_DEV_DEAD	0
18762306a36Sopenharmony_ci#define UBLK_S_DEV_LIVE	1
18862306a36Sopenharmony_ci#define UBLK_S_DEV_QUIESCED	2
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci/* shipped via sqe->cmd of io_uring command */
19162306a36Sopenharmony_cistruct ublksrv_ctrl_cmd {
19262306a36Sopenharmony_ci	/* sent to which device, must be valid */
19362306a36Sopenharmony_ci	__u32	dev_id;
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci	/* sent to which queue, must be -1 if the cmd isn't for queue */
19662306a36Sopenharmony_ci	__u16	queue_id;
19762306a36Sopenharmony_ci	/*
19862306a36Sopenharmony_ci	 * cmd specific buffer, can be IN or OUT.
19962306a36Sopenharmony_ci	 */
20062306a36Sopenharmony_ci	__u16	len;
20162306a36Sopenharmony_ci	__u64	addr;
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci	/* inline data */
20462306a36Sopenharmony_ci	__u64	data[1];
20562306a36Sopenharmony_ci
20662306a36Sopenharmony_ci	/*
20762306a36Sopenharmony_ci	 * Used for UBLK_F_UNPRIVILEGED_DEV and UBLK_CMD_GET_DEV_INFO2
20862306a36Sopenharmony_ci	 * only, include null char
20962306a36Sopenharmony_ci	 */
21062306a36Sopenharmony_ci	__u16	dev_path_len;
21162306a36Sopenharmony_ci	__u16	pad;
21262306a36Sopenharmony_ci	__u32	reserved;
21362306a36Sopenharmony_ci};
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_cistruct ublksrv_ctrl_dev_info {
21662306a36Sopenharmony_ci	__u16	nr_hw_queues;
21762306a36Sopenharmony_ci	__u16	queue_depth;
21862306a36Sopenharmony_ci	__u16	state;
21962306a36Sopenharmony_ci	__u16	pad0;
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ci	__u32	max_io_buf_bytes;
22262306a36Sopenharmony_ci	__u32	dev_id;
22362306a36Sopenharmony_ci
22462306a36Sopenharmony_ci	__s32	ublksrv_pid;
22562306a36Sopenharmony_ci	__u32	pad1;
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_ci	__u64	flags;
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci	/* For ublksrv internal use, invisible to ublk driver */
23062306a36Sopenharmony_ci	__u64	ublksrv_flags;
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_ci	__u32	owner_uid;	/* store by kernel */
23362306a36Sopenharmony_ci	__u32	owner_gid;	/* store by kernel */
23462306a36Sopenharmony_ci	__u64	reserved1;
23562306a36Sopenharmony_ci	__u64   reserved2;
23662306a36Sopenharmony_ci};
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_ci#define		UBLK_IO_OP_READ		0
23962306a36Sopenharmony_ci#define		UBLK_IO_OP_WRITE		1
24062306a36Sopenharmony_ci#define		UBLK_IO_OP_FLUSH		2
24162306a36Sopenharmony_ci#define		UBLK_IO_OP_DISCARD		3
24262306a36Sopenharmony_ci#define		UBLK_IO_OP_WRITE_SAME		4
24362306a36Sopenharmony_ci#define		UBLK_IO_OP_WRITE_ZEROES		5
24462306a36Sopenharmony_ci#define		UBLK_IO_OP_ZONE_OPEN		10
24562306a36Sopenharmony_ci#define		UBLK_IO_OP_ZONE_CLOSE		11
24662306a36Sopenharmony_ci#define		UBLK_IO_OP_ZONE_FINISH		12
24762306a36Sopenharmony_ci#define		UBLK_IO_OP_ZONE_APPEND		13
24862306a36Sopenharmony_ci#define		UBLK_IO_OP_ZONE_RESET_ALL	14
24962306a36Sopenharmony_ci#define		UBLK_IO_OP_ZONE_RESET		15
25062306a36Sopenharmony_ci/*
25162306a36Sopenharmony_ci * Construct a zone report. The report request is carried in `struct
25262306a36Sopenharmony_ci * ublksrv_io_desc`. The `start_sector` field must be the first sector of a zone
25362306a36Sopenharmony_ci * and shall indicate the first zone of the report. The `nr_zones` shall
25462306a36Sopenharmony_ci * indicate how many zones should be reported at most. The report shall be
25562306a36Sopenharmony_ci * delivered as a `struct blk_zone` array. To report fewer zones than requested,
25662306a36Sopenharmony_ci * zero the last entry of the returned array.
25762306a36Sopenharmony_ci *
25862306a36Sopenharmony_ci * Related definitions(blk_zone, blk_zone_cond, blk_zone_type, ...) in
25962306a36Sopenharmony_ci * include/uapi/linux/blkzoned.h are part of ublk UAPI.
26062306a36Sopenharmony_ci */
26162306a36Sopenharmony_ci#define		UBLK_IO_OP_REPORT_ZONES		18
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_ci#define		UBLK_IO_F_FAILFAST_DEV		(1U << 8)
26462306a36Sopenharmony_ci#define		UBLK_IO_F_FAILFAST_TRANSPORT	(1U << 9)
26562306a36Sopenharmony_ci#define		UBLK_IO_F_FAILFAST_DRIVER	(1U << 10)
26662306a36Sopenharmony_ci#define		UBLK_IO_F_META			(1U << 11)
26762306a36Sopenharmony_ci#define		UBLK_IO_F_FUA			(1U << 13)
26862306a36Sopenharmony_ci#define		UBLK_IO_F_NOUNMAP		(1U << 15)
26962306a36Sopenharmony_ci#define		UBLK_IO_F_SWAP			(1U << 16)
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_ci/*
27262306a36Sopenharmony_ci * io cmd is described by this structure, and stored in share memory, indexed
27362306a36Sopenharmony_ci * by request tag.
27462306a36Sopenharmony_ci *
27562306a36Sopenharmony_ci * The data is stored by ublk driver, and read by ublksrv after one fetch command
27662306a36Sopenharmony_ci * returns.
27762306a36Sopenharmony_ci */
27862306a36Sopenharmony_cistruct ublksrv_io_desc {
27962306a36Sopenharmony_ci	/* op: bit 0-7, flags: bit 8-31 */
28062306a36Sopenharmony_ci	__u32		op_flags;
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_ci	union {
28362306a36Sopenharmony_ci		__u32		nr_sectors;
28462306a36Sopenharmony_ci		__u32		nr_zones; /* for UBLK_IO_OP_REPORT_ZONES */
28562306a36Sopenharmony_ci	};
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_ci	/* start sector for this io */
28862306a36Sopenharmony_ci	__u64		start_sector;
28962306a36Sopenharmony_ci
29062306a36Sopenharmony_ci	/* buffer address in ublksrv daemon vm space, from ublk driver */
29162306a36Sopenharmony_ci	__u64		addr;
29262306a36Sopenharmony_ci};
29362306a36Sopenharmony_ci
29462306a36Sopenharmony_cistatic inline __u8 ublksrv_get_op(const struct ublksrv_io_desc *iod)
29562306a36Sopenharmony_ci{
29662306a36Sopenharmony_ci	return iod->op_flags & 0xff;
29762306a36Sopenharmony_ci}
29862306a36Sopenharmony_ci
29962306a36Sopenharmony_cistatic inline __u32 ublksrv_get_flags(const struct ublksrv_io_desc *iod)
30062306a36Sopenharmony_ci{
30162306a36Sopenharmony_ci	return iod->op_flags >> 8;
30262306a36Sopenharmony_ci}
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_ci/* issued to ublk driver via /dev/ublkcN */
30562306a36Sopenharmony_cistruct ublksrv_io_cmd {
30662306a36Sopenharmony_ci	__u16	q_id;
30762306a36Sopenharmony_ci
30862306a36Sopenharmony_ci	/* for fetch/commit which result */
30962306a36Sopenharmony_ci	__u16	tag;
31062306a36Sopenharmony_ci
31162306a36Sopenharmony_ci	/* io result, it is valid for COMMIT* command only */
31262306a36Sopenharmony_ci	__s32	result;
31362306a36Sopenharmony_ci
31462306a36Sopenharmony_ci	union {
31562306a36Sopenharmony_ci		/*
31662306a36Sopenharmony_ci		 * userspace buffer address in ublksrv daemon process, valid for
31762306a36Sopenharmony_ci		 * FETCH* command only
31862306a36Sopenharmony_ci		 *
31962306a36Sopenharmony_ci		 * `addr` should not be used when UBLK_F_USER_COPY is enabled,
32062306a36Sopenharmony_ci		 * because userspace handles data copy by pread()/pwrite() over
32162306a36Sopenharmony_ci		 * /dev/ublkcN. But in case of UBLK_F_ZONED, this union is
32262306a36Sopenharmony_ci		 * re-used to pass back the allocated LBA for
32362306a36Sopenharmony_ci		 * UBLK_IO_OP_ZONE_APPEND which actually depends on
32462306a36Sopenharmony_ci		 * UBLK_F_USER_COPY
32562306a36Sopenharmony_ci		 */
32662306a36Sopenharmony_ci		__u64	addr;
32762306a36Sopenharmony_ci		__u64	zone_append_lba;
32862306a36Sopenharmony_ci	};
32962306a36Sopenharmony_ci};
33062306a36Sopenharmony_ci
33162306a36Sopenharmony_cistruct ublk_param_basic {
33262306a36Sopenharmony_ci#define UBLK_ATTR_READ_ONLY            (1 << 0)
33362306a36Sopenharmony_ci#define UBLK_ATTR_ROTATIONAL           (1 << 1)
33462306a36Sopenharmony_ci#define UBLK_ATTR_VOLATILE_CACHE       (1 << 2)
33562306a36Sopenharmony_ci#define UBLK_ATTR_FUA                  (1 << 3)
33662306a36Sopenharmony_ci	__u32	attrs;
33762306a36Sopenharmony_ci	__u8	logical_bs_shift;
33862306a36Sopenharmony_ci	__u8	physical_bs_shift;
33962306a36Sopenharmony_ci	__u8	io_opt_shift;
34062306a36Sopenharmony_ci	__u8	io_min_shift;
34162306a36Sopenharmony_ci
34262306a36Sopenharmony_ci	__u32	max_sectors;
34362306a36Sopenharmony_ci	__u32	chunk_sectors;
34462306a36Sopenharmony_ci
34562306a36Sopenharmony_ci	__u64   dev_sectors;
34662306a36Sopenharmony_ci	__u64   virt_boundary_mask;
34762306a36Sopenharmony_ci};
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_cistruct ublk_param_discard {
35062306a36Sopenharmony_ci	__u32	discard_alignment;
35162306a36Sopenharmony_ci
35262306a36Sopenharmony_ci	__u32	discard_granularity;
35362306a36Sopenharmony_ci	__u32	max_discard_sectors;
35462306a36Sopenharmony_ci
35562306a36Sopenharmony_ci	__u32	max_write_zeroes_sectors;
35662306a36Sopenharmony_ci	__u16	max_discard_segments;
35762306a36Sopenharmony_ci	__u16	reserved0;
35862306a36Sopenharmony_ci};
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_ci/*
36162306a36Sopenharmony_ci * read-only, can't set via UBLK_CMD_SET_PARAMS, disk_devt is available
36262306a36Sopenharmony_ci * after device is started
36362306a36Sopenharmony_ci */
36462306a36Sopenharmony_cistruct ublk_param_devt {
36562306a36Sopenharmony_ci	__u32   char_major;
36662306a36Sopenharmony_ci	__u32   char_minor;
36762306a36Sopenharmony_ci	__u32   disk_major;
36862306a36Sopenharmony_ci	__u32   disk_minor;
36962306a36Sopenharmony_ci};
37062306a36Sopenharmony_ci
37162306a36Sopenharmony_cistruct ublk_param_zoned {
37262306a36Sopenharmony_ci	__u32	max_open_zones;
37362306a36Sopenharmony_ci	__u32	max_active_zones;
37462306a36Sopenharmony_ci	__u32	max_zone_append_sectors;
37562306a36Sopenharmony_ci	__u8	reserved[20];
37662306a36Sopenharmony_ci};
37762306a36Sopenharmony_ci
37862306a36Sopenharmony_cistruct ublk_params {
37962306a36Sopenharmony_ci	/*
38062306a36Sopenharmony_ci	 * Total length of parameters, userspace has to set 'len' for both
38162306a36Sopenharmony_ci	 * SET_PARAMS and GET_PARAMS command, and driver may update len
38262306a36Sopenharmony_ci	 * if two sides use different version of 'ublk_params', same with
38362306a36Sopenharmony_ci	 * 'types' fields.
38462306a36Sopenharmony_ci	 */
38562306a36Sopenharmony_ci	__u32	len;
38662306a36Sopenharmony_ci#define UBLK_PARAM_TYPE_BASIC           (1 << 0)
38762306a36Sopenharmony_ci#define UBLK_PARAM_TYPE_DISCARD         (1 << 1)
38862306a36Sopenharmony_ci#define UBLK_PARAM_TYPE_DEVT            (1 << 2)
38962306a36Sopenharmony_ci#define UBLK_PARAM_TYPE_ZONED           (1 << 3)
39062306a36Sopenharmony_ci	__u32	types;			/* types of parameter included */
39162306a36Sopenharmony_ci
39262306a36Sopenharmony_ci	struct ublk_param_basic		basic;
39362306a36Sopenharmony_ci	struct ublk_param_discard	discard;
39462306a36Sopenharmony_ci	struct ublk_param_devt		devt;
39562306a36Sopenharmony_ci	struct ublk_param_zoned	zoned;
39662306a36Sopenharmony_ci};
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_ci#endif
399