xref: /linux/include/uapi/linux/blkzoned.h (revision a1c613ae4c322ddd58d5a8539dbfba2a0380a8c0)
1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
26a0cb1bcSHannes Reinecke /*
36a0cb1bcSHannes Reinecke  * Zoned block devices handling.
46a0cb1bcSHannes Reinecke  *
56a0cb1bcSHannes Reinecke  * Copyright (C) 2015 Seagate Technology PLC
66a0cb1bcSHannes Reinecke  *
76a0cb1bcSHannes Reinecke  * Written by: Shaun Tancheff <shaun.tancheff@seagate.com>
86a0cb1bcSHannes Reinecke  *
96a0cb1bcSHannes Reinecke  * Modified by: Damien Le Moal <damien.lemoal@hgst.com>
106a0cb1bcSHannes Reinecke  * Copyright (C) 2016 Western Digital
116a0cb1bcSHannes Reinecke  *
126a0cb1bcSHannes Reinecke  * This file is licensed under  the terms of the GNU General Public
136a0cb1bcSHannes Reinecke  * License version 2. This program is licensed "as is" without any
146a0cb1bcSHannes Reinecke  * warranty of any kind, whether express or implied.
156a0cb1bcSHannes Reinecke  */
166a0cb1bcSHannes Reinecke #ifndef _UAPI_BLKZONED_H
176a0cb1bcSHannes Reinecke #define _UAPI_BLKZONED_H
186a0cb1bcSHannes Reinecke 
196a0cb1bcSHannes Reinecke #include <linux/types.h>
203ed05a98SShaun Tancheff #include <linux/ioctl.h>
216a0cb1bcSHannes Reinecke 
226a0cb1bcSHannes Reinecke /**
236a0cb1bcSHannes Reinecke  * enum blk_zone_type - Types of zones allowed in a zoned device.
246a0cb1bcSHannes Reinecke  *
256a0cb1bcSHannes Reinecke  * @BLK_ZONE_TYPE_CONVENTIONAL: The zone has no write pointer and can be writen
266a0cb1bcSHannes Reinecke  *                              randomly. Zone reset has no effect on the zone.
276a0cb1bcSHannes Reinecke  * @BLK_ZONE_TYPE_SEQWRITE_REQ: The zone must be written sequentially
286a0cb1bcSHannes Reinecke  * @BLK_ZONE_TYPE_SEQWRITE_PREF: The zone can be written non-sequentially
296a0cb1bcSHannes Reinecke  *
306a0cb1bcSHannes Reinecke  * Any other value not defined is reserved and must be considered as invalid.
316a0cb1bcSHannes Reinecke  */
326a0cb1bcSHannes Reinecke enum blk_zone_type {
336a0cb1bcSHannes Reinecke 	BLK_ZONE_TYPE_CONVENTIONAL	= 0x1,
346a0cb1bcSHannes Reinecke 	BLK_ZONE_TYPE_SEQWRITE_REQ	= 0x2,
356a0cb1bcSHannes Reinecke 	BLK_ZONE_TYPE_SEQWRITE_PREF	= 0x3,
366a0cb1bcSHannes Reinecke };
376a0cb1bcSHannes Reinecke 
386a0cb1bcSHannes Reinecke /**
396a0cb1bcSHannes Reinecke  * enum blk_zone_cond - Condition [state] of a zone in a zoned device.
406a0cb1bcSHannes Reinecke  *
416a0cb1bcSHannes Reinecke  * @BLK_ZONE_COND_NOT_WP: The zone has no write pointer, it is conventional.
426a0cb1bcSHannes Reinecke  * @BLK_ZONE_COND_EMPTY: The zone is empty.
436a0cb1bcSHannes Reinecke  * @BLK_ZONE_COND_IMP_OPEN: The zone is open, but not explicitly opened.
446a0cb1bcSHannes Reinecke  * @BLK_ZONE_COND_EXP_OPEN: The zones was explicitly opened by an
456a0cb1bcSHannes Reinecke  *                          OPEN ZONE command.
466a0cb1bcSHannes Reinecke  * @BLK_ZONE_COND_CLOSED: The zone was [explicitly] closed after writing.
476a0cb1bcSHannes Reinecke  * @BLK_ZONE_COND_FULL: The zone is marked as full, possibly by a zone
486a0cb1bcSHannes Reinecke  *                      FINISH ZONE command.
496a0cb1bcSHannes Reinecke  * @BLK_ZONE_COND_READONLY: The zone is read-only.
506a0cb1bcSHannes Reinecke  * @BLK_ZONE_COND_OFFLINE: The zone is offline (sectors cannot be read/written).
516a0cb1bcSHannes Reinecke  *
526a0cb1bcSHannes Reinecke  * The Zone Condition state machine in the ZBC/ZAC standards maps the above
536a0cb1bcSHannes Reinecke  * deinitions as:
54*e0933b52SBart Van Assche  *   - ZC1: Empty         | BLK_ZONE_COND_EMPTY
556a0cb1bcSHannes Reinecke  *   - ZC2: Implicit Open | BLK_ZONE_COND_IMP_OPEN
566a0cb1bcSHannes Reinecke  *   - ZC3: Explicit Open | BLK_ZONE_COND_EXP_OPEN
57*e0933b52SBart Van Assche  *   - ZC4: Closed        | BLK_ZONE_COND_CLOSED
58*e0933b52SBart Van Assche  *   - ZC5: Full          | BLK_ZONE_COND_FULL
59*e0933b52SBart Van Assche  *   - ZC6: Read Only     | BLK_ZONE_COND_READONLY
60*e0933b52SBart Van Assche  *   - ZC7: Offline       | BLK_ZONE_COND_OFFLINE
616a0cb1bcSHannes Reinecke  *
626a0cb1bcSHannes Reinecke  * Conditions 0x5 to 0xC are reserved by the current ZBC/ZAC spec and should
636a0cb1bcSHannes Reinecke  * be considered invalid.
646a0cb1bcSHannes Reinecke  */
656a0cb1bcSHannes Reinecke enum blk_zone_cond {
666a0cb1bcSHannes Reinecke 	BLK_ZONE_COND_NOT_WP	= 0x0,
676a0cb1bcSHannes Reinecke 	BLK_ZONE_COND_EMPTY	= 0x1,
686a0cb1bcSHannes Reinecke 	BLK_ZONE_COND_IMP_OPEN	= 0x2,
696a0cb1bcSHannes Reinecke 	BLK_ZONE_COND_EXP_OPEN	= 0x3,
706a0cb1bcSHannes Reinecke 	BLK_ZONE_COND_CLOSED	= 0x4,
716a0cb1bcSHannes Reinecke 	BLK_ZONE_COND_READONLY	= 0xD,
726a0cb1bcSHannes Reinecke 	BLK_ZONE_COND_FULL	= 0xE,
736a0cb1bcSHannes Reinecke 	BLK_ZONE_COND_OFFLINE	= 0xF,
746a0cb1bcSHannes Reinecke };
756a0cb1bcSHannes Reinecke 
766a0cb1bcSHannes Reinecke /**
7782394db7SMatias Bjørling  * enum blk_zone_report_flags - Feature flags of reported zone descriptors.
7882394db7SMatias Bjørling  *
7982394db7SMatias Bjørling  * @BLK_ZONE_REP_CAPACITY: Zone descriptor has capacity field.
8082394db7SMatias Bjørling  */
8182394db7SMatias Bjørling enum blk_zone_report_flags {
8282394db7SMatias Bjørling 	BLK_ZONE_REP_CAPACITY	= (1 << 0),
8382394db7SMatias Bjørling };
8482394db7SMatias Bjørling 
8582394db7SMatias Bjørling /**
866a0cb1bcSHannes Reinecke  * struct blk_zone - Zone descriptor for BLKREPORTZONE ioctl.
876a0cb1bcSHannes Reinecke  *
886a0cb1bcSHannes Reinecke  * @start: Zone start in 512 B sector units
896a0cb1bcSHannes Reinecke  * @len: Zone length in 512 B sector units
906a0cb1bcSHannes Reinecke  * @wp: Zone write pointer location in 512 B sector units
916a0cb1bcSHannes Reinecke  * @type: see enum blk_zone_type for possible values
926a0cb1bcSHannes Reinecke  * @cond: see enum blk_zone_cond for possible values
936a0cb1bcSHannes Reinecke  * @non_seq: Flag indicating that the zone is using non-sequential resources
946a0cb1bcSHannes Reinecke  *           (for host-aware zoned block devices only).
956a0cb1bcSHannes Reinecke  * @reset: Flag indicating that a zone reset is recommended.
968858e8d9SDamien Le Moal  * @resv: Padding for 8B alignment.
978858e8d9SDamien Le Moal  * @capacity: Zone usable capacity in 512 B sector units
988858e8d9SDamien Le Moal  * @reserved: Padding to 64 B to match the ZBC, ZAC and ZNS defined zone
998858e8d9SDamien Le Moal  *            descriptor size.
1006a0cb1bcSHannes Reinecke  *
1018858e8d9SDamien Le Moal  * start, len, capacity and wp use the regular 512 B sector unit, regardless
1028858e8d9SDamien Le Moal  * of the device logical block size. The overall structure size is 64 B to
1038858e8d9SDamien Le Moal  * match the ZBC, ZAC and ZNS defined zone descriptor and allow support for
1048858e8d9SDamien Le Moal  * future additional zone information.
1056a0cb1bcSHannes Reinecke  */
1066a0cb1bcSHannes Reinecke struct blk_zone {
1076a0cb1bcSHannes Reinecke 	__u64	start;		/* Zone start sector */
1086a0cb1bcSHannes Reinecke 	__u64	len;		/* Zone length in number of sectors */
1096a0cb1bcSHannes Reinecke 	__u64	wp;		/* Zone write pointer position */
1106a0cb1bcSHannes Reinecke 	__u8	type;		/* Zone type */
1116a0cb1bcSHannes Reinecke 	__u8	cond;		/* Zone condition */
1126a0cb1bcSHannes Reinecke 	__u8	non_seq;	/* Non-sequential write resources active */
1136a0cb1bcSHannes Reinecke 	__u8	reset;		/* Reset write pointer recommended */
11482394db7SMatias Bjørling 	__u8	resv[4];
11582394db7SMatias Bjørling 	__u64	capacity;	/* Zone capacity in number of sectors */
11682394db7SMatias Bjørling 	__u8	reserved[24];
1176a0cb1bcSHannes Reinecke };
1186a0cb1bcSHannes Reinecke 
1193ed05a98SShaun Tancheff /**
1203ed05a98SShaun Tancheff  * struct blk_zone_report - BLKREPORTZONE ioctl request/reply
1213ed05a98SShaun Tancheff  *
1223ed05a98SShaun Tancheff  * @sector: starting sector of report
1233ed05a98SShaun Tancheff  * @nr_zones: IN maximum / OUT actual
1248858e8d9SDamien Le Moal  * @flags: one or more flags as defined by enum blk_zone_report_flags.
1253ed05a98SShaun Tancheff  * @zones: Space to hold @nr_zones @zones entries on reply.
1263ed05a98SShaun Tancheff  *
1273ed05a98SShaun Tancheff  * The array of at most @nr_zones must follow this structure in memory.
1283ed05a98SShaun Tancheff  */
1293ed05a98SShaun Tancheff struct blk_zone_report {
1303ed05a98SShaun Tancheff 	__u64		sector;
1313ed05a98SShaun Tancheff 	__u32		nr_zones;
13282394db7SMatias Bjørling 	__u32		flags;
13394dfc73eSGustavo A. R. Silva 	struct blk_zone zones[];
134b3e7e7d2SBart Van Assche };
1353ed05a98SShaun Tancheff 
1363ed05a98SShaun Tancheff /**
137e876df1fSAjay Joshi  * struct blk_zone_range - BLKRESETZONE/BLKOPENZONE/
138e876df1fSAjay Joshi  *                         BLKCLOSEZONE/BLKFINISHZONE ioctl
139e876df1fSAjay Joshi  *                         requests
140e876df1fSAjay Joshi  * @sector: Starting sector of the first zone to operate on.
141e876df1fSAjay Joshi  * @nr_sectors: Total number of sectors of all zones to operate on.
1423ed05a98SShaun Tancheff  */
1433ed05a98SShaun Tancheff struct blk_zone_range {
1443ed05a98SShaun Tancheff 	__u64		sector;
1453ed05a98SShaun Tancheff 	__u64		nr_sectors;
1463ed05a98SShaun Tancheff };
1473ed05a98SShaun Tancheff 
1483ed05a98SShaun Tancheff /**
1493ed05a98SShaun Tancheff  * Zoned block device ioctl's:
1503ed05a98SShaun Tancheff  *
1513ed05a98SShaun Tancheff  * @BLKREPORTZONE: Get zone information. Takes a zone report as argument.
1523ed05a98SShaun Tancheff  *                 The zone report will start from the zone containing the
1533ed05a98SShaun Tancheff  *                 sector specified in the report request structure.
1543ed05a98SShaun Tancheff  * @BLKRESETZONE: Reset the write pointer of the zones in the specified
1553ed05a98SShaun Tancheff  *                sector range. The sector range must be zone aligned.
15672cd8757SDamien Le Moal  * @BLKGETZONESZ: Get the device zone size in number of 512 B sectors.
157745815f9SDamien Le Moal  * @BLKGETNRZONES: Get the total number of zones of the device.
158e876df1fSAjay Joshi  * @BLKOPENZONE: Open the zones in the specified sector range.
159e876df1fSAjay Joshi  *               The 512 B sector range must be zone aligned.
160e876df1fSAjay Joshi  * @BLKCLOSEZONE: Close the zones in the specified sector range.
161e876df1fSAjay Joshi  *                The 512 B sector range must be zone aligned.
162e876df1fSAjay Joshi  * @BLKFINISHZONE: Mark the zones as full in the specified sector range.
163e876df1fSAjay Joshi  *                 The 512 B sector range must be zone aligned.
1643ed05a98SShaun Tancheff  */
1653ed05a98SShaun Tancheff #define BLKREPORTZONE	_IOWR(0x12, 130, struct blk_zone_report)
1663ed05a98SShaun Tancheff #define BLKRESETZONE	_IOW(0x12, 131, struct blk_zone_range)
16798256376SDmitry V. Levin #define BLKGETZONESZ	_IOR(0x12, 132, __u32)
16898256376SDmitry V. Levin #define BLKGETNRZONES	_IOR(0x12, 133, __u32)
169e876df1fSAjay Joshi #define BLKOPENZONE	_IOW(0x12, 134, struct blk_zone_range)
170e876df1fSAjay Joshi #define BLKCLOSEZONE	_IOW(0x12, 135, struct blk_zone_range)
171e876df1fSAjay Joshi #define BLKFINISHZONE	_IOW(0x12, 136, struct blk_zone_range)
1723ed05a98SShaun Tancheff 
1736a0cb1bcSHannes Reinecke #endif /* _UAPI_BLKZONED_H */
174