Informing the Host about Media Changes
A device that interfaces to a MultiMediaCard or other removable mediashould inform the USB host when a card is inserted. A device must alsoinform the host if the host attempts to access the device when the media has been removed or the device isn’t ready to perform read, write, or verify operations for another reason.
To inform the host that media has been inserted, a device can generate a UNIT ATTENTION condition and set ASC = 28h and ASCQ = 00h, which the SPC specification defines as NOT READY TO READY CHANGE, MEDIUM MAY HAVE CHANGED.
On receiving a media-access command when the media is removed, a device should set the SENSE KEY field to 02h (NOT READY) and set ASC = 3Ah and ASCQ = 00h, which the SPC specification defines as MEDIUM NOT PRESENT.
After a device reports that the media isn’t present, a host may send periodic TEST UNIT READY commands to find out if media has been inserted. After a device reports that the media has changed, the host can send commands to learn about the new media.
In a similar way, a device that accesses files on its own (not via the USB host) should inform the USB host when firmware has written to a file or made other changes to a volume’s contents. A device can do so via the UNIT ATTENTION condition as described above. Another option is to allow device firmware to access files on its own only when the device isn’t attached to and enumerated by a USB host. For example, a data logger can collect data in the field and store the data in files. When the device is brought in from the field and attached to a USB host, the firmware no longer collects and stores data on its own and instead responds to commands from the USB host. Device firmware can use the presence of VBUS or successful enumeration of an attached device to determine whether the firmware can access files.
A device generates a UNIT ATTENTION condition after experiencing a reset. The SCSI Architectural Model specification describes three conditions that correspond to different reset types. The conditions are power on, hard reset, and logical-unit reset. A device sets an ADDITIONAL SENSE CODE value to indicate which type of reset occurred.
A power-on condition exists after power is applied. The power-on condition causes a hard-reset condition. A transport protocol can define other events that cause a device to enter the hard-reset condition. A hard reset in turn causes the device to enter the logical-unit reset condition. Other logical-unit reset events can cause the device to enter the logical-unit reset condition. Unlike the power-on and hard reset, a logical-unit reset doesn’t reset mode-page and other parameters to default values.
The USB specifications define two reset types for mass-storage devices: the USB port reset and the Bulk-Only Mass Storage Reset request. The USB specifications don’t map these resets to SCSI reset types and thus don’t specify SCSI behaviors on resetting. Devices typically map the USB port reset to the SCSI hard reset. Some devices map the bulk-only mass-storage reset to the hard reset, while others map the bulk-only reset to the logical-unit reset. Problems can result if a host’s expectations don’t match a device’s behavior after a reset.