SG_RAW(8) | SG3_UTILS | SG_RAW(8) |
sg_raw - send arbitrary SCSI command to a device
sg_raw [--binary] [--cmdfile=CF] [--enumerate] [--help] [--infile=IFILE] [--nosense] [--outfile=OFILE] [--readonly] [--request=RLEN] [--send=SLEN] [--skip=KLEN] [--timeout=SECS] [--verbose] [--version] DEVICE [CDB0 CDB1 ...]
This utility sends an arbitrary SCSI command (between 6 and 256 bytes) to the DEVICE. There may be no associated data transfer; or data may be read from a file and sent to the DEVICE; or data may be received from the DEVICE and then displayed or written to a file. If supported by the pass through, bidirectional commands may be sent (i.e. containing both data to be sent to the DEVICE and received from the DEVICE).
The SCSI command may be between 6 and 256 bytes long. Each command byte is specified in plain hex format (00..FF) without a prefix or suffix. The command can be given either on the command line or via the --cmdfile=CF option. See EXAMPLES section below.
The commands pass through a generic SCSI interface which is implemented for several operating systems including Linux, FreeBSD and Windows.
Experimental support has been added to send NVMe Admin commands to the DEVICE. Since all NVMe commands are 64 bytes long it is more convenient to use the --cmdfile=CF option rather than type the 64 bytes of the NVMe command on the command line. See the section on NVME below.
Arguments to long options are mandatory for short options as well. The options are arranged in alphabetical order based on the long option name.
The sg_inq utility can be used to send an INQUIRY command to a device to determine its peripheral device type (e.g. '1' for a streaming device (tape drive)) which determines which SCSI command sets a device should support (e.g. SPC and SSC). The sg_vpd utility reads and decodes a device's Vital Product Pages which may contain useful information.
The ability to send more than a 16 byte CDB (in some cases 12 byte CDB) may be restricted by the pass-through interface, the low level driver or the transport. In the Linux series 3 kernels, the bsg driver can handle longer CDBs, block devices (e.g. /dev/sdc) accessed via the SG_IO ioctl cannot handle CDBs longer than 16 bytes, and the sg driver can handle longer CDBs from lk 3.17 .
The CDB command name defined by T10 for the given CDB is shown if the '-vv' option is given. The command line syntax still needs to be correct, so /dev/null may be used for the DEVICE since the CDB command name decoding is done before the DEVICE is checked.
Support for NVMe (a.k.a. NVM Express) is currently experimental. NVMe concepts map reasonably well to the SCSI architecture. A SCSI logical unit (LU) is similar to a NVMe namespace (although LUN 0 is very common in SCSI while namespace IDs start at 1). A SCSI target device is similar to a NVMe controller. SCSI commands vary from 6 to 260 bytes long (although SCSI command descriptor blocks (cdb_s) longer than 32 bytes are uncommon) while all NVMe commands are currently 64 bytes long. The SCSI architecture makes a clear distinction between an initiator (often called a HBA) and a target (device) while (at least on the PCIe transport) the NVMe controller plays both roles. At this time this utility only supports "Admin" commands (i.e. it does not support the I/O (or "NVM") command set). Admin commands are sent to submission queue 0 while non-admin commands are sent to submissions greater than 0.
One significant difference is that SCSI uses a big endian representation for integers that are longer than 8 bits (i.e. longer than 1 byte) while NVMe uses a little endian representation (like most things that have originated from the Intel organisation). NVMe specifications talk about Words (16 bits), Double Words (32 bits) and sometimes Quad Words (64 bits) and has tighter alignment requirements than SCSI.
One difference that impacts this utility is that NVMe places pointers to host memory in its commands while SCSI leaves this detail to whichever transport it is using (e.g. SAS, iSCSI, SRP). Since this utility takes the command from the user (either on the command line or in a file named CF) but this utility allocates a data-in or data-out buffer as required, the user does not know in advance what the address of that buffer will be. Some special addresses have been introduced to help with this problem: the address 0xfffffffffffffffe is interpreted as "use the data-in buffer's address" while 0xfffffffffffffffd is interpreted as "use the data-out buffer's address". Since NVMe uses little endian notation then that first address appears in the NVMe command byte stream as "fe" followed by seven "ff"s. A similar arrangement is made for the length of that buffer, but since that is a 32 byte quantity, the first 4 bytes (all "ff"s) are removed.
Two command file examples can be found in the examples directory of this package's source tarball: nvme_identify_ctl.hex and nvme_dev_self_test.hex .
These examples, apart from the last one, use Linux device names. For suitable device names in other supported Operating Systems see the sg3_utils(8) man page.
The exit status of sg_raw is 0 when it is successful. Otherwise see the sg3_utils(8) man page.
Written by Ingo van Lil
Report bugs to <inguin at gmx dot de>.
Copyright © 2001-2018 Ingo van Lil
This software is distributed under the GPL version 2. There is NO warranty;
not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
sg_inq, sg_vpd, sg3_utils (sg3_utils), plscsi
May 2018 | sg3_utils-1.43 |