The BusLogic SCSI controller emulation is now fully converted to the SCSI device abstraction layer;
The SCSI device abstraction layer is now in scsi_device.c/h.
This commit is contained in:
130
src/scsi.c
130
src/scsi.c
@@ -26,7 +26,6 @@
|
||||
#include "scsi.h"
|
||||
#include "scsi_aha154x.h"
|
||||
#include "scsi_buslogic.h"
|
||||
#include "scsi_disk.h"
|
||||
|
||||
|
||||
uint8_t SCSIPhase = SCSI_PHASE_BUS_FREE;
|
||||
@@ -161,132 +160,3 @@ void SCSIReset(uint8_t id, uint8_t lun)
|
||||
SCSIDevices[id][lun].CmdBuffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void scsi_target_command(int lun_type, uint8_t id, uint8_t *cdb)
|
||||
{
|
||||
if (lun_type == SCSI_DISK)
|
||||
{
|
||||
SCSIPhase = SCSI_PHASE_COMMAND;
|
||||
scsi_hd_command(id, cdb);
|
||||
SCSIStatus = scsi_hd_err_stat_to_scsi(id);
|
||||
}
|
||||
else if (lun_type == SCSI_CDROM)
|
||||
{
|
||||
SCSIPhase = SCSI_PHASE_COMMAND;
|
||||
cdrom_command(id, cdb);
|
||||
SCSIStatus = cdrom_CDROM_PHASE_to_scsi(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
SCSIStatus = SCSI_STATUS_CHECK_CONDITION;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int scsi_target_phase_to_scsi(int lun_type, uint8_t id)
|
||||
{
|
||||
if (lun_type == SCSI_DISK)
|
||||
{
|
||||
return scsi_hd_phase_to_scsi(id);
|
||||
}
|
||||
else if (lun_type == SCSI_CDROM)
|
||||
{
|
||||
return cdrom_atapi_phase_to_scsi(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void scsi_target_phase_callback(int lun_type, uint8_t id)
|
||||
{
|
||||
if (lun_type == SCSI_DISK)
|
||||
{
|
||||
scsi_hd_callback(id);
|
||||
}
|
||||
else if (lun_type == SCSI_CDROM)
|
||||
{
|
||||
cdrom_phase_callback(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int scsi_target_err_stat_to_scsi(int lun_type, uint8_t id)
|
||||
{
|
||||
if (lun_type == SCSI_DISK)
|
||||
{
|
||||
return scsi_hd_err_stat_to_scsi(id);
|
||||
}
|
||||
else if (lun_type == SCSI_CDROM)
|
||||
{
|
||||
return cdrom_CDROM_PHASE_to_scsi(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
return SCSI_STATUS_CHECK_CONDITION;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void scsi_target_save_cdb_byte(int lun_type, uint8_t id, uint8_t cdb_byte)
|
||||
{
|
||||
if (lun_type == SCSI_DISK)
|
||||
{
|
||||
shdc[id].request_length = cdb_byte;
|
||||
}
|
||||
else if (lun_type == SCSI_CDROM)
|
||||
{
|
||||
cdrom[id].request_length = cdb_byte;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void scsi_command(int cdb_len, int lun_type, uint8_t id, uint8_t *cdb)
|
||||
{
|
||||
uint8_t phase = 0;
|
||||
|
||||
/*
|
||||
* Since that field in the target struct is never used when
|
||||
* the bus type is SCSI, let's use it for this scope.
|
||||
*/
|
||||
scsi_target_save_cdb_byte(lun_type, id, cdb[1]);
|
||||
|
||||
if (cdb_len != 12) {
|
||||
/*
|
||||
* Make sure the LUN field of the temporary CDB is always 0,
|
||||
* otherwise Daemon Tools drives will misbehave when a command
|
||||
* is passed through to them.
|
||||
*/
|
||||
cdb[1] &= 0x1f;
|
||||
}
|
||||
|
||||
/* Finally, execute the SCSI command immediately and get the transfer length. */
|
||||
scsi_target_command(lun_type, id, cdb);
|
||||
if (SCSIStatus == SCSI_STATUS_OK) {
|
||||
phase = scsi_target_phase_to_scsi(lun_type, id);
|
||||
if (phase == 2) {
|
||||
/* Command completed - call the phase callback to complete the command. */
|
||||
scsi_target_phase_callback(lun_type, id);
|
||||
} else {
|
||||
/* Command first phase complete - call the callback to execute the second phase. */
|
||||
scsi_target_phase_callback(lun_type, id);
|
||||
SCSIStatus = scsi_target_err_stat_to_scsi(lun_type, id);
|
||||
/* Command second phase complete - call the callback to complete the command. */
|
||||
scsi_target_phase_callback(lun_type, id);
|
||||
}
|
||||
} else {
|
||||
/* Error (Check Condition) - call the phase callback to complete the command. */
|
||||
scsi_target_phase_callback(lun_type, id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user