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