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)
52*13fe8e68SMing Lei #define UBLK_U_CMD_DEL_DEV_ASYNC \
53*13fe8e68SMing Lei _IOR('u', 0x14, struct ublksrv_ctrl_cmd)
54b5bbc52fSMing Lei
55b5bbc52fSMing Lei /*
56b5bbc52fSMing Lei * 64bits are enough now, and it should be easy to extend in case of
57b5bbc52fSMing Lei * running out of feature flags
58b5bbc52fSMing Lei */
59b5bbc52fSMing Lei #define UBLK_FEATURES_LEN 8
602d786e66SMing Lei
6171f28f31SMing Lei /*
6271f28f31SMing Lei * IO commands, issued by ublk server, and handled by ublk driver.
6371f28f31SMing Lei *
6471f28f31SMing Lei * FETCH_REQ: issued via sqe(URING_CMD) beforehand for fetching IO request
6571f28f31SMing Lei * from ublk driver, should be issued only when starting device. After
6671f28f31SMing Lei * the associated cqe is returned, request's tag can be retrieved via
6771f28f31SMing Lei * cqe->userdata.
6871f28f31SMing Lei *
6971f28f31SMing Lei * COMMIT_AND_FETCH_REQ: issued via sqe(URING_CMD) after ublkserver handled
7071f28f31SMing Lei * this IO request, request's handling result is committed to ublk
7171f28f31SMing Lei * driver, meantime FETCH_REQ is piggyback, and FETCH_REQ has to be
7271f28f31SMing Lei * handled before completing io request.
734e18403dSZiyangZhang *
744e18403dSZiyangZhang * NEED_GET_DATA: only used for write requests to set io addr and copy data
754e18403dSZiyangZhang * When NEED_GET_DATA is set, ublksrv has to issue UBLK_IO_NEED_GET_DATA
764e18403dSZiyangZhang * command after ublk driver returns UBLK_IO_RES_NEED_GET_DATA.
774e18403dSZiyangZhang *
784e18403dSZiyangZhang * It is only used if ublksrv set UBLK_F_NEED_GET_DATA flag
794e18403dSZiyangZhang * while starting a ublk device.
8071f28f31SMing Lei */
812d786e66SMing Lei
822d786e66SMing Lei /*
832d786e66SMing Lei * Legacy IO command definition, don't use in new application, and don't
842d786e66SMing Lei * add new such definition any more
852d786e66SMing Lei */
8671f28f31SMing Lei #define UBLK_IO_FETCH_REQ 0x20
8771f28f31SMing Lei #define UBLK_IO_COMMIT_AND_FETCH_REQ 0x21
884e18403dSZiyangZhang #define UBLK_IO_NEED_GET_DATA 0x22
8971f28f31SMing Lei
902d786e66SMing Lei /* Any new IO command should encode by __IOWR() */
912d786e66SMing Lei #define UBLK_U_IO_FETCH_REQ \
922d786e66SMing Lei _IOWR('u', UBLK_IO_FETCH_REQ, struct ublksrv_io_cmd)
932d786e66SMing Lei #define UBLK_U_IO_COMMIT_AND_FETCH_REQ \
942d786e66SMing Lei _IOWR('u', UBLK_IO_COMMIT_AND_FETCH_REQ, struct ublksrv_io_cmd)
952d786e66SMing Lei #define UBLK_U_IO_NEED_GET_DATA \
962d786e66SMing Lei _IOWR('u', UBLK_IO_NEED_GET_DATA, struct ublksrv_io_cmd)
972d786e66SMing Lei
9871f28f31SMing Lei /* only ABORT means that no re-fetch */
9971f28f31SMing Lei #define UBLK_IO_RES_OK 0
1004e18403dSZiyangZhang #define UBLK_IO_RES_NEED_GET_DATA 1
10171f28f31SMing Lei #define UBLK_IO_RES_ABORT (-ENODEV)
10271f28f31SMing Lei
10371f28f31SMing Lei #define UBLKSRV_CMD_BUF_OFFSET 0
10471f28f31SMing Lei #define UBLKSRV_IO_BUF_OFFSET 0x80000000
10571f28f31SMing Lei
10662fe99ceSMing Lei /* tag bit is 16bit, so far limit at most 4096 IOs for each queue */
10771f28f31SMing Lei #define UBLK_MAX_QUEUE_DEPTH 4096
10871f28f31SMing Lei
10962fe99ceSMing Lei /* single IO buffer max size is 32MB */
11062fe99ceSMing Lei #define UBLK_IO_BUF_OFF 0
11162fe99ceSMing Lei #define UBLK_IO_BUF_BITS 25
11262fe99ceSMing Lei #define UBLK_IO_BUF_BITS_MASK ((1ULL << UBLK_IO_BUF_BITS) - 1)
11362fe99ceSMing Lei
11462fe99ceSMing Lei /* so at most 64K IOs for each queue */
11562fe99ceSMing Lei #define UBLK_TAG_OFF UBLK_IO_BUF_BITS
11662fe99ceSMing Lei #define UBLK_TAG_BITS 16
11762fe99ceSMing Lei #define UBLK_TAG_BITS_MASK ((1ULL << UBLK_TAG_BITS) - 1)
11862fe99ceSMing Lei
11962fe99ceSMing Lei /* max 4096 queues */
12062fe99ceSMing Lei #define UBLK_QID_OFF (UBLK_TAG_OFF + UBLK_TAG_BITS)
12162fe99ceSMing Lei #define UBLK_QID_BITS 12
12262fe99ceSMing Lei #define UBLK_QID_BITS_MASK ((1ULL << UBLK_QID_BITS) - 1)
12362fe99ceSMing Lei
12462fe99ceSMing Lei #define UBLK_MAX_NR_QUEUES (1U << UBLK_QID_BITS)
12562fe99ceSMing Lei
12662fe99ceSMing Lei #define UBLKSRV_IO_BUF_TOTAL_BITS (UBLK_QID_OFF + UBLK_QID_BITS)
12762fe99ceSMing Lei #define UBLKSRV_IO_BUF_TOTAL_SIZE (1ULL << UBLKSRV_IO_BUF_TOTAL_BITS)
12862fe99ceSMing Lei
12971f28f31SMing Lei /*
13071f28f31SMing Lei * zero copy requires 4k block size, and can remap ublk driver's io
13171f28f31SMing Lei * request into ublksrv's vm space
13271f28f31SMing Lei */
1336d8c5afcSMing Lei #define UBLK_F_SUPPORT_ZERO_COPY (1ULL << 0)
13471f28f31SMing Lei
1350edb3696SMing Lei /*
1360edb3696SMing Lei * Force to complete io cmd via io_uring_cmd_complete_in_task so that
1370edb3696SMing Lei * performance comparison is done easily with using task_work_add
1380edb3696SMing Lei */
1396d8c5afcSMing Lei #define UBLK_F_URING_CMD_COMP_IN_TASK (1ULL << 1)
1400edb3696SMing Lei
1414e18403dSZiyangZhang /*
1424e18403dSZiyangZhang * User should issue io cmd again for write requests to
1434e18403dSZiyangZhang * set io buffer address and copy data from bio vectors
1444e18403dSZiyangZhang * to the userspace io buffer.
1454e18403dSZiyangZhang *
1464e18403dSZiyangZhang * In this mode, task_work is not used.
1474e18403dSZiyangZhang */
1484e18403dSZiyangZhang #define UBLK_F_NEED_GET_DATA (1UL << 2)
1494e18403dSZiyangZhang
15077a440e2SZiyangZhang #define UBLK_F_USER_RECOVERY (1UL << 3)
15177a440e2SZiyangZhang
152a0d41dc1SZiyangZhang #define UBLK_F_USER_RECOVERY_REISSUE (1UL << 4)
153a0d41dc1SZiyangZhang
1544093cb5aSMing Lei /*
1554093cb5aSMing Lei * Unprivileged user can create /dev/ublkcN and /dev/ublkbN.
1564093cb5aSMing Lei *
1574093cb5aSMing Lei * /dev/ublk-control needs to be available for unprivileged user, and it
1584093cb5aSMing Lei * can be done via udev rule to make all control commands available to
1594093cb5aSMing Lei * unprivileged user. Except for the command of UBLK_CMD_ADD_DEV, all
1604093cb5aSMing Lei * other commands are only allowed for the owner of the specified device.
1614093cb5aSMing Lei *
1624093cb5aSMing Lei * When userspace sends UBLK_CMD_ADD_DEV, the device pair's owner_uid and
1634093cb5aSMing Lei * owner_gid are stored to ublksrv_ctrl_dev_info by kernel, so far only
1644093cb5aSMing Lei * the current user's uid/gid is stored, that said owner of the created
1654093cb5aSMing Lei * device is always the current user.
1664093cb5aSMing Lei *
1674093cb5aSMing Lei * We still need udev rule to apply OWNER/GROUP with the stored owner_uid
1684093cb5aSMing Lei * and owner_gid.
1694093cb5aSMing Lei *
1704093cb5aSMing Lei * Then ublk server can be run as unprivileged user, and /dev/ublkbN can
1714093cb5aSMing Lei * be accessed and managed by its owner represented by owner_uid/owner_gid.
1724093cb5aSMing Lei */
1734093cb5aSMing Lei #define UBLK_F_UNPRIVILEGED_DEV (1UL << 5)
1744093cb5aSMing Lei
1752d786e66SMing Lei /* use ioctl encoding for uring command */
1762d786e66SMing Lei #define UBLK_F_CMD_IOCTL_ENCODE (1UL << 6)
1772d786e66SMing Lei
1781172d5b8SMing Lei /* Copy between request and user buffer by pread()/pwrite() */
1791172d5b8SMing Lei #define UBLK_F_USER_COPY (1UL << 7)
1801172d5b8SMing Lei
18129802d7cSAndreas Hindborg /*
18229802d7cSAndreas Hindborg * User space sets this flag when setting up the device to request zoned storage support. Kernel may
18329802d7cSAndreas Hindborg * deny the request by returning an error.
18429802d7cSAndreas Hindborg */
18529802d7cSAndreas Hindborg #define UBLK_F_ZONED (1ULL << 8)
18629802d7cSAndreas Hindborg
18771f28f31SMing Lei /* device state */
18871f28f31SMing Lei #define UBLK_S_DEV_DEAD 0
18971f28f31SMing Lei #define UBLK_S_DEV_LIVE 1
19077a440e2SZiyangZhang #define UBLK_S_DEV_QUIESCED 2
19171f28f31SMing Lei
19271f28f31SMing Lei /* shipped via sqe->cmd of io_uring command */
19371f28f31SMing Lei struct ublksrv_ctrl_cmd {
19471f28f31SMing Lei /* sent to which device, must be valid */
19571f28f31SMing Lei __u32 dev_id;
19671f28f31SMing Lei
19771f28f31SMing Lei /* sent to which queue, must be -1 if the cmd isn't for queue */
19871f28f31SMing Lei __u16 queue_id;
19971f28f31SMing Lei /*
20071f28f31SMing Lei * cmd specific buffer, can be IN or OUT.
20171f28f31SMing Lei */
20271f28f31SMing Lei __u16 len;
20371f28f31SMing Lei __u64 addr;
20471f28f31SMing Lei
20571f28f31SMing Lei /* inline data */
2064093cb5aSMing Lei __u64 data[1];
2074093cb5aSMing Lei
2084093cb5aSMing Lei /*
2094093cb5aSMing Lei * Used for UBLK_F_UNPRIVILEGED_DEV and UBLK_CMD_GET_DEV_INFO2
2104093cb5aSMing Lei * only, include null char
2114093cb5aSMing Lei */
2124093cb5aSMing Lei __u16 dev_path_len;
2134093cb5aSMing Lei __u16 pad;
2144093cb5aSMing Lei __u32 reserved;
21571f28f31SMing Lei };
21671f28f31SMing Lei
21771f28f31SMing Lei struct ublksrv_ctrl_dev_info {
21871f28f31SMing Lei __u16 nr_hw_queues;
21971f28f31SMing Lei __u16 queue_depth;
22071f28f31SMing Lei __u16 state;
2214bf9cbf3SMing Lei __u16 pad0;
22271f28f31SMing Lei
2234bf9cbf3SMing Lei __u32 max_io_buf_bytes;
22471f28f31SMing Lei __u32 dev_id;
22571f28f31SMing Lei
22671f28f31SMing Lei __s32 ublksrv_pid;
2274bf9cbf3SMing Lei __u32 pad1;
2284bf9cbf3SMing Lei
2296d8c5afcSMing Lei __u64 flags;
23071f28f31SMing Lei
23171f28f31SMing Lei /* For ublksrv internal use, invisible to ublk driver */
23271f28f31SMing Lei __u64 ublksrv_flags;
2334bf9cbf3SMing Lei
2344093cb5aSMing Lei __u32 owner_uid; /* store by kernel */
2354093cb5aSMing Lei __u32 owner_gid; /* store by kernel */
2364bf9cbf3SMing Lei __u64 reserved1;
2374bf9cbf3SMing Lei __u64 reserved2;
23871f28f31SMing Lei };
23971f28f31SMing Lei
24071f28f31SMing Lei #define UBLK_IO_OP_READ 0
24171f28f31SMing Lei #define UBLK_IO_OP_WRITE 1
24271f28f31SMing Lei #define UBLK_IO_OP_FLUSH 2
24371f28f31SMing Lei #define UBLK_IO_OP_DISCARD 3
24471f28f31SMing Lei #define UBLK_IO_OP_WRITE_SAME 4
24571f28f31SMing Lei #define UBLK_IO_OP_WRITE_ZEROES 5
24629802d7cSAndreas Hindborg #define UBLK_IO_OP_ZONE_OPEN 10
24729802d7cSAndreas Hindborg #define UBLK_IO_OP_ZONE_CLOSE 11
24829802d7cSAndreas Hindborg #define UBLK_IO_OP_ZONE_FINISH 12
24929802d7cSAndreas Hindborg #define UBLK_IO_OP_ZONE_APPEND 13
250851e0629SMing Lei #define UBLK_IO_OP_ZONE_RESET_ALL 14
25129802d7cSAndreas Hindborg #define UBLK_IO_OP_ZONE_RESET 15
25229802d7cSAndreas Hindborg /*
25329802d7cSAndreas Hindborg * Construct a zone report. The report request is carried in `struct
25429802d7cSAndreas Hindborg * ublksrv_io_desc`. The `start_sector` field must be the first sector of a zone
25529802d7cSAndreas Hindborg * and shall indicate the first zone of the report. The `nr_zones` shall
25629802d7cSAndreas Hindborg * indicate how many zones should be reported at most. The report shall be
25729802d7cSAndreas Hindborg * delivered as a `struct blk_zone` array. To report fewer zones than requested,
25829802d7cSAndreas Hindborg * zero the last entry of the returned array.
25929802d7cSAndreas Hindborg *
26029802d7cSAndreas Hindborg * Related definitions(blk_zone, blk_zone_cond, blk_zone_type, ...) in
26129802d7cSAndreas Hindborg * include/uapi/linux/blkzoned.h are part of ublk UAPI.
26229802d7cSAndreas Hindborg */
26329802d7cSAndreas Hindborg #define UBLK_IO_OP_REPORT_ZONES 18
26471f28f31SMing Lei
26571f28f31SMing Lei #define UBLK_IO_F_FAILFAST_DEV (1U << 8)
26671f28f31SMing Lei #define UBLK_IO_F_FAILFAST_TRANSPORT (1U << 9)
26771f28f31SMing Lei #define UBLK_IO_F_FAILFAST_DRIVER (1U << 10)
26871f28f31SMing Lei #define UBLK_IO_F_META (1U << 11)
26971f28f31SMing Lei #define UBLK_IO_F_FUA (1U << 13)
27071f28f31SMing Lei #define UBLK_IO_F_NOUNMAP (1U << 15)
27171f28f31SMing Lei #define UBLK_IO_F_SWAP (1U << 16)
27271f28f31SMing Lei
27371f28f31SMing Lei /*
27471f28f31SMing Lei * io cmd is described by this structure, and stored in share memory, indexed
27571f28f31SMing Lei * by request tag.
27671f28f31SMing Lei *
27771f28f31SMing Lei * The data is stored by ublk driver, and read by ublksrv after one fetch command
27871f28f31SMing Lei * returns.
27971f28f31SMing Lei */
28071f28f31SMing Lei struct ublksrv_io_desc {
28171f28f31SMing Lei /* op: bit 0-7, flags: bit 8-31 */
28271f28f31SMing Lei __u32 op_flags;
28371f28f31SMing Lei
28429802d7cSAndreas Hindborg union {
28571f28f31SMing Lei __u32 nr_sectors;
28629802d7cSAndreas Hindborg __u32 nr_zones; /* for UBLK_IO_OP_REPORT_ZONES */
28729802d7cSAndreas Hindborg };
28871f28f31SMing Lei
28971f28f31SMing Lei /* start sector for this io */
29071f28f31SMing Lei __u64 start_sector;
29171f28f31SMing Lei
29271f28f31SMing Lei /* buffer address in ublksrv daemon vm space, from ublk driver */
29371f28f31SMing Lei __u64 addr;
29471f28f31SMing Lei };
29571f28f31SMing Lei
ublksrv_get_op(const struct ublksrv_io_desc * iod)29671f28f31SMing Lei static inline __u8 ublksrv_get_op(const struct ublksrv_io_desc *iod)
29771f28f31SMing Lei {
29871f28f31SMing Lei return iod->op_flags & 0xff;
29971f28f31SMing Lei }
30071f28f31SMing Lei
ublksrv_get_flags(const struct ublksrv_io_desc * iod)30171f28f31SMing Lei static inline __u32 ublksrv_get_flags(const struct ublksrv_io_desc *iod)
30271f28f31SMing Lei {
30371f28f31SMing Lei return iod->op_flags >> 8;
30471f28f31SMing Lei }
30571f28f31SMing Lei
30671f28f31SMing Lei /* issued to ublk driver via /dev/ublkcN */
30771f28f31SMing Lei struct ublksrv_io_cmd {
30871f28f31SMing Lei __u16 q_id;
30971f28f31SMing Lei
31071f28f31SMing Lei /* for fetch/commit which result */
31171f28f31SMing Lei __u16 tag;
31271f28f31SMing Lei
31371f28f31SMing Lei /* io result, it is valid for COMMIT* command only */
31471f28f31SMing Lei __s32 result;
31571f28f31SMing Lei
31629802d7cSAndreas Hindborg union {
31771f28f31SMing Lei /*
31871f28f31SMing Lei * userspace buffer address in ublksrv daemon process, valid for
31971f28f31SMing Lei * FETCH* command only
32029802d7cSAndreas Hindborg *
32129802d7cSAndreas Hindborg * `addr` should not be used when UBLK_F_USER_COPY is enabled,
32229802d7cSAndreas Hindborg * because userspace handles data copy by pread()/pwrite() over
32329802d7cSAndreas Hindborg * /dev/ublkcN. But in case of UBLK_F_ZONED, this union is
32429802d7cSAndreas Hindborg * re-used to pass back the allocated LBA for
32529802d7cSAndreas Hindborg * UBLK_IO_OP_ZONE_APPEND which actually depends on
32629802d7cSAndreas Hindborg * UBLK_F_USER_COPY
32771f28f31SMing Lei */
32871f28f31SMing Lei __u64 addr;
32929802d7cSAndreas Hindborg __u64 zone_append_lba;
33029802d7cSAndreas Hindborg };
33171f28f31SMing Lei };
33271f28f31SMing Lei
3330aa73170SMing Lei struct ublk_param_basic {
3340aa73170SMing Lei #define UBLK_ATTR_READ_ONLY (1 << 0)
3350aa73170SMing Lei #define UBLK_ATTR_ROTATIONAL (1 << 1)
3360aa73170SMing Lei #define UBLK_ATTR_VOLATILE_CACHE (1 << 2)
3370aa73170SMing Lei #define UBLK_ATTR_FUA (1 << 3)
3380aa73170SMing Lei __u32 attrs;
3390aa73170SMing Lei __u8 logical_bs_shift;
3400aa73170SMing Lei __u8 physical_bs_shift;
3410aa73170SMing Lei __u8 io_opt_shift;
3420aa73170SMing Lei __u8 io_min_shift;
3430aa73170SMing Lei
3440aa73170SMing Lei __u32 max_sectors;
3450aa73170SMing Lei __u32 chunk_sectors;
3460aa73170SMing Lei
3470aa73170SMing Lei __u64 dev_sectors;
3480aa73170SMing Lei __u64 virt_boundary_mask;
3490aa73170SMing Lei };
3500aa73170SMing Lei
3510aa73170SMing Lei struct ublk_param_discard {
3520aa73170SMing Lei __u32 discard_alignment;
3530aa73170SMing Lei
3540aa73170SMing Lei __u32 discard_granularity;
3550aa73170SMing Lei __u32 max_discard_sectors;
3560aa73170SMing Lei
3570aa73170SMing Lei __u32 max_write_zeroes_sectors;
3580aa73170SMing Lei __u16 max_discard_segments;
3590aa73170SMing Lei __u16 reserved0;
3600aa73170SMing Lei };
3610aa73170SMing Lei
362abb864d3SMing Lei /*
363abb864d3SMing Lei * read-only, can't set via UBLK_CMD_SET_PARAMS, disk_devt is available
364abb864d3SMing Lei * after device is started
365abb864d3SMing Lei */
366abb864d3SMing Lei struct ublk_param_devt {
367abb864d3SMing Lei __u32 char_major;
368abb864d3SMing Lei __u32 char_minor;
369abb864d3SMing Lei __u32 disk_major;
370abb864d3SMing Lei __u32 disk_minor;
371abb864d3SMing Lei };
372abb864d3SMing Lei
37329802d7cSAndreas Hindborg struct ublk_param_zoned {
37429802d7cSAndreas Hindborg __u32 max_open_zones;
37529802d7cSAndreas Hindborg __u32 max_active_zones;
37629802d7cSAndreas Hindborg __u32 max_zone_append_sectors;
37729802d7cSAndreas Hindborg __u8 reserved[20];
37829802d7cSAndreas Hindborg };
37929802d7cSAndreas Hindborg
3800aa73170SMing Lei struct ublk_params {
3810aa73170SMing Lei /*
3820aa73170SMing Lei * Total length of parameters, userspace has to set 'len' for both
3830aa73170SMing Lei * SET_PARAMS and GET_PARAMS command, and driver may update len
3840aa73170SMing Lei * if two sides use different version of 'ublk_params', same with
3850aa73170SMing Lei * 'types' fields.
3860aa73170SMing Lei */
3870aa73170SMing Lei __u32 len;
3880aa73170SMing Lei #define UBLK_PARAM_TYPE_BASIC (1 << 0)
3890aa73170SMing Lei #define UBLK_PARAM_TYPE_DISCARD (1 << 1)
390abb864d3SMing Lei #define UBLK_PARAM_TYPE_DEVT (1 << 2)
39129802d7cSAndreas Hindborg #define UBLK_PARAM_TYPE_ZONED (1 << 3)
3920aa73170SMing Lei __u32 types; /* types of parameter included */
3930aa73170SMing Lei
3940aa73170SMing Lei struct ublk_param_basic basic;
3950aa73170SMing Lei struct ublk_param_discard discard;
396abb864d3SMing Lei struct ublk_param_devt devt;
39729802d7cSAndreas Hindborg struct ublk_param_zoned zoned;
3980aa73170SMing Lei };
3990aa73170SMing Lei
40071f28f31SMing Lei #endif
401