Skip to content

Commit

Permalink
Refactor delay handling
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Nov 29, 2023
1 parent d9cc3dc commit 8159b6f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
9 changes: 4 additions & 5 deletions cpp/base/primary_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ using namespace scsi_defs;

class PrimaryDevice: private ScsiPrimaryCommands, public Device
{
friend class AbstractController;
friend class AbstractController;

using operation = function<void()>;

public:

PrimaryDevice(PbDeviceType type, int lun) : Device(type, lun) {}
PrimaryDevice(PbDeviceType type, int lun, int delay_after_bytes = BUS::SEND_NO_DELAY)
: Device(type, lun), send_delay(delay_after_bytes) { }
~PrimaryDevice() override = default;

virtual bool Init(const param_map&);
Expand Down Expand Up @@ -68,8 +69,6 @@ class PrimaryDevice: private ScsiPrimaryCommands, public Device
virtual vector<uint8_t> InquiryInternal() const = 0;
void CheckReady();

void SetSendDelay(int s) { send_delay = s; }

void Inquiry() override;
void RequestSense() override;

Expand Down Expand Up @@ -107,7 +106,7 @@ class PrimaryDevice: private ScsiPrimaryCommands, public Device

unordered_map<scsi_command, operation> commands;

int send_delay = BUS::SEND_NO_DELAY;
int send_delay;

int reserving_initiator = NOT_RESERVED;
};
6 changes: 2 additions & 4 deletions cpp/devices/daynaport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
using namespace scsi_defs;
using namespace scsi_command_util;

SCSIDaynaPort::SCSIDaynaPort(int lun) : PrimaryDevice(SCDP, lun)
// The MacOS Daynaport driver needs to have a delay after the size/flags field of the read response
SCSIDaynaPort::SCSIDaynaPort(int lun) : PrimaryDevice(SCDP, lun, DAYNAPORT_READ_HEADER_SZ)
{
SupportsParams(true);
}
Expand All @@ -44,9 +45,6 @@ bool SCSIDaynaPort::Init(const param_map& params)
AddCommand(scsi_command::cmd_set_mcast_addr, [this] { SetMcastAddr(); });
AddCommand(scsi_command::cmd_enable_interface, [this] { EnableInterface(); });

// The MacOS Daynaport driver needs to have a delay after the size/flags field of the read response
SetSendDelay(DAYNAPORT_READ_HEADER_SZ);

tap_enabled = tap.Init(GetParams());
if (!tap_enabled) {
// Not terminating on a regular PC is helpful for testing
Expand Down
1 change: 0 additions & 1 deletion cpp/test/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ class MockPrimaryDevice : public PrimaryDevice
FRIEND_TEST(PrimaryDeviceTest, TestUnitReady);
FRIEND_TEST(PrimaryDeviceTest, RequestSense);
FRIEND_TEST(PrimaryDeviceTest, Inquiry);
FRIEND_TEST(PrimaryDeviceTest, GetSetSendDelay);
FRIEND_TEST(ScsiControllerTest, RequestSense);
FRIEND_TEST(S2pExecutorTest, ValidateOperationAgainstDevice);

Expand Down
9 changes: 0 additions & 9 deletions cpp/test/primary_device_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,6 @@ TEST(PrimaryDeviceTest, WriteByteSequence)
EXPECT_FALSE(device->WriteByteSequence({})) << "Primary device does not support writing byte sequences";
}

TEST(PrimaryDeviceTest, GetSetSendDelay)
{
MockPrimaryDevice device(0);

EXPECT_EQ(-1, device.GetSendDelay()) << "Wrong delay default value";
device.SetSendDelay(1234);
EXPECT_EQ(1234, device.GetSendDelay());
}

TEST(PrimaryDeviceTest, Init)
{
param_map params;
Expand Down

0 comments on commit 8159b6f

Please sign in to comment.