diff --git a/src/raspberrypi/controllers/sasidev_ctrl.cpp b/src/raspberrypi/controllers/sasidev_ctrl.cpp index 500b951c..ed1a3941 100644 --- a/src/raspberrypi/controllers/sasidev_ctrl.cpp +++ b/src/raspberrypi/controllers/sasidev_ctrl.cpp @@ -18,7 +18,6 @@ #include "gpiobus.h" #include "devices/scsi_host_bridge.h" #include "devices/scsi_daynaport.h" -#include "exceptions.h" #include //=========================================================================== @@ -369,14 +368,7 @@ void SASIDEV::Command() ctrl.blocks = 0; // Execution Phase - try { - Execute(); - } - catch (lun_exception& e) { - LOGINFO("%s Invalid LUN %d for ID %d", __PRETTY_FUNCTION__, e.getlun(), GetSCSIID()); - - Error(ERROR_CODES::sense_key::ILLEGAL_REQUEST, ERROR_CODES::asc::INVALID_LUN); - } + Execute(); } } @@ -397,18 +389,6 @@ void SASIDEV::Execute() ctrl.blocks = 1; ctrl.execstart = SysTimer::GetTimerLow(); - // Discard pending sense data from the previous command if the current command is not REQUEST SENSE - if ((SASIDEV::scsi_command)ctrl.cmd[0] != eCmdRequestSense) { - ctrl.status = 0; - } - - ctrl.device = NULL; - - // REQUEST SENSE requires a special LUN handling - if (ctrl.cmd[0] != eCmdRequestSense) { - ctrl.device = ctrl.unit[GetLun()]; - } - // Process by command // TODO This code does not belong here. Each device type needs such a dispatcher, which the controller has to call. switch ((SASIDEV::scsi_command)ctrl.cmd[0]) { @@ -755,21 +735,14 @@ void SASIDEV::CmdRequestSense() { LOGTRACE( "%s REQUEST SENSE Command ", __PRETTY_FUNCTION__); - DWORD lun; - try { - lun = GetLun(); - } - catch(const lun_exception& e) { - // Note: According to the SCSI specs the LUN handling for REQUEST SENSE is special. - // Non-existing LUNs do *not* result in CHECK CONDITION. - // Only the Sense Key and ASC are set in order to signal the non-existing LUN. - - // LUN 0 can be assumed to be present (required to call RequestSense() below) - lun = 0; - - Error(ERROR_CODES::sense_key::ILLEGAL_REQUEST, ERROR_CODES::asc::INVALID_LUN); - } + // Logical Unit + DWORD lun = (ctrl.cmd[1] >> 5) & 0x07; + if (!ctrl.unit[lun]) { + Error(); + return; + } + // Command processing on drive ctrl.length = ctrl.unit[lun]->RequestSense(ctrl.cmd, ctrl.buffer); ASSERT(ctrl.length > 0); @@ -1530,18 +1503,3 @@ void SASIDEV::GetPhaseStr(char *str) } } #endif - -//--------------------------------------------------------------------------- -// -// Validate and get LUN -// -//--------------------------------------------------------------------------- -DWORD SASIDEV::GetLun() -{ - DWORD lun = (ctrl.cmd[1] >> 5) & 0x07; - if (!ctrl.unit[lun]) { - throw lun_exception(lun); - } - - return lun; -} diff --git a/src/raspberrypi/controllers/sasidev_ctrl.h b/src/raspberrypi/controllers/sasidev_ctrl.h index c05a5548..718d7273 100644 --- a/src/raspberrypi/controllers/sasidev_ctrl.h +++ b/src/raspberrypi/controllers/sasidev_ctrl.h @@ -220,8 +220,6 @@ protected: // Special operations void FlushUnit(); // Flush the logical unit - DWORD GetLun(); // Get the validated LUN - protected: ctrl_t ctrl; // Internal data }; diff --git a/src/raspberrypi/controllers/scsidev_ctrl.cpp b/src/raspberrypi/controllers/scsidev_ctrl.cpp index 664b0eac..f4b7c6be 100644 --- a/src/raspberrypi/controllers/scsidev_ctrl.cpp +++ b/src/raspberrypi/controllers/scsidev_ctrl.cpp @@ -1081,6 +1081,21 @@ BOOL SCSIDEV::XferMsg(DWORD msg) return TRUE; } +//--------------------------------------------------------------------------- +// +// Validate and get LUN +// +//--------------------------------------------------------------------------- +DWORD SCSIDEV::GetLun() const +{ + DWORD lun = (ctrl.cmd[1] >> 5) & 0x07; + if (!ctrl.unit[lun]) { + throw lun_exception(lun); + } + + return lun; +} + //--------------------------------------------------------------------------- // // Get start sector and sector count for a READ/WRITE(10/16) operation diff --git a/src/raspberrypi/controllers/scsidev_ctrl.h b/src/raspberrypi/controllers/scsidev_ctrl.h index 8bed31e9..37def3ed 100644 --- a/src/raspberrypi/controllers/scsidev_ctrl.h +++ b/src/raspberrypi/controllers/scsidev_ctrl.h @@ -103,6 +103,7 @@ private: void Receive(); // Receive data BOOL XferMsg(DWORD msg); // Data transfer message + DWORD GetLun() const; bool GetStartAndCount(uint64_t&, uint32_t&, bool); scsi_t scsi; // Internal data