*** src/sbin/camcontrol/Makefile.orig --- src/sbin/camcontrol/Makefile *************** *** 3,9 **** PROG= camcontrol SRCS= camcontrol.c util.c .if !defined(RELEASE_CRUNCH) ! SRCS+= attrib.c fwdownload.c modeedit.c persist.c progress.c .else CFLAGS+= -DMINIMALISTIC .endif --- 3,9 ---- PROG= camcontrol SRCS= camcontrol.c util.c .if !defined(RELEASE_CRUNCH) ! SRCS+= attrib.c fwdownload.c modeedit.c persist.c progress.c zone.c .else CFLAGS+= -DMINIMALISTIC .endif *** src/sbin/camcontrol/camcontrol.8.orig --- src/sbin/camcontrol/camcontrol.8 *************** *** 27,33 **** .\" .\" $FreeBSD$ .\" ! .Dd August 6, 2015 .Dt CAMCONTROL 8 .Os .Sh NAME --- 27,33 ---- .\" .\" $FreeBSD$ .\" ! .Dd October 16, 2015 .Dt CAMCONTROL 8 .Os .Sh NAME *************** *** 320,325 **** --- 320,332 ---- .Op Fl N .Op Fl T .Nm + .Ic zone + .Aq Fl c Ar cmd + .Op Fl a + .Op Fl l Ar lba + .Op Fl o Ar rep_opts + .Op Fl P Ar print_opts + .Nm .Ic help .Sh DESCRIPTION The *************** *** 2038,2048 **** .Dq portal , and .Dq drive . - .El .It Fl V Ar vol_num Specify the number of the logical volume to operate on. If the media has multiple logical volumes, this will allow displaying or writing attributes on the given logical volume. .It Ic opcodes Issue the REPORT SUPPORTED OPCODES service action of the .Tn SCSI --- 2045,2055 ---- .Dq portal , and .Dq drive . .It Fl V Ar vol_num Specify the number of the logical volume to operate on. If the media has multiple logical volumes, this will allow displaying or writing attributes on the given logical volume. + .El .It Ic opcodes Issue the REPORT SUPPORTED OPCODES service action of the .Tn SCSI *************** *** 2089,2094 **** --- 2096,2254 ---- The timeout values are in seconds. The timeout descriptor also includes a command-specific .El + .It Ic zone + Manage + .Tn SCSI + and + .Tn ATA + Zoned Block devices. + This allows managing devices that conform to the + .Tn SCSI + Zoned Block Commands (ZBC) and + .Tn ATA + Zoned ATA Command Set (ZAC) + specifications. + Devices using these command sets are usually hard drives using Shingled + Magnetic Recording (SMR). + There are three types of SMR drives: + .Bl -tag -width 13n + .It Drive Managed + Drive Managed drives look and act just like a standard random access block + device, but underneath, the drive reads and writes the bulk of its capacity + using SMR zones. + Sequential writes will yield better performance, but writing sequentially + is not required. + .It Host Aware + Host Aware drives expose the underlying zone layout via + .Tn SCSI + or + .Tn ATA + commands and allow the host to manage the zone conditions. + The host is not required to manage the zones on the drive, though. + Sequential writes will yield better performance in Sequential Write + Preferred zones, but the host can write randomly in those zones. + .It Host Managed + Host Managed drives expose the underlying zone layout via + .Tn SCSI + or + .Tn ATA + commands. + The host is required to access the zones according to the rules described + by the zone layout. + Any commands that violate the rules will be returned with an error. + .El + .Pp + SMR drives are divided into zones (typically in the range of 256MB each) + that fall into three general categories: + .Bl -tag -width 20n + .It Conventional + These are also known as Non Write Pointer zones. + These zones can be randomly written without an unexpected performance penalty. + .It Sequential Preferred + These zones should be written sequentially starting at the write pointer + for the zone. + They may be written randomly. + Writes that do not conform to the zone layout may be significantly slower + than expected. + .It Sequential Required + These zones must be written sequentially. + If they are not written sequentially, starting at the write pointer, the + command will fail. + .El + .Pp + .Bl -tag -width 12n + .It Fl c Ar cmd + Specify the zone subcommand: + .Bl -tag -width 6n + .It rz + Issue the Report Zones command. + All zones are returned by default. + Specify report options with + .Fl o + and printing options with + .Fl P . + Specify the starting LBA with + .Fl l . + Note that + .Dq reportzones + is also accepted as a command argument. + .It open + Explicitly open the zone specified by the starting LBA. + .It close + Close the zone specified by starting LBA. + .It finish + Finish the zone specified by the starting LBA. + .It rwp + Reset the write pointer for the zone specified by the starting LBA. + .El + .It Fl a + For the Open, Close, Finish and Reset Write Pointer operations, apply the + operation to all zones on the drive. + .It Fl l Ar lba + Specify the starting LBA. + For the Report Zones command, this tells the drive to report starting with + the zone that starts at the given LBA. + For the other commands, this allows the user to identify the zone requested + by its starting LBA. + The LBA may be specified in decimal, hexadecimal or octal notation. + .It Fl o Ar rep_opt + For the Report Zones command, specify a subset of zones to report. + .Bl -tag -width 8n + .It all + Report all zones. + This is the default. + .It emtpy + Report only empty zones. + .It imp_open + Report zones that are implicitly open. + This means that the host has sent a write to the zone without explicitly + opening the zone. + .It exp_open + Report zones that are explicitly open. + .It closed + Report zones that have been closed by the host. + .It full + Report zones that are full. + .It ro + Report zones that are in the read only state. + Note that + .Dq readonly + is also accepted as an argument. + .It offline + Report zones that are in the offline state. + .It reset + Report zones that the device recommends should have their write pointers reset. + .It nonseq + Report zones that have the Non Sequential Resources Active flag set. + These are zones that are Sequential Write Preferred, but have been written + non-sequentially. + .It nonwp + Report Non Write Pointer zones, also known as Conventional zones. + .El + .It Fl P Ar print_opt + Specify a printing option for Report Zones: + .Bl -tag -width 7n + .It normal + Normal Report Zones output. + This is the default. + The summary and column headings are printed, fields are separated by spaces + and the fields themselves may contain spaces. + .It summary + Just print the summary: the number of zones, the maximum LBA (LBA of the + last logical block on the drive), and the value of the + .Dq same + field. + The + .Dq same + field describes whether the zones on the drive are all identical, all + different, or whether they are the same except for the last zone, etc. + .It script + Print the zones in a script friendly format. + The summary and column headings are omitted, the fields are separated by + commas, and the fields do not contain spaces. + The fields contain underscores where spaces would normally be used. + .El + .El .It Ic help Print out verbose usage information. .El *************** *** 2324,2329 **** --- 2484,2522 ---- in tape drive sa0, and will display any .Tn SCSI errors that result. + .Pp + .Bd -literal -offset indent + camcontrol zone da0 -v -c rz -P summary + .Ed + .Pp + This will request the SMR zone list from disk da0, and print out a + summary of the zone parameters, and display any + .Tn SCSI + or + .Tn ATA + errors that result. + .Pp + .Bd -literal -offset indent + camcontrol zone da0 -v -c rz -o reset + .Ed + .Pp + This will request the list of SMR zones that should have their write + pointer reset from the disk da0, and display any + .Tn SCSI + or + .Tn ATA + errors that result. + .Pp + .Bd -literal -offset indent + camcontrol zone da0 -v -c rwp -l 0x2c80000 + .Ed + .Pp + This will issue the Reset Write Pointer command to disk da0 for the zone + that starts at LBA 0x2c80000 and display any + .Tn SCSI + or + .Tn ATA + errors that result. .Sh SEE ALSO .Xr cam 3 , .Xr cam_cdbparse 3 , *** src/sbin/camcontrol/camcontrol.c.orig --- src/sbin/camcontrol/camcontrol.c *************** *** 100,106 **** CAM_CMD_APM = 0x00000021, CAM_CMD_AAM = 0x00000022, CAM_CMD_ATTRIB = 0x00000023, ! CAM_CMD_OPCODES = 0x00000024 } cam_cmdmask; typedef enum { --- 100,107 ---- CAM_CMD_APM = 0x00000021, CAM_CMD_AAM = 0x00000022, CAM_CMD_ATTRIB = 0x00000023, ! CAM_CMD_OPCODES = 0x00000024, ! CAM_CMD_ZONE = 0x00000025 } cam_cmdmask; typedef enum { *************** *** 228,233 **** --- 229,235 ---- {"persist", CAM_CMD_PERSIST, CAM_ARG_NONE, "ai:I:k:K:o:ps:ST:U"}, {"attrib", CAM_CMD_ATTRIB, CAM_ARG_NONE, "a:ce:F:p:r:s:T:w:V:"}, {"opcodes", CAM_CMD_OPCODES, CAM_ARG_NONE, "No:s:T"}, + {"zone", CAM_CMD_ZONE, CAM_ARG_NONE, "ac:l:o:P:"}, #endif /* MINIMALISTIC */ {"help", CAM_CMD_USAGE, CAM_ARG_NONE, NULL}, {"-?", CAM_CMD_USAGE, CAM_ARG_NONE, NULL}, *************** *** 5075,5081 **** build_ata_cmd(union ccb *ccb, uint32_t retry_count, uint32_t flags, uint8_t tag_action, uint8_t protocol, uint8_t ata_flags, uint16_t features, uint16_t sector_count, uint64_t lba, uint8_t command, uint8_t *data_ptr, ! uint16_t dxfer_len, uint8_t sense_len, uint32_t timeout, int is48bit, camcontrol_devtype devtype) { if (devtype == CC_DT_ATA) { --- 5077,5083 ---- build_ata_cmd(union ccb *ccb, uint32_t retry_count, uint32_t flags, uint8_t tag_action, uint8_t protocol, uint8_t ata_flags, uint16_t features, uint16_t sector_count, uint64_t lba, uint8_t command, uint8_t *data_ptr, ! uint32_t dxfer_len, uint8_t sense_len, uint32_t timeout, int is48bit, camcontrol_devtype devtype) { if (devtype == CC_DT_ATA) { *************** *** 8737,8742 **** --- 8739,8746 ---- " [-p part][-s start][-T type][-V vol]\n" " camcontrol opcodes [dev_id][generic args][-o opcode][-s SA]\n" " [-N][-T]\n" + " camcontrol zone [dev_id][generic args]<-c cmd> [-a] [-l LBA]\n" + " [-o rep_opts] [-P print_opts]\n" #endif /* MINIMALISTIC */ " camcontrol help\n"); if (!printlong) *************** *** 8778,8783 **** --- 8782,8788 ---- "persist send the SCSI PERSISTENT RESERVE IN or OUT commands\n" "attrib send the SCSI READ or WRITE ATTRIBUTE commands\n" "opcodes send the SCSI REPORT SUPPORTED OPCODES command\n" + "zone manage Zoned Block (Shingled) devices\n" "help this message\n" "Device Identifiers:\n" "bus:target specify the bus and target, lun defaults to 0\n" *************** *** 8948,8953 **** --- 8953,8965 ---- "-s service_action specify the service action for the opcode\n" "-N do not return SCSI error for unsupported SA\n" "-T request nominal and recommended timeout values\n" + "zone arguments:\n" + "-c cmd required: rz, open, close, finish, or rwp\n" + "-a apply the action to all zones\n" + "-l LBA specify the zone starting LBA\n" + "-o rep_opts report zones options: all, empty, imp_open, exp_open,\n" + " closed, full, ro, offline, reset, nonseq, nonwp\n" + "-P print_opt report zones printing: normal, summary, script\n" ); #endif /* MINIMALISTIC */ } *************** *** 9300,9305 **** --- 9312,9321 ---- error = scsiopcodes(cam_dev, argc, argv, combinedopt, retry_count, timeout, arglist & CAM_ARG_VERBOSE); break; + case CAM_CMD_ZONE: + error = zone(cam_dev, argc, argv, combinedopt, + retry_count, timeout, arglist & CAM_ARG_VERBOSE); + break; #endif /* MINIMALISTIC */ case CAM_CMD_USAGE: usage(1); *** src/sbin/camcontrol/camcontrol.h.orig --- src/sbin/camcontrol/camcontrol.h *************** *** 66,78 **** void build_ata_cmd(union ccb *ccb, uint32_t retry_count, uint32_t flags, uint8_t tag_action, uint8_t protocol, uint8_t ata_flags, uint16_t features, uint16_t sector_count, uint64_t lba, ! uint8_t command, uint8_t *data_ptr, uint16_t dxfer_len, uint8_t sense_len, uint32_t timeout, int is48bit, camcontrol_devtype devtype); int camxferrate(struct cam_device *device); int fwdownload(struct cam_device *device, int argc, char **argv, char *combinedopt, int printerrors, int retry_count, int timeout); void mode_sense(struct cam_device *device, int mode_page, int page_control, int dbd, int retry_count, int timeout, u_int8_t *data, int datalen); --- 66,80 ---- void build_ata_cmd(union ccb *ccb, uint32_t retry_count, uint32_t flags, uint8_t tag_action, uint8_t protocol, uint8_t ata_flags, uint16_t features, uint16_t sector_count, uint64_t lba, ! uint8_t command, uint8_t *data_ptr, uint32_t dxfer_len, uint8_t sense_len, uint32_t timeout, int is48bit, camcontrol_devtype devtype); int camxferrate(struct cam_device *device); int fwdownload(struct cam_device *device, int argc, char **argv, char *combinedopt, int printerrors, int retry_count, int timeout); + int zone(struct cam_device *device, int argc, char **argv, char *combinedopt, + int retry_count, int timeout, int verbosemode); void mode_sense(struct cam_device *device, int mode_page, int page_control, int dbd, int retry_count, int timeout, u_int8_t *data, int datalen); *** /dev/null Mon Jan 18 15:15:01 2016 --- src/sbin/camcontrol/zone.c Mon Jan 18 15:15:17 2016 *************** *** 0 **** --- 1,616 ---- + /*- + * Copyright (c) 2015 Spectra Logic Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * Authors: Ken Merry (Spectra Logic Corporation) + */ + /* + * SCSI and ATA Shingled Media Recording (SMR) support for camcontrol(8). + * This is an implementation of the SCSI ZBC and ATA ZAC specs. + */ + + #include + __FBSDID("$FreeBSD$"); + + #include + #include + #include + #include + #include + #include + #include + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include "camcontrol.h" + + static struct scsi_nv zone_cmd_map[] = { + { "rz", ZBC_IN_SA_REPORT_ZONES }, + { "reportzones", ZBC_IN_SA_REPORT_ZONES }, + { "close", ZBC_OUT_SA_CLOSE }, + { "finish", ZBC_OUT_SA_FINISH }, + { "open", ZBC_OUT_SA_OPEN }, + { "rwp", ZBC_OUT_SA_RWP } + }; + + static struct scsi_nv zone_rep_opts[] = { + { "all", ZBC_IN_REP_ALL_ZONES }, + { "empty", ZBC_IN_REP_EMPTY }, + { "imp_open", ZBC_IN_REP_IMP_OPEN }, + { "exp_open", ZBC_IN_REP_EXP_OPEN }, + { "closed", ZBC_IN_REP_CLOSED }, + { "full", ZBC_IN_REP_FULL }, + { "readonly", ZBC_IN_REP_READONLY }, + { "ro", ZBC_IN_REP_READONLY }, + { "offline", ZBC_IN_REP_OFFLINE }, + { "rwp", ZBC_IN_REP_RESET }, + { "reset", ZBC_IN_REP_RESET }, + { "nonseq", ZBC_IN_REP_NON_SEQ }, + { "nonwp", ZBC_IN_REP_NON_WP } + }; + + typedef enum { + ZONE_OF_NORMAL = 0x00, + ZONE_OF_SUMMARY = 0x01, + ZONE_OF_SCRIPT = 0x02 + } zone_output_flags; + + static struct scsi_nv zone_print_opts[] = { + { "normal", ZONE_OF_NORMAL }, + { "summary", ZONE_OF_SUMMARY }, + { "script", ZONE_OF_SCRIPT } + }; + + #define ZAC_ATA_SECTOR_COUNT(bcount) (((bcount) / 512) & 0xffff) + + typedef enum { + ZONE_PRINT_OK, + ZONE_PRINT_MORE_DATA, + ZONE_PRINT_ERROR + } zone_print_status; + + typedef enum { + ZONE_FW_START, + ZONE_FW_LEN, + ZONE_FW_WP, + ZONE_FW_TYPE, + ZONE_FW_COND, + ZONE_FW_SEQ, + ZONE_FW_RESET, + ZONE_NUM_FIELDS + } zone_field_widths; + + zone_print_status zone_rz_print(uint8_t *data_ptr, uint32_t valid_len, + int ata_format, zone_output_flags out_flags, + int first_pass, uint64_t *next_start_lba); + + + zone_print_status + zone_rz_print(uint8_t *data_ptr, uint32_t valid_len, int ata_format, + zone_output_flags out_flags, int first_pass, + uint64_t *next_start_lba) + { + struct scsi_report_zones_hdr *hdr = NULL; + struct scsi_report_zones_desc *desc = NULL; + uint32_t hdr_len, len; + uint64_t max_lba, next_lba = 0; + int more_data = 0; + zone_print_status status = ZONE_PRINT_OK; + char tmpstr[80]; + int field_widths[ZONE_NUM_FIELDS]; + char word_sep; + + if (valid_len < sizeof(*hdr)) { + status = ZONE_PRINT_ERROR; + goto bailout; + } + + hdr = (struct scsi_report_zones_hdr *)data_ptr; + + field_widths[ZONE_FW_START] = 11; + field_widths[ZONE_FW_LEN] = 6; + field_widths[ZONE_FW_WP] = 11; + field_widths[ZONE_FW_TYPE] = 13; + field_widths[ZONE_FW_COND] = 13; + field_widths[ZONE_FW_SEQ] = 14; + field_widths[ZONE_FW_RESET] = 16; + + if (ata_format == 0) { + hdr_len = scsi_4btoul(hdr->length); + max_lba = scsi_8btou64(hdr->maximum_lba); + } else { + hdr_len = le32dec(hdr->length); + max_lba = le64dec(hdr->maximum_lba); + } + + if (hdr_len > (valid_len + sizeof(*hdr))) { + more_data = 1; + status = ZONE_PRINT_MORE_DATA; + } + + len = MIN(valid_len - sizeof(*hdr), hdr_len); + + if (out_flags == ZONE_OF_SCRIPT) + word_sep = '_'; + else + word_sep = ' '; + + if ((out_flags != ZONE_OF_SCRIPT) + && (first_pass != 0)) { + printf("%zu zones, Maximum LBA %#jx (%ju)\n", + hdr_len / sizeof(*desc), (uintmax_t)max_lba, + (uintmax_t)max_lba); + + switch (hdr->byte4 & SRZ_SAME_MASK) { + case SRZ_SAME_ALL_DIFFERENT: + printf("Zone lengths and types may vary\n"); + break; + case SRZ_SAME_ALL_SAME: + printf("Zone lengths and types are all the same\n"); + break; + case SRZ_SAME_LAST_DIFFERENT: + printf("Zone types are the same, last zone length " + "differs\n"); + break; + case SRZ_SAME_TYPES_DIFFERENT: + printf("Zone lengths are the same, types vary\n"); + break; + default: + printf("Unknown SAME field value %#x\n", + hdr->byte4 & SRZ_SAME_MASK); + break; + } + } + if (out_flags == ZONE_OF_SUMMARY) { + status = ZONE_PRINT_OK; + goto bailout; + } + + if ((out_flags == ZONE_OF_NORMAL) + && (first_pass != 0)) { + printf("%*s %*s %*s %*s %*s %*s %*s\n", + field_widths[ZONE_FW_START], "Start LBA", + field_widths[ZONE_FW_LEN], "Length", + field_widths[ZONE_FW_WP], "WP LBA", + field_widths[ZONE_FW_TYPE], "Zone Type", + field_widths[ZONE_FW_COND], "Condition", + field_widths[ZONE_FW_SEQ], "Sequential", + field_widths[ZONE_FW_RESET], "Reset"); + } + + for (desc = &hdr->desc_list[0]; len >= sizeof(*desc); + len -= sizeof(*desc), desc++) { + uint64_t length, start_lba, wp_lba; + + if (ata_format == 0) { + length = scsi_8btou64(desc->zone_length); + start_lba = scsi_8btou64(desc->zone_start_lba); + wp_lba = scsi_8btou64(desc->write_pointer_lba); + } else { + length = le64dec(desc->zone_length); + start_lba = le64dec(desc->zone_start_lba); + wp_lba = le64dec(desc->write_pointer_lba); + } + + printf("%#*jx, %*ju, %#*jx, ", field_widths[ZONE_FW_START], + (uintmax_t)start_lba, field_widths[ZONE_FW_LEN], + (uintmax_t)length, field_widths[ZONE_FW_WP], + (uintmax_t)wp_lba); + + switch (desc->zone_type & SRZ_TYPE_MASK) { + case SRZ_TYPE_CONVENTIONAL: + snprintf(tmpstr, sizeof(tmpstr), "Conventional"); + break; + case SRZ_TYPE_SEQ_PREFERRED: + case SRZ_TYPE_SEQ_REQUIRED: + snprintf(tmpstr, sizeof(tmpstr), "Seq%c%s", + word_sep, ((desc->zone_type & SRZ_TYPE_MASK) == + SRZ_TYPE_SEQ_PREFERRED) ? "Preferred" : + "Required"); + break; + default: + snprintf(tmpstr, sizeof(tmpstr), "Zone%ctype%c%#x", + word_sep, word_sep,desc->zone_type & + SRZ_TYPE_MASK); + break; + } + printf("%*s, ", field_widths[ZONE_FW_TYPE], tmpstr); + + switch (desc->zone_flags & SRZ_ZONE_COND_MASK) { + case SRZ_ZONE_COND_NWP: + snprintf(tmpstr, sizeof(tmpstr), "NWP"); + break; + case SRZ_ZONE_COND_EMPTY: + snprintf(tmpstr, sizeof(tmpstr), "Empty"); + break; + case SRZ_ZONE_COND_IMP_OPEN: + snprintf(tmpstr, sizeof(tmpstr), "Implicit%cOpen", + word_sep); + break; + case SRZ_ZONE_COND_EXP_OPEN: + snprintf(tmpstr, sizeof(tmpstr), "Explicit%cOpen", + word_sep); + break; + case SRZ_ZONE_COND_CLOSED: + snprintf(tmpstr, sizeof(tmpstr), "Closed"); + break; + case SRZ_ZONE_COND_READONLY: + snprintf(tmpstr, sizeof(tmpstr), "Readonly"); + break; + case SRZ_ZONE_COND_FULL: + snprintf(tmpstr, sizeof(tmpstr), "Full"); + break; + case SRZ_ZONE_COND_OFFLINE: + snprintf(tmpstr, sizeof(tmpstr), "Offline"); + break; + default: + snprintf(tmpstr, sizeof(tmpstr), "%#x", + desc->zone_flags & SRZ_ZONE_COND_MASK); + break; + } + + printf("%*s, ", field_widths[ZONE_FW_COND], tmpstr); + + if (desc->zone_flags & SRZ_ZONE_NON_SEQ) + snprintf(tmpstr, sizeof(tmpstr), "Non%cSequential", + word_sep); + else + snprintf(tmpstr, sizeof(tmpstr), "Sequential"); + + printf("%*s, ", field_widths[ZONE_FW_SEQ], tmpstr); + + if (desc->zone_flags & SRZ_ZONE_RESET) + snprintf(tmpstr, sizeof(tmpstr), "Reset%cNeeded", + word_sep); + else + snprintf(tmpstr, sizeof(tmpstr), "No%cReset%cNeeded", + word_sep, word_sep); + + printf("%*s\n", field_widths[ZONE_FW_RESET], tmpstr); + + next_lba = start_lba + length; + } + bailout: + *next_start_lba = next_lba; + + return (status); + } + + int + zone(struct cam_device *device, int argc, char **argv, char *combinedopt, + int retry_count, int timeout, int verbosemode __unused) + { + union ccb *ccb = NULL; + int action = -1, rep_option = -1; + int all_zones = 0; + uint64_t lba = 0; + int error = 0; + uint8_t *data_ptr = NULL; + uint32_t alloc_len = 0, valid_len = 0; + camcontrol_devtype devtype; + int ata_format = 0; + int first_pass = 1; + zone_print_status zp_status; + zone_output_flags out_flags = ZONE_OF_NORMAL; + int c; + + ccb = cam_getccb(device); + if (ccb == NULL) { + warnx("%s: error allocating CCB", __func__); + error = 1; + goto bailout; + } + + bzero(&(&ccb->ccb_h)[1], + sizeof(union ccb) - sizeof(struct ccb_hdr)); + + while ((c = getopt(argc, argv, combinedopt)) != -1) { + switch (c) { + case 'a': + all_zones = 1; + break; + case 'c': { + scsi_nv_status status; + int entry_num; + + status = scsi_get_nv(zone_cmd_map, + (sizeof(zone_cmd_map) / sizeof(zone_cmd_map[0])), + optarg, &entry_num, SCSI_NV_FLAG_IG_CASE); + if (status == SCSI_NV_FOUND) + action = zone_cmd_map[entry_num].value; + else { + warnx("%s: %s: %s option %s", __func__, + (status == SCSI_NV_AMBIGUOUS) ? + "ambiguous" : "invalid", "zone command", + optarg); + error = 1; + goto bailout; + } + break; + } + case 'l': { + char *endptr; + + lba = strtoull(optarg, &endptr, 0); + if (*endptr != '\0') { + warnx("%s: invalid lba argument %s", __func__, + optarg); + error = 1; + goto bailout; + } + break; + } + case 'o': { + scsi_nv_status status; + int entry_num; + + status = scsi_get_nv(zone_rep_opts, + (sizeof(zone_rep_opts) /sizeof(zone_rep_opts[0])), + optarg, &entry_num, SCSI_NV_FLAG_IG_CASE); + if (status == SCSI_NV_FOUND) + rep_option = zone_rep_opts[entry_num].value; + else { + warnx("%s: %s: %s option %s", __func__, + (status == SCSI_NV_AMBIGUOUS) ? + "ambiguous" : "invalid", "report zones", + optarg); + error = 1; + goto bailout; + } + break; + } + case 'P': { + scsi_nv_status status; + int entry_num; + + status = scsi_get_nv(zone_print_opts, + (sizeof(zone_print_opts) / + sizeof(zone_print_opts[0])), optarg, &entry_num, + SCSI_NV_FLAG_IG_CASE); + if (status == SCSI_NV_FOUND) + out_flags = zone_print_opts[entry_num].value; + else { + warnx("%s: %s: %s option %s", __func__, + (status == SCSI_NV_AMBIGUOUS) ? + "ambiguous" : "invalid", "print", + optarg); + error = 1; + goto bailout; + } + break; + } + default: + break; + } + } + if (action == -1) { + warnx("%s: must specify -c ", __func__); + error = 1; + goto bailout; + } + error = get_device_type(device, retry_count, timeout, + /*printerrors*/ 1, &devtype); + if (error != 0) + errx(1, "Unable to determine device type"); + + if (action == ZBC_IN_SA_REPORT_ZONES) { + + alloc_len = sizeof(struct scsi_report_zones_hdr) + + (sizeof(struct scsi_report_zones_desc) * 4096); + + data_ptr = malloc(alloc_len); + if (data_ptr == NULL) + err(1, "unable to allocate %u bytes", alloc_len); + + restart_report: + bzero(data_ptr, alloc_len); + + switch (devtype) { + case CC_DT_SCSI: + scsi_zbc_in(&ccb->csio, + /*retries*/ retry_count, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*service_action*/ action, + /*zone_start_lba*/ lba, + /*zone_options*/ (rep_option != -1) ? + rep_option : 0, + /*data_ptr*/ data_ptr, + /*dxfer_len*/ alloc_len, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout ? timeout : 60000); + break; + case CC_DT_ATA: + case CC_DT_ATA_BEHIND_SCSI: { + uint16_t features; + + /* + * XXX KDM support the partial bit? + */ + features = action; + if (rep_option != -1) + features |= (rep_option << 8); + + build_ata_cmd(ccb, + /*retry_count*/ retry_count, + /*flags*/ CAM_DIR_IN | CAM_DEV_QFRZDIS, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*protocol*/ AP_PROTO_DMA, + /*ata_flags*/ AP_FLAG_BYT_BLOK_BLOCKS | + AP_FLAG_TLEN_SECT_CNT | + AP_FLAG_TDIR_FROM_DEV, + /*features*/ features, + /*sector_count*/ ZAC_ATA_SECTOR_COUNT(alloc_len), + /*lba*/ lba, + /*command*/ ATA_ZAC_MANAGEMENT_IN, + /*data_ptr*/ data_ptr, + /*dxfer_len*/ ZAC_ATA_SECTOR_COUNT(alloc_len)*512, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout ? timeout : 60000, + /*is48bit*/ 1, + /*devtype*/ devtype); + + ata_format = 1; + + break; + } + default: + warnx("%s: Unknown device type %d", __func__,devtype); + error = 1; + goto bailout; + break; /*NOTREACHED*/ + } + } else { + /* + * XXX KDM the current methodology is to always send ATA + * commands to ATA devices. Need to figure out how to + * detect whether a SCSI to ATA translation layer will + * translate ZBC IN/OUT commands to the appropriate ZAC + * command. + */ + switch (devtype) { + case CC_DT_SCSI: + scsi_zbc_out(&ccb->csio, + /*retries*/ retry_count, + /*cbfcnp*/ NULL, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*service_action*/ action, + /*zone_id*/ lba, + /*zone_flags*/ (all_zones != 0) ? ZBC_OUT_ALL : 0, + /*data_ptr*/ NULL, + /*dxfer_len*/ 0, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout ? timeout : 60000); + break; + case CC_DT_ATA: + case CC_DT_ATA_BEHIND_SCSI: { + uint16_t features; + + /* + * Note that we're taking advantage of the fact + * that the action numbers are the same between the + * ZBC and ZAC specs. + */ + features = action & 0xf; + if (all_zones != 0) + features |= (ZBC_OUT_ALL << 8); + + build_ata_cmd(ccb, + /*retry_count*/ retry_count, + /*flags*/ CAM_DIR_NONE | CAM_DEV_QFRZDIS, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*protocol*/ AP_PROTO_NON_DATA, + /*ata_flags*/ AP_FLAG_BYT_BLOK_BYTES | + AP_FLAG_TLEN_NO_DATA, + /*features*/ features, + /*sector_count*/ 0, + /*lba*/ lba, + /*command*/ ATA_ZAC_MANAGEMENT_OUT, + /*data_ptr*/ NULL, + /*dxfer_len*/ 0, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout ? timeout : 60000, + /*is48bit*/ 1, + /*devtype*/ devtype); + ata_format = 1; + break; + } + default: + warnx("%s: Unknown device type %d", __func__,devtype); + error = 1; + goto bailout; + break; /*NOTREACHED*/ + } + } + + ccb->ccb_h.flags |= CAM_DEV_QFRZDIS; + if (retry_count > 0) + ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER; + + error = cam_send_ccb(device, ccb); + if (error != 0) { + warn("error sending %s %s CCB", (devtype == CC_DT_SCSI) ? + "ZBC" : "ZAC Management", + (action == ZBC_IN_SA_REPORT_ZONES) ? "In" : "Out"); + error = -1; + goto bailout; + } + + if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { + cam_error_print(device, ccb, CAM_ESF_ALL, CAM_EPF_ALL,stderr); + error = 1; + goto bailout; + } + + /* + * If we aren't reading the list of zones, we're done. + */ + if (action != ZBC_IN_SA_REPORT_ZONES) + goto bailout; + + if (ccb->ccb_h.func_code == XPT_SCSI_IO) + valid_len = ccb->csio.dxfer_len - ccb->csio.resid; + else + valid_len = ccb->ataio.dxfer_len - ccb->ataio.resid; + + zp_status = zone_rz_print(data_ptr, valid_len, ata_format, out_flags, + first_pass, &lba); + + if (zp_status == ZONE_PRINT_MORE_DATA) { + bzero(ccb, sizeof(*ccb)); + first_pass = 0; + goto restart_report; + } else if (zp_status == ZONE_PRINT_ERROR) + error = 1; + bailout: + if (ccb != NULL) + cam_freeccb(ccb); + + free(data_ptr); + + return (error); + } ==== - //depot/users/kenm/FreeBSD-stable2/10/sbin/camcontrol/zone.c#1 ==== *** src/sys/cam/ata/ata_all.c.orig --- src/sys/cam/ata/ata_all.c *************** *** 105,110 **** --- 105,111 ---- case 0x3f: return ("WRITE_LOG_EXT"); case 0x40: return ("READ_VERIFY"); case 0x42: return ("READ_VERIFY48"); + case 0x4a: return ("ZAC_MANAGEMENT_IN"); case 0x51: return ("CONFIGURE_STREAM"); case 0x60: return ("READ_FPDMA_QUEUED"); case 0x61: return ("WRITE_FPDMA_QUEUED"); *************** *** 125,130 **** --- 126,132 ---- case 0x87: return ("CFA_TRANSLATE_SECTOR"); case 0x90: return ("EXECUTE_DEVICE_DIAGNOSTIC"); case 0x92: return ("DOWNLOAD_MICROCODE"); + case 0x9a: return ("ZAC_MANAGEMENT_OUT"); case 0xa0: return ("PACKET"); case 0xa1: return ("ATAPI_IDENTIFY"); case 0xa2: return ("SERVICE"); *************** *** 417,423 **** cmd == ATA_WRITE_DMA_QUEUED48 || cmd == ATA_WRITE_DMA_QUEUED_FUA48 || cmd == ATA_WRITE_STREAM_DMA48 || ! cmd == ATA_DATA_SET_MANAGEMENT) ataio->cmd.flags |= CAM_ATAIO_DMA; ataio->cmd.command = cmd; ataio->cmd.features = features; --- 419,426 ---- cmd == ATA_WRITE_DMA_QUEUED48 || cmd == ATA_WRITE_DMA_QUEUED_FUA48 || cmd == ATA_WRITE_STREAM_DMA48 || ! cmd == ATA_DATA_SET_MANAGEMENT || ! cmd == ATA_READ_LOG_DMA_EXT) ataio->cmd.flags |= CAM_ATAIO_DMA; ataio->cmd.command = cmd; ataio->cmd.features = features; *************** *** 488,493 **** --- 491,526 ---- } void + ata_read_log(struct ccb_ataio *ataio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint32_t log_address, uint32_t page_number, uint16_t block_count, + uint32_t protocol, uint8_t *data_ptr, uint32_t dxfer_len, + uint32_t timeout) + { + uint64_t lba; + + cam_fill_ataio(ataio, + /*retries*/ 1, + /*cbfcnp*/ cbfcnp, + /*flags*/ CAM_DIR_IN, + /*tag_action*/ 0, + /*data_ptr*/ data_ptr, + /*dxfer_len*/ dxfer_len, + /*timeout*/ timeout); + + lba = (((uint64_t)page_number & 0xff00) << 32) | + ((page_number & 0x00ff) << 8) | + (log_address & 0xff); + + ata_48bit_cmd(ataio, + /*cmd*/ (protocol & CAM_ATAIO_DMA) ? ATA_READ_LOG_DMA_EXT : + ATA_READ_LOG_EXT, + /*features*/ 0, + /*lba*/ lba, + /*sector_count*/ block_count); + } + + void ata_bswap(int8_t *buf, int len) { u_int16_t *ptr = (u_int16_t*)(buf + len); *************** *** 847,849 **** --- 880,1015 ---- length > 0 ? data_ptr[0] : 0, 0x80, length / 4); } + + void + ata_zac_mgmt_out(struct ccb_ataio *ataio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + int use_ncq __unused, uint8_t zm_action, uint64_t zone_id, + uint8_t zone_flags, uint16_t sector_count, uint8_t *data_ptr, + uint32_t dxfer_len, uint32_t timeout) + { + uint8_t command_out, ata_flags; + uint16_t features_out, sectors_out; + + #if 0 + if ((protocol & CAM_ATAIO_FPDMA) == 0) { + #endif + command_out = ATA_ZAC_MANAGEMENT_OUT; + features_out = (zm_action & 0xf) | (zone_flags << 8); + if (dxfer_len == 0) { + ata_flags = 0; + sectors_out = 0; + } else { + ata_flags = CAM_ATAIO_DMA; + /* XXX KDM use sector count? */ + sectors_out = ((dxfer_len >> 9) & 0xffff); + } + #if 0 + } else { + /* + * XXX KDM how do we specify the action here? + */ + if (dxfer_len == 0) { + command_out = ATA_NCQ_NON_DATA; + features_out = ATA_NCQ_ZAC_MGMT_OUT; + features_out |= ((sectors_out & 0xff) << 8); + sectors_out = 0; + } else { + command_out = ATA_SEND_FPDMA_QUEUED; + sectors_out = (ATA_SFPDMA_ZAC_MGMT_OUT << 8); + features_out = ((dxfer_len >> 9) & 0xffff); + } + + ata_flags = CAM_ATAIO_FPDMA; + } + #endif + + cam_fill_ataio(ataio, + /*retries*/ 1, + /*cbfcnp*/ cbfcnp, + /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE, + /*tag_action*/ 0, + /*data_ptr*/ data_ptr, + /*dxfer_len*/ dxfer_len, + /*timeout*/ timeout); + + ata_48bit_cmd(ataio, + /*cmd*/ command_out, + /*features*/ features_out, + /*lba*/ zone_id, + /*sector_count*/ sectors_out); + + } + + void + ata_zac_mgmt_in(struct ccb_ataio *ataio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + int use_ncq __unused, uint8_t zm_action, uint64_t zone_id, + uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len, + uint32_t timeout) + { + uint8_t command_out, ata_flags; + uint16_t features_out, sectors_out; + + + #if 0 + if ((protocol & CAM_ATAIO_FPDMA) == 0) { + #endif + command_out = ATA_ZAC_MANAGEMENT_IN; + /* XXX KDM put a macro here */ + features_out = (zm_action & 0xf) | (zone_flags << 8); + if (dxfer_len == 0) { + /* + * XXX KDM there is currently not a defined action + * of ZAC Management In that specifies no data. So + * callers shouldn't be doing this currently. But, + * just in case one is defined later, set things + * properly here. + */ + ata_flags = 0; + sectors_out = 0; + } else { + ata_flags = CAM_ATAIO_DMA; + sectors_out = ((dxfer_len >> 9) & 0xffff); + } + #if 0 + } else { + /* + * XXX KDM NCQ encapsulation cannot work currently. It + * requires using the Auxiliary register to hold + * Features(15:0), but there is no way to represent that + * in struct ata_cmd. Need to add the auxiliary register, + * backward compatibility glue, and update at least some + * of the ATA drivers to support it. It will also require + * drive support. + */ + if (dxfer_len == 0) { + command_out = ATA_NCQ_NON_DATA; + features_out = ATA_NCQ_ZAC_MGMT_IN; + features_out |= ((sectors_out & 0xff) << 8); + sectors_out = 0; + } else { + command_out = ATA_RECV_FPDMA_QUEUED; + auxiliary = ATA_RFPDMA_ZAC_MGMT_IN | (zone_flags << 8); + features_out = ((dxfer_len >> 9) & 0xffff); + sectors_out = + } + ata_flags = CAM_ATAIO_FPDMA; + } + #endif + + cam_fill_ataio(ataio, + /*retries*/ 1, + /*cbfcnp*/ cbfcnp, + /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE, + /*tag_action*/ 0, + /*data_ptr*/ data_ptr, + /*dxfer_len*/ dxfer_len, + /*timeout*/ timeout); + + ata_48bit_cmd(ataio, + /*cmd*/ command_out, + /*features*/ features_out, + /*lba*/ zone_id, + /*sector_count*/ sectors_out); + } *** src/sys/cam/ata/ata_all.h.orig --- src/sys/cam/ata/ata_all.h *************** *** 124,129 **** --- 124,134 ---- void ata_reset_cmd(struct ccb_ataio *ataio); void ata_pm_read_cmd(struct ccb_ataio *ataio, int reg, int port); void ata_pm_write_cmd(struct ccb_ataio *ataio, int reg, int port, uint32_t val); + void ata_read_log(struct ccb_ataio *ataio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint32_t log_address, uint32_t page_number, + uint16_t block_count, uint32_t protocol, + uint8_t *data_ptr, uint32_t dxfer_len, uint32_t timeout); void ata_bswap(int8_t *buf, int len); void ata_btrim(int8_t *buf, int len); *************** *** 166,169 **** --- 171,186 ---- uint8_t tag_action, uint8_t *data_ptr, uint16_t param_list_length, uint32_t timeout); + void ata_zac_mgmt_out(struct ccb_ataio *ataio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + int use_ncq __unused, uint8_t zm_action, uint64_t zone_id, + uint8_t zone_flags, uint16_t sector_count, uint8_t *data_ptr, + uint32_t dxfer_len, uint32_t timeout); + + void ata_zac_mgmt_in(struct ccb_ataio *ataio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + int use_ncq __unused, uint8_t zm_action, uint64_t zone_id, + uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len, + uint32_t timeout); + #endif *** src/sys/cam/ata/ata_da.c.orig --- src/sys/cam/ata/ata_da.c *************** *** 43,51 **** --- 43,53 ---- #include #include #include + #include #include #include #include + #include #include #endif /* _KERNEL */ *************** *** 58,63 **** --- 60,67 ---- #include #include #include + #include + #include #include #include *************** *** 71,93 **** typedef enum { ADA_STATE_RAHEAD, ADA_STATE_WCACHE, ADA_STATE_NORMAL } ada_state; typedef enum { ! ADA_FLAG_CAN_48BIT = 0x0002, ! ADA_FLAG_CAN_FLUSHCACHE = 0x0004, ! ADA_FLAG_CAN_NCQ = 0x0008, ! ADA_FLAG_CAN_DMA = 0x0010, ! ADA_FLAG_NEED_OTAG = 0x0020, ! ADA_FLAG_WAS_OTAG = 0x0040, ! ADA_FLAG_CAN_TRIM = 0x0080, ! ADA_FLAG_OPEN = 0x0100, ! ADA_FLAG_SCTX_INIT = 0x0200, ! ADA_FLAG_CAN_CFA = 0x0400, ! ADA_FLAG_CAN_POWERMGT = 0x0800, ! ADA_FLAG_CAN_DMA48 = 0x1000, ! ADA_FLAG_DIRTY = 0x2000 } ada_flags; typedef enum { --- 75,109 ---- typedef enum { ADA_STATE_RAHEAD, ADA_STATE_WCACHE, + ADA_STATE_LOGDIR, + ADA_STATE_IDDIR, + ADA_STATE_SUP_CAP, + ADA_STATE_ZONE, ADA_STATE_NORMAL } ada_state; typedef enum { ! ADA_FLAG_CAN_48BIT = 0x000002, ! ADA_FLAG_CAN_FLUSHCACHE = 0x000004, ! ADA_FLAG_CAN_NCQ = 0x000008, ! ADA_FLAG_CAN_DMA = 0x000010, ! ADA_FLAG_NEED_OTAG = 0x000020, ! ADA_FLAG_WAS_OTAG = 0x000040, ! ADA_FLAG_CAN_TRIM = 0x000080, ! ADA_FLAG_OPEN = 0x000100, ! ADA_FLAG_SCTX_INIT = 0x000200, ! ADA_FLAG_CAN_CFA = 0x000400, ! ADA_FLAG_CAN_POWERMGT = 0x000800, ! ADA_FLAG_CAN_DMA48 = 0x001000, ! ADA_FLAG_CAN_LOG = 0x002000, ! ADA_FLAG_CAN_IDLOG = 0x004000, ! ADA_FLAG_CAN_SUPCAP = 0x008000, ! ADA_FLAG_CAN_ZONE = 0x010000, ! ADA_FLAG_CAN_WCACHE = 0x020000, ! ADA_FLAG_CAN_RAHEAD = 0x040000, ! ADA_FLAG_PROBED = 0x080000, ! ADA_FLAG_ANNOUNCED = 0x100000, ! ADA_FLAG_DIRTY = 0x200000 } ada_flags; typedef enum { *************** *** 105,113 **** --- 121,172 ---- ADA_CCB_BUFFER_IO = 0x03, ADA_CCB_DUMP = 0x05, ADA_CCB_TRIM = 0x06, + ADA_CCB_LOGDIR = 0x07, + ADA_CCB_IDDIR = 0x08, + ADA_CCB_SUP_CAP = 0x09, + ADA_CCB_ZONE = 0x0a, ADA_CCB_TYPE_MASK = 0x0F, } ada_ccb_state; + typedef enum { + ADA_ZONE_NONE = 0x00, + ADA_ZONE_DRIVE_MANAGED = 0x01, + ADA_ZONE_HOST_AWARE = 0x02, + ADA_ZONE_HOST_MANAGED = 0x03 + } ada_zone_mode; + + typedef enum { + ADA_ZONE_FLAG_RZ_SUP = 0x0001, + ADA_ZONE_FLAG_OPEN_SUP = 0x0002, + ADA_ZONE_FLAG_CLOSE_SUP = 0x0004, + ADA_ZONE_FLAG_FINISH_SUP = 0x0008, + ADA_ZONE_FLAG_RWP_SUP = 0x0010, + ADA_ZONE_FLAG_SUP_MASK = (ADA_ZONE_FLAG_RZ_SUP | + ADA_ZONE_FLAG_OPEN_SUP | + ADA_ZONE_FLAG_CLOSE_SUP | + ADA_ZONE_FLAG_FINISH_SUP | + ADA_ZONE_FLAG_RWP_SUP), + ADA_ZONE_FLAG_URSWRZ = 0x0020, + ADA_ZONE_FLAG_OPT_SEQ_SET = 0x0040, + ADA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080, + ADA_ZONE_FLAG_MAX_SEQ_SET = 0x0100, + ADA_ZONE_FLAG_SET_MASK = (ADA_ZONE_FLAG_OPT_SEQ_SET | + ADA_ZONE_FLAG_OPT_NONSEQ_SET | + ADA_ZONE_FLAG_MAX_SEQ_SET) + } ada_zone_flags; + + static struct ada_zone_desc { + ada_zone_flags value; + const char *desc; + } ada_zone_desc_table[] = { + {ADA_ZONE_FLAG_RZ_SUP, "Report Zones" }, + {ADA_ZONE_FLAG_OPEN_SUP, "Open" }, + {ADA_ZONE_FLAG_CLOSE_SUP, "Close" }, + {ADA_ZONE_FLAG_FINISH_SUP, "Finish" }, + {ADA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" }, + }; + + /* Offsets into our private area for storing information */ #define ccb_state ppriv_field0 #define ccb_bp ppriv_ptr1 *************** *** 134,139 **** --- 193,207 ---- int refcount; /* Active xpt_action() calls */ ada_state state; ada_flags flags; + ada_zone_mode zone_mode; + ada_zone_flags zone_flags; + struct ata_gp_log_dir ata_logdir; + int valid_logdir_len; + struct ata_identify_log_pages ata_iddir; + int valid_iddir_len; + uint64_t optimal_seq_zones; + uint64_t optimal_nonseq_zones; + uint64_t max_seq_zones; ada_quirks quirks; int sort_io_queue; int trim_max_ranges; *************** *** 517,529 **** static disk_strategy_t adastrategy; static dumper_t adadump; static periph_init_t adainit; static void adaasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg); static void adasysctlinit(void *context, int pending); static periph_ctor_t adaregister; ! static periph_dtor_t adacleanup; static periph_start_t adastart; ! static periph_oninv_t adaoninvalidate; static void adadone(struct cam_periph *periph, union ccb *done_ccb); static int adaerror(union ccb *ccb, u_int32_t cam_flags, --- 585,614 ---- static disk_strategy_t adastrategy; static dumper_t adadump; static periph_init_t adainit; + static void adadiskgonecb(struct disk *dp); + static periph_oninv_t adaoninvalidate; + static periph_dtor_t adacleanup; + static void adareprobe(struct cam_periph *periph, + struct ccb_getdev *cgd); static void adaasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg); + static int adazonemodesysctl(SYSCTL_HANDLER_ARGS); + static int adazonesupsysctl(SYSCTL_HANDLER_ARGS); static void adasysctlinit(void *context, int pending); + static int adagetattr(struct bio *bp); + static void adasetflags(struct ada_softc *softc, + struct ccb_getdev *cgd); static periph_ctor_t adaregister; ! static void ada_dsmtrim(struct ada_softc *softc, struct bio *bp, ! struct ccb_ataio *ataio); ! static void ada_cfaerase(struct ada_softc *softc, struct bio *bp, ! struct ccb_ataio *ataio); ! static int ada_zone_bio_to_ata(int disk_zone_cmd); ! static int ada_zone_cmd(struct cam_periph *periph, union ccb *ccb, ! struct bio *bp, int *queue_ccb); static periph_start_t adastart; ! static void adaprobedone(struct cam_periph *periph, union ccb *ccb); ! static void adazonedone(struct cam_periph *periph, union ccb *ccb); static void adadone(struct cam_periph *periph, union ccb *done_ccb); static int adaerror(union ccb *ccb, u_int32_t cam_flags, *************** *** 642,647 **** --- 727,734 ---- PERIPHDRIVER_DECLARE(ada, adadriver); + static MALLOC_DEFINE(M_ATADA, "ata_da", "ata_da buffers"); + static int adaopen(struct disk *dp) { *************** *** 768,773 **** --- 855,868 ---- biofinish(bp, NULL, ENXIO); return; } + + /* + * Zone commands must be ordered, because they can depend on the + * effects of previously issued commands, and they may affect + * commands after them. + */ + if (bp->bio_cmd == BIO_ZONE) + bp->bio_flags |= BIO_ORDERED; /* * Place it in the queue of disk activities for this disk *************** *** 970,975 **** --- 1065,1103 ---- } static void + adareprobe(struct cam_periph *periph, struct ccb_getdev *cgd) + { + struct ada_softc *softc; + cam_status status; + + softc = (struct ada_softc *)periph->softc; + + if (softc->state != ADA_STATE_NORMAL) + return; + + status = cam_periph_acquire(periph); + if (status != CAM_REQ_CMP) + return; + + if (ADA_RA >= 0 && softc->flags & ADA_FLAG_CAN_RAHEAD) { + softc->state = ADA_STATE_RAHEAD; + } else if (ADA_WC >= 0 && softc->flags & ADA_FLAG_CAN_WCACHE) { + softc->state = ADA_STATE_WCACHE; + } else if (softc->flags & ADA_FLAG_CAN_LOG) { + softc->state = ADA_STATE_LOGDIR; + } else { + /* + * Nothing to probe, so we can just transition to the + * normal state. + */ + adaprobedone(periph, NULL); + return; + } + + xpt_schedule(periph, CAM_PRIORITY_DEV); + } + + static void adaasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg) { *************** *** 1015,1044 **** cgd.ccb_h.func_code = XPT_GDEV_TYPE; xpt_action((union ccb *)&cgd); ! if ((cgd.ident_data.capabilities1 & ATA_SUPPORT_DMA) && ! (cgd.inq_flags & SID_DMA)) ! softc->flags |= ADA_FLAG_CAN_DMA; ! else ! softc->flags &= ~ADA_FLAG_CAN_DMA; ! if (cgd.ident_data.support.command2 & ATA_SUPPORT_ADDRESS48) { ! softc->flags |= ADA_FLAG_CAN_48BIT; ! if (cgd.inq_flags & SID_DMA48) ! softc->flags |= ADA_FLAG_CAN_DMA48; ! else ! softc->flags &= ~ADA_FLAG_CAN_DMA48; ! } else ! softc->flags &= ~(ADA_FLAG_CAN_48BIT | ! ADA_FLAG_CAN_DMA48); ! if ((cgd.ident_data.satacapabilities & ATA_SUPPORT_NCQ) && ! (cgd.inq_flags & SID_DMA) && (cgd.inq_flags & SID_CmdQue)) ! softc->flags |= ADA_FLAG_CAN_NCQ; ! else ! softc->flags &= ~ADA_FLAG_CAN_NCQ; ! if ((cgd.ident_data.support_dsm & ATA_SUPPORT_DSM_TRIM) && ! (cgd.inq_flags & SID_DMA)) ! softc->flags |= ADA_FLAG_CAN_TRIM; ! else ! softc->flags &= ~ADA_FLAG_CAN_TRIM; cam_periph_async(periph, code, path, arg); break; --- 1143,1152 ---- cgd.ccb_h.func_code = XPT_GDEV_TYPE; xpt_action((union ccb *)&cgd); ! /* ! * Set/clear support flags based on the new Identify data. ! */ ! adasetflags(softc, &cgd); cam_periph_async(periph, code, path, arg); break; *************** *** 1067,1078 **** xpt_setup_ccb(&cgd.ccb_h, periph->path, CAM_PRIORITY_NORMAL); cgd.ccb_h.func_code = XPT_GDEV_TYPE; xpt_action((union ccb *)&cgd); ! if (ADA_RA >= 0 && ! cgd.ident_data.support.command1 & ATA_SUPPORT_LOOKAHEAD) softc->state = ADA_STATE_RAHEAD; ! else if (ADA_WC >= 0 && ! cgd.ident_data.support.command1 & ATA_SUPPORT_WRITECACHE) softc->state = ADA_STATE_WCACHE; else break; if (cam_periph_acquire(periph) != CAM_REQ_CMP) --- 1175,1186 ---- xpt_setup_ccb(&cgd.ccb_h, periph->path, CAM_PRIORITY_NORMAL); cgd.ccb_h.func_code = XPT_GDEV_TYPE; xpt_action((union ccb *)&cgd); ! if (ADA_RA >= 0 && softc->flags & ADA_FLAG_CAN_RAHEAD) softc->state = ADA_STATE_RAHEAD; ! else if (ADA_WC >= 0 && softc->flags & ADA_FLAG_CAN_RAHEAD) softc->state = ADA_STATE_WCACHE; + else if (softc->flags & ADA_FLAG_CAN_LOG) + softc->state = ADA_STATE_LOGDIR; else break; if (cam_periph_acquire(periph) != CAM_REQ_CMP) *************** *** 1086,1091 **** --- 1194,1266 ---- } } + static int + adazonemodesysctl(SYSCTL_HANDLER_ARGS) + { + char tmpbuf[40]; + struct ada_softc *softc; + int error; + + softc = (struct ada_softc *)arg1; + + switch (softc->zone_mode) { + case ADA_ZONE_DRIVE_MANAGED: + snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed"); + break; + case ADA_ZONE_HOST_AWARE: + snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware"); + break; + case ADA_ZONE_HOST_MANAGED: + snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed"); + break; + case ADA_ZONE_NONE: + default: + snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned"); + break; + } + + error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req); + + return (error); + } + + static int + adazonesupsysctl(SYSCTL_HANDLER_ARGS) + { + char tmpbuf[180]; + struct ada_softc *softc; + struct sbuf sb; + int error, first; + unsigned int i; + + softc = (struct ada_softc *)arg1; + + error = 0; + first = 1; + sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0); + + for (i = 0; i < sizeof(ada_zone_desc_table) / + sizeof(ada_zone_desc_table[0]); i++) { + if (softc->zone_flags & ada_zone_desc_table[i].value) { + if (first == 0) + sbuf_printf(&sb, ", "); + else + first = 0; + sbuf_cat(&sb, ada_zone_desc_table[i].desc); + } + } + + if (first == 1) + sbuf_printf(&sb, "None"); + + sbuf_finish(&sb); + + error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req); + + return (error); + } + + static void adasysctlinit(void *context, int pending) { *************** *** 1102,1108 **** } softc = (struct ada_softc *)periph->softc; ! snprintf(tmpstr, sizeof(tmpstr), "CAM ADA unit %d", periph->unit_number); snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number); sysctl_ctx_init(&softc->sysctl_ctx); --- 1277,1283 ---- } softc = (struct ada_softc *)periph->softc; ! snprintf(tmpstr, sizeof(tmpstr), "CAM ADA unit %d",periph->unit_number); snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number); sysctl_ctx_init(&softc->sysctl_ctx); *************** *** 1126,1131 **** --- 1301,1330 ---- OID_AUTO, "sort_io_queue", CTLFLAG_RW | CTLFLAG_MPSAFE, &softc->sort_io_queue, 0, "Sort IO queue to try and optimise disk access patterns"); + + SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), + OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD, + softc, 0, adazonemodesysctl, "A", + "Zone Mode"); + SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), + OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD, + softc, 0, adazonesupsysctl, "A", + "Zone Support"); + SYSCTL_ADD_UQUAD(&softc->sysctl_ctx, + SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, + "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones, + "Optimal Number of Open Sequential Write Preferred Zones"); + SYSCTL_ADD_UQUAD(&softc->sysctl_ctx, + SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, + "optimal_nonseq_zones", CTLFLAG_RD, + &softc->optimal_nonseq_zones, + "Optimal Number of Non-Sequentially Written Sequential Write " + "Preferred Zones"); + SYSCTL_ADD_UQUAD(&softc->sysctl_ctx, + SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, + "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones, + "Maximum Number of Open Sequential Write Required Zones"); + #ifdef ADA_TEST_FAILURE /* * Add a 'door bell' sysctl which allows one to set it from userland *************** *** 1164,1169 **** --- 1363,1444 ---- return ret; } + static void + adasetflags(struct ada_softc *softc, struct ccb_getdev *cgd) + { + if ((cgd->ident_data.capabilities1 & ATA_SUPPORT_DMA) && + (cgd->inq_flags & SID_DMA)) + softc->flags |= ADA_FLAG_CAN_DMA; + else + softc->flags &= ~ADA_FLAG_CAN_DMA; + + if (cgd->ident_data.support.command2 & ATA_SUPPORT_ADDRESS48) { + softc->flags |= ADA_FLAG_CAN_48BIT; + if (cgd->inq_flags & SID_DMA48) + softc->flags |= ADA_FLAG_CAN_DMA48; + else + softc->flags &= ~ADA_FLAG_CAN_DMA48; + } else + softc->flags &= ~(ADA_FLAG_CAN_48BIT | ADA_FLAG_CAN_DMA48); + + if (cgd->ident_data.support.command2 & ATA_SUPPORT_FLUSHCACHE) + softc->flags |= ADA_FLAG_CAN_FLUSHCACHE; + else + softc->flags &= ~ADA_FLAG_CAN_FLUSHCACHE; + + if (cgd->ident_data.support.command1 & ATA_SUPPORT_POWERMGT) + softc->flags |= ADA_FLAG_CAN_POWERMGT; + else + softc->flags &= ~ADA_FLAG_CAN_POWERMGT; + + if ((cgd->ident_data.satacapabilities & ATA_SUPPORT_NCQ) && + (cgd->inq_flags & SID_DMA) && (cgd->inq_flags & SID_CmdQue)) + softc->flags |= ADA_FLAG_CAN_NCQ; + else + softc->flags &= ~ADA_FLAG_CAN_NCQ; + + if ((cgd->ident_data.support_dsm & ATA_SUPPORT_DSM_TRIM) && + (cgd->inq_flags & SID_DMA)) { + softc->flags |= ADA_FLAG_CAN_TRIM; + softc->trim_max_ranges = TRIM_MAX_RANGES; + if (cgd->ident_data.max_dsm_blocks != 0) { + softc->trim_max_ranges = + min(cgd->ident_data.max_dsm_blocks * + ATA_DSM_BLK_RANGES, softc->trim_max_ranges); + } + } else + softc->flags &= ~ADA_FLAG_CAN_TRIM; + + if (cgd->ident_data.support.command2 & ATA_SUPPORT_CFA) + softc->flags |= ADA_FLAG_CAN_CFA; + else + softc->flags &= ~ADA_FLAG_CAN_CFA; + + if (cgd->ident_data.support.extension & ATA_SUPPORT_GENLOG) + softc->flags |= ADA_FLAG_CAN_LOG; + else + softc->flags &= ~ADA_FLAG_CAN_LOG; + + if ((cgd->ident_data.support3 & ATA_SUPPORT_ZONE_MASK) == + ATA_SUPPORT_ZONE_HOST_AWARE) + softc->zone_mode = ADA_ZONE_HOST_AWARE; + else if ((cgd->ident_data.support3 & ATA_SUPPORT_ZONE_MASK) == + ATA_SUPPORT_ZONE_DEV_MANAGED) + softc->zone_mode = ADA_ZONE_DRIVE_MANAGED; + else + softc->zone_mode = ADA_ZONE_NONE; + + if (cgd->ident_data.support.command1 & ATA_SUPPORT_LOOKAHEAD) + softc->flags |= ADA_FLAG_CAN_RAHEAD; + else + softc->flags &= ~ADA_FLAG_CAN_RAHEAD; + + if (cgd->ident_data.support.command1 & ATA_SUPPORT_WRITECACHE) + softc->flags |= ADA_FLAG_CAN_WCACHE; + else + softc->flags &= ~ADA_FLAG_CAN_WCACHE; + } + static cam_status adaregister(struct cam_periph *periph, void *arg) { *************** *** 1194,1226 **** bioq_init(&softc->bio_queue); bioq_init(&softc->trim_queue); ! if ((cgd->ident_data.capabilities1 & ATA_SUPPORT_DMA) && ! (cgd->inq_flags & SID_DMA)) ! softc->flags |= ADA_FLAG_CAN_DMA; ! if (cgd->ident_data.support.command2 & ATA_SUPPORT_ADDRESS48) { ! softc->flags |= ADA_FLAG_CAN_48BIT; ! if (cgd->inq_flags & SID_DMA48) ! softc->flags |= ADA_FLAG_CAN_DMA48; ! } ! if (cgd->ident_data.support.command2 & ATA_SUPPORT_FLUSHCACHE) ! softc->flags |= ADA_FLAG_CAN_FLUSHCACHE; ! if (cgd->ident_data.support.command1 & ATA_SUPPORT_POWERMGT) ! softc->flags |= ADA_FLAG_CAN_POWERMGT; ! if ((cgd->ident_data.satacapabilities & ATA_SUPPORT_NCQ) && ! (cgd->inq_flags & SID_DMA) && (cgd->inq_flags & SID_CmdQue)) ! softc->flags |= ADA_FLAG_CAN_NCQ; ! if ((cgd->ident_data.support_dsm & ATA_SUPPORT_DSM_TRIM) && ! (cgd->inq_flags & SID_DMA)) { ! softc->flags |= ADA_FLAG_CAN_TRIM; ! softc->trim_max_ranges = TRIM_MAX_RANGES; ! if (cgd->ident_data.max_dsm_blocks != 0) { ! softc->trim_max_ranges = ! min(cgd->ident_data.max_dsm_blocks * ! ATA_DSM_BLK_RANGES, softc->trim_max_ranges); ! } ! } ! if (cgd->ident_data.support.command2 & ATA_SUPPORT_CFA) ! softc->flags |= ADA_FLAG_CAN_CFA; periph->softc = softc; --- 1469,1478 ---- bioq_init(&softc->bio_queue); bioq_init(&softc->trim_queue); ! /* ! * Set support flags based on the Identify data. ! */ ! adasetflags(softc, cgd); periph->softc = softc; *************** *** 1294,1300 **** maxio = min(maxio, 256 * softc->params.secsize); softc->disk->d_maxsize = maxio; softc->disk->d_unit = periph->unit_number; ! softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION; if (softc->flags & ADA_FLAG_CAN_FLUSHCACHE) softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE; if (softc->flags & ADA_FLAG_CAN_TRIM) { --- 1546,1552 ---- maxio = min(maxio, 256 * softc->params.secsize); softc->disk->d_maxsize = maxio; softc->disk->d_unit = periph->unit_number; ! softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE; if (softc->flags & ADA_FLAG_CAN_FLUSHCACHE) softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE; if (softc->flags & ADA_FLAG_CAN_TRIM) { *************** *** 1366,1372 **** } disk_create(softc->disk, DISK_VERSION); cam_periph_lock(periph); - cam_periph_unhold(periph); dp = &softc->params; snprintf(announce_buf, sizeof(announce_buf), --- 1618,1623 ---- *************** *** 1407,1426 **** (ada_default_timeout * hz) / ADA_ORDEREDTAG_INTERVAL, adasendorderedtag, softc); ! if (ADA_RA >= 0 && ! cgd->ident_data.support.command1 & ATA_SUPPORT_LOOKAHEAD) { softc->state = ADA_STATE_RAHEAD; ! } else if (ADA_WC >= 0 && ! cgd->ident_data.support.command1 & ATA_SUPPORT_WRITECACHE) { softc->state = ADA_STATE_WCACHE; } else { ! softc->state = ADA_STATE_NORMAL; return(CAM_REQ_CMP); } ! if (cam_periph_acquire(periph) != CAM_REQ_CMP) ! softc->state = ADA_STATE_NORMAL; ! else ! xpt_schedule(periph, CAM_PRIORITY_DEV); return(CAM_REQ_CMP); } --- 1658,1680 ---- (ada_default_timeout * hz) / ADA_ORDEREDTAG_INTERVAL, adasendorderedtag, softc); ! if (ADA_RA >= 0 && softc->flags & ADA_FLAG_CAN_RAHEAD) { softc->state = ADA_STATE_RAHEAD; ! } else if (ADA_WC >= 0 && softc->flags & ADA_FLAG_CAN_WCACHE) { softc->state = ADA_STATE_WCACHE; + } else if (softc->flags & ADA_FLAG_CAN_LOG) { + softc->state = ADA_STATE_LOGDIR; } else { ! /* ! * Nothing to probe, so we can just transition to the ! * normal state. ! */ ! adaprobedone(periph, NULL); return(CAM_REQ_CMP); } ! ! xpt_schedule(periph, CAM_PRIORITY_DEV); ! return(CAM_REQ_CMP); } *************** *** 1520,1525 **** --- 1774,1979 ---- ata_28bit_cmd(ataio, ATA_CFA_ERASE, 0, lba, count); } + static int + ada_zone_bio_to_ata(int disk_zone_cmd) + { + switch (disk_zone_cmd) { + case DISK_ZONE_OPEN: + return ATA_ZM_OPEN_ZONE; + case DISK_ZONE_CLOSE: + return ATA_ZM_CLOSE_ZONE; + case DISK_ZONE_FINISH: + return ATA_ZM_FINISH_ZONE; + case DISK_ZONE_RWP: + return ATA_ZM_RWP; + } + + return -1; + } + + static int + ada_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp, + int *queue_ccb) + { + struct ada_softc *softc; + int error; + + error = 0; + + if (bp->bio_cmd != BIO_ZONE) { + error = EINVAL; + goto bailout; + } + + softc = periph->softc; + + switch (bp->bio_zone.zone_cmd) { + case DISK_ZONE_OPEN: + case DISK_ZONE_CLOSE: + case DISK_ZONE_FINISH: + case DISK_ZONE_RWP: { + int zone_flags; + int zone_sa; + uint64_t lba; + + zone_sa = ada_zone_bio_to_ata(bp->bio_zone.zone_cmd); + if (zone_sa == -1) { + xpt_print(periph->path, "Cannot translate zone " + "cmd %#x to ATA\n", bp->bio_zone.zone_cmd); + error = EINVAL; + goto bailout; + } + + zone_flags = 0; + lba = bp->bio_zone.zone_params.rwp.id; + + if (bp->bio_zone.zone_params.rwp.flags & + DISK_ZONE_RWP_FLAG_ALL) + zone_flags |= ZBC_OUT_ALL; + + ata_zac_mgmt_out(&ccb->ataio, + /*retries*/ ada_retry_count, + /*cbfcnp*/ adadone, + /*use_ncq*/ 0, + /*zm_action*/ zone_sa, + /*zone_id*/ lba, + /*zone_flags*/ zone_flags, + /*sector_count*/ 0, + /*data_ptr*/ NULL, + /*dxfer_len*/ 0, + /*timeout*/ ada_default_timeout * 1000); + *queue_ccb = 1; + + break; + } + case DISK_ZONE_REPORT_ZONES: { + uint8_t *rz_ptr; + uint32_t num_entries, alloc_size; + struct disk_zone_report *rep; + + rep = &bp->bio_zone.zone_params.report; + + num_entries = rep->entries_allocated; + if (num_entries == 0) { + xpt_print(periph->path, "No entries allocated for " + "Report Zones request\n"); + error = EINVAL; + goto bailout; + } + alloc_size = sizeof(struct scsi_report_zones_hdr) + + (sizeof(struct scsi_report_zones_desc) * num_entries); + rz_ptr = malloc(alloc_size, M_ATADA, M_NOWAIT | M_ZERO); + if (rz_ptr == NULL) { + xpt_print(periph->path, "Unable to allocate memory " + "for Report Zones request\n"); + error = ENOMEM; + goto bailout; + } + + ata_zac_mgmt_in(&ccb->ataio, + /*retries*/ ada_retry_count, + /*cbcfnp*/ adadone, + /*use_ncq*/ 0, + /*zm_action*/ ATA_ZM_REPORT_ZONES, + /*zone_id*/ rep->starting_id, + /*zone_flags*/ rep->rep_options, + /*data_ptr*/ rz_ptr, + /*dxfer_len*/ alloc_size, + /*timeout*/ ada_default_timeout * 1000); + + /* + * For BIO_ZONE, this isn't normally needed. However, it + * is used by devstat_end_transaction_bio() to determine + * how much data was transferred. + */ + /* + * XXX KDM we have a problem. But I'm not sure how to fix + * it. devstat uses bio_bcount - bio_resid to calculate + * the amount of data transferred. The GEOM disk code + * uses bio_length - bio_resid to calculate the amount of + * data in bio_completed. We have different structure + * sizes above and below the ada(4) driver. So, if we + * use the sizes above, the amount transferred won't be + * quite accurate for devstat. If we use different sizes + * for bio_bcount and bio_length (above and below + * respectively), then the residual needs to match one or + * the other. Everything is calculated after the bio + * leaves the driver, so changing the values around isn't + * really an option. For now, just set the count to the + * passed in length. This means that the calculations + * above (e.g. bio_completed) will be correct, but the + * amount of data reported to devstat will be slightly + * under or overstated. + */ + bp->bio_bcount = bp->bio_length; + + *queue_ccb = 1; + + break; + } + case DISK_ZONE_GET_PARAMS: { + struct disk_zone_disk_params *params; + + params = &bp->bio_zone.zone_params.disk_params; + bzero(params, sizeof(*params)); + + switch (softc->zone_mode) { + case ADA_ZONE_DRIVE_MANAGED: + params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED; + break; + case ADA_ZONE_HOST_AWARE: + params->zone_mode = DISK_ZONE_MODE_HOST_AWARE; + break; + case ADA_ZONE_HOST_MANAGED: + params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED; + break; + default: + case ADA_ZONE_NONE: + params->zone_mode = DISK_ZONE_MODE_NONE; + break; + } + + if (softc->zone_flags & ADA_ZONE_FLAG_URSWRZ) + params->flags |= DISK_ZONE_DISK_URSWRZ; + + if (softc->zone_flags & ADA_ZONE_FLAG_OPT_SEQ_SET) { + params->optimal_seq_zones = softc->optimal_seq_zones; + params->flags |= DISK_ZONE_OPT_SEQ_SET; + } + + if (softc->zone_flags & ADA_ZONE_FLAG_OPT_NONSEQ_SET) { + params->optimal_nonseq_zones = + softc->optimal_nonseq_zones; + params->flags |= DISK_ZONE_OPT_NONSEQ_SET; + } + + if (softc->zone_flags & ADA_ZONE_FLAG_MAX_SEQ_SET) { + params->max_seq_zones = softc->max_seq_zones; + params->flags |= DISK_ZONE_MAX_SEQ_SET; + } + if (softc->zone_flags & ADA_ZONE_FLAG_RZ_SUP) + params->flags |= DISK_ZONE_RZ_SUP; + + if (softc->zone_flags & ADA_ZONE_FLAG_OPEN_SUP) + params->flags |= DISK_ZONE_OPEN_SUP; + + if (softc->zone_flags & ADA_ZONE_FLAG_CLOSE_SUP) + params->flags |= DISK_ZONE_CLOSE_SUP; + + if (softc->zone_flags & ADA_ZONE_FLAG_FINISH_SUP) + params->flags |= DISK_ZONE_FINISH_SUP; + + if (softc->zone_flags & ADA_ZONE_FLAG_RWP_SUP) + params->flags |= DISK_ZONE_RWP_SUP; + break; + } + default: + break; + } + bailout: + return (error); + } + static void adastart(struct cam_periph *periph, union ccb *start_ccb) { *************** *** 1709,1714 **** --- 2163,2182 ---- else ata_28bit_cmd(ataio, ATA_FLUSHCACHE, 0, 0, 0); break; + case BIO_ZONE: { + int error, queue_ccb; + + queue_ccb = 0; + + error = ada_zone_cmd(periph, start_ccb, bp, &queue_ccb); + if ((error != 0) + || (queue_ccb == 0)) { + biofinish(bp, NULL, error); + xpt_release_ccb(start_ccb); + return; + } + break; + } } start_ccb->ccb_h.ccb_state = ADA_CCB_BUFFER_IO; start_ccb->ccb_h.flags |= CAM_UNLOCKED; *************** *** 1750,1770 **** xpt_action(start_ccb); break; } } } static void adadone(struct cam_periph *periph, union ccb *done_ccb) { struct ada_softc *softc; struct ccb_ataio *ataio; - struct ccb_getdev *cgd; struct cam_path *path; int state; softc = (struct ada_softc *)periph->softc; ataio = &done_ccb->ataio; path = done_ccb->ccb_h.path; CAM_DEBUG(path, CAM_DEBUG_TRACE, ("adadone\n")); --- 2218,2523 ---- xpt_action(start_ccb); break; } + case ADA_STATE_LOGDIR: + { + struct ata_gp_log_dir *log_dir; + + if ((softc->flags & ADA_FLAG_CAN_LOG) == 0) { + adaprobedone(periph, start_ccb); + break; + } + + log_dir = malloc(sizeof(*log_dir), M_ATADA, M_NOWAIT|M_ZERO); + if (log_dir == NULL) { + xpt_print(periph->path, "Couldn't malloc log_dir " + "data\n"); + softc->state = ADA_STATE_NORMAL; + xpt_release_ccb(start_ccb); + break; + } + + + ata_read_log(ataio, + /*retries*/1, + /*cbfcnp*/adadone, + /*log_address*/ ATA_LOG_DIRECTORY, + /*page_number*/ 0, + /*block_count*/ 1, + /*protocol*/ softc->flags & ADA_FLAG_CAN_DMA ? + CAM_ATAIO_DMA : 0, + /*data_ptr*/ (uint8_t *)log_dir, + /*dxfer_len*/sizeof(*log_dir), + /*timeout*/ada_default_timeout*1000); + + start_ccb->ccb_h.ccb_state = ADA_CCB_LOGDIR; + xpt_action(start_ccb); + break; + } + case ADA_STATE_IDDIR: + { + struct ata_identify_log_pages *id_dir; + + id_dir = malloc(sizeof(*id_dir), M_ATADA, M_NOWAIT | M_ZERO); + if (id_dir == NULL) { + xpt_print(periph->path, "Couldn't malloc id_dir " + "data\n"); + adaprobedone(periph, start_ccb); + break; + } + + ata_read_log(ataio, + /*retries*/1, + /*cbfcnp*/adadone, + /*log_address*/ ATA_IDENTIFY_DATA_LOG, + /*page_number*/ ATA_IDL_PAGE_LIST, + /*block_count*/ 1, + /*protocol*/ softc->flags & ADA_FLAG_CAN_DMA ? + CAM_ATAIO_DMA : 0, + /*data_ptr*/ (uint8_t *)id_dir, + /*dxfer_len*/ sizeof(*id_dir), + /*timeout*/ada_default_timeout*1000); + + start_ccb->ccb_h.ccb_state = ADA_CCB_IDDIR; + xpt_action(start_ccb); + break; + } + case ADA_STATE_SUP_CAP: + { + struct ata_identify_log_sup_cap *sup_cap; + + sup_cap = malloc(sizeof(*sup_cap), M_ATADA, M_NOWAIT|M_ZERO); + if (sup_cap == NULL) { + xpt_print(periph->path, "Couldn't malloc sup_cap " + "data\n"); + adaprobedone(periph, start_ccb); + break; + } + + ata_read_log(ataio, + /*retries*/1, + /*cbfcnp*/adadone, + /*log_address*/ ATA_IDENTIFY_DATA_LOG, + /*page_number*/ ATA_IDL_SUP_CAP, + /*block_count*/ 1, + /*protocol*/ softc->flags & ADA_FLAG_CAN_DMA ? + CAM_ATAIO_DMA : 0, + /*data_ptr*/ (uint8_t *)sup_cap, + /*dxfer_len*/ sizeof(*sup_cap), + /*timeout*/ada_default_timeout*1000); + + start_ccb->ccb_h.ccb_state = ADA_CCB_SUP_CAP; + xpt_action(start_ccb); + break; + } + case ADA_STATE_ZONE: + { + struct ata_zoned_info_log *ata_zone; + + ata_zone = malloc(sizeof(*ata_zone), M_ATADA, M_NOWAIT|M_ZERO); + if (ata_zone == NULL) { + xpt_print(periph->path, "Couldn't malloc ata_zone " + "data\n"); + adaprobedone(periph, start_ccb); + break; + } + + ata_read_log(ataio, + /*retries*/1, + /*cbfcnp*/adadone, + /*log_address*/ ATA_IDENTIFY_DATA_LOG, + /*page_number*/ ATA_IDL_ZDI, + /*block_count*/ 1, + /*protocol*/ softc->flags & ADA_FLAG_CAN_DMA ? + CAM_ATAIO_DMA : 0, + /*data_ptr*/ (uint8_t *)ata_zone, + /*dxfer_len*/ sizeof(*ata_zone), + /*timeout*/ada_default_timeout*1000); + + start_ccb->ccb_h.ccb_state = ADA_CCB_ZONE; + xpt_action(start_ccb); + break; + } + } + } + + static void + adaprobedone(struct cam_periph *periph, union ccb *ccb) + { + struct ada_softc *softc; + + softc = (struct ada_softc *)periph->softc; + + if (ccb != NULL) + xpt_release_ccb(ccb); + + softc->state = ADA_STATE_NORMAL; + softc->flags |= ADA_FLAG_PROBED; + adaschedule(periph); + if ((softc->flags & ADA_FLAG_ANNOUNCED) == 0) { + softc->flags |= ADA_FLAG_ANNOUNCED; + cam_periph_unhold(periph); + } else { + cam_periph_release_locked(periph); + } + } + + static void + adazonedone(struct cam_periph *periph, union ccb *ccb) + { + struct ada_softc *softc; + struct bio *bp; + + softc = periph->softc; + bp = (struct bio *)ccb->ccb_h.ccb_bp; + + switch (bp->bio_zone.zone_cmd) { + case DISK_ZONE_OPEN: + case DISK_ZONE_CLOSE: + case DISK_ZONE_FINISH: + case DISK_ZONE_RWP: + break; + case DISK_ZONE_REPORT_ZONES: { + uint32_t avail_len; + struct disk_zone_report *rep; + struct scsi_report_zones_hdr *hdr; + struct scsi_report_zones_desc *desc; + struct disk_zone_rep_entry *entry; + uint32_t num_alloced, hdr_len, num_avail; + uint32_t num_to_fill, i; + + rep = &bp->bio_zone.zone_params.report; + avail_len = ccb->ataio.dxfer_len - ccb->ataio.resid; + /* + * Note that bio_resid isn't normally used for zone + * commands, but it is used by devstat_end_transaction_bio() + * to determine how much data was transferred. Because + * the size of the SCSI/ATA data structures is different + * than the size of the BIO interface structures, the + * amount of data actually transferred from the drive will + * be different than the amount of data transferred to + * the user. + */ + num_alloced = rep->entries_allocated; + hdr = (struct scsi_report_zones_hdr *)ccb->ataio.data_ptr; + if (avail_len < sizeof(*hdr)) { + /* + * Is there a better error than EIO here? We asked + * for at least the header, and we got less than + * that. + */ + bp->bio_error = EIO; + bp->bio_flags |= BIO_ERROR; + bp->bio_resid = bp->bio_bcount; + break; + } + + hdr_len = le32dec(hdr->length); + if (hdr_len > 0) + rep->entries_available = hdr_len / sizeof(*desc); + else + rep->entries_available = 0; + /* + * NOTE: using the same values for the BIO version of the + * same field as the SCSI/ATA values. This means we could + * get some additional values that aren't defined in bio.h + * if more values of the same field are defined later. + */ + rep->header.same = hdr->byte4 & SRZ_SAME_MASK; + rep->header.maximum_lba = le64dec(hdr->maximum_lba); + /* + * If the drive reports no entries that match the query, + * we're done. + */ + if (hdr_len == 0) { + rep->entries_filled = 0; + bp->bio_resid = bp->bio_bcount; + break; + } + + num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc), + hdr_len / sizeof(*desc)); + /* + * If the drive didn't return any data, then we're done. + */ + if (num_avail == 0) { + rep->entries_filled = 0; + bp->bio_resid = bp->bio_bcount; + break; + } + + num_to_fill = min(num_avail, rep->entries_allocated); + /* + * If the user didn't allocate any entries for us to fill, + * we're done. + */ + if (num_to_fill == 0) { + rep->entries_filled = 0; + bp->bio_resid = bp->bio_bcount; + break; + } + + for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0]; + i < num_to_fill; i++, desc++, entry++) { + /* + * NOTE: we're mapping the values here directly + * from the SCSI/ATA bit definitions to the bio.h + * definitons. There is also a warning in + * disk_zone.h, but the impact is that if + * additional values are added in the SCSI/ATA + * specs these will be visible to consumers of + * this interface. + */ + entry->zone_type = desc->zone_type & SRZ_TYPE_MASK; + entry->zone_condition = + (desc->zone_flags & SRZ_ZONE_COND_MASK) >> + SRZ_ZONE_COND_SHIFT; + entry->zone_flags |= desc->zone_flags & + (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET); + entry->zone_length = le64dec(desc->zone_length); + entry->zone_start_lba = le64dec(desc->zone_start_lba); + entry->write_pointer_lba = + le64dec(desc->write_pointer_lba); + } + rep->entries_filled = num_to_fill; + /* + * Note that this residual is accurate from the user's + * standpoint, but the amount transferred isn't accurate + * from the standpoint of what actually came back from the + * drive. + */ + bp->bio_resid = bp->bio_bcount - (num_to_fill * sizeof(*entry)); + break; } + case DISK_ZONE_GET_PARAMS: + default: + /* + * In theory we should not get a GET_PARAMS bio, since it + * should be handled without queueing the command to the + * drive. + */ + panic("%s: Invalid zone command %d", __func__, + bp->bio_zone.zone_cmd); + break; + } + + if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES) + free(ccb->ataio.data_ptr, M_ATADA); } + static void adadone(struct cam_periph *periph, union ccb *done_ccb) { struct ada_softc *softc; struct ccb_ataio *ataio; struct cam_path *path; + uint32_t priority; int state; softc = (struct ada_softc *)periph->softc; ataio = &done_ccb->ataio; path = done_ccb->ccb_h.path; + priority = done_ccb->ccb_h.pinfo.priority; CAM_DEBUG(path, CAM_DEBUG_TRACE, ("adadone\n")); *************** *** 1793,1798 **** --- 2546,2552 ---- } else { if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) panic("REQ_CMP with QFRZN"); + error = 0; } bp = (struct bio *)done_ccb->ccb_h.ccb_bp; *************** *** 1801,1811 **** bp->bio_resid = bp->bio_bcount; bp->bio_flags |= BIO_ERROR; } else { ! if (state == ADA_CCB_TRIM) bp->bio_resid = 0; else bp->bio_resid = ataio->resid; ! if (bp->bio_resid > 0) bp->bio_flags |= BIO_ERROR; } softc->outstanding_cmds--; --- 2555,2569 ---- bp->bio_resid = bp->bio_bcount; bp->bio_flags |= BIO_ERROR; } else { ! if (bp->bio_cmd == BIO_ZONE) ! adazonedone(periph, done_ccb); ! else if (state == ADA_CCB_TRIM) bp->bio_resid = 0; else bp->bio_resid = ataio->resid; ! ! if ((bp->bio_resid > 0) ! && (bp->bio_cmd != BIO_ZONE)) bp->bio_flags |= BIO_ERROR; } softc->outstanding_cmds--; *************** *** 1851,1857 **** { if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { if (adaerror(done_ccb, 0, 0) == ERESTART) { - out: /* Drop freeze taken due to CAM_DEV_QFREEZE */ cam_release_devq(path, 0, 0, 0, FALSE); return; --- 2609,2614 ---- *************** *** 1872,1901 **** * is removed, and we need it around for the CCB release * operation. */ ! cgd = (struct ccb_getdev *)done_ccb; ! xpt_setup_ccb(&cgd->ccb_h, path, CAM_PRIORITY_NORMAL); ! cgd->ccb_h.func_code = XPT_GDEV_TYPE; ! xpt_action((union ccb *)cgd); ! if (ADA_WC >= 0 && ! cgd->ident_data.support.command1 & ATA_SUPPORT_WRITECACHE) { ! softc->state = ADA_STATE_WCACHE; ! xpt_release_ccb(done_ccb); ! xpt_schedule(periph, CAM_PRIORITY_DEV); ! goto out; ! } ! softc->state = ADA_STATE_NORMAL; xpt_release_ccb(done_ccb); /* Drop freeze taken due to CAM_DEV_QFREEZE */ cam_release_devq(path, 0, 0, 0, FALSE); - adaschedule(periph); - cam_periph_release_locked(periph); return; } case ADA_CCB_WCACHE: { if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { if (adaerror(done_ccb, 0, 0) == ERESTART) { ! goto out; } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { cam_release_devq(path, /*relsim_flags*/0, --- 2629,2649 ---- * is removed, and we need it around for the CCB release * operation. */ ! xpt_release_ccb(done_ccb); + softc->state = ADA_STATE_WCACHE; + xpt_schedule(periph, priority); /* Drop freeze taken due to CAM_DEV_QFREEZE */ cam_release_devq(path, 0, 0, 0, FALSE); return; } case ADA_CCB_WCACHE: { if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { if (adaerror(done_ccb, 0, 0) == ERESTART) { ! /* Drop freeze taken due to CAM_DEV_QFREEZE */ ! cam_release_devq(path, 0, 0, 0, FALSE); ! return; } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { cam_release_devq(path, /*relsim_flags*/0, *************** *** 1905,1924 **** } } - softc->state = ADA_STATE_NORMAL; - /* - * Since our peripheral may be invalidated by an error - * above or an external event, we must release our CCB - * before releasing the reference on the peripheral. - * The peripheral will only go away once the last reference - * is removed, and we need it around for the CCB release - * operation. - */ - xpt_release_ccb(done_ccb); /* Drop freeze taken due to CAM_DEV_QFREEZE */ cam_release_devq(path, 0, 0, 0, FALSE); ! adaschedule(periph); ! cam_periph_release_locked(periph); return; } case ADA_CCB_DUMP: --- 2653,3017 ---- } } /* Drop freeze taken due to CAM_DEV_QFREEZE */ cam_release_devq(path, 0, 0, 0, FALSE); ! ! if (softc->flags & ADA_FLAG_CAN_LOG) { ! xpt_release_ccb(done_ccb); ! softc->state = ADA_STATE_LOGDIR; ! xpt_schedule(periph, priority); ! } else { ! adaprobedone(periph, done_ccb); ! } ! return; ! } ! case ADA_CCB_LOGDIR: ! { ! int error; ! ! if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { ! error = 0; ! softc->valid_logdir_len = 0; ! bzero(&softc->ata_logdir, sizeof(softc->ata_logdir)); ! softc->valid_logdir_len = ! ataio->dxfer_len - ataio->resid; ! if (softc->valid_logdir_len > 0) ! bcopy(ataio->data_ptr, &softc->ata_logdir, ! min(softc->valid_logdir_len, ! sizeof(softc->ata_logdir))); ! /* ! * Figure out whether the Identify Device log is ! * supported. The General Purpose log directory ! * has a header, and lists the number of pages ! * available for each GP log identified by the ! * offset into the list. ! */ ! if ((softc->valid_logdir_len >= ! ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t))) ! && (le16dec(softc->ata_logdir.header) == ! ATA_GP_LOG_DIR_VERSION) ! && (le16dec(&softc->ata_logdir.num_pages[ ! (ATA_IDENTIFY_DATA_LOG * ! sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){ ! softc->flags |= ADA_FLAG_CAN_IDLOG; ! } else { ! softc->flags &= ~ADA_FLAG_CAN_IDLOG; ! } ! } else { ! error = adaerror(done_ccb, CAM_RETRY_SELTO, ! SF_RETRY_UA|SF_NO_PRINT); ! if (error == ERESTART) ! return; ! else if (error != 0) { ! /* ! * If we can't get the ATA log directory, ! * then ATA logs are effectively not ! * supported even if the bit is set in the ! * identify data. ! */ ! softc->flags &= ~(ADA_FLAG_CAN_LOG | ! ADA_FLAG_CAN_IDLOG); ! if ((done_ccb->ccb_h.status & ! CAM_DEV_QFRZN) != 0) { ! /* Don't wedge this device's queue */ ! cam_release_devq(done_ccb->ccb_h.path, ! /*relsim_flags*/0, ! /*reduction*/0, ! /*timeout*/0, ! /*getcount_only*/0); ! } ! } ! ! ! } ! ! free(ataio->data_ptr, M_ATADA); ! ! if ((error == 0) ! && (softc->flags & ADA_FLAG_CAN_IDLOG)) { ! softc->state = ADA_STATE_IDDIR; ! xpt_release_ccb(done_ccb); ! xpt_schedule(periph, priority); ! } else ! adaprobedone(periph, done_ccb); ! ! return; ! } ! case ADA_CCB_IDDIR: { ! int error; ! ! if ((ataio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { ! off_t entries_offset, max_entries; ! error = 0; ! ! softc->valid_iddir_len = 0; ! bzero(&softc->ata_iddir, sizeof(softc->ata_iddir)); ! softc->flags &= ~(ADA_FLAG_CAN_SUPCAP | ! ADA_FLAG_CAN_ZONE); ! softc->valid_iddir_len = ! ataio->dxfer_len - ataio->resid; ! if (softc->valid_iddir_len > 0) ! bcopy(ataio->data_ptr, &softc->ata_iddir, ! min(softc->valid_iddir_len, ! sizeof(softc->ata_iddir))); ! ! entries_offset = ! __offsetof(struct ata_identify_log_pages,entries); ! max_entries = softc->valid_iddir_len - entries_offset; ! if ((softc->valid_iddir_len > (entries_offset + 1)) ! && (le64dec(softc->ata_iddir.header) == ! ATA_IDLOG_REVISION) ! && (softc->ata_iddir.entry_count > 0)) { ! int num_entries, i; ! ! num_entries = softc->ata_iddir.entry_count; ! num_entries = min(num_entries, ! softc->valid_iddir_len - entries_offset); ! for (i = 0; i < num_entries && ! i < max_entries; i++) { ! if (softc->ata_iddir.entries[i] == ! ATA_IDL_SUP_CAP) ! softc->flags |= ! ADA_FLAG_CAN_SUPCAP; ! else if (softc->ata_iddir.entries[i]== ! ATA_IDL_ZDI) ! softc->flags |= ! ADA_FLAG_CAN_ZONE; ! ! if ((softc->flags & ! ADA_FLAG_CAN_SUPCAP) ! && (softc->flags & ! ADA_FLAG_CAN_ZONE)) ! break; ! } ! } ! } else { ! error = adaerror(done_ccb, CAM_RETRY_SELTO, ! SF_RETRY_UA|SF_NO_PRINT); ! if (error == ERESTART) ! return; ! else if (error != 0) { ! /* ! * If we can't get the ATA Identify Data log ! * directory, then it effectively isn't ! * supported even if the ATA Log directory ! * a non-zero number of pages present for ! * this log. ! */ ! softc->flags &= ~ADA_FLAG_CAN_IDLOG; ! if ((done_ccb->ccb_h.status & ! CAM_DEV_QFRZN) != 0) { ! /* Don't wedge this device's queue */ ! cam_release_devq(done_ccb->ccb_h.path, ! /*relsim_flags*/0, ! /*reduction*/0, ! /*timeout*/0, ! /*getcount_only*/0); ! } ! } ! } ! ! free(ataio->data_ptr, M_ATADA); ! ! if ((error == 0) ! && (softc->flags & ADA_FLAG_CAN_SUPCAP)) { ! softc->state = ADA_STATE_SUP_CAP; ! xpt_release_ccb(done_ccb); ! xpt_schedule(periph, priority); ! } else ! adaprobedone(periph, done_ccb); ! return; ! } ! case ADA_CCB_SUP_CAP: { ! int error; ! ! if ((ataio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { ! uint32_t valid_len; ! size_t needed_size; ! struct ata_identify_log_sup_cap *sup_cap; ! error = 0; ! ! sup_cap = (struct ata_identify_log_sup_cap *) ! ataio->data_ptr; ! valid_len = ataio->dxfer_len - ataio->resid; ! needed_size = ! __offsetof(struct ata_identify_log_sup_cap, ! sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap); ! if (valid_len >= needed_size) { ! uint64_t zoned, zac_cap; ! ! zoned = le64dec(sup_cap->zoned_cap); ! if (zoned & ATA_ZONED_VALID) { ! /* ! * This should have already been ! * set, because this is also in the ! * ATA identify data. ! */ ! if ((zoned & ATA_ZONED_MASK) == ! ATA_SUPPORT_ZONE_HOST_AWARE) ! softc->zone_mode = ! ADA_ZONE_HOST_AWARE; ! else if ((zoned & ATA_ZONED_MASK) == ! ATA_SUPPORT_ZONE_DEV_MANAGED) ! softc->zone_mode = ! ADA_ZONE_DRIVE_MANAGED; ! } ! ! zac_cap = le64dec(sup_cap->sup_zac_cap); ! if (zac_cap & ATA_SUP_ZAC_CAP_VALID) { ! if (zac_cap & ATA_REPORT_ZONES_SUP) ! softc->zone_flags |= ! ADA_ZONE_FLAG_RZ_SUP; ! if (zac_cap & ATA_ND_OPEN_ZONE_SUP) ! softc->zone_flags |= ! ADA_ZONE_FLAG_OPEN_SUP; ! if (zac_cap & ATA_ND_CLOSE_ZONE_SUP) ! softc->zone_flags |= ! ADA_ZONE_FLAG_CLOSE_SUP; ! if (zac_cap & ATA_ND_FINISH_ZONE_SUP) ! softc->zone_flags |= ! ADA_ZONE_FLAG_FINISH_SUP; ! if (zac_cap & ATA_ND_RWP_SUP) ! softc->zone_flags |= ! ADA_ZONE_FLAG_RWP_SUP; ! } else { ! /* ! * This field was introduced in ! * ACS-4, r08 on April 28th, 2015. ! * If the drive firmware was written ! * to an earlier spec, it won't have ! * the field. So, assume all ! * commands are supported. ! */ ! softc->zone_flags |= ! ADA_ZONE_FLAG_SUP_MASK; ! } ! ! } ! } else { ! error = adaerror(done_ccb, CAM_RETRY_SELTO, ! SF_RETRY_UA|SF_NO_PRINT); ! if (error == ERESTART) ! return; ! else if (error != 0) { ! /* ! * If we can't get the ATA Identify Data ! * Supported Capabilities page, clear the ! * flag... ! */ ! softc->flags &= ~ADA_FLAG_CAN_SUPCAP; ! /* ! * And clear zone capabilities. ! */ ! softc->zone_flags &= ~ADA_ZONE_FLAG_SUP_MASK; ! if ((done_ccb->ccb_h.status & ! CAM_DEV_QFRZN) != 0) { ! /* Don't wedge this device's queue */ ! cam_release_devq(done_ccb->ccb_h.path, ! /*relsim_flags*/0, ! /*reduction*/0, ! /*timeout*/0, ! /*getcount_only*/0); ! } ! } ! } ! ! free(ataio->data_ptr, M_ATADA); ! ! if ((error == 0) ! && (softc->flags & ADA_FLAG_CAN_ZONE)) { ! softc->state = ADA_STATE_ZONE; ! xpt_release_ccb(done_ccb); ! xpt_schedule(periph, priority); ! } else ! adaprobedone(periph, done_ccb); ! return; ! } ! case ADA_CCB_ZONE: { ! int error; ! ! if ((ataio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { ! struct ata_zoned_info_log *zi_log; ! uint32_t valid_len; ! size_t needed_size; ! ! zi_log = (struct ata_zoned_info_log *)ataio->data_ptr; ! ! valid_len = ataio->dxfer_len - ataio->resid; ! needed_size = __offsetof(struct ata_zoned_info_log, ! version_info) + 1 + sizeof(zi_log->version_info); ! if (valid_len >= needed_size) { ! uint64_t tmpvar; ! ! tmpvar = le64dec(zi_log->zoned_cap); ! if (tmpvar & ATA_ZDI_CAP_VALID) { ! if (tmpvar & ATA_ZDI_CAP_URSWRZ) ! softc->zone_flags |= ! ADA_ZONE_FLAG_URSWRZ; ! else ! softc->zone_flags &= ! ~ADA_ZONE_FLAG_URSWRZ; ! } ! tmpvar = le64dec(zi_log->optimal_seq_zones); ! if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) { ! softc->zone_flags |= ! ADA_ZONE_FLAG_OPT_SEQ_SET; ! softc->optimal_seq_zones = (tmpvar & ! ATA_ZDI_OPT_SEQ_MASK); ! } else { ! softc->zone_flags &= ! ~ADA_ZONE_FLAG_OPT_SEQ_SET; ! softc->optimal_seq_zones = 0; ! } ! ! tmpvar =le64dec(zi_log->optimal_nonseq_zones); ! if (tmpvar & ATA_ZDI_OPT_NS_VALID) { ! softc->zone_flags |= ! ADA_ZONE_FLAG_OPT_NONSEQ_SET; ! softc->optimal_nonseq_zones = ! (tmpvar & ATA_ZDI_OPT_NS_MASK); ! } else { ! softc->zone_flags &= ! ~ADA_ZONE_FLAG_OPT_NONSEQ_SET; ! softc->optimal_nonseq_zones = 0; ! } ! ! tmpvar = le64dec(zi_log->max_seq_req_zones); ! if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) { ! softc->zone_flags |= ! ADA_ZONE_FLAG_MAX_SEQ_SET; ! softc->max_seq_zones = ! (tmpvar & ATA_ZDI_MAX_SEQ_MASK); ! } else { ! softc->zone_flags &= ! ~ADA_ZONE_FLAG_MAX_SEQ_SET; ! softc->max_seq_zones = 0; ! } ! } ! } else { ! error = adaerror(done_ccb, CAM_RETRY_SELTO, ! SF_RETRY_UA|SF_NO_PRINT); ! if (error == ERESTART) ! return; ! else if (error != 0) { ! softc->flags &= ~ADA_FLAG_CAN_ZONE; ! softc->flags &= ~ADA_ZONE_FLAG_SET_MASK; ! ! if ((done_ccb->ccb_h.status & ! CAM_DEV_QFRZN) != 0) { ! /* Don't wedge this device's queue */ ! cam_release_devq(done_ccb->ccb_h.path, ! /*relsim_flags*/0, ! /*reduction*/0, ! /*timeout*/0, ! /*getcount_only*/0); ! } ! } ! ! } ! free(ataio->data_ptr, M_ATADA); ! ! adaprobedone(periph, done_ccb); return; } case ADA_CCB_DUMP: *** src/sys/cam/scsi/scsi_all.c.orig --- src/sys/cam/scsi/scsi_all.c *************** *** 502,510 **** /* 93 M ERASE(16) */ { 0x93, T, "ERASE(16)" }, /* 94 O ZBC OUT */ ! { 0x94, D, "ZBC OUT" }, /* 95 O ZBC OUT */ ! { 0x95, D, "ZBC OUT" }, /* 96 */ /* 97 */ /* 98 */ --- 502,510 ---- /* 93 M ERASE(16) */ { 0x93, T, "ERASE(16)" }, /* 94 O ZBC OUT */ ! { 0x94, ALL, "ZBC OUT" }, /* 95 O ZBC OUT */ ! { 0x95, ALL, "ZBC OUT" }, /* 96 */ /* 97 */ /* 98 */ *************** *** 520,526 **** /* XXX KDM ALL for this? op-num.txt defines it for none.. */ /* 9E SERVICE ACTION IN(16) */ { 0x9E, ALL, "SERVICE ACTION IN(16)" }, - /* XXX KDM ALL for this? op-num.txt defines it for ADC.. */ /* 9F M SERVICE ACTION OUT(16) */ { 0x9F, ALL, "SERVICE ACTION OUT(16)" }, /* A0 MMOOO OMMM OMO REPORT LUNS */ --- 520,525 ---- *************** *** 674,679 **** --- 673,684 ---- if (pd_type == T_RBC) pd_type = T_DIRECT; + /* + * Host managed drives are direct access for the most part. + */ + if (pd_type == T_ZBC_HM) + pd_type = T_DIRECT; + /* Map NODEVICE to Direct Access Device to handle REPORT LUNS, etc. */ if (pd_type == T_NODEVICE) pd_type = T_DIRECT; *************** *** 4250,4255 **** --- 4255,4261 ---- switch (SID_TYPE(inq_data)) { case T_DIRECT: case T_RBC: + case T_ZBC_HM: break; default: goto bailout; *************** *** 5400,5405 **** --- 5406,5414 ---- case T_ADC: dtype = "Automation/Drive Interface"; break; + case T_ZBC_HM: + dtype = "Host Managed Zoned Block"; + break; case T_NODEVICE: dtype = "Uninstalled"; break; *************** *** 8163,8174 **** } void scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int32_t flags, u_int8_t tag_action, u_int8_t protocol, u_int8_t ata_flags, u_int16_t features, u_int16_t sector_count, uint64_t lba, u_int8_t command, ! u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len, u_int32_t timeout) { struct ata_pass_16 *ata_cmd; --- 8172,8236 ---- } void + scsi_ata_read_log(struct ccb_scsiio *csio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint8_t tag_action, uint32_t log_address, + uint32_t page_number, uint16_t block_count, + uint8_t protocol, uint8_t *data_ptr, uint32_t dxfer_len, + uint8_t sense_len, uint32_t timeout) + { + uint8_t command, protocol_out; + uint16_t count_out; + uint64_t lba; + + switch (protocol) { + case AP_PROTO_DMA: + count_out = block_count; + command = ATA_READ_LOG_DMA_EXT; + protocol_out = AP_PROTO_DMA; + break; + case AP_PROTO_PIO_IN: + default: + count_out = block_count; + command = ATA_READ_LOG_EXT; + protocol_out = AP_PROTO_PIO_IN; + break; + } + + lba = (((uint64_t)page_number & 0xff00) << 32) | + ((page_number & 0x00ff) << 8) | + (log_address & 0xff); + + protocol_out |= AP_EXTEND; + + scsi_ata_pass_16(csio, + retries, + cbfcnp, + /*flags*/CAM_DIR_IN, + tag_action, + /*protocol*/ protocol_out, + /*ata_flags*/AP_FLAG_TLEN_SECT_CNT | + AP_FLAG_BYT_BLOK_BLOCKS | + AP_FLAG_TDIR_FROM_DEV, + /*features*/ 0, + /*sector_count*/ count_out, + /*lba*/ lba, + /*command*/ command, + /*control*/0, + data_ptr, + dxfer_len, + sense_len, + timeout); + + } + + void scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int32_t flags, u_int8_t tag_action, u_int8_t protocol, u_int8_t ata_flags, u_int16_t features, u_int16_t sector_count, uint64_t lba, u_int8_t command, ! u_int8_t control, u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, u_int32_t timeout) { struct ata_pass_16 *ata_cmd; *** src/sys/cam/scsi/scsi_all.h.orig --- src/sys/cam/scsi/scsi_all.h *************** *** 2064,2069 **** --- 2064,2070 ---- #define T_OCRW 0x0f #define T_OSD 0x11 #define T_ADC 0x12 + #define T_ZBC_HM 0x14 #define T_NODEVICE 0x1f #define T_ANY 0xff /* Used in Quirk table matches */ *************** *** 2710,2719 **** uint8_t flags; #define SVPD_VBULS 0x01 #define SVPD_FUAB 0x02 ! #define SVPD_HAW_ZBC 0x10 uint8_t reserved[55]; }; /* * Logical Block Provisioning VPD Page based on * T10/1799-D Revision 31 --- 2711,2727 ---- uint8_t flags; #define SVPD_VBULS 0x01 #define SVPD_FUAB 0x02 ! #define SVPD_ZBC_NR 0x00 /* Not Reported */ ! #define SVPD_HAW_ZBC 0x10 /* Host Aware */ ! #define SVPD_DM_ZBC 0x20 /* Drive Managed */ ! #define SVPD_ZBC_MASK 0x30 /* Zoned mask */ uint8_t reserved[55]; }; + #define SBDC_IS_PRESENT(bdc, length, field) \ + ((length >= offsetof(struct scsi_vpd_block_device_characteristics, \ + field) + sizeof(bdc->field)) ? 1 : 0) + /* * Logical Block Provisioning VPD Page based on * T10/1799-D Revision 31 *************** *** 2772,2777 **** --- 2780,2807 ---- u_int8_t max_atomic_boundary_size[4]; }; + /* + * Zoned Block Device Characacteristics VPD page. + * From ZBC-r04, dated August 12, 2015. + */ + struct scsi_vpd_zoned_bdc { + uint8_t device; + uint8_t page_code; + #define SVPD_ZONED_BDC 0xB6 + uint8_t page_length[2]; + #define SVPD_ZBDC_PL 0x3C + uint8_t flags; + #define SVPD_ZBDC_URSWRZ 0x01 + uint8_t reserved1[3]; + uint8_t optimal_seq_zones[4]; + #define SVPD_ZBDC_OPT_SEQ_NR 0xffffffff + uint8_t optimal_nonseq_zones[4]; + #define SVPD_ZBDC_OPT_NONSEQ_NR 0xffffffff + uint8_t max_seq_req_zones[4]; + #define SVPD_ZBDC_MAX_SEQ_UNLIMITED 0xffffffff + uint8_t reserved2[44]; + }; + struct scsi_read_capacity { u_int8_t opcode; *************** *** 3956,3967 **** u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len, u_int32_t timeout); void scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int32_t flags, u_int8_t tag_action, u_int8_t protocol, u_int8_t ata_flags, u_int16_t features, u_int16_t sector_count, uint64_t lba, u_int8_t command, ! u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len, u_int32_t timeout); void scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries, --- 3986,4004 ---- u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len, u_int32_t timeout); + void scsi_ata_read_log(struct ccb_scsiio *csio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint8_t tag_action, uint32_t log_address, + uint32_t page_number, uint16_t block_count, + uint8_t protocol, uint8_t *data_ptr, uint32_t dxfer_len, + uint8_t sense_len, uint32_t timeout); + void scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *), u_int32_t flags, u_int8_t tag_action, u_int8_t protocol, u_int8_t ata_flags, u_int16_t features, u_int16_t sector_count, uint64_t lba, u_int8_t command, ! u_int8_t control, u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, u_int32_t timeout); void scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries, *** src/sys/cam/scsi/scsi_da.c.orig --- src/sys/cam/scsi/scsi_da.c *************** *** 46,51 **** --- 46,52 ---- #include #include #include + #include #include #include #endif /* _KERNEL */ *************** *** 62,71 **** #include #include - - #ifndef _KERNEL #include - #endif /* !_KERNEL */ #ifdef _KERNEL typedef enum { --- 63,69 ---- *************** *** 75,97 **** DA_STATE_PROBE_BLK_LIMITS, DA_STATE_PROBE_BDC, DA_STATE_PROBE_ATA, DA_STATE_NORMAL } da_state; typedef enum { ! DA_FLAG_PACK_INVALID = 0x001, ! DA_FLAG_NEW_PACK = 0x002, ! DA_FLAG_PACK_LOCKED = 0x004, ! DA_FLAG_PACK_REMOVABLE = 0x008, ! DA_FLAG_NEED_OTAG = 0x020, ! DA_FLAG_WAS_OTAG = 0x040, ! DA_FLAG_RETRY_UA = 0x080, ! DA_FLAG_OPEN = 0x100, ! DA_FLAG_SCTX_INIT = 0x200, ! DA_FLAG_CAN_RC16 = 0x400, ! DA_FLAG_PROBED = 0x800, ! DA_FLAG_DIRTY = 0x1000, ! DA_FLAG_ANNOUNCED = 0x2000 } da_flags; typedef enum { --- 73,105 ---- DA_STATE_PROBE_BLK_LIMITS, DA_STATE_PROBE_BDC, DA_STATE_PROBE_ATA, + DA_STATE_PROBE_ATA_LOGDIR, + DA_STATE_PROBE_ATA_IDDIR, + DA_STATE_PROBE_ATA_SUP, + DA_STATE_PROBE_ATA_ZONE, + DA_STATE_PROBE_ZONE, DA_STATE_NORMAL } da_state; typedef enum { ! DA_FLAG_PACK_INVALID = 0x000001, ! DA_FLAG_NEW_PACK = 0x000002, ! DA_FLAG_PACK_LOCKED = 0x000004, ! DA_FLAG_PACK_REMOVABLE = 0x000008, ! DA_FLAG_NEED_OTAG = 0x000020, ! DA_FLAG_WAS_OTAG = 0x000040, ! DA_FLAG_RETRY_UA = 0x000080, ! DA_FLAG_OPEN = 0x000100, ! DA_FLAG_SCTX_INIT = 0x000200, ! DA_FLAG_CAN_RC16 = 0x000400, ! DA_FLAG_PROBED = 0x000800, ! DA_FLAG_DIRTY = 0x001000, ! DA_FLAG_ANNOUNCED = 0x002000, ! DA_FLAG_CAN_ATA_DMA = 0x004000, ! DA_FLAG_CAN_ATA_LOG = 0x008000, ! DA_FLAG_CAN_ATA_IDLOG = 0x010000, ! DA_FLAG_CAN_ATA_SUPCAP = 0x020000, ! DA_FLAG_CAN_ATA_ZONE = 0x040000 } da_flags; typedef enum { *************** *** 102,108 **** DA_Q_4K = 0x08, DA_Q_NO_RC16 = 0x10, DA_Q_NO_UNMAP = 0x20, ! DA_Q_RETRY_BUSY = 0x40 } da_quirks; #define DA_Q_BIT_STRING \ --- 110,117 ---- DA_Q_4K = 0x08, DA_Q_NO_RC16 = 0x10, DA_Q_NO_UNMAP = 0x20, ! DA_Q_RETRY_BUSY = 0x40, ! DA_Q_SMR_DM = 0x80 } da_quirks; #define DA_Q_BIT_STRING \ *************** *** 113,119 **** "\0044K" \ "\005NO_RC16" \ "\006NO_UNMAP" \ ! "\007RETRY_BUSY" typedef enum { DA_CCB_PROBE_RC = 0x01, --- 122,129 ---- "\0044K" \ "\005NO_RC16" \ "\006NO_UNMAP" \ ! "\007RETRY_BUSY" \ ! "\008SMR_DM" typedef enum { DA_CCB_PROBE_RC = 0x01, *************** *** 126,133 **** DA_CCB_DUMP = 0x0A, DA_CCB_DELETE = 0x0B, DA_CCB_TUR = 0x0C, ! DA_CCB_TYPE_MASK = 0x0F, ! DA_CCB_RETRY_UA = 0x10 } da_ccb_state; /* --- 136,148 ---- DA_CCB_DUMP = 0x0A, DA_CCB_DELETE = 0x0B, DA_CCB_TUR = 0x0C, ! DA_CCB_PROBE_ZONE = 0x0D, ! DA_CCB_PROBE_ATA_LOGDIR = 0x0E, ! DA_CCB_PROBE_ATA_IDDIR = 0x0F, ! DA_CCB_PROBE_ATA_SUP = 0x10, ! DA_CCB_PROBE_ATA_ZONE = 0x11, ! DA_CCB_TYPE_MASK = 0x1F, ! DA_CCB_RETRY_UA = 0x20 } da_ccb_state; /* *************** *** 151,156 **** --- 166,229 ---- DA_DELETE_MAX = DA_DELETE_ZERO } da_delete_methods; + /* + * For SCSI, host managed drives show up as a separate device type. For + * ATA, host managed drives also have a different device signature. + * XXX KDM figure out the ATA host managed signature. + */ + typedef enum { + DA_ZONE_NONE = 0x00, + DA_ZONE_DRIVE_MANAGED = 0x01, + DA_ZONE_HOST_AWARE = 0x02, + DA_ZONE_HOST_MANAGED = 0x03 + } da_zone_mode; + + /* + * XXX KDM we need to distinguish between these interface cases in addition + * to the drive type: + * o ATA drive behind a SCSI translation layer that knows about ZBC/ZAC + * o ATA drive behind a SCSI translation layer that does not know about + * ZBC/ZAC, and so needs to be managed via ATA passthrough. In this + * case, we would need to share the ATA code with the ada(4) driver. + * o SCSI drive. + */ + typedef enum { + DA_ZONE_IF_SCSI, + DA_ZONE_IF_ATA_PASS, + DA_ZONE_IF_ATA_SAT, + } da_zone_interface; + + typedef enum { + DA_ZONE_FLAG_RZ_SUP = 0x0001, + DA_ZONE_FLAG_OPEN_SUP = 0x0002, + DA_ZONE_FLAG_CLOSE_SUP = 0x0004, + DA_ZONE_FLAG_FINISH_SUP = 0x0008, + DA_ZONE_FLAG_RWP_SUP = 0x0010, + DA_ZONE_FLAG_SUP_MASK = (DA_ZONE_FLAG_RZ_SUP | + DA_ZONE_FLAG_OPEN_SUP | + DA_ZONE_FLAG_CLOSE_SUP | + DA_ZONE_FLAG_FINISH_SUP | + DA_ZONE_FLAG_RWP_SUP), + DA_ZONE_FLAG_URSWRZ = 0x0020, + DA_ZONE_FLAG_OPT_SEQ_SET = 0x0040, + DA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080, + DA_ZONE_FLAG_MAX_SEQ_SET = 0x0100, + DA_ZONE_FLAG_SET_MASK = (DA_ZONE_FLAG_OPT_SEQ_SET | + DA_ZONE_FLAG_OPT_NONSEQ_SET | + DA_ZONE_FLAG_MAX_SEQ_SET) + } da_zone_flags; + + static struct da_zone_desc { + da_zone_flags value; + const char *desc; + } da_zone_desc_table[] = { + {DA_ZONE_FLAG_RZ_SUP, "Report Zones" }, + {DA_ZONE_FLAG_OPEN_SUP, "Open" }, + {DA_ZONE_FLAG_CLOSE_SUP, "Close" }, + {DA_ZONE_FLAG_FINISH_SUP, "Finish" }, + {DA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" }, + }; + typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb, struct bio *bp); static da_delete_func_t da_delete_trim; *************** *** 215,221 **** int trim_max_ranges; int delete_running; int delete_available; /* Delete methods possibly available */ ! u_int maxio; uint32_t unmap_max_ranges; uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */ uint64_t ws_max_blks; --- 288,304 ---- int trim_max_ranges; int delete_running; int delete_available; /* Delete methods possibly available */ ! da_zone_mode zone_mode; ! da_zone_interface zone_interface; ! da_zone_flags zone_flags; ! struct ata_gp_log_dir ata_logdir; ! int valid_logdir_len; ! struct ata_identify_log_pages ata_iddir; ! int valid_iddir_len; ! uint64_t optimal_seq_zones; ! uint64_t optimal_nonseq_zones; ! uint64_t max_seq_zones; ! u_int maxio; uint32_t unmap_max_ranges; uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */ uint64_t ws_max_blks; *************** *** 1185,1190 **** --- 1268,1282 ---- }, { /* + * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR) + * Drive Managed SATA hard drive. This drive doesn't report + * in firmware that it is a drive managed SMR drive. + */ + { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS0002*", "*" }, + /*quirks*/DA_Q_SMR_DM + }, + { + /* * MX-ES USB Drive by Mach Xtreme */ { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"}, *************** *** 1200,1205 **** --- 1292,1299 ---- static void dasysctlinit(void *context, int pending); static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS); static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS); + static int dazonemodesysctl(SYSCTL_HANDLER_ARGS); + static int dazonesupsysctl(SYSCTL_HANDLER_ARGS); static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS); static void dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method); *************** *** 1213,1218 **** --- 1307,1313 ---- static periph_dtor_t dacleanup; static periph_start_t dastart; static periph_oninv_t daoninvalidate; + static void dazonedone(struct cam_periph *periph, union ccb *ccb); static void dadone(struct cam_periph *periph, union ccb *done_ccb); static int daerror(union ccb *ccb, u_int32_t cam_flags, *************** *** 1445,1450 **** --- 1540,1553 ---- CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp)); /* + * Zone commands must be ordered, because they can depend on the + * effects of previously issued commands, and they may affect + * commands after them. + */ + if (bp->bio_cmd == BIO_ZONE) + bp->bio_flags |= BIO_ORDERED; + + /* * Place it in the queue of disk activities for this disk */ if (bp->bio_cmd == BIO_DELETE) { *************** *** 1672,1678 **** break; if (SID_TYPE(&cgd->inq_data) != T_DIRECT && SID_TYPE(&cgd->inq_data) != T_RBC ! && SID_TYPE(&cgd->inq_data) != T_OPTICAL) break; /* --- 1775,1782 ---- break; if (SID_TYPE(&cgd->inq_data) != T_DIRECT && SID_TYPE(&cgd->inq_data) != T_RBC ! && SID_TYPE(&cgd->inq_data) != T_OPTICAL ! && SID_TYPE(&cgd->inq_data) != T_ZBC_HM) break; /* *************** *** 1821,1826 **** --- 1925,1953 ---- OID_AUTO, "sort_io_queue", CTLFLAG_RW, &softc->sort_io_queue, 0, "Sort IO queue to try and optimise disk access patterns"); + SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), + OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD, + softc, 0, dazonemodesysctl, "A", + "Zone Mode"); + SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), + OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD, + softc, 0, dazonesupsysctl, "A", + "Zone Support"); + SYSCTL_ADD_UQUAD(&softc->sysctl_ctx, + SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, + "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones, + "Optimal Number of Open Sequential Write Preferred Zones"); + SYSCTL_ADD_UQUAD(&softc->sysctl_ctx, + SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, + "optimal_nonseq_zones", CTLFLAG_RD, + &softc->optimal_nonseq_zones, + "Optimal Number of Non-Sequentially Written Sequential Write " + "Preferred Zones"); + SYSCTL_ADD_UQUAD(&softc->sysctl_ctx, + SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, + "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones, + "Maximum Number of Open Sequential Write Required Zones"); + SYSCTL_ADD_INT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, *************** *** 2064,2069 **** --- 2191,2262 ---- return (0); } + static int + dazonemodesysctl(SYSCTL_HANDLER_ARGS) + { + char tmpbuf[40]; + struct da_softc *softc; + int error; + + softc = (struct da_softc *)arg1; + + switch (softc->zone_mode) { + case DA_ZONE_DRIVE_MANAGED: + snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed"); + break; + case DA_ZONE_HOST_AWARE: + snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware"); + break; + case DA_ZONE_HOST_MANAGED: + snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed"); + break; + case DA_ZONE_NONE: + default: + snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned"); + break; + } + + error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req); + + return (error); + } + + static int + dazonesupsysctl(SYSCTL_HANDLER_ARGS) + { + char tmpbuf[180]; + struct da_softc *softc; + struct sbuf sb; + int error, first; + unsigned int i; + + softc = (struct da_softc *)arg1; + + error = 0; + first = 1; + sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0); + + for (i = 0; i < sizeof(da_zone_desc_table) / + sizeof(da_zone_desc_table[0]); i++) { + if (softc->zone_flags & da_zone_desc_table[i].value) { + if (first == 0) + sbuf_printf(&sb, ", "); + else + first = 0; + sbuf_cat(&sb, da_zone_desc_table[i].desc); + } + } + + if (first == 1) + sbuf_printf(&sb, "None"); + + sbuf_finish(&sb); + + error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req); + + return (error); + } + static cam_status daregister(struct cam_periph *periph, void *arg) { *************** *** 2124,2129 **** --- 2317,2329 ---- if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE)) softc->quirks |= DA_Q_NO_6_BYTE; + if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM) + softc->zone_mode = DA_ZONE_HOST_MANAGED; + else if (softc->quirks & DA_Q_SMR_DM) + softc->zone_mode = DA_ZONE_DRIVE_MANAGED; + else + softc->zone_mode = DA_ZONE_NONE; + TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph); /* *************** *** 2205,2211 **** softc->maxio = cpi.maxio; softc->disk->d_maxsize = softc->maxio; softc->disk->d_unit = periph->unit_number; ! softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION; if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE; if ((cpi.hba_misc & PIM_UNMAPPED) != 0) --- 2405,2411 ---- softc->maxio = cpi.maxio; softc->disk->d_maxsize = softc->maxio; softc->disk->d_unit = periph->unit_number; ! softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE; if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE; if ((cpi.hba_misc & PIM_UNMAPPED) != 0) *************** *** 2270,2275 **** --- 2470,2707 ---- return(CAM_REQ_CMP); } + static int + da_zone_bio_to_scsi(int disk_zone_cmd) + { + switch (disk_zone_cmd) { + case DISK_ZONE_OPEN: + return ZBC_OUT_SA_OPEN; + case DISK_ZONE_CLOSE: + return ZBC_OUT_SA_CLOSE; + case DISK_ZONE_FINISH: + return ZBC_OUT_SA_FINISH; + case DISK_ZONE_RWP: + return ZBC_OUT_SA_RWP; + } + + return -1; + } + + static int + da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp, + int *queue_ccb) + { + struct da_softc *softc; + int error; + + error = 0; + + if (bp->bio_cmd != BIO_ZONE) { + error = EINVAL; + goto bailout; + } + + softc = periph->softc; + + switch (bp->bio_zone.zone_cmd) { + case DISK_ZONE_OPEN: + case DISK_ZONE_CLOSE: + case DISK_ZONE_FINISH: + case DISK_ZONE_RWP: { + int zone_flags; + int zone_sa; + uint64_t lba; + + zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd); + if (zone_sa == -1) { + xpt_print(periph->path, "Cannot translate zone " + "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd); + error = EINVAL; + goto bailout; + } + + zone_flags = 0; + lba = bp->bio_zone.zone_params.rwp.id; + + if (bp->bio_zone.zone_params.rwp.flags & + DISK_ZONE_RWP_FLAG_ALL) + zone_flags |= ZBC_OUT_ALL; + + if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) { + scsi_zbc_out(&ccb->csio, + /*retries*/ da_retry_count, + /*cbfcnp*/ dadone, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*service_action*/ zone_sa, + /*zone_id*/ lba, + /*zone_flags*/ zone_flags, + /*data_ptr*/ NULL, + /*dxfer_len*/ 0, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ da_default_timeout * 1000); + } else { + scsi_ata_zac_mgmt_out(&ccb->csio, + /*retries*/ da_retry_count, + /*cbfcnp*/ dadone, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*use_ncq*/ 0, + /*zm_action*/ zone_sa, + /*zone_id*/ lba, + /*zone_flags*/ zone_flags, + /*data_ptr*/ NULL, + /*dxfer_len*/ 0, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ + da_default_timeout * 1000); + } + *queue_ccb = 1; + + break; + } + case DISK_ZONE_REPORT_ZONES: { + uint8_t *rz_ptr; + uint32_t num_entries, alloc_size; + struct disk_zone_report *rep; + + rep = &bp->bio_zone.zone_params.report; + + num_entries = rep->entries_allocated; + if (num_entries == 0) { + xpt_print(periph->path, "No entries allocated for " + "Report Zones request\n"); + error = EINVAL; + goto bailout; + } + alloc_size = sizeof(struct scsi_report_zones_hdr) + + (sizeof(struct scsi_report_zones_desc) * num_entries); + rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO); + if (rz_ptr == NULL) { + xpt_print(periph->path, "Unable to allocate memory " + "for Report Zones request\n"); + error = ENOMEM; + goto bailout; + } + + if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) { + scsi_zbc_in(&ccb->csio, + /*retries*/ da_retry_count, + /*cbcfnp*/ dadone, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*service_action*/ ZBC_IN_SA_REPORT_ZONES, + /*zone_start_lba*/ rep->starting_id, + /*zone_options*/ rep->rep_options, + /*data_ptr*/ rz_ptr, + /*dxfer_len*/ alloc_size, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ da_default_timeout * 1000); + } else { + scsi_ata_zac_mgmt_in(&ccb->csio, + /*retries*/ da_retry_count, + /*cbcfnp*/ dadone, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*use_ncq*/ 0, + /*zm_action*/ ATA_ZM_REPORT_ZONES, + /*zone_id*/ rep->starting_id, + /*zone_flags*/ rep->rep_options, + /*data_ptr*/ rz_ptr, + /*dxfer_len*/ alloc_size, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ da_default_timeout * 1000); + } + + /* + * For BIO_ZONE, this isn't normally needed. However, it + * is used by devstat_end_transaction_bio() to determine + * how much data was transferred. + */ + /* + * XXX KDM we have a problem. But I'm not sure how to fix + * it. devstat uses bio_bcount - bio_resid to calculate + * the amount of data transferred. The GEOM disk code + * uses bio_length - bio_resid to calculate the amount of + * data in bio_completed. We have different structure + * sizes above and below the ada(4) driver. So, if we + * use the sizes above, the amount transferred won't be + * quite accurate for devstat. If we use different sizes + * for bio_bcount and bio_length (above and below + * respectively), then the residual needs to match one or + * the other. Everything is calculated after the bio + * leaves the driver, so changing the values around isn't + * really an option. For now, just set the count to the + * passed in length. This means that the calculations + * above (e.g. bio_completed) will be correct, but the + * amount of data reported to devstat will be slightly + * under or overstated. + */ + bp->bio_bcount = bp->bio_length; + + *queue_ccb = 1; + + break; + } + case DISK_ZONE_GET_PARAMS: { + struct disk_zone_disk_params *params; + + params = &bp->bio_zone.zone_params.disk_params; + bzero(params, sizeof(*params)); + + switch (softc->zone_mode) { + case DA_ZONE_DRIVE_MANAGED: + params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED; + break; + case DA_ZONE_HOST_AWARE: + params->zone_mode = DISK_ZONE_MODE_HOST_AWARE; + break; + case DA_ZONE_HOST_MANAGED: + params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED; + break; + default: + case DA_ZONE_NONE: + params->zone_mode = DISK_ZONE_MODE_NONE; + break; + } + + if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ) + params->flags |= DISK_ZONE_DISK_URSWRZ; + + if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) { + params->optimal_seq_zones = softc->optimal_seq_zones; + params->flags |= DISK_ZONE_OPT_SEQ_SET; + } + + if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) { + params->optimal_nonseq_zones = + softc->optimal_nonseq_zones; + params->flags |= DISK_ZONE_OPT_NONSEQ_SET; + } + + if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) { + params->max_seq_zones = softc->max_seq_zones; + params->flags |= DISK_ZONE_MAX_SEQ_SET; + } + if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP) + params->flags |= DISK_ZONE_RZ_SUP; + + if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP) + params->flags |= DISK_ZONE_OPEN_SUP; + + if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP) + params->flags |= DISK_ZONE_CLOSE_SUP; + + if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP) + params->flags |= DISK_ZONE_FINISH_SUP; + + if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP) + params->flags |= DISK_ZONE_RWP_SUP; + break; + } + default: + break; + } + bailout: + return (error); + } + static void dastart(struct cam_periph *periph, union ccb *start_ccb) { *************** *** 2383,2389 **** --- 2815,2835 ---- SSD_FULL_SIZE, da_default_timeout*1000); break; + case BIO_ZONE: { + int error, queue_ccb; + + queue_ccb = 0; + + error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb); + if ((error != 0) + || (queue_ccb == 0)) { + biofinish(bp, NULL, error); + xpt_release_ccb(start_ccb); + return; + } + break; } + } start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO; start_ccb->ccb_h.flags |= CAM_UNLOCKED; *************** *** 2572,2586 **** struct ata_params *ata_params; if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) { daprobedone(periph, start_ccb); break; } ata_params = (struct ata_params*) ! malloc(sizeof(*ata_params), M_SCSIDA, M_NOWAIT|M_ZERO); if (ata_params == NULL) { ! printf("dastart: Couldn't malloc ata_params data\n"); /* da_free_periph??? */ break; } --- 3018,3045 ---- struct ata_params *ata_params; if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) { + if ((softc->zone_mode == DA_ZONE_HOST_AWARE) + || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) { + /* + * Note that if the ATA VPD page isn't + * supported, we aren't talking to an ATA + * device anyway. Support for that VPD + * page is mandatory for SCSI to ATA (SAT) + * translation layers. + */ + softc->state = DA_STATE_PROBE_ZONE; + goto skipstate; + } daprobedone(periph, start_ccb); break; } ata_params = (struct ata_params*) ! malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO); if (ata_params == NULL) { ! xpt_print(periph->path, "Couldn't malloc ata_params " ! "data\n"); /* da_free_periph??? */ break; } *************** *** 2598,2603 **** --- 3057,3262 ---- xpt_action(start_ccb); break; } + case DA_STATE_PROBE_ATA_LOGDIR: + { + struct ata_gp_log_dir *log_dir; + + if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) { + /* + * If we don't have log support, not much point in + * trying to probe zone support. + */ + daprobedone(periph, start_ccb); + break; + } + + /* + * If we have an ATA device (the SCSI ATA Information VPD + * page should be present and the ATA identify should have + * succeeded) and it supports logs, ask for the log directory. + */ + + log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO); + if (log_dir == NULL) { + xpt_print(periph->path, "Couldn't malloc log_dir " + "data\n"); + /* da_free_periph??? */ + break; + } + + scsi_ata_read_log(&start_ccb->csio, + /*retries*/ da_retry_count, + /*cbfcnp*/ dadone, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*log_address*/ ATA_LOG_DIRECTORY, + /*page_number*/ 0, + /*block_count*/ 1, + /*protocol*/ softc->flags & + DA_FLAG_CAN_ATA_DMA ? + AP_PROTO_DMA : AP_PROTO_PIO_IN, + /*data_ptr*/ (uint8_t *)log_dir, + /*dxfer_len*/ sizeof(*log_dir), + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ da_default_timeout * 1000); + start_ccb->ccb_h.ccb_bp = NULL; + start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR; + xpt_action(start_ccb); + break; + } + case DA_STATE_PROBE_ATA_IDDIR: + { + struct ata_identify_log_pages *id_dir; + + /* + * Check here to see whether the Identify Device log is + * supported in the directory of logs. If so, continue + * with requesting the log of identify device pages. + */ + if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) { + daprobedone(periph, start_ccb); + break; + } + + id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO); + if (id_dir == NULL) { + xpt_print(periph->path, "Couldn't malloc id_dir " + "data\n"); + /* da_free_periph??? */ + break; + } + + scsi_ata_read_log(&start_ccb->csio, + /*retries*/ da_retry_count, + /*cbfcnp*/ dadone, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*log_address*/ ATA_IDENTIFY_DATA_LOG, + /*page_number*/ ATA_IDL_PAGE_LIST, + /*block_count*/ 1, + /*protocol*/ softc->flags & + DA_FLAG_CAN_ATA_DMA ? + AP_PROTO_DMA : AP_PROTO_PIO_IN, + /*data_ptr*/ (uint8_t *)id_dir, + /*dxfer_len*/ sizeof(*id_dir), + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ da_default_timeout * 1000); + start_ccb->ccb_h.ccb_bp = NULL; + start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR; + xpt_action(start_ccb); + break; + } + case DA_STATE_PROBE_ATA_SUP: + { + struct ata_identify_log_sup_cap *sup_cap; + + /* + * Check here to see whether the Supported Capabilities log + * is in the list of Identify Device logs. + */ + if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) { + daprobedone(periph, start_ccb); + break; + } + + sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO); + if (sup_cap == NULL) { + xpt_print(periph->path, "Couldn't malloc sup_cap " + "data\n"); + /* da_free_periph??? */ + break; + } + + scsi_ata_read_log(&start_ccb->csio, + /*retries*/ da_retry_count, + /*cbfcnp*/ dadone, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*log_address*/ ATA_IDENTIFY_DATA_LOG, + /*page_number*/ ATA_IDL_SUP_CAP, + /*block_count*/ 1, + /*protocol*/ softc->flags & + DA_FLAG_CAN_ATA_DMA ? + AP_PROTO_DMA : AP_PROTO_PIO_IN, + /*data_ptr*/ (uint8_t *)sup_cap, + /*dxfer_len*/ sizeof(*sup_cap), + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ da_default_timeout * 1000); + start_ccb->ccb_h.ccb_bp = NULL; + start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP; + xpt_action(start_ccb); + break; + } + case DA_STATE_PROBE_ATA_ZONE: + { + struct ata_zoned_info_log *ata_zone; + + /* + * Check here to see whether the zoned device information + * page is supported. If so, continue on to request it. + */ + if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) { + daprobedone(periph, start_ccb); + break; + } + ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA, + M_NOWAIT|M_ZERO); + if (ata_zone == NULL) { + xpt_print(periph->path, "Couldn't malloc ata_zone " + "data\n"); + /* da_free_periph??? */ + break; + } + + scsi_ata_read_log(&start_ccb->csio, + /*retries*/ da_retry_count, + /*cbfcnp*/ dadone, + /*tag_action*/ MSG_SIMPLE_Q_TAG, + /*log_address*/ ATA_IDENTIFY_DATA_LOG, + /*page_number*/ ATA_IDL_ZDI, + /*block_count*/ 1, + /*protocol*/ softc->flags & + DA_FLAG_CAN_ATA_DMA ? + AP_PROTO_DMA : AP_PROTO_PIO_IN, + /*data_ptr*/ (uint8_t *)ata_zone, + /*dxfer_len*/ sizeof(*ata_zone), + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ da_default_timeout * 1000); + start_ccb->ccb_h.ccb_bp = NULL; + start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE; + xpt_action(start_ccb); + + break; + } + case DA_STATE_PROBE_ZONE: + { + struct scsi_vpd_zoned_bdc *bdc; + + if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) { + daprobedone(periph, start_ccb); + break; + } + bdc = (struct scsi_vpd_zoned_bdc *) + malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO); + + if (bdc == NULL) { + xpt_release_ccb(start_ccb); + xpt_print(periph->path, "Couldn't malloc zone VPD " + "data\n"); + break; + } + scsi_inquiry(&start_ccb->csio, + /*retries*/da_retry_count, + /*cbfcnp*/dadone, + /*tag_action*/MSG_SIMPLE_Q_TAG, + /*inq_buf*/(u_int8_t *)bdc, + /*inq_len*/sizeof(*bdc), + /*evpd*/TRUE, + /*page_code*/SVPD_ZONED_BDC, + /*sense_len*/SSD_FULL_SIZE, + /*timeout*/da_default_timeout * 1000); + start_ccb->ccb_h.ccb_bp = NULL; + start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE; + xpt_action(start_ccb); + break; + } } } *************** *** 2943,2948 **** --- 3602,3754 ---- } static void + dazonedone(struct cam_periph *periph, union ccb *ccb) + { + struct da_softc *softc; + struct bio *bp; + + softc = periph->softc; + bp = (struct bio *)ccb->ccb_h.ccb_bp; + + switch (bp->bio_zone.zone_cmd) { + case DISK_ZONE_OPEN: + case DISK_ZONE_CLOSE: + case DISK_ZONE_FINISH: + case DISK_ZONE_RWP: + break; + case DISK_ZONE_REPORT_ZONES: { + uint32_t avail_len; + struct disk_zone_report *rep; + struct scsi_report_zones_hdr *hdr; + struct scsi_report_zones_desc *desc; + struct disk_zone_rep_entry *entry; + uint32_t num_alloced, hdr_len, num_avail; + uint32_t num_to_fill, i; + int ata; + + rep = &bp->bio_zone.zone_params.report; + avail_len = ccb->csio.dxfer_len - ccb->csio.resid; + /* + * Note that bio_resid isn't normally used for zone + * commands, but it is used by devstat_end_transaction_bio() + * to determine how much data was transferred. Because + * the size of the SCSI/ATA data structures is different + * than the size of the BIO interface structures, the + * amount of data actually transferred from the drive will + * be different than the amount of data transferred to + * the user. + */ + bp->bio_resid = ccb->csio.resid; + num_alloced = rep->entries_allocated; + hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr; + if (avail_len < sizeof(*hdr)) { + /* + * Is there a better error than EIO here? We asked + * for at least the header, and we got less than + * that. + */ + bp->bio_error = EIO; + bp->bio_flags |= BIO_ERROR; + bp->bio_resid = bp->bio_bcount; + break; + } + + if (softc->zone_interface == DA_ZONE_IF_ATA_PASS) + ata = 1; + else + ata = 0; + + hdr_len = ata ? le32dec(hdr->length) : + scsi_4btoul(hdr->length); + if (hdr_len > 0) + rep->entries_available = hdr_len / sizeof(*desc); + else + rep->entries_available = 0; + /* + * NOTE: using the same values for the BIO version of the + * same field as the SCSI/ATA values. This means we could + * get some additional values that aren't defined in bio.h + * if more values of the same field are defined later. + */ + rep->header.same = hdr->byte4 & SRZ_SAME_MASK; + rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) : + scsi_8btou64(hdr->maximum_lba); + /* + * If the drive reports no entries that match the query, + * we're done. + */ + if (hdr_len == 0) { + rep->entries_filled = 0; + break; + } + + num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc), + hdr_len / sizeof(*desc)); + /* + * If the drive didn't return any data, then we're done. + */ + if (num_avail == 0) { + rep->entries_filled = 0; + break; + } + + num_to_fill = min(num_avail, rep->entries_allocated); + /* + * If the user didn't allocate any entries for us to fill, + * we're done. + */ + if (num_to_fill == 0) { + rep->entries_filled = 0; + break; + } + + for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0]; + i < num_to_fill; i++, desc++, entry++) { + /* + * NOTE: we're mapping the values here directly + * from the SCSI/ATA bit definitions to the bio.h + * definitons. There is also a warning in + * disk_zone.h, but the impact is that if + * additional values are added in the SCSI/ATA + * specs these will be visible to consumers of + * this interface. + */ + entry->zone_type = desc->zone_type & SRZ_TYPE_MASK; + entry->zone_condition = + (desc->zone_flags & SRZ_ZONE_COND_MASK) >> + SRZ_ZONE_COND_SHIFT; + entry->zone_flags |= desc->zone_flags & + (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET); + entry->zone_length = + ata ? le64dec(desc->zone_length) : + scsi_8btou64(desc->zone_length); + entry->zone_start_lba = + ata ? le64dec(desc->zone_start_lba) : + scsi_8btou64(desc->zone_start_lba); + entry->write_pointer_lba = + ata ? le64dec(desc->write_pointer_lba) : + scsi_8btou64(desc->write_pointer_lba); + } + rep->entries_filled = num_to_fill; + break; + } + case DISK_ZONE_GET_PARAMS: + default: + /* + * In theory we should not get a GET_PARAMS bio, since it + * should be handled without queueing the command to the + * drive. + */ + panic("%s: Invalid zone command %d", __func__, + bp->bio_zone.zone_cmd); + break; + } + + if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES) + free(ccb->csio.data_ptr, M_SCSIDA); + } + + static void dadone(struct cam_periph *periph, union ccb *done_ccb) { struct da_softc *softc; *************** *** 3034,3044 **** } else if (bp != NULL) { if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) panic("REQ_CMP with QFRZN"); ! if (state == DA_CCB_DELETE) bp->bio_resid = 0; else bp->bio_resid = csio->resid; ! if (csio->resid > 0) bp->bio_flags |= BIO_ERROR; if (softc->error_inject != 0) { bp->bio_error = softc->error_inject; --- 3840,3853 ---- } else if (bp != NULL) { if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) panic("REQ_CMP with QFRZN"); ! if (bp->bio_cmd == BIO_ZONE) ! dazonedone(periph, done_ccb); ! else if (state == DA_CCB_DELETE) bp->bio_resid = 0; else bp->bio_resid = csio->resid; ! if ((csio->resid > 0) ! && (bp->bio_cmd != BIO_ZONE)) bp->bio_flags |= BIO_ERROR; if (softc->error_inject != 0) { bp->bio_error = softc->error_inject; *************** *** 3455,3480 **** } case DA_CCB_PROBE_BDC: { ! struct scsi_vpd_block_characteristics *bdc; ! bdc = (struct scsi_vpd_block_characteristics *)csio->data_ptr; if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { /* * Disable queue sorting for non-rotational media * by default. */ u_int16_t old_rate = softc->disk->d_rotation_rate; ! softc->disk->d_rotation_rate = ! scsi_2btoul(bdc->medium_rotation_rate); ! if (softc->disk->d_rotation_rate == ! SVPD_BDC_RATE_NON_ROTATING) { ! softc->sort_io_queue = 0; } ! if (softc->disk->d_rotation_rate != old_rate) { ! disk_attr_changed(softc->disk, ! "GEOM::rotation_rate", M_NOWAIT); } } else { int error; --- 4264,4319 ---- } case DA_CCB_PROBE_BDC: { ! struct scsi_vpd_block_device_characteristics *bdc; ! bdc = (struct scsi_vpd_block_device_characteristics *) ! csio->data_ptr; if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { + uint32_t valid_len; + /* * Disable queue sorting for non-rotational media * by default. */ u_int16_t old_rate = softc->disk->d_rotation_rate; ! valid_len = csio->dxfer_len - csio->resid; ! if (SBDC_IS_PRESENT(bdc, valid_len, ! medium_rotation_rate)) { ! softc->disk->d_rotation_rate = ! scsi_2btoul(bdc->medium_rotation_rate); ! if (softc->disk->d_rotation_rate == ! SVPD_BDC_RATE_NON_ROTATING) { ! softc->sort_io_queue = 0; ! } ! if (softc->disk->d_rotation_rate != old_rate) { ! disk_attr_changed(softc->disk, ! "GEOM::rotation_rate", M_NOWAIT); ! } } ! if (SBDC_IS_PRESENT(bdc, valid_len, flags)) { ! /* ! * The Zoned field will only be set for ! * Drive Managed and Host Aware drives. If ! * they are Host Managed, the device type ! * in the standard INQUIRY data should be ! * set to T_ZBC_HM (0x14). ! */ ! if ((bdc->flags & SVPD_ZBC_MASK) == ! SVPD_HAW_ZBC) { ! softc->zone_mode = DA_ZONE_HOST_AWARE; ! softc->zone_interface = DA_ZONE_IF_SCSI; ! } else if ((bdc->flags & SVPD_ZBC_MASK) == ! SVPD_DM_ZBC) { ! softc->zone_mode =DA_ZONE_DRIVE_MANAGED; ! softc->zone_interface = DA_ZONE_IF_SCSI; ! } else if ((bdc->flags & SVPD_ZBC_MASK) != ! SVPD_ZBC_NR) { ! xpt_print(periph->path, "Unknown zoned " ! "type %#x", ! bdc->flags & SVPD_ZBC_MASK); ! } } } else { int error; *************** *** 3504,3513 **** --- 4343,4356 ---- { int i; struct ata_params *ata_params; + int continue_probe; + int error; int16_t *ptr; ata_params = (struct ata_params *)csio->data_ptr; ptr = (uint16_t *)ata_params; + continue_probe = 0; + error = 0; if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { uint16_t old_rate; *************** *** 3539,3552 **** disk_attr_changed(softc->disk, "GEOM::rotation_rate", M_NOWAIT); } } else { - int error; error = daerror(done_ccb, CAM_RETRY_SELTO, SF_RETRY_UA|SF_NO_PRINT); if (error == ERESTART) return; else if (error != 0) { ! if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { /* Don't wedge this device's queue */ cam_release_devq(done_ccb->ccb_h.path, /*relsim_flags*/0, --- 4382,4426 ---- disk_attr_changed(softc->disk, "GEOM::rotation_rate", M_NOWAIT); } + + if (ata_params->capabilities1 & ATA_SUPPORT_DMA) + softc->flags |= DA_FLAG_CAN_ATA_DMA; + + if (ata_params->support.extension & + ATA_SUPPORT_GENLOG) + softc->flags |= DA_FLAG_CAN_ATA_LOG; + + /* + * At this point, if we have a SATA host aware drive, + * we default to communicating via ATA passthrough. + * Once the SAT spec and implementations catch up + * with Zoned device support, we can probe for + * zoned support in the SAT layer and use that + * instead of ATA passthrough. + */ + /* + * XXX KDM figure out how to detect a host managed + * SATA drive. + */ + if ((ata_params->support3 & ATA_SUPPORT_ZONE_MASK) == + ATA_SUPPORT_ZONE_HOST_AWARE) { + softc->zone_mode = DA_ZONE_HOST_AWARE; + softc->zone_interface = DA_ZONE_IF_ATA_PASS; + } else if ((ata_params->support3 & + ATA_SUPPORT_ZONE_MASK) == + ATA_SUPPORT_ZONE_DEV_MANAGED) { + softc->zone_mode = DA_ZONE_DRIVE_MANAGED; + softc->zone_interface = DA_ZONE_IF_ATA_PASS; + } + } else { error = daerror(done_ccb, CAM_RETRY_SELTO, SF_RETRY_UA|SF_NO_PRINT); if (error == ERESTART) return; else if (error != 0) { ! if ((done_ccb->ccb_h.status & ! CAM_DEV_QFRZN) != 0) { /* Don't wedge this device's queue */ cam_release_devq(done_ccb->ccb_h.path, /*relsim_flags*/0, *************** *** 3558,3563 **** --- 4432,4878 ---- } free(ata_params, M_SCSIDA); + if ((softc->zone_mode == DA_ZONE_HOST_AWARE) + || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) { + /* + * If the ATA IDENTIFY failed, we could be talking + * to a SCSI drive, although that seems unlikely, + * since the drive did report that it supported the + * ATA Information VPD page. If the ATA IDENTIFY + * succeeded, continue on to get the directory of + * ATA logs, and complete the rest of the ZAC probe. + */ + if ((error == 0) + && (softc->flags & DA_FLAG_CAN_ATA_LOG)) + softc->state = DA_STATE_PROBE_ATA_LOGDIR; + else + softc->state = DA_STATE_PROBE_ZONE; + continue_probe = 1; + } + if (continue_probe != 0) { + xpt_release_ccb(done_ccb); + xpt_schedule(periph, priority); + return; + } else + daprobedone(periph, done_ccb); + return; + } + case DA_CCB_PROBE_ATA_LOGDIR: + { + int error; + + if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { + error = 0; + softc->valid_logdir_len = 0; + bzero(&softc->ata_logdir, sizeof(softc->ata_logdir)); + softc->valid_logdir_len = + csio->dxfer_len - csio->resid; + if (softc->valid_logdir_len > 0) + bcopy(csio->data_ptr, &softc->ata_logdir, + min(softc->valid_logdir_len, + sizeof(softc->ata_logdir))); + /* + * Figure out whether the Identify Device log is + * supported. The General Purpose log directory + * has a header, and lists the number of pages + * available for each GP log identified by the + * offset into the list. + */ + if ((softc->valid_logdir_len >= + ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t))) + && (le16dec(softc->ata_logdir.header) == + ATA_GP_LOG_DIR_VERSION) + && (le16dec(&softc->ata_logdir.num_pages[ + (ATA_IDENTIFY_DATA_LOG * + sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){ + softc->flags |= DA_FLAG_CAN_ATA_IDLOG; + } else { + softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG; + } + } else { + error = daerror(done_ccb, CAM_RETRY_SELTO, + SF_RETRY_UA|SF_NO_PRINT); + if (error == ERESTART) + return; + else if (error != 0) { + /* + * If we can't get the ATA log directory, + * then ATA logs are effectively not + * supported even if the bit is set in the + * identify data. + */ + softc->flags &= ~(DA_FLAG_CAN_ATA_LOG | + DA_FLAG_CAN_ATA_IDLOG); + if ((done_ccb->ccb_h.status & + CAM_DEV_QFRZN) != 0) { + /* Don't wedge this device's queue */ + cam_release_devq(done_ccb->ccb_h.path, + /*relsim_flags*/0, + /*reduction*/0, + /*timeout*/0, + /*getcount_only*/0); + } + } + } + + free(csio->data_ptr, M_SCSIDA); + + if ((error == 0) + && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) { + softc->state = DA_STATE_PROBE_ATA_IDDIR; + xpt_release_ccb(done_ccb); + xpt_schedule(periph, priority); + return; + } + daprobedone(periph, done_ccb); + return; + } + case DA_CCB_PROBE_ATA_IDDIR: + { + int error; + + if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { + off_t entries_offset, max_entries; + error = 0; + + softc->valid_iddir_len = 0; + bzero(&softc->ata_iddir, sizeof(softc->ata_iddir)); + softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP | + DA_FLAG_CAN_ATA_ZONE); + softc->valid_iddir_len = + csio->dxfer_len - csio->resid; + if (softc->valid_iddir_len > 0) + bcopy(csio->data_ptr, &softc->ata_iddir, + min(softc->valid_iddir_len, + sizeof(softc->ata_iddir))); + + entries_offset = + __offsetof(struct ata_identify_log_pages,entries); + max_entries = softc->valid_iddir_len - entries_offset; + if ((softc->valid_iddir_len > (entries_offset + 1)) + && (le64dec(softc->ata_iddir.header) == + ATA_IDLOG_REVISION) + && (softc->ata_iddir.entry_count > 0)) { + int num_entries, i; + + num_entries = softc->ata_iddir.entry_count; + num_entries = min(num_entries, + softc->valid_iddir_len - entries_offset); + for (i = 0; i < num_entries && + i < max_entries; i++) { + if (softc->ata_iddir.entries[i] == + ATA_IDL_SUP_CAP) + softc->flags |= + DA_FLAG_CAN_ATA_SUPCAP; + else if (softc->ata_iddir.entries[i]== + ATA_IDL_ZDI) + softc->flags |= + DA_FLAG_CAN_ATA_ZONE; + + if ((softc->flags & + DA_FLAG_CAN_ATA_SUPCAP) + && (softc->flags & + DA_FLAG_CAN_ATA_ZONE)) + break; + } + } + } else { + error = daerror(done_ccb, CAM_RETRY_SELTO, + SF_RETRY_UA|SF_NO_PRINT); + if (error == ERESTART) + return; + else if (error != 0) { + /* + * If we can't get the ATA Identify Data log + * directory, then it effectively isn't + * supported even if the ATA Log directory + * a non-zero number of pages present for + * this log. + */ + softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG; + if ((done_ccb->ccb_h.status & + CAM_DEV_QFRZN) != 0) { + /* Don't wedge this device's queue */ + cam_release_devq(done_ccb->ccb_h.path, + /*relsim_flags*/0, + /*reduction*/0, + /*timeout*/0, + /*getcount_only*/0); + } + } + } + + free(csio->data_ptr, M_SCSIDA); + + if ((error == 0) + && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) { + softc->state = DA_STATE_PROBE_ATA_SUP; + xpt_release_ccb(done_ccb); + xpt_schedule(periph, priority); + return; + } + daprobedone(periph, done_ccb); + return; + } + case DA_CCB_PROBE_ATA_SUP: + { + int error; + + if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { + uint32_t valid_len; + size_t needed_size; + struct ata_identify_log_sup_cap *sup_cap; + error = 0; + + sup_cap = (struct ata_identify_log_sup_cap *) + csio->data_ptr; + valid_len = csio->dxfer_len - csio->resid; + needed_size = + __offsetof(struct ata_identify_log_sup_cap, + sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap); + if (valid_len >= needed_size) { + uint64_t zoned, zac_cap; + + zoned = le64dec(sup_cap->zoned_cap); + if (zoned & ATA_ZONED_VALID) { + /* + * This should have already been + * set, because this is also in the + * ATA identify data. + */ + if ((zoned & ATA_ZONED_MASK) == + ATA_SUPPORT_ZONE_HOST_AWARE) + softc->zone_mode = + DA_ZONE_HOST_AWARE; + else if ((zoned & ATA_ZONED_MASK) == + ATA_SUPPORT_ZONE_DEV_MANAGED) + softc->zone_mode = + DA_ZONE_DRIVE_MANAGED; + } + + zac_cap = le64dec(sup_cap->sup_zac_cap); + if (zac_cap & ATA_SUP_ZAC_CAP_VALID) { + if (zac_cap & ATA_REPORT_ZONES_SUP) + softc->zone_flags |= + DA_ZONE_FLAG_RZ_SUP; + if (zac_cap & ATA_ND_OPEN_ZONE_SUP) + softc->zone_flags |= + DA_ZONE_FLAG_OPEN_SUP; + if (zac_cap & ATA_ND_CLOSE_ZONE_SUP) + softc->zone_flags |= + DA_ZONE_FLAG_CLOSE_SUP; + if (zac_cap & ATA_ND_FINISH_ZONE_SUP) + softc->zone_flags |= + DA_ZONE_FLAG_FINISH_SUP; + if (zac_cap & ATA_ND_RWP_SUP) + softc->zone_flags |= + DA_ZONE_FLAG_RWP_SUP; + } else { + /* + * This field was introduced in + * ACS-4, r08 on April 28th, 2015. + * If the drive firmware was written + * to an earlier spec, it won't have + * the field. So, assume all + * commands are supported. + */ + softc->zone_flags |= + DA_ZONE_FLAG_SUP_MASK; + } + + } + } else { + error = daerror(done_ccb, CAM_RETRY_SELTO, + SF_RETRY_UA|SF_NO_PRINT); + if (error == ERESTART) + return; + else if (error != 0) { + /* + * If we can't get the ATA Identify Data + * Supported Capabilities page, clear the + * flag... + */ + softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP; + /* + * And clear zone capabilities. + */ + softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK; + if ((done_ccb->ccb_h.status & + CAM_DEV_QFRZN) != 0) { + /* Don't wedge this device's queue */ + cam_release_devq(done_ccb->ccb_h.path, + /*relsim_flags*/0, + /*reduction*/0, + /*timeout*/0, + /*getcount_only*/0); + } + } + } + + free(csio->data_ptr, M_SCSIDA); + + if ((error == 0) + && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) { + softc->state = DA_STATE_PROBE_ATA_ZONE; + xpt_release_ccb(done_ccb); + xpt_schedule(periph, priority); + return; + } + daprobedone(periph, done_ccb); + return; + } + case DA_CCB_PROBE_ATA_ZONE: + { + int error; + + if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { + struct ata_zoned_info_log *zi_log; + uint32_t valid_len; + size_t needed_size; + + zi_log = (struct ata_zoned_info_log *)csio->data_ptr; + + valid_len = csio->dxfer_len - csio->resid; + needed_size = __offsetof(struct ata_zoned_info_log, + version_info) + 1 + sizeof(zi_log->version_info); + if (valid_len >= needed_size) { + uint64_t tmpvar; + + tmpvar = le64dec(zi_log->zoned_cap); + if (tmpvar & ATA_ZDI_CAP_VALID) { + if (tmpvar & ATA_ZDI_CAP_URSWRZ) + softc->zone_flags |= + DA_ZONE_FLAG_URSWRZ; + else + softc->zone_flags &= + ~DA_ZONE_FLAG_URSWRZ; + } + tmpvar = le64dec(zi_log->optimal_seq_zones); + if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) { + softc->zone_flags |= + DA_ZONE_FLAG_OPT_SEQ_SET; + softc->optimal_seq_zones = (tmpvar & + ATA_ZDI_OPT_SEQ_MASK); + } else { + softc->zone_flags &= + ~DA_ZONE_FLAG_OPT_SEQ_SET; + softc->optimal_seq_zones = 0; + } + + tmpvar =le64dec(zi_log->optimal_nonseq_zones); + if (tmpvar & ATA_ZDI_OPT_NS_VALID) { + softc->zone_flags |= + DA_ZONE_FLAG_OPT_NONSEQ_SET; + softc->optimal_nonseq_zones = + (tmpvar & ATA_ZDI_OPT_NS_MASK); + } else { + softc->zone_flags &= + ~DA_ZONE_FLAG_OPT_NONSEQ_SET; + softc->optimal_nonseq_zones = 0; + } + + tmpvar = le64dec(zi_log->max_seq_req_zones); + if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) { + softc->zone_flags |= + DA_ZONE_FLAG_MAX_SEQ_SET; + softc->max_seq_zones = + (tmpvar & ATA_ZDI_MAX_SEQ_MASK); + } else { + softc->zone_flags &= + ~DA_ZONE_FLAG_MAX_SEQ_SET; + softc->max_seq_zones = 0; + } + } + } else { + error = daerror(done_ccb, CAM_RETRY_SELTO, + SF_RETRY_UA|SF_NO_PRINT); + if (error == ERESTART) + return; + else if (error != 0) { + softc->flags &= ~DA_FLAG_CAN_ATA_ZONE; + softc->flags &= ~DA_ZONE_FLAG_SET_MASK; + + if ((done_ccb->ccb_h.status & + CAM_DEV_QFRZN) != 0) { + /* Don't wedge this device's queue */ + cam_release_devq(done_ccb->ccb_h.path, + /*relsim_flags*/0, + /*reduction*/0, + /*timeout*/0, + /*getcount_only*/0); + } + } + + } + free(csio->data_ptr, M_SCSIDA); + daprobedone(periph, done_ccb); + return; + } + case DA_CCB_PROBE_ZONE: + { + int error; + + if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { + uint32_t valid_len; + size_t needed_len; + struct scsi_vpd_zoned_bdc *zoned_bdc; + + error = 0; + zoned_bdc = (struct scsi_vpd_zoned_bdc *) + csio->data_ptr; + valid_len = csio->dxfer_len - csio->resid; + needed_len = __offsetof(struct scsi_vpd_zoned_bdc, + max_seq_req_zones) + 1 + + sizeof(zoned_bdc->max_seq_req_zones); + if ((valid_len >= needed_len) + && (scsi_2btoul(zoned_bdc->page_length) >= + SVPD_ZBDC_PL)) { + if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ) + softc->zone_flags |= + DA_ZONE_FLAG_URSWRZ; + else + softc->zone_flags &= + ~DA_ZONE_FLAG_URSWRZ; + softc->optimal_seq_zones = + scsi_4btoul(zoned_bdc->optimal_seq_zones); + softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET; + softc->optimal_nonseq_zones = scsi_4btoul( + zoned_bdc->optimal_nonseq_zones); + softc->zone_flags |= + DA_ZONE_FLAG_OPT_NONSEQ_SET; + softc->max_seq_zones = + scsi_4btoul(zoned_bdc->max_seq_req_zones); + softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET; + } + /* + * All of the zone commands are mandatory for SCSI + * devices. + * + * XXX KDM this is valid as of September 2015. + * Re-check this assumption once the SAT spec is + * updated to support SCSI ZBC to ATA ZAC mapping. + * Since ATA allows zone commands to be reported + * as supported or not, this may not necessarily + * be true for an ATA device behind a SAT (SCSI to + * ATA Translation) layer. + */ + softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK; + } else { + error = daerror(done_ccb, CAM_RETRY_SELTO, + SF_RETRY_UA|SF_NO_PRINT); + if (error == ERESTART) + return; + else if (error != 0) { + if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { + /* Don't wedge this device's queue */ + cam_release_devq(done_ccb->ccb_h.path, + /*relsim_flags*/0, + /*reduction*/0, + /*timeout*/0, + /*getcount_only*/0); + } + } + } daprobedone(periph, done_ccb); return; } *************** *** 4034,4036 **** --- 5349,5527 ---- } #endif /* _KERNEL */ + + void + scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint8_t tag_action, uint8_t service_action, uint64_t zone_id, + uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len, + uint8_t sense_len, uint32_t timeout) + { + struct scsi_zbc_out *scsi_cmd; + + scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes; + scsi_cmd->opcode = ZBC_OUT; + scsi_cmd->service_action = service_action; + scsi_u64to8b(zone_id, scsi_cmd->zone_id); + scsi_cmd->zone_flags = zone_flags; + + cam_fill_csio(csio, + retries, + cbfcnp, + /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE, + tag_action, + data_ptr, + dxfer_len, + sense_len, + sizeof(*scsi_cmd), + timeout); + } + + void + scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba, + uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len, + uint8_t sense_len, uint32_t timeout) + { + struct scsi_zbc_in *scsi_cmd; + + scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes; + scsi_cmd->opcode = ZBC_IN; + scsi_cmd->service_action = service_action; + scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba); + scsi_cmd->zone_options = zone_options; + + cam_fill_csio(csio, + retries, + cbfcnp, + /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE, + tag_action, + data_ptr, + dxfer_len, + sense_len, + sizeof(*scsi_cmd), + timeout); + + } + + void + scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint8_t tag_action, int use_ncq __unused, + uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags, + uint8_t *data_ptr, uint32_t dxfer_len, + uint8_t sense_len, uint32_t timeout) + { + uint8_t command_out, protocol, ata_flags; + uint16_t features_out; + uint32_t sectors_out; + + #if 0 + if (use_ncq == 0) { + #endif + command_out = ATA_ZAC_MANAGEMENT_OUT; + features_out = (zm_action & 0xf) | (zone_flags << 8), + ata_flags = AP_FLAG_BYT_BLOK_BLOCKS; + if (dxfer_len == 0) { + protocol = AP_PROTO_NON_DATA; + ata_flags |= AP_FLAG_TLEN_NO_DATA; + sectors_out = 0; + } else { + protocol = AP_PROTO_DMA; + ata_flags |= AP_FLAG_TLEN_SECT_CNT | + AP_FLAG_TDIR_TO_DEV; + sectors_out = ((dxfer_len >> 9) & 0xffff); + } + #if 0 + } else { + /* + * XXX KDM how do we specify the action here? + */ + if (dxfer_len == 0) { + command_out = ATA_NCQ_NON_DATA; + features_out = ATA_NCQ_ZAC_MGMT_OUT; + } else { + command_out = ATA_SEND_FPDMA_QUEUED; + features_out = ATA_SFPDMA_ZAC_MGMT_OUT; + } + protocol = AP_PROTO_FPDMA; + } + #endif + + protocol |= AP_EXTEND; + + scsi_ata_pass_16(csio, + retries, + cbfcnp, + /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : + CAM_DIR_NONE, + tag_action, + /*protocol*/ protocol, + /*ata_flags*/ ata_flags, + /*features*/ features_out, + /*sector_count*/ sectors_out, + /*lba*/ zone_id, + /*command*/ command_out, + /*control*/ 0, + /*data_ptr*/ data_ptr, + /*dxfer_len*/ dxfer_len, + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); + } + + void + scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint8_t tag_action, int use_ncq __unused, + uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags, + uint8_t *data_ptr, uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout) + { + uint8_t command_out, protocol; + uint16_t features_out; + + #if 0 + if (use_ncq == 0) { + #endif + command_out = ATA_ZAC_MANAGEMENT_IN; + /* XXX KDM put a macro here */ + features_out = (zm_action & 0xf) | (zone_flags << 8), + protocol = AP_PROTO_DMA; + #if 0 + } else { + command_out = ATA_RECV_FPDMA_QUEUED; + /* + * XXX KDM NCQ encapsulation cannot work currently. It + * requires using the Auxiliary register to hold + * Features(15:0), but there is no way to represent the + * Auxiliary register in the SCSI ATA PASS-THROUGH (16) + * CDB. Until the specs allow for that, we can't really + * make NCQ mode work. So we have the + */ + features_out = ATA_RFPDMA_ZAC_MGMT_IN | (zone_flags << 8); + protocol = AP_PROTO_FPDMA; + } + #endif + + protocol |= AP_EXTEND; + + scsi_ata_pass_16(csio, + retries, + cbfcnp, + /*flags*/ CAM_DIR_IN, + tag_action, + /*protocol*/ protocol, + /*ata_flags*/ AP_FLAG_TLEN_SECT_CNT | + AP_FLAG_BYT_BLOK_BLOCKS | + AP_FLAG_TDIR_FROM_DEV, + /*features*/ features_out, + /*sector_count*/ dxfer_len >> 9, /* XXX KDM macro*/ + /*lba*/ zone_id, + /*command*/ command_out, + /*control*/ 0, + /*data_ptr*/ data_ptr, + /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */ + /*sense_len*/ SSD_FULL_SIZE, + /*timeout*/ timeout); + } *** src/sys/cam/scsi/scsi_da.h.orig --- src/sys/cam/scsi/scsi_da.h *************** *** 153,158 **** --- 153,236 ---- uint8_t control; }; + struct scsi_zbc_out + { + uint8_t opcode; + uint8_t service_action; + #define ZBC_OUT_SA_CLOSE 0x01 + #define ZBC_OUT_SA_FINISH 0x02 + #define ZBC_OUT_SA_OPEN 0x03 + #define ZBC_OUT_SA_RWP 0x04 + uint8_t zone_id[8]; + uint8_t reserved[4]; + uint8_t zone_flags; + #define ZBC_OUT_ALL 0x01 + uint8_t control; + }; + + struct scsi_zbc_in + { + uint8_t opcode; + uint8_t service_action; + #define ZBC_IN_SA_REPORT_ZONES 0x00 + uint8_t zone_start_lba[8]; + uint8_t length[4]; + uint8_t zone_options; + #define ZBC_IN_PARTIAL 0x80 + #define ZBC_IN_REP_ALL_ZONES 0x00 + #define ZBC_IN_REP_EMPTY 0x01 + #define ZBC_IN_REP_IMP_OPEN 0x02 + #define ZBC_IN_REP_EXP_OPEN 0x03 + #define ZBC_IN_REP_CLOSED 0x04 + #define ZBC_IN_REP_FULL 0x05 + #define ZBC_IN_REP_READONLY 0x06 + #define ZBC_IN_REP_OFFLINE 0x07 + #define ZBC_IN_REP_RESET 0x10 + #define ZBC_IN_REP_NON_SEQ 0x11 + #define ZBC_IN_REP_NON_WP 0x3f + #define ZBC_IN_REP_MASK 0x3f + uint8_t control; + }; + + struct scsi_report_zones_desc { + uint8_t zone_type; + #define SRZ_TYPE_CONVENTIONAL 0x01 + #define SRZ_TYPE_SEQ_REQUIRED 0x02 + #define SRZ_TYPE_SEQ_PREFERRED 0x03 + #define SRZ_TYPE_MASK 0x0f + uint8_t zone_flags; + #define SRZ_ZONE_COND_SHIFT 4 + #define SRZ_ZONE_COND_MASK 0xf0 + #define SRZ_ZONE_COND_NWP 0x00 + #define SRZ_ZONE_COND_EMPTY 0x10 + #define SRZ_ZONE_COND_IMP_OPEN 0x20 + #define SRZ_ZONE_COND_EXP_OPEN 0x30 + #define SRZ_ZONE_COND_CLOSED 0x40 + #define SRZ_ZONE_COND_READONLY 0xd0 + #define SRZ_ZONE_COND_FULL 0xe0 + #define SRZ_ZONE_COND_OFFLINE 0xf0 + #define SRZ_ZONE_NON_SEQ 0x02 + #define SRZ_ZONE_RESET 0x01 + uint8_t reserved[6]; + uint8_t zone_length[8]; + uint8_t zone_start_lba[8]; + uint8_t write_pointer_lba[8]; + uint8_t reserved2[32]; + }; + + struct scsi_report_zones_hdr { + uint8_t length[4]; + uint8_t byte4; + #define SRZ_SAME_ALL_DIFFERENT 0x00 /* Lengths and types vary */ + #define SRZ_SAME_ALL_SAME 0x01 /* Lengths and types the same */ + #define SRZ_SAME_LAST_DIFFERENT 0x02 /* Types same, last length varies */ + #define SRZ_SAME_TYPES_DIFFERENT 0x03 /* Types vary, length the same */ + #define SRZ_SAME_MASK 0x0f + uint8_t reserved[3]; + uint8_t maximum_lba[8]; + uint8_t reserved2[48]; + struct scsi_report_zones_desc desc_list[]; + }; /* * Opcodes *************** *** 167,172 **** --- 245,252 ---- #define VERIFY 0x2f #define READ_DEFECT_DATA_10 0x37 #define SANITIZE 0x48 + #define ZBC_OUT 0x94 + #define ZBC_IN 0x95 #define READ_DEFECT_DATA_12 0xb7 struct format_defect_list_header *************** *** 581,586 **** --- 661,696 ---- u_int32_t timeout); #endif /* !_KERNEL */ + + void scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint8_t tag_action, uint8_t service_action, uint64_t zone_id, + uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len, + uint8_t sense_len, uint32_t timeout); + + void scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint8_t tag_action, uint8_t service_action, + uint64_t zone_start_lba, uint8_t zone_options, + uint8_t *data_ptr, uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout); + + void scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint8_t tag_action, int use_ncq, + uint8_t zm_action, uint64_t zone_id, + uint8_t zone_flags, uint8_t *data_ptr, + uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout); + + void scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint8_t tag_action, int use_ncq, + uint8_t zm_action, uint64_t zone_id, + uint8_t zone_flags, uint8_t *data_ptr, + uint32_t dxfer_len, uint8_t sense_len, + uint32_t timeout); + __END_DECLS #endif /* _SCSI_SCSI_DA_H */ *** src/sys/geom/eli/g_eli.c.orig --- src/sys/geom/eli/g_eli.c *************** *** 315,320 **** --- 315,321 ---- case BIO_WRITE: case BIO_GETATTR: case BIO_FLUSH: + case BIO_ZONE: break; case BIO_DELETE: /* *************** *** 348,353 **** --- 349,355 ---- break; case BIO_GETATTR: case BIO_FLUSH: + case BIO_ZONE: cbp->bio_done = g_std_done; cp = LIST_FIRST(&sc->sc_geom->consumer); cbp->bio_to = cp->provider; *** src/sys/geom/geom.h.orig --- src/sys/geom/geom.h *************** *** 56,61 **** --- 56,62 ---- struct sbuf; struct gctl_req; struct g_configargs; + struct disk_zone_args; typedef int g_config_t (struct g_configargs *ca); typedef void g_ctl_req_t (struct gctl_req *, struct g_class *cp, char const *verb); *************** *** 318,323 **** --- 319,325 ---- void g_destroy_bio(struct bio *); void g_io_deliver(struct bio *bp, int error); int g_io_getattr(const char *attr, struct g_consumer *cp, int *len, void *ptr); + int g_io_zonecmd(struct disk_zone_args *zone_args, struct g_consumer *cp); int g_io_flush(struct g_consumer *cp); int g_register_classifier(struct g_classifier_hook *hook); void g_unregister_classifier(struct g_classifier_hook *hook); *** src/sys/geom/geom_dev.c.orig --- src/sys/geom/geom_dev.c *************** *** 571,576 **** --- 571,612 ---- error = g_io_getattr(arg->name, cp, &arg->len, &arg->value); break; } + case DIOCZONECMD: { + struct disk_zone_args *zone_args =(struct disk_zone_args *)data; + struct disk_zone_rep_entry *new_entries, *old_entries; + struct disk_zone_report *rep; + size_t alloc_size; + + old_entries = NULL; + new_entries = NULL; + rep = NULL; + alloc_size = 0; + + if (zone_args->zone_cmd == DISK_ZONE_REPORT_ZONES) { + + rep = &zone_args->zone_params.report; + alloc_size = rep->entries_allocated * + sizeof(struct disk_zone_rep_entry); + if (alloc_size != 0) + new_entries = g_malloc(alloc_size, + M_WAITOK| M_ZERO); + old_entries = rep->entries; + rep->entries = new_entries; + } + error = g_io_zonecmd(zone_args, cp); + if ((zone_args->zone_cmd == DISK_ZONE_REPORT_ZONES) + && (alloc_size != 0) + && (error == 0)) { + error = copyout(new_entries, old_entries, alloc_size); + } + if ((old_entries != NULL) + && (rep != NULL)) + rep->entries = old_entries; + + if (new_entries != NULL) + g_free(new_entries); + break; + } default: if (cp->provider->geom->ioctl != NULL) { error = cp->provider->geom->ioctl(cp->provider, cmd, data, fflag, td); *************** *** 596,601 **** --- 632,640 ---- bp->bio_error = bp2->bio_error; bp->bio_completed = bp2->bio_completed; bp->bio_resid = bp->bio_length - bp2->bio_completed; + if (bp2->bio_cmd == BIO_ZONE) + bcopy(&bp2->bio_zone, &bp->bio_zone, sizeof(bp->bio_zone)); + if (bp2->bio_error != 0) { g_trace(G_T_BIO, "g_dev_done(%p) had error %d", bp2, bp2->bio_error); *************** *** 630,636 **** KASSERT(bp->bio_cmd == BIO_READ || bp->bio_cmd == BIO_WRITE || bp->bio_cmd == BIO_DELETE || ! bp->bio_cmd == BIO_FLUSH, ("Wrong bio_cmd bio=%p cmd=%d", bp, bp->bio_cmd)); dev = bp->bio_dev; cp = dev->si_drv2; --- 669,676 ---- KASSERT(bp->bio_cmd == BIO_READ || bp->bio_cmd == BIO_WRITE || bp->bio_cmd == BIO_DELETE || ! bp->bio_cmd == BIO_FLUSH || ! bp->bio_cmd == BIO_ZONE, ("Wrong bio_cmd bio=%p cmd=%d", bp, bp->bio_cmd)); dev = bp->bio_dev; cp = dev->si_drv2; *** src/sys/geom/geom_disk.c.orig --- src/sys/geom/geom_disk.c *************** *** 245,252 **** if (bp2->bio_error == 0) bp2->bio_error = bp->bio_error; bp2->bio_completed += bp->bio_completed; ! if ((bp->bio_cmd & (BIO_READ|BIO_WRITE|BIO_DELETE|BIO_FLUSH)) != 0) devstat_end_transaction_bio_bt(sc->dp->d_devstat, bp, &now); bp2->bio_inbed++; if (bp2->bio_children == bp2->bio_inbed) { mtx_unlock(&sc->done_mtx); --- 245,255 ---- if (bp2->bio_error == 0) bp2->bio_error = bp->bio_error; bp2->bio_completed += bp->bio_completed; ! if ((bp->bio_cmd & (BIO_READ|BIO_WRITE|BIO_DELETE|BIO_FLUSH| ! BIO_ZONE)) != 0) devstat_end_transaction_bio_bt(sc->dp->d_devstat, bp, &now); + if (bp->bio_cmd == BIO_ZONE) + bcopy(&bp->bio_zone, &bp2->bio_zone, sizeof(bp->bio_zone)); bp2->bio_inbed++; if (bp2->bio_children == bp2->bio_inbed) { mtx_unlock(&sc->done_mtx); *************** *** 536,541 **** --- 539,554 ---- error = EOPNOTSUPP; break; } + /*FALLTHROUGH*/ + case BIO_ZONE: + if (bp->bio_cmd == BIO_ZONE) { + if (!(dp->d_flags & DISKFLAG_CANZONE)) { + error = EOPNOTSUPP; + break; + } + g_trace(G_T_BIO, "g_disk_zone(%s)", + bp->bio_to->name); + } bp2 = g_clone_bio(bp); if (bp2 == NULL) { g_io_deliver(bp, ENOMEM); *** src/sys/geom/geom_disk.h.orig --- src/sys/geom/geom_disk.h *************** *** 112,117 **** --- 112,118 ---- #define DISKFLAG_UNMAPPED_BIO 0x10 #define DISKFLAG_DIRECT_COMPLETION 0x20 #define DISKFLAG_LACKS_ROTRATE 0x40 + #define DISKFLAG_CANZONE 0x80 struct disk *disk_alloc(void); void disk_create(struct disk *disk, int version); *** src/sys/geom/geom_io.c.orig --- src/sys/geom/geom_io.c *************** *** 218,223 **** --- 218,226 ---- bp2->bio_ma_n = bp->bio_ma_n; bp2->bio_ma_offset = bp->bio_ma_offset; bp2->bio_attribute = bp->bio_attribute; + if (bp->bio_cmd == BIO_ZONE) + bcopy(&bp->bio_zone, &bp2->bio_zone, + sizeof(bp->bio_zone)); /* Inherit classification info from the parent */ bp2->bio_classifier1 = bp->bio_classifier1; bp2->bio_classifier2 = bp->bio_classifier2; *************** *** 298,303 **** --- 301,334 ---- } int + g_io_zonecmd(struct disk_zone_args *zone_args, struct g_consumer *cp) + { + struct bio *bp; + int error; + + g_trace(G_T_BIO, "bio_zone(%d)", zone_args->zone_cmd); + bp = g_alloc_bio(); + bp->bio_cmd = BIO_ZONE; + bp->bio_done = NULL; + /* + * XXX KDM need to handle report zone data. + */ + bcopy(zone_args, &bp->bio_zone, sizeof(*zone_args)); + if (zone_args->zone_cmd == DISK_ZONE_REPORT_ZONES) + bp->bio_length = + zone_args->zone_params.report.entries_allocated * + sizeof(struct disk_zone_rep_entry); + else + bp->bio_length = 0; + + g_io_request(bp, cp); + error = biowait(bp, "gzone"); + bcopy(&bp->bio_zone, zone_args, sizeof(*zone_args)); + g_destroy_bio(bp); + return (error); + } + + int g_io_flush(struct g_consumer *cp) { struct bio *bp; *************** *** 342,347 **** --- 373,386 ---- if (cp->acw == 0) return (EPERM); break; + case BIO_ZONE: + if ((bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES) || + (bp->bio_zone.zone_cmd == DISK_ZONE_GET_PARAMS)) { + if (cp->acr == 0) + return (EPERM); + } else if (cp->acw == 0) + return (EPERM); + break; default: return (EPERM); } *************** *** 495,505 **** if (bp->bio_cmd & (BIO_READ|BIO_WRITE|BIO_GETATTR)) { KASSERT(bp->bio_data != NULL, ! ("NULL bp->data in g_io_request(cmd=%hhu)", bp->bio_cmd)); } if (bp->bio_cmd & (BIO_DELETE|BIO_FLUSH)) { KASSERT(bp->bio_data == NULL, ! ("non-NULL bp->data in g_io_request(cmd=%hhu)", bp->bio_cmd)); } if (bp->bio_cmd & (BIO_READ|BIO_WRITE|BIO_DELETE)) { --- 534,544 ---- if (bp->bio_cmd & (BIO_READ|BIO_WRITE|BIO_GETATTR)) { KASSERT(bp->bio_data != NULL, ! ("NULL bp->data in g_io_request(cmd=%hu)", bp->bio_cmd)); } if (bp->bio_cmd & (BIO_DELETE|BIO_FLUSH)) { KASSERT(bp->bio_data == NULL, ! ("non-NULL bp->data in g_io_request(cmd=%hu)", bp->bio_cmd)); } if (bp->bio_cmd & (BIO_READ|BIO_WRITE|BIO_DELETE)) { *************** *** 979,984 **** --- 1018,1052 ---- cmd = "FLUSH"; printf("%s[%s]", pname, cmd); return; + case BIO_ZONE: { + char *subcmd = NULL; + cmd = "ZONE"; + switch (bp->bio_zone.zone_cmd) { + case DISK_ZONE_OPEN: + subcmd = "OPEN"; + break; + case DISK_ZONE_CLOSE: + subcmd = "CLOSE"; + break; + case DISK_ZONE_FINISH: + subcmd = "FINISH"; + break; + case DISK_ZONE_RWP: + subcmd = "RWP"; + break; + case DISK_ZONE_REPORT_ZONES: + subcmd = "REPORT ZONES"; + break; + case DISK_ZONE_GET_PARAMS: + subcmd = "GET PARAMS"; + break; + default: + subcmd = "UKNOWN"; + break; + } + printf("%s[%s,%s]", pname, cmd, subcmd); + return; + } case BIO_READ: cmd = "READ"; break; *** src/sys/geom/geom_subr.c.orig --- src/sys/geom/geom_subr.c *************** *** 1471,1476 **** --- 1471,1477 ---- case BIO_CMD0: db_printf("BIO_CMD0"); break; case BIO_CMD1: db_printf("BIO_CMD1"); break; case BIO_CMD2: db_printf("BIO_CMD2"); break; + case BIO_ZONE: db_printf("BIO_ZONE"); break; default: db_printf("UNKNOWN"); break; } db_printf("\n"); *** src/sys/kern/subr_devstat.c.orig --- src/sys/kern/subr_devstat.c *************** *** 356,362 **** if (bp->bio_cmd == BIO_DELETE) flg = DEVSTAT_FREE; ! else if (bp->bio_cmd == BIO_READ) flg = DEVSTAT_READ; else if (bp->bio_cmd == BIO_WRITE) flg = DEVSTAT_WRITE; --- 356,364 ---- if (bp->bio_cmd == BIO_DELETE) flg = DEVSTAT_FREE; ! else if ((bp->bio_cmd == BIO_READ) ! || ((bp->bio_cmd == BIO_ZONE) ! && (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES))) flg = DEVSTAT_READ; else if (bp->bio_cmd == BIO_WRITE) flg = DEVSTAT_WRITE; *** src/sys/sys/ata.h.orig --- src/sys/sys/ata.h *************** *** 105,110 **** --- 105,114 ---- /*069*/ u_int16_t support3; #define ATA_SUPPORT_RZAT 0x0020 #define ATA_SUPPORT_DRAT 0x4000 + #define ATA_SUPPORT_ZONE_MASK 0x0003 + #define ATA_SUPPORT_ZONE_NR 0x0000 + #define ATA_SUPPORT_ZONE_HOST_AWARE 0x0001 + #define ATA_SUPPORT_ZONE_DEV_MANAGED 0x0002 u_int16_t reserved70; /*071*/ u_int16_t rlsovlap; /* rel time (us) for overlap */ /*072*/ u_int16_t rlsservice; /* rel time (us) for service */ *************** *** 369,385 **** --- 373,404 ---- #define ATA_READ_VERIFY 0x40 #define ATA_READ_VERIFY48 0x42 #define ATA_READ_LOG_DMA_EXT 0x47 /* read log DMA ext - PIO Data-In */ + #define ATA_ZAC_MANAGEMENT_IN 0x4a /* ZAC management in */ + #define ATA_ZM_REPORT_ZONES 0x00 /* report zones */ #define ATA_READ_FPDMA_QUEUED 0x60 /* read DMA NCQ */ #define ATA_WRITE_FPDMA_QUEUED 0x61 /* write DMA NCQ */ #define ATA_NCQ_NON_DATA 0x63 /* NCQ non-data command */ + #define ATA_ABORT_NCQ_QUEUE 0x00 /* abort NCQ queue */ + #define ATA_DEADLINE_HANDLING 0x01 /* deadline handling */ + #define ATA_SET_FEATURES 0x05 /* set features */ + #define ATA_ZERO_EXT 0x06 /* zero ext */ + #define ATA_NCQ_ZAC_MGMT_OUT 0x07 /* NCQ ZAC mgmt out no data */ #define ATA_SEND_FPDMA_QUEUED 0x64 /* send DMA NCQ */ #define ATA_SFPDMA_DSM 0x00 /* Data set management */ #define ATA_SFPDMA_DSM_TRIM 0x01 /* Set trim bit in auxilary */ #define ATA_SFPDMA_HYBRID_EVICT 0x01 /* Hybrid Evict */ #define ATA_SFPDMA_WLDMA 0x02 /* Write Log DMA EXT */ + #define ATA_SFPDMA_ZAC_MGMT_OUT 0x03 /* NCQ ZAC mgmt out w/data */ #define ATA_RECV_FPDMA_QUEUED 0x65 /* recieve DMA NCQ */ + #define ATA_RFPDMA_RL_DMA_EXT 0x00 /* Read Log DMA EXT */ + #define ATA_RFPDMA_ZAC_MGMT_IN 0x02 /* NCQ ZAC mgmt in w/data */ #define ATA_SEP_ATTN 0x67 /* SEP request */ #define ATA_SEEK 0x70 /* seek */ + #define ATA_ZAC_MANAGEMENT_OUT 0x9f /* ZAC management out */ + #define ATA_ZM_CLOSE_ZONE 0x01 /* close zone */ + #define ATA_ZM_FINISH_ZONE 0x02 /* finish zone */ + #define ATA_ZM_OPEN_ZONE 0x03 /* open zone */ + #define ATA_ZM_RWP 0x04 /* reset write pointer */ #define ATA_PACKET_CMD 0xa0 /* packet command */ #define ATA_ATAPI_IDENTIFY 0xa1 /* get ATAPI params*/ #define ATA_SERVICE 0xa2 /* service command */ *************** *** 543,548 **** --- 562,768 ---- u_int8_t specific2; /* sense key specific */ } __packed; + #define ATA_LOG_DIRECTORY 0x00 /* Directory of all logs */ + #define ATA_IDENTIFY_DATA_LOG 0x30 /* Identify Device Data Log */ + #define ATA_IDL_PAGE_LIST 0x00 /* List of supported pages */ + #define ATA_IDL_IDENTIFY_DATA 0x01 /* Copy of Identify Device data */ + #define ATA_IDL_CAPACITY 0x02 /* Capacity */ + #define ATA_IDL_SUP_CAP 0x03 /* Supported Capabilities */ + #define ATA_IDL_CUR_SETTINGS 0x04 /* Current Settings */ + #define ATA_IDL_ATA_STRINGS 0x05 /* ATA Strings */ + #define ATA_IDL_SECURITY 0x06 /* Security */ + #define ATA_IDL_PARALLEL_ATA 0x07 /* Parallel ATA */ + #define ATA_IDL_SERIAL_ATA 0x08 /* Seiral ATA */ + #define ATA_IDL_ZDI 0x09 /* Zoned Device Information */ + + struct ata_gp_log_dir { + uint8_t header[2]; + #define ATA_GP_LOG_DIR_VERSION 0x0001 + uint8_t num_pages[255*2]; /* Number of log pages at address */ + }; + + /* + * ATA IDENTIFY DEVICE data log (0x30) page 0x00 + * List of Supported IDENTIFY DEVICE data pages. + */ + struct ata_identify_log_pages { + uint8_t header[8]; + #define ATA_IDLOG_REVISION 0x0000000000000001 + uint8_t entry_count; + uint8_t entries[503]; + }; + + /* + * ATA IDENTIFY DEVICE data log (0x30) + * Capacity (Page 0x02). + */ + struct ata_identify_log_capacity { + uint8_t header[8]; + #define ATA_CAP_HEADER_VALID 0x8000000000000000 + #define ATA_CAP_PAGE_NUM_MASK 0x0000000000ff0000 + #define ATA_CAP_PAGE_NUM_SHIFT 16 + #define ATA_CAP_REV_MASK 0x00000000000000ff + uint8_t capacity[8]; + #define ATA_CAP_CAPACITY_VALID 0x8000000000000000 + #define ATA_CAP_ACCESSIBLE_CAP 0x0000ffffffffffff + uint8_t phys_logical_sect_size[8]; + #define ATA_CAP_PL_VALID 0x8000000000000000 + #define ATA_CAP_LTOP_REL_SUP 0x4000000000000000 + #define ATA_CAP_LOG_SECT_SUP 0x2000000000000000 + #define ATA_CAP_ALIGN_ERR_MASK 0x0000000000300000 + #define ATA_CAP_LTOP_MASK 0x00000000000f0000 + #define ATA_CAP_LOG_SECT_OFF 0x000000000000ffff + uint8_t logical_sect_size[8]; + #define ATA_CAP_LOG_SECT_VALID 0x8000000000000000 + #define ATA_CAP_LOG_SECT_SIZE 0x00000000ffffffff + uint8_t nominal_buffer_size[8]; + #define ATA_CAP_NOM_BUF_VALID 0x8000000000000000 + #define ATA_CAP_NOM_BUF_SIZE 0x7fffffffffffffff + uint8_t reserved[472]; + }; + + /* + * ATA IDENTIFY DEVICE data log (0x30) + * Supported Capabilities (Page 0x03). + */ + + struct ata_identify_log_sup_cap { + uint8_t header[8]; + #define ATA_SUP_CAP_HEADER_VALID 0x8000000000000000 + #define ATA_SUP_CAP_PAGE_NUM_MASK 0x0000000000ff0000 + #define ATA_SUP_CAP_PAGE_NUM_SHIFT 16 + #define ATA_SUP_CAP_REV_MASK 0x00000000000000ff + uint8_t sup_cap[8]; + #define ATA_SUP_CAP_VALID 0x8000000000000000 + #define ATA_SC_SET_SECT_CONFIG_SUP 0x0002000000000000 /* Set Sect Conf*/ + #define ATA_SC_ZERO_EXT_SUP 0x0001000000000000 /* Zero EXT */ + #define ATA_SC_SUCC_NCQ_SENSE_SUP 0x0000800000000000 /* Succ. NCQ Sns */ + #define ATA_SC_DLC_SUP 0x0000400000000000 /* DLC */ + #define ATA_SC_RQSN_DEV_FAULT_SUP 0x0000200000000000 /* Req Sns Dev Flt*/ + #define ATA_SC_DSN_SUP 0x0000100000000000 /* DSN */ + #define ATA_SC_LP_STANDBY_SUP 0x0000080000000000 /* LP Standby */ + #define ATA_SC_SET_EPC_PS_SUP 0x0000040000000000 /* Set EPC PS */ + #define ATA_SC_AMAX_ADDR_SUP 0x0000020000000000 /* AMAX Addr */ + #define ATA_SC_DRAT_SUP 0x0000008000000000 /* DRAT */ + #define ATA_SC_LPS_MISALGN_SUP 0x0000004000000000 /* LPS Misalign */ + #define ATA_SC_RB_DMA_SUP 0x0000001000000000 /* Read Buf DMA */ + #define ATA_SC_WB_DMA_SUP 0x0000000800000000 /* Write Buf DMA */ + #define ATA_SC_DNLD_MC_DMA_SUP 0x0000000200000000 /* DL MCode DMA */ + #define ATA_SC_28BIT_SUP 0x0000000100000000 /* 28-bit */ + #define ATA_SC_RZAT_SUP 0x0000000080000000 /* RZAT */ + #define ATA_SC_NOP_SUP 0x0000000020000000 /* NOP */ + #define ATA_SC_READ_BUFFER_SUP 0x0000000010000000 /* Read Buffer */ + #define ATA_SC_WRITE_BUFFER_SUP 0x0000000008000000 /* Write Buffer */ + #define ATA_SC_READ_LOOK_AHEAD_SUP 0x0000000002000000 /* Read Look-Ahead*/ + #define ATA_SC_VOLATILE_WC_SUP 0x0000000001000000 /* Volatile WC */ + #define ATA_SC_SMART_SUP 0x0000000000800000 /* SMART */ + #define ATA_SC_FLUSH_CACHE_EXT_SUP 0x0000000000400000 /* Flush Cache Ext */ + #define ATA_SC_48BIT_SUP 0x0000000000100000 /* 48-Bit */ + #define ATA_SC_SPINUP_SUP 0x0000000000040000 /* Spin-Up */ + #define ATA_SC_PUIS_SUP 0x0000000000020000 /* PUIS */ + #define ATA_SC_APM_SUP 0x0000000000010000 /* APM */ + #define ATA_SC_DL_MICROCODE_SUP 0x0000000000004000 /* DL Microcode */ + #define ATA_SC_UNLOAD_SUP 0x0000000000002000 /* Unload */ + #define ATA_SC_WRITE_FUA_EXT_SUP 0x0000000000001000 /* Write FUA EXT */ + #define ATA_SC_GPL_SUP 0x0000000000000800 /* GPL */ + #define ATA_SC_STREAMING_SUP 0x0000000000000400 /* Streaming */ + #define ATA_SC_SMART_SELFTEST_SUP 0x0000000000000100 /* SMART self-test */ + #define ATA_SC_SMART_ERR_LOG_SUP 0x0000000000000080 /* SMART Err Log */ + #define ATA_SC_EPC_SUP 0x0000000000000040 /* EPC */ + #define ATA_SC_SENSE_SUP 0x0000000000000020 /* Sense data */ + #define ATA_SC_FREEFALL_SUP 0x0000000000000010 /* Free-Fall */ + #define ATA_SC_DM_MODE3_SUP 0x0000000000000008 /* DM Mode 3 */ + #define ATA_SC_GPL_DMA_SUP 0x0000000000000004 /* GPL DMA */ + #define ATA_SC_WRITE_UNCOR_SUP 0x0000000000000002 /* Write uncorr. */ + #define ATA_SC_WRV_SUP 0x0000000000000001 /* WRV */ + uint8_t download_code_cap[8]; + #define ATA_DL_CODE_VALID 0x8000000000000000 + #define ATA_DLC_DM_OFFSETS_DEFER_SUP 0x0000000400000000 + #define ATA_DLC_DM_IMMED_SUP 0x0000000200000000 + #define ATA_DLC_DM_OFF_IMMED_SUP 0x0000000100000000 + #define ATA_DLC_DM_MAX_XFER_SIZE_MASK 0x00000000ffff0000 + #define ATA_DLC_DM_MAX_XFER_SIZE_SHIFT 16 + #define ATA_DLC_DM_MIN_XFER_SIZE_MASK 0x000000000000ffff + uint8_t nom_media_rotation_rate[8]; + #define ATA_NOM_MEDIA_ROTATION_VALID 0x8000000000000000 + #define ATA_ROTATION_MASK 0x000000000000ffff + uint8_t form_factor[8]; + #define ATA_FORM_FACTOR_VALID 0x8000000000000000 + #define ATA_FF_MASK 0x000000000000000f + #define ATA_FF_NOT_REPORTED 0x0000000000000000 /* Not reported */ + #define ATA_FF_525_IN 0x0000000000000001 /* 5.25 inch */ + #define ATA_FF_35_IN 0x0000000000000002 /* 3.5 inch */ + #define ATA_FF_25_IN 0x0000000000000003 /* 2.5 inch */ + #define ATA_FF_18_IN 0x0000000000000004 /* 1.8 inch */ + #define ATA_FF_LT_18_IN 0x0000000000000005 /* < 1.8 inch */ + #define ATA_FF_MSATA 0x0000000000000006 /* mSATA */ + #define ATA_FF_M2 0x0000000000000007 /* M.2 */ + #define ATA_FF_MICROSSD 0x0000000000000008 /* MicroSSD */ + #define ATA_FF_CFAST 0x0000000000000009 /* CFast */ + uint8_t wrv_sec_cnt_mode3[8]; + #define ATA_WRV_MODE3_VALID 0x8000000000000000 + #define ATA_WRV_MODE3_COUNT 0x00000000ffffffff + uint8_t wrv_sec_cnt_mode2[8]; + #define ATA_WRV_MODE2_VALID 0x8000000000000000 + #define ATA_WRV_MODE2_COUNT 0x00000000ffffffff + uint8_t wwn[16]; + /* XXX KDM need to figure out how to handle 128-bit fields */ + uint8_t dsm[8]; + #define ATA_DSM_VALID 0x8000000000000000 + #define ATA_LB_MARKUP_SUP 0x000000000000ff00 + #define ATA_TRIM_SUP 0x0000000000000001 + uint8_t util_per_unit_time[16]; + /* XXX KDM need to figure out how to handle 128-bit fields */ + uint8_t util_usage_rate_sup[8]; + #define ATA_UTIL_USAGE_RATE_VALID 0x8000000000000000 + #define ATA_SETTING_RATE_SUP 0x0000000000800000 + #define ATA_SINCE_POWERON_SUP 0x0000000000000100 + #define ATA_POH_RATE_SUP 0x0000000000000010 + #define ATA_DATE_TIME_RATE_SUP 0x0000000000000001 + uint8_t zoned_cap[8]; + #define ATA_ZONED_VALID 0x8000000000000000 + #define ATA_ZONED_MASK 0x0000000000000003 + uint8_t sup_zac_cap[8]; + #define ATA_SUP_ZAC_CAP_VALID 0x8000000000000000 + #define ATA_ND_RWP_SUP 0x0000000000000010 /* Reset Write Ptr*/ + #define ATA_ND_FINISH_ZONE_SUP 0x0000000000000008 /* Finish Zone */ + #define ATA_ND_CLOSE_ZONE_SUP 0x0000000000000004 /* Close Zone */ + #define ATA_ND_OPEN_ZONE_SUP 0x0000000000000002 /* Open Zone */ + #define ATA_REPORT_ZONES_SUP 0x0000000000000001 /* Report Zones */ + uint8_t reserved[392]; + }; + + /* + * ATA Identify Device Data Log Zoned Device Information Page (0x09). + * Current as of ZAC r04a, August 25, 2015. + */ + struct ata_zoned_info_log { + uint8_t header[8]; + #define ATA_ZDI_HEADER_VALID 0x8000000000000000 + #define ATA_ZDI_PAGE_NUM_MASK 0x0000000000ff0000 + #define ATA_ZDI_PAGE_NUM_SHIFT 16 + #define ATA_ZDI_REV_MASK 0x00000000000000ff + uint8_t zoned_cap[8]; + #define ATA_ZDI_CAP_VALID 0x8000000000000000 + #define ATA_ZDI_CAP_URSWRZ 0x0000000000000001 + uint8_t zoned_settings[8]; + #define ATA_ZDI_SETTINGS_VALID 0x8000000000000000 + uint8_t optimal_seq_zones[8]; + #define ATA_ZDI_OPT_SEQ_VALID 0x8000000000000000 + #define ATA_ZDI_OPT_SEQ_MASK 0x00000000ffffffff + uint8_t optimal_nonseq_zones[8]; + #define ATA_ZDI_OPT_NS_VALID 0x8000000000000000 + #define ATA_ZDI_OPT_NS_MASK 0x00000000ffffffff + uint8_t max_seq_req_zones[8]; + #define ATA_ZDI_MAX_SEQ_VALID 0x8000000000000000 + #define ATA_ZDI_MAX_SEQ_MASK 0x00000000ffffffff + uint8_t version_info[8]; + #define ATA_ZDI_VER_VALID 0x8000000000000000 + #define ATA_ZDI_VER_ZAC_SUP 0x0100000000000000 + #define ATA_ZDI_VER_ZAC_MASK 0x00000000000000ff + uint8_t reserved[456]; + }; + struct ata_ioc_request { union { struct { *** src/sys/sys/bio.h.orig --- src/sys/sys/bio.h *************** *** 39,44 **** --- 39,45 ---- #define _SYS_BIO_H_ #include + #include /* bio_cmd */ #define BIO_READ 0x01 /* Read I/O data */ *************** *** 49,54 **** --- 50,56 ---- #define BIO_CMD0 0x20 /* Available for local hacks */ #define BIO_CMD1 0x40 /* Available for local hacks */ #define BIO_CMD2 0x80 /* Available for local hacks */ + #define BIO_ZONE 0x100 /* Zone command */ /* bio_flags */ #define BIO_ERROR 0x01 /* An error occurred processing this bio. */ *************** *** 77,83 **** * The bio structure describes an I/O operation in the kernel. */ struct bio { ! uint8_t bio_cmd; /* I/O operation. */ uint8_t bio_flags; /* General flags. */ uint8_t bio_cflags; /* Private use by the consumer. */ uint8_t bio_pflags; /* Private use by the provider. */ --- 79,85 ---- * The bio structure describes an I/O operation in the kernel. */ struct bio { ! uint16_t bio_cmd; /* I/O operation. */ uint8_t bio_flags; /* General flags. */ uint8_t bio_cflags; /* Private use by the consumer. */ uint8_t bio_pflags; /* Private use by the provider. */ *************** *** 98,103 **** --- 100,106 ---- void *bio_caller2; /* Private use by the consumer. */ TAILQ_ENTRY(bio) bio_queue; /* Disksort queue. */ const char *bio_attribute; /* Attribute for BIO_[GS]ETATTR */ + struct disk_zone_args bio_zone;/* Used for BIO_ZONE */ struct g_consumer *bio_from; /* GEOM linkage */ struct g_provider *bio_to; /* GEOM linkage */ off_t bio_length; /* Like bio_bcount */ *** src/sys/sys/disk.h.orig --- src/sys/sys/disk.h *************** *** 15,20 **** --- 15,21 ---- #include #include + #include #ifdef _KERNEL *************** *** 136,139 **** --- 137,142 ---- }; #define DIOCGATTR _IOWR('d', 142, struct diocgattr_arg) + #define DIOCZONECMD _IOWR('d', 143, struct disk_zone_args) + #endif /* _SYS_DISK_H_ */ *** /dev/null Mon Jan 18 15:15:01 2016 --- src/sys/sys/disk_zone.h Mon Jan 18 15:15:17 2016 *************** *** 0 **** --- 1,182 ---- + /*- + * Copyright (c) 2015 Spectra Logic Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * Authors: Ken Merry (Spectra Logic Corporation) + */ + + #ifndef _SYS_DISK_ZONE_H_ + #define _SYS_DISK_ZONE_H_ + + /* + * Interface for Zone-based disks. This allows managing devices that + * conform to the SCSI Zoned Block Commands (ZBC) and ATA Zoned ATA Command + * Set (ZAC) specifications. Devices using these command sets are + * currently (October 2015) hard drives using Shingled Magnetic Recording + * (SMR). + */ + + /* + * There are currently three types of zoned devices: + * + * Drive Managed: + * Drive Managed drives look and act just like a standard random access + * block device, but underneath, the drive reads and writes the bulk of + * its capacity using SMR zones. Sequential writes will yield better + * performance, but writing sequentially is not required. + * + * Host Aware: + * Host Aware drives expose the underlying zone layout via SCSI or ATA + * commands and allow the host to manage the zone conditions. The host + * is not required to manage the zones on the drive, though. Sequential + * writes will yield better performance in Sequential Write Preferred + * zones, but the host can write randomly in those zones. + * + * Host Managed: + * Host Managed drives expose the underlying zone layout via SCSI or ATA + * commands. The host is required to access the zones according to the + * rules described by the zone layout. Any commands that violate the + * rules will be returned with an error. + */ + struct disk_zone_disk_params { + uint32_t zone_mode; + #define DISK_ZONE_MODE_NONE 0x00 + #define DISK_ZONE_MODE_HOST_AWARE 0x01 + #define DISK_ZONE_MODE_DRIVE_MANAGED 0x02 + #define DISK_ZONE_MODE_HOST_MANAGED 0x04 + uint64_t flags; + #define DISK_ZONE_DISK_URSWRZ 0x001 + #define DISK_ZONE_OPT_SEQ_SET 0x002 + #define DISK_ZONE_OPT_NONSEQ_SET 0x004 + #define DISK_ZONE_MAX_SEQ_SET 0x008 + #define DISK_ZONE_RZ_SUP 0x010 + #define DISK_ZONE_OPEN_SUP 0x020 + #define DISK_ZONE_CLOSE_SUP 0x040 + #define DISK_ZONE_FINISH_SUP 0x080 + #define DISK_ZONE_RWP_SUP 0x100 + #define DISK_ZONE_CMD_SUP_MASK 0x1f0 + uint64_t optimal_seq_zones; + uint64_t optimal_nonseq_zones; + uint64_t max_seq_zones; + }; + + /* + * Used for reset write pointer, open, close and finish. + */ + struct disk_zone_rwp { + uint64_t id; + uint8_t flags; + #define DISK_ZONE_RWP_FLAG_NONE 0x00 + #define DISK_ZONE_RWP_FLAG_ALL 0x01 + }; + + /* + * Report Zones header. All of these values are passed out. + */ + struct disk_zone_rep_header { + uint8_t same; + #define DISK_ZONE_SAME_ALL_DIFFERENT 0x0 /* Lengths and types vary */ + #define DISK_ZONE_SAME_ALL_SAME 0x1 /* Lengths and types the same */ + #define DISK_ZONE_SAME_LAST_DIFFERENT 0x2 /* Types same, last len varies */ + #define DISK_ZONE_SAME_TYPES_DIFFERENT 0x3 /* Types vary, length the same */ + uint64_t maximum_lba; + /* + * XXX KDM padding space may not be a good idea inside the bio. + */ + uint8_t reserved[64]; + }; + + /* + * Report Zones entry. Note that the zone types, conditions, and flags + * are mapped directly from the SCSI/ATA flag values. Any additional + * SCSI/ATA zone types or conditions or flags that are defined in the + * future could result in additional values that are not yet defined here. + */ + struct disk_zone_rep_entry { + uint8_t zone_type; + #define DISK_ZONE_TYPE_CONVENTIONAL 0x01 + #define DISK_ZONE_TYPE_SEQ_REQUIRED 0x02 /* Host Managed */ + #define DISK_ZONE_TYPE_SEQ_PREFERRED 0x03 /* Host Aware */ + uint8_t zone_condition; + #define DISK_ZONE_COND_NOT_WP 0x00 + #define DISK_ZONE_COND_EMPTY 0x01 + #define DISK_ZONE_COND_IMPLICIT_OPEN 0x02 + #define DISK_ZONE_COND_EXPLICIT_OPEN 0x03 + #define DISK_ZONE_COND_CLOSED 0x04 + #define DISK_ZONE_COND_READONLY 0x0D + #define DISK_ZONE_COND_FULL 0x0E + #define DISK_ZONE_COND_OFFLINE 0x0F + uint8_t zone_flags; + #define DISK_ZONE_FLAG_RESET 0x01 /* Zone needs RWP */ + #define DISK_ZONE_FLAG_NON_SEQ 0x02 /* Zone accssessed nonseq */ + uint64_t zone_length; + uint64_t zone_start_lba; + uint64_t write_pointer_lba; + /* XXX KDM padding space may not be a good idea inside the bio */ + uint8_t reserved[32]; + }; + + struct disk_zone_report { + uint64_t starting_id; /* Passed In */ + uint8_t rep_options; /* Passed In */ + #define DISK_ZONE_REP_ALL 0x00 + #define DISK_ZONE_REP_EMPTY 0x01 + #define DISK_ZONE_REP_IMP_OPEN 0x02 + #define DISK_ZONE_REP_EXP_OPEN 0x03 + #define DISK_ZONE_REP_CLOSED 0x04 + #define DISK_ZONE_REP_FULL 0x05 + #define DISK_ZONE_REP_READONLY 0x06 + #define DISK_ZONE_REP_OFFLINE 0x07 + #define DISK_ZONE_REP_RWP 0x10 + #define DISK_ZONE_REP_NON_SEQ 0x11 + #define DISK_ZONE_REP_NON_WP 0x3F + struct disk_zone_rep_header header; + uint32_t entries_allocated; /* Passed In */ + uint32_t entries_filled; /* Passed Out */ + uint32_t entries_available; /* Passed Out */ + struct disk_zone_rep_entry *entries; + }; + + union disk_zone_params { + struct disk_zone_disk_params disk_params; + struct disk_zone_rwp rwp; + struct disk_zone_report report; + }; + + struct disk_zone_args { + uint8_t zone_cmd; + #define DISK_ZONE_OPEN 0x00 + #define DISK_ZONE_CLOSE 0x01 + #define DISK_ZONE_FINISH 0x02 + #define DISK_ZONE_REPORT_ZONES 0x03 + #define DISK_ZONE_RWP 0x04 + #define DISK_ZONE_GET_PARAMS 0x05 + union disk_zone_params zone_params; + }; + + #endif /* _SYS_DISK_ZONE_H_ */ ==== - //depot/users/kenm/FreeBSD-stable2/10/sys/sys/disk_zone.h#1 ==== *** src/usr.sbin/Makefile.orig --- src/usr.sbin/Makefile *************** *** 93,99 **** wake \ watch \ watchdogd \ ! zic # NB: keep these sorted by MK_* knobs --- 93,100 ---- wake \ watch \ watchdogd \ ! zic \ ! zonectl # NB: keep these sorted by MK_* knobs *** src/usr.sbin/diskinfo/diskinfo.c.orig --- src/usr.sbin/diskinfo/diskinfo.c *************** *** 1,5 **** --- 1,6 ---- /*- * Copyright (c) 2003 Poul-Henning Kamp + * Copyright (c) 2015 Spectra Logic Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without *************** *** 54,67 **** static void speeddisk(int fd, off_t mediasize, u_int sectorsize); static void commandtime(int fd, off_t mediasize, u_int sectorsize); int main(int argc, char **argv) { int i, ch, fd, error, exitval = 0; char buf[BUFSIZ], ident[DISK_IDENT_SIZE], physpath[MAXPATHLEN]; off_t mediasize, stripesize, stripeoffset; ! u_int sectorsize, fwsectors, fwheads; while ((ch = getopt(argc, argv, "ctv")) != -1) { switch (ch) { --- 55,72 ---- static void speeddisk(int fd, off_t mediasize, u_int sectorsize); static void commandtime(int fd, off_t mediasize, u_int sectorsize); + static int zonecheck(int fd, uint32_t *zone_mode, char *zone_str, + size_t zone_str_len); int main(int argc, char **argv) { int i, ch, fd, error, exitval = 0; char buf[BUFSIZ], ident[DISK_IDENT_SIZE], physpath[MAXPATHLEN]; + char zone_desc[64]; off_t mediasize, stripesize, stripeoffset; ! u_int sectorsize, fwsectors, fwheads, zoned = 0; ! uint32_t zone_mode; while ((ch = getopt(argc, argv, "ctv")) != -1) { switch (ch) { *************** *** 121,126 **** --- 126,134 ---- error = ioctl(fd, DIOCGSTRIPEOFFSET, &stripeoffset); if (error) stripeoffset = 0; + error = zonecheck(fd, &zone_mode, zone_desc, sizeof(zone_desc)); + if (error == 0) + zoned = 1; if (!opt_v) { printf("%s", argv[i]); printf("\t%u", sectorsize); *************** *** 155,160 **** --- 163,170 ---- printf("\t%-12s\t# Disk ident.\n", ident); if (ioctl(fd, DIOCGPHYSPATH, physpath) == 0) printf("\t%-12s\t# Physical path\n", physpath); + if (zoned != 0) + printf("\t%-12s\t# Zone Mode\n", zone_desc); } printf("\n"); if (opt_c) *************** *** 386,388 **** --- 396,434 ---- printf("\n"); return; } + + static int + zonecheck(int fd, uint32_t *zone_mode, char *zone_str, size_t zone_str_len) + { + struct disk_zone_args zone_args; + int error; + + bzero(&zone_args, sizeof(zone_args)); + + zone_args.zone_cmd = DISK_ZONE_GET_PARAMS; + error = ioctl(fd, DIOCZONECMD, &zone_args); + + if (error == 0) { + *zone_mode = zone_args.zone_params.disk_params.zone_mode; + + switch (*zone_mode) { + case DISK_ZONE_MODE_NONE: + snprintf(zone_str, zone_str_len, "Not_Zoned"); + break; + case DISK_ZONE_MODE_HOST_AWARE: + snprintf(zone_str, zone_str_len, "Host_Aware"); + break; + case DISK_ZONE_MODE_DRIVE_MANAGED: + snprintf(zone_str, zone_str_len, "Drive_Managed"); + break; + case DISK_ZONE_MODE_HOST_MANAGED: + snprintf(zone_str, zone_str_len, "Host_Managed"); + break; + default: + snprintf(zone_str, zone_str_len, "Unknown_zone_mode_%u", + *zone_mode); + break; + } + } + return (error); + } *** /dev/null Mon Jan 18 15:15:01 2016 --- src/usr.sbin/zonectl/Makefile Mon Jan 18 15:15:18 2016 *************** *** 0 **** --- 1,11 ---- + # $FreeBSD$ + + PROG= zonectl + SRCS= zonectl.c + SDIR= ${.CURDIR}/../../sys + DPADD= ${LIBCAM} ${LIBSBUF} ${LIBUTIL} + LDADD= -lcam -lsbuf -lutil + MAN= zonectl.8 + CFLAGS+=-g -O0 + + .include ==== - //depot/users/kenm/FreeBSD-stable2/10/usr.sbin/zonectl/Makefile#1 ==== *** /dev/null Mon Jan 18 15:15:01 2016 --- src/usr.sbin/zonectl/zonectl.8 Mon Jan 18 15:15:18 2016 *************** *** 0 **** --- 1,236 ---- + .\" + .\" Copyright (c) 2015 Spectra Logic Corporation + .\" All rights reserved. + .\" + .\" Redistribution and use in source and binary forms, with or without + .\" modification, are permitted provided that the following conditions + .\" are met: + .\" 1. Redistributions of source code must retain the above copyright + .\" notice, this list of conditions, and the following disclaimer, + .\" without modification. + .\" 2. Redistributions in binary form must reproduce at minimum a disclaimer + .\" substantially similar to the "NO WARRANTY" disclaimer below + .\" ("Disclaimer") and any redistribution must be conditioned upon + .\" including a substantially similar Disclaimer requirement for further + .\" binary redistribution. + .\" + .\" NO WARRANTY + .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + .\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + .\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + .\" HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + .\" POSSIBILITY OF SUCH DAMAGES. + .\" + .\" Authors: Ken Merry (Spectra Logic Corporation) + .\" + .\" $FreeBSD$ + .\" + .Dd October 16, 2015 + .Dt ZONECTL 8 + .Os + .Sh NAME + .Nm zonectl + .Nd Shingled Magnetic Recording Zone Control utility + .Sh SYNOPSIS + .Nm + .Aq Fl d Ar dev + .Aq Fl c Ar cmd + .Op Fl a + .Op Fl l Ar LBA + .Op Fl o Ar rep_opts + .Op Fl P Ar print_opts + .Sh DESCRIPTION + Manage + .Tn SCSI + and + .Tn ATA + Zoned Block devices. + This allows managing devices that conform to the + .Tn SCSI + Zoned Block Commands (ZBC) and + .Tn ATA + Zoned ATA Command Set (ZAC) + specifications. + Devices using these command sets are usually hard drives using Shingled + Magnetic Recording (SMR). + There are three types of SMR drives: + .Bl -tag -width 13n + .It Drive Managed + Drive Managed drives look and act just like a standard random access block + device, but underneath, the drive reads and writes the bulk of its capacity + using SMR zones. + Sequential writes will yield better performance, but writing sequentially + is not required. + .It Host Aware + Host Aware drives expose the underlying zone layout via + .Tn SCSI + or + .Tn ATA + commands and allow the host to manage the zone conditions. + The host is not required to manage the zones on the drive, though. + Sequential writes will yield better performance in Sequential Write + Preferred zones, but the host can write randomly in those zones. + .It Host Managed + Host Managed drives expose the underlying zone layout via + .Tn SCSI + or + .Tn ATA + commands. + The host is required to access the zones according to the rules described + by the zone layout. + Any commands that violate the rules will be returned with an error. + .El + .Pp + SMR drives are divided into zones (typically in the range of 256MB each) + that fall into three general categories: + .Bl -tag -width 20n + .It Conventional + These are also known as Non Write Pointer zones. + These zones can be randomly written without an unexpected performance penalty. + .It Sequential Preferred + These zones should be written sequentially starting at the write pointer + for the zone. + They may be written randomly. + Writes that do not conform to the zone layout may be significantly slower + than expected. + .It Sequential Required + These zones must be written sequentially. + If they are not written sequentially, starting at the write pointer, the + command will fail. + .El + .Pp + .Bl -tag -width 12n + .It Fl c Ar cmd + Specify the zone subcommand: + .Bl -tag -width 6n + .It params + Display device parameters, including the type of device (Drive Managed, + Host Aware, Host Managed, Not Zoned), the zone commands supported, and + how many open zones it supports. + .It rz + Issue the Report Zones command. + All zones are returned by default. + Specify report options with + .Fl o + and printing options with + .Fl P . + Specify the starting LBA with + .Fl l . + Note that + .Dq reportzones + is also accepted as a command argument. + .It open + Explicitly open the zone specified by the starting LBA. + .It close + Close the zone specified by starting LBA. + .It finish + Finish the zone specified by the starting LBA. + .It rwp + Reset the write pointer for the zone specified by the starting LBA. + .El + .It Fl a + For the Open, Close, Finish and Reset Write Pointer operations, apply the + operation to all zones on the drive. + .It Fl l Ar lba + Specify the starting LBA. + For the Report Zones command, this tells the drive to report starting with + the zone that starts at the given LBA. + For the other commands, this allows the user to identify the zone requested + by its starting LBA. + The LBA may be specified in decimal, hexadecimal or octal notation. + .It Fl o Ar rep_opt + For the Report Zones command, specify a subset of zones to report. + .Bl -tag -width 8n + .It all + Report all zones. + This is the default. + .It emtpy + Report only empty zones. + .It imp_open + Report zones that are implicitly open. + This means that the host has sent a write to the zone without explicitly + opening the zone. + .It exp_open + Report zones that are explicitly open. + .It closed + Report zones that have been closed by the host. + .It full + Report zones that are full. + .It ro + Report zones that are in the read only state. + Note that + .Dq readonly + is also accepted as an argument. + .It offline + Report zones that are in the offline state. + .It reset + Report zones that the device recommends should have their write pointers reset. + .It nonseq + Report zones that have the Non Sequential Resources Active flag set. + These are zones that are Sequential Write Preferred, but have been written + non-sequentially. + .It nonwp + Report Non Write Pointer zones, also known as Conventional zones. + .El + .It Fl P Ar print_opt + Specify a printing option for Report Zones: + .Bl -tag -width 7n + .It normal + Normal Report Zones output. + This is the default. + The summary and column headings are printed, fields are separated by spaces + and the fields themselves may contain spaces. + .It summary + Just print the summary: the number of zones, the maximum LBA (LBA of the + last logical block on the drive), and the value of the + .Dq same + field. + The + .Dq same + field describes whether the zones on the drive are all identical, all + different, or whether they are the same except for the last zone, etc. + .It script + Print the zones in a script friendly format. + The summary and column headings are omitted, the fields are separated by + commas, and the fields do not contain spaces. + The fields contain underscores where spaces would normally be used. + .El + .El + .Sh EXAMPLES + .Bd -literal -offset indent + zonectl -d /dev/da5 -c params + .Ed + .Pp + This will display basic zoning information for disk da5. + .Pp + .Bd -literal -offset indent + zonectl -d /dev/da5 -c rz + .Ed + .Pp + This will issue the Report Zones command to disk da5, and print out all + zones on the drive in the default format. + .Pp + .Bd -literal -offset indent + zonectl -d /dev/da5 -c rz -o reset -P script + .Ed + .Pp + This will issue the Report Zones command to disk da5, and print out all + of the zones that have the Reset Write Pointer Recommended bit set to true. + It will print the zones in a script friendly form. + .Pp + .Bd -literal -offset indent + zonectl -d /dev/da5 -c rwp -l 0x2c80000 + .Ed + .Pp + This will issue the Reset Write Pointer command to disk da5 for the zone + that starts at LBA 0x2c80000. + .Pp + .Bd -literal -offset indent + .Sh AUTHORS + .An Kenneth Merry Aq ken@FreeBSD.org ==== - //depot/users/kenm/FreeBSD-stable2/10/usr.sbin/zonectl/zonectl.8#2 ==== *** /dev/null Mon Jan 18 15:15:01 2016 --- src/usr.sbin/zonectl/zonectl.c Mon Jan 18 15:15:18 2016 *************** *** 0 **** --- 1,591 ---- + /*- + * Copyright (c) 2015 Spectra Logic Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * Authors: Ken Merry (Spectra Logic Corporation) + */ + + #include + __FBSDID("$FreeBSD$"); + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + + #include + #include + #include + #include + + static struct scsi_nv zone_cmd_map[] = { + { "rz", DISK_ZONE_REPORT_ZONES }, + { "reportzones", DISK_ZONE_REPORT_ZONES }, + { "close", DISK_ZONE_CLOSE }, + { "finish", DISK_ZONE_FINISH }, + { "open", DISK_ZONE_OPEN }, + { "rwp", DISK_ZONE_RWP }, + { "params", DISK_ZONE_GET_PARAMS } + }; + + static struct scsi_nv zone_rep_opts[] = { + { "all", DISK_ZONE_REP_ALL }, + { "empty", DISK_ZONE_REP_EMPTY }, + { "imp_open", DISK_ZONE_REP_IMP_OPEN }, + { "exp_open", DISK_ZONE_REP_EXP_OPEN }, + { "closed", DISK_ZONE_REP_CLOSED }, + { "full", DISK_ZONE_REP_FULL }, + { "readonly", DISK_ZONE_REP_READONLY }, + { "ro", DISK_ZONE_REP_READONLY }, + { "offline", DISK_ZONE_REP_OFFLINE }, + { "reset", DISK_ZONE_REP_RWP }, + { "rwp", DISK_ZONE_REP_RWP }, + { "nonseq", DISK_ZONE_REP_NON_SEQ }, + { "nonwp", DISK_ZONE_REP_NON_WP } + }; + + + typedef enum { + ZONE_OF_NORMAL = 0x00, + ZONE_OF_SUMMARY = 0x01, + ZONE_OF_SCRIPT = 0x02 + } zone_output_flags; + + static struct scsi_nv zone_print_opts[] = { + { "normal", ZONE_OF_NORMAL }, + { "summary", ZONE_OF_SUMMARY }, + { "script", ZONE_OF_SCRIPT } + }; + + static struct scsi_nv zone_cmd_desc_table[] = { + {"Report Zones", DISK_ZONE_RZ_SUP }, + {"Open", DISK_ZONE_OPEN_SUP }, + {"Close", DISK_ZONE_CLOSE_SUP }, + {"Finish", DISK_ZONE_FINISH_SUP }, + {"Reset Write Pointer", DISK_ZONE_RWP_SUP } + }; + + typedef enum { + ZONE_PRINT_OK, + ZONE_PRINT_MORE_DATA, + ZONE_PRINT_ERROR + } zone_print_status; + + typedef enum { + ZONE_FW_START, + ZONE_FW_LEN, + ZONE_FW_WP, + ZONE_FW_TYPE, + ZONE_FW_COND, + ZONE_FW_SEQ, + ZONE_FW_RESET, + ZONE_NUM_FIELDS + } zone_field_widths; + + + static void usage(int error); + static void zonectl_print_params(struct disk_zone_disk_params *params); + zone_print_status zonectl_print_rz(struct disk_zone_report *report, + zone_output_flags out_flags, int first_pass); + + static void + usage(int error) + { + fprintf(error ? stderr : stdout, + "usage: zonectl <-d dev> <-c cmd> [-a][-o rep_opts] [-l lba][-P print_opts]\n" + ); + } + + static void + zonectl_print_params(struct disk_zone_disk_params *params) + { + unsigned int i; + int first; + + printf("Zone Mode: "); + switch (params->zone_mode) { + case DISK_ZONE_MODE_NONE: + printf("None"); + break; + case DISK_ZONE_MODE_HOST_AWARE: + printf("Host Aware"); + break; + case DISK_ZONE_MODE_DRIVE_MANAGED: + printf("Drive Managed"); + break; + case DISK_ZONE_MODE_HOST_MANAGED: + printf("Host Managed"); + break; + default: + printf("Unknown mode %#x", params->zone_mode); + break; + } + printf("\n"); + + first = 1; + printf("Command support: "); + for (i = 0; i < sizeof(zone_cmd_desc_table) / + sizeof(zone_cmd_desc_table[0]); i++) { + if (params->flags & zone_cmd_desc_table[i].value) { + if (first == 0) + printf(", "); + else + first = 0; + printf("%s", zone_cmd_desc_table[i].name); + } + } + if (first == 1) + printf("None"); + printf("\n"); + + printf("Unrestricted Read in Sequential Write Required Zone " + "(URSWRZ): %s\n", (params->flags & DISK_ZONE_DISK_URSWRZ) ? + "Yes" : "No"); + + printf("Optimal Number of Open Sequential Write Preferred Zones: "); + if (params->flags & DISK_ZONE_OPT_SEQ_SET) + if (params->optimal_seq_zones == SVPD_ZBDC_OPT_SEQ_NR) + printf("Not Reported"); + else + printf("%ju", (uintmax_t)params->optimal_seq_zones); + else + printf("Not Set"); + printf("\n"); + + + printf("Optimal Number of Non-Sequentially Written Sequential Write " + "Preferred Zones: "); + if (params->flags & DISK_ZONE_OPT_NONSEQ_SET) + if (params->optimal_nonseq_zones == SVPD_ZBDC_OPT_NONSEQ_NR) + printf("Not Reported"); + else + printf("%ju",(uintmax_t)params->optimal_nonseq_zones); + else + printf("Not Set"); + printf("\n"); + + printf("Maximum Number of Open Sequential Write Required Zones: "); + if (params->flags & DISK_ZONE_MAX_SEQ_SET) + if (params->max_seq_zones == SVPD_ZBDC_MAX_SEQ_UNLIMITED) + printf("Unlimited"); + else + printf("%ju", (uintmax_t)params->max_seq_zones); + else + printf("Not Set"); + printf("\n"); + } + + zone_print_status + zonectl_print_rz(struct disk_zone_report *report, zone_output_flags out_flags, + int first_pass) + { + zone_print_status status = ZONE_PRINT_OK; + struct disk_zone_rep_header *header = &report->header; + int field_widths[ZONE_NUM_FIELDS]; + struct disk_zone_rep_entry *entry; + uint64_t next_lba = 0; + char tmpstr[80]; + char word_sep; + int more_data = 0; + uint32_t i; + + field_widths[ZONE_FW_START] = 11; + field_widths[ZONE_FW_LEN] = 6; + field_widths[ZONE_FW_WP] = 11; + field_widths[ZONE_FW_TYPE] = 13; + field_widths[ZONE_FW_COND] = 13; + field_widths[ZONE_FW_SEQ] = 14; + field_widths[ZONE_FW_RESET] = 16; + + if ((report->entries_available - report->entries_filled) > 0) { + more_data = 1; + status = ZONE_PRINT_MORE_DATA; + } + + if (out_flags == ZONE_OF_SCRIPT) + word_sep = '_'; + else + word_sep = ' '; + + if ((out_flags != ZONE_OF_SCRIPT) + && (first_pass != 0)) { + printf("%u zones, Maximum LBA %#jx (%ju)\n", + report->entries_available, + (uintmax_t)header->maximum_lba, + (uintmax_t)header->maximum_lba); + + switch (header->same) { + case DISK_ZONE_SAME_ALL_DIFFERENT: + printf("Zone lengths and types may vary\n"); + break; + case DISK_ZONE_SAME_ALL_SAME: + printf("Zone lengths and types are all the same\n"); + break; + case DISK_ZONE_SAME_LAST_DIFFERENT: + printf("Zone types are the same, last zone length " + "differs\n"); + break; + case DISK_ZONE_SAME_TYPES_DIFFERENT: + printf("Zone lengths are the same, types vary\n"); + break; + default: + printf("Unknown SAME field value %#x\n",header->same); + break; + } + } + if (out_flags == ZONE_OF_SUMMARY) { + status = ZONE_PRINT_OK; + goto bailout; + } + + if ((out_flags == ZONE_OF_NORMAL) + && (first_pass != 0)) { + printf("%*s %*s %*s %*s %*s %*s %*s\n", + field_widths[ZONE_FW_START], "Start LBA", + field_widths[ZONE_FW_LEN], "Length", + field_widths[ZONE_FW_WP], "WP LBA", + field_widths[ZONE_FW_TYPE], "Zone Type", + field_widths[ZONE_FW_COND], "Condition", + field_widths[ZONE_FW_SEQ], "Sequential", + field_widths[ZONE_FW_RESET], "Reset"); + } + + for (i = 0; i < report->entries_filled; i++) { + entry = &report->entries[i]; + + printf("%#*jx, %*ju, %#*jx, ", field_widths[ZONE_FW_START], + (uintmax_t)entry->zone_start_lba, + field_widths[ZONE_FW_LEN], + (uintmax_t)entry->zone_length, field_widths[ZONE_FW_WP], + (uintmax_t)entry->write_pointer_lba); + + switch (entry->zone_type) { + case DISK_ZONE_TYPE_CONVENTIONAL: + snprintf(tmpstr, sizeof(tmpstr), "Conventional"); + break; + case DISK_ZONE_TYPE_SEQ_PREFERRED: + case DISK_ZONE_TYPE_SEQ_REQUIRED: + snprintf(tmpstr, sizeof(tmpstr), "Seq%c%s", + word_sep, (entry->zone_type == + DISK_ZONE_TYPE_SEQ_PREFERRED) ? "Preferred" : + "Required"); + break; + default: + snprintf(tmpstr, sizeof(tmpstr), "Zone%ctype%c%#x", + word_sep, word_sep, entry->zone_type); + break; + } + printf("%*s, ", field_widths[ZONE_FW_TYPE], tmpstr); + + switch (entry->zone_condition) { + case DISK_ZONE_COND_NOT_WP: + snprintf(tmpstr, sizeof(tmpstr), "NWP"); + break; + case DISK_ZONE_COND_EMPTY: + snprintf(tmpstr, sizeof(tmpstr), "Empty"); + break; + case DISK_ZONE_COND_IMPLICIT_OPEN: + snprintf(tmpstr, sizeof(tmpstr), "Implicit%cOpen", + word_sep); + break; + case DISK_ZONE_COND_EXPLICIT_OPEN: + snprintf(tmpstr, sizeof(tmpstr), "Explicit%cOpen", + word_sep); + break; + case DISK_ZONE_COND_CLOSED: + snprintf(tmpstr, sizeof(tmpstr), "Closed"); + break; + case DISK_ZONE_COND_READONLY: + snprintf(tmpstr, sizeof(tmpstr), "Readonly"); + break; + case DISK_ZONE_COND_FULL: + snprintf(tmpstr, sizeof(tmpstr), "Full"); + break; + case DISK_ZONE_COND_OFFLINE: + snprintf(tmpstr, sizeof(tmpstr), "Offline"); + break; + default: + snprintf(tmpstr, sizeof(tmpstr), "%#x", + entry->zone_condition); + break; + } + + printf("%*s, ", field_widths[ZONE_FW_COND], tmpstr); + + if (entry->zone_flags & DISK_ZONE_FLAG_NON_SEQ) + snprintf(tmpstr, sizeof(tmpstr), "Non%cSequential", + word_sep); + else + snprintf(tmpstr, sizeof(tmpstr), "Sequential"); + + printf("%*s, ", field_widths[ZONE_FW_SEQ], tmpstr); + + if (entry->zone_flags & DISK_ZONE_FLAG_RESET) + snprintf(tmpstr, sizeof(tmpstr), "Reset%cNeeded", + word_sep); + else + snprintf(tmpstr, sizeof(tmpstr), "No%cReset%cNeeded", + word_sep, word_sep); + + printf("%*s\n", field_widths[ZONE_FW_RESET], tmpstr); + + next_lba = entry->zone_start_lba + entry->zone_length; + } + bailout: + report->starting_id = next_lba; + + return (status); + } + + int + main(int argc, char **argv) + { + int c; + int all_zones = 0; + int error = 0; + int action = -1, rep_option = -1; + int fd = -1; + uint64_t lba = 0; + zone_output_flags out_flags = ZONE_OF_NORMAL; + char *filename = NULL; + struct disk_zone_args zone_args; + struct disk_zone_rep_entry *entries = NULL; + uint32_t num_entries = 2048; + zone_print_status zp_status; + int first_pass = 1; + size_t entry_alloc_size; + int open_flags = O_RDONLY; + + while ((c = getopt(argc, argv, "ac:d:hl:o:P:?")) != -1) { + switch (c) { + case 'a': + all_zones = 1; + break; + case 'c': { + scsi_nv_status status; + int entry_num; + + status = scsi_get_nv(zone_cmd_map, + (sizeof(zone_cmd_map) / sizeof(zone_cmd_map[0])), + optarg, &entry_num, SCSI_NV_FLAG_IG_CASE); + if (status == SCSI_NV_FOUND) + action = zone_cmd_map[entry_num].value; + else { + warnx("%s: %s: %s option %s", __func__, + (status == SCSI_NV_AMBIGUOUS) ? + "ambiguous" : "invalid", "zone command", + optarg); + error = 1; + goto bailout; + } + break; + } + case 'd': + filename = strdup(optarg); + if (filename == NULL) + err(1, "Unable to allocate memory for " + "filename"); + break; + case 'l': { + char *endptr; + + lba = strtoull(optarg, &endptr, 0); + if (*endptr != '\0') { + warnx("%s: invalid lba argument %s", __func__, + optarg); + error = 1; + goto bailout; + } + break; + } + case 'o': { + scsi_nv_status status; + int entry_num; + + status = scsi_get_nv(zone_rep_opts, + (sizeof(zone_rep_opts) / + sizeof(zone_rep_opts[0])), + optarg, &entry_num, SCSI_NV_FLAG_IG_CASE); + if (status == SCSI_NV_FOUND) + rep_option = zone_rep_opts[entry_num].value; + else { + warnx("%s: %s: %s option %s", __func__, + (status == SCSI_NV_AMBIGUOUS) ? + "ambiguous" : "invalid", "report zones", + optarg); + error = 1; + goto bailout; + } + break; + } + case 'P': { + scsi_nv_status status; + int entry_num; + + status = scsi_get_nv(zone_print_opts, + (sizeof(zone_print_opts) / + sizeof(zone_print_opts[0])), optarg, &entry_num, + SCSI_NV_FLAG_IG_CASE); + if (status == SCSI_NV_FOUND) + out_flags = zone_print_opts[entry_num].value; + else { + warnx("%s: %s: %s option %s", __func__, + (status == SCSI_NV_AMBIGUOUS) ? + "ambiguous" : "invalid", "print", + optarg); + error = 1; + goto bailout; + } + break; + } + default: + error = 1; + case 'h': /*FALLTHROUGH*/ + usage(error); + goto bailout; + break; /*NOTREACHED*/ + } + } + + if (filename == NULL) { + warnx("You must specify a device with -d"); + error = 1; + } + if (action == -1) { + warnx("You must specify an action with -c"); + error = 1; + } + + if (error != 0) { + usage(error); + goto bailout; + } + + bzero(&zone_args, sizeof(zone_args)); + + zone_args.zone_cmd = action; + + switch (action) { + case DISK_ZONE_OPEN: + case DISK_ZONE_CLOSE: + case DISK_ZONE_FINISH: + case DISK_ZONE_RWP: + open_flags = O_RDWR; + zone_args.zone_params.rwp.id = lba; + if (all_zones != 0) + zone_args.zone_params.rwp.flags |= + DISK_ZONE_RWP_FLAG_ALL; + break; + case DISK_ZONE_REPORT_ZONES: { + entry_alloc_size = num_entries * + sizeof(struct disk_zone_rep_entry); + entries = malloc(entry_alloc_size); + if (entries == NULL) { + warn("Could not allocate %zu bytes", + entry_alloc_size); + error = 1; + goto bailout; + } + zone_args.zone_params.report.entries_allocated = num_entries; + zone_args.zone_params.report.entries = entries; + zone_args.zone_params.report.starting_id = lba; + if (rep_option != -1) + zone_args.zone_params.report.rep_options = rep_option; + break; + } + case DISK_ZONE_GET_PARAMS: + break; + default: + warnx("Unknown action %d", action); + error = 1; + goto bailout; + break; /*NOTREACHED*/ + } + + fd = open(filename, open_flags); + if (fd == -1) { + warn("Unable to open device %s", filename); + error = 1; + goto bailout; + } + next_chunk: + error = ioctl(fd, DIOCZONECMD, &zone_args); + if (error == -1) { + warn("DIOCZONECMD ioctl failed"); + error = 1; + goto bailout; + } + + switch (action) { + case DISK_ZONE_OPEN: + case DISK_ZONE_CLOSE: + case DISK_ZONE_FINISH: + case DISK_ZONE_RWP: + break; + case DISK_ZONE_REPORT_ZONES: + zp_status = zonectl_print_rz(&zone_args.zone_params.report, + out_flags, first_pass); + if (zp_status == ZONE_PRINT_MORE_DATA) { + first_pass = 0; + bzero(entries, entry_alloc_size); + zone_args.zone_params.report.entries_filled = 0; + goto next_chunk; + } else if (zp_status == ZONE_PRINT_ERROR) + error = 1; + break; + case DISK_ZONE_GET_PARAMS: + zonectl_print_params(&zone_args.zone_params.disk_params); + break; + default: + warnx("Unknown action %d", action); + error = 1; + goto bailout; + break; /*NOTREACHED*/ + } + bailout: + free(entries); + + if (fd != -1) + close(fd); + exit (error); + } ==== - //depot/users/kenm/FreeBSD-stable2/10/usr.sbin/zonectl/zonectl.c#2 ====