| 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
| 2 | /* |
| 3 | * Zoned block devices handling. |
| 4 | * |
| 5 | * Copyright (C) 2015 Seagate Technology PLC |
| 6 | * |
| 7 | * Written by: Shaun Tancheff <shaun.tancheff@seagate.com> |
| 8 | * |
| 9 | * Modified by: Damien Le Moal <damien.lemoal@hgst.com> |
| 10 | * Copyright (C) 2016 Western Digital |
| 11 | * |
| 12 | * This file is licensed under the terms of the GNU General Public |
| 13 | * License version 2. This program is licensed "as is" without any |
| 14 | * warranty of any kind, whether express or implied. |
| 15 | */ |
| 16 | #ifndef _BLKZONED_H |
| 17 | #define _BLKZONED_H |
| 18 | |
| 19 | #include <linux/types.h> |
| 20 | #include <linux/ioctl.h> |
| 21 | |
| 22 | /** |
| 23 | * enum blk_zone_type - Types of zones allowed in a zoned device. |
| 24 | * |
| 25 | * @BLK_ZONE_TYPE_CONVENTIONAL: The zone has no write pointer and can be writen |
| 26 | * randomly. Zone reset has no effect on the zone. |
| 27 | * @BLK_ZONE_TYPE_SEQWRITE_REQ: The zone must be written sequentially |
| 28 | * @BLK_ZONE_TYPE_SEQWRITE_PREF: The zone can be written non-sequentially |
| 29 | * |
| 30 | * Any other value not defined is reserved and must be considered as invalid. |
| 31 | */ |
| 32 | enum blk_zone_type { |
| 33 | 	BLK_ZONE_TYPE_CONVENTIONAL	= 0x1, |
| 34 | 	BLK_ZONE_TYPE_SEQWRITE_REQ	= 0x2, |
| 35 | 	BLK_ZONE_TYPE_SEQWRITE_PREF	= 0x3, |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * enum blk_zone_cond - Condition [state] of a zone in a zoned device. |
| 40 | * |
| 41 | * @BLK_ZONE_COND_NOT_WP: The zone has no write pointer, it is conventional. |
| 42 | * @BLK_ZONE_COND_EMPTY: The zone is empty. |
| 43 | * @BLK_ZONE_COND_IMP_OPEN: The zone is open, but not explicitly opened. |
| 44 | * @BLK_ZONE_COND_EXP_OPEN: The zones was explicitly opened by an |
| 45 | * OPEN ZONE command. |
| 46 | * @BLK_ZONE_COND_CLOSED: The zone was [explicitly] closed after writing. |
| 47 | * @BLK_ZONE_COND_FULL: The zone is marked as full, possibly by a zone |
| 48 | * FINISH ZONE command. |
| 49 | * @BLK_ZONE_COND_READONLY: The zone is read-only. |
| 50 | * @BLK_ZONE_COND_OFFLINE: The zone is offline (sectors cannot be read/written). |
| 51 | * @BLK_ZONE_COND_ACTIVE: The zone is either implicitly open, explicitly open, |
| 52 | *			 or closed. |
| 53 | * |
| 54 | * The Zone Condition state machine in the ZBC/ZAC standards maps the above |
| 55 | * deinitions as: |
| 56 | * - ZC1: Empty | BLK_ZONE_COND_EMPTY |
| 57 | * - ZC2: Implicit Open | BLK_ZONE_COND_IMP_OPEN |
| 58 | * - ZC3: Explicit Open | BLK_ZONE_COND_EXP_OPEN |
| 59 | * - ZC4: Closed | BLK_ZONE_COND_CLOSED |
| 60 | * - ZC5: Full | BLK_ZONE_COND_FULL |
| 61 | * - ZC6: Read Only | BLK_ZONE_COND_READONLY |
| 62 | * - ZC7: Offline | BLK_ZONE_COND_OFFLINE |
| 63 | * |
| 64 | * Conditions 0x5 to 0xC are reserved by the current ZBC/ZAC spec and should |
| 65 | * be considered invalid. |
| 66 | * |
| 67 | * The condition BLK_ZONE_COND_ACTIVE is used only with cached zone reports. |
| 68 | * It is used to report any of the BLK_ZONE_COND_IMP_OPEN, |
| 69 | * BLK_ZONE_COND_EXP_OPEN and BLK_ZONE_COND_CLOSED conditions. Conversely, a |
| 70 | * regular zone report will never report a zone condition using |
| 71 | * BLK_ZONE_COND_ACTIVE and instead use the conditions BLK_ZONE_COND_IMP_OPEN, |
| 72 | * BLK_ZONE_COND_EXP_OPEN or BLK_ZONE_COND_CLOSED as reported by the device. |
| 73 | */ |
| 74 | enum blk_zone_cond { |
| 75 | 	BLK_ZONE_COND_NOT_WP	= 0x0, |
| 76 | 	BLK_ZONE_COND_EMPTY	= 0x1, |
| 77 | 	BLK_ZONE_COND_IMP_OPEN	= 0x2, |
| 78 | 	BLK_ZONE_COND_EXP_OPEN	= 0x3, |
| 79 | 	BLK_ZONE_COND_CLOSED	= 0x4, |
| 80 | 	BLK_ZONE_COND_READONLY	= 0xD, |
| 81 | 	BLK_ZONE_COND_FULL	= 0xE, |
| 82 | 	BLK_ZONE_COND_OFFLINE	= 0xF, |
| 83 | |
| 84 | 	BLK_ZONE_COND_ACTIVE	= 0xFF, /* added in Linux 6.19 */ |
| 85 | #define BLK_ZONE_COND_ACTIVE	BLK_ZONE_COND_ACTIVE |
| 86 | }; |
| 87 | |
| 88 | /** |
| 89 | * enum blk_zone_report_flags - Feature flags of reported zone descriptors. |
| 90 | * |
| 91 | * @BLK_ZONE_REP_CAPACITY: Output only. Indicates that zone descriptors in a |
| 92 | *			 zone report have a valid capacity field. |
| 93 | * @BLK_ZONE_REP_CACHED: Input only. Indicates that the zone report should be |
| 94 | *			 generated using cached zone information. In this case, |
| 95 | *			 the implicit open, explicit open and closed zone |
| 96 | *			 conditions are all reported with the |
| 97 | *			 BLK_ZONE_COND_ACTIVE condition. |
| 98 | */ |
| 99 | enum blk_zone_report_flags { |
| 100 | 	/* Output flags */ |
| 101 | 	BLK_ZONE_REP_CAPACITY	= (1U << 0), |
| 102 | |
| 103 | 	/* Input flags */ |
| 104 | 	BLK_ZONE_REP_CACHED	= (1U << 31), /* added in Linux 6.19 */ |
| 105 | #define BLK_ZONE_REP_CACHED	BLK_ZONE_REP_CACHED |
| 106 | }; |
| 107 | |
| 108 | /** |
| 109 | * struct blk_zone - Zone descriptor for BLKREPORTZONE ioctl. |
| 110 | * |
| 111 | * @start: Zone start in 512 B sector units |
| 112 | * @len: Zone length in 512 B sector units |
| 113 | * @wp: Zone write pointer location in 512 B sector units |
| 114 | * @type: see enum blk_zone_type for possible values |
| 115 | * @cond: see enum blk_zone_cond for possible values |
| 116 | * @non_seq: Flag indicating that the zone is using non-sequential resources |
| 117 | * (for host-aware zoned block devices only). |
| 118 | * @reset: Flag indicating that a zone reset is recommended. |
| 119 | * @resv: Padding for 8B alignment. |
| 120 | * @capacity: Zone usable capacity in 512 B sector units |
| 121 | * @reserved: Padding to 64 B to match the ZBC, ZAC and ZNS defined zone |
| 122 | * descriptor size. |
| 123 | * |
| 124 | * start, len, capacity and wp use the regular 512 B sector unit, regardless |
| 125 | * of the device logical block size. The overall structure size is 64 B to |
| 126 | * match the ZBC, ZAC and ZNS defined zone descriptor and allow support for |
| 127 | * future additional zone information. |
| 128 | */ |
| 129 | struct blk_zone { |
| 130 | 	__u64	start;		/* Zone start sector */ |
| 131 | 	__u64	len;		/* Zone length in number of sectors */ |
| 132 | 	__u64	wp;		/* Zone write pointer position */ |
| 133 | 	__u8	type;		/* Zone type */ |
| 134 | 	__u8	cond;		/* Zone condition */ |
| 135 | 	__u8	non_seq;	/* Non-sequential write resources active */ |
| 136 | 	__u8	reset;		/* Reset write pointer recommended */ |
| 137 | 	__u8	resv[4]; |
| 138 | 	__u64	capacity;	/* Zone capacity in number of sectors */ |
| 139 | 	__u8	reserved[24]; |
| 140 | }; |
| 141 | |
| 142 | /** |
| 143 | * struct blk_zone_report - BLKREPORTZONE ioctl request/reply |
| 144 | * |
| 145 | * @sector: starting sector of report |
| 146 | * @nr_zones: IN maximum / OUT actual |
| 147 | * @flags: one or more flags as defined by enum blk_zone_report_flags. |
| 148 | * @flags: one or more flags as defined by enum blk_zone_report_flags. |
| 149 | *	 With BLKREPORTZONE, this field is ignored as an input and is valid |
| 150 | *	 only as an output. Using BLKREPORTZONEV2, this field is used as both |
| 151 | *	 input and output. |
| 152 | * @zones: Space to hold @nr_zones @zones entries on reply. |
| 153 | * |
| 154 | * The array of at most @nr_zones must follow this structure in memory. |
| 155 | */ |
| 156 | struct blk_zone_report { |
| 157 | 	__u64		sector; |
| 158 | 	__u32		nr_zones; |
| 159 | 	__u32		flags; |
| 160 | 	struct blk_zone zones[]; |
| 161 | }; |
| 162 | |
| 163 | /** |
| 164 | * struct blk_zone_range - BLKRESETZONE/BLKOPENZONE/ |
| 165 | * BLKCLOSEZONE/BLKFINISHZONE ioctl |
| 166 | * requests |
| 167 | * @sector: Starting sector of the first zone to operate on. |
| 168 | * @nr_sectors: Total number of sectors of all zones to operate on. |
| 169 | */ |
| 170 | struct blk_zone_range { |
| 171 | 	__u64		sector; |
| 172 | 	__u64		nr_sectors; |
| 173 | }; |
| 174 | |
| 175 | /** |
| 176 | * Zoned block device ioctl's: |
| 177 | * |
| 178 | * @BLKREPORTZONE: Get zone information from a zoned device. Takes a zone report |
| 179 | *		 as argument. The zone report will start from the zone |
| 180 | *		 containing the sector specified in struct blk_zone_report. |
| 181 | *		 The flags field of struct blk_zone_report is used as an |
| 182 | *		 output only and ignored as an input. |
| 183 | *		 DEPRECATED, use BLKREPORTZONEV2 instead. |
| 184 | * @BLKREPORTZONEV2: Same as @BLKREPORTZONE but uses the flags field of |
| 185 | *		 struct blk_zone_report as an input, allowing to get a zone |
| 186 | *		 report using cached zone information if the flag |
| 187 | *		 BLK_ZONE_REP_CACHED is set. In such case, the zone report |
| 188 | *		 may include zones with the condition @BLK_ZONE_COND_ACTIVE |
| 189 | *		 (c.f. the description of this condition above for more |
| 190 | *		 details). |
| 191 | * @BLKRESETZONE: Reset the write pointer of the zones in the specified |
| 192 | * sector range. The sector range must be zone aligned. |
| 193 | * @BLKGETZONESZ: Get the device zone size in number of 512 B sectors. |
| 194 | * @BLKGETNRZONES: Get the total number of zones of the device. |
| 195 | * @BLKOPENZONE: Open the zones in the specified sector range. |
| 196 | * The 512 B sector range must be zone aligned. |
| 197 | * @BLKCLOSEZONE: Close the zones in the specified sector range. |
| 198 | * The 512 B sector range must be zone aligned. |
| 199 | * @BLKFINISHZONE: Mark the zones as full in the specified sector range. |
| 200 | * The 512 B sector range must be zone aligned. |
| 201 | */ |
| 202 | #define BLKREPORTZONE	_IOWR(0x12, 130, struct blk_zone_report) |
| 203 | #define BLKRESETZONE	_IOW(0x12, 131, struct blk_zone_range) |
| 204 | #define BLKGETZONESZ	_IOR(0x12, 132, __u32) |
| 205 | #define BLKGETNRZONES	_IOR(0x12, 133, __u32) |
| 206 | #define BLKOPENZONE	_IOW(0x12, 134, struct blk_zone_range) |
| 207 | #define BLKCLOSEZONE	_IOW(0x12, 135, struct blk_zone_range) |
| 208 | #define BLKFINISHZONE	_IOW(0x12, 136, struct blk_zone_range) |
| 209 | #define BLKREPORTZONEV2	_IOWR(0x12, 142, struct blk_zone_report) |
| 210 | |
| 211 | #endif /* _BLKZONED_H */ |