xref: /openbmc/linux/include/uapi/linux/ublk_cmd.h (revision 851e0629)
171f28f31SMing Lei /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
271f28f31SMing Lei #ifndef USER_BLK_DRV_CMD_INC_H
371f28f31SMing Lei #define USER_BLK_DRV_CMD_INC_H
471f28f31SMing Lei 
571f28f31SMing Lei #include <linux/types.h>
671f28f31SMing Lei 
771f28f31SMing Lei /* ublk server command definition */
871f28f31SMing Lei 
971f28f31SMing Lei /*
1071f28f31SMing Lei  * Admin commands, issued by ublk server, and handled by ublk driver.
112d786e66SMing Lei  *
122d786e66SMing Lei  * Legacy command definition, don't use in new application, and don't
132d786e66SMing Lei  * add new such definition any more
1471f28f31SMing Lei  */
1571f28f31SMing Lei #define	UBLK_CMD_GET_QUEUE_AFFINITY	0x01
1671f28f31SMing Lei #define	UBLK_CMD_GET_DEV_INFO	0x02
1771f28f31SMing Lei #define	UBLK_CMD_ADD_DEV		0x04
1871f28f31SMing Lei #define	UBLK_CMD_DEL_DEV		0x05
1971f28f31SMing Lei #define	UBLK_CMD_START_DEV	0x06
2071f28f31SMing Lei #define	UBLK_CMD_STOP_DEV	0x07
210aa73170SMing Lei #define	UBLK_CMD_SET_PARAMS	0x08
220aa73170SMing Lei #define	UBLK_CMD_GET_PARAMS	0x09
23c732a852SZiyangZhang #define	UBLK_CMD_START_USER_RECOVERY	0x10
24c732a852SZiyangZhang #define	UBLK_CMD_END_USER_RECOVERY	0x11
254093cb5aSMing Lei #define	UBLK_CMD_GET_DEV_INFO2		0x12
264093cb5aSMing Lei 
272d786e66SMing Lei /* Any new ctrl command should encode by __IO*() */
282d786e66SMing Lei #define UBLK_U_CMD_GET_QUEUE_AFFINITY	\
292d786e66SMing Lei 	_IOR('u', UBLK_CMD_GET_QUEUE_AFFINITY, struct ublksrv_ctrl_cmd)
302d786e66SMing Lei #define UBLK_U_CMD_GET_DEV_INFO		\
312d786e66SMing Lei 	_IOR('u', UBLK_CMD_GET_DEV_INFO, struct ublksrv_ctrl_cmd)
322d786e66SMing Lei #define UBLK_U_CMD_ADD_DEV		\
332d786e66SMing Lei 	_IOWR('u', UBLK_CMD_ADD_DEV, struct ublksrv_ctrl_cmd)
342d786e66SMing Lei #define UBLK_U_CMD_DEL_DEV		\
352d786e66SMing Lei 	_IOWR('u', UBLK_CMD_DEL_DEV, struct ublksrv_ctrl_cmd)
362d786e66SMing Lei #define UBLK_U_CMD_START_DEV		\
372d786e66SMing Lei 	_IOWR('u', UBLK_CMD_START_DEV, struct ublksrv_ctrl_cmd)
382d786e66SMing Lei #define UBLK_U_CMD_STOP_DEV		\
392d786e66SMing Lei 	_IOWR('u', UBLK_CMD_STOP_DEV, struct ublksrv_ctrl_cmd)
402d786e66SMing Lei #define UBLK_U_CMD_SET_PARAMS		\
412d786e66SMing Lei 	_IOWR('u', UBLK_CMD_SET_PARAMS, struct ublksrv_ctrl_cmd)
422d786e66SMing Lei #define UBLK_U_CMD_GET_PARAMS		\
432d786e66SMing Lei 	_IOR('u', UBLK_CMD_GET_PARAMS, struct ublksrv_ctrl_cmd)
442d786e66SMing Lei #define UBLK_U_CMD_START_USER_RECOVERY	\
452d786e66SMing Lei 	_IOWR('u', UBLK_CMD_START_USER_RECOVERY, struct ublksrv_ctrl_cmd)
462d786e66SMing Lei #define UBLK_U_CMD_END_USER_RECOVERY	\
472d786e66SMing Lei 	_IOWR('u', UBLK_CMD_END_USER_RECOVERY, struct ublksrv_ctrl_cmd)
482d786e66SMing Lei #define UBLK_U_CMD_GET_DEV_INFO2	\
492d786e66SMing Lei 	_IOR('u', UBLK_CMD_GET_DEV_INFO2, struct ublksrv_ctrl_cmd)
50b5bbc52fSMing Lei #define UBLK_U_CMD_GET_FEATURES	\
51b5bbc52fSMing Lei 	_IOR('u', 0x13, struct ublksrv_ctrl_cmd)
52b5bbc52fSMing Lei 
53b5bbc52fSMing Lei /*
54b5bbc52fSMing Lei  * 64bits are enough now, and it should be easy to extend in case of
55b5bbc52fSMing Lei  * running out of feature flags
56b5bbc52fSMing Lei  */
57b5bbc52fSMing Lei #define UBLK_FEATURES_LEN  8
582d786e66SMing Lei 
5971f28f31SMing Lei /*
6071f28f31SMing Lei  * IO commands, issued by ublk server, and handled by ublk driver.
6171f28f31SMing Lei  *
6271f28f31SMing Lei  * FETCH_REQ: issued via sqe(URING_CMD) beforehand for fetching IO request
6371f28f31SMing Lei  *      from ublk driver, should be issued only when starting device. After
6471f28f31SMing Lei  *      the associated cqe is returned, request's tag can be retrieved via
6571f28f31SMing Lei  *      cqe->userdata.
6671f28f31SMing Lei  *
6771f28f31SMing Lei  * COMMIT_AND_FETCH_REQ: issued via sqe(URING_CMD) after ublkserver handled
6871f28f31SMing Lei  *      this IO request, request's handling result is committed to ublk
6971f28f31SMing Lei  *      driver, meantime FETCH_REQ is piggyback, and FETCH_REQ has to be
7071f28f31SMing Lei  *      handled before completing io request.
714e18403dSZiyangZhang  *
724e18403dSZiyangZhang  * NEED_GET_DATA: only used for write requests to set io addr and copy data
734e18403dSZiyangZhang  *      When NEED_GET_DATA is set, ublksrv has to issue UBLK_IO_NEED_GET_DATA
744e18403dSZiyangZhang  *      command after ublk driver returns UBLK_IO_RES_NEED_GET_DATA.
754e18403dSZiyangZhang  *
764e18403dSZiyangZhang  *      It is only used if ublksrv set UBLK_F_NEED_GET_DATA flag
774e18403dSZiyangZhang  *      while starting a ublk device.
7871f28f31SMing Lei  */
792d786e66SMing Lei 
802d786e66SMing Lei /*
812d786e66SMing Lei  * Legacy IO command definition, don't use in new application, and don't
822d786e66SMing Lei  * add new such definition any more
832d786e66SMing Lei  */
8471f28f31SMing Lei #define	UBLK_IO_FETCH_REQ		0x20
8571f28f31SMing Lei #define	UBLK_IO_COMMIT_AND_FETCH_REQ	0x21
864e18403dSZiyangZhang #define	UBLK_IO_NEED_GET_DATA	0x22
8771f28f31SMing Lei 
882d786e66SMing Lei /* Any new IO command should encode by __IOWR() */
892d786e66SMing Lei #define	UBLK_U_IO_FETCH_REQ		\
902d786e66SMing Lei 	_IOWR('u', UBLK_IO_FETCH_REQ, struct ublksrv_io_cmd)
912d786e66SMing Lei #define	UBLK_U_IO_COMMIT_AND_FETCH_REQ	\
922d786e66SMing Lei 	_IOWR('u', UBLK_IO_COMMIT_AND_FETCH_REQ, struct ublksrv_io_cmd)
932d786e66SMing Lei #define	UBLK_U_IO_NEED_GET_DATA		\
942d786e66SMing Lei 	_IOWR('u', UBLK_IO_NEED_GET_DATA, struct ublksrv_io_cmd)
952d786e66SMing Lei 
9671f28f31SMing Lei /* only ABORT means that no re-fetch */
9771f28f31SMing Lei #define UBLK_IO_RES_OK			0
984e18403dSZiyangZhang #define UBLK_IO_RES_NEED_GET_DATA	1
9971f28f31SMing Lei #define UBLK_IO_RES_ABORT		(-ENODEV)
10071f28f31SMing Lei 
10171f28f31SMing Lei #define UBLKSRV_CMD_BUF_OFFSET	0
10271f28f31SMing Lei #define UBLKSRV_IO_BUF_OFFSET	0x80000000
10371f28f31SMing Lei 
10462fe99ceSMing Lei /* tag bit is 16bit, so far limit at most 4096 IOs for each queue */
10571f28f31SMing Lei #define UBLK_MAX_QUEUE_DEPTH	4096
10671f28f31SMing Lei 
10762fe99ceSMing Lei /* single IO buffer max size is 32MB */
10862fe99ceSMing Lei #define UBLK_IO_BUF_OFF		0
10962fe99ceSMing Lei #define UBLK_IO_BUF_BITS	25
11062fe99ceSMing Lei #define UBLK_IO_BUF_BITS_MASK	((1ULL << UBLK_IO_BUF_BITS) - 1)
11162fe99ceSMing Lei 
11262fe99ceSMing Lei /* so at most 64K IOs for each queue */
11362fe99ceSMing Lei #define UBLK_TAG_OFF		UBLK_IO_BUF_BITS
11462fe99ceSMing Lei #define UBLK_TAG_BITS		16
11562fe99ceSMing Lei #define UBLK_TAG_BITS_MASK	((1ULL << UBLK_TAG_BITS) - 1)
11662fe99ceSMing Lei 
11762fe99ceSMing Lei /* max 4096 queues */
11862fe99ceSMing Lei #define UBLK_QID_OFF		(UBLK_TAG_OFF + UBLK_TAG_BITS)
11962fe99ceSMing Lei #define UBLK_QID_BITS		12
12062fe99ceSMing Lei #define UBLK_QID_BITS_MASK	((1ULL << UBLK_QID_BITS) - 1)
12162fe99ceSMing Lei 
12262fe99ceSMing Lei #define UBLK_MAX_NR_QUEUES	(1U << UBLK_QID_BITS)
12362fe99ceSMing Lei 
12462fe99ceSMing Lei #define UBLKSRV_IO_BUF_TOTAL_BITS	(UBLK_QID_OFF + UBLK_QID_BITS)
12562fe99ceSMing Lei #define UBLKSRV_IO_BUF_TOTAL_SIZE	(1ULL << UBLKSRV_IO_BUF_TOTAL_BITS)
12662fe99ceSMing Lei 
12771f28f31SMing Lei /*
12871f28f31SMing Lei  * zero copy requires 4k block size, and can remap ublk driver's io
12971f28f31SMing Lei  * request into ublksrv's vm space
13071f28f31SMing Lei  */
1316d8c5afcSMing Lei #define UBLK_F_SUPPORT_ZERO_COPY	(1ULL << 0)
13271f28f31SMing Lei 
1330edb3696SMing Lei /*
1340edb3696SMing Lei  * Force to complete io cmd via io_uring_cmd_complete_in_task so that
1350edb3696SMing Lei  * performance comparison is done easily with using task_work_add
1360edb3696SMing Lei  */
1376d8c5afcSMing Lei #define UBLK_F_URING_CMD_COMP_IN_TASK	(1ULL << 1)
1380edb3696SMing Lei 
1394e18403dSZiyangZhang /*
1404e18403dSZiyangZhang  * User should issue io cmd again for write requests to
1414e18403dSZiyangZhang  * set io buffer address and copy data from bio vectors
1424e18403dSZiyangZhang  * to the userspace io buffer.
1434e18403dSZiyangZhang  *
1444e18403dSZiyangZhang  * In this mode, task_work is not used.
1454e18403dSZiyangZhang  */
1464e18403dSZiyangZhang #define UBLK_F_NEED_GET_DATA (1UL << 2)
1474e18403dSZiyangZhang 
14877a440e2SZiyangZhang #define UBLK_F_USER_RECOVERY	(1UL << 3)
14977a440e2SZiyangZhang 
150a0d41dc1SZiyangZhang #define UBLK_F_USER_RECOVERY_REISSUE	(1UL << 4)
151a0d41dc1SZiyangZhang 
1524093cb5aSMing Lei /*
1534093cb5aSMing Lei  * Unprivileged user can create /dev/ublkcN and /dev/ublkbN.
1544093cb5aSMing Lei  *
1554093cb5aSMing Lei  * /dev/ublk-control needs to be available for unprivileged user, and it
1564093cb5aSMing Lei  * can be done via udev rule to make all control commands available to
1574093cb5aSMing Lei  * unprivileged user. Except for the command of UBLK_CMD_ADD_DEV, all
1584093cb5aSMing Lei  * other commands are only allowed for the owner of the specified device.
1594093cb5aSMing Lei  *
1604093cb5aSMing Lei  * When userspace sends UBLK_CMD_ADD_DEV, the device pair's owner_uid and
1614093cb5aSMing Lei  * owner_gid are stored to ublksrv_ctrl_dev_info by kernel, so far only
1624093cb5aSMing Lei  * the current user's uid/gid is stored, that said owner of the created
1634093cb5aSMing Lei  * device is always the current user.
1644093cb5aSMing Lei  *
1654093cb5aSMing Lei  * We still need udev rule to apply OWNER/GROUP with the stored owner_uid
1664093cb5aSMing Lei  * and owner_gid.
1674093cb5aSMing Lei  *
1684093cb5aSMing Lei  * Then ublk server can be run as unprivileged user, and /dev/ublkbN can
1694093cb5aSMing Lei  * be accessed and managed by its owner represented by owner_uid/owner_gid.
1704093cb5aSMing Lei  */
1714093cb5aSMing Lei #define UBLK_F_UNPRIVILEGED_DEV	(1UL << 5)
1724093cb5aSMing Lei 
1732d786e66SMing Lei /* use ioctl encoding for uring command */
1742d786e66SMing Lei #define UBLK_F_CMD_IOCTL_ENCODE	(1UL << 6)
1752d786e66SMing Lei 
1761172d5b8SMing Lei /* Copy between request and user buffer by pread()/pwrite() */
1771172d5b8SMing Lei #define UBLK_F_USER_COPY	(1UL << 7)
1781172d5b8SMing Lei 
17929802d7cSAndreas Hindborg /*
18029802d7cSAndreas Hindborg  * User space sets this flag when setting up the device to request zoned storage support. Kernel may
18129802d7cSAndreas Hindborg  * deny the request by returning an error.
18229802d7cSAndreas Hindborg  */
18329802d7cSAndreas Hindborg #define UBLK_F_ZONED (1ULL << 8)
18429802d7cSAndreas Hindborg 
18571f28f31SMing Lei /* device state */
18671f28f31SMing Lei #define UBLK_S_DEV_DEAD	0
18771f28f31SMing Lei #define UBLK_S_DEV_LIVE	1
18877a440e2SZiyangZhang #define UBLK_S_DEV_QUIESCED	2
18971f28f31SMing Lei 
19071f28f31SMing Lei /* shipped via sqe->cmd of io_uring command */
19171f28f31SMing Lei struct ublksrv_ctrl_cmd {
19271f28f31SMing Lei 	/* sent to which device, must be valid */
19371f28f31SMing Lei 	__u32	dev_id;
19471f28f31SMing Lei 
19571f28f31SMing Lei 	/* sent to which queue, must be -1 if the cmd isn't for queue */
19671f28f31SMing Lei 	__u16	queue_id;
19771f28f31SMing Lei 	/*
19871f28f31SMing Lei 	 * cmd specific buffer, can be IN or OUT.
19971f28f31SMing Lei 	 */
20071f28f31SMing Lei 	__u16	len;
20171f28f31SMing Lei 	__u64	addr;
20271f28f31SMing Lei 
20371f28f31SMing Lei 	/* inline data */
2044093cb5aSMing Lei 	__u64	data[1];
2054093cb5aSMing Lei 
2064093cb5aSMing Lei 	/*
2074093cb5aSMing Lei 	 * Used for UBLK_F_UNPRIVILEGED_DEV and UBLK_CMD_GET_DEV_INFO2
2084093cb5aSMing Lei 	 * only, include null char
2094093cb5aSMing Lei 	 */
2104093cb5aSMing Lei 	__u16	dev_path_len;
2114093cb5aSMing Lei 	__u16	pad;
2124093cb5aSMing Lei 	__u32	reserved;
21371f28f31SMing Lei };
21471f28f31SMing Lei 
21571f28f31SMing Lei struct ublksrv_ctrl_dev_info {
21671f28f31SMing Lei 	__u16	nr_hw_queues;
21771f28f31SMing Lei 	__u16	queue_depth;
21871f28f31SMing Lei 	__u16	state;
2194bf9cbf3SMing Lei 	__u16	pad0;
22071f28f31SMing Lei 
2214bf9cbf3SMing Lei 	__u32	max_io_buf_bytes;
22271f28f31SMing Lei 	__u32	dev_id;
22371f28f31SMing Lei 
22471f28f31SMing Lei 	__s32	ublksrv_pid;
2254bf9cbf3SMing Lei 	__u32	pad1;
2264bf9cbf3SMing Lei 
2276d8c5afcSMing Lei 	__u64	flags;
22871f28f31SMing Lei 
22971f28f31SMing Lei 	/* For ublksrv internal use, invisible to ublk driver */
23071f28f31SMing Lei 	__u64	ublksrv_flags;
2314bf9cbf3SMing Lei 
2324093cb5aSMing Lei 	__u32	owner_uid;	/* store by kernel */
2334093cb5aSMing Lei 	__u32	owner_gid;	/* store by kernel */
2344bf9cbf3SMing Lei 	__u64	reserved1;
2354bf9cbf3SMing Lei 	__u64   reserved2;
23671f28f31SMing Lei };
23771f28f31SMing Lei 
23871f28f31SMing Lei #define		UBLK_IO_OP_READ		0
23971f28f31SMing Lei #define		UBLK_IO_OP_WRITE		1
24071f28f31SMing Lei #define		UBLK_IO_OP_FLUSH		2
24171f28f31SMing Lei #define		UBLK_IO_OP_DISCARD		3
24271f28f31SMing Lei #define		UBLK_IO_OP_WRITE_SAME		4
24371f28f31SMing Lei #define		UBLK_IO_OP_WRITE_ZEROES		5
24429802d7cSAndreas Hindborg #define		UBLK_IO_OP_ZONE_OPEN		10
24529802d7cSAndreas Hindborg #define		UBLK_IO_OP_ZONE_CLOSE		11
24629802d7cSAndreas Hindborg #define		UBLK_IO_OP_ZONE_FINISH		12
24729802d7cSAndreas Hindborg #define		UBLK_IO_OP_ZONE_APPEND		13
248*851e0629SMing Lei #define		UBLK_IO_OP_ZONE_RESET_ALL	14
24929802d7cSAndreas Hindborg #define		UBLK_IO_OP_ZONE_RESET		15
25029802d7cSAndreas Hindborg /*
25129802d7cSAndreas Hindborg  * Construct a zone report. The report request is carried in `struct
25229802d7cSAndreas Hindborg  * ublksrv_io_desc`. The `start_sector` field must be the first sector of a zone
25329802d7cSAndreas Hindborg  * and shall indicate the first zone of the report. The `nr_zones` shall
25429802d7cSAndreas Hindborg  * indicate how many zones should be reported at most. The report shall be
25529802d7cSAndreas Hindborg  * delivered as a `struct blk_zone` array. To report fewer zones than requested,
25629802d7cSAndreas Hindborg  * zero the last entry of the returned array.
25729802d7cSAndreas Hindborg  *
25829802d7cSAndreas Hindborg  * Related definitions(blk_zone, blk_zone_cond, blk_zone_type, ...) in
25929802d7cSAndreas Hindborg  * include/uapi/linux/blkzoned.h are part of ublk UAPI.
26029802d7cSAndreas Hindborg  */
26129802d7cSAndreas Hindborg #define		UBLK_IO_OP_REPORT_ZONES		18
26271f28f31SMing Lei 
26371f28f31SMing Lei #define		UBLK_IO_F_FAILFAST_DEV		(1U << 8)
26471f28f31SMing Lei #define		UBLK_IO_F_FAILFAST_TRANSPORT	(1U << 9)
26571f28f31SMing Lei #define		UBLK_IO_F_FAILFAST_DRIVER	(1U << 10)
26671f28f31SMing Lei #define		UBLK_IO_F_META			(1U << 11)
26771f28f31SMing Lei #define		UBLK_IO_F_FUA			(1U << 13)
26871f28f31SMing Lei #define		UBLK_IO_F_NOUNMAP		(1U << 15)
26971f28f31SMing Lei #define		UBLK_IO_F_SWAP			(1U << 16)
27071f28f31SMing Lei 
27171f28f31SMing Lei /*
27271f28f31SMing Lei  * io cmd is described by this structure, and stored in share memory, indexed
27371f28f31SMing Lei  * by request tag.
27471f28f31SMing Lei  *
27571f28f31SMing Lei  * The data is stored by ublk driver, and read by ublksrv after one fetch command
27671f28f31SMing Lei  * returns.
27771f28f31SMing Lei  */
27871f28f31SMing Lei struct ublksrv_io_desc {
27971f28f31SMing Lei 	/* op: bit 0-7, flags: bit 8-31 */
28071f28f31SMing Lei 	__u32		op_flags;
28171f28f31SMing Lei 
28229802d7cSAndreas Hindborg 	union {
28371f28f31SMing Lei 		__u32		nr_sectors;
28429802d7cSAndreas Hindborg 		__u32		nr_zones; /* for UBLK_IO_OP_REPORT_ZONES */
28529802d7cSAndreas Hindborg 	};
28671f28f31SMing Lei 
28771f28f31SMing Lei 	/* start sector for this io */
28871f28f31SMing Lei 	__u64		start_sector;
28971f28f31SMing Lei 
29071f28f31SMing Lei 	/* buffer address in ublksrv daemon vm space, from ublk driver */
29171f28f31SMing Lei 	__u64		addr;
29271f28f31SMing Lei };
29371f28f31SMing Lei 
ublksrv_get_op(const struct ublksrv_io_desc * iod)29471f28f31SMing Lei static inline __u8 ublksrv_get_op(const struct ublksrv_io_desc *iod)
29571f28f31SMing Lei {
29671f28f31SMing Lei 	return iod->op_flags & 0xff;
29771f28f31SMing Lei }
29871f28f31SMing Lei 
ublksrv_get_flags(const struct ublksrv_io_desc * iod)29971f28f31SMing Lei static inline __u32 ublksrv_get_flags(const struct ublksrv_io_desc *iod)
30071f28f31SMing Lei {
30171f28f31SMing Lei 	return iod->op_flags >> 8;
30271f28f31SMing Lei }
30371f28f31SMing Lei 
30471f28f31SMing Lei /* issued to ublk driver via /dev/ublkcN */
30571f28f31SMing Lei struct ublksrv_io_cmd {
30671f28f31SMing Lei 	__u16	q_id;
30771f28f31SMing Lei 
30871f28f31SMing Lei 	/* for fetch/commit which result */
30971f28f31SMing Lei 	__u16	tag;
31071f28f31SMing Lei 
31171f28f31SMing Lei 	/* io result, it is valid for COMMIT* command only */
31271f28f31SMing Lei 	__s32	result;
31371f28f31SMing Lei 
31429802d7cSAndreas Hindborg 	union {
31571f28f31SMing Lei 		/*
31671f28f31SMing Lei 		 * userspace buffer address in ublksrv daemon process, valid for
31771f28f31SMing Lei 		 * FETCH* command only
31829802d7cSAndreas Hindborg 		 *
31929802d7cSAndreas Hindborg 		 * `addr` should not be used when UBLK_F_USER_COPY is enabled,
32029802d7cSAndreas Hindborg 		 * because userspace handles data copy by pread()/pwrite() over
32129802d7cSAndreas Hindborg 		 * /dev/ublkcN. But in case of UBLK_F_ZONED, this union is
32229802d7cSAndreas Hindborg 		 * re-used to pass back the allocated LBA for
32329802d7cSAndreas Hindborg 		 * UBLK_IO_OP_ZONE_APPEND which actually depends on
32429802d7cSAndreas Hindborg 		 * UBLK_F_USER_COPY
32571f28f31SMing Lei 		 */
32671f28f31SMing Lei 		__u64	addr;
32729802d7cSAndreas Hindborg 		__u64	zone_append_lba;
32829802d7cSAndreas Hindborg 	};
32971f28f31SMing Lei };
33071f28f31SMing Lei 
3310aa73170SMing Lei struct ublk_param_basic {
3320aa73170SMing Lei #define UBLK_ATTR_READ_ONLY            (1 << 0)
3330aa73170SMing Lei #define UBLK_ATTR_ROTATIONAL           (1 << 1)
3340aa73170SMing Lei #define UBLK_ATTR_VOLATILE_CACHE       (1 << 2)
3350aa73170SMing Lei #define UBLK_ATTR_FUA                  (1 << 3)
3360aa73170SMing Lei 	__u32	attrs;
3370aa73170SMing Lei 	__u8	logical_bs_shift;
3380aa73170SMing Lei 	__u8	physical_bs_shift;
3390aa73170SMing Lei 	__u8	io_opt_shift;
3400aa73170SMing Lei 	__u8	io_min_shift;
3410aa73170SMing Lei 
3420aa73170SMing Lei 	__u32	max_sectors;
3430aa73170SMing Lei 	__u32	chunk_sectors;
3440aa73170SMing Lei 
3450aa73170SMing Lei 	__u64   dev_sectors;
3460aa73170SMing Lei 	__u64   virt_boundary_mask;
3470aa73170SMing Lei };
3480aa73170SMing Lei 
3490aa73170SMing Lei struct ublk_param_discard {
3500aa73170SMing Lei 	__u32	discard_alignment;
3510aa73170SMing Lei 
3520aa73170SMing Lei 	__u32	discard_granularity;
3530aa73170SMing Lei 	__u32	max_discard_sectors;
3540aa73170SMing Lei 
3550aa73170SMing Lei 	__u32	max_write_zeroes_sectors;
3560aa73170SMing Lei 	__u16	max_discard_segments;
3570aa73170SMing Lei 	__u16	reserved0;
3580aa73170SMing Lei };
3590aa73170SMing Lei 
360abb864d3SMing Lei /*
361abb864d3SMing Lei  * read-only, can't set via UBLK_CMD_SET_PARAMS, disk_devt is available
362abb864d3SMing Lei  * after device is started
363abb864d3SMing Lei  */
364abb864d3SMing Lei struct ublk_param_devt {
365abb864d3SMing Lei 	__u32   char_major;
366abb864d3SMing Lei 	__u32   char_minor;
367abb864d3SMing Lei 	__u32   disk_major;
368abb864d3SMing Lei 	__u32   disk_minor;
369abb864d3SMing Lei };
370abb864d3SMing Lei 
37129802d7cSAndreas Hindborg struct ublk_param_zoned {
37229802d7cSAndreas Hindborg 	__u32	max_open_zones;
37329802d7cSAndreas Hindborg 	__u32	max_active_zones;
37429802d7cSAndreas Hindborg 	__u32	max_zone_append_sectors;
37529802d7cSAndreas Hindborg 	__u8	reserved[20];
37629802d7cSAndreas Hindborg };
37729802d7cSAndreas Hindborg 
3780aa73170SMing Lei struct ublk_params {
3790aa73170SMing Lei 	/*
3800aa73170SMing Lei 	 * Total length of parameters, userspace has to set 'len' for both
3810aa73170SMing Lei 	 * SET_PARAMS and GET_PARAMS command, and driver may update len
3820aa73170SMing Lei 	 * if two sides use different version of 'ublk_params', same with
3830aa73170SMing Lei 	 * 'types' fields.
3840aa73170SMing Lei 	 */
3850aa73170SMing Lei 	__u32	len;
3860aa73170SMing Lei #define UBLK_PARAM_TYPE_BASIC           (1 << 0)
3870aa73170SMing Lei #define UBLK_PARAM_TYPE_DISCARD         (1 << 1)
388abb864d3SMing Lei #define UBLK_PARAM_TYPE_DEVT            (1 << 2)
38929802d7cSAndreas Hindborg #define UBLK_PARAM_TYPE_ZONED           (1 << 3)
3900aa73170SMing Lei 	__u32	types;			/* types of parameter included */
3910aa73170SMing Lei 
3920aa73170SMing Lei 	struct ublk_param_basic		basic;
3930aa73170SMing Lei 	struct ublk_param_discard	discard;
394abb864d3SMing Lei 	struct ublk_param_devt		devt;
39529802d7cSAndreas Hindborg 	struct ublk_param_zoned	zoned;
3960aa73170SMing Lei };
3970aa73170SMing Lei 
39871f28f31SMing Lei #endif
399