Skip to content

Commit

Permalink
Print CDB and data in Trace mode
Browse files Browse the repository at this point in the history
This enhances trace output for scsi_controller to print the CDB and
the following data for send and receive.

Signed-off-by: Klaus Kämpf <kkaempf@gmail.com>
  • Loading branch information
kkaempf committed Apr 1, 2024
1 parent b1a3ffb commit 67b81ba
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion cpp/controllers/scsi_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ void ScsiController::Send()

if (HasValidLength()) {
LogTrace("Sending data, offset: " + to_string(GetOffset()) + ", length: " + to_string(GetLength()));
uint8_t *data = GetBuffer().data() + GetOffset();

// The delay should be taken from the respective LUN, but as there are no Daynaport drivers for
// LUNs other than 0 this work-around works.
Expand All @@ -444,6 +445,16 @@ void ScsiController::Send()
Error(sense_key::aborted_command);
return;
}
else {
if ((GetLength() > 0) && (GetLength() < 512) && (spdlog::get_level() == spdlog::level::trace)) {
stringstream s;
s << "Sent data $" << setfill('0') << hex;
for (uint32_t i = 0; i < GetLength(); i++) {
s << setw(2) << (int)(*data++);
}
LogTrace(s.str());
}
}

UpdateOffsetAndLength();

Expand Down Expand Up @@ -510,14 +521,24 @@ void ScsiController::Receive()

if (HasValidLength()) {
LogTrace("Receiving data, transfer length: " + to_string(GetLength()) + " byte(s)");

uint8_t *data = GetBuffer().data() + GetOffset();
// If not able to receive all, move to status phase
if (uint32_t len = GetBus().ReceiveHandShake(GetBuffer().data() + GetOffset(), GetLength()); len != GetLength()) {
LogError("Not able to receive " + to_string(GetLength()) + " byte(s) of data, only received "
+ to_string(len));
Error(sense_key::aborted_command);
return;
}
else {
if ((GetLength() > 0) && (GetLength() < 512) && (spdlog::get_level() == spdlog::level::trace)) {
stringstream s;
s << "Received data $" << setfill('0') << hex;
for (uint32_t i = 0; i < GetLength(); i++) {
s << setw(2) << (int)(*data++);
}
LogTrace(s.str());
}
}
}

if (IsByteTransfer()) {
Expand Down

0 comments on commit 67b81ba

Please # to comment.