xref: /linux/include/uapi/linux/ublk_cmd.h (revision e540341508ce2f6e27810106253d5de194b66750)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef USER_BLK_DRV_CMD_INC_H
3 #define USER_BLK_DRV_CMD_INC_H
4 
5 #include <linux/types.h>
6 
7 /* ublk server command definition */
8 
9 /*
10  * Admin commands, issued by ublk server, and handled by ublk driver.
11  *
12  * Legacy command definition, don't use in new application, and don't
13  * add new such definition any more
14  */
15 #define	UBLK_CMD_GET_QUEUE_AFFINITY	0x01
16 #define	UBLK_CMD_GET_DEV_INFO	0x02
17 #define	UBLK_CMD_ADD_DEV		0x04
18 #define	UBLK_CMD_DEL_DEV		0x05
19 #define	UBLK_CMD_START_DEV	0x06
20 #define	UBLK_CMD_STOP_DEV	0x07
21 #define	UBLK_CMD_SET_PARAMS	0x08
22 #define	UBLK_CMD_GET_PARAMS	0x09
23 #define	UBLK_CMD_START_USER_RECOVERY	0x10
24 #define	UBLK_CMD_END_USER_RECOVERY	0x11
25 #define	UBLK_CMD_GET_DEV_INFO2		0x12
26 
27 /* Any new ctrl command should encode by __IO*() */
28 #define UBLK_U_CMD_GET_QUEUE_AFFINITY	\
29 	_IOR('u', UBLK_CMD_GET_QUEUE_AFFINITY, struct ublksrv_ctrl_cmd)
30 #define UBLK_U_CMD_GET_DEV_INFO		\
31 	_IOR('u', UBLK_CMD_GET_DEV_INFO, struct ublksrv_ctrl_cmd)
32 #define UBLK_U_CMD_ADD_DEV		\
33 	_IOWR('u', UBLK_CMD_ADD_DEV, struct ublksrv_ctrl_cmd)
34 #define UBLK_U_CMD_DEL_DEV		\
35 	_IOWR('u', UBLK_CMD_DEL_DEV, struct ublksrv_ctrl_cmd)
36 #define UBLK_U_CMD_START_DEV		\
37 	_IOWR('u', UBLK_CMD_START_DEV, struct ublksrv_ctrl_cmd)
38 #define UBLK_U_CMD_STOP_DEV		\
39 	_IOWR('u', UBLK_CMD_STOP_DEV, struct ublksrv_ctrl_cmd)
40 #define UBLK_U_CMD_SET_PARAMS		\
41 	_IOWR('u', UBLK_CMD_SET_PARAMS, struct ublksrv_ctrl_cmd)
42 #define UBLK_U_CMD_GET_PARAMS		\
43 	_IOR('u', UBLK_CMD_GET_PARAMS, struct ublksrv_ctrl_cmd)
44 #define UBLK_U_CMD_START_USER_RECOVERY	\
45 	_IOWR('u', UBLK_CMD_START_USER_RECOVERY, struct ublksrv_ctrl_cmd)
46 #define UBLK_U_CMD_END_USER_RECOVERY	\
47 	_IOWR('u', UBLK_CMD_END_USER_RECOVERY, struct ublksrv_ctrl_cmd)
48 #define UBLK_U_CMD_GET_DEV_INFO2	\
49 	_IOR('u', UBLK_CMD_GET_DEV_INFO2, struct ublksrv_ctrl_cmd)
50 #define UBLK_U_CMD_GET_FEATURES	\
51 	_IOR('u', 0x13, struct ublksrv_ctrl_cmd)
52 #define UBLK_U_CMD_DEL_DEV_ASYNC	\
53 	_IOR('u', 0x14, struct ublksrv_ctrl_cmd)
54 #define UBLK_U_CMD_UPDATE_SIZE		\
55 	_IOWR('u', 0x15, struct ublksrv_ctrl_cmd)
56 #define UBLK_U_CMD_QUIESCE_DEV		\
57 	_IOWR('u', 0x16, struct ublksrv_ctrl_cmd)
58 
59 /*
60  * 64bits are enough now, and it should be easy to extend in case of
61  * running out of feature flags
62  */
63 #define UBLK_FEATURES_LEN  8
64 
65 /*
66  * IO commands, issued by ublk server, and handled by ublk driver.
67  *
68  * FETCH_REQ: issued via sqe(URING_CMD) beforehand for fetching IO request
69  *      from ublk driver, should be issued only when starting device. After
70  *      the associated cqe is returned, request's tag can be retrieved via
71  *      cqe->userdata.
72  *
73  * COMMIT_AND_FETCH_REQ: issued via sqe(URING_CMD) after ublkserver handled
74  *      this IO request, request's handling result is committed to ublk
75  *      driver, meantime FETCH_REQ is piggyback, and FETCH_REQ has to be
76  *      handled before completing io request.
77  *
78  * NEED_GET_DATA: only used for write requests to set io addr and copy data
79  *      When NEED_GET_DATA is set, ublksrv has to issue UBLK_IO_NEED_GET_DATA
80  *      command after ublk driver returns UBLK_IO_RES_NEED_GET_DATA.
81  *
82  *      It is only used if ublksrv set UBLK_F_NEED_GET_DATA flag
83  *      while starting a ublk device.
84  */
85 
86 /*
87  * Legacy IO command definition, don't use in new application, and don't
88  * add new such definition any more
89  */
90 #define	UBLK_IO_FETCH_REQ		0x20
91 #define	UBLK_IO_COMMIT_AND_FETCH_REQ	0x21
92 #define	UBLK_IO_NEED_GET_DATA	0x22
93 
94 /* Any new IO command should encode by __IOWR() */
95 #define	UBLK_U_IO_FETCH_REQ		\
96 	_IOWR('u', UBLK_IO_FETCH_REQ, struct ublksrv_io_cmd)
97 #define	UBLK_U_IO_COMMIT_AND_FETCH_REQ	\
98 	_IOWR('u', UBLK_IO_COMMIT_AND_FETCH_REQ, struct ublksrv_io_cmd)
99 #define	UBLK_U_IO_NEED_GET_DATA		\
100 	_IOWR('u', UBLK_IO_NEED_GET_DATA, struct ublksrv_io_cmd)
101 #define	UBLK_U_IO_REGISTER_IO_BUF	\
102 	_IOWR('u', 0x23, struct ublksrv_io_cmd)
103 #define	UBLK_U_IO_UNREGISTER_IO_BUF	\
104 	_IOWR('u', 0x24, struct ublksrv_io_cmd)
105 
106 /* only ABORT means that no re-fetch */
107 #define UBLK_IO_RES_OK			0
108 #define UBLK_IO_RES_NEED_GET_DATA	1
109 #define UBLK_IO_RES_ABORT		(-ENODEV)
110 
111 #define UBLKSRV_CMD_BUF_OFFSET	0
112 #define UBLKSRV_IO_BUF_OFFSET	0x80000000
113 
114 /* tag bit is 16bit, so far limit at most 4096 IOs for each queue */
115 #define UBLK_MAX_QUEUE_DEPTH	4096
116 
117 /* single IO buffer max size is 32MB */
118 #define UBLK_IO_BUF_OFF		0
119 #define UBLK_IO_BUF_BITS	25
120 #define UBLK_IO_BUF_BITS_MASK	((1ULL << UBLK_IO_BUF_BITS) - 1)
121 
122 /* so at most 64K IOs for each queue */
123 #define UBLK_TAG_OFF		UBLK_IO_BUF_BITS
124 #define UBLK_TAG_BITS		16
125 #define UBLK_TAG_BITS_MASK	((1ULL << UBLK_TAG_BITS) - 1)
126 
127 /* max 4096 queues */
128 #define UBLK_QID_OFF		(UBLK_TAG_OFF + UBLK_TAG_BITS)
129 #define UBLK_QID_BITS		12
130 #define UBLK_QID_BITS_MASK	((1ULL << UBLK_QID_BITS) - 1)
131 
132 #define UBLK_MAX_NR_QUEUES	(1U << UBLK_QID_BITS)
133 
134 #define UBLKSRV_IO_BUF_TOTAL_BITS	(UBLK_QID_OFF + UBLK_QID_BITS)
135 #define UBLKSRV_IO_BUF_TOTAL_SIZE	(1ULL << UBLKSRV_IO_BUF_TOTAL_BITS)
136 
137 /*
138  * ublk server can register data buffers for incoming I/O requests with a sparse
139  * io_uring buffer table. The request buffer can then be used as the data buffer
140  * for io_uring operations via the fixed buffer index.
141  * Note that the ublk server can never directly access the request data memory.
142  *
143  * To use this feature, the ublk server must first register a sparse buffer
144  * table on an io_uring instance.
145  * When an incoming ublk request is received, the ublk server submits a
146  * UBLK_U_IO_REGISTER_IO_BUF command to that io_uring instance. The
147  * ublksrv_io_cmd's q_id and tag specify the request whose buffer to register
148  * and addr is the index in the io_uring's buffer table to install the buffer.
149  * SQEs can now be submitted to the io_uring to read/write the request's buffer
150  * by enabling fixed buffers (e.g. using IORING_OP_{READ,WRITE}_FIXED or
151  * IORING_URING_CMD_FIXED) and passing the registered buffer index in buf_index.
152  * Once the last io_uring operation using the request's buffer has completed,
153  * the ublk server submits a UBLK_U_IO_UNREGISTER_IO_BUF command with q_id, tag,
154  * and addr again specifying the request buffer to unregister.
155  * The ublk request is completed when its buffer is unregistered from all
156  * io_uring instances and the ublk server issues UBLK_U_IO_COMMIT_AND_FETCH_REQ.
157  *
158  * Not available for UBLK_F_UNPRIVILEGED_DEV, as a ublk server can leak
159  * uninitialized kernel memory by not reading into the full request buffer.
160  */
161 #define UBLK_F_SUPPORT_ZERO_COPY	(1ULL << 0)
162 
163 /*
164  * Force to complete io cmd via io_uring_cmd_complete_in_task so that
165  * performance comparison is done easily with using task_work_add
166  */
167 #define UBLK_F_URING_CMD_COMP_IN_TASK	(1ULL << 1)
168 
169 /*
170  * User should issue io cmd again for write requests to
171  * set io buffer address and copy data from bio vectors
172  * to the userspace io buffer.
173  *
174  * In this mode, task_work is not used.
175  */
176 #define UBLK_F_NEED_GET_DATA (1UL << 2)
177 
178 /*
179  * - Block devices are recoverable if ublk server exits and restarts
180  * - Outstanding I/O when ublk server exits is met with errors
181  * - I/O issued while there is no ublk server queues
182  */
183 #define UBLK_F_USER_RECOVERY	(1UL << 3)
184 
185 /*
186  * - Block devices are recoverable if ublk server exits and restarts
187  * - Outstanding I/O when ublk server exits is reissued
188  * - I/O issued while there is no ublk server queues
189  */
190 #define UBLK_F_USER_RECOVERY_REISSUE	(1UL << 4)
191 
192 /*
193  * Unprivileged user can create /dev/ublkcN and /dev/ublkbN.
194  *
195  * /dev/ublk-control needs to be available for unprivileged user, and it
196  * can be done via udev rule to make all control commands available to
197  * unprivileged user. Except for the command of UBLK_CMD_ADD_DEV, all
198  * other commands are only allowed for the owner of the specified device.
199  *
200  * When userspace sends UBLK_CMD_ADD_DEV, the device pair's owner_uid and
201  * owner_gid are stored to ublksrv_ctrl_dev_info by kernel, so far only
202  * the current user's uid/gid is stored, that said owner of the created
203  * device is always the current user.
204  *
205  * We still need udev rule to apply OWNER/GROUP with the stored owner_uid
206  * and owner_gid.
207  *
208  * Then ublk server can be run as unprivileged user, and /dev/ublkbN can
209  * be accessed and managed by its owner represented by owner_uid/owner_gid.
210  */
211 #define UBLK_F_UNPRIVILEGED_DEV	(1UL << 5)
212 
213 /* use ioctl encoding for uring command */
214 #define UBLK_F_CMD_IOCTL_ENCODE	(1UL << 6)
215 
216 /*
217  *  Copy between request and user buffer by pread()/pwrite()
218  *
219  *  Not available for UBLK_F_UNPRIVILEGED_DEV, otherwise userspace may
220  *  deceive us by not filling request buffer, then kernel uninitialized
221  *  data may be leaked.
222  */
223 #define UBLK_F_USER_COPY	(1UL << 7)
224 
225 /*
226  * User space sets this flag when setting up the device to request zoned storage support. Kernel may
227  * deny the request by returning an error.
228  */
229 #define UBLK_F_ZONED (1ULL << 8)
230 
231 /*
232  * - Block devices are recoverable if ublk server exits and restarts
233  * - Outstanding I/O when ublk server exits is met with errors
234  * - I/O issued while there is no ublk server is met with errors
235  */
236 #define UBLK_F_USER_RECOVERY_FAIL_IO (1ULL << 9)
237 
238 /*
239  * Resizing a block device is possible with UBLK_U_CMD_UPDATE_SIZE
240  * New size is passed in cmd->data[0] and is in units of sectors
241  */
242 #define UBLK_F_UPDATE_SIZE		 (1ULL << 10)
243 
244 /*
245  * request buffer is registered automatically to uring_cmd's io_uring
246  * context before delivering this io command to ublk server, meantime
247  * it is un-registered automatically when completing this io command.
248  *
249  * For using this feature:
250  *
251  * - ublk server has to create sparse buffer table on the same `io_ring_ctx`
252  *   for issuing `UBLK_IO_FETCH_REQ` and `UBLK_IO_COMMIT_AND_FETCH_REQ`.
253  *   If uring_cmd isn't issued on same `io_ring_ctx`, it is ublk server's
254  *   responsibility to unregister the buffer by issuing `IO_UNREGISTER_IO_BUF`
255  *   manually, otherwise this ublk request won't complete.
256  *
257  * - ublk server passes auto buf register data via uring_cmd's sqe->addr,
258  *   `struct ublk_auto_buf_reg` is populated from sqe->addr, please see
259  *   the definition of ublk_sqe_addr_to_auto_buf_reg()
260  *
261  * - pass buffer index from `ublk_auto_buf_reg.index`
262  *
263  * - all reserved fields in `ublk_auto_buf_reg` need to be zeroed
264  *
265  * - pass flags from `ublk_auto_buf_reg.flags` if needed
266  *
267  * This way avoids extra cost from two uring_cmd, but also simplifies backend
268  * implementation, such as, the dependency on IO_REGISTER_IO_BUF and
269  * IO_UNREGISTER_IO_BUF becomes not necessary.
270  *
271  * If wrong data or flags are provided, both IO_FETCH_REQ and
272  * IO_COMMIT_AND_FETCH_REQ are failed, for the latter, the ublk IO request
273  * won't be completed until new IO_COMMIT_AND_FETCH_REQ command is issued
274  * successfully
275  */
276 #define UBLK_F_AUTO_BUF_REG 	(1ULL << 11)
277 
278 /*
279  * Control command `UBLK_U_CMD_QUIESCE_DEV` is added for quiescing device,
280  * which state can be transitioned to `UBLK_S_DEV_QUIESCED` or
281  * `UBLK_S_DEV_FAIL_IO` finally, and it needs ublk server cooperation for
282  * handling `UBLK_IO_RES_ABORT` correctly.
283  *
284  * Typical use case is for supporting to upgrade ublk server application,
285  * meantime keep ublk block device persistent during the period.
286  *
287  * This feature is only available when UBLK_F_USER_RECOVERY is enabled.
288  *
289  * Note, this command returns -EBUSY in case that all IO commands are being
290  * handled by ublk server and not completed in specified time period which
291  * is passed from the control command parameter.
292  */
293 #define UBLK_F_QUIESCE		(1ULL << 12)
294 
295 /*
296  * If this feature is set, ublk_drv supports each (qid,tag) pair having
297  * its own independent daemon task that is responsible for handling it.
298  * If it is not set, daemons are per-queue instead, so for two pairs
299  * (qid1,tag1) and (qid2,tag2), if qid1 == qid2, then the same task must
300  * be responsible for handling (qid1,tag1) and (qid2,tag2).
301  */
302 #define UBLK_F_PER_IO_DAEMON (1ULL << 13)
303 
304 /* device state */
305 #define UBLK_S_DEV_DEAD	0
306 #define UBLK_S_DEV_LIVE	1
307 #define UBLK_S_DEV_QUIESCED	2
308 #define UBLK_S_DEV_FAIL_IO 	3
309 
310 /* shipped via sqe->cmd of io_uring command */
311 struct ublksrv_ctrl_cmd {
312 	/* sent to which device, must be valid */
313 	__u32	dev_id;
314 
315 	/* sent to which queue, must be -1 if the cmd isn't for queue */
316 	__u16	queue_id;
317 	/*
318 	 * cmd specific buffer, can be IN or OUT.
319 	 */
320 	__u16	len;
321 	__u64	addr;
322 
323 	/* inline data */
324 	__u64	data[1];
325 
326 	/*
327 	 * Used for UBLK_F_UNPRIVILEGED_DEV and UBLK_CMD_GET_DEV_INFO2
328 	 * only, include null char
329 	 */
330 	__u16	dev_path_len;
331 	__u16	pad;
332 	__u32	reserved;
333 };
334 
335 struct ublksrv_ctrl_dev_info {
336 	__u16	nr_hw_queues;
337 	__u16	queue_depth;
338 	__u16	state;
339 	__u16	pad0;
340 
341 	__u32	max_io_buf_bytes;
342 	__u32	dev_id;
343 
344 	__s32	ublksrv_pid;
345 	__u32	pad1;
346 
347 	__u64	flags;
348 
349 	/* For ublksrv internal use, invisible to ublk driver */
350 	__u64	ublksrv_flags;
351 
352 	__u32	owner_uid;	/* store by kernel */
353 	__u32	owner_gid;	/* store by kernel */
354 	__u64	reserved1;
355 	__u64   reserved2;
356 };
357 
358 #define		UBLK_IO_OP_READ		0
359 #define		UBLK_IO_OP_WRITE		1
360 #define		UBLK_IO_OP_FLUSH		2
361 #define		UBLK_IO_OP_DISCARD		3
362 #define		UBLK_IO_OP_WRITE_SAME		4
363 #define		UBLK_IO_OP_WRITE_ZEROES		5
364 #define		UBLK_IO_OP_ZONE_OPEN		10
365 #define		UBLK_IO_OP_ZONE_CLOSE		11
366 #define		UBLK_IO_OP_ZONE_FINISH		12
367 #define		UBLK_IO_OP_ZONE_APPEND		13
368 #define		UBLK_IO_OP_ZONE_RESET_ALL	14
369 #define		UBLK_IO_OP_ZONE_RESET		15
370 /*
371  * Construct a zone report. The report request is carried in `struct
372  * ublksrv_io_desc`. The `start_sector` field must be the first sector of a zone
373  * and shall indicate the first zone of the report. The `nr_zones` shall
374  * indicate how many zones should be reported at most. The report shall be
375  * delivered as a `struct blk_zone` array. To report fewer zones than requested,
376  * zero the last entry of the returned array.
377  *
378  * Related definitions(blk_zone, blk_zone_cond, blk_zone_type, ...) in
379  * include/uapi/linux/blkzoned.h are part of ublk UAPI.
380  */
381 #define		UBLK_IO_OP_REPORT_ZONES		18
382 
383 #define		UBLK_IO_F_FAILFAST_DEV		(1U << 8)
384 #define		UBLK_IO_F_FAILFAST_TRANSPORT	(1U << 9)
385 #define		UBLK_IO_F_FAILFAST_DRIVER	(1U << 10)
386 #define		UBLK_IO_F_META			(1U << 11)
387 #define		UBLK_IO_F_FUA			(1U << 13)
388 #define		UBLK_IO_F_NOUNMAP		(1U << 15)
389 #define		UBLK_IO_F_SWAP			(1U << 16)
390 /*
391  * For UBLK_F_AUTO_BUF_REG & UBLK_AUTO_BUF_REG_FALLBACK only.
392  *
393  * This flag is set if auto buffer register is failed & ublk server passes
394  * UBLK_AUTO_BUF_REG_FALLBACK, and ublk server need to register buffer
395  * manually for handling the delivered IO command if this flag is observed
396  *
397  * ublk server has to check this flag if UBLK_AUTO_BUF_REG_FALLBACK is
398  * passed in.
399  */
400 #define		UBLK_IO_F_NEED_REG_BUF		(1U << 17)
401 
402 /*
403  * io cmd is described by this structure, and stored in share memory, indexed
404  * by request tag.
405  *
406  * The data is stored by ublk driver, and read by ublksrv after one fetch command
407  * returns.
408  */
409 struct ublksrv_io_desc {
410 	/* op: bit 0-7, flags: bit 8-31 */
411 	__u32		op_flags;
412 
413 	union {
414 		__u32		nr_sectors;
415 		__u32		nr_zones; /* for UBLK_IO_OP_REPORT_ZONES */
416 	};
417 
418 	/* start sector for this io */
419 	__u64		start_sector;
420 
421 	/* buffer address in ublksrv daemon vm space, from ublk driver */
422 	__u64		addr;
423 };
424 
ublksrv_get_op(const struct ublksrv_io_desc * iod)425 static inline __u8 ublksrv_get_op(const struct ublksrv_io_desc *iod)
426 {
427 	return iod->op_flags & 0xff;
428 }
429 
ublksrv_get_flags(const struct ublksrv_io_desc * iod)430 static inline __u32 ublksrv_get_flags(const struct ublksrv_io_desc *iod)
431 {
432 	return iod->op_flags >> 8;
433 }
434 
435 /*
436  * If this flag is set, fallback by completing the uring_cmd and setting
437  * `UBLK_IO_F_NEED_REG_BUF` in case of auto-buf-register failure;
438  * otherwise the client ublk request is failed silently
439  *
440  * If ublk server passes this flag, it has to check if UBLK_IO_F_NEED_REG_BUF
441  * is set in `ublksrv_io_desc.op_flags`. If UBLK_IO_F_NEED_REG_BUF is set,
442  * ublk server needs to register io buffer manually for handling IO command.
443  */
444 #define UBLK_AUTO_BUF_REG_FALLBACK 	(1 << 0)
445 #define UBLK_AUTO_BUF_REG_F_MASK 	UBLK_AUTO_BUF_REG_FALLBACK
446 
447 struct ublk_auto_buf_reg {
448 	/* index for registering the delivered request buffer */
449 	__u16  index;
450 	__u8   flags;
451 	__u8   reserved0;
452 
453 	/*
454 	 * io_ring FD can be passed via the reserve field in future for
455 	 * supporting to register io buffer to external io_uring
456 	 */
457 	__u32  reserved1;
458 };
459 
460 /*
461  * For UBLK_F_AUTO_BUF_REG, auto buffer register data is carried via
462  * uring_cmd's sqe->addr:
463  *
464  * 	- bit0 ~ bit15: buffer index
465  * 	- bit16 ~ bit23: flags
466  * 	- bit24 ~ bit31: reserved0
467  * 	- bit32 ~ bit63: reserved1
468  */
ublk_sqe_addr_to_auto_buf_reg(__u64 sqe_addr)469 static inline struct ublk_auto_buf_reg ublk_sqe_addr_to_auto_buf_reg(
470 		__u64 sqe_addr)
471 {
472 	struct ublk_auto_buf_reg reg = {
473 		.index = (__u16)sqe_addr,
474 		.flags = (__u8)(sqe_addr >> 16),
475 		.reserved0 = (__u8)(sqe_addr >> 24),
476 		.reserved1 = (__u32)(sqe_addr >> 32),
477 	};
478 
479 	return reg;
480 }
481 
482 static inline __u64
ublk_auto_buf_reg_to_sqe_addr(const struct ublk_auto_buf_reg * buf)483 ublk_auto_buf_reg_to_sqe_addr(const struct ublk_auto_buf_reg *buf)
484 {
485 	__u64 addr = buf->index | (__u64)buf->flags << 16 | (__u64)buf->reserved0 << 24 |
486 		(__u64)buf->reserved1 << 32;
487 
488 	return addr;
489 }
490 
491 /* issued to ublk driver via /dev/ublkcN */
492 struct ublksrv_io_cmd {
493 	__u16	q_id;
494 
495 	/* for fetch/commit which result */
496 	__u16	tag;
497 
498 	/* io result, it is valid for COMMIT* command only */
499 	__s32	result;
500 
501 	union {
502 		/*
503 		 * userspace buffer address in ublksrv daemon process, valid for
504 		 * FETCH* command only
505 		 *
506 		 * `addr` should not be used when UBLK_F_USER_COPY is enabled,
507 		 * because userspace handles data copy by pread()/pwrite() over
508 		 * /dev/ublkcN. But in case of UBLK_F_ZONED, this union is
509 		 * re-used to pass back the allocated LBA for
510 		 * UBLK_IO_OP_ZONE_APPEND which actually depends on
511 		 * UBLK_F_USER_COPY
512 		 */
513 		__u64	addr;
514 		__u64	zone_append_lba;
515 	};
516 };
517 
518 struct ublk_param_basic {
519 #define UBLK_ATTR_READ_ONLY            (1 << 0)
520 #define UBLK_ATTR_ROTATIONAL           (1 << 1)
521 #define UBLK_ATTR_VOLATILE_CACHE       (1 << 2)
522 #define UBLK_ATTR_FUA                  (1 << 3)
523 	__u32	attrs;
524 	__u8	logical_bs_shift;
525 	__u8	physical_bs_shift;
526 	__u8	io_opt_shift;
527 	__u8	io_min_shift;
528 
529 	__u32	max_sectors;
530 	__u32	chunk_sectors;
531 
532 	__u64   dev_sectors;
533 	__u64   virt_boundary_mask;
534 };
535 
536 struct ublk_param_discard {
537 	__u32	discard_alignment;
538 
539 	__u32	discard_granularity;
540 	__u32	max_discard_sectors;
541 
542 	__u32	max_write_zeroes_sectors;
543 	__u16	max_discard_segments;
544 	__u16	reserved0;
545 };
546 
547 /*
548  * read-only, can't set via UBLK_CMD_SET_PARAMS, disk_devt is available
549  * after device is started
550  */
551 struct ublk_param_devt {
552 	__u32   char_major;
553 	__u32   char_minor;
554 	__u32   disk_major;
555 	__u32   disk_minor;
556 };
557 
558 struct ublk_param_zoned {
559 	__u32	max_open_zones;
560 	__u32	max_active_zones;
561 	__u32	max_zone_append_sectors;
562 	__u8	reserved[20];
563 };
564 
565 struct ublk_param_dma_align {
566 	__u32	alignment;
567 	__u8	pad[4];
568 };
569 
570 #define UBLK_MIN_SEGMENT_SIZE   4096
571 /*
572  * If any one of the three segment parameter is set as 0, the behavior is
573  * undefined.
574  */
575 struct ublk_param_segment {
576 	/*
577 	 * seg_boundary_mask + 1 needs to be power_of_2(), and the sum has
578 	 * to be >= UBLK_MIN_SEGMENT_SIZE(4096)
579 	 */
580 	__u64 	seg_boundary_mask;
581 
582 	/*
583 	 * max_segment_size could be override by virt_boundary_mask, so be
584 	 * careful when setting both.
585 	 *
586 	 * max_segment_size has to be >= UBLK_MIN_SEGMENT_SIZE(4096)
587 	 */
588 	__u32 	max_segment_size;
589 	__u16 	max_segments;
590 	__u8	pad[2];
591 };
592 
593 struct ublk_params {
594 	/*
595 	 * Total length of parameters, userspace has to set 'len' for both
596 	 * SET_PARAMS and GET_PARAMS command, and driver may update len
597 	 * if two sides use different version of 'ublk_params', same with
598 	 * 'types' fields.
599 	 */
600 	__u32	len;
601 #define UBLK_PARAM_TYPE_BASIC           (1 << 0)
602 #define UBLK_PARAM_TYPE_DISCARD         (1 << 1)
603 #define UBLK_PARAM_TYPE_DEVT            (1 << 2)
604 #define UBLK_PARAM_TYPE_ZONED           (1 << 3)
605 #define UBLK_PARAM_TYPE_DMA_ALIGN       (1 << 4)
606 #define UBLK_PARAM_TYPE_SEGMENT         (1 << 5)
607 	__u32	types;			/* types of parameter included */
608 
609 	struct ublk_param_basic		basic;
610 	struct ublk_param_discard	discard;
611 	struct ublk_param_devt		devt;
612 	struct ublk_param_zoned	zoned;
613 	struct ublk_param_dma_align	dma;
614 	struct ublk_param_segment	seg;
615 };
616 
617 #endif
618