This series implements some code reorganization in an attempt to simplify the disk driver command dispatch system. The series should have no user-visible changes - it's mostly just code reorg.
At the end of the series, the command dispatch for "scsi style" devices is removed in favor of a single dispatch system for all drives.
The series also makes the supported runtime modes (ie, 32bit or 16bit) of drivers more explicit.
This series is also available at: https://github.com/KevinOConnor/seabios/tree/testing
-Kevin
Kevin O'Connor (17): block: Split process_op() command dispatch up into multiple functions block: Introduce default_process_op() with common command handling codes block: Route scsi style commands through 'struct disk_op_s' blockcmd: Introduce scsi_fill_cmd() ata: Handle ATA ATAPI drives directly via 'struct disk_op_s' requests ahci: Handle AHCI ATAPI drives directly via 'struct disk_op_s' requests usb-msc: Handle USB drives directly via 'struct disk_op_s' requests usb-uas: Handle USB drives directly via 'struct disk_op_s' requests lsi-scsi: Handle LSI drives directly via 'struct disk_op_s' requests esp-scsi: Handle ESP drives directly via 'struct disk_op_s' requests megasas: Handle Megasas drives directly via 'struct disk_op_s' requests virtio-scsi: Handle virtio drives directly via 'struct disk_op_s' requests pvscsi: Move pvscsi_fill_req() code into pvscsi_cmd() pvscsi: Handle pvscsi drives directly via 'struct disk_op_s' requests blockcmd: Remove unused scsi_process_op() and cdb_cmd_data() blockcmd: Convert cdb_is_read() to scsi_is_read() block: Rename process_XXX_op() functions to XXX_process_op()
src/block.c | 152 +++++++++++++++++++++++++++++++-------------------- src/block.h | 14 ++++- src/cdrom.c | 15 ++--- src/hw/ahci.c | 29 ++++------ src/hw/ahci.h | 4 +- src/hw/ata.c | 17 +++--- src/hw/ata.h | 5 +- src/hw/blockcmd.c | 138 +++++++++++++++------------------------------- src/hw/blockcmd.h | 4 +- src/hw/esp-scsi.c | 33 +++++------ src/hw/esp-scsi.h | 2 +- src/hw/floppy.c | 2 +- src/hw/lsi-scsi.c | 32 +++++------ src/hw/lsi-scsi.h | 2 +- src/hw/megasas.c | 12 ++-- src/hw/megasas.h | 2 +- src/hw/pvscsi.c | 62 ++++++++------------- src/hw/pvscsi.h | 2 +- src/hw/ramdisk.c | 8 +-- src/hw/sdcard.c | 12 +--- src/hw/usb-msc.c | 14 +++-- src/hw/usb-msc.h | 2 +- src/hw/usb-uas.c | 6 +- src/hw/usb-uas.h | 2 +- src/hw/virtio-blk.c | 12 +--- src/hw/virtio-blk.h | 2 +- src/hw/virtio-scsi.c | 37 +++++-------- src/hw/virtio-scsi.h | 2 +- src/util.h | 8 +-- 29 files changed, 283 insertions(+), 349 deletions(-)
Introduce process_op_32(), process_op_16(), and process_op_both() and split the disk driver command dispatch by its runtime mode requirements. This makes it more clear which modes each driver runs in. It also reduces the call32() boiler-plate code.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 125 +++++++++++++++++++++++++++++----------------------- src/hw/ahci.c | 2 +- src/hw/blockcmd.c | 2 +- src/hw/sdcard.c | 2 +- src/hw/virtio-blk.c | 2 +- 5 files changed, 73 insertions(+), 60 deletions(-)
diff --git a/src/block.c b/src/block.c index a9b9851..e534319 100644 --- a/src/block.c +++ b/src/block.c @@ -464,10 +464,10 @@ fill_edd(u16 seg, struct int13dpt_s *param_far, struct drive_s *drive_gf)
/**************************************************************** - * 16bit calling interface + * Disk driver dispatch ****************************************************************/
-int VISIBLE32FLAT +static int process_atapi_op(struct disk_op_s *op) { switch (op->command) { @@ -479,72 +479,85 @@ process_atapi_op(struct disk_op_s *op) } }
-// Execute a disk_op request. -int -process_op(struct disk_op_s *op) +// Command dispatch for disk drivers that run in both 16bit and 32bit mode +static int +process_op_both(struct disk_op_s *op) { - ASSERT16(); - int ret, origcount = op->count; - if (origcount * GET_GLOBALFLAT(op->drive_gf->blksize) > 64*1024) { - op->count = 0; - return DISK_RET_EBOUNDARY; - } - u8 type = GET_GLOBALFLAT(op->drive_gf->type); - switch (type) { - case DTYPE_FLOPPY: - ret = process_floppy_op(op); - break; - case DTYPE_ATA: - ret = process_ata_op(op); - break; - case DTYPE_RAMDISK: - ret = process_ramdisk_op(op); - break; - case DTYPE_CDEMU: - ret = process_cdemu_op(op); - break; - case DTYPE_VIRTIO_BLK: ; - extern void _cfunc32flat_process_virtio_blk_op(void); - ret = call32(_cfunc32flat_process_virtio_blk_op - , (u32)MAKE_FLATPTR(GET_SEG(SS), op), DISK_RET_EPARAM); - break; - case DTYPE_AHCI: ; - extern void _cfunc32flat_process_ahci_op(void); - ret = call32(_cfunc32flat_process_ahci_op - , (u32)MAKE_FLATPTR(GET_SEG(SS), op), DISK_RET_EPARAM); - break; + switch (GET_GLOBALFLAT(op->drive_gf->type)) { case DTYPE_ATA_ATAPI: - ret = process_atapi_op(op); - break; - case DTYPE_AHCI_ATAPI: ; - extern void _cfunc32flat_process_atapi_op(void); - ret = call32(_cfunc32flat_process_atapi_op - , (u32)MAKE_FLATPTR(GET_SEG(SS), op), DISK_RET_EPARAM); - break; - case DTYPE_SDCARD: ; - extern void _cfunc32flat_process_sdcard_op(void); - ret = call32(_cfunc32flat_process_sdcard_op - , (u32)MAKE_FLATPTR(GET_SEG(SS), op), DISK_RET_EPARAM); - break; + return process_atapi_op(op); case DTYPE_USB: case DTYPE_UAS: case DTYPE_LSI_SCSI: case DTYPE_ESP_SCSI: case DTYPE_MEGASAS: - ret = scsi_process_op(op); - break; + return scsi_process_op(op); + default: + if (!MODESEGMENT) + return DISK_RET_EPARAM; + // In 16bit mode and driver not found - try in 32bit mode + extern void _cfunc32flat_process_op_32(void); + return call32(_cfunc32flat_process_op_32 + , (u32)MAKE_FLATPTR(GET_SEG(SS), op), DISK_RET_EPARAM); + } +} + +// Command dispatch for disk drivers that only run in 32bit mode +int VISIBLE32FLAT +process_op_32(struct disk_op_s *op) +{ + ASSERT32FLAT(); + switch (op->drive_gf->type) { + case DTYPE_VIRTIO_BLK: + return process_virtio_blk_op(op); + case DTYPE_AHCI: + return process_ahci_op(op); + case DTYPE_AHCI_ATAPI: + return process_atapi_op(op); + case DTYPE_SDCARD: + return process_sdcard_op(op); case DTYPE_USB_32: case DTYPE_UAS_32: case DTYPE_VIRTIO_SCSI: - case DTYPE_PVSCSI: ; - extern void _cfunc32flat_scsi_process_op(void); - ret = call32(_cfunc32flat_scsi_process_op - , (u32)MAKE_FLATPTR(GET_SEG(SS), op), DISK_RET_EPARAM); - break; + case DTYPE_PVSCSI: + return scsi_process_op(op); default: - ret = DISK_RET_EPARAM; - break; + return process_op_both(op); } +} + +// Command dispatch for disk drivers that only run in 16bit mode +static int +process_op_16(struct disk_op_s *op) +{ + ASSERT16(); + switch (GET_GLOBALFLAT(op->drive_gf->type)) { + case DTYPE_FLOPPY: + return process_floppy_op(op); + case DTYPE_ATA: + return process_ata_op(op); + case DTYPE_RAMDISK: + return process_ramdisk_op(op); + case DTYPE_CDEMU: + return process_cdemu_op(op); + default: + return process_op_both(op); + } +} + +// Execute a disk_op_s request. +int +process_op(struct disk_op_s *op) +{ + int ret, origcount = op->count; + if (origcount * GET_GLOBALFLAT(op->drive_gf->blksize) > 64*1024) { + op->count = 0; + return DISK_RET_EBOUNDARY; + } + if (MODESEGMENT) + ret = process_op_16(op); + else + ret = process_op_32(op); if (ret && op->count == origcount) // If the count hasn't changed on error, assume no data transferred. op->count = 0; diff --git a/src/hw/ahci.c b/src/hw/ahci.c index 0d71cc4..82fce42 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -296,7 +296,7 @@ ahci_disk_readwrite(struct disk_op_s *op, int iswrite) }
// command demuxer -int VISIBLE32FLAT +int process_ahci_op(struct disk_op_s *op) { if (!CONFIG_AHCI) diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 4440201..3128f0a 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -166,7 +166,7 @@ cdb_write(struct disk_op_s *op) * Main SCSI commands ****************************************************************/
-int VISIBLE32FLAT +int scsi_process_op(struct disk_op_s *op) { switch (op->command) { diff --git a/src/hw/sdcard.c b/src/hw/sdcard.c index 6ff93c8..626f042 100644 --- a/src/hw/sdcard.c +++ b/src/hw/sdcard.c @@ -208,7 +208,7 @@ sdcard_readwrite(struct disk_op_s *op, int iswrite) return DISK_RET_SUCCESS; }
-int VISIBLE32FLAT +int process_sdcard_op(struct disk_op_s *op) { if (!CONFIG_SDCARD) diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 29bc4a5..0a02a03 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -77,7 +77,7 @@ virtio_blk_op(struct disk_op_s *op, int write) return status == VIRTIO_BLK_S_OK ? DISK_RET_SUCCESS : DISK_RET_EBADTRACK; }
-int VISIBLE32FLAT +int process_virtio_blk_op(struct disk_op_s *op) { if (! CONFIG_VIRTIO_BLK)
Most disk drivers only implement a couple of the available bios commands. Unify the common fallback handling code into a new function default_process_op() to reduce boiler-plate code.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 17 +++++++++++++++++ src/block.h | 1 + src/cdrom.c | 7 +------ src/hw/ahci.c | 9 +-------- src/hw/ata.c | 6 +----- src/hw/blockcmd.c | 8 +------- src/hw/ramdisk.c | 6 +----- src/hw/sdcard.c | 8 +------- src/hw/virtio-blk.c | 8 +------- 9 files changed, 25 insertions(+), 45 deletions(-)
diff --git a/src/block.c b/src/block.c index e534319..1d628f9 100644 --- a/src/block.c +++ b/src/block.c @@ -467,6 +467,23 @@ fill_edd(u16 seg, struct int13dpt_s *param_far, struct drive_s *drive_gf) * Disk driver dispatch ****************************************************************/
+// Fallback handler for command requests not implemented by drivers +int +default_process_op(struct disk_op_s *op) +{ + switch (op->command) { + case CMD_FORMAT: + case CMD_RESET: + case CMD_ISREADY: + case CMD_VERIFY: + case CMD_SEEK: + // Return success if the driver doesn't implement these commands + return DISK_RET_SUCCESS; + default: + return DISK_RET_EPARAM; + } +} + static int process_atapi_op(struct disk_op_s *op) { diff --git a/src/block.h b/src/block.h index 8182288..2fa52bd 100644 --- a/src/block.h +++ b/src/block.h @@ -102,6 +102,7 @@ void map_hd_drive(struct drive_s *drive); void map_cd_drive(struct drive_s *drive); struct int13dpt_s; int fill_edd(u16 seg, struct int13dpt_s *param_far, struct drive_s *drive_gf); +int default_process_op(struct disk_op_s *op); int process_op(struct disk_op_s *op); int send_disk_op(struct disk_op_s *op); int create_bounce_buf(void); diff --git a/src/cdrom.c b/src/cdrom.c index ba02340..bf1d2a6 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -100,13 +100,8 @@ process_cdemu_op(struct disk_op_s *op) case CMD_WRITE: case CMD_FORMAT: return DISK_RET_EWRITEPROTECT; - case CMD_VERIFY: - case CMD_RESET: - case CMD_SEEK: - case CMD_ISREADY: - return DISK_RET_SUCCESS; default: - return DISK_RET_EPARAM; + return default_process_op(op); } }
diff --git a/src/hw/ahci.c b/src/hw/ahci.c index 82fce42..ad813ce 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -306,15 +306,8 @@ process_ahci_op(struct disk_op_s *op) return ahci_disk_readwrite(op, 0); case CMD_WRITE: return ahci_disk_readwrite(op, 1); - case CMD_FORMAT: - case CMD_RESET: - case CMD_ISREADY: - case CMD_VERIFY: - case CMD_SEEK: - return DISK_RET_SUCCESS; default: - dprintf(1, "AHCI: unknown disk command %d\n", op->command); - return DISK_RET_EPARAM; + return default_process_op(op); } }
diff --git a/src/hw/ata.c b/src/hw/ata.c index d805706..d674f61 100644 --- a/src/hw/ata.c +++ b/src/hw/ata.c @@ -569,12 +569,8 @@ process_ata_op(struct disk_op_s *op) return DISK_RET_SUCCESS; case CMD_ISREADY: return isready(adrive_gf); - case CMD_FORMAT: - case CMD_VERIFY: - case CMD_SEEK: - return DISK_RET_SUCCESS; default: - return DISK_RET_EPARAM; + return default_process_op(op); } }
diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 3128f0a..ecfeb5d 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -174,14 +174,8 @@ scsi_process_op(struct disk_op_s *op) return cdb_read(op); case CMD_WRITE: return cdb_write(op); - case CMD_FORMAT: - case CMD_RESET: - case CMD_ISREADY: - case CMD_VERIFY: - case CMD_SEEK: - return DISK_RET_SUCCESS; default: - return DISK_RET_EPARAM; + return default_process_op(op); } }
diff --git a/src/hw/ramdisk.c b/src/hw/ramdisk.c index 6b44c83..67ba59c 100644 --- a/src/hw/ramdisk.c +++ b/src/hw/ramdisk.c @@ -101,11 +101,7 @@ process_ramdisk_op(struct disk_op_s *op) return ramdisk_copy(op, 0); case CMD_WRITE: return ramdisk_copy(op, 1); - case CMD_VERIFY: - case CMD_FORMAT: - case CMD_RESET: - return DISK_RET_SUCCESS; default: - return DISK_RET_EPARAM; + return default_process_op(op); } } diff --git a/src/hw/sdcard.c b/src/hw/sdcard.c index 626f042..965543c 100644 --- a/src/hw/sdcard.c +++ b/src/hw/sdcard.c @@ -218,14 +218,8 @@ process_sdcard_op(struct disk_op_s *op) return sdcard_readwrite(op, 0); case CMD_WRITE: return sdcard_readwrite(op, 1); - case CMD_FORMAT: - case CMD_RESET: - case CMD_ISREADY: - case CMD_VERIFY: - case CMD_SEEK: - return DISK_RET_SUCCESS; default: - return DISK_RET_EPARAM; + return default_process_op(op); } }
diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 0a02a03..92a5546 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -87,14 +87,8 @@ process_virtio_blk_op(struct disk_op_s *op) return virtio_blk_op(op, 0); case CMD_WRITE: return virtio_blk_op(op, 1); - case CMD_FORMAT: - case CMD_RESET: - case CMD_ISREADY: - case CMD_VERIFY: - case CMD_SEEK: - return DISK_RET_SUCCESS; default: - return DISK_RET_EPARAM; + return default_process_op(op); } }
Support sending scsi style "command data block" commands (cdbcmd) through the 'struct disk_op_s' command request structure. And change the blockcmd.c and cdrom.c code to route these commands through the process_op() code.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.h | 13 +++++++++++-- src/cdrom.c | 6 +++--- src/hw/blockcmd.c | 27 ++++++++++++++++++++++----- 3 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/src/block.h b/src/block.h index 2fa52bd..702f357 100644 --- a/src/block.h +++ b/src/block.h @@ -9,11 +9,19 @@ ****************************************************************/
struct disk_op_s { - u64 lba; void *buf_fl; struct drive_s *drive_gf; - u16 count; u8 command; + u16 count; + union { + // Commands: READ, WRITE, VERIFY, SEEK, FORMAT + u64 lba; + // Commands: SCSI + struct { + u16 blocksize; + void *cdbcmd; + }; + }; };
#define CMD_RESET 0x00 @@ -23,6 +31,7 @@ struct disk_op_s { #define CMD_FORMAT 0x05 #define CMD_SEEK 0x07 #define CMD_ISREADY 0x10 +#define CMD_SCSI 0x20
/**************************************************************** diff --git a/src/cdrom.c b/src/cdrom.c index bf1d2a6..60964bd 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -153,7 +153,7 @@ cdrom_boot(struct drive_s *drive) dop.lba = 0x11; dop.count = 1; dop.buf_fl = buffer; - ret = scsi_process_op(&dop); + ret = process_op(&dop); if (ret) return 3;
@@ -169,7 +169,7 @@ cdrom_boot(struct drive_s *drive) // And we read the Boot Catalog dop.lba = lba; dop.count = 1; - ret = scsi_process_op(&dop); + ret = process_op(&dop); if (ret) return 7;
@@ -218,7 +218,7 @@ cdrom_boot(struct drive_s *drive) if (count > 64*1024/CDROM_SECTOR_SIZE) count = 64*1024/CDROM_SECTOR_SIZE; dop.count = count; - ret = scsi_process_op(&dop); + ret = process_op(&dop); if (ret) return 12; nbsectors -= count; diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index ecfeb5d..99ebabc 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -80,9 +80,12 @@ cdb_get_inquiry(struct disk_op_s *op, struct cdbres_inquiry *data) memset(&cmd, 0, sizeof(cmd)); cmd.command = CDB_CMD_INQUIRY; cmd.length = sizeof(*data); + op->command = CMD_SCSI; op->count = 1; op->buf_fl = data; - return cdb_cmd_data(op, &cmd, sizeof(*data)); + op->cdbcmd = &cmd; + op->blocksize = sizeof(*data); + return process_op(op); }
// Request SENSE @@ -93,9 +96,12 @@ cdb_get_sense(struct disk_op_s *op, struct cdbres_request_sense *data) memset(&cmd, 0, sizeof(cmd)); cmd.command = CDB_CMD_REQUEST_SENSE; cmd.length = sizeof(*data); + op->command = CMD_SCSI; op->count = 1; op->buf_fl = data; - return cdb_cmd_data(op, &cmd, sizeof(*data)); + op->cdbcmd = &cmd; + op->blocksize = sizeof(*data); + return process_op(op); }
// Test unit ready @@ -105,9 +111,12 @@ cdb_test_unit_ready(struct disk_op_s *op) struct cdb_request_sense cmd; memset(&cmd, 0, sizeof(cmd)); cmd.command = CDB_CMD_TEST_UNIT_READY; + op->command = CMD_SCSI; op->count = 0; op->buf_fl = NULL; - return cdb_cmd_data(op, &cmd, 0); + op->cdbcmd = &cmd; + op->blocksize = 0; + return process_op(op); }
// Request capacity @@ -117,9 +126,12 @@ cdb_read_capacity(struct disk_op_s *op, struct cdbres_read_capacity *data) struct cdb_read_capacity cmd; memset(&cmd, 0, sizeof(cmd)); cmd.command = CDB_CMD_READ_CAPACITY; + op->command = CMD_SCSI; op->count = 1; op->buf_fl = data; - return cdb_cmd_data(op, &cmd, sizeof(*data)); + op->cdbcmd = &cmd; + op->blocksize = sizeof(*data); + return process_op(op); }
// Mode sense, geometry page. @@ -132,9 +144,12 @@ cdb_mode_sense_geom(struct disk_op_s *op, struct cdbres_mode_sense_geom *data) cmd.flags = 8; /* DBD */ cmd.page = MODE_PAGE_HD_GEOMETRY; cmd.count = cpu_to_be16(sizeof(*data)); + op->command = CMD_SCSI; op->count = 1; op->buf_fl = data; - return cdb_cmd_data(op, &cmd, sizeof(*data)); + op->cdbcmd = &cmd; + op->blocksize = sizeof(*data); + return process_op(op); }
// Read sectors. @@ -174,6 +189,8 @@ scsi_process_op(struct disk_op_s *op) return cdb_read(op); case CMD_WRITE: return cdb_write(op); + case CMD_SCSI: + return cdb_cmd_data(op, op->cdbcmd, op->blocksize); default: return default_process_op(op); }
Introduce scsi_fill_cmd() which creates a scsi style "command data block" from a "struct disk_op_s" disk request.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/blockcmd.c | 53 +++++++++++++++++++++++------------------------------ src/hw/blockcmd.h | 1 + 2 files changed, 24 insertions(+), 30 deletions(-)
diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 99ebabc..004c58f 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -152,51 +152,44 @@ cdb_mode_sense_geom(struct disk_op_s *op, struct cdbres_mode_sense_geom *data) return process_op(op); }
-// Read sectors. -static int -cdb_read(struct disk_op_s *op) -{ - struct cdb_rwdata_10 cmd; - memset(&cmd, 0, sizeof(cmd)); - cmd.command = CDB_CMD_READ_10; - cmd.lba = cpu_to_be32(op->lba); - cmd.count = cpu_to_be16(op->count); - return cdb_cmd_data(op, &cmd, GET_GLOBALFLAT(op->drive_gf->blksize)); -} - -// Write sectors. -static int -cdb_write(struct disk_op_s *op) -{ - struct cdb_rwdata_10 cmd; - memset(&cmd, 0, sizeof(cmd)); - cmd.command = CDB_CMD_WRITE_10; - cmd.lba = cpu_to_be32(op->lba); - cmd.count = cpu_to_be16(op->count); - return cdb_cmd_data(op, &cmd, GET_GLOBALFLAT(op->drive_gf->blksize)); -} -
/**************************************************************** * Main SCSI commands ****************************************************************/
+// Create a scsi command request from a disk_op_s request int -scsi_process_op(struct disk_op_s *op) +scsi_fill_cmd(struct disk_op_s *op, void *cdbcmd, int maxcdb) { switch (op->command) { case CMD_READ: - return cdb_read(op); - case CMD_WRITE: - return cdb_write(op); + case CMD_WRITE: ; + struct cdb_rwdata_10 *cmd = cdbcmd; + memset(cmd, 0, maxcdb); + cmd->command = (op->command == CMD_READ ? CDB_CMD_READ_10 + : CDB_CMD_WRITE_10); + cmd->lba = cpu_to_be32(op->lba); + cmd->count = cpu_to_be16(op->count); + return GET_GLOBALFLAT(op->drive_gf->blksize); case CMD_SCSI: - return cdb_cmd_data(op, op->cdbcmd, op->blocksize); + memcpy(cdbcmd, op->cdbcmd, maxcdb); + return op->blocksize; default: - return default_process_op(op); + return -1; } }
int +scsi_process_op(struct disk_op_s *op) +{ + char cdbcmd[16]; + int blocksize = scsi_fill_cmd(op, cdbcmd, sizeof(cdbcmd)); + if (blocksize < 0) + return default_process_op(op); + return cdb_cmd_data(op, cdbcmd, blocksize); +} + +int scsi_is_ready(struct disk_op_s *op) { dprintf(6, "scsi_is_ready (drive=%p)\n", op->drive_gf); diff --git a/src/hw/blockcmd.h b/src/hw/blockcmd.h index df12a6d..9077e82 100644 --- a/src/hw/blockcmd.h +++ b/src/hw/blockcmd.h @@ -102,6 +102,7 @@ struct cdbres_mode_sense_geom { // blockcmd.c int cdb_is_read(u8 *cdbcmd, u16 blocksize); struct disk_op_s; +int scsi_fill_cmd(struct disk_op_s *op, void *cdbcmd, int maxcdb); int scsi_process_op(struct disk_op_s *op); int scsi_is_ready(struct disk_op_s *op); struct drive_s;
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 2 +- src/hw/ata.c | 9 ++++++++- src/hw/ata.h | 2 +- src/hw/blockcmd.c | 3 --- 4 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/block.c b/src/block.c index 1d628f9..8bd9398 100644 --- a/src/block.c +++ b/src/block.c @@ -502,7 +502,7 @@ process_op_both(struct disk_op_s *op) { switch (GET_GLOBALFLAT(op->drive_gf->type)) { case DTYPE_ATA_ATAPI: - return process_atapi_op(op); + return ata_atapi_process_op(op); case DTYPE_USB: case DTYPE_UAS: case DTYPE_LSI_SCSI: diff --git a/src/hw/ata.c b/src/hw/ata.c index d674f61..b5bd75f 100644 --- a/src/hw/ata.c +++ b/src/hw/ata.c @@ -583,11 +583,18 @@ process_ata_op(struct disk_op_s *op)
// Low-level atapi command transmit function. int -atapi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) +ata_atapi_process_op(struct disk_op_s *op) { if (! CONFIG_ATA) return 0;
+ if (op->command == CMD_WRITE || op->command == CMD_FORMAT) + return DISK_RET_EWRITEPROTECT; + u8 cdbcmd[CDROM_CDB_SIZE]; + int blocksize = scsi_fill_cmd(op, cdbcmd, sizeof(cdbcmd)); + if (blocksize < 0) + return default_process_op(op); + struct atadrive_s *adrive_gf = container_of( op->drive_gf, struct atadrive_s, drive); struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf); diff --git a/src/hw/ata.h b/src/hw/ata.h index c73892b..3a7ab65 100644 --- a/src/hw/ata.h +++ b/src/hw/ata.h @@ -25,7 +25,7 @@ struct atadrive_s { char *ata_extract_model(char *model, u32 size, u16 *buffer); int ata_extract_version(u16 *buffer); int cdrom_read(struct disk_op_s *op); -int atapi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize); +int ata_atapi_process_op(struct disk_op_s *op); void ata_setup(void); int process_ata_op(struct disk_op_s *op);
diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 004c58f..d227d17 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -6,7 +6,6 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "ahci.h" // atapi_cmd_data -#include "ata.h" // atapi_cmd_data #include "biosvar.h" // GET_GLOBALFLAT #include "block.h" // struct disk_op_s #include "blockcmd.h" // struct cdb_request_sense @@ -29,8 +28,6 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) { u8 type = GET_GLOBALFLAT(op->drive_gf->type); switch (type) { - case DTYPE_ATA_ATAPI: - return atapi_cmd_data(op, cdbcmd, blocksize); case DTYPE_USB: return usb_cmd_data(op, cdbcmd, blocksize); case DTYPE_UAS:
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 14 +------------- src/hw/ahci.c | 16 ++++++++-------- src/hw/ahci.h | 2 +- src/hw/blockcmd.c | 4 ---- 4 files changed, 10 insertions(+), 26 deletions(-)
diff --git a/src/block.c b/src/block.c index 8bd9398..5f238c7 100644 --- a/src/block.c +++ b/src/block.c @@ -484,18 +484,6 @@ default_process_op(struct disk_op_s *op) } }
-static int -process_atapi_op(struct disk_op_s *op) -{ - switch (op->command) { - case CMD_WRITE: - case CMD_FORMAT: - return DISK_RET_EWRITEPROTECT; - default: - return scsi_process_op(op); - } -} - // Command dispatch for disk drivers that run in both 16bit and 32bit mode static int process_op_both(struct disk_op_s *op) @@ -530,7 +518,7 @@ process_op_32(struct disk_op_s *op) case DTYPE_AHCI: return process_ahci_op(op); case DTYPE_AHCI_ATAPI: - return process_atapi_op(op); + return ahci_atapi_process_op(op); case DTYPE_SDCARD: return process_sdcard_op(op); case DTYPE_USB_32: diff --git a/src/hw/ahci.c b/src/hw/ahci.c index ad813ce..72ba230 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -213,7 +213,7 @@ static int ahci_command(struct ahci_port_s *port_gf, int iswrite, int isatapi,
#define CDROM_CDB_SIZE 12
-int ahci_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) +int ahci_atapi_process_op(struct disk_op_s *op) { if (! CONFIG_AHCI) return 0; @@ -221,15 +221,15 @@ int ahci_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) struct ahci_port_s *port_gf = container_of( op->drive_gf, struct ahci_port_s, drive); struct ahci_cmd_s *cmd = port_gf->cmd; - u8 *atapi = cdbcmd; - int i, rc;
+ if (op->command == CMD_WRITE || op->command == CMD_FORMAT) + return DISK_RET_EWRITEPROTECT; + int blocksize = scsi_fill_cmd(op, cmd->atapi, CDROM_CDB_SIZE); + if (blocksize < 0) + return default_process_op(op); sata_prep_atapi(&cmd->fis, blocksize); - for (i = 0; i < CDROM_CDB_SIZE; i++) { - cmd->atapi[i] = atapi[i]; - } - rc = ahci_command(port_gf, 0, 1, op->buf_fl, - op->count * blocksize); + int rc = ahci_command(port_gf, 0, 1, op->buf_fl, + op->count * blocksize); if (rc < 0) return DISK_RET_EBADTRACK; return DISK_RET_SUCCESS; diff --git a/src/hw/ahci.h b/src/hw/ahci.h index c8c755a..16ad6a9 100644 --- a/src/hw/ahci.h +++ b/src/hw/ahci.h @@ -84,7 +84,7 @@ struct ahci_port_s {
void ahci_setup(void); int process_ahci_op(struct disk_op_s *op); -int ahci_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize); +int ahci_atapi_process_op(struct disk_op_s *op);
#define AHCI_IRQ_ON_SG (1 << 31) #define AHCI_CMD_ATAPI (1 << 5) diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index d227d17..20bd59e 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -5,7 +5,6 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "ahci.h" // atapi_cmd_data #include "biosvar.h" // GET_GLOBALFLAT #include "block.h" // struct disk_op_s #include "blockcmd.h" // struct cdb_request_sense @@ -50,9 +49,6 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) case DTYPE_PVSCSI: if (!MODESEGMENT) return pvscsi_cmd_data(op, cdbcmd, blocksize); - case DTYPE_AHCI_ATAPI: - if (!MODESEGMENT) - return ahci_cmd_data(op, cdbcmd, blocksize); default: return DISK_RET_EPARAM; }
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 3 +++ src/hw/blockcmd.c | 6 ------ src/hw/usb-msc.c | 14 ++++++++------ src/hw/usb-msc.h | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/src/block.c b/src/block.c index 5f238c7..3aa7595 100644 --- a/src/block.c +++ b/src/block.c @@ -12,6 +12,7 @@ #include "hw/blockcmd.h" // cdb_* #include "hw/pci.h" // pci_bdf_to_bus #include "hw/rtc.h" // rtc_read +#include "hw/usb-msc.h" // usb_process_op #include "hw/virtio-blk.h" // process_virtio_blk_op #include "malloc.h" // malloc_low #include "output.h" // dprintf @@ -492,6 +493,7 @@ process_op_both(struct disk_op_s *op) case DTYPE_ATA_ATAPI: return ata_atapi_process_op(op); case DTYPE_USB: + return usb_process_op(op); case DTYPE_UAS: case DTYPE_LSI_SCSI: case DTYPE_ESP_SCSI: @@ -522,6 +524,7 @@ process_op_32(struct disk_op_s *op) case DTYPE_SDCARD: return process_sdcard_op(op); case DTYPE_USB_32: + return usb_process_op(op); case DTYPE_UAS_32: case DTYPE_VIRTIO_SCSI: case DTYPE_PVSCSI: diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 20bd59e..9b91098 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -16,7 +16,6 @@ #include "output.h" // dprintf #include "std/disk.h" // DISK_RET_EPARAM #include "string.h" // memset -#include "usb-msc.h" // usb_cmd_data #include "usb-uas.h" // usb_cmd_data #include "util.h" // timer_calc #include "virtio-scsi.h" // virtio_scsi_cmd_data @@ -27,8 +26,6 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) { u8 type = GET_GLOBALFLAT(op->drive_gf->type); switch (type) { - case DTYPE_USB: - return usb_cmd_data(op, cdbcmd, blocksize); case DTYPE_UAS: return uas_cmd_data(op, cdbcmd, blocksize); case DTYPE_LSI_SCSI: @@ -40,9 +37,6 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) case DTYPE_VIRTIO_SCSI: if (!MODESEGMENT) return virtio_scsi_cmd_data(op, cdbcmd, blocksize); - case DTYPE_USB_32: - if (!MODESEGMENT) - return usb_cmd_data(op, cdbcmd, blocksize); case DTYPE_UAS_32: if (!MODESEGMENT) return uas_cmd_data(op, cdbcmd, blocksize); diff --git a/src/hw/usb-msc.c b/src/hw/usb-msc.c index d90319f..3376f2c 100644 --- a/src/hw/usb-msc.c +++ b/src/hw/usb-msc.c @@ -63,25 +63,27 @@ usb_msc_send(struct usbdrive_s *udrive_gf, int dir, void *buf, u32 bytes)
// Low-level usb command transmit function. int -usb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) +usb_process_op(struct disk_op_s *op) { if (!CONFIG_USB_MSC) return 0;
- dprintf(16, "usb_cmd_data id=%p write=%d count=%d bs=%d buf=%p\n" - , op->drive_gf, 0, op->count, blocksize, op->buf_fl); + dprintf(16, "usb_cmd_data id=%p write=%d count=%d buf=%p\n" + , op->drive_gf, 0, op->count, op->buf_fl); struct usbdrive_s *udrive_gf = container_of( op->drive_gf, struct usbdrive_s, drive);
// Setup command block wrapper. - u32 bytes = blocksize * op->count; struct cbw_s cbw; memset(&cbw, 0, sizeof(cbw)); - memcpy(cbw.CBWCB, cdbcmd, USB_CDB_SIZE); + int blocksize = scsi_fill_cmd(op, cbw.CBWCB, USB_CDB_SIZE); + if (blocksize < 0) + return default_process_op(op); + u32 bytes = blocksize * op->count; cbw.dCBWSignature = CBW_SIGNATURE; cbw.dCBWTag = 999; // XXX cbw.dCBWDataTransferLength = bytes; - cbw.bmCBWFlags = cdb_is_read(cdbcmd, blocksize) ? USB_DIR_IN : USB_DIR_OUT; + cbw.bmCBWFlags = cdb_is_read(cbw.CBWCB, blocksize) ? USB_DIR_IN : USB_DIR_OUT; cbw.bCBWLUN = GET_GLOBALFLAT(udrive_gf->lun); cbw.bCBWCBLength = USB_CDB_SIZE;
diff --git a/src/hw/usb-msc.h b/src/hw/usb-msc.h index c40d755..ff3c380 100644 --- a/src/hw/usb-msc.h +++ b/src/hw/usb-msc.h @@ -3,7 +3,7 @@
// usb-msc.c struct disk_op_s; -int usb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize); +int usb_process_op(struct disk_op_s *op); struct usbdevice_s; int usb_msc_setup(struct usbdevice_s *usbdev);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 3 +++ src/hw/blockcmd.c | 6 ------ src/hw/usb-uas.c | 6 ++++-- src/hw/usb-uas.h | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/block.c b/src/block.c index 3aa7595..3e76857 100644 --- a/src/block.c +++ b/src/block.c @@ -13,6 +13,7 @@ #include "hw/pci.h" // pci_bdf_to_bus #include "hw/rtc.h" // rtc_read #include "hw/usb-msc.h" // usb_process_op +#include "hw/usb-uas.h" // uas_process_op #include "hw/virtio-blk.h" // process_virtio_blk_op #include "malloc.h" // malloc_low #include "output.h" // dprintf @@ -495,6 +496,7 @@ process_op_both(struct disk_op_s *op) case DTYPE_USB: return usb_process_op(op); case DTYPE_UAS: + return uas_process_op(op); case DTYPE_LSI_SCSI: case DTYPE_ESP_SCSI: case DTYPE_MEGASAS: @@ -526,6 +528,7 @@ process_op_32(struct disk_op_s *op) case DTYPE_USB_32: return usb_process_op(op); case DTYPE_UAS_32: + return uas_process_op(op); case DTYPE_VIRTIO_SCSI: case DTYPE_PVSCSI: return scsi_process_op(op); diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 9b91098..2d80c1f 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -16,7 +16,6 @@ #include "output.h" // dprintf #include "std/disk.h" // DISK_RET_EPARAM #include "string.h" // memset -#include "usb-uas.h" // usb_cmd_data #include "util.h" // timer_calc #include "virtio-scsi.h" // virtio_scsi_cmd_data
@@ -26,8 +25,6 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) { u8 type = GET_GLOBALFLAT(op->drive_gf->type); switch (type) { - case DTYPE_UAS: - return uas_cmd_data(op, cdbcmd, blocksize); case DTYPE_LSI_SCSI: return lsi_scsi_cmd_data(op, cdbcmd, blocksize); case DTYPE_ESP_SCSI: @@ -37,9 +34,6 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) case DTYPE_VIRTIO_SCSI: if (!MODESEGMENT) return virtio_scsi_cmd_data(op, cdbcmd, blocksize); - case DTYPE_UAS_32: - if (!MODESEGMENT) - return uas_cmd_data(op, cdbcmd, blocksize); case DTYPE_PVSCSI: if (!MODESEGMENT) return pvscsi_cmd_data(op, cdbcmd, blocksize); diff --git a/src/hw/usb-uas.c b/src/hw/usb-uas.c index 6ef8d09..10e3845 100644 --- a/src/hw/usb-uas.c +++ b/src/hw/usb-uas.c @@ -91,7 +91,7 @@ struct uasdrive_s { };
int -uas_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) +uas_process_op(struct disk_op_s *op) { if (!CONFIG_USB_UAS) return DISK_RET_EBADTRACK; @@ -104,7 +104,9 @@ uas_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) ui.hdr.id = UAS_UI_COMMAND; ui.hdr.tag = 0xdead; ui.command.lun[1] = GET_GLOBALFLAT(drive_gf->lun); - memcpy(ui.command.cdb, cdbcmd, sizeof(ui.command.cdb)); + int blocksize = scsi_fill_cmd(op, ui.command.cdb, sizeof(ui.command.cdb)); + if (blocksize < 0) + return default_process_op(op); int ret = usb_send_bulk(GET_GLOBALFLAT(drive_gf->command), USB_DIR_OUT, MAKE_FLATPTR(GET_SEG(SS), &ui), sizeof(ui.hdr) + sizeof(ui.command)); diff --git a/src/hw/usb-uas.h b/src/hw/usb-uas.h index ad91c5f..8b2f810 100644 --- a/src/hw/usb-uas.h +++ b/src/hw/usb-uas.h @@ -2,7 +2,7 @@ #define __USB_UAS_H
struct disk_op_s; -int uas_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize); +int uas_process_op(struct disk_op_s *op); struct usbdevice_s; int usb_uas_setup(struct usbdevice_s *usbdev);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 2 ++ src/hw/blockcmd.c | 3 --- src/hw/lsi-scsi.c | 30 ++++++++++++------------------ src/hw/lsi-scsi.h | 2 +- 4 files changed, 15 insertions(+), 22 deletions(-)
diff --git a/src/block.c b/src/block.c index 3e76857..99b768c 100644 --- a/src/block.c +++ b/src/block.c @@ -10,6 +10,7 @@ #include "hw/ata.h" // process_ata_op #include "hw/ahci.h" // process_ahci_op #include "hw/blockcmd.h" // cdb_* +#include "hw/lsi-scsi.h" // lsi_scsi_process_op #include "hw/pci.h" // pci_bdf_to_bus #include "hw/rtc.h" // rtc_read #include "hw/usb-msc.h" // usb_process_op @@ -498,6 +499,7 @@ process_op_both(struct disk_op_s *op) case DTYPE_UAS: return uas_process_op(op); case DTYPE_LSI_SCSI: + return lsi_scsi_process_op(op); case DTYPE_ESP_SCSI: case DTYPE_MEGASAS: return scsi_process_op(op); diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 2d80c1f..329515c 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -10,7 +10,6 @@ #include "blockcmd.h" // struct cdb_request_sense #include "byteorder.h" // be32_to_cpu #include "esp-scsi.h" // esp_scsi_cmd_data -#include "lsi-scsi.h" // lsi_scsi_cmd_data #include "megasas.h" // megasas_cmd_data #include "pvscsi.h" // pvscsi_cmd_data #include "output.h" // dprintf @@ -25,8 +24,6 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) { u8 type = GET_GLOBALFLAT(op->drive_gf->type); switch (type) { - case DTYPE_LSI_SCSI: - return lsi_scsi_cmd_data(op, cdbcmd, blocksize); case DTYPE_ESP_SCSI: return esp_scsi_cmd_data(op, cdbcmd, blocksize); case DTYPE_MEGASAS: diff --git a/src/hw/lsi-scsi.c b/src/hw/lsi-scsi.c index b1d6bbf..ad9c3bf 100644 --- a/src/hw/lsi-scsi.c +++ b/src/hw/lsi-scsi.c @@ -50,10 +50,19 @@ struct lsi_lun_s { u8 lun; };
-static int -lsi_scsi_cmd(struct lsi_lun_s *llun_gf, struct disk_op_s *op, - void *cdbcmd, u16 target, u16 lun, u16 blocksize) +int +lsi_scsi_process_op(struct disk_op_s *op) { + if (!CONFIG_LSI_SCSI) + return DISK_RET_EBADTRACK; + struct lsi_lun_s *llun_gf = + container_of(op->drive_gf, struct lsi_lun_s, drive); + u16 target = GET_GLOBALFLAT(llun_gf->target); + u16 lun = GET_GLOBALFLAT(llun_gf->lun); + u8 cdbcmd[16]; + int blocksize = scsi_fill_cmd(op, cdbcmd, sizeof(cdbcmd)); + if (blocksize < 0) + return default_process_op(op); u32 iobase = GET_GLOBALFLAT(llun_gf->iobase); u32 dma = ((cdb_is_read(cdbcmd, blocksize) ? 0x01000000 : 0x00000000) | (op->count * blocksize)); @@ -122,21 +131,6 @@ fail: return DISK_RET_EBADTRACK; }
-int -lsi_scsi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) -{ - if (!CONFIG_LSI_SCSI) - return DISK_RET_EBADTRACK; - - struct lsi_lun_s *llun_gf = - container_of(op->drive_gf, struct lsi_lun_s, drive); - - return lsi_scsi_cmd(llun_gf, op, cdbcmd, - GET_GLOBALFLAT(llun_gf->target), - GET_GLOBALFLAT(llun_gf->lun), - blocksize); -} - static int lsi_scsi_add_lun(struct pci_device *pci, u32 iobase, u8 target, u8 lun) { diff --git a/src/hw/lsi-scsi.h b/src/hw/lsi-scsi.h index 9c5a9b2..6baf4a1 100644 --- a/src/hw/lsi-scsi.h +++ b/src/hw/lsi-scsi.h @@ -2,7 +2,7 @@ #define __LSI_SCSI_H
struct disk_op_s; -int lsi_scsi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize); +int lsi_scsi_process_op(struct disk_op_s *op); void lsi_scsi_setup(void);
#endif /* __LSI_SCSI_H */
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 2 ++ src/hw/blockcmd.c | 3 --- src/hw/esp-scsi.c | 30 ++++++++++++------------------ src/hw/esp-scsi.h | 2 +- 4 files changed, 15 insertions(+), 22 deletions(-)
diff --git a/src/block.c b/src/block.c index 99b768c..b76c6e2 100644 --- a/src/block.c +++ b/src/block.c @@ -10,6 +10,7 @@ #include "hw/ata.h" // process_ata_op #include "hw/ahci.h" // process_ahci_op #include "hw/blockcmd.h" // cdb_* +#include "hw/esp-scsi.h" // esp_scsi_process_op #include "hw/lsi-scsi.h" // lsi_scsi_process_op #include "hw/pci.h" // pci_bdf_to_bus #include "hw/rtc.h" // rtc_read @@ -501,6 +502,7 @@ process_op_both(struct disk_op_s *op) case DTYPE_LSI_SCSI: return lsi_scsi_process_op(op); case DTYPE_ESP_SCSI: + return esp_scsi_process_op(op); case DTYPE_MEGASAS: return scsi_process_op(op); default: diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 329515c..8b6c122 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -9,7 +9,6 @@ #include "block.h" // struct disk_op_s #include "blockcmd.h" // struct cdb_request_sense #include "byteorder.h" // be32_to_cpu -#include "esp-scsi.h" // esp_scsi_cmd_data #include "megasas.h" // megasas_cmd_data #include "pvscsi.h" // pvscsi_cmd_data #include "output.h" // dprintf @@ -24,8 +23,6 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) { u8 type = GET_GLOBALFLAT(op->drive_gf->type); switch (type) { - case DTYPE_ESP_SCSI: - return esp_scsi_cmd_data(op, cdbcmd, blocksize); case DTYPE_MEGASAS: return megasas_cmd_data(op, cdbcmd, blocksize); case DTYPE_VIRTIO_SCSI: diff --git a/src/hw/esp-scsi.c b/src/hw/esp-scsi.c index 33cc449..0266492 100644 --- a/src/hw/esp-scsi.c +++ b/src/hw/esp-scsi.c @@ -76,10 +76,19 @@ esp_scsi_dma(u32 iobase, u32 buf, u32 len, int read) outb(read ? 0x83 : 0x03, iobase + ESP_DMA_CMD); }
-static int -esp_scsi_cmd(struct esp_lun_s *llun_gf, struct disk_op_s *op, - u8 *cdbcmd, u16 target, u16 lun, u16 blocksize) +int +esp_scsi_process_op(struct disk_op_s *op) { + if (!CONFIG_ESP_SCSI) + return DISK_RET_EBADTRACK; + struct esp_lun_s *llun_gf = + container_of(op->drive_gf, struct esp_lun_s, drive); + u16 target = GET_GLOBALFLAT(llun_gf->target); + u16 lun = GET_GLOBALFLAT(llun_gf->lun); + u8 cdbcmd[16]; + int blocksize = scsi_fill_cmd(op, cdbcmd, sizeof(cdbcmd)); + if (blocksize < 0) + return default_process_op(op); u32 iobase = GET_GLOBALFLAT(llun_gf->iobase); int i, state; u8 status; @@ -144,21 +153,6 @@ esp_scsi_cmd(struct esp_lun_s *llun_gf, struct disk_op_s *op, return DISK_RET_EBADTRACK; }
-int -esp_scsi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) -{ - if (!CONFIG_ESP_SCSI) - return DISK_RET_EBADTRACK; - - struct esp_lun_s *llun_gf = - container_of(op->drive_gf, struct esp_lun_s, drive); - - return esp_scsi_cmd(llun_gf, op, cdbcmd, - GET_GLOBALFLAT(llun_gf->target), - GET_GLOBALFLAT(llun_gf->lun), - blocksize); -} - static int esp_scsi_add_lun(struct pci_device *pci, u32 iobase, u8 target, u8 lun) { diff --git a/src/hw/esp-scsi.h b/src/hw/esp-scsi.h index dc555f3..0616d14 100644 --- a/src/hw/esp-scsi.h +++ b/src/hw/esp-scsi.h @@ -2,7 +2,7 @@ #define __ESP_SCSI_H
struct disk_op_s; -int esp_scsi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize); +int esp_scsi_process_op(struct disk_op_s *op); void esp_scsi_setup(void);
#endif /* __ESP_SCSI_H */
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 3 ++- src/hw/blockcmd.c | 3 --- src/hw/megasas.c | 12 +++++++----- src/hw/megasas.h | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/block.c b/src/block.c index b76c6e2..d4bf029 100644 --- a/src/block.c +++ b/src/block.c @@ -12,6 +12,7 @@ #include "hw/blockcmd.h" // cdb_* #include "hw/esp-scsi.h" // esp_scsi_process_op #include "hw/lsi-scsi.h" // lsi_scsi_process_op +#include "hw/megasas.h" // megasas_process_op #include "hw/pci.h" // pci_bdf_to_bus #include "hw/rtc.h" // rtc_read #include "hw/usb-msc.h" // usb_process_op @@ -504,7 +505,7 @@ process_op_both(struct disk_op_s *op) case DTYPE_ESP_SCSI: return esp_scsi_process_op(op); case DTYPE_MEGASAS: - return scsi_process_op(op); + return megasas_process_op(op); default: if (!MODESEGMENT) return DISK_RET_EPARAM; diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 8b6c122..b0a512b 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -9,7 +9,6 @@ #include "block.h" // struct disk_op_s #include "blockcmd.h" // struct cdb_request_sense #include "byteorder.h" // be32_to_cpu -#include "megasas.h" // megasas_cmd_data #include "pvscsi.h" // pvscsi_cmd_data #include "output.h" // dprintf #include "std/disk.h" // DISK_RET_EPARAM @@ -23,8 +22,6 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) { u8 type = GET_GLOBALFLAT(op->drive_gf->type); switch (type) { - case DTYPE_MEGASAS: - return megasas_cmd_data(op, cdbcmd, blocksize); case DTYPE_VIRTIO_SCSI: if (!MODESEGMENT) return virtio_scsi_cmd_data(op, cdbcmd, blocksize); diff --git a/src/hw/megasas.c b/src/hw/megasas.c index 6677977..5a07ab3 100644 --- a/src/hw/megasas.c +++ b/src/hw/megasas.c @@ -157,18 +157,20 @@ static int megasas_fire_cmd(u16 pci_id, u32 ioaddr, }
int -megasas_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) +megasas_process_op(struct disk_op_s *op) { + if (!CONFIG_MEGASAS) + return DISK_RET_EBADTRACK; + u8 cdb[16]; + int blocksize = scsi_fill_cmd(op, cdb, sizeof(cdb)); + if (blocksize < 0) + return default_process_op(op); struct megasas_lun_s *mlun_gf = container_of(op->drive_gf, struct megasas_lun_s, drive); - u8 *cdb = cdbcmd; struct megasas_cmd_frame *frame = GET_GLOBALFLAT(mlun_gf->frame); u16 pci_id = GET_GLOBALFLAT(mlun_gf->pci_id); int i;
- if (!CONFIG_MEGASAS) - return DISK_RET_EBADTRACK; - memset_fl(frame, 0, sizeof(*frame)); SET_LOWFLAT(frame->cmd, MFI_CMD_LD_SCSI_IO); SET_LOWFLAT(frame->cmd_status, 0xFF); diff --git a/src/hw/megasas.h b/src/hw/megasas.h index 124042e..ed0e4f0 100644 --- a/src/hw/megasas.h +++ b/src/hw/megasas.h @@ -2,7 +2,7 @@ #define __MEGASAS_H
struct disk_op_s; -int megasas_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize); +int megasas_process_op(struct disk_op_s *op); void megasas_setup(void);
#endif /* __MEGASAS_H */
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 2 ++ src/hw/blockcmd.c | 4 ---- src/hw/virtio-scsi.c | 37 +++++++++++++++---------------------- src/hw/virtio-scsi.h | 2 +- 4 files changed, 18 insertions(+), 27 deletions(-)
diff --git a/src/block.c b/src/block.c index d4bf029..422e2a2 100644 --- a/src/block.c +++ b/src/block.c @@ -18,6 +18,7 @@ #include "hw/usb-msc.h" // usb_process_op #include "hw/usb-uas.h" // uas_process_op #include "hw/virtio-blk.h" // process_virtio_blk_op +#include "hw/virtio-scsi.h" // virtio_scsi_process_op #include "malloc.h" // malloc_low #include "output.h" // dprintf #include "stacks.h" // stack_hop @@ -535,6 +536,7 @@ process_op_32(struct disk_op_s *op) case DTYPE_UAS_32: return uas_process_op(op); case DTYPE_VIRTIO_SCSI: + return virtio_scsi_process_op(op); case DTYPE_PVSCSI: return scsi_process_op(op); default: diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index b0a512b..684f420 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -14,7 +14,6 @@ #include "std/disk.h" // DISK_RET_EPARAM #include "string.h" // memset #include "util.h" // timer_calc -#include "virtio-scsi.h" // virtio_scsi_cmd_data
// Route command to low-level handler. static int @@ -22,9 +21,6 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) { u8 type = GET_GLOBALFLAT(op->drive_gf->type); switch (type) { - case DTYPE_VIRTIO_SCSI: - if (!MODESEGMENT) - return virtio_scsi_cmd_data(op, cdbcmd, blocksize); case DTYPE_PVSCSI: if (!MODESEGMENT) return pvscsi_cmd_data(op, cdbcmd, blocksize); diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index cb825d4..8cdcfd0 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -32,24 +32,30 @@ struct virtio_lun_s { u16 lun; };
-static int -virtio_scsi_cmd(struct vp_device *vp, struct vring_virtqueue *vq, - struct disk_op_s *op, void *cdbcmd, u16 target, u16 lun, - u16 blocksize) +int +virtio_scsi_process_op(struct disk_op_s *op) { + if (! CONFIG_VIRTIO_SCSI) + return 0; + struct virtio_lun_s *vlun = + container_of(op->drive_gf, struct virtio_lun_s, drive); + struct vp_device *vp = vlun->vp; + struct vring_virtqueue *vq = vlun->vq; struct virtio_scsi_req_cmd req; struct virtio_scsi_resp_cmd resp; struct vring_list sg[3];
memset(&req, 0, sizeof(req)); + int blocksize = scsi_fill_cmd(op, req.cdb, 16); + if (blocksize < 0) + return default_process_op(op); req.lun[0] = 1; - req.lun[1] = target; - req.lun[2] = (lun >> 8) | 0x40; - req.lun[3] = (lun & 0xff); - memcpy(req.cdb, cdbcmd, 16); + req.lun[1] = vlun->target; + req.lun[2] = (vlun->lun >> 8) | 0x40; + req.lun[3] = (vlun->lun & 0xff);
u32 len = op->count * blocksize; - int datain = cdb_is_read(cdbcmd, blocksize); + int datain = cdb_is_read((u8*)req.cdb, blocksize); int in_num = (datain ? 2 : 1); int out_num = (len ? 3 : 2) - in_num;
@@ -87,19 +93,6 @@ virtio_scsi_cmd(struct vp_device *vp, struct vring_virtqueue *vq, return DISK_RET_EBADTRACK; }
-int -virtio_scsi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) -{ - struct virtio_lun_s *vlun_gf = - container_of(op->drive_gf, struct virtio_lun_s, drive); - - return virtio_scsi_cmd(vlun_gf->vp, - vlun_gf->vq, op, cdbcmd, - vlun_gf->target, - vlun_gf->lun, - blocksize); -} - static int virtio_scsi_add_lun(struct pci_device *pci, struct vp_device *vp, struct vring_virtqueue *vq, u16 target, u16 lun) diff --git a/src/hw/virtio-scsi.h b/src/hw/virtio-scsi.h index 96c3701..7532cc9 100644 --- a/src/hw/virtio-scsi.h +++ b/src/hw/virtio-scsi.h @@ -41,7 +41,7 @@ struct virtio_scsi_resp_cmd { #define VIRTIO_SCSI_S_OK 0
struct disk_op_s; -int virtio_scsi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize); +int virtio_scsi_process_op(struct disk_op_s *op); void virtio_scsi_setup(void);
#endif /* _VIRTIO_SCSI_H */
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/pvscsi.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-)
diff --git a/src/hw/pvscsi.c b/src/hw/pvscsi.c index 601a551..67d1d94 100644 --- a/src/hw/pvscsi.c +++ b/src/hw/pvscsi.c @@ -197,29 +197,6 @@ pvscsi_init_rings(void *iobase, struct pvscsi_ring_dsc_s **ring_dsc) *ring_dsc = dsc; }
-static void pvscsi_fill_req(struct PVSCSIRingsState *s, - struct PVSCSIRingReqDesc *req, - u16 target, u16 lun, void *cdbcmd, u16 blocksize, - struct disk_op_s *op) -{ - req->bus = 0; - req->target = target; - memset(req->lun, 0, sizeof(req->lun)); - req->lun[1] = lun; - req->senseLen = 0; - req->senseAddr = 0; - req->cdbLen = 16; - req->vcpuHint = 0; - memcpy(req->cdb, cdbcmd, 16); - req->tag = SIMPLE_QUEUE_TAG; - req->flags = cdb_is_read(cdbcmd, blocksize) ? - PVSCSI_FLAG_CMD_DIR_TOHOST : PVSCSI_FLAG_CMD_DIR_TODEVICE; - - req->dataLen = op->count * blocksize; - req->dataAddr = (u32)op->buf_fl; - s->reqProdIdx = s->reqProdIdx + 1; -} - static u32 pvscsi_get_rsp(struct PVSCSIRingsState *s, struct PVSCSIRingCmpDesc *rsp) @@ -248,7 +225,21 @@ pvscsi_cmd(struct pvscsi_lun_s *plun, struct disk_op_s *op, }
req = ring_dsc->ring_reqs + (s->reqProdIdx & MASK(req_entries)); - pvscsi_fill_req(s, req, target, lun, cdbcmd, blocksize, op); + req->bus = 0; + req->target = target; + memset(req->lun, 0, sizeof(req->lun)); + req->lun[1] = lun; + req->senseLen = 0; + req->senseAddr = 0; + req->cdbLen = 16; + req->vcpuHint = 0; + memcpy(req->cdb, cdbcmd, 16); + req->tag = SIMPLE_QUEUE_TAG; + req->flags = cdb_is_read(cdbcmd, blocksize) ? + PVSCSI_FLAG_CMD_DIR_TOHOST : PVSCSI_FLAG_CMD_DIR_TODEVICE; + req->dataLen = op->count * blocksize; + req->dataAddr = (u32)op->buf_fl; + s->reqProdIdx = s->reqProdIdx + 1;
pvscsi_kick_rw_io(plun->iobase); pvscsi_wait_intr_cmpl(plun->iobase);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 3 ++- src/hw/blockcmd.c | 4 ---- src/hw/pvscsi.c | 31 ++++++++++++------------------- src/hw/pvscsi.h | 2 +- 4 files changed, 15 insertions(+), 25 deletions(-)
diff --git a/src/block.c b/src/block.c index 422e2a2..8e5bdad 100644 --- a/src/block.c +++ b/src/block.c @@ -14,6 +14,7 @@ #include "hw/lsi-scsi.h" // lsi_scsi_process_op #include "hw/megasas.h" // megasas_process_op #include "hw/pci.h" // pci_bdf_to_bus +#include "hw/pvscsi.h" // pvscsi_process_op #include "hw/rtc.h" // rtc_read #include "hw/usb-msc.h" // usb_process_op #include "hw/usb-uas.h" // uas_process_op @@ -538,7 +539,7 @@ process_op_32(struct disk_op_s *op) case DTYPE_VIRTIO_SCSI: return virtio_scsi_process_op(op); case DTYPE_PVSCSI: - return scsi_process_op(op); + return pvscsi_process_op(op); default: return process_op_both(op); } diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 684f420..4b4798b 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -9,7 +9,6 @@ #include "block.h" // struct disk_op_s #include "blockcmd.h" // struct cdb_request_sense #include "byteorder.h" // be32_to_cpu -#include "pvscsi.h" // pvscsi_cmd_data #include "output.h" // dprintf #include "std/disk.h" // DISK_RET_EPARAM #include "string.h" // memset @@ -21,9 +20,6 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) { u8 type = GET_GLOBALFLAT(op->drive_gf->type); switch (type) { - case DTYPE_PVSCSI: - if (!MODESEGMENT) - return pvscsi_cmd_data(op, cdbcmd, blocksize); default: return DISK_RET_EPARAM; } diff --git a/src/hw/pvscsi.c b/src/hw/pvscsi.c index 67d1d94..4e98b5d 100644 --- a/src/hw/pvscsi.c +++ b/src/hw/pvscsi.c @@ -206,10 +206,13 @@ pvscsi_get_rsp(struct PVSCSIRingsState *s, return status; }
-static int -pvscsi_cmd(struct pvscsi_lun_s *plun, struct disk_op_s *op, - void *cdbcmd, u16 target, u16 lun, u16 blocksize) +int +pvscsi_process_op(struct disk_op_s *op) { + if (!CONFIG_PVSCSI) + return DISK_RET_EBADTRACK; + struct pvscsi_lun_s *plun = + container_of(op->drive_gf, struct pvscsi_lun_s, drive); struct pvscsi_ring_dsc_s *ring_dsc = plun->ring_dsc; struct PVSCSIRingsState *s = ring_dsc->ring_state; u32 req_entries = s->reqNumEntriesLog2; @@ -225,17 +228,19 @@ pvscsi_cmd(struct pvscsi_lun_s *plun, struct disk_op_s *op, }
req = ring_dsc->ring_reqs + (s->reqProdIdx & MASK(req_entries)); + int blocksize = scsi_fill_cmd(op, req->cdb, 16); + if (blocksize < 0) + return default_process_op(op); req->bus = 0; - req->target = target; + req->target = plun->target; memset(req->lun, 0, sizeof(req->lun)); - req->lun[1] = lun; + req->lun[1] = plun->lun; req->senseLen = 0; req->senseAddr = 0; req->cdbLen = 16; req->vcpuHint = 0; - memcpy(req->cdb, cdbcmd, 16); req->tag = SIMPLE_QUEUE_TAG; - req->flags = cdb_is_read(cdbcmd, blocksize) ? + req->flags = cdb_is_read(req->cdb, blocksize) ? PVSCSI_FLAG_CMD_DIR_TOHOST : PVSCSI_FLAG_CMD_DIR_TODEVICE; req->dataLen = op->count * blocksize; req->dataAddr = (u32)op->buf_fl; @@ -250,18 +255,6 @@ pvscsi_cmd(struct pvscsi_lun_s *plun, struct disk_op_s *op, return status == 0 ? DISK_RET_SUCCESS : DISK_RET_EBADTRACK; }
-int -pvscsi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) -{ - if (!CONFIG_PVSCSI) - return DISK_RET_EBADTRACK; - - struct pvscsi_lun_s *plun = - container_of(op->drive_gf, struct pvscsi_lun_s, drive); - - return pvscsi_cmd(plun, op, cdbcmd, plun->target, plun->lun, blocksize); -} - static int pvscsi_add_lun(struct pci_device *pci, void *iobase, struct pvscsi_ring_dsc_s *ring_dsc, u8 target, u8 lun) diff --git a/src/hw/pvscsi.h b/src/hw/pvscsi.h index fde9f0b..5af7dcb 100644 --- a/src/hw/pvscsi.h +++ b/src/hw/pvscsi.h @@ -2,7 +2,7 @@ #define _PVSCSI_H_
struct disk_op_s; -int pvscsi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize); +int pvscsi_process_op(struct disk_op_s *op); void pvscsi_setup(void);
#endif /* _PVSCSI_H_ */
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/blockcmd.c | 21 --------------------- src/hw/blockcmd.h | 1 - 2 files changed, 22 deletions(-)
diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 4b4798b..c56f7f5 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -14,17 +14,6 @@ #include "string.h" // memset #include "util.h" // timer_calc
-// Route command to low-level handler. -static int -cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) -{ - u8 type = GET_GLOBALFLAT(op->drive_gf->type); - switch (type) { - default: - return DISK_RET_EPARAM; - } -} - // Determine if the command is a request to pull data from the device int cdb_is_read(u8 *cdbcmd, u16 blocksize) @@ -144,16 +133,6 @@ scsi_fill_cmd(struct disk_op_s *op, void *cdbcmd, int maxcdb) }
int -scsi_process_op(struct disk_op_s *op) -{ - char cdbcmd[16]; - int blocksize = scsi_fill_cmd(op, cdbcmd, sizeof(cdbcmd)); - if (blocksize < 0) - return default_process_op(op); - return cdb_cmd_data(op, cdbcmd, blocksize); -} - -int scsi_is_ready(struct disk_op_s *op) { dprintf(6, "scsi_is_ready (drive=%p)\n", op->drive_gf); diff --git a/src/hw/blockcmd.h b/src/hw/blockcmd.h index 9077e82..52b72bc 100644 --- a/src/hw/blockcmd.h +++ b/src/hw/blockcmd.h @@ -103,7 +103,6 @@ struct cdbres_mode_sense_geom { int cdb_is_read(u8 *cdbcmd, u16 blocksize); struct disk_op_s; int scsi_fill_cmd(struct disk_op_s *op, void *cdbcmd, int maxcdb); -int scsi_process_op(struct disk_op_s *op); int scsi_is_ready(struct disk_op_s *op); struct drive_s; int scsi_drive_setup(struct drive_s *drive, const char *s, int prio);
Convert the cdb_is_read() function to a new function scsi_is_read() which takes a 'struct disk_op_s' as a paramter.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/blockcmd.c | 15 ++++++++------- src/hw/blockcmd.h | 2 +- src/hw/esp-scsi.c | 3 +-- src/hw/lsi-scsi.c | 2 +- src/hw/pvscsi.c | 2 +- src/hw/usb-msc.c | 2 +- src/hw/virtio-scsi.c | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index c56f7f5..e20e3fc 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -14,13 +14,6 @@ #include "string.h" // memset #include "util.h" // timer_calc
-// Determine if the command is a request to pull data from the device -int -cdb_is_read(u8 *cdbcmd, u16 blocksize) -{ - return blocksize && cdbcmd[0] != CDB_CMD_WRITE_10; -} -
/**************************************************************** * Low level command requests @@ -132,6 +125,14 @@ scsi_fill_cmd(struct disk_op_s *op, void *cdbcmd, int maxcdb) } }
+// Determine if the command is a request to pull data from the device +int +scsi_is_read(struct disk_op_s *op) +{ + return op->command == CMD_READ || (op->command == CMD_SCSI && op->blocksize); +} + +// Check if a SCSI device is ready to receive commands int scsi_is_ready(struct disk_op_s *op) { diff --git a/src/hw/blockcmd.h b/src/hw/blockcmd.h index 52b72bc..b543f85 100644 --- a/src/hw/blockcmd.h +++ b/src/hw/blockcmd.h @@ -100,9 +100,9 @@ struct cdbres_mode_sense_geom { } PACKED;
// blockcmd.c -int cdb_is_read(u8 *cdbcmd, u16 blocksize); struct disk_op_s; int scsi_fill_cmd(struct disk_op_s *op, void *cdbcmd, int maxcdb); +int scsi_is_read(struct disk_op_s *op); int scsi_is_ready(struct disk_op_s *op); struct drive_s; int scsi_drive_setup(struct drive_s *drive, const char *s, int prio); diff --git a/src/hw/esp-scsi.c b/src/hw/esp-scsi.c index 0266492..d4e47e3 100644 --- a/src/hw/esp-scsi.c +++ b/src/hw/esp-scsi.c @@ -122,8 +122,7 @@ esp_scsi_process_op(struct disk_op_s *op) if (op->count && blocksize) { /* Data phase. */ u32 count = (u32)op->count * blocksize; - esp_scsi_dma(iobase, (u32)op->buf_fl, count, - cdb_is_read(cdbcmd, blocksize)); + esp_scsi_dma(iobase, (u32)op->buf_fl, count, scsi_is_read(op)); outb(ESP_CMD_TI | ESP_CMD_DMA, iobase + ESP_CMD); continue; } diff --git a/src/hw/lsi-scsi.c b/src/hw/lsi-scsi.c index ad9c3bf..ad33528 100644 --- a/src/hw/lsi-scsi.c +++ b/src/hw/lsi-scsi.c @@ -64,7 +64,7 @@ lsi_scsi_process_op(struct disk_op_s *op) if (blocksize < 0) return default_process_op(op); u32 iobase = GET_GLOBALFLAT(llun_gf->iobase); - u32 dma = ((cdb_is_read(cdbcmd, blocksize) ? 0x01000000 : 0x00000000) | + u32 dma = ((scsi_is_read(op) ? 0x01000000 : 0x00000000) | (op->count * blocksize)); u8 msgout[] = { 0x80 | lun, // select lun diff --git a/src/hw/pvscsi.c b/src/hw/pvscsi.c index 4e98b5d..a462522 100644 --- a/src/hw/pvscsi.c +++ b/src/hw/pvscsi.c @@ -240,7 +240,7 @@ pvscsi_process_op(struct disk_op_s *op) req->cdbLen = 16; req->vcpuHint = 0; req->tag = SIMPLE_QUEUE_TAG; - req->flags = cdb_is_read(req->cdb, blocksize) ? + req->flags = scsi_is_read(op) ? PVSCSI_FLAG_CMD_DIR_TOHOST : PVSCSI_FLAG_CMD_DIR_TODEVICE; req->dataLen = op->count * blocksize; req->dataAddr = (u32)op->buf_fl; diff --git a/src/hw/usb-msc.c b/src/hw/usb-msc.c index 3376f2c..a234f13 100644 --- a/src/hw/usb-msc.c +++ b/src/hw/usb-msc.c @@ -83,7 +83,7 @@ usb_process_op(struct disk_op_s *op) cbw.dCBWSignature = CBW_SIGNATURE; cbw.dCBWTag = 999; // XXX cbw.dCBWDataTransferLength = bytes; - cbw.bmCBWFlags = cdb_is_read(cbw.CBWCB, blocksize) ? USB_DIR_IN : USB_DIR_OUT; + cbw.bmCBWFlags = scsi_is_read(op) ? USB_DIR_IN : USB_DIR_OUT; cbw.bCBWLUN = GET_GLOBALFLAT(udrive_gf->lun); cbw.bCBWCBLength = USB_CDB_SIZE;
diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index 8cdcfd0..80afd04 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -55,7 +55,7 @@ virtio_scsi_process_op(struct disk_op_s *op) req.lun[3] = (vlun->lun & 0xff);
u32 len = op->count * blocksize; - int datain = cdb_is_read((u8*)req.cdb, blocksize); + int datain = scsi_is_read(op); int in_num = (datain ? 2 : 1); int out_num = (len ? 3 : 2) - in_num;
Rename disk driver dispatch functions to a consistent naming style.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 14 +++++++------- src/cdrom.c | 2 +- src/hw/ahci.c | 2 +- src/hw/ahci.h | 2 +- src/hw/ata.c | 2 +- src/hw/ata.h | 3 +-- src/hw/floppy.c | 2 +- src/hw/ramdisk.c | 2 +- src/hw/sdcard.c | 2 +- src/hw/virtio-blk.c | 2 +- src/hw/virtio-blk.h | 2 +- src/util.h | 8 ++++---- 12 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/src/block.c b/src/block.c index 8e5bdad..5e08663 100644 --- a/src/block.c +++ b/src/block.c @@ -525,13 +525,13 @@ process_op_32(struct disk_op_s *op) ASSERT32FLAT(); switch (op->drive_gf->type) { case DTYPE_VIRTIO_BLK: - return process_virtio_blk_op(op); + return virtio_blk_process_op(op); case DTYPE_AHCI: - return process_ahci_op(op); + return ahci_process_op(op); case DTYPE_AHCI_ATAPI: return ahci_atapi_process_op(op); case DTYPE_SDCARD: - return process_sdcard_op(op); + return sdcard_process_op(op); case DTYPE_USB_32: return usb_process_op(op); case DTYPE_UAS_32: @@ -552,13 +552,13 @@ process_op_16(struct disk_op_s *op) ASSERT16(); switch (GET_GLOBALFLAT(op->drive_gf->type)) { case DTYPE_FLOPPY: - return process_floppy_op(op); + return floppy_process_op(op); case DTYPE_ATA: - return process_ata_op(op); + return ata_process_op(op); case DTYPE_RAMDISK: - return process_ramdisk_op(op); + return ramdisk_process_op(op); case DTYPE_CDEMU: - return process_cdemu_op(op); + return cdemu_process_op(op); default: return process_op_both(op); } diff --git a/src/cdrom.c b/src/cdrom.c index 60964bd..00e9e09 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -89,7 +89,7 @@ cdemu_read(struct disk_op_s *op) }
int -process_cdemu_op(struct disk_op_s *op) +cdemu_process_op(struct disk_op_s *op) { if (!CONFIG_CDROM_EMU) return 0; diff --git a/src/hw/ahci.c b/src/hw/ahci.c index 72ba230..2253281 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -297,7 +297,7 @@ ahci_disk_readwrite(struct disk_op_s *op, int iswrite)
// command demuxer int -process_ahci_op(struct disk_op_s *op) +ahci_process_op(struct disk_op_s *op) { if (!CONFIG_AHCI) return 0; diff --git a/src/hw/ahci.h b/src/hw/ahci.h index 16ad6a9..fa11d66 100644 --- a/src/hw/ahci.h +++ b/src/hw/ahci.h @@ -83,7 +83,7 @@ struct ahci_port_s { };
void ahci_setup(void); -int process_ahci_op(struct disk_op_s *op); +int ahci_process_op(struct disk_op_s *op); int ahci_atapi_process_op(struct disk_op_s *op);
#define AHCI_IRQ_ON_SG (1 << 31) diff --git a/src/hw/ata.c b/src/hw/ata.c index b5bd75f..3efc6ab 100644 --- a/src/hw/ata.c +++ b/src/hw/ata.c @@ -552,7 +552,7 @@ ata_readwrite(struct disk_op_s *op, int iswrite)
// 16bit command demuxer for ATA harddrives. int -process_ata_op(struct disk_op_s *op) +ata_process_op(struct disk_op_s *op) { if (!CONFIG_ATA) return 0; diff --git a/src/hw/ata.h b/src/hw/ata.h index 3a7ab65..65bfcb7 100644 --- a/src/hw/ata.h +++ b/src/hw/ata.h @@ -24,10 +24,9 @@ struct atadrive_s { // ata.c char *ata_extract_model(char *model, u32 size, u16 *buffer); int ata_extract_version(u16 *buffer); -int cdrom_read(struct disk_op_s *op); +int ata_process_op(struct disk_op_s *op); int ata_atapi_process_op(struct disk_op_s *op); void ata_setup(void); -int process_ata_op(struct disk_op_s *op);
#define PORT_ATA2_CMD_BASE 0x0170 #define PORT_ATA1_CMD_BASE 0x01f0 diff --git a/src/hw/floppy.c b/src/hw/floppy.c index d60362a..a14f7e0 100644 --- a/src/hw/floppy.c +++ b/src/hw/floppy.c @@ -613,7 +613,7 @@ floppy_format(struct disk_op_s *op) }
int -process_floppy_op(struct disk_op_s *op) +floppy_process_op(struct disk_op_s *op) { if (!CONFIG_FLOPPY) return 0; diff --git a/src/hw/ramdisk.c b/src/hw/ramdisk.c index 67ba59c..e847824 100644 --- a/src/hw/ramdisk.c +++ b/src/hw/ramdisk.c @@ -91,7 +91,7 @@ ramdisk_copy(struct disk_op_s *op, int iswrite) }
int -process_ramdisk_op(struct disk_op_s *op) +ramdisk_process_op(struct disk_op_s *op) { if (!CONFIG_FLASH_FLOPPY) return 0; diff --git a/src/hw/sdcard.c b/src/hw/sdcard.c index 965543c..d2c3288 100644 --- a/src/hw/sdcard.c +++ b/src/hw/sdcard.c @@ -209,7 +209,7 @@ sdcard_readwrite(struct disk_op_s *op, int iswrite) }
int -process_sdcard_op(struct disk_op_s *op) +sdcard_process_op(struct disk_op_s *op) { if (!CONFIG_SDCARD) return 0; diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 92a5546..94485e2 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -78,7 +78,7 @@ virtio_blk_op(struct disk_op_s *op, int write) }
int -process_virtio_blk_op(struct disk_op_s *op) +virtio_blk_process_op(struct disk_op_s *op) { if (! CONFIG_VIRTIO_BLK) return 0; diff --git a/src/hw/virtio-blk.h b/src/hw/virtio-blk.h index b233c74..157bed6 100644 --- a/src/hw/virtio-blk.h +++ b/src/hw/virtio-blk.h @@ -37,7 +37,7 @@ struct virtio_blk_outhdr { #define VIRTIO_BLK_S_UNSUPP 2
struct disk_op_s; -int process_virtio_blk_op(struct disk_op_s *op); +int virtio_blk_process_op(struct disk_op_s *op); void virtio_blk_setup(void);
#endif /* _VIRTIO_BLK_H */ diff --git a/src/util.h b/src/util.h index 6250c12..cea844f 100644 --- a/src/util.h +++ b/src/util.h @@ -47,7 +47,7 @@ extern u8 CDRom_locks[]; extern struct eltorito_s CDEmu; extern struct drive_s *cdemu_drive_gf; struct disk_op_s; -int process_cdemu_op(struct disk_op_s *op); +int cdemu_process_op(struct disk_op_s *op); void cdrom_prepboot(void); int cdrom_boot(struct drive_s *drive_g);
@@ -143,15 +143,15 @@ extern struct floppy_ext_dbt_s diskette_param_table2; void floppy_setup(void); struct drive_s *init_floppy(int floppyid, int ftype); int find_floppy_type(u32 size); -int process_floppy_op(struct disk_op_s *op); +int floppy_process_op(struct disk_op_s *op); void floppy_tick(void);
// hw/ramdisk.c void ramdisk_setup(void); -int process_ramdisk_op(struct disk_op_s *op); +int ramdisk_process_op(struct disk_op_s *op);
// hw/sdcard.c -int process_sdcard_op(struct disk_op_s *op); +int sdcard_process_op(struct disk_op_s *op); void sdcard_setup(void);
// hw/timer.c
On Tue, Jul 07, 2015 at 03:26:04PM -0400, Kevin O'Connor wrote:
This series implements some code reorganization in an attempt to simplify the disk driver command dispatch system. The series should have no user-visible changes - it's mostly just code reorg.
FYI - I have pushed this series.
-Kevin