From patchwork Tue Apr 5 19:29:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaun Tancheff X-Patchwork-Id: 8754641 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2CAA09F39A for ; Tue, 5 Apr 2016 19:31:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3421820389 for ; Tue, 5 Apr 2016 19:31:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3767220383 for ; Tue, 5 Apr 2016 19:30:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759771AbcDETa5 (ORCPT ); Tue, 5 Apr 2016 15:30:57 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:34141 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759759AbcDETaz (ORCPT ); Tue, 5 Apr 2016 15:30:55 -0400 Received: by mail-pa0-f46.google.com with SMTP id fe3so16592495pab.1; Tue, 05 Apr 2016 12:30:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=dgXBPK9u/Ww6jFtAz08CjiG02bQvJsk8OZ0OMURecQM=; b=ccynQEHbKdfYasP5XZiT7AIPESBvcXCEdfp0Z/SZXy/t4sK4f/MR2JCxwI8TjvOsI7 yogYPfc3I25dkKiGxuR/ygpAVaVAESe5YEp2f+Z1KEk9fhkXyAVgu9MvOtIjIGH8iFom PK1+CQPzNnN8DnxaqNFM//o1T7JRqH8V8sV3D/VLJLARC5OyL2Qczgroda8dsKqwUVk/ ruRGHoh4PYlnjetgvU7LAEqIjsj7wq9GDHDAG0Wn2MYn4+zzPfZbh4Hpqc83VmVmXrlO ixSn5QCDDIcnHkK9fquj6k/vPA5BKvv48t3GurcoaIl7BDnxOPdIlYabUkqNdwkz9naO FxxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=dgXBPK9u/Ww6jFtAz08CjiG02bQvJsk8OZ0OMURecQM=; b=XT2Z0/ZjZm5m0cr3xW5LSpp99L7j78G+Rrj40ZGmsY6x7FF7HGuPSjTS/Wffl2btla G8q3tvWQo2WErx+KCAmuLCNpId0q+bDX9fAZQm9P3keGLGtk1q+195fv/gSZeRQ3jvof 0AMUycf+hrxHnrUVZU74zPM3q8RhcIv5LcmMfBR0uBFa52oqYYFcrIn/PyDMloxkVKZK hE/iHhCWFq6F/ny9ZQCgspyYkoTigXXYXxyVeZfej7lKwUzzwAJoSVbpqhYXA2MOQyxG 4DnBaXo4Oc5lcbY6htD7NlheWDmdsUpyNltN9Xmsg2Ev7ARgxYDgSNLDXo/WEyh6fp9w vq/w== X-Gm-Message-State: AD7BkJK2Y+ZDaeZGBhJ473WeQl73atMt+SY5jI0HW2NCjNiUvDZJfvd9NS9pYTXIDc+Ayw== X-Received: by 10.66.183.230 with SMTP id ep6mr65667540pac.89.1459884654009; Tue, 05 Apr 2016 12:30:54 -0700 (PDT) Received: from localhost.localdomain ([103.47.135.1]) by smtp.gmail.com with ESMTPSA id r68sm48679938pfb.51.2016.04.05.12.30.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Apr 2016 12:30:53 -0700 (PDT) From: Shaun Tancheff To: linux-ide@vger.kernel.org, linux-block@vger.kernel.org, linux-scsi@vger.kernel.org Cc: Jens Axboe , Hannes Reinecke , Mike Christie , Shaun Tancheff , Shaun Tancheff Subject: [PATCH v2 2/3] Add bio/request flags for using ZBC/ZAC commands Date: Wed, 6 Apr 2016 02:29:27 +0700 Message-Id: <1459884568-12091-3-git-send-email-shaun@tancheff.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1459884568-12091-1-git-send-email-shaun@tancheff.com> References: <1459884568-12091-1-git-send-email-shaun@tancheff.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP T10 ZBC and T13 ZAC specify operations for Zoned devices. To be able to access the zone information and open and close zones adding flags for the report zones command (REQ_REPORT_ZONES) and for Open and Close zone (REQ_OPEN_ZONE and REQ_CLOSE_ZONE) can be added for use by struct bio's bi_rw and by struct request's cmd_flags. To reduce the number of additional flags needed, the REQ_RESET_ZONE shares the same bit as REQ_REPORT_ZONES and is differentiated by direction (bi_op). Report zones is a device read that requires a buffer. Reset is a device command (WRITE) that has no associated data transfer. Originally the intent was to use REQ_DISCARD as a functional analog to zone reset, however the number of incompatible special cases that need to be visited seems more error-prone than have one of the new flags initially dual purposed. The Finish zone command is intentionally not implimented as there is no current use case for that operation. Signed-off-by: Shaun Tancheff --- MAINTAINERS | 9 ++ block/blk-lib.c | 125 ++++++++++++++++++++++ drivers/scsi/sd.c | 107 +++++++++++++++++++ drivers/scsi/sd.h | 1 + include/linux/blk_types.h | 17 ++- include/linux/blkzoned_api.h | 25 +++++ include/scsi/scsi_device.h | 1 + include/uapi/linux/Kbuild | 1 + include/uapi/linux/blkzoned_api.h | 215 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/fs.h | 1 + 10 files changed, 500 insertions(+), 2 deletions(-) create mode 100644 include/linux/blkzoned_api.h create mode 100644 include/uapi/linux/blkzoned_api.h diff --git a/MAINTAINERS b/MAINTAINERS index 1c32f8a..b68acbb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12340,6 +12340,15 @@ F: Documentation/networking/z8530drv.txt F: drivers/net/hamradio/*scc.c F: drivers/net/hamradio/z8530.h +ZBC AND ZBC BLOCK DEVICES +M: Shaun Tancheff +W: http://seagate.com +W: https://github.com/Seagate/ZDM-Device-Mapper +L: linux-block@vger.kernel.org +S: Maintained +F: include/linux/blkzoned_api.h +F: include/uapi/linux/blkzoned_api.h + ZBUD COMPRESSED PAGE ALLOCATOR M: Seth Jennings L: linux-mm@kvack.org diff --git a/block/blk-lib.c b/block/blk-lib.c index d01b5f2..8424dfe 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "blk.h" @@ -303,3 +304,127 @@ int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, return __blkdev_issue_zeroout(bdev, sector, nr_sects, gfp_mask); } EXPORT_SYMBOL(blkdev_issue_zeroout); + +/** + * blkdev_issue_zone_report - queue a report zones operation + * @bdev: target blockdev + * @bi_rw: extra bio rw flags. If unsure, use 0. + * @sector: starting sector (report will include this sector). + * @page: one or more contiguous pages. + * @pgsz: up to size of page in bytes, size of report. + * @gfp_mask: memory allocation flags (for bio_alloc) + * + * Description: + * Issue a zone report request for the sectors in question. + */ +int blkdev_issue_zone_report(struct block_device *bdev, unsigned int bi_rw, + sector_t sector, u8 opt, struct page *page, + size_t pgsz, gfp_t gfp_mask) +{ + DECLARE_COMPLETION_ONSTACK(wait); + struct bdev_zone_report *conv = page_address(page); + struct bio_batch bb; + struct bio *bio; + unsigned int nr_iovecs = 1; + int ret = 0; + + if (pgsz < (sizeof(struct bdev_zone_report) + + sizeof(struct bdev_zone_descriptor))) + return -EINVAL; + + conv->descriptor_count = 0; + atomic_set(&bb.done, 1); + bb.error = 0; + bb.wait = &wait; + + bio = bio_alloc(gfp_mask, nr_iovecs); + if (!bio) + return -ENOMEM; + + bio->bi_iter.bi_sector = sector; + bio->bi_end_io = bio_batch_end_io; + bio->bi_bdev = bdev; + bio->bi_private = &bb; + bio->bi_vcnt = 0; + bio->bi_iter.bi_size = 0; + bio->bi_op = REQ_OP_READ; + bio->bi_rw = bi_rw | REQ_REPORT_ZONES; + + bio_set_streamid(bio, opt); + bio_add_page(bio, page, pgsz, 0); + atomic_inc(&bb.done); + submit_bio(bio); + + /* Wait for bios in-flight */ + if (!atomic_dec_and_test(&bb.done)) + wait_for_completion_io(&wait); + + /* + * When our request it nak'd the underlying device maybe conventional + * so ... report a single conventional zone the size of the device. + */ + if (bb.error == -EIO && conv->descriptor_count) { + /* Adjust the conventional to the size of the partition ... */ + __be64 blksz = cpu_to_be64(bdev->bd_part->nr_sects); + + conv->maximum_lba = blksz; + conv->descriptors[0].type = ZTYP_CONVENTIONAL; + conv->descriptors[0].flags = ZCOND_CONVENTIONAL << 4; + conv->descriptors[0].length = blksz; + conv->descriptors[0].lba_start = 0; + conv->descriptors[0].lba_wptr = blksz; + return 0; + } + if (bb.error) + return bb.error; + return ret; +} +EXPORT_SYMBOL(blkdev_issue_zone_report); + +/** + * blkdev_issue_zone_action - queue a report zones operation + * @bdev: target blockdev + * @bi_rw: REQ_OPEN_ZONE, REQ_CLOSE_ZONE, or REQ_RESET_ZONE. + * @sector: starting lba of sector + * @gfp_mask: memory allocation flags (for bio_alloc) + * + * Description: + * Issue a zone report request for the sectors in question. + */ +int blkdev_issue_zone_action(struct block_device *bdev, unsigned int bi_rw, + sector_t sector, gfp_t gfp_mask) +{ + DECLARE_COMPLETION_ONSTACK(wait); + struct bio_batch bb; + struct bio *bio; + int ret = 0; + + atomic_set(&bb.done, 1); + bb.error = 0; + bb.wait = &wait; + + bio = bio_alloc(gfp_mask, 1); + if (!bio) + return -ENOMEM; + + bio->bi_iter.bi_sector = sector; + bio->bi_end_io = bio_batch_end_io; + bio->bi_bdev = bdev; + bio->bi_private = &bb; + bio->bi_vcnt = 0; + bio->bi_iter.bi_size = 0; + bio->bi_op = REQ_OP_WRITE; + bio->bi_rw = bi_rw; + + atomic_inc(&bb.done); + submit_bio(bio); + + /* Wait for bios in-flight */ + if (!atomic_dec_and_test(&bb.done)) + wait_for_completion_io(&wait); + + if (bb.error) + return bb.error; + return ret; +} +EXPORT_SYMBOL(blkdev_issue_zone_action); diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 909b0fd..559f611 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -52,6 +52,7 @@ #include #include #include +#include #include #include @@ -1137,6 +1138,97 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) return ret; } +static int sd_setup_zoned_cmnd(struct scsi_cmnd *cmd) +{ + struct request *rq = cmd->request; + struct scsi_device *sdp = cmd->device; + struct bio *bio = rq->bio; + sector_t sector = blk_rq_pos(rq); + struct gendisk *disk = rq->rq_disk; + unsigned int nr_bytes = blk_rq_bytes(rq); + int ret = BLKPREP_KILL; + u8 allbit = 0; + + if (rq->cmd_flags & REQ_REPORT_ZONES && rq->op == REQ_OP_READ) { + WARN_ON(nr_bytes == 0); + + /* + * For conventional drives generate a report that shows a + * large single convetional zone the size of the block device + */ + if (!sdp->zabc) { + void *src; + struct bdev_zone_report *conv; + + if (nr_bytes < sizeof(struct bdev_zone_report)) + goto out; + + src = kmap_atomic(bio->bi_io_vec->bv_page); + conv = src + bio->bi_io_vec->bv_offset; + conv->descriptor_count = cpu_to_be32(1); + conv->same_field = ZS_ALL_SAME; + conv->maximum_lba = cpu_to_be64(disk->part0.nr_sects); + kunmap_atomic(src); + goto out; + } + + ret = scsi_init_io(cmd); + if (ret != BLKPREP_OK) + goto out; + + cmd = rq->special; + if (sdp->changed) { + pr_err("SCSI disk has been changed or is not present."); + ret = BLKPREP_KILL; + goto out; + } + + cmd->cmd_len = 16; + memset(cmd->cmnd, 0, cmd->cmd_len); + cmd->cmnd[0] = ZBC_IN; + cmd->cmnd[1] = ZI_REPORT_ZONES; + put_unaligned_be64(sector, &cmd->cmnd[2]); + put_unaligned_be32(nr_bytes, &cmd->cmnd[10]); + cmd->cmnd[14] = bio_get_streamid(bio); + cmd->sc_data_direction = DMA_FROM_DEVICE; + cmd->sdb.length = nr_bytes; + cmd->transfersize = sdp->sector_size; + cmd->underflow = 0; + cmd->allowed = SD_MAX_RETRIES; + ret = BLKPREP_OK; + goto out; + } + + if (!sdp->zabc) + goto out; + + if (sector == ~0ul) { + allbit = 1; + sector = 0; + } + + cmd->cmd_len = 16; + memset(cmd->cmnd, 0, cmd->cmd_len); + memset(&cmd->sdb, 0, sizeof(cmd->sdb)); + + cmd->cmnd[0] = ZBC_OUT; + cmd->cmnd[1] = ZO_OPEN_ZONE; + if (rq->cmd_flags & REQ_CLOSE_ZONE) + cmd->cmnd[1] = ZO_CLOSE_ZONE; + if (rq->cmd_flags & REQ_RESET_ZONE) + cmd->cmnd[1] = ZO_RESET_WRITE_POINTER; + cmd->cmnd[14] = allbit; + put_unaligned_be64(sector, &cmd->cmnd[2]); + cmd->transfersize = 0; + cmd->underflow = 0; + cmd->allowed = SD_MAX_RETRIES; + cmd->sc_data_direction = DMA_NONE; + + ret = BLKPREP_OK; +out: + return ret; +} + static int sd_init_command(struct scsi_cmnd *cmd) { struct request *rq = cmd->request; @@ -1150,6 +1242,8 @@ static int sd_init_command(struct scsi_cmnd *cmd) return sd_setup_flush_cmnd(cmd); case REQ_OP_READ: case REQ_OP_WRITE: + if (rq->cmd_flags & REQ_ZONED_CMDS) + return sd_setup_zoned_cmnd(cmd); return sd_setup_read_write_cmnd(cmd); default: BUG(); @@ -2743,6 +2837,19 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp) queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, sdkp->disk->queue); } + if (buffer[8] & 0x10) { + /* + * A Host Aware ZBC device 'reset wp' operation will discard + * a zone of data. A zone can be very large and need not all + * be of the same size on a single drive so we will defer + * all of that to the kernel layer handling the zones geometry + * and issuing the RESET_ZONE to the device. + * + * Any subsequent reads will be zero'd. + */ + sdkp->device->zabc = 1; + } + out: kfree(buffer); } diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h index 5f2a84a..cac4018 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -56,6 +56,7 @@ enum { SD_LBP_WS16, /* Use WRITE SAME(16) with UNMAP bit */ SD_LBP_WS10, /* Use WRITE SAME(10) with UNMAP bit */ SD_LBP_ZERO, /* Use WRITE SAME(10) with zero payload */ + SD_LBP_RESET_WP, /* Use Reset WP */ SD_LBP_DISABLE, /* Discard disabled due to failed cmd */ }; diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 0747954..66a38a0 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -188,6 +188,10 @@ enum rq_flag_bits { __REQ_FUA, /* forced unit access */ __REQ_PREFLUSH, /* request for cache flush */ + __REQ_REPORT_ZONES, /* Zoned device: Report Zones */ + __REQ_OPEN_ZONE, /* Zoned device: Open Zone */ + __REQ_CLOSE_ZONE, /* Zoned device: Close Zone */ + /* bio only flags */ __REQ_RAHEAD, /* read ahead, can fail anytime */ __REQ_THROTTLED, /* This bio has already been subjected to @@ -226,16 +230,24 @@ enum rq_flag_bits { #define REQ_NOIDLE (1ULL << __REQ_NOIDLE) #define REQ_INTEGRITY (1ULL << __REQ_INTEGRITY) +#define REQ_REPORT_ZONES (1ULL << __REQ_REPORT_ZONES) +#define REQ_OPEN_ZONE (1ULL << __REQ_OPEN_ZONE) +#define REQ_CLOSE_ZONE (1ULL << __REQ_CLOSE_ZONE) +#define REQ_RESET_ZONE (REQ_REPORT_ZONES) +#define REQ_ZONED_CMDS \ + (REQ_OPEN_ZONE | REQ_CLOSE_ZONE | REQ_RESET_ZONE | REQ_REPORT_ZONES) + #define REQ_FAILFAST_MASK \ (REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER) #define REQ_COMMON_MASK \ (REQ_FAILFAST_MASK | REQ_SYNC | REQ_META | REQ_PRIO | REQ_NOIDLE | \ - REQ_PREFLUSH | REQ_FUA | REQ_SECURE | REQ_INTEGRITY) + REQ_PREFLUSH | REQ_FUA | REQ_SECURE | REQ_INTEGRITY | REQ_ZONED_CMDS) #define REQ_CLONE_MASK REQ_COMMON_MASK /* This mask is used for both bio and request merge checking */ #define REQ_NOMERGE_FLAGS \ - (REQ_NOMERGE | REQ_STARTED | REQ_SOFTBARRIER | REQ_PREFLUSH | REQ_FUA | REQ_FLUSH_SEQ) + (REQ_NOMERGE | REQ_STARTED | REQ_SOFTBARRIER | REQ_PREFLUSH | \ + REQ_FUA | REQ_FLUSH_SEQ | REQ_ZONED_CMDS) #define REQ_RAHEAD (1ULL << __REQ_RAHEAD) #define REQ_THROTTLED (1ULL << __REQ_THROTTLED) @@ -270,6 +282,7 @@ enum req_op { REQ_OP_FLUSH, /* request for cache flush */ }; + typedef unsigned int blk_qc_t; #define BLK_QC_T_NONE -1U #define BLK_QC_T_SHIFT 16 diff --git a/include/linux/blkzoned_api.h b/include/linux/blkzoned_api.h new file mode 100644 index 0000000..6061983 --- /dev/null +++ b/include/linux/blkzoned_api.h @@ -0,0 +1,25 @@ +/* + * Functions for zone based SMR devices. + * + * Copyright (C) 2015 Seagate Technology PLC + * + * Written by: + * Shaun Tancheff + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#ifndef _BLKZONED_API_H +#define _BLKZONED_API_H + +#include + +extern int blkdev_issue_zone_action(struct block_device *, unsigned int bi_rw, + sector_t, gfp_t); +extern int blkdev_issue_zone_report(struct block_device *, unsigned int bi_rw, + sector_t, u8 opt, struct page *, size_t, + gfp_t); + +#endif /* _BLKZONED_API_H */ diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index c067019..e341890 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -177,6 +177,7 @@ struct scsi_device { unsigned broken_fua:1; /* Don't set FUA bit */ unsigned lun_in_cdb:1; /* Store LUN bits in CDB[1] */ unsigned synchronous_alua:1; /* Synchronous ALUA commands */ + unsigned zabc:1; /* ZBC/ZAC zoned device */ atomic_t disk_events_disable_depth; /* disable depth for disk events */ diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild index 4599d32..d9e8e61 100644 --- a/include/uapi/linux/Kbuild +++ b/include/uapi/linux/Kbuild @@ -70,6 +70,7 @@ header-y += bfs_fs.h header-y += binfmts.h header-y += blkpg.h header-y += blktrace_api.h +header-y += blkzoned_api.h header-y += bpf_common.h header-y += bpf.h header-y += bpqether.h diff --git a/include/uapi/linux/blkzoned_api.h b/include/uapi/linux/blkzoned_api.h new file mode 100644 index 0000000..189e925 --- /dev/null +++ b/include/uapi/linux/blkzoned_api.h @@ -0,0 +1,215 @@ +/* + * Functions for zone based SMR devices. + * + * Copyright (C) 2015 Seagate Technology PLC + * + * Written by: + * Shaun Tancheff + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#ifndef _UAPI_BLKZONED_API_H +#define _UAPI_BLKZONED_API_H + +#include + +/** + * enum zone_report_option - Report Zones types to be included. + * + * @ZOPT_NON_SEQ_AND_RESET: Default (all zones). + * @ZOPT_ZC1_EMPTY: Zones which are empty. + * @ZOPT_ZC2_OPEN_IMPLICIT: Zones open but not explicitly opened + * @ZOPT_ZC3_OPEN_EXPLICIT: Zones opened explicitly + * @ZOPT_ZC4_CLOSED: Zones closed for writing. + * @ZOPT_ZC5_FULL: Zones that are full. + * @ZOPT_ZC6_READ_ONLY: Zones that are read-only + * @ZOPT_ZC7_OFFLINE: Zones that are offline + * @ZOPT_RESET: Zones that are empty + * @ZOPT_NON_SEQ: Zones that have HA media-cache writes pending + * @ZOPT_NON_WP_ZONES: Zones that do not have Write Pointers (conventional) + * + * @ZOPT_USE_ATA_PASS: Flag used in kernel to service command I/O + * + * Used by Report Zones in bdev_zone_get_report: report_option + */ +enum zone_report_option { + ZOPT_NON_SEQ_AND_RESET = 0x00, + ZOPT_ZC1_EMPTY, + ZOPT_ZC2_OPEN_IMPLICIT, + ZOPT_ZC3_OPEN_EXPLICIT, + ZOPT_ZC4_CLOSED, + ZOPT_ZC5_FULL, + ZOPT_ZC6_READ_ONLY, + ZOPT_ZC7_OFFLINE, + ZOPT_RESET = 0x10, + ZOPT_NON_SEQ = 0x11, + ZOPT_NON_WP_ZONES = 0x3f, + ZOPT_USE_ATA_PASS = 0x80, +}; + +/** + * enum bdev_zone_type - Type of zone in descriptor + * + * @ZTYP_RESERVED: Reserved + * @ZTYP_CONVENTIONAL: Conventional random write zone (No Write Pointer) + * @ZTYP_SEQ_WRITE_REQUIRED: Non-sequential writes are rejected. + * @ZTYP_SEQ_WRITE_PREFERRED: Non-sequential writes allowed but discouraged. + * + * Returned from Report Zones. See bdev_zone_descriptor* type. + */ +enum bdev_zone_type { + ZTYP_RESERVED = 0, + ZTYP_CONVENTIONAL = 1, + ZTYP_SEQ_WRITE_REQUIRED = 2, + ZTYP_SEQ_WRITE_PREFERRED = 3, +}; + + +/** + * enum bdev_zone_condition - Condition of zone in descriptor + * + * @ZCOND_CONVENTIONAL: N/A + * @ZCOND_ZC1_EMPTY: Empty + * @ZCOND_ZC2_OPEN_IMPLICIT: Opened via write to zone. + * @ZCOND_ZC3_OPEN_EXPLICIT: Opened via open zone command. + * @ZCOND_ZC4_CLOSED: Closed + * @ZCOND_ZC6_READ_ONLY: + * @ZCOND_ZC5_FULL: No remaining space in zone. + * @ZCOND_ZC7_OFFLINE: Offline + * + * Returned from Report Zones. See bdev_zone_descriptor* flags. + */ +enum bdev_zone_condition { + ZCOND_CONVENTIONAL = 0, + ZCOND_ZC1_EMPTY = 1, + ZCOND_ZC2_OPEN_IMPLICIT = 2, + ZCOND_ZC3_OPEN_EXPLICIT = 3, + ZCOND_ZC4_CLOSED = 4, + /* 0x5 to 0xC are reserved */ + ZCOND_ZC6_READ_ONLY = 0xd, + ZCOND_ZC5_FULL = 0xe, + ZCOND_ZC7_OFFLINE = 0xf, +}; + + +/** + * enum bdev_zone_same - Report Zones same code. + * + * @ZS_ALL_DIFFERENT: All zones differ in type and size. + * @ZS_ALL_SAME: All zones are the same size and type. + * @ZS_LAST_DIFFERS: All zones are the same size and type except the last zone. + * @ZS_SAME_LEN_DIFF_TYPES: All zones are the same length but types differ. + * + * Returned from Report Zones. See bdev_zone_report* same_field. + */ +enum bdev_zone_same { + ZS_ALL_DIFFERENT = 0, + ZS_ALL_SAME = 1, + ZS_LAST_DIFFERS = 2, + ZS_SAME_LEN_DIFF_TYPES = 3, +}; + + +/** + * struct bdev_zone_get_report - ioctl: Report Zones request + * + * @zone_locator_lba: starting lba for first [reported] zone + * @return_page_count: number of *bytes* allocated for result + * @report_option: see: zone_report_option enum + * + * Used to issue report zones command to connected device + */ +struct bdev_zone_get_report { + __u64 zone_locator_lba; + __u32 return_page_count; + __u8 report_option; +} __packed; + +/** + * struct bdev_zone_descriptor_le - See: bdev_zone_descriptor + */ +struct bdev_zone_descriptor_le { + __u8 type; + __u8 flags; + __u8 reserved1[6]; + __le64 length; + __le64 lba_start; + __le64 lba_wptr; + __u8 reserved[32]; +} __packed; + + +/** + * struct bdev_zone_report_le - See: bdev_zone_report + */ +struct bdev_zone_report_le { + __le32 descriptor_count; + __u8 same_field; + __u8 reserved1[3]; + __le64 maximum_lba; + __u8 reserved2[48]; + struct bdev_zone_descriptor_le descriptors[0]; +} __packed; + + +/** + * struct bdev_zone_descriptor - A Zone descriptor entry from report zones + * + * @type: see zone_type enum + * @flags: Bits 0:reset, 1:non-seq, 2-3: resv, 4-7: see zone_condition enum + * @reserved1: padding + * @length: length of zone in sectors + * @lba_start: lba where the zone starts. + * @lba_wptr: lba of the current write pointer. + * @reserved: padding + * + */ +struct bdev_zone_descriptor { + __u8 type; + __u8 flags; + __u8 reserved1[6]; + __be64 length; + __be64 lba_start; + __be64 lba_wptr; + __u8 reserved[32]; +} __packed; + + +/** + * struct bdev_zone_report - Report Zones result + * + * @descriptor_count: Number of descriptor entries that follow + * @same_field: bits 0-3: enum zone_same (MASK: 0x0F) + * @reserved1: padding + * @maximum_lba: LBA of the last logical sector on the device, inclusive + * of all logical sectors in all zones. + * @reserved2: padding + * @descriptors: array of descriptors follows. + */ +struct bdev_zone_report { + __be32 descriptor_count; + __u8 same_field; + __u8 reserved1[3]; + __be64 maximum_lba; + __u8 reserved2[48]; + struct bdev_zone_descriptor descriptors[0]; +} __packed; + + +/** + * struct bdev_zone_report_io - Report Zones ioctl argument. + * + * @in: Report Zones inputs + * @out: Report Zones output + */ +struct bdev_zone_report_io { + union { + struct bdev_zone_get_report in; + struct bdev_zone_report out; + } data; +} __packed; + +#endif /* _UAPI_BLKZONED_API_H */ diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index a079d50..4675a78 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -223,6 +223,7 @@ struct fsxattr { #define BLKROTATIONAL _IO(0x12,126) #define BLKZEROOUT _IO(0x12,127) #define BLKDAXGET _IO(0x12,129) +/* A jump here: See blkzoned_api.h, Reserving 130 to 133. */ #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1) /* bmap access */