diff options
author | Michael Brown <mcb30@etherboot.org> | 2006-05-19 18:54:38 +0000 |
---|---|---|
committer | Michael Brown <mcb30@etherboot.org> | 2006-05-19 18:54:38 +0000 |
commit | 402ba15c6449f8dc7d5a31a04a9d7eb2eef330a3 (patch) | |
tree | 8c0f8e9ba74254f3a798539a3214bd23ecd6b897 /src/drivers/block | |
parent | 444b885a7dfaaf4132c440b75018b59990cbfcd5 (diff) | |
download | ipxe-402ba15c6449f8dc7d5a31a04a9d7eb2eef330a3.tar.gz |
READ CAPACITY (16) turns out to be an optional command (even though
READ(16) is mandatory); we must use READ CAPACITY (10) first and then
use READ CAPACITY (16) if the READ CAPACITY (10) returns "out of range".
Diffstat (limited to 'src/drivers/block')
-rw-r--r-- | src/drivers/block/scsi.c | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/src/drivers/block/scsi.c b/src/drivers/block/scsi.c index 1a1d70d8..1e906e13 100644 --- a/src/drivers/block/scsi.c +++ b/src/drivers/block/scsi.c @@ -96,12 +96,41 @@ static int scsi_write ( struct block_device *blockdev, uint64_t block, } /** - * Read capacity of SCSI device + * Read capacity of SCSI device via READ CAPACITY (10) * * @v blockdev Block device * @ret rc Return status code */ -static int scsi_read_capacity ( struct block_device *blockdev ) { +static int scsi_read_capacity_10 ( struct block_device *blockdev ) { + struct scsi_device *scsi = block_to_scsi ( blockdev ); + struct scsi_command command; + struct scsi_cdb_read_capacity_10 *cdb = &command.cdb.readcap10; + struct scsi_capacity_10 capacity; + int rc; + + /* Issue READ CAPACITY (10) */ + memset ( &command, 0, sizeof ( command ) ); + cdb->opcode = SCSI_OPCODE_READ_CAPACITY_10; + command.data_in = virt_to_user ( &capacity ); + command.data_in_len = sizeof ( capacity ); + + if ( ( rc = scsi_command ( scsi, &command ) ) != 0 ) + return rc; + + /* Fill in block device fields */ + blockdev->blksize = be32_to_cpu ( capacity.blksize ); + blockdev->blocks = ( be32_to_cpu ( capacity.lba ) + 1 ); + + return 0; +} + +/** + * Read capacity of SCSI device via READ CAPACITY (16) + * + * @v blockdev Block device + * @ret rc Return status code + */ +static int scsi_read_capacity_16 ( struct block_device *blockdev ) { struct scsi_device *scsi = block_to_scsi ( blockdev ); struct scsi_command command; struct scsi_cdb_read_capacity_16 *cdb = &command.cdb.readcap16; @@ -126,6 +155,32 @@ static int scsi_read_capacity ( struct block_device *blockdev ) { } /** + * Read capacity of SCSI device + * + * @v blockdev Block device + * @ret rc Return status code + */ +static int scsi_read_capacity ( struct block_device *blockdev ) { + int rc; + + /* Try READ CAPACITY (10), which is a mandatory command, first. */ + if ( ( rc = scsi_read_capacity_10 ( blockdev ) ) != 0 ) + return rc; + + /* If capacity range was exceeded (i.e. capacity.lba was + * 0xffffffff, meaning that blockdev->blocks is now zero), use + * READ CAPACITY (16) instead. READ CAPACITY (16) is not + * mandatory, so we can't just use it straight off. + */ + if ( blockdev->blocks == 0 ) { + if ( ( rc = scsi_read_capacity_16 ( blockdev ) ) != 0 ) + return rc; + } + + return 0; +} + +/** * Initialise SCSI device * * @v scsi SCSI device |