Add support for managing Shingled Magnetic Recording (SMR) drives.

This change includes support for SCSI SMR drives (which conform to the
Zoned Block Commands or ZBC spec) and ATA SMR drives (which conform to
the Zoned ATA Command Set or ZAC spec) behind SAS expanders.

This includes full management support through the GEOM BIO interface, and
through a new userland utility, zonectl(8), and through camcontrol(8).

This is now ready for filesystems to use to detect and manage zoned drives.
(There is no work in progress that I know of to use this for ZFS or UFS, if
anyone is interested, let me know and I may have some suggestions.)

Also, improve ATA command passthrough and dispatch support, both via ATA
and ATA passthrough over SCSI.

Also, add support to camcontrol(8) for the ATA Extended Power Conditions
feature set.  You can now manage ATA device power states, and set various
idle time thresholds for a drive to enter lower power states.

Note that this change cannot be MFCed in full, because it depends on
changes to the struct bio API that break compatilibity.  In order to
avoid breaking the stable API, only changes that don't touch or depend on
the struct bio changes can be merged.  For example, the camcontrol(8)
changes don't depend on the new bio API, but zonectl(8) and the probe
changes to the da(4) and ada(4) drivers do depend on it.

Also note that the SMR changes have not yet been tested with an actual
SCSI ZBC device, or a SCSI to ATA translation layer (SAT) that supports
ZBC to ZAC translation.  I have not yet gotten a suitable drive or SAT
layer, so any testing help would be appreciated.  These changes have been
tested with Seagate Host Aware SATA drives attached to both SAS and SATA
controllers.  Also, I do not have any SATA Host Managed devices, and I
suspect that it may take additional (hopefully minor) changes to support
them.

Thanks to Seagate for supplying the test hardware and answering questions.

sbin/camcontrol/Makefile:
	Add epc.c and zone.c.

sbin/camcontrol/camcontrol.8:
	Document the zone and epc subcommands.

sbin/camcontrol/camcontrol.c:
	Add the zone and epc subcommands.

	Add auxiliary register support to build_ata_cmd().  Make sure to
	set the CAM_ATAIO_NEEDRESULT, CAM_ATAIO_DMA, and CAM_ATAIO_FPDMA
	flags as appropriate for ATA commands.

	Add a new get_ata_status() function to parse ATA result from SCSI
	sense descriptors (for ATA passthrough over SCSI) and ATA I/O
	requests.

sbin/camcontrol/camcontrol.h:
	Update the build_ata_cmd() prototype

	Add get_ata_status(), zone(), and epc().

sbin/camcontrol/epc.c:
	Support for ATA Extended Power Conditions features.  This includes
	support for all features documented in the ACS-4 Revision 12
	specification from t13.org (dated February 18, 2016).

	The EPC feature set allows putting a drive into a power power mode
	immediately, or setting timeouts so that the drive will
	automatically enter progressively lower power states after various
	idle times.

sbin/camcontrol/fwdownload.c:
	Update the firmware download code for the new build_ata_cmd()
	arguments.

sbin/camcontrol/zone.c:
	Implement support for Shingled Magnetic Recording (SMR) drives
	via SCSI Zoned Block Commands (ZBC) and ATA Zoned Device ATA
	Command Set (ZAC).

	These specs were developed in concert, and are functionally
	identical.  The primary differences are due to SCSI and ATA
	differences.  (SCSI is big endian, ATA is little endian, for
	example.)

	This includes support for all commands defined in the ZBC and
	ZAC specs.

sys/cam/ata/ata_all.c:
	Decode a number of additional ATA command names in ata_op_string().

	Add a new CCB building function, ata_read_log().

	Add ata_zac_mgmt_in() and ata_zac_mgmt_out() CCB building
	functions.  These support both DMA and NCQ encapsulation.

sys/cam/ata/ata_all.h:
	Add prototypes for ata_read_log(), ata_zac_mgmt_out(), and
	ata_zac_mgmt_in().

sys/cam/ata/ata_da.c:
	Revamp the ada(4) driver to support zoned devices.

	Add four new probe states to gather information needed for zone
	support.

	Add a new adasetflags() function to avoid duplication of large
	blocks of flag setting between the async handler and register
	functions.

	Add new sysctl variables that describe zone support and paramters.

	Add support for the new BIO_ZONE bio, and all of its subcommands:
	DISK_ZONE_OPEN, DISK_ZONE_CLOSE, DISK_ZONE_FINISH, DISK_ZONE_RWP,
	DISK_ZONE_REPORT_ZONES, and DISK_ZONE_GET_PARAMS.

sys/cam/scsi/scsi_all.c:
	Add command descriptions for the ZBC IN/OUT commands.

	Add descriptions for ZBC Host Managed devices.

	Add a new function, scsi_ata_pass() to do ATA passthrough over
	SCSI.  This will eventually replace scsi_ata_pass_16() -- it
	can create the 12, 16, and 32-byte variants of the ATA
	PASS-THROUGH command, and supports setting all of the
	registers defined as of SAT-4, Revision 5 (March 11, 2016).

	Change scsi_ata_identify() to use scsi_ata_pass() instead of
	scsi_ata_pass_16().

	Add a new scsi_ata_read_log() function to facilitate reading
	ATA logs via SCSI.

sys/cam/scsi/scsi_all.h:
	Add the new ATA PASS-THROUGH(32) command CDB.  Add extended and
	variable CDB opcodes.

	Add Zoned Block Device Characteristics VPD page.

	Add ATA Return SCSI sense descriptor.

	Add prototypes for scsi_ata_read_log() and scsi_ata_pass().

sys/cam/scsi/scsi_da.c:
	Revamp the da(4) driver to support zoned devices.

	Add five new probe states, four of which are needed for ATA
	devices.

	Add five new sysctl variables that describe zone support and
	parameters.

	The da(4) driver supports SCSI ZBC devices, as well as ATA ZAC
	devices when they are attached via a SCSI to ATA Translation (SAT)
	layer.  Since ZBC -> ZAC translation is a new feature in the T10
	SAT-4 spec, most SATA drives will be supported via ATA commands
	sent via the SCSI ATA PASS-THROUGH command.  The da(4) driver will
	prefer the ZBC interface, if it is available, for performance
	reasons, but will use the ATA PASS-THROUGH interface to the ZAC
	command set if the SAT layer doesn't support translation yet.
	As I mentioned above, ZBC command support is untested.

	Add support for the new BIO_ZONE bio, and all of its subcommands:
	DISK_ZONE_OPEN, DISK_ZONE_CLOSE, DISK_ZONE_FINISH, DISK_ZONE_RWP,
	DISK_ZONE_REPORT_ZONES, and DISK_ZONE_GET_PARAMS.

	Add scsi_zbc_in() and scsi_zbc_out() CCB building functions.

	Add scsi_ata_zac_mgmt_out() and scsi_ata_zac_mgmt_in() CCB/CDB
	building functions.  Note that these have return values, unlike
	almost all other CCB building functions in CAM.  The reason is
	that they can fail, depending upon the particular combination
	of input parameters.  The primary failure case is if the user
	wants NCQ, but fails to specify additional CDB storage.  NCQ
	requires using the 32-byte version of the SCSI ATA PASS-THROUGH
	command, and the current CAM CDB size is 16 bytes.

sys/cam/scsi/scsi_da.h:
	Add ZBC IN and ZBC OUT CDBs and opcodes.

	Add SCSI Report Zones data structures.

	Add scsi_zbc_in(), scsi_zbc_out(), scsi_ata_zac_mgmt_out(), and
	scsi_ata_zac_mgmt_in() prototypes.

sys/dev/ahci/ahci.c:
	Fix SEND / RECEIVE FPDMA QUEUED in the ahci(4) driver.

	ahci_setup_fis() previously set the top bits of the sector count
	register in the FIS to 0 for FPDMA commands.  This is okay for
	read and write, because the PRIO field is in the only thing in
	those bits, and we don't implement that further up the stack.

	But, for SEND and RECEIVE FPDMA QUEUED, the subcommand is in that
	byte, so it needs to be transmitted to the drive.

	In ahci_setup_fis(), always set the the top 8 bits of the
	sector count register.  We need it in both the standard
	and NCQ / FPDMA cases.

sys/geom/eli/g_eli.c:
	Pass BIO_ZONE commands through the GELI class.

sys/geom/geom.h:
	Add g_io_zonecmd() prototype.

sys/geom/geom_dev.c:
	Add new DIOCZONECMD ioctl, which allows sending zone commands to
	disks.

sys/geom/geom_disk.c:
	Add support for BIO_ZONE commands.

sys/geom/geom_disk.h:
	Add a new flag, DISKFLAG_CANZONE, that indicates that a given
	GEOM disk client can handle BIO_ZONE commands.

sys/geom/geom_io.c:
	Add a new function, g_io_zonecmd(), that handles execution of
	BIO_ZONE commands.

	Add permissions check for BIO_ZONE commands.

	Add command decoding for BIO_ZONE commands.

sys/geom/geom_subr.c:
	Add DDB command decoding for BIO_ZONE commands.

sys/kern/subr_devstat.c:
	Record statistics for REPORT ZONES commands.  Note that the
	number of bytes transferred for REPORT ZONES won't quite match
	what is received from the harware.  This is because we're
	necessarily counting bytes coming from the da(4) / ada(4) drivers,
	which are using the disk_zone.h interface to communicate up
	the stack.  The structure sizes it uses are slightly different
	than the SCSI and ATA structure sizes.

sys/sys/ata.h:
	Add many bit and structure definitions for ZAC, NCQ, and EPC
	command support.

sys/sys/bio.h:
	Convert the bio_cmd field to a straight enumeration.  This will
	yield more space for additional commands in the future.  After
	change r297955 and other related changes, this is now possible.
	Converting to an enumeration will also prevent use as a bitmask
	in the future.

sys/sys/disk.h:
	Define the DIOCZONECMD ioctl.

sys/sys/disk_zone.h:
	Add a new API for managing zoned disks.  This is very close to
	the SCSI ZBC and ATA ZAC standards, but uses integers in native
	byte order instead of big endian (SCSI) or little endian (ATA)
	byte arrays.

	This is intended to offer to the complete feature set of the ZBC
	and ZAC disk management without requiring the application developer
	to include SCSI or ATA headers.  We also use one set of headers
	for ioctl consumers and kernel bio-level consumers.

sys/sys/param.h:
	Bump __FreeBSD_version for sys/bio.h command changes, and inclusion
	of SMR support.

usr.sbin/Makefile:
	Add the zonectl utility.

usr.sbin/diskinfo/diskinfo.c
	Add disk zoning capability to the 'diskinfo -v' output.

usr.sbin/zonectl/Makefile:
	Add zonectl makefile.

usr.sbin/zonectl/zonectl.8
	zonectl(8) man page.

usr.sbin/zonectl/zonectl.c
	The zonectl(8) utility.  This allows managing SCSI or ATA zoned
	disks via the disk_zone.h API.  You can report zones, reset write
	pointers, get parameters, etc.

Sponsored by:	Spectra Logic
Differential Revision:	https://reviews.freebsd.org/D6147
Reviewed by:	wblock (documentation)
This commit is contained in:
Kenneth D. Merry
2016-05-19 14:08:36 +00:00
parent b7c02deed2
commit 9a6844d55f
33 changed files with 7468 additions and 260 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ PACKAGE=runtime
PROG= camcontrol
SRCS= camcontrol.c util.c
.if !defined(RELEASE_CRUNCH)
SRCS+= attrib.c fwdownload.c modeedit.c persist.c progress.c
SRCS+= attrib.c epc.c fwdownload.c modeedit.c persist.c progress.c zone.c
.else
CFLAGS+= -DMINIMALISTIC
.endif
+396 -2
View File
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd April 26, 2016
.Dd May 16, 2016
.Dt CAMCONTROL 8
.Os
.Sh NAME
@@ -323,6 +323,26 @@
.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 epc
.Aq Fl c Ar cmd
.Op Fl d
.Op Fl D
.Op Fl e
.Op Fl H
.Op Fl p Ar power_cond
.Op Fl P
.Op Fl r Ar restore_src
.Op Fl s
.Op Fl S Ar power_src
.Op Fl T Ar timer
.Nm
.Ic help
.Sh DESCRIPTION
The
@@ -2052,11 +2072,11 @@ Valid types are:
.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.
.El
.It Ic opcodes
Issue the REPORT SUPPORTED OPCODES service action of the
.Tn SCSI
@@ -2103,6 +2123,300 @@ for the given command or commands.
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 where the device recommends resetting write pointers.
.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 epc
Issue
.Tn ATA
Extended Power Conditions (EPC) feature set commands.
This only works on
.Tn ATA
protocol drives, and will not work on
.Tn SCSI
protocol drives.
It will work on
.Tn SATA
drives behind a
.Tn SCSI
to
.Tn ATA
translation layer (SAT).
It may be helpful to read the ATA Command Set - 4 (ACS-4) description of
the Extended Power Conditions feature set, available at t13.org, to
understand the details of this particular
.Nm
subcommand.
.Bl -tag -width 6n
.It Fl c Ar cmd
Specify the epc subcommand
.Bl -tag -width 7n
.It restore
Restore drive power condition settings.
.Bl -tag -width 6n
.It Fl r Ar src
Specify the source for the restored power settings, either
.Dq default
or
.Dq saved .
This argument is required.
.It Fl s
Save the settings.
This only makes sense to specify when restoring from defaults.
.El
.It goto
Go to the specified power condition.
.Bl -tag -width 7n
.It Fl p Ar cond
Specify the power condition: Idle_a, Idle_b, Idle_c, Standby_y, Standby_z.
This argument is required.
.It Fl D
Specify delayed entry to the power condition.
The drive, if it supports this, can enter the power condition after the
command completes.
.It Fl H
Hold the power condition.
If the drive supports this option, it will hold the power condition and
reject all commands that would normally cause it to exit that power
condition.
.El
.It timer
Set the timer value for a power condition and enable or disable the
condition.
See the
.Dq list
display described below to see what the current timer settings are for each
Idle and Standby mode supported by the drive.
.Bl -tag -width 8n
.It Fl e
Enable the power condition.
One of
.Fl e
or
.Fl d
is required.
.It Fl d
Disable the power condition.
One of
.Fl d
or
.Fl e
is required.
.It Fl T Ar timer
Specify the timer in seconds.
The user may specify a timer as a floating point number with a maximum
supported resolution of tenths of a second.
Drives may or may not support sub-second timer values.
.It Fl p Ar cond
Specify the power condition: Idle_a, Idle_b, Idle_c, Standby_y, Standby_z.
This argument is required.
.It Fl s
Save the timer and power condition enable/disable state.
By default, if this option is not specified, only the current values for
this power condition will be affected.
.El
.It state
Enable or disable a particular power condition.
.Bl -tag -width 7n
.It Fl p Ar cond
Specify the power condition: Idle_a, Idle_b, Idle_c, Standby_y, Standby_z.
This argument is required.
.It Fl s
Save the power condition enable/disable state.
By default, if this option is not specified, only the current values for
this power condition will be affected.
.El
.It enable
Enable the Extended Power Condition (EPC) feature set.
.It disable
Disable the Extended Power Condition (EPC) feature set.
.It source
Specify the EPC power source.
.Bl -tag -width 6n
.It Fl S Ar src
Specify the power source, either
.Dq battery
or
.Dq nonbattery .
.El
.It status
Get the current status of several parameters related to the Extended Power
Condition (EPC) feature set, including whether APM and EPC are supported
and enabled, whether Low Power Standby is supported, whether setting the
EPC power source is supported, whether Low Power Standby is supported and
the current power condition.
.Bl -tag -width 3n
.It Fl P
Only report the current power condition.
Some drives will exit their current power condition if a command other than
the
.Tn ATA
CHECK POWER MODE command is received.
If this flag is specified,
.Nm
will only issue the
.Tn ATA
CHECK POWER MODE command to the drive.
.El
.It list
Display the
.Tn ATA
Power Conditions log (Log Address 0x08).
This shows the list of Idle and Standby power conditions the drive
supports, and a number of parameters about each condition, including
whether it is enabled and what the timer value is.
.El
.El
.It Ic help
Print out verbose usage information.
.El
@@ -2336,6 +2650,86 @@ This will read and decode the attribute values from partition 1 on the tape
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.
.Pp
.Bd -literal -offset indent
camcontrol epc ada0 -c timer -T 60.1 -p Idle_a -e -s
.Ed
.Pp
Set the timer for the Idle_a power condition on drive
.Pa ada0
to 60.1 seconds, enable that particular power condition, and save the timer
value and the enabled state of the power condition.
.Pp
.Bd -literal -offset indent
camcontrol epc da4 -c goto -p Standby_z -H
.Ed
.Pp
Tell drive
.Pa da4
to go to the Standby_z power state (which is
the drive's lowest power state) and hold in that state until it is
explicitly released by another
.Cm goto
command.
.Pp
.Bd -literal -offset indent
camcontrol epc da2 -c status -P
.Ed
.Pp
Report only the power state of
drive
.Pa da2 .
Some drives will power up in response to the commands sent by the
.Pa status
subcommand, and the
.Fl P
option causes
.Nm
to only send the
.Tn ATA
CHECK POWER MODE command, which should not trigger a change in the drive's
power state.
.Pp
.Bd -literal -offset indent
camcontrol epc ada0 -c list
.Ed
.Pp
Display the ATA Power Conditions log (Log Address 0x08) for
drive
.Pa ada0 .
.Sh SEE ALSO
.Xr cam 3 ,
.Xr cam_cdbparse 3 ,
+205 -6
View File
@@ -101,7 +101,9 @@ typedef enum {
CAM_CMD_AAM = 0x00000022,
CAM_CMD_ATTRIB = 0x00000023,
CAM_CMD_OPCODES = 0x00000024,
CAM_CMD_REPROBE = 0x00000025
CAM_CMD_REPROBE = 0x00000025,
CAM_CMD_ZONE = 0x00000026,
CAM_CMD_EPC = 0x00000027
} cam_cmdmask;
typedef enum {
@@ -230,6 +232,8 @@ static struct camcontrol_opts option_table[] = {
{"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:No:P:"},
{"epc", CAM_CMD_EPC, CAM_ARG_NONE, "c:dDeHp:Pr:sS:T:"},
#endif /* MINIMALISTIC */
{"help", CAM_CMD_USAGE, CAM_ARG_NONE, NULL},
{"-?", CAM_CMD_USAGE, CAM_ARG_NONE, NULL},
@@ -5071,13 +5075,16 @@ get_device_type(struct cam_device *dev, int retry_count, int timeout,
return (retval);
}
void
int
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,
uint16_t sector_count, uint64_t lba, uint8_t command, uint32_t auxiliary,
uint8_t *data_ptr, uint32_t dxfer_len, uint8_t *cdb_storage,
size_t cdb_storage_len, uint8_t sense_len, uint32_t timeout,
int is48bit, camcontrol_devtype devtype)
{
int retval = 0;
if (devtype == CC_DT_ATA) {
cam_fill_ataio(&ccb->ataio,
/*retries*/ retry_count,
@@ -5093,11 +5100,24 @@ build_ata_cmd(union ccb *ccb, uint32_t retry_count, uint32_t flags,
else
ata_28bit_cmd(&ccb->ataio, command, features, lba,
sector_count);
if (auxiliary != 0) {
ccb->ataio.ata_flags |= ATA_FLAG_AUX;
ccb->ataio.aux = auxiliary;
}
if (ata_flags & AP_FLAG_CHK_COND)
ccb->ataio.cmd.flags |= CAM_ATAIO_NEEDRESULT;
if ((protocol & AP_PROTO_MASK) == AP_PROTO_DMA)
ccb->ataio.cmd.flags |= CAM_ATAIO_DMA;
else if ((protocol & AP_PROTO_MASK) == AP_PROTO_FPDMA)
ccb->ataio.cmd.flags |= CAM_ATAIO_FPDMA;
} else {
if (is48bit || lba > ATA_MAX_28BIT_LBA)
protocol |= AP_EXTEND;
scsi_ata_pass_16(&ccb->csio,
retval = scsi_ata_pass(&ccb->csio,
/*retries*/ retry_count,
/*cbfcnp*/ NULL,
/*flags*/ flags,
@@ -5108,14 +5128,158 @@ build_ata_cmd(union ccb *ccb, uint32_t retry_count, uint32_t flags,
/*sector_count*/ sector_count,
/*lba*/ lba,
/*command*/ command,
/*device*/ 0,
/*icc*/ 0,
/*auxiliary*/ auxiliary,
/*control*/ 0,
/*data_ptr*/ data_ptr,
/*dxfer_len*/ dxfer_len,
/*cdb_storage*/ cdb_storage,
/*cdb_storage_len*/ cdb_storage_len,
/*minimum_cmd_size*/ 0,
/*sense_len*/ sense_len,
/*timeout*/ timeout);
}
return (retval);
}
int
get_ata_status(struct cam_device *dev, union ccb *ccb, uint8_t *error,
uint16_t *count, uint64_t *lba, uint8_t *device, uint8_t *status)
{
int retval = 0;
switch (ccb->ccb_h.func_code) {
case XPT_SCSI_IO: {
uint8_t opcode;
int error_code = 0, sense_key = 0, asc = 0, ascq = 0;
/*
* In this case, we have SCSI ATA PASS-THROUGH command, 12
* or 16 byte, and need to see what
*/
if (ccb->ccb_h.flags & CAM_CDB_POINTER)
opcode = ccb->csio.cdb_io.cdb_ptr[0];
else
opcode = ccb->csio.cdb_io.cdb_bytes[0];
if ((opcode != ATA_PASS_12)
&& (opcode != ATA_PASS_16)) {
retval = 1;
warnx("%s: unsupported opcode %02x", __func__, opcode);
goto bailout;
}
retval = scsi_extract_sense_ccb(ccb, &error_code, &sense_key,
&asc, &ascq);
/* Note: the _ccb() variant returns 0 for an error */
if (retval == 0) {
retval = 1;
goto bailout;
} else
retval = 0;
switch (error_code) {
case SSD_DESC_CURRENT_ERROR:
case SSD_DESC_DEFERRED_ERROR: {
struct scsi_sense_data_desc *sense;
struct scsi_sense_ata_ret_desc *desc;
uint8_t *desc_ptr;
sense = (struct scsi_sense_data_desc *)
&ccb->csio.sense_data;
desc_ptr = scsi_find_desc(sense, ccb->csio.sense_len -
ccb->csio.sense_resid, SSD_DESC_ATA);
if (desc_ptr == NULL) {
cam_error_print(dev, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
retval = 1;
goto bailout;
}
desc = (struct scsi_sense_ata_ret_desc *)desc_ptr;
*error = desc->error;
*count = (desc->count_15_8 << 8) |
desc->count_7_0;
*lba = ((uint64_t)desc->lba_47_40 << 40) |
((uint64_t)desc->lba_39_32 << 32) |
(desc->lba_31_24 << 24) |
(desc->lba_23_16 << 16) |
(desc->lba_15_8 << 8) |
desc->lba_7_0;
*device = desc->device;
*status = desc->status;
/*
* If the extend bit isn't set, the result is for a
* 12-byte ATA PASS-THROUGH command or a 16 or 32 byte
* command without the extend bit set. This means
* that the device is supposed to return 28-bit
* status. The count field is only 8 bits, and the
* LBA field is only 8 bits.
*/
if ((desc->flags & SSD_DESC_ATA_FLAG_EXTEND) == 0){
*count &= 0xff;
*lba &= 0x0fffffff;
}
break;
}
case SSD_CURRENT_ERROR:
case SSD_DEFERRED_ERROR: {
#if 0
struct scsi_sense_data_fixed *sense;
#endif
/*
* XXX KDM need to support fixed sense data.
*/
warnx("%s: Fixed sense data not supported yet",
__func__);
retval = 1;
goto bailout;
break; /*NOTREACHED*/
}
default:
retval = 1;
goto bailout;
break;
}
break;
}
case XPT_ATA_IO: {
struct ata_res *res;
/*
* In this case, we have an ATA command, and we need to
* fill in the requested values from the result register
* set.
*/
res = &ccb->ataio.res;
*error = res->error;
*status = res->status;
*device = res->device;
*count = res->sector_count;
*lba = (res->lba_high << 16) |
(res->lba_mid << 8) |
(res->lba_low);
if (res->flags & CAM_ATAIO_48BIT) {
*count |= (res->sector_count_exp << 8);
*lba |= (res->lba_low_exp << 24) |
((uint64_t)res->lba_mid_exp << 32) |
((uint64_t)res->lba_high_exp << 40);
} else {
*lba |= (res->device & 0xf) << 24;
}
break;
}
default:
retval = 1;
break;
}
bailout:
return (retval);
}
static void
cpi_print(struct ccb_pathinq *cpi)
@@ -8774,6 +8938,11 @@ usage(int printlong)
" [-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"
" camcontrol epc [dev_id][generic_args]<-c cmd> [-d] [-D] [-e]\n"
" [-H] [-p power_cond] [-P] [-r rst_src] [-s]\n"
" [-S power_src] [-T timer]\n"
#endif /* MINIMALISTIC */
" camcontrol help\n");
if (!printlong)
@@ -8816,6 +8985,8 @@ usage(int printlong)
"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"
"epc send ATA Extended Power Conditions commands\n"
"help this message\n"
"Device Identifiers:\n"
"bus:target specify the bus and target, lun defaults to 0\n"
@@ -8986,6 +9157,27 @@ usage(int printlong)
"-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"
"epc arguments:\n"
"-c cmd required: restore, goto, timer, state, enable, disable,\n"
" source, status, list\n"
"-d disable power mode (timer, state)\n"
"-D delayed entry (goto)\n"
"-e enable power mode (timer, state)\n"
"-H hold power mode (goto)\n"
"-p power_cond Idle_a, Idle_b, Idle_c, Standby_y, Standby_z (timer,\n"
" state, goto)\n"
"-P only display power mode (status)\n"
"-r rst_src restore settings from: default, saved (restore)\n"
"-s save mode (timer, state, restore)\n"
"-S power_src set power source: battery, nonbattery (source)\n"
"-T timer set timer, seconds, .1 sec resolution (timer)\n"
);
#endif /* MINIMALISTIC */
}
@@ -9341,7 +9533,14 @@ main(int argc, char **argv)
case CAM_CMD_REPROBE:
error = scsireprobe(cam_dev);
break;
case CAM_CMD_ZONE:
error = zone(cam_dev, argc, argv, combinedopt,
retry_count, timeout, arglist & CAM_ARG_VERBOSE);
break;
case CAM_CMD_EPC:
error = epc(cam_dev, argc, argv, combinedopt,
retry_count, timeout, arglist & CAM_ARG_VERBOSE);
break;
#endif /* MINIMALISTIC */
case CAM_CMD_USAGE:
usage(1);
+14 -6
View File
@@ -63,16 +63,24 @@ int dev_has_vpd_page(struct cam_device *dev, uint8_t page_id, int retry_count,
int timeout, int verbosemode);
int get_device_type(struct cam_device *dev, int retry_count, int timeout,
int verbosemode, camcontrol_devtype *devtype);
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 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, uint32_t auxiliary, uint8_t *data_ptr,
uint32_t dxfer_len, uint8_t *cdb_storage,
size_t cdb_storage_len, uint8_t sense_len, uint32_t timeout,
int is48bit, camcontrol_devtype devtype);
int get_ata_status(struct cam_device *dev, union ccb *ccb, uint8_t *error,
uint16_t *count, uint64_t *lba, uint8_t *device,
uint8_t *status);
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);
int epc(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);
+857
View File
@@ -0,0 +1,857 @@
/*-
* Copyright (c) 2016 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)
*/
/*
* ATA Extended Power Conditions (EPC) support
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/ioctl.h>
#include <sys/stdint.h>
#include <sys/types.h>
#include <sys/endian.h>
#include <sys/sbuf.h>
#include <sys/queue.h>
#include <sys/ata.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <fcntl.h>
#include <ctype.h>
#include <limits.h>
#include <err.h>
#include <locale.h>
#include <cam/cam.h>
#include <cam/cam_debug.h>
#include <cam/cam_ccb.h>
#include <cam/scsi/scsi_all.h>
#include <cam/scsi/scsi_da.h>
#include <cam/scsi/scsi_pass.h>
#include <cam/scsi/scsi_message.h>
#include <camlib.h>
#include "camcontrol.h"
typedef enum {
EPC_ACTION_NONE = 0x00,
EPC_ACTION_LIST = 0x01,
EPC_ACTION_TIMER_SET = 0x02,
EPC_ACTION_IMMEDIATE = 0x03,
EPC_ACTION_GETMODE = 0x04
} epc_action;
static struct scsi_nv epc_flags[] = {
{ "Supported", ATA_PCL_COND_SUPPORTED },
{ "Saveable", ATA_PCL_COND_SUPPORTED },
{ "Changeable", ATA_PCL_COND_CHANGEABLE },
{ "Default Timer Enabled", ATA_PCL_DEFAULT_TIMER_EN },
{ "Saved Timer Enabled", ATA_PCL_SAVED_TIMER_EN },
{ "Current Timer Enabled", ATA_PCL_CURRENT_TIMER_EN },
{ "Hold Power Condition Not Supported", ATA_PCL_HOLD_PC_NOT_SUP }
};
static struct scsi_nv epc_power_cond_map[] = {
{ "Standby_z", ATA_EPC_STANDBY_Z },
{ "z", ATA_EPC_STANDBY_Z },
{ "Standby_y", ATA_EPC_STANDBY_Y },
{ "y", ATA_EPC_STANDBY_Y },
{ "Idle_a", ATA_EPC_IDLE_A },
{ "a", ATA_EPC_IDLE_A },
{ "Idle_b", ATA_EPC_IDLE_B },
{ "b", ATA_EPC_IDLE_B },
{ "Idle_c", ATA_EPC_IDLE_C },
{ "c", ATA_EPC_IDLE_C }
};
static struct scsi_nv epc_rst_val[] = {
{ "default", ATA_SF_EPC_RST_DFLT },
{ "saved", 0}
};
static struct scsi_nv epc_ps_map[] = {
{ "unknown", ATA_SF_EPC_SRC_UNKNOWN },
{ "battery", ATA_SF_EPC_SRC_BAT },
{ "notbattery", ATA_SF_EPC_SRC_NOT_BAT }
};
/*
* These aren't subcommands of the EPC SET FEATURES subcommand, but rather
* commands that determine the current capabilities and status of the drive.
* The EPC subcommands are limited to 4 bits, so we won't collide with any
* future values.
*/
#define CCTL_EPC_GET_STATUS 0x8001
#define CCTL_EPC_LIST 0x8002
static struct scsi_nv epc_cmd_map[] = {
{ "restore", ATA_SF_EPC_RESTORE },
{ "goto", ATA_SF_EPC_GOTO },
{ "timer", ATA_SF_EPC_SET_TIMER },
{ "state", ATA_SF_EPC_SET_STATE },
{ "enable", ATA_SF_EPC_ENABLE },
{ "disable", ATA_SF_EPC_DISABLE },
{ "source", ATA_SF_EPC_SET_SOURCE },
{ "status", CCTL_EPC_GET_STATUS },
{ "list", CCTL_EPC_LIST }
};
static int epc_list(struct cam_device *device, camcontrol_devtype devtype,
union ccb *ccb, int retry_count, int timeout);
static void epc_print_pcl_desc(struct ata_power_cond_log_desc *desc,
const char *prefix);
static int epc_getmode(struct cam_device *device, camcontrol_devtype devtype,
union ccb *ccb, int retry_count, int timeout,
int power_only);
static int epc_set_features(struct cam_device *device,
camcontrol_devtype devtype, union ccb *ccb,
int retry_count, int timeout, int action,
int power_cond, int timer, int enable, int save,
int delayed_entry, int hold, int power_src,
int restore_src);
static void
epc_print_pcl_desc(struct ata_power_cond_log_desc *desc, const char *prefix)
{
int first;
unsigned int i, num_printed, max_chars;
first = 1;
max_chars = 75;
num_printed = printf("%sFlags: ", prefix);
for (i = 0; i < (sizeof(epc_flags) / sizeof(epc_flags[0])); i++) {
if ((desc->flags & epc_flags[i].value) == 0)
continue;
if (first == 0) {
num_printed += printf(", ");
}
if ((num_printed + strlen(epc_flags[i].name)) > max_chars) {
printf("\n");
num_printed = printf("%s ", prefix);
}
num_printed += printf("%s", epc_flags[i].name);
first = 0;
}
if (first != 0)
printf("None");
printf("\n");
printf("%sDefault timer setting: %.1f sec\n", prefix,
(double)(le32dec(desc->default_timer) / 10));
printf("%sSaved timer setting: %.1f sec\n", prefix,
(double)(le32dec(desc->saved_timer) / 10));
printf("%sCurrent timer setting: %.1f sec\n", prefix,
(double)(le32dec(desc->current_timer) / 10));
printf("%sNominal time to active: %.1f sec\n", prefix,
(double)(le32dec(desc->nom_time_to_active) / 10));
printf("%sMinimum timer: %.1f sec\n", prefix,
(double)(le32dec(desc->min_timer) / 10));
printf("%sMaximum timer: %.1f sec\n", prefix,
(double)(le32dec(desc->max_timer) / 10));
printf("%sNumber of transitions to power condition: %u\n", prefix,
le32dec(desc->num_transitions_to_pc));
printf("%sHours in power condition: %u\n", prefix,
le32dec(desc->hours_in_pc));
}
static int
epc_list(struct cam_device *device, camcontrol_devtype devtype, union ccb *ccb,
int retry_count, int timeout)
{
struct ata_power_cond_log_idle *idle_log;
struct ata_power_cond_log_standby *standby_log;
uint8_t log_buf[sizeof(*idle_log) + sizeof(*standby_log)];
uint16_t log_addr = ATA_POWER_COND_LOG;
uint16_t page_number = ATA_PCL_IDLE;
uint64_t lba;
int error = 0;
lba = (((uint64_t)page_number & 0xff00) << 32) |
((page_number & 0x00ff) << 8) |
(log_addr & 0xff);
error = 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 | AP_EXTEND,
/*ata_flags*/ AP_FLAG_BYT_BLOK_BLOCKS |
AP_FLAG_TLEN_SECT_CNT |
AP_FLAG_TDIR_FROM_DEV,
/*features*/ 0,
/*sector_count*/ 2,
/*lba*/ lba,
/*command*/ ATA_READ_LOG_DMA_EXT,
/*auxiliary*/ 0,
/*data_ptr*/ log_buf,
/*dxfer_len*/ sizeof(log_buf),
/*cdb_storage*/ NULL,
/*cdb_storage_len*/ 0,
/*sense_len*/ SSD_FULL_SIZE,
/*timeout*/ timeout ? timeout : 60000,
/*is48bit*/ 1,
/*devtype*/ devtype);
if (error != 0) {
warnx("%s: build_ata_cmd() failed, likely programmer error",
__func__);
goto bailout;
}
if (retry_count > 0)
ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
error = cam_send_ccb(device, ccb);
if (error != 0) {
warn("error sending ATA READ LOG EXT CCB");
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;
}
idle_log = (struct ata_power_cond_log_idle *)log_buf;
standby_log =
(struct ata_power_cond_log_standby *)&log_buf[sizeof(*idle_log)];
printf("ATA Power Conditions Log:\n");
printf(" Idle power conditions page:\n");
printf(" Idle A condition:\n");
epc_print_pcl_desc(&idle_log->idle_a_desc, " ");
printf(" Idle B condition:\n");
epc_print_pcl_desc(&idle_log->idle_b_desc, " ");
printf(" Idle C condition:\n");
epc_print_pcl_desc(&idle_log->idle_c_desc, " ");
printf(" Standby power conditions page:\n");
printf(" Standby Y condition:\n");
epc_print_pcl_desc(&standby_log->standby_y_desc, " ");
printf(" Standby Z condition:\n");
epc_print_pcl_desc(&standby_log->standby_z_desc, " ");
bailout:
return (error);
}
static int
epc_getmode(struct cam_device *device, camcontrol_devtype devtype,
union ccb *ccb, int retry_count, int timeout, int power_only)
{
struct ata_params *ident = NULL;
struct ata_identify_log_sup_cap sup_cap;
const char *mode_name = NULL;
uint8_t error = 0, ata_device = 0, status = 0;
uint16_t count = 0;
uint64_t lba = 0;
uint32_t page_number, log_address;
uint64_t caps = 0;
int avail_bytes = 0;
int res_available = 0;
int retval;
retval = 0;
if (power_only != 0)
goto check_power_mode;
/*
* Get standard ATA Identify data.
*/
retval = ata_do_identify(device, retry_count, timeout, ccb, &ident);
if (retval != 0) {
warnx("Couldn't get identify data");
goto bailout;
}
/*
* Get the ATA Identify Data Log (0x30),
* Supported Capabilities Page (0x03).
*/
log_address = ATA_IDENTIFY_DATA_LOG;
page_number = ATA_IDL_SUP_CAP;
lba = (((uint64_t)page_number & 0xff00) << 32) |
((page_number & 0x00ff) << 8) |
(log_address & 0xff);
bzero(&sup_cap, sizeof(sup_cap));
/*
* XXX KDM check the supported protocol.
*/
retval = 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 |
AP_EXTEND,
/*ata_flags*/ AP_FLAG_BYT_BLOK_BLOCKS |
AP_FLAG_TLEN_SECT_CNT |
AP_FLAG_TDIR_FROM_DEV,
/*features*/ 0,
/*sector_count*/ 1,
/*lba*/ lba,
/*command*/ ATA_READ_LOG_DMA_EXT,
/*auxiliary*/ 0,
/*data_ptr*/ (uint8_t *)&sup_cap,
/*dxfer_len*/ sizeof(sup_cap),
/*cdb_storage*/ NULL,
/*cdb_storage_len*/ 0,
/*sense_len*/ SSD_FULL_SIZE,
/*timeout*/ timeout ? timeout : 60000,
/*is48bit*/ 1,
/*devtype*/ devtype);
if (retval != 0) {
warnx("%s: build_ata_cmd() failed, likely a programmer error",
__func__);
goto bailout;
}
if (retry_count > 0)
ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
retval = cam_send_ccb(device, ccb);
if (retval != 0) {
warn("error sending ATA READ LOG CCB");
retval = 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);
retval = 1;
goto bailout;
}
if (ccb->ccb_h.func_code == XPT_SCSI_IO) {
avail_bytes = ccb->csio.dxfer_len - ccb->csio.resid;
} else {
avail_bytes = ccb->ataio.dxfer_len - ccb->ataio.resid;
}
if (avail_bytes < (int)sizeof(sup_cap)) {
warnx("Couldn't get enough of the ATA Supported "
"Capabilities log, %d bytes returned", avail_bytes);
retval = 1;
goto bailout;
}
caps = le64dec(sup_cap.sup_cap);
if ((caps & ATA_SUP_CAP_VALID) == 0) {
warnx("Supported capabilities bits are not valid");
retval = 1;
goto bailout;
}
printf("APM: %sSupported, %sEnabled\n",
(ident->support.command2 & ATA_SUPPORT_APM) ? "" : "NOT ",
(ident->enabled.command2 & ATA_SUPPORT_APM) ? "" : "NOT ");
printf("EPC: %sSupported, %sEnabled\n",
(ident->support2 & ATA_SUPPORT_EPC) ? "" : "NOT ",
(ident->enabled2 & ATA_ENABLED_EPC) ? "" : "NOT ");
printf("Low Power Standby %sSupported\n",
(caps & ATA_SC_LP_STANDBY_SUP) ? "" : "NOT ");
printf("Set EPC Power Source %sSupported\n",
(caps & ATA_SC_SET_EPC_PS_SUP) ? "" : "NOT ");
check_power_mode:
retval = 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 |
AP_EXTEND,
/*ata_flags*/ AP_FLAG_BYT_BLOK_BLOCKS |
AP_FLAG_TLEN_NO_DATA |
AP_FLAG_CHK_COND,
/*features*/ ATA_SF_EPC,
/*sector_count*/ 0,
/*lba*/ 0,
/*command*/ ATA_CHECK_POWER_MODE,
/*auxiliary*/ 0,
/*data_ptr*/ NULL,
/*dxfer_len*/ 0,
/*cdb_storage*/ NULL,
/*cdb_storage_len*/ 0,
/*sense_len*/ SSD_FULL_SIZE,
/*timeout*/ timeout ? timeout : 60000,
/*is48bit*/ 0,
/*devtype*/ devtype);
if (retval != 0) {
warnx("%s: build_ata_cmd() failed, likely a programmer error",
__func__);
goto bailout;
}
if (retry_count > 0)
ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
retval = cam_send_ccb(device, ccb);
if (retval != 0) {
warn("error sending ATA CHECK POWER MODE CCB");
retval = 1;
goto bailout;
}
/*
* Check to see whether we got the requested ATA result if this
* is an SCSI ATA PASS-THROUGH command.
*/
if (((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_SCSI_STATUS_ERROR)
&& (ccb->csio.scsi_status == SCSI_STATUS_CHECK_COND)) {
int error_code, sense_key, asc, ascq;
retval = scsi_extract_sense_ccb(ccb, &error_code,
&sense_key, &asc, &ascq);
if (retval == 0) {
cam_error_print(device, ccb, CAM_ESF_ALL, CAM_EPF_ALL,
stderr);
retval = 1;
goto bailout;
}
if ((sense_key == SSD_KEY_RECOVERED_ERROR)
&& (asc == 0x00)
&& (ascq == 0x1d)) {
res_available = 1;
}
}
if (((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
&& (res_available == 0)) {
cam_error_print(device, ccb, CAM_ESF_ALL, CAM_EPF_ALL,stderr);
retval = 1;
goto bailout;
}
retval = get_ata_status(device, ccb, &error, &count, &lba, &ata_device,
&status);
if (retval != 0) {
warnx("Unable to get ATA CHECK POWER MODE result");
retval = 1;
goto bailout;
}
mode_name = scsi_nv_to_str(epc_power_cond_map,
sizeof(epc_power_cond_map) / sizeof(epc_power_cond_map[0]), count);
printf("Current power state: ");
/* Note: ident can be null in power_only mode */
if ((ident == NULL)
|| (ident->enabled2 & ATA_ENABLED_EPC)) {
if (mode_name != NULL)
printf("%s", mode_name);
else if (count == 0xff) {
printf("PM0:Active or PM1:Idle");
}
} else {
switch (count) {
case 0x00:
printf("PM2:Standby");
break;
case 0x80:
printf("PM1:Idle");
break;
case 0xff:
printf("PM0:Active or PM1:Idle");
break;
}
}
printf("(0x%02x)\n", count);
if (power_only != 0)
goto bailout;
if (caps & ATA_SC_LP_STANDBY_SUP) {
uint32_t wait_mode;
wait_mode = (lba >> 20) & 0xff;
if (wait_mode == 0xff) {
printf("Device not waiting to enter lower power "
"condition");
} else {
mode_name = scsi_nv_to_str(epc_power_cond_map,
sizeof(epc_power_cond_map) /
sizeof(epc_power_cond_map[0]), wait_mode);
printf("Device waiting to enter mode %s (0x%02x)\n",
(mode_name != NULL) ? mode_name : "Unknown",
wait_mode);
}
printf("Device is %sheld in the current power condition\n",
(lba & 0x80000) ? "" : "NOT ");
}
bailout:
return (retval);
}
static int
epc_set_features(struct cam_device *device, camcontrol_devtype devtype,
union ccb *ccb, int retry_count, int timeout, int action,
int power_cond, int timer, int enable, int save,
int delayed_entry, int hold, int power_src, int restore_src)
{
uint64_t lba;
uint16_t count = 0;
int error;
error = 0;
lba = action;
switch (action) {
case ATA_SF_EPC_SET_TIMER:
lba |= ((timer << ATA_SF_EPC_TIMER_SHIFT) &
ATA_SF_EPC_TIMER_MASK);
/* FALLTHROUGH */
case ATA_SF_EPC_SET_STATE:
lba |= (enable ? ATA_SF_EPC_TIMER_EN : 0) |
(save ? ATA_SF_EPC_TIMER_SAVE : 0);
count = power_cond;
break;
case ATA_SF_EPC_GOTO:
count = power_cond;
lba |= (delayed_entry ? ATA_SF_EPC_GOTO_DELAY : 0) |
(hold ? ATA_SF_EPC_GOTO_HOLD : 0);
break;
case ATA_SF_EPC_RESTORE:
lba |= restore_src |
(save ? ATA_SF_EPC_RST_SAVE : 0);
break;
case ATA_SF_EPC_ENABLE:
case ATA_SF_EPC_DISABLE:
break;
case ATA_SF_EPC_SET_SOURCE:
count = power_src;
break;
}
error = 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 | AP_EXTEND,
/*ata_flags*/ AP_FLAG_BYT_BLOK_BLOCKS |
AP_FLAG_TLEN_NO_DATA |
AP_FLAG_TDIR_FROM_DEV,
/*features*/ ATA_SF_EPC,
/*sector_count*/ count,
/*lba*/ lba,
/*command*/ ATA_SETFEATURES,
/*auxiliary*/ 0,
/*data_ptr*/ NULL,
/*dxfer_len*/ 0,
/*cdb_storage*/ NULL,
/*cdb_storage_len*/ 0,
/*sense_len*/ SSD_FULL_SIZE,
/*timeout*/ timeout ? timeout : 60000,
/*is48bit*/ 1,
/*devtype*/ devtype);
if (error != 0) {
warnx("%s: build_ata_cmd() failed, likely a programmer error",
__func__);
goto bailout;
}
if (retry_count > 0)
ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
error = cam_send_ccb(device, ccb);
if (error != 0) {
warn("error sending ATA SET FEATURES CCB");
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;
}
bailout:
return (error);
}
int
epc(struct cam_device *device, int argc, char **argv, char *combinedopt,
int retry_count, int timeout, int verbosemode __unused)
{
union ccb *ccb = NULL;
int error = 0;
int c;
int action = -1;
camcontrol_devtype devtype;
double timer_val = -1;
int timer_tenths = 0, power_cond = -1;
int delayed_entry = 0, hold = 0;
int enable = -1, save = 0;
int restore_src = -1;
int power_src = -1;
int power_only = 0;
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 'c': {
scsi_nv_status status;
int entry_num;
status = scsi_get_nv(epc_cmd_map,
(sizeof(epc_cmd_map) / sizeof(epc_cmd_map[0])),
optarg, &entry_num, SCSI_NV_FLAG_IG_CASE);
if (status == SCSI_NV_FOUND)
action = epc_cmd_map[entry_num].value;
else {
warnx("%s: %s: %s option %s", __func__,
(status == SCSI_NV_AMBIGUOUS) ?
"ambiguous" : "invalid", "epc command",
optarg);
error = 1;
goto bailout;
}
break;
}
case 'd':
enable = 0;
break;
case 'D':
delayed_entry = 1;
break;
case 'e':
enable = 1;
break;
case 'H':
hold = 1;
break;
case 'p': {
scsi_nv_status status;
int entry_num;
status = scsi_get_nv(epc_power_cond_map,
(sizeof(epc_power_cond_map) /
sizeof(epc_power_cond_map[0])), optarg,
&entry_num, SCSI_NV_FLAG_IG_CASE);
if (status == SCSI_NV_FOUND)
power_cond =epc_power_cond_map[entry_num].value;
else {
warnx("%s: %s: %s option %s", __func__,
(status == SCSI_NV_AMBIGUOUS) ?
"ambiguous" : "invalid", "power condition",
optarg);
error = 1;
goto bailout;
}
break;
}
case 'P':
power_only = 1;
break;
case 'r': {
scsi_nv_status status;
int entry_num;
status = scsi_get_nv(epc_rst_val,
(sizeof(epc_rst_val) /
sizeof(epc_rst_val[0])), optarg,
&entry_num, SCSI_NV_FLAG_IG_CASE);
if (status == SCSI_NV_FOUND)
restore_src = epc_rst_val[entry_num].value;
else {
warnx("%s: %s: %s option %s", __func__,
(status == SCSI_NV_AMBIGUOUS) ?
"ambiguous" : "invalid",
"restore value source", optarg);
error = 1;
goto bailout;
}
break;
}
case 's':
save = 1;
break;
case 'S': {
scsi_nv_status status;
int entry_num;
status = scsi_get_nv(epc_ps_map,
(sizeof(epc_ps_map) / sizeof(epc_ps_map[0])),
optarg, &entry_num, SCSI_NV_FLAG_IG_CASE);
if (status == SCSI_NV_FOUND)
power_src = epc_ps_map[entry_num].value;
else {
warnx("%s: %s: %s option %s", __func__,
(status == SCSI_NV_AMBIGUOUS) ?
"ambiguous" : "invalid", "power source",
optarg);
error = 1;
goto bailout;
}
break;
}
case 'T': {
char *endptr;
timer_val = strtod(optarg, &endptr);
if (timer_val < 0) {
warnx("Invalid timer value %f", timer_val);
error = 1;
goto bailout;
} else if (*endptr != '\0') {
warnx("Invalid timer value %s", optarg);
error = 1;
goto bailout;
}
timer_tenths = timer_val * 10;
break;
}
default:
break;
}
}
if (action == -1) {
warnx("Must specify an action");
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");
switch (devtype) {
case CC_DT_ATA:
case CC_DT_ATA_BEHIND_SCSI:
break;
default:
warnx("The epc subcommand only works with ATA protocol "
"devices");
error = 1;
goto bailout;
break; /*NOTREACHED*/
}
switch (action) {
case ATA_SF_EPC_SET_TIMER:
if (timer_val == -1) {
warnx("Must specify a timer value (-T time)");
error = 1;
}
case ATA_SF_EPC_SET_STATE:
if (enable == -1) {
warnx("Must specify enable (-e) or disable (-d)");
error = 1;
}
/* FALLTHROUGH */
case ATA_SF_EPC_GOTO:
if (power_cond == -1) {
warnx("Must specify a power condition with -p");
error = 1;
}
if (error != 0)
goto bailout;
break;
case ATA_SF_EPC_SET_SOURCE:
if (power_src == -1) {
warnx("Must specify a power source (-S battery or "
"-S notbattery) value");
error = 1;
goto bailout;
}
break;
case ATA_SF_EPC_RESTORE:
if (restore_src == -1) {
warnx("Must specify a source for restored value, "
"-r default or -r saved");
error = 1;
goto bailout;
}
break;
case ATA_SF_EPC_ENABLE:
case ATA_SF_EPC_DISABLE:
case CCTL_EPC_GET_STATUS:
case CCTL_EPC_LIST:
default:
break;
}
switch (action) {
case CCTL_EPC_GET_STATUS:
error = epc_getmode(device, devtype, ccb, retry_count, timeout,
power_only);
break;
case CCTL_EPC_LIST:
error = epc_list(device, devtype, ccb, retry_count, timeout);
break;
case ATA_SF_EPC_RESTORE:
case ATA_SF_EPC_GOTO:
case ATA_SF_EPC_SET_TIMER:
case ATA_SF_EPC_SET_STATE:
case ATA_SF_EPC_ENABLE:
case ATA_SF_EPC_DISABLE:
case ATA_SF_EPC_SET_SOURCE:
error = epc_set_features(device, devtype, ccb, retry_count,
timeout, action, power_cond, timer_tenths, enable, save,
delayed_entry, hold, power_src, restore_src);
break;
default:
warnx("Not implemented yet");
error = 1;
goto bailout;
break;
}
bailout:
if (ccb != NULL)
cam_freeccb(ccb);
return (error);
}
+20 -2
View File
@@ -692,7 +692,7 @@ fw_check_device_ready(struct cam_device *dev, camcontrol_devtype devtype,
break;
case CC_DT_ATA_BEHIND_SCSI:
case CC_DT_ATA: {
build_ata_cmd(ccb,
retval = build_ata_cmd(ccb,
/*retries*/ 1,
/*flags*/ CAM_DIR_IN,
/*tag_action*/ MSG_SIMPLE_Q_TAG,
@@ -704,12 +704,21 @@ fw_check_device_ready(struct cam_device *dev, camcontrol_devtype devtype,
/*sector_count*/ (uint8_t) dxfer_len,
/*lba*/ 0,
/*command*/ ATA_ATA_IDENTIFY,
/*auxiliary*/ 0,
/*data_ptr*/ (uint8_t *)ptr,
/*dxfer_len*/ dxfer_len,
/*cdb_storage*/ NULL,
/*cdb_storage_len*/ 0,
/*sense_len*/ SSD_FULL_SIZE,
/*timeout*/ timeout ? timeout : 30 * 1000,
/*is48bit*/ 0,
/*devtype*/ devtype);
if (retval != 0) {
retval = -1;
warnx("%s: build_ata_cmd() failed, likely "
"programmer error", __func__);
goto bailout;
}
break;
}
default:
@@ -847,7 +856,7 @@ fw_download_img(struct cam_device *cam_dev, struct fw_vendor *vp,
off = (uint32_t)(pkt_ptr - buf);
build_ata_cmd(ccb,
retval = build_ata_cmd(ccb,
/*retry_count*/ retry_count,
/*flags*/ CAM_DIR_OUT | CAM_DEV_QFRZDIS,
/*tag_action*/ CAM_TAG_ACTION_NONE,
@@ -859,12 +868,21 @@ fw_download_img(struct cam_device *cam_dev, struct fw_vendor *vp,
/*sector_count*/ ATA_MAKE_SECTORS(pkt_size),
/*lba*/ ATA_MAKE_LBA(off, pkt_size),
/*command*/ ATA_DOWNLOAD_MICROCODE,
/*auxiliary*/ 0,
/*data_ptr*/ (uint8_t *)pkt_ptr,
/*dxfer_len*/ pkt_size,
/*cdb_storage*/ NULL,
/*cdb_storage_len*/ 0,
/*sense_len*/ SSD_FULL_SIZE,
/*timeout*/ timeout ? timeout : WB_TIMEOUT,
/*is48bit*/ 0,
/*devtype*/ devtype);
if (retval != 0) {
warnx("%s: build_ata_cmd() failed, likely "
"programmer error", __func__);
goto bailout;
}
break;
}
default:
+676
View File
@@ -0,0 +1,676 @@
/*-
* Copyright (c) 2015, 2016 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 <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/ioctl.h>
#include <sys/stdint.h>
#include <sys/types.h>
#include <sys/endian.h>
#include <sys/sbuf.h>
#include <sys/queue.h>
#include <sys/chio.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <fcntl.h>
#include <ctype.h>
#include <limits.h>
#include <err.h>
#include <locale.h>
#include <cam/cam.h>
#include <cam/cam_debug.h>
#include <cam/cam_ccb.h>
#include <cam/scsi/scsi_all.h>
#include <cam/scsi/scsi_da.h>
#include <cam/scsi/scsi_pass.h>
#include <cam/scsi/scsi_ch.h>
#include <cam/scsi/scsi_message.h>
#include <camlib.h>
#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 = 65536, valid_len = 0;
camcontrol_devtype devtype;
int ata_format = 0, use_ncq = 0;
int first_pass = 1;
zone_print_status zp_status;
zone_output_flags out_flags = ZONE_OF_NORMAL;
uint8_t *cdb_storage = NULL;
int cdb_storage_len = 32;
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 'N':
use_ncq = 1;
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 <zone_cmd>", __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) {
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: {
uint8_t command = 0;
uint8_t protocol = 0;
uint16_t features = 0, sector_count = 0;
uint32_t auxiliary = 0;
/*
* XXX KDM support the partial bit?
*/
if (use_ncq == 0) {
command = ATA_ZAC_MANAGEMENT_IN;
features = action;
if (rep_option != -1)
features |= (rep_option << 8);
sector_count = ZAC_ATA_SECTOR_COUNT(alloc_len);
protocol = AP_PROTO_DMA;
} else {
cdb_storage = calloc(cdb_storage_len, 1);
if (cdb_storage == NULL)
err(1, "couldn't allocate memory");
command = ATA_RECV_FPDMA_QUEUED;
features = ZAC_ATA_SECTOR_COUNT(alloc_len);
sector_count = ATA_RFPDMA_ZAC_MGMT_IN << 8;
auxiliary = action & 0xf;
if (rep_option != -1)
auxiliary |= rep_option << 8;
protocol = AP_PROTO_FPDMA;
}
error = build_ata_cmd(ccb,
/*retry_count*/ retry_count,
/*flags*/ CAM_DIR_IN | CAM_DEV_QFRZDIS,
/*tag_action*/ MSG_SIMPLE_Q_TAG,
/*protocol*/ protocol,
/*ata_flags*/ AP_FLAG_BYT_BLOK_BLOCKS |
AP_FLAG_TLEN_SECT_CNT |
AP_FLAG_TDIR_FROM_DEV,
/*features*/ features,
/*sector_count*/ sector_count,
/*lba*/ lba,
/*command*/ command,
/*auxiliary*/ auxiliary,
/*data_ptr*/ data_ptr,
/*dxfer_len*/ ZAC_ATA_SECTOR_COUNT(alloc_len)*512,
/*cdb_storage*/ cdb_storage,
/*cdb_storage_len*/ cdb_storage_len,
/*sense_len*/ SSD_FULL_SIZE,
/*timeout*/ timeout ? timeout : 60000,
/*is48bit*/ 1,
/*devtype*/ devtype);
if (error != 0) {
warnx("%s: build_ata_cmd() failed, likely "
"programmer error", __func__);
goto bailout;
}
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: {
uint8_t command = 0;
uint8_t protocol = 0;
uint16_t features = 0, sector_count = 0;
uint32_t auxiliary = 0;
/*
* Note that we're taking advantage of the fact
* that the action numbers are the same between the
* ZBC and ZAC specs.
*/
if (use_ncq == 0) {
protocol = AP_PROTO_NON_DATA;
command = ATA_ZAC_MANAGEMENT_OUT;
features = action & 0xf;
if (all_zones != 0)
features |= (ZBC_OUT_ALL << 8);
} else {
cdb_storage = calloc(cdb_storage_len, 1);
if (cdb_storage == NULL)
err(1, "couldn't allocate memory");
protocol = AP_PROTO_FPDMA;
command = ATA_NCQ_NON_DATA;
features = ATA_NCQ_ZAC_MGMT_OUT;
auxiliary = action & 0xf;
if (all_zones != 0)
auxiliary |= (ZBC_OUT_ALL << 8);
}
error = 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*/ sector_count,
/*lba*/ lba,
/*command*/ command,
/*auxiliary*/ auxiliary,
/*data_ptr*/ NULL,
/*dxfer_len*/ 0,
/*cdb_storage*/ cdb_storage,
/*cdb_storage_len*/ cdb_storage_len,
/*sense_len*/ SSD_FULL_SIZE,
/*timeout*/ timeout ? timeout : 60000,
/*is48bit*/ 1,
/*devtype*/ devtype);
if (error != 0) {
warnx("%s: build_ata_cmd() failed, likely "
"programmer error", __func__);
goto bailout;
}
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);
free(cdb_storage);
return (error);
}
+242 -17
View File
@@ -110,18 +110,45 @@ ata_op_string(struct ata_cmd *cmd)
case 0x3f: return ("WRITE_LOG_EXT");
case 0x40: return ("READ_VERIFY");
case 0x42: return ("READ_VERIFY48");
case 0x44: return ("ZERO_EXT");
case 0x45:
switch (cmd->features) {
case 0x55: return ("WRITE_UNCORRECTABLE48 PSEUDO");
case 0xaa: return ("WRITE_UNCORRECTABLE48 FLAGGED");
}
return "WRITE_UNCORRECTABLE48";
case 0x47: return ("READ_LOG_DMA_EXT");
case 0x4a: return ("ZAC_MANAGEMENT_IN");
case 0x51: return ("CONFIGURE_STREAM");
case 0x60: return ("READ_FPDMA_QUEUED");
case 0x61: return ("WRITE_FPDMA_QUEUED");
case 0x63: return ("NCQ_NON_DATA");
case 0x64: return ("SEND_FPDMA_QUEUED");
case 0x65: return ("RECEIVE_FPDMA_QUEUED");
case 0x63:
switch (cmd->features & 0xf) {
case 0x00: return ("NCQ_NON_DATA ABORT NCQ QUEUE");
case 0x01: return ("NCQ_NON_DATA DEADLINE HANDLING");
case 0x05: return ("NCQ_NON_DATA SET FEATURES");
/*
* XXX KDM need common decoding between NCQ and non-NCQ
* versions of SET FEATURES.
*/
case 0x06: return ("NCQ_NON_DATA ZERO EXT");
case 0x07: return ("NCQ_NON_DATA ZAC MANAGEMENT OUT");
}
return ("NCQ_NON_DATA");
case 0x64:
switch (cmd->sector_count_exp & 0xf) {
case 0x00: return ("SEND_FPDMA_QUEUED DATA SET MANAGEMENT");
case 0x02: return ("SEND_FPDMA_QUEUED WRITE LOG DMA EXT");
case 0x03: return ("SEND_FPDMA_QUEUED ZAC MANAGEMENT OUT");
case 0x04: return ("SEND_FPDMA_QUEUED DATA SET MANAGEMENT XL");
}
return ("SEND_FPDMA_QUEUED");
case 0x65:
switch (cmd->sector_count_exp & 0xf) {
case 0x01: return ("RECEIVE_FPDMA_QUEUED READ LOG DMA EXT");
case 0x02: return ("RECEIVE_FPDMA_QUEUED ZAC MANAGEMENT IN");
}
return ("RECEIVE_FPDMA_QUEUED");
case 0x67:
if (cmd->features == 0xec)
return ("SEP_ATTN IDENTIFY");
@@ -136,6 +163,7 @@ ata_op_string(struct ata_cmd *cmd)
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");
@@ -179,23 +207,44 @@ ata_op_string(struct ata_cmd *cmd)
case 0xec: return ("ATA_IDENTIFY");
case 0xed: return ("MEDIA_EJECT");
case 0xef:
/*
* XXX KDM need common decoding between NCQ and non-NCQ
* versions of SET FEATURES.
*/
switch (cmd->features) {
case 0x03: return ("SETFEATURES SET TRANSFER MODE");
case 0x02: return ("SETFEATURES ENABLE WCACHE");
case 0x82: return ("SETFEATURES DISABLE WCACHE");
case 0x06: return ("SETFEATURES ENABLE PUIS");
case 0x86: return ("SETFEATURES DISABLE PUIS");
case 0x07: return ("SETFEATURES SPIN-UP");
case 0x10: return ("SETFEATURES ENABLE SATA FEATURE");
case 0x90: return ("SETFEATURES DISABLE SATA FEATURE");
case 0xaa: return ("SETFEATURES ENABLE RCACHE");
case 0x55: return ("SETFEATURES DISABLE RCACHE");
case 0x02: return ("SETFEATURES ENABLE WCACHE");
case 0x03: return ("SETFEATURES SET TRANSFER MODE");
case 0x04: return ("SETFEATURES ENABLE APM");
case 0x06: return ("SETFEATURES ENABLE PUIS");
case 0x07: return ("SETFEATURES SPIN-UP");
case 0x0b: return ("SETFEATURES ENABLE WRITE READ VERIFY");
case 0x0c: return ("SETFEATURES ENABLE DEVICE LIFE CONTROL");
case 0x10: return ("SETFEATURES ENABLE SATA FEATURE");
case 0x41: return ("SETFEATURES ENABLE FREEFALL CONTROL");
case 0x43: return ("SETFEATURES SET MAX HOST INT SECT TIMES");
case 0x45: return ("SETFEATURES SET RATE BASIS");
case 0x4a: return ("SETFEATURES EXTENDED POWER CONDITIONS");
case 0x55: return ("SETFEATURES DISABLE RCACHE");
case 0x5d: return ("SETFEATURES ENABLE RELIRQ");
case 0xdd: return ("SETFEATURES DISABLE RELIRQ");
case 0x5e: return ("SETFEATURES ENABLE SRVIRQ");
case 0x62: return ("SETFEATURES LONG PHYS SECT ALIGN ERC");
case 0x63: return ("SETFEATURES DSN");
case 0x66: return ("SETFEATURES DISABLE DEFAULTS");
case 0x82: return ("SETFEATURES DISABLE WCACHE");
case 0x85: return ("SETFEATURES DISABLE APM");
case 0x86: return ("SETFEATURES DISABLE PUIS");
case 0x8b: return ("SETFEATURES DISABLE WRITE READ VERIFY");
case 0x8c: return ("SETFEATURES DISABLE DEVICE LIFE CONTROL");
case 0x90: return ("SETFEATURES DISABLE SATA FEATURE");
case 0xaa: return ("SETFEATURES ENABLE RCACHE");
case 0xC1: return ("SETFEATURES DISABLE FREEFALL CONTROL");
case 0xC3: return ("SETFEATURES SENSE DATA REPORTING");
case 0xC4: return ("SETFEATURES NCQ SENSE DATA RETURN");
case 0xCC: return ("SETFEATURES ENABLE DEFAULTS");
case 0xdd: return ("SETFEATURES DISABLE RELIRQ");
case 0xde: return ("SETFEATURES DISABLE SRVIRQ");
}
return "SETFEATURES";
}
return "SETFEATURES";
case 0xf1: return ("SECURITY_SET_PASSWORD");
case 0xf2: return ("SECURITY_UNLOCK");
case 0xf3: return ("SECURITY_ERASE_PREPARE");
@@ -463,7 +512,8 @@ ata_48bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint16_t features,
cmd == ATA_WRITE_DMA_QUEUED48 ||
cmd == ATA_WRITE_DMA_QUEUED_FUA48 ||
cmd == ATA_WRITE_STREAM_DMA48 ||
cmd == ATA_DATA_SET_MANAGEMENT)
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;
@@ -533,6 +583,36 @@ ata_pm_write_cmd(struct ccb_ataio *ataio, int reg, int port, uint32_t val)
ataio->cmd.device = port & 0x0f;
}
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)
{
@@ -893,3 +973,148 @@ semb_write_buffer(struct ccb_ataio *ataio,
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, 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;
uint32_t auxiliary;
if (use_ncq == 0) {
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);
}
auxiliary = 0;
} else {
if (dxfer_len == 0) {
command_out = ATA_NCQ_NON_DATA;
features_out = ATA_NCQ_ZAC_MGMT_OUT;
sectors_out = 0;
} else {
command_out = ATA_SEND_FPDMA_QUEUED;
/* Note that we're defaulting to normal priority */
sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
/*
* For SEND FPDMA QUEUED, the transfer length is
* encoded in the FEATURE register, and 0 means
* that 65536 512 byte blocks are to be tranferred.
* In practice, it seems unlikely that we'll see
* a transfer that large.
*/
if (dxfer_len == (65536 * 512)) {
features_out = 0;
} else {
/*
* Yes, the caller can theoretically send a
* transfer larger than we can handle.
* Anyone using this function needs enough
* knowledge to avoid doing that.
*/
features_out = ((dxfer_len >> 9) & 0xffff);
}
}
auxiliary = (zm_action & 0xf) | (zone_flags << 8);
ata_flags = CAM_ATAIO_FPDMA;
}
cam_fill_ataio(ataio,
/*retries*/ retries,
/*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);
ataio->cmd.flags |= ata_flags;
if (auxiliary != 0) {
ataio->ata_flags |= ATA_FLAG_AUX;
ataio->aux = auxiliary;
}
}
void
ata_zac_mgmt_in(struct ccb_ataio *ataio, uint32_t retries,
void (*cbfcnp)(struct cam_periph *, union ccb *),
int use_ncq, 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;
uint32_t auxiliary;
if (use_ncq == 0) {
command_out = ATA_ZAC_MANAGEMENT_IN;
/* XXX KDM put a macro here */
features_out = (zm_action & 0xf) | (zone_flags << 8);
ata_flags = CAM_ATAIO_DMA;
sectors_out = ((dxfer_len >> 9) & 0xffff);
auxiliary = 0;
} else {
command_out = ATA_RECV_FPDMA_QUEUED;
sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
auxiliary = (zm_action & 0xf) | (zone_flags << 8),
ata_flags = CAM_ATAIO_FPDMA;
/*
* For RECEIVE FPDMA QUEUED, the transfer length is
* encoded in the FEATURE register, and 0 means
* that 65536 512 byte blocks are to be tranferred.
* In practice, it is unlikely we will see a transfer that
* large.
*/
if (dxfer_len == (65536 * 512)) {
features_out = 0;
} else {
/*
* Yes, the caller can theoretically request a
* transfer larger than we can handle.
* Anyone using this function needs enough
* knowledge to avoid doing that.
*/
features_out = ((dxfer_len >> 9) & 0xffff);
}
}
cam_fill_ataio(ataio,
/*retries*/ retries,
/*cbfcnp*/ cbfcnp,
/*flags*/ CAM_DIR_IN,
/*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);
ataio->cmd.flags |= ata_flags;
if (auxiliary != 0) {
ataio->ata_flags |= ATA_FLAG_AUX;
ataio->aux = auxiliary;
}
}
+17
View File
@@ -125,6 +125,11 @@ void ata_ncq_cmd(struct ccb_ataio *ataio, uint8_t cmd,
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);
@@ -167,4 +172,16 @@ void semb_write_buffer(struct ccb_ataio *ataio,
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
+1196 -146
View File
File diff suppressed because it is too large Load Diff
+280 -21
View File
@@ -111,6 +111,7 @@ static void fetchtableentries(int sense_key, int asc, int ascq,
struct scsi_inquiry_data *,
const struct sense_key_table_entry **,
const struct asc_table_entry **);
#ifdef _KERNEL
static void init_scsi_delay(void);
static int sysctl_scsi_delay(SYSCTL_HANDLER_ARGS);
@@ -502,9 +503,9 @@ static struct op_table_entry scsi_op_codes[] = {
/* 93 M ERASE(16) */
{ 0x93, T, "ERASE(16)" },
/* 94 O ZBC OUT */
{ 0x94, D, "ZBC OUT" },
/* 95 O ZBC OUT */
{ 0x95, D, "ZBC OUT" },
{ 0x94, ALL, "ZBC OUT" },
/* 95 O ZBC IN */
{ 0x95, ALL, "ZBC IN" },
/* 96 */
/* 97 */
/* 98 */
@@ -520,7 +521,6 @@ static struct op_table_entry scsi_op_codes[] = {
/* 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 */
@@ -673,6 +673,12 @@ scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
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;
@@ -4259,6 +4265,7 @@ scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len,
switch (SID_TYPE(inq_data)) {
case T_DIRECT:
case T_RBC:
case T_ZBC_HM:
break;
default:
goto bailout;
@@ -5408,6 +5415,9 @@ scsi_print_inquiry(struct scsi_inquiry_data *inq_data)
case T_ADC:
dtype = "Automation/Drive Interface";
break;
case T_ZBC_HM:
dtype = "Host Managed Zoned Block";
break;
case T_NODEVICE:
dtype = "Uninstalled";
break;
@@ -8135,23 +8145,30 @@ scsi_ata_identify(struct ccb_scsiio *csio, u_int32_t retries,
u_int16_t dxfer_len, u_int8_t sense_len,
u_int32_t timeout)
{
scsi_ata_pass_16(csio,
retries,
cbfcnp,
/*flags*/CAM_DIR_IN,
tag_action,
/*protocol*/AP_PROTO_PIO_IN,
/*ata_flags*/AP_FLAG_TDIR_FROM_DEV|
AP_FLAG_BYT_BLOK_BYTES|AP_FLAG_TLEN_SECT_CNT,
/*features*/0,
/*sector_count*/dxfer_len,
/*lba*/0,
/*command*/ATA_ATA_IDENTIFY,
/*control*/0,
data_ptr,
dxfer_len,
sense_len,
timeout);
scsi_ata_pass(csio,
retries,
cbfcnp,
/*flags*/CAM_DIR_IN,
tag_action,
/*protocol*/AP_PROTO_PIO_IN,
/*ata_flags*/AP_FLAG_TDIR_FROM_DEV |
AP_FLAG_BYT_BLOK_BYTES |
AP_FLAG_TLEN_SECT_CNT,
/*features*/0,
/*sector_count*/dxfer_len,
/*lba*/0,
/*command*/ATA_ATA_IDENTIFY,
/*device*/ 0,
/*icc*/ 0,
/*auxiliary*/ 0,
/*control*/0,
data_ptr,
dxfer_len,
/*cdb_storage*/ NULL,
/*cdb_storage_len*/ 0,
/*minimum_cmd_size*/ 0,
sense_len,
timeout);
}
void
@@ -8179,6 +8196,248 @@ scsi_ata_trim(struct ccb_scsiio *csio, u_int32_t retries,
timeout);
}
int
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;
int retval;
retval = 0;
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;
retval = scsi_ata_pass(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,
/*feature*/ 0,
/*sector_count*/ count_out,
/*lba*/ lba,
/*command*/ command,
/*device*/ 0,
/*icc*/ 0,
/*auxiliary*/ 0,
/*control*/0,
data_ptr,
dxfer_len,
/*cdb_storage*/ NULL,
/*cdb_storage_len*/ 0,
/*minimum_cmd_size*/ 0,
sense_len,
timeout);
return (retval);
}
/*
* Note! This is an unusual CDB building function because it can return
* an error in the event that the command in question requires a variable
* length CDB, but the caller has not given storage space for one or has not
* given enough storage space. If there is enough space available in the
* standard SCSI CCB CDB bytes, we'll prefer that over passed in storage.
*/
int
scsi_ata_pass(struct ccb_scsiio *csio, uint32_t retries,
void (*cbfcnp)(struct cam_periph *, union ccb *),
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 device, uint8_t icc, uint32_t auxiliary,
uint8_t control, u_int8_t *data_ptr, uint32_t dxfer_len,
uint8_t *cdb_storage, size_t cdb_storage_len,
int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout)
{
uint32_t cam_flags;
uint8_t *cdb_ptr;
int cmd_size;
int retval;
uint8_t cdb_len;
retval = 0;
cam_flags = flags;
/*
* Round the user's request to the nearest command size that is at
* least as big as what he requested.
*/
if (minimum_cmd_size <= 12)
cmd_size = 12;
else if (minimum_cmd_size > 16)
cmd_size = 32;
else
cmd_size = 16;
/*
* If we have parameters that require a 48-bit ATA command, we have to
* use the 16 byte ATA PASS-THROUGH command at least.
*/
if (((lba > ATA_MAX_28BIT_LBA)
|| (sector_count > 255)
|| (features > 255)
|| (protocol & AP_EXTEND))
&& ((cmd_size < 16)
|| ((protocol & AP_EXTEND) == 0))) {
if (cmd_size < 16)
cmd_size = 16;
protocol |= AP_EXTEND;
}
/*
* The icc and auxiliary ATA registers are only supported in the
* 32-byte version of the ATA PASS-THROUGH command.
*/
if ((icc != 0)
|| (auxiliary != 0)) {
cmd_size = 32;
protocol |= AP_EXTEND;
}
if ((cmd_size > sizeof(csio->cdb_io.cdb_bytes))
&& ((cdb_storage == NULL)
|| (cdb_storage_len < cmd_size))) {
retval = 1;
goto bailout;
}
/*
* At this point we know we have enough space to store the command
* in one place or another. We prefer the built-in array, but used
* the passed in storage if necessary.
*/
if (cmd_size <= sizeof(csio->cdb_io.cdb_bytes))
cdb_ptr = csio->cdb_io.cdb_bytes;
else {
cdb_ptr = cdb_storage;
cam_flags |= CAM_CDB_POINTER;
}
if (cmd_size <= 12) {
struct ata_pass_12 *cdb;
cdb = (struct ata_pass_12 *)cdb_ptr;
cdb_len = sizeof(*cdb);
bzero(cdb, cdb_len);
cdb->opcode = ATA_PASS_12;
cdb->protocol = protocol;
cdb->flags = ata_flags;
cdb->features = features;
cdb->sector_count = sector_count;
cdb->lba_low = lba & 0xff;
cdb->lba_mid = (lba >> 8) & 0xff;
cdb->lba_high = (lba >> 16) & 0xff;
cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
cdb->command = command;
cdb->control = control;
} else if (cmd_size <= 16) {
struct ata_pass_16 *cdb;
cdb = (struct ata_pass_16 *)cdb_ptr;
cdb_len = sizeof(*cdb);
bzero(cdb, cdb_len);
cdb->opcode = ATA_PASS_16;
cdb->protocol = protocol;
cdb->flags = ata_flags;
cdb->features = features & 0xff;
cdb->sector_count = sector_count & 0xff;
cdb->lba_low = lba & 0xff;
cdb->lba_mid = (lba >> 8) & 0xff;
cdb->lba_high = (lba >> 16) & 0xff;
/*
* If AP_EXTEND is set, we're sending a 48-bit command.
* Otherwise it's a 28-bit command.
*/
if (protocol & AP_EXTEND) {
cdb->lba_low_ext = (lba >> 24) & 0xff;
cdb->lba_mid_ext = (lba >> 32) & 0xff;
cdb->lba_high_ext = (lba >> 40) & 0xff;
cdb->features_ext = (features >> 8) & 0xff;
cdb->sector_count_ext = (sector_count >> 8) & 0xff;
cdb->device = device | ATA_DEV_LBA;
} else {
cdb->lba_low_ext = (lba >> 24) & 0xf;
cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
}
cdb->command = command;
cdb->control = control;
} else {
struct ata_pass_32 *cdb;
uint8_t tmp_lba[8];
cdb = (struct ata_pass_32 *)cdb_ptr;
cdb_len = sizeof(*cdb);
bzero(cdb, cdb_len);
cdb->opcode = VARIABLE_LEN_CDB;
cdb->control = control;
cdb->length = sizeof(*cdb) - __offsetof(struct ata_pass_32,
service_action);
scsi_ulto2b(ATA_PASS_32_SA, cdb->service_action);
cdb->protocol = protocol;
cdb->flags = ata_flags;
if ((protocol & AP_EXTEND) == 0) {
lba &= 0x0fffffff;
cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
features &= 0xff;
sector_count &= 0xff;
} else {
cdb->device = device | ATA_DEV_LBA;
}
scsi_u64to8b(lba, tmp_lba);
bcopy(&tmp_lba[2], cdb->lba, sizeof(cdb->lba));
scsi_ulto2b(features, cdb->features);
scsi_ulto2b(sector_count, cdb->count);
cdb->command = command;
cdb->icc = icc;
scsi_ulto4b(auxiliary, cdb->auxiliary);
}
cam_fill_csio(csio,
retries,
cbfcnp,
cam_flags,
tag_action,
data_ptr,
dxfer_len,
sense_len,
cmd_size,
timeout);
bailout:
return (retval);
}
void
scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries,
void (*cbfcnp)(struct cam_periph *, union ccb *),
+95 -1
View File
@@ -1414,6 +1414,7 @@ struct ata_pass_12 {
#define AP_PROTO_UDMA_OUT (0x0b << 1)
#define AP_PROTO_FPDMA (0x0c << 1)
#define AP_PROTO_RESP_INFO (0x0f << 1)
#define AP_PROTO_MASK 0x1e
#define AP_MULTI 0xe0
u_int8_t flags;
#define AP_T_LEN 0x03
@@ -1955,6 +1956,27 @@ struct ata_pass_16 {
u_int8_t control;
};
struct ata_pass_32 {
uint8_t opcode;
uint8_t control;
uint8_t reserved1[5];
uint8_t length;
uint8_t service_action[2];
#define ATA_PASS_32_SA 0x1ff0
uint8_t protocol;
uint8_t flags;
uint8_t reserved2[2];
uint8_t lba[6];
uint8_t features[2];
uint8_t count[2];
uint8_t device;
uint8_t command;
uint8_t reserved3;
uint8_t icc;
uint8_t auxiliary[4];
};
#define SC_SCSI_1 0x01
#define SC_SCSI_2 0x03
@@ -1997,6 +2019,8 @@ struct ata_pass_16 {
#define MODE_SENSE_10 0x5A
#define PERSISTENT_RES_IN 0x5E
#define PERSISTENT_RES_OUT 0x5F
#define EXTENDED_CDB 0x7E
#define VARIABLE_LEN_CDB 0x7F
#define EXTENDED_COPY 0x83
#define RECEIVE_COPY_STATUS 0x84
#define ATA_PASS_16 0x85
@@ -2064,6 +2088,7 @@ struct ata_pass_16 {
#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 */
@@ -2712,10 +2737,17 @@ struct scsi_vpd_block_device_characteristics
uint8_t flags;
#define SVPD_VBULS 0x01
#define SVPD_FUAB 0x02
#define SVPD_HAW_ZBC 0x10
#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
@@ -2774,6 +2806,28 @@ struct scsi_vpd_block_limits
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;
@@ -3344,6 +3398,29 @@ struct scsi_sense_osd_attr_id
uint8_t attr_desc[0];
};
/*
* ATA Return descriptor, used for the SCSI ATA PASS-THROUGH(12), (16) and
* (32) commands. Described in SAT-4r05.
*/
struct scsi_sense_ata_ret_desc
{
uint8_t desc_type;
#define SSD_DESC_ATA 0x09
uint8_t length;
uint8_t flags;
#define SSD_DESC_ATA_FLAG_EXTEND 0x01
uint8_t error;
uint8_t count_15_8;
uint8_t count_7_0;
uint8_t lba_31_24;
uint8_t lba_7_0;
uint8_t lba_39_32;
uint8_t lba_15_8;
uint8_t lba_47_40;
uint8_t lba_23_16;
uint8_t device;
uint8_t status;
};
/*
* Used with Sense keys No Sense (0x00) and Not Ready (0x02).
*
@@ -3960,6 +4037,23 @@ void scsi_ata_trim(struct ccb_scsiio *csio, u_int32_t retries,
u_int8_t *data_ptr, u_int16_t dxfer_len,
u_int8_t sense_len, u_int32_t timeout);
int 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);
int scsi_ata_pass(struct ccb_scsiio *csio, uint32_t retries,
void (*cbfcnp)(struct cam_periph *, union ccb *),
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 device, uint8_t icc, uint32_t auxiliary,
uint8_t control, u_int8_t *data_ptr, uint32_t dxfer_len,
uint8_t *cdb_storage, size_t cdb_storage_len,
int minimum_cmd_size, 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,
+1767 -41
View File
File diff suppressed because it is too large Load Diff
+112
View File
@@ -153,6 +153,84 @@ struct scsi_read_defect_data_12
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,6 +245,8 @@ struct scsi_read_defect_data_12
#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,6 +661,38 @@ void scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
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);
int 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 *cdb_storage,
size_t cdb_storage_len, uint8_t sense_len,
uint32_t timeout);
int 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 *cdb_storage,
size_t cdb_storage_len, uint8_t sense_len,
uint32_t timeout);
__END_DECLS
#endif /* _SCSI_SCSI_DA_H */
+1 -2
View File
@@ -2411,11 +2411,10 @@ ahci_setup_fis(struct ahci_channel *ch, struct ahci_cmd_tab *ctp, union ccb *ccb
fis[11] = ccb->ataio.cmd.features_exp;
if (ccb->ataio.cmd.flags & CAM_ATAIO_FPDMA) {
fis[12] = tag << 3;
fis[13] = 0;
} else {
fis[12] = ccb->ataio.cmd.sector_count;
fis[13] = ccb->ataio.cmd.sector_count_exp;
}
fis[13] = ccb->ataio.cmd.sector_count_exp;
fis[15] = ATA_A_4BIT;
} else {
fis[15] = ccb->ataio.cmd.control;
+2
View File
@@ -309,6 +309,7 @@ g_eli_start(struct bio *bp)
case BIO_WRITE:
case BIO_GETATTR:
case BIO_FLUSH:
case BIO_ZONE:
break;
case BIO_DELETE:
/*
@@ -348,6 +349,7 @@ g_eli_start(struct bio *bp)
case BIO_GETATTR:
case BIO_FLUSH:
case BIO_DELETE:
case BIO_ZONE:
cbp->bio_done = g_std_done;
cp = LIST_FIRST(&sc->sc_geom->consumer);
cbp->bio_to = cp->provider;
+2
View File
@@ -56,6 +56,7 @@ struct bio;
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,6 +319,7 @@ struct bio * g_duplicate_bio(struct bio *);
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);
+41 -1
View File
@@ -549,6 +549,42 @@ g_dev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread
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);
@@ -574,6 +610,9 @@ g_dev_done(struct bio *bp2)
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);
@@ -608,7 +647,8 @@ g_dev_strategy(struct bio *bp)
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_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;
+14
View File
@@ -226,7 +226,11 @@ g_disk_done(struct bio *bp)
if (bp2->bio_error == 0)
bp2->bio_error = bp->bio_error;
bp2->bio_completed += bp->bio_completed;
switch (bp->bio_cmd) {
case BIO_ZONE:
bcopy(&bp->bio_zone, &bp2->bio_zone, sizeof(bp->bio_zone));
/*FALLTHROUGH*/
case BIO_READ:
case BIO_WRITE:
case BIO_DELETE:
@@ -515,6 +519,16 @@ g_disk_start(struct bio *bp)
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);
+1
View File
@@ -109,6 +109,7 @@ struct disk {
#define DISKFLAG_CANFLUSHCACHE 0x8
#define DISKFLAG_UNMAPPED_BIO 0x10
#define DISKFLAG_DIRECT_COMPLETION 0x20
#define DISKFLAG_CANZONE 0x80
struct disk *disk_alloc(void);
void disk_create(struct disk *disk, int version);
+68
View File
@@ -218,6 +218,9 @@ g_clone_bio(struct bio *bp)
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;
@@ -304,6 +307,34 @@ g_io_getattr(const char *attr, struct g_consumer *cp, int *len, void *ptr)
return (error);
}
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)
{
@@ -349,6 +380,14 @@ g_io_check(struct bio *bp)
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);
}
@@ -988,6 +1027,35 @@ g_print_bio(struct bio *bp)
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 = "UNKNOWN";
break;
}
printf("%s[%s,%s]", pname, cmd, subcmd);
return;
}
case BIO_READ:
cmd = "READ";
break;
+1
View File
@@ -1471,6 +1471,7 @@ db_print_bio_cmd(struct bio *bp)
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");
+3 -1
View File
@@ -354,7 +354,9 @@ devstat_end_transaction_bio_bt(struct devstat *ds, struct bio *bp,
if (bp->bio_cmd == BIO_DELETE)
flg = DEVSTAT_FREE;
else if (bp->bio_cmd == BIO_READ)
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;
+374 -4
View File
@@ -105,6 +105,10 @@ struct ata_params {
/*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 */
@@ -228,7 +232,14 @@ struct ata_params {
#define ATA_SUPPORT_RWLOGDMAEXT 0x0008
#define ATA_SUPPORT_MICROCODE3 0x0010
#define ATA_SUPPORT_FREEFALL 0x0020
#define ATA_SUPPORT_SENSE_REPORT 0x0040
#define ATA_SUPPORT_EPC 0x0080
/*120*/ u_int16_t enabled2;
#define ATA_ENABLED_WRITEREADVERIFY 0x0002
#define ATA_ENABLED_WRITEUNCORREXT 0x0004
#define ATA_ENABLED_FREEFALL 0x0020
#define ATA_ENABLED_SENSE_REPORT 0x0040
#define ATA_ENABLED_EPC 0x0080
u_int16_t reserved121[6];
/*127*/ u_int16_t removable_status;
/*128*/ u_int16_t security_status;
@@ -298,8 +309,14 @@ struct ata_params {
#define ATA_MAX_28BIT_LBA 268435455UL
/* ATA Status Register */
#define ATA_STATUS_ERROR 0x01
#define ATA_STATUS_DEVICE_FAULT 0x20
#define ATA_STATUS_ERROR 0x01
#define ATA_STATUS_SENSE_AVAIL 0x02
#define ATA_STATUS_ALIGN_ERR 0x04
#define ATA_STATUS_DATA_REQ 0x08
#define ATA_STATUS_DEF_WRITE_ERR 0x10
#define ATA_STATUS_DEVICE_FAULT 0x20
#define ATA_STATUS_DEVICE_READY 0x40
#define ATA_STATUS_BUSY 0x80
/* ATA Error Register */
#define ATA_ERROR_ABORT 0x04
@@ -372,17 +389,32 @@ struct ata_params {
#define ATA_WU_PSEUDO 0x55 /* pseudo-uncorrectable error */
#define ATA_WU_FLAGGED 0xaa /* flagged-uncorrectable error */
#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 auxiliary */
#define ATA_SFPDMA_HYBRID_EVICT 0x01 /* Hybrid Evict */
#define ATA_SFPDMA_WLDMA 0x02 /* Write Log DMA EXT */
#define ATA_RECV_FPDMA_QUEUED 0x65 /* receive DMA NCQ */
#define ATA_SFPDMA_ZAC_MGMT_OUT 0x03 /* NCQ ZAC mgmt out w/data */
#define ATA_RECV_FPDMA_QUEUED 0x65 /* receive 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 */
@@ -409,18 +441,29 @@ struct ata_params {
#define ATA_FLUSHCACHE48 0xea /* flush cache to disk */
#define ATA_ATA_IDENTIFY 0xec /* get ATA params */
#define ATA_SETFEATURES 0xef /* features command */
#define ATA_SF_SETXFER 0x03 /* set transfer mode */
#define ATA_SF_ENAB_WCACHE 0x02 /* enable write cache */
#define ATA_SF_DIS_WCACHE 0x82 /* disable write cache */
#define ATA_SF_SETXFER 0x03 /* set transfer mode */
#define ATA_SF_APM 0x05 /* Enable APM feature set */
#define ATA_SF_ENAB_PUIS 0x06 /* enable PUIS */
#define ATA_SF_DIS_PUIS 0x86 /* disable PUIS */
#define ATA_SF_PUIS_SPINUP 0x07 /* PUIS spin-up */
#define ATA_SF_WRV 0x0b /* Enable Write-Read-Verify */
#define ATA_SF_DLC 0x0c /* Enable device life control */
#define ATA_SF_SATA 0x10 /* Enable use of SATA feature */
#define ATA_SF_FFC 0x41 /* Free-fall Control */
#define ATA_SF_MHIST 0x43 /* Set Max Host Sect. Times */
#define ATA_SF_RATE 0x45 /* Set Rate Basis */
#define ATA_SF_EPC 0x4A /* Extended Power Conditions */
#define ATA_SF_ENAB_RCACHE 0xaa /* enable readahead cache */
#define ATA_SF_DIS_RCACHE 0x55 /* disable readahead cache */
#define ATA_SF_ENAB_RELIRQ 0x5d /* enable release interrupt */
#define ATA_SF_DIS_RELIRQ 0xdd /* disable release interrupt */
#define ATA_SF_ENAB_SRVIRQ 0x5e /* enable service interrupt */
#define ATA_SF_DIS_SRVIRQ 0xde /* disable service interrupt */
#define ATA_SF_LPSAERC 0x62 /* Long Phys Sect Align ErrRep*/
#define ATA_SF_DSN 0x63 /* Device Stats Notification */
#define ATA_CHECK_POWER_MODE 0xe5 /* Check Power Mode */
#define ATA_SECURITY_SET_PASSWORD 0xf1 /* set drive password */
#define ATA_SECURITY_UNLOCK 0xf2 /* unlock drive using passwd */
#define ATA_SECURITY_ERASE_PREPARE 0xf3 /* prepare to erase drive */
@@ -547,6 +590,333 @@ struct atapi_sense {
u_int8_t specific2; /* sense key specific */
} __packed;
/*
* SET FEATURES subcommands
*/
/*
* SET FEATURES command
* Extended Power Conditions subcommand -- ATA_SF_EPC (0x4A)
* These values go in the LBA 3:0.
*/
#define ATA_SF_EPC_RESTORE 0x00 /* Restore Power Condition Settings */
#define ATA_SF_EPC_GOTO 0x01 /* Go To Power Condition */
#define ATA_SF_EPC_SET_TIMER 0x02 /* Set Power Condition Timer */
#define ATA_SF_EPC_SET_STATE 0x03 /* Set Power Condition State */
#define ATA_SF_EPC_ENABLE 0x04 /* Enable the EPC feature set */
#define ATA_SF_EPC_DISABLE 0x05 /* Disable the EPC feature set */
#define ATA_SF_EPC_SET_SOURCE 0x06 /* Set EPC Power Source */
/*
* SET FEATURES command
* Extended Power Conditions subcommand -- ATA_SF_EPC (0x4A)
* Power Condition ID field
* These values go in the count register.
*/
#define ATA_EPC_STANDBY_Z 0x00 /* Substate of PM2:Standby */
#define ATA_EPC_STANDBY_Y 0x01 /* Substate of PM2:Standby */
#define ATA_EPC_IDLE_A 0x81 /* Substate of PM1:Idle */
#define ATA_EPC_IDLE_B 0x82 /* Substate of PM1:Idle */
#define ATA_EPC_IDLE_C 0x83 /* Substate of PM1:Idle */
#define ATA_EPC_ALL 0xff /* All supported power conditions */
/*
* SET FEATURES command
* Extended Power Conditions subcommand -- ATA_SF_EPC (0x4A)
* Restore Power Conditions Settings subcommand
* These values go in the LBA register.
*/
#define ATA_SF_EPC_RST_DFLT 0x40 /* 1=Rst from Default, 0= from Saved */
#define ATA_SF_EPC_RST_SAVE 0x10 /* 1=Save on completion */
/*
* SET FEATURES command
* Extended Power Conditions subcommand -- ATA_SF_EPC (0x4A)
* Got To Power Condition subcommand
* These values go in the LBA register.
*/
#define ATA_SF_EPC_GOTO_DELAY 0x02000000 /* Delayed entry bit */
#define ATA_SF_EPC_GOTO_HOLD 0x01000000 /* Hold Power Cond bit */
/*
* SET FEATURES command
* Extended Power Conditions subcommand -- ATA_SF_EPC (0x4A)
* Set Power Condition Timer subcommand
* These values go in the LBA register.
*/
#define ATA_SF_EPC_TIMER_MASK 0x00ffff00 /* Timer field */
#define ATA_SF_EPC_TIMER_SHIFT 8
#define ATA_SF_EPC_TIMER_SEC 0x00000080 /* Timer units, 1=sec, 0=.1s */
#define ATA_SF_EPC_TIMER_EN 0x00000020 /* Enable/disable cond. */
#define ATA_SF_EPC_TIMER_SAVE 0x00000010 /* Save settings on comp. */
/*
* SET FEATURES command
* Extended Power Conditions subcommand -- ATA_SF_EPC (0x4A)
* Set Power Condition State subcommand
* These values go in the LBA register.
*/
#define ATA_SF_EPC_SETCON_EN 0x00000020 /* Enable power cond. */
#define ATA_SF_EPC_SETCON_SAVE 0x00000010 /* Save settings on comp */
/*
* SET FEATURES command
* Extended Power Conditions subcommand -- ATA_SF_EPC (0x4A)
* Set EPC Power Source subcommand
* These values go in the count register.
*/
#define ATA_SF_EPC_SRC_UNKNOWN 0x0000 /* Unknown source */
#define ATA_SF_EPC_SRC_BAT 0x0001 /* battery source */
#define ATA_SF_EPC_SRC_NOT_BAT 0x0002 /* not battery source */
#define ATA_LOG_DIRECTORY 0x00 /* Directory of all logs */
#define ATA_POWER_COND_LOG 0x08 /* Power Conditions Log */
#define ATA_PCL_IDLE 0x00 /* Idle Power Conditions Page */
#define ATA_PCL_STANDBY 0x01 /* Standby Power Conditions Page */
#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 Power Conditions log descriptor
*/
struct ata_power_cond_log_desc {
uint8_t reserved1;
uint8_t flags;
#define ATA_PCL_COND_SUPPORTED 0x80
#define ATA_PCL_COND_SAVEABLE 0x40
#define ATA_PCL_COND_CHANGEABLE 0x20
#define ATA_PCL_DEFAULT_TIMER_EN 0x10
#define ATA_PCL_SAVED_TIMER_EN 0x08
#define ATA_PCL_CURRENT_TIMER_EN 0x04
#define ATA_PCL_HOLD_PC_NOT_SUP 0x02
uint8_t reserved2[2];
uint8_t default_timer[4];
uint8_t saved_timer[4];
uint8_t current_timer[4];
uint8_t nom_time_to_active[4];
uint8_t min_timer[4];
uint8_t max_timer[4];
uint8_t num_transitions_to_pc[4];
uint8_t hours_in_pc[4];
uint8_t reserved3[28];
};
/*
* ATA Power Conditions Log (0x08), Idle power conditions page (0x00)
*/
struct ata_power_cond_log_idle {
struct ata_power_cond_log_desc idle_a_desc;
struct ata_power_cond_log_desc idle_b_desc;
struct ata_power_cond_log_desc idle_c_desc;
uint8_t reserved[320];
};
/*
* ATA Power Conditions Log (0x08), Standby power conditions page (0x01)
*/
struct ata_power_cond_log_standby {
uint8_t reserved[384];
struct ata_power_cond_log_desc standby_y_desc;
struct ata_power_cond_log_desc standby_z_desc;
};
/*
* 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 {
+9 -6
View File
@@ -39,16 +39,18 @@
#define _SYS_BIO_H_
#include <sys/queue.h>
#include <sys/disk_zone.h>
/* bio_cmd */
#define BIO_READ 0x01 /* Read I/O data */
#define BIO_WRITE 0x02 /* Write I/O data */
#define BIO_DELETE 0x04 /* TRIM or free blocks, i.e. mark as unused */
#define BIO_GETATTR 0x08 /* Get GEOM attributes of object */
#define BIO_FLUSH 0x10 /* Commit outstanding I/O now */
#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_DELETE 0x03 /* TRIM or free blocks, i.e. mark as unused */
#define BIO_GETATTR 0x04 /* Get GEOM attributes of object */
#define BIO_FLUSH 0x05 /* Commit outstanding I/O now */
#define BIO_CMD0 0x06 /* Available for local hacks */
#define BIO_CMD1 0x07 /* Available for local hacks */
#define BIO_CMD2 0x08 /* Available for local hacks */
#define BIO_ZONE 0x09 /* Zone command */
/* bio_flags */
#define BIO_ERROR 0x01 /* An error occurred processing this bio. */
@@ -98,6 +100,7 @@ struct bio {
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 */
+3
View File
@@ -15,6 +15,7 @@
#include <sys/ioccom.h>
#include <sys/types.h>
#include <sys/disk_zone.h>
#ifdef _KERNEL
@@ -136,4 +137,6 @@ struct diocgattr_arg {
};
#define DIOCGATTR _IOWR('d', 142, struct diocgattr_arg)
#define DIOCZONECMD _IOWR('d', 143, struct disk_zone_args)
#endif /* _SYS_DISK_H_ */
+184
View File
@@ -0,0 +1,184 @@
/*-
* 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$
*/
#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_ */
+1 -1
View File
@@ -58,7 +58,7 @@
* in the range 5 to 9.
*/
#undef __FreeBSD_version
#define __FreeBSD_version 1100109 /* Master, propagated to newvers */
#define __FreeBSD_version 1100110 /* Master, propagated to newvers */
/*
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
+2 -1
View File
@@ -96,7 +96,8 @@ SUBDIR= adduser \
wake \
watch \
watchdogd \
zic
zic \
zonectl
# NB: keep these sorted by MK_* knobs
+47 -1
View File
@@ -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,14 +55,18 @@ static int opt_c, opt_t, opt_v;
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;
u_int sectorsize, fwsectors, fwheads, zoned = 0;
uint32_t zone_mode;
while ((ch = getopt(argc, argv, "ctv")) != -1) {
switch (ch) {
@@ -121,6 +126,9 @@ main(int argc, char **argv)
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,6 +163,8 @@ main(int argc, char **argv)
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,3 +396,39 @@ commandtime(int fd, off_t mediasize, u_int sectorsize)
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);
}
+10
View File
@@ -0,0 +1,10 @@
# $FreeBSD$
PROG= zonectl
SRCS= zonectl.c
SDIR= ${.CURDIR}/../../sys
LIBADD= cam sbuf util
MAN= zonectl.8
CFLAGS+=-g -O0
.include <bsd.prog.mk>
+236
View File
@@ -0,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 May 18, 2016
.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
Display basic zoning information for disk da5.
.Pp
.Bd -literal -offset indent
zonectl -d /dev/da5 -c rz
.Ed
.Pp
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
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.
Print the zones in a script friendly form.
.Pp
.Bd -literal -offset indent
zonectl -d /dev/da5 -c rwp -l 0x2c80000
.Ed
.Pp
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
+591
View File
@@ -0,0 +1,591 @@
/*-
* Copyright (c) 2015, 2016 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 <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/ioctl.h>
#include <sys/stdint.h>
#include <sys/types.h>
#include <sys/endian.h>
#include <sys/sbuf.h>
#include <sys/queue.h>
#include <sys/disk.h>
#include <sys/disk_zone.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <fcntl.h>
#include <ctype.h>
#include <limits.h>
#include <err.h>
#include <locale.h>
#include <cam/cam.h>
#include <cam/cam_debug.h>
#include <cam/cam_ccb.h>
#include <cam/scsi/scsi_all.h>
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 = 16384;
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);
}