summaryrefslogtreecommitdiffstats
path: root/src/drivers/block
diff options
context:
space:
mode:
authorMichael Brown2006-12-12 19:54:35 +0100
committerMichael Brown2006-12-12 19:54:35 +0100
commita39b11168442a6437c293fa65e31fff636d6cd9c (patch)
treece831c4eac8353c441b98314283d6b02341fe671 /src/drivers/block
parentCatch SCSI errors, and work around the start-of-day CHECK CONDITION (diff)
downloadipxe-a39b11168442a6437c293fa65e31fff636d6cd9c.tar.gz
ipxe-a39b11168442a6437c293fa65e31fff636d6cd9c.tar.xz
ipxe-a39b11168442a6437c293fa65e31fff636d6cd9c.zip
Automatically select between the "10" and "16" variants of command set,
based on the device size.
Diffstat (limited to 'src/drivers/block')
-rw-r--r--src/drivers/block/scsi.c103
1 files changed, 72 insertions, 31 deletions
diff --git a/src/drivers/block/scsi.c b/src/drivers/block/scsi.c
index 0578403a..9651583a 100644
--- a/src/drivers/block/scsi.c
+++ b/src/drivers/block/scsi.c
@@ -70,7 +70,7 @@ static int scsi_command ( struct scsi_device *scsi,
}
/**
- * Read block from SCSI device
+ * Read block from SCSI device using READ (10)
*
* @v blockdev Block device
* @v block LBA block number
@@ -78,8 +78,33 @@ static int scsi_command ( struct scsi_device *scsi,
* @v buffer Data buffer
* @ret rc Return status code
*/
-static int scsi_read ( struct block_device *blockdev, uint64_t block,
- unsigned long count, userptr_t buffer ) {
+static int scsi_read_10 ( struct block_device *blockdev, uint64_t block,
+ unsigned long count, userptr_t buffer ) {
+ struct scsi_device *scsi = block_to_scsi ( blockdev );
+ struct scsi_command command;
+ struct scsi_cdb_read_10 *cdb = &command.cdb.read10;
+
+ /* Issue READ (10) */
+ memset ( &command, 0, sizeof ( command ) );
+ cdb->opcode = SCSI_OPCODE_READ_10;
+ cdb->lba = cpu_to_be32 ( block );
+ cdb->len = cpu_to_be16 ( count );
+ command.data_in = buffer;
+ command.data_in_len = ( count * blockdev->blksize );
+ return scsi_command ( scsi, &command );
+}
+
+/**
+ * Read block from SCSI device using READ (16)
+ *
+ * @v blockdev Block device
+ * @v block LBA block number
+ * @v count Block count
+ * @v buffer Data buffer
+ * @ret rc Return status code
+ */
+static int scsi_read_16 ( struct block_device *blockdev, uint64_t block,
+ unsigned long count, userptr_t buffer ) {
struct scsi_device *scsi = block_to_scsi ( blockdev );
struct scsi_command command;
struct scsi_cdb_read_16 *cdb = &command.cdb.read16;
@@ -95,7 +120,7 @@ static int scsi_read ( struct block_device *blockdev, uint64_t block,
}
/**
- * Write block to SCSI device
+ * Write block to SCSI device using WRITE (10)
*
* @v blockdev Block device
* @v block LBA block number
@@ -103,8 +128,33 @@ static int scsi_read ( struct block_device *blockdev, uint64_t block,
* @v buffer Data buffer
* @ret rc Return status code
*/
-static int scsi_write ( struct block_device *blockdev, uint64_t block,
- unsigned long count, userptr_t buffer ) {
+static int scsi_write_10 ( struct block_device *blockdev, uint64_t block,
+ unsigned long count, userptr_t buffer ) {
+ struct scsi_device *scsi = block_to_scsi ( blockdev );
+ struct scsi_command command;
+ struct scsi_cdb_write_10 *cdb = &command.cdb.write10;
+
+ /* Issue WRITE (10) */
+ memset ( &command, 0, sizeof ( command ) );
+ cdb->opcode = SCSI_OPCODE_WRITE_10;
+ cdb->lba = cpu_to_be32 ( block );
+ cdb->len = cpu_to_be16 ( count );
+ command.data_out = buffer;
+ command.data_out_len = ( count * blockdev->blksize );
+ return scsi_command ( scsi, &command );
+}
+
+/**
+ * Write block to SCSI device using WRITE (16)
+ *
+ * @v blockdev Block device
+ * @v block LBA block number
+ * @v count Block count
+ * @v buffer Data buffer
+ * @ret rc Return status code
+ */
+static int scsi_write_16 ( struct block_device *blockdev, uint64_t block,
+ unsigned long count, userptr_t buffer ) {
struct scsi_device *scsi = block_to_scsi ( blockdev );
struct scsi_command command;
struct scsi_cdb_write_16 *cdb = &command.cdb.write16;
@@ -179,12 +229,17 @@ static int scsi_read_capacity_16 ( struct block_device *blockdev ) {
}
/**
- * Read capacity of SCSI device
+ * Initialise SCSI device
*
- * @v blockdev Block device
+ * @v scsi SCSI device
* @ret rc Return status code
+ *
+ * Initialises a SCSI device. The scsi_device::command and
+ * scsi_device::lun fields must already be filled in. This function
+ * will configure scsi_device::blockdev, including issuing a READ
+ * CAPACITY call to determine the block size and total device size.
*/
-static int scsi_read_capacity ( struct block_device *blockdev ) {
+int init_scsidev ( struct scsi_device *scsi ) {
int rc;
/* Issue a theoretically extraneous READ CAPACITY (10)
@@ -192,10 +247,12 @@ static int scsi_read_capacity ( struct block_device *blockdev ) {
* (power-on occurred)" that some dumb targets insist on
* sending as an error at start of day.
*/
- scsi_read_capacity_10 ( blockdev );
+ scsi_read_capacity_10 ( &scsi->blockdev );
/* Try READ CAPACITY (10), which is a mandatory command, first. */
- if ( ( rc = scsi_read_capacity_10 ( blockdev ) ) != 0 )
+ scsi->blockdev.read = scsi_read_10;
+ scsi->blockdev.write = scsi_write_10;
+ if ( ( rc = scsi_read_capacity_10 ( &scsi->blockdev ) ) != 0 )
return rc;
/* If capacity range was exceeded (i.e. capacity.lba was
@@ -203,28 +260,12 @@ static int scsi_read_capacity ( struct block_device *blockdev ) {
* 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 )
+ if ( scsi->blockdev.blocks == 0 ) {
+ scsi->blockdev.read = scsi_read_16;
+ scsi->blockdev.write = scsi_write_16;
+ if ( ( rc = scsi_read_capacity_16 ( &scsi->blockdev ) ) != 0 )
return rc;
}
return 0;
}
-
-/**
- * Initialise SCSI device
- *
- * @v scsi SCSI device
- * @ret rc Return status code
- *
- * Initialises a SCSI device. The scsi_device::command and
- * scsi_device::lun fields must already be filled in. This function
- * will configure scsi_device::blockdev, including issuing a READ
- * CAPACITY call to determine the block size and total device size.
- */
-int init_scsidev ( struct scsi_device *scsi ) {
- /** Fill in read and write methods, and get device capacity */
- scsi->blockdev.read = scsi_read;
- scsi->blockdev.write = scsi_write;
- return scsi_read_capacity ( &scsi->blockdev );
-}