iPXE
|
SCSI block device. More...
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <byteswap.h>
#include <errno.h>
#include <ipxe/list.h>
#include <ipxe/process.h>
#include <ipxe/xfer.h>
#include <ipxe/blockdev.h>
#include <ipxe/scsi.h>
Go to the source code of this file.
Data Structures | |
struct | scsi_device |
A SCSI device. More... | |
struct | scsi_command |
A SCSI command. More... | |
struct | scsi_command_type |
A SCSI command type. More... | |
struct | scsi_read_capacity_private |
SCSI READ CAPACITY private data. More... | |
Enumerations | |
enum | scsi_device_flags { SCSIDEV_UNIT_TESTED = 0x0001, SCSIDEV_UNIT_READY = 0x0002 } |
SCSI device flags. More... | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
int | scsi_parse_lun (const char *lun_string, struct scsi_lun *lun) |
Parse SCSI LUN. More... | |
void | scsi_parse_sense (const void *data, size_t len, struct scsi_sns_descriptor *sense) |
Parse SCSI sense data. More... | |
int | scsi_command (struct interface *control, struct interface *data, struct scsi_cmd *command) |
Issue SCSI command. More... | |
void | scsi_response (struct interface *intf, struct scsi_rsp *response) |
Report SCSI response. More... | |
static struct scsi_device * | scsidev_get (struct scsi_device *scsidev) |
Get reference to SCSI device. More... | |
static void | scsidev_put (struct scsi_device *scsidev) |
Drop reference to SCSI device. More... | |
static struct scsi_command * | scsicmd_get (struct scsi_command *scsicmd) |
Get reference to SCSI command. More... | |
static void | scsicmd_put (struct scsi_command *scsicmd) |
Drop reference to SCSI command. More... | |
static void * | scsicmd_priv (struct scsi_command *scsicmd) |
Get SCSI command private data. More... | |
static void | scsicmd_free (struct refcnt *refcnt) |
Free SCSI command. More... | |
static void | scsicmd_close (struct scsi_command *scsicmd, int rc) |
Close SCSI command. More... | |
static int | scsicmd_command (struct scsi_command *scsicmd) |
Construct and issue SCSI command. More... | |
static void | scsicmd_done (struct scsi_command *scsicmd, int rc) |
Handle SCSI command completion. More... | |
static void | scsicmd_response (struct scsi_command *scsicmd, struct scsi_rsp *response) |
Handle SCSI response. More... | |
static void | scsicmd_read_cmd (struct scsi_command *scsicmd, struct scsi_cmd *command) |
Construct SCSI READ command. More... | |
static void | scsicmd_write_cmd (struct scsi_command *scsicmd, struct scsi_cmd *command) |
Construct SCSI WRITE command. More... | |
static void | scsicmd_read_capacity_cmd (struct scsi_command *scsicmd, struct scsi_cmd *command) |
Construct SCSI READ CAPACITY command. More... | |
static void | scsicmd_read_capacity_done (struct scsi_command *scsicmd, int rc) |
Handle SCSI READ CAPACITY command completion. More... | |
static void | scsicmd_test_unit_ready_cmd (struct scsi_command *scsicmd __unused, struct scsi_cmd *command) |
Construct SCSI TEST UNIT READY command. More... | |
static int | scsidev_command (struct scsi_device *scsidev, struct interface *block, struct scsi_command_type *type, uint64_t lba, unsigned int count, userptr_t buffer, size_t len) |
Create SCSI command. More... | |
static int | scsidev_read (struct scsi_device *scsidev, struct interface *block, uint64_t lba, unsigned int count, userptr_t buffer, size_t len) |
Issue SCSI block read. More... | |
static int | scsidev_write (struct scsi_device *scsidev, struct interface *block, uint64_t lba, unsigned int count, userptr_t buffer, size_t len) |
Issue SCSI block write. More... | |
static int | scsidev_read_capacity (struct scsi_device *scsidev, struct interface *block) |
Read SCSI device capacity. More... | |
static int | scsidev_test_unit_ready (struct scsi_device *scsidev, struct interface *block) |
Test to see if SCSI device is ready. More... | |
static size_t | scsidev_window (struct scsi_device *scsidev) |
Check SCSI device flow-control window. More... | |
static void | scsidev_close (struct scsi_device *scsidev, int rc) |
Close SCSI device. More... | |
static void | scsidev_ready (struct scsi_device *scsidev, int rc) |
Handle SCSI TEST UNIT READY response. More... | |
static void | scsidev_step (struct scsi_device *scsidev) |
SCSI TEST UNIT READY process. More... | |
int | scsi_open (struct interface *block, struct interface *scsi, struct scsi_lun *lun) |
Open SCSI device. More... | |
Variables | |
static struct scsi_command_type | scsicmd_read |
SCSI READ command type. More... | |
static struct scsi_command_type | scsicmd_write |
SCSI WRITE command type. More... | |
static struct scsi_command_type | scsicmd_read_capacity |
SCSI READ CAPACITY command type. More... | |
static struct scsi_command_type | scsicmd_test_unit_ready |
SCSI TEST UNIT READY command type. More... | |
static struct interface_operation | scsicmd_block_op [] |
SCSI command block interface operations. More... | |
static struct interface_descriptor | scsicmd_block_desc |
SCSI command block interface descriptor. More... | |
static struct interface_operation | scsicmd_scsi_op [] |
SCSI command SCSI interface operations. More... | |
static struct interface_descriptor | scsicmd_scsi_desc |
SCSI command SCSI interface descriptor. More... | |
static struct interface_operation | scsidev_block_op [] |
SCSI device block interface operations. More... | |
static struct interface_descriptor | scsidev_block_desc |
SCSI device block interface descriptor. More... | |
static struct interface_operation | scsidev_ready_op [] |
SCSI device TEST UNIT READY interface operations. More... | |
static struct interface_descriptor | scsidev_ready_desc |
SCSI device TEST UNIT READY interface descriptor. More... | |
static struct interface_operation | scsidev_scsi_op [] |
SCSI device SCSI interface operations. More... | |
static struct interface_descriptor | scsidev_scsi_desc |
SCSI device SCSI interface descriptor. More... | |
static struct process_descriptor | scsidev_process_desc |
SCSI device process descriptor. More... | |
SCSI block device.
Definition in file scsi.c.
#define SCSI_READY_MAX_RETRIES 10 |
#define EIO_NO_SENSE __einfo_error ( EINFO_EIO_NO_SENSE ) |
#define EINFO_EIO_NO_SENSE __einfo_uniqify ( EINFO_EIO, 0x00, "No sense" ) |
#define EIO_RECOVERED_ERROR __einfo_error ( EINFO_EIO_RECOVERED_ERROR ) |
#define EINFO_EIO_RECOVERED_ERROR __einfo_uniqify ( EINFO_EIO, 0x01, "Recovered error" ) |
#define EIO_NOT_READY __einfo_error ( EINFO_EIO_NOT_READY ) |
#define EINFO_EIO_NOT_READY __einfo_uniqify ( EINFO_EIO, 0x02, "Not ready" ) |
#define EIO_MEDIUM_ERROR __einfo_error ( EINFO_EIO_MEDIUM_ERROR ) |
#define EINFO_EIO_MEDIUM_ERROR __einfo_uniqify ( EINFO_EIO, 0x03, "Medium error" ) |
#define EIO_HARDWARE_ERROR __einfo_error ( EINFO_EIO_HARDWARE_ERROR ) |
#define EINFO_EIO_HARDWARE_ERROR __einfo_uniqify ( EINFO_EIO, 0x04, "Hardware error" ) |
#define EIO_ILLEGAL_REQUEST __einfo_error ( EINFO_EIO_ILLEGAL_REQUEST ) |
#define EINFO_EIO_ILLEGAL_REQUEST __einfo_uniqify ( EINFO_EIO, 0x05, "Illegal request" ) |
#define EIO_UNIT_ATTENTION __einfo_error ( EINFO_EIO_UNIT_ATTENTION ) |
#define EINFO_EIO_UNIT_ATTENTION __einfo_uniqify ( EINFO_EIO, 0x06, "Unit attention" ) |
#define EIO_DATA_PROTECT __einfo_error ( EINFO_EIO_DATA_PROTECT ) |
#define EINFO_EIO_DATA_PROTECT __einfo_uniqify ( EINFO_EIO, 0x07, "Data protect" ) |
#define EIO_BLANK_CHECK __einfo_error ( EINFO_EIO_BLANK_CHECK ) |
#define EINFO_EIO_BLANK_CHECK __einfo_uniqify ( EINFO_EIO, 0x08, "Blank check" ) |
#define EIO_VENDOR_SPECIFIC __einfo_error ( EINFO_EIO_VENDOR_SPECIFIC ) |
#define EINFO_EIO_VENDOR_SPECIFIC __einfo_uniqify ( EINFO_EIO, 0x09, "Vendor specific" ) |
#define EIO_COPY_ABORTED __einfo_error ( EINFO_EIO_COPY_ABORTED ) |
#define EINFO_EIO_COPY_ABORTED __einfo_uniqify ( EINFO_EIO, 0x0a, "Copy aborted" ) |
#define EIO_ABORTED_COMMAND __einfo_error ( EINFO_EIO_ABORTED_COMMAND ) |
#define EINFO_EIO_ABORTED_COMMAND __einfo_uniqify ( EINFO_EIO, 0x0b, "Aborted command" ) |
#define EIO_RESERVED __einfo_error ( EINFO_EIO_RESERVED ) |
#define EINFO_EIO_RESERVED __einfo_uniqify ( EINFO_EIO, 0x0c, "Reserved" ) |
#define EIO_VOLUME_OVERFLOW __einfo_error ( EINFO_EIO_VOLUME_OVERFLOW ) |
#define EINFO_EIO_VOLUME_OVERFLOW __einfo_uniqify ( EINFO_EIO, 0x0d, "Volume overflow" ) |
#define EIO_MISCOMPARE __einfo_error ( EINFO_EIO_MISCOMPARE ) |
#define EINFO_EIO_MISCOMPARE __einfo_uniqify ( EINFO_EIO, 0x0e, "Miscompare" ) |
#define EIO_COMPLETED __einfo_error ( EINFO_EIO_COMPLETED ) |
#define EINFO_EIO_COMPLETED __einfo_uniqify ( EINFO_EIO, 0x0f, "Completed" ) |
#define EIO_SENSE | ( | key | ) |
enum scsi_device_flags |
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
int scsi_parse_lun | ( | const char * | lun_string, |
struct scsi_lun * | lun | ||
) |
Parse SCSI LUN.
lun_string | LUN string representation |
lun | LUN to fill in |
rc | Return status code |
Definition at line 117 of file scsi.c.
References EINVAL, htons, lun, memset(), and strtoul().
Referenced by fcp_parse_uri(), ib_srp_parse_lun(), and iscsi_parse_root_path().
void scsi_parse_sense | ( | const void * | data, |
size_t | len, | ||
struct scsi_sns_descriptor * | sense | ||
) |
Parse SCSI sense data.
data | Raw sense data |
len | Length of raw sense data |
sense | Descriptor-format sense data to fill in |
Definition at line 146 of file scsi.c.
References scsi_sns_fixed::additional, scsi_sns_descriptor::additional, scsi_sns::code, data, scsi_sns::desc, scsi_sns::fixed, len, memcpy(), memset(), and SCSI_SENSE_FIXED.
Referenced by fcpcmd_recv_rsp(), iscsi_rx_scsi_response(), and srp_rsp().
int scsi_command | ( | struct interface * | control, |
struct interface * | data, | ||
struct scsi_cmd * | command | ||
) |
Issue SCSI command.
control | SCSI control interface |
data | SCSI data interface |
command | SCSI command |
tag | Command tag, or negative error |
Definition at line 181 of file scsi.c.
References control, data, dest, EOPNOTSUPP, intf_get_dest_op, intf_object(), intf_put(), op, and scsi_command_TYPE.
Report SCSI response.
interface | SCSI command interface |
response | SCSI response |
Definition at line 206 of file scsi.c.
References dest, interface::intf, intf_get_dest_op, intf_object(), intf_put(), op, scsi_response(), and scsi_response_TYPE.
Referenced by fcpcmd_recv_rsp(), iscsi_scsi_done(), scsi_response(), and srp_rsp().
|
inlinestatic |
Get reference to SCSI device.
scsidev | SCSI device |
scsidev | SCSI device |
Definition at line 322 of file scsi.c.
References ref_get, and scsi_device::refcnt.
Referenced by scsidev_command().
|
inlinestatic |
Drop reference to SCSI device.
scsidev | SCSI device |
Definition at line 333 of file scsi.c.
References ref_put, and scsi_device::refcnt.
Referenced by scsicmd_free().
|
inlinestatic |
Get reference to SCSI command.
scsicmd | SCSI command |
scsicmd | SCSI command |
Definition at line 344 of file scsi.c.
References ref_get, and scsi_command::refcnt.
|
inlinestatic |
Drop reference to SCSI command.
scsicmd | SCSI command |
Definition at line 355 of file scsi.c.
References ref_put, and scsi_command::refcnt.
Referenced by scsicmd_close().
|
inlinestatic |
Get SCSI command private data.
scsicmd | SCSI command |
priv | Private data |
Definition at line 366 of file scsi.c.
References scsi_command::priv.
Referenced by scsicmd_read_capacity_cmd(), and scsicmd_read_capacity_done().
|
static |
Free SCSI command.
refcnt | Reference count |
Definition at line 375 of file scsi.c.
References container_of, free, scsi_command::scsidev, and scsidev_put().
Referenced by scsidev_command().
|
static |
Close SCSI command.
scsicmd | SCSI command |
rc | Reason for close |
Definition at line 392 of file scsi.c.
References scsi_command::block, DBGC, intfs_shutdown(), scsi_command::list, list_del, NULL, rc, scsi_command::scsi, scsicmd_put(), scsi_command::scsidev, strerror(), and scsi_command::tag.
Referenced by scsicmd_read_capacity_done(), scsidev_close(), and scsidev_command().
|
static |
Construct and issue SCSI command.
rc | Return status code |
Definition at line 415 of file scsi.c.
References scsi_command_type::cmd, DBGC, DBGC2, scsi_device::lun, memcpy(), memset(), scsi_command_type::name, rc, scsi_command::scsi, scsi_device::scsi, SCSI_CDB_DATA, SCSI_CDB_FORMAT, scsi_command::scsidev, strerror(), tag, scsi_command::tag, and scsi_command::type.
Referenced by scsicmd_read_capacity_done(), and scsidev_command().
|
static |
Handle SCSI command completion.
scsicmd | SCSI command |
rc | Reason for close |
Definition at line 454 of file scsi.c.
References scsi_command_type::done, intf_restart(), rc, scsi_command::scsi, and scsi_command::type.
Referenced by scsicmd_response().
|
static |
Handle SCSI response.
scsicmd | SCSI command |
response | SCSI response |
Definition at line 469 of file scsi.c.
References scsi_sns_descriptor::additional, scsi_sns_descriptor::code, DBGC, EIO_SENSE, scsi_sns_descriptor::key, ntohs, scsi_rsp::overrun, rc, SCSI_SENSE_CODE_MASK, SCSI_SENSE_KEY_MASK, scsicmd_done(), scsi_command::scsidev, scsi_rsp::sense, scsi_rsp::status, and scsi_command::tag.
|
static |
Construct SCSI READ command.
scsicmd | SCSI command |
command | SCSI command IU |
Definition at line 505 of file scsi.c.
References scsi_command::buffer, scsi_command::count, cpu_to_be16, cpu_to_be32, cpu_to_be64, scsi_command::lba, scsi_command::len, SCSI_MAX_BLOCK_10, SCSI_OPCODE_READ_10, and SCSI_OPCODE_READ_16.
|
static |
Construct SCSI WRITE command.
scsicmd | SCSI command |
command | SCSI command IU |
Definition at line 536 of file scsi.c.
References scsi_command::buffer, scsi_command::count, cpu_to_be16, cpu_to_be32, cpu_to_be64, scsi_command::lba, scsi_command::len, SCSI_MAX_BLOCK_10, SCSI_OPCODE_WRITE_10, and SCSI_OPCODE_WRITE_16.
|
static |
Construct SCSI READ CAPACITY command.
scsicmd | SCSI command |
command | SCSI command IU |
Definition at line 580 of file scsi.c.
References cpu_to_be32, scsi_cdb_read_capacity_16::len, scsi_cdb_read_capacity_10::opcode, scsi_cdb_read_capacity_16::opcode, priv, SCSI_OPCODE_READ_CAPACITY_10, SCSI_OPCODE_SERVICE_ACTION_IN, SCSI_SERVICE_ACTION_READ_CAPACITY_16, scsicmd_priv(), scsi_cdb_read_capacity_16::service_action, and virt_to_user().
|
static |
Handle SCSI READ CAPACITY command completion.
scsicmd | SCSI command |
rc | Reason for completion |
Definition at line 610 of file scsi.c.
References be32_to_cpu, be64_to_cpu, block_device_capacity::blksize, scsi_capacity_10::blksize, scsi_capacity_16::blksize, scsi_command::block, block_capacity(), block_device_capacity::blocks, scsi_capacity_10::lba, scsi_capacity_16::lba, block_device_capacity::max_count, priv, rc, scsi_device::scsi, scsicmd_close(), scsicmd_command(), scsicmd_priv(), and scsi_command::scsidev.
|
static |
Construct SCSI TEST UNIT READY command.
scsicmd | SCSI command |
command | SCSI command IU |
Definition at line 673 of file scsi.c.
References scsi_cdb_test_unit_ready::opcode, and SCSI_OPCODE_TEST_UNIT_READY.
|
static |
Create SCSI command.
scsidev | SCSI device |
block | Block data interface |
type | SCSI command type |
lba | Starting logical block address |
count | Number of blocks to transfer |
buffer | Data buffer |
len | Length of data buffer |
rc | Return status code |
Definition at line 720 of file scsi.c.
References block, scsi_command::block, buffer, scsi_command::buffer, scsi_device::cmds, count, scsi_command::count, ENOMEM, intf_init(), intf_plug_plug(), lba, scsi_command::lba, len, scsi_command::len, scsi_command::list, list_add, rc, ref_init, ref_put, scsi_command::refcnt, scsi_command::scsi, scsicmd_block_desc, scsicmd_close(), scsicmd_command(), scsicmd_free(), scsicmd_scsi_desc, scsi_command::scsidev, scsidev_get(), type, scsi_command::type, and zalloc().
Referenced by scsidev_read(), scsidev_read_capacity(), scsidev_test_unit_ready(), and scsidev_write().
|
static |
Issue SCSI block read.
scsidev | SCSI device |
block | Block data interface |
lba | Starting logical block address |
count | Number of blocks to transfer |
buffer | Data buffer |
len | Length of data buffer |
rc | Return status code |
Definition at line 773 of file scsi.c.
References block, buffer, count, lba, len, scsicmd_read, scsi_command::scsidev, and scsidev_command().
|
static |
Issue SCSI block write.
scsidev | SCSI device |
block | Block data interface |
lba | Starting logical block address |
count | Number of blocks to transfer |
buffer | Data buffer |
len | Length of data buffer |
rc | Return status code |
Definition at line 792 of file scsi.c.
References block, buffer, count, lba, len, scsicmd_write, scsi_command::scsidev, and scsidev_command().
|
static |
Read SCSI device capacity.
scsidev | SCSI device |
block | Block data interface |
rc | Return status code |
Definition at line 807 of file scsi.c.
References block, scsicmd_read_capacity, scsi_command::scsidev, scsidev_command(), and UNULL.
|
static |
Test to see if SCSI device is ready.
scsidev | SCSI device |
block | Block data interface |
rc | Return status code |
Definition at line 820 of file scsi.c.
References block, scsicmd_test_unit_ready, scsi_command::scsidev, scsidev_command(), and UNULL.
Referenced by scsidev_step().
|
static |
Check SCSI device flow-control window.
scsidev | SCSI device |
len | Length of window |
Definition at line 832 of file scsi.c.
References scsi_device::flags, scsi_device::scsi, scsi_command::scsidev, SCSIDEV_UNIT_READY, and xfer_window().
|
static |
Close SCSI device.
scsidev | SCSI device |
rc | Reason for close |
Definition at line 847 of file scsi.c.
References scsi_device::block, scsi_device::cmds, intfs_shutdown(), scsi_command::list, list_for_each_entry_safe, NULL, scsi_device::process, process_del(), rc, scsi_device::ready, scsi_device::scsi, scsicmd_close(), scsi_command::scsidev, and tmp.
Referenced by scsidev_ready(), and scsidev_step().
|
static |
Handle SCSI TEST UNIT READY response.
scsidev | SCSI device |
rc | Reason for close |
Definition at line 884 of file scsi.c.
References scsi_device::block, DBGC, scsi_device::flags, intf_restart(), scsi_device::process, process_add(), rc, scsi_device::ready, scsi_device::retries, SCSI_READY_MAX_RETRIES, scsidev_close(), SCSIDEV_UNIT_READY, SCSIDEV_UNIT_TESTED, strerror(), and xfer_window_changed().
|
static |
SCSI TEST UNIT READY process.
scsidev | SCSI device |
Definition at line 937 of file scsi.c.
References DBGC, scsi_device::flags, rc, scsi_device::ready, scsi_device::scsi, scsidev_close(), scsidev_test_unit_ready(), SCSIDEV_UNIT_TESTED, and xfer_window().
Open SCSI device.
block | Block control interface |
scsi | SCSI control interface |
lun | SCSI LUN |
rc | Return status code |
Definition at line 984 of file scsi.c.
References block, scsi_device::block, scsi_device::cmds, DBGC, ENOMEM, INIT_LIST_HEAD, intf_init(), intf_plug_plug(), lun, scsi_device::lun, memcpy(), NULL, scsi_device::process, process_init(), scsi_device::ready, ref_init, ref_put, scsi_device::refcnt, scsi_device::scsi, SCSI_LUN_DATA, SCSI_LUN_FORMAT, scsidev_block_desc, scsidev_process_desc, scsidev_ready_desc, scsidev_scsi_desc, and zalloc().
Referenced by fcpdev_open(), iscsi_open(), srp_open(), and usbblk_open_uri().
|
static |
SCSI READ command type.
Definition at line 524 of file scsi.c.
Referenced by scsidev_read().
|
static |
SCSI WRITE command type.
Definition at line 555 of file scsi.c.
Referenced by scsidev_write().
|
static |
SCSI READ CAPACITY command type.
Definition at line 660 of file scsi.c.
Referenced by scsidev_read_capacity().
|
static |
SCSI TEST UNIT READY command type.
Definition at line 681 of file scsi.c.
Referenced by scsidev_test_unit_ready().
|
static |
SCSI command block interface operations.
|
static |
SCSI command block interface descriptor.
Definition at line 693 of file scsi.c.
Referenced by scsidev_command().
|
static |
SCSI command SCSI interface operations.
|
static |
SCSI command SCSI interface descriptor.
Definition at line 704 of file scsi.c.
Referenced by scsidev_command().
|
static |
SCSI device block interface operations.
|
static |
SCSI device block interface descriptor.
Definition at line 874 of file scsi.c.
Referenced by scsi_open().
|
static |
SCSI device TEST UNIT READY interface operations.
|
static |
SCSI device TEST UNIT READY interface descriptor.
Definition at line 929 of file scsi.c.
Referenced by scsi_open().
|
static |
SCSI device SCSI interface operations.
|
static |
SCSI device SCSI interface descriptor.
Definition at line 968 of file scsi.c.
Referenced by scsi_open().
|
static |
SCSI device process descriptor.
Definition at line 973 of file scsi.c.
Referenced by scsi_open().