Monday, 29 April 2013

SCSI FUNDAMENTALS - 2


SCSI COMMANDS AND THEIR FORMAT


A SCSI command is generated by the Initiator (in the host) and is sent to the Target in the command phase. A command and its parameters are sent as a block several bytes long called the Command Descriptor Block (CDB). In SCSI-2 or SCSI-3, there are three groups of commands, depending on the length of their CDBs:
Group - 0 uses 6-byte CDBs
- 1,2 uses 10-byte CDBs
- 5 uses 12-byte CDBs
Command groups 3 and 4 are reserved, and groups 6 and 7 are "vendor specific"


The generic structure of the CDB of all groups is as follows:
The first byte of the CDB is the Operation Code (OP code). It is followed by the Logical Unit Number (LUN) in the upper three bits of the second byte, and by the block address (LBA) and transfer length fields (Read and Write commands) or other parameters. The last byte of each CDB is the Control byte. This byte contains two important bits, the LINK and FLAG; these bits are used for controlling the linked commands mechanism.

CDB EXAMPLE TAKEN FROM THE SCSI SPECIFICATION

The following illustration shows exact format and definition of a READ command CDB (Command
Descriptor Block). A definition of individual fields and values of the CDB follows. In the EXAMPLES
OF SCSI COMMANDS section, the CDBs are shown as the Command phase (on the fifth line) in
each of the examples.
READ command CDB (Command Descriptor Block)


The READ(6)  command with opcode 08h requests that the target transfer data to the initiator. The most recent data value written in the addressed logical block shall be returned.
The cache control bits are not provided for this format. Targets with cache memory may have values for the cache control bits that affect the READ(6) command; however, no default value is defined by this command. If explicit control is required, the READ(10) command should be used. The logical block address field specifies the logical block at which the read operation shall begin.
The transfer length field specifies the number of contiguous logical blocks of data to be transferred. A transfer length of zero indicates that 256 logical blocks shall be transferred. Any other value indicates the number of logical blocks that shall be transferred.


SCSI COMMAND PHASES


Individual commands execute in subsequent parts called phases. Some phases are set by the Initiator, some by the Target. Following is a list of SCSI command phases:

  • arbitration
  • selection
  • message out
  • message in
  • command data out
  • data in
  • status
  • bus free

The SCSI specification allows execution of command phases in any order, with the exception that each command must start with arbitration and selection.


COMMAND LINKING


The LINK and FLAG bits in the Control byte of a CDB (the last byte) allow linking of two or more successive commands together. If the LINK bit is set, the current command does not end with Bus
Free phase, but attaches the following command by starting with its Command phase instead. 
Command linking is used for example in data base applications when a Read command must be followed immediately by a Write command, without interruption from another Initiator (host).


COMMAND QUEUING


Command Queuing is the capability of a SCSI Target to accept multiple commands (I/O Processes), and to execute them in an optimum sequence. This may sometimes be useful, for example, in a high performance system to minimize latency, access, or seek times in disks. It is an optional function which may or may not be supported by a Target.


NEGOTIATING FOR THE BUS (Starting a SCSI Command)


The negotiation stage begins with an idle bus. The idle condition is called the Bus Free phase, and is detected when both the BSY and SEL control lines are released by all devices. During a Bus Free phase, a device needing to use the bus begins an Arbitration phase by asserting the BSY control line and its own ID data line. Note that the device drives only one data bit representing its own ID number. 

At the same time, other data bits (lines) may be driven by the devices that own them. If more than one device attempts to gain control during the same Arbitration phase, the one with the highest priority ID number (see Figure 3) wins control of the bus, and the losing devices must release all their lines
within a specified time. The winning device then attempts to get the attention of its Target by beginning a Selection or Reselection phase. The SEL control line is asserted, and the ID data line for the device being addressed is added to the data bus; at this point, two data lines (Initiator ID and Target ID bits) are driven "true" (Low) and with good (odd) parity. After this, the BSY control line is released. When the addressed device notices that it is being addressed, it asserts the BSY control
line. Finally, the calling device releases the SEL control line and the data bus.


CONTROL OVER THE BUS


The wires of the SCSI bus are shared among all the devices connected. Because the wires can carry only one piece of information at a time, a device which wishes to use the SCSI bus must obtain permission from all the other devices (Arbitration phase). After winning the arbitration, the device controlling the bus must get the attention of the device with which it wishes to communicate (Selection phase). These actions together makeup the initial part of each command. Following the selection phase, information transfer starts, and the data is sent between the two devices.


INFORMATION TRANSFER


An information stage begins when the selection phase ends. During the information stage, the Target controls the quantity and variety of information transmitted, and the direction of transfer for each byte. As in the arbitration and selection phases, the information stage is divided into individual phases called Information Transfer phases: Msg-Out phase, Command phase, Data-In/Out phase, Status phase, and Msg-Inphase.


Message-Out phase, where the Initiator tells the Target which part of the Target (which LUN) should act on the command.


Command phase. This is the time when the Initiator tells the Target what to do; it sends the Command Descriptor Block (CDB) to the Target. The particular command may require that more information be transferred between the devices. This is done during a Data-In or Data-Out phase, but never both within the same command.


Target tells the Initiator whether the command was successful or not by using the Status phase.

Finally, the command is completed by sending final progress report using a Message-In phase.


THE MESSAGE SYSTEM


The message system in SCSI is used to allow communication between the Initiators and Targets for the purpose of interface management. Messages can be sent in both directions: message-out from Initiator to Target, or message-in from Target to Initiator. There are three types of message formats:

1. single-byte,
2. two-byte, and
3. extended messages - which can be three bytes or longer.

We can also classify messages by their usage:

1. Identification messages identify the I/O process as part of an initial connection by a host
adapter or during re-connection by a target.
2. I/O Process Management messages are used to manage I/O processes, logical units, and
targets.
3. Connection Management messages manage the physical transfer of information between host
adapters and targets.




The most common message is the single byte with value = 00, which means "command complete".
This is the I/O Process Management message which is sent in the last phase of a command.


THE STATUS


Status of the Target is reported to the Initiator on two levels: brief status in the status phase of each command, or more detailed status in SENSE DATA. The status byte at the end of each SCSI command (in status phase) reports to the Initiator whether
execution of a command was successful (value = 00), whether an error occurred (value = 02), or reports other information like BUSY (value = 08), etc. This status byte does not give any detailed information however.



If a Check Condition status is reported for a command (value = 02) it means that some condition exists which prevented successful completion of that command. It could be an error in the CDB, a hardware problem, or some external problem. The Initiator can obtain detailed information regarding this condition by issuing a REQUEST SENSE command. The Target will respond by returning SENSE DATA in the data-in phase of the same command.

The SENSE DATA is a set of flags and indicators within the Target, which are continuously updated to reflect current status in full detail. The SENSE DATA is presented in a hierarchical manner by the Target. It starts with general conditions and proceeds to specific conditions as follows:

1. SENSE-KEY
2. ADDITIONAL SENSE CODE (ASC)
3. ADDITIONAL SENSE CODE QUALIFIER (ASCQ)

The Sense Key defines the class of error or condition nformation. There are fifteen Sense Keys which classify the device condition as hardware or software problem, a fatal or recoverable error, etc. The ASC and the ASCQ provide more detailed information. Consult the SCSI specification and your particular device manual for specific descriptions.

EXAMPLES OF SCSI COMMANDS AND USAGE RULES

TEST UNIT READY



INQUIRY


Note: The above post is to get a understanding on  SCSI interface with a hardware background.















2 comments:

  1. Hi Anna,

    I have one doubt.. regd SCSI Arch Model?

    What is the difference between LUN congl and LUN?
    what is the use of Well known LUN?

    ReplyDelete
  2. All SCSI target devices shall support LUN 0 or the REPORT LUNS well-known logical unit, support for WLUN is optional, there are several addressing format for logical unit is supported in SAM (scsi arch model) Eg: peripheral addressing, Lun addressing, well known addressing, WLUN are logical unit that only performs specific functions. Usage I feel it will be house keeping LUN when SCSI used in hierarchical manner section 4.6 on SAM 4 elaborates on this

    ReplyDelete