Skip to content

Commit

Permalink
Setting To Ignore Parity For Initiator Mode Data Transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
androda committed Oct 14, 2024
1 parent 1bf6c57 commit 85dc3c4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
26 changes: 21 additions & 5 deletions lib/BlueSCSI_platform_RP2040/scsiHostPhy.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022 Rabbit Hole Computing™
// Copyright (c) 2024 Tech by Androda, LLC

#include "scsiHostPhy.h"
#include "BlueSCSI_platform.h"
Expand All @@ -13,6 +14,7 @@ extern "C" {
}

volatile int g_scsiHostPhyReset;
bool perform_parity_checking = true;

// Release bus and pulse RST signal, initialize PHY to host mode.
void scsiHostPhyReset(void)
Expand Down Expand Up @@ -168,7 +170,7 @@ static inline void scsiHostWriteOneByte(uint8_t value)
}

// Read one byte from SCSI target using the handshake mechanism.
static inline uint8_t scsiHostReadOneByte(int* parityError)
static inline uint8_t scsiHostReadOneByte(int* parityError, uint32_t *parityResult)
{
SCSIHOST_WAIT_ACTIVE(REQ);
uint16_t r = SCSI_IN_DATA();
Expand All @@ -178,8 +180,8 @@ static inline uint8_t scsiHostReadOneByte(int* parityError)

if (parityError && r != (g_scsi_parity_lookup[r & 0xFF] ^ SCSI_IO_DATA_MASK))
{
log("Parity error in scsiReadOneByte(): ", (uint32_t)r);
*parityError = 1;
*parityResult = (uint32_t)r;
}

return (uint8_t)r;
Expand Down Expand Up @@ -213,6 +215,7 @@ uint32_t scsiHostWrite(const uint8_t *data, uint32_t count)
uint32_t scsiHostRead(uint8_t *data, uint32_t count)
{
int parityError = 0;
uint32_t parityResult;
uint32_t fullcount = count;

int cd_start = SCSI_IN(CD);
Expand All @@ -221,7 +224,12 @@ uint32_t scsiHostRead(uint8_t *data, uint32_t count)
if ((count & 1) == 0 && ((uint32_t)data & 1) == 0)
{
// Even number of bytes, use accelerated routine
count = scsi_accel_host_read(data, count, &parityError, &g_scsiHostPhyReset);
count = scsi_accel_host_read(data, count, &parityError, &parityResult, &g_scsiHostPhyReset);
if (parityError && perform_parity_checking) {
log("Parity error in scsi_accel_host_read(): ", parityResult);
} else {
parityError = 0;
}
}
else
{
Expand All @@ -235,8 +243,12 @@ uint32_t scsiHostRead(uint8_t *data, uint32_t count)
count = i;
}
}

data[i] = scsiHostReadOneByte(&parityError);
data[i] = scsiHostReadOneByte(&parityError, &parityResult);
if (parityError && perform_parity_checking) {
log("Parity error in scsiReadOneByte(): ", parityResult);
} else {
parityError = 0;
}
}
}

Expand Down Expand Up @@ -264,3 +276,7 @@ void scsiHostPhyRelease()
SCSI_RELEASE_OUTPUTS();
SCSI_RELEASE_DATA_REQ();
}

void setInitiatorModeParityCheck(bool checkParity) {
perform_parity_checking = checkParity;
}
2 changes: 2 additions & 0 deletions lib/BlueSCSI_platform_RP2040/scsiHostPhy.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ uint32_t scsiHostRead(uint8_t *data, uint32_t count);

// Release all bus signals
void scsiHostPhyRelease();

void setInitiatorModeParityCheck(bool checkParity);
5 changes: 3 additions & 2 deletions lib/BlueSCSI_platform_RP2040/scsi_accel_host.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Accelerated SCSI subroutines for SCSI initiator/host side communication
// Copyright (c) 2022 Rabbit Hole Computing™
// Copyright (c) 2024 Tech by Androda, LLC

#include "scsi_accel_host.h"
#include "BlueSCSI_platform.h"
Expand Down Expand Up @@ -65,7 +66,7 @@ static void scsi_accel_host_config_gpio()
}
}

uint32_t scsi_accel_host_read(uint8_t *buf, uint32_t count, int *parityError, volatile int *resetFlag)
uint32_t scsi_accel_host_read(uint8_t *buf, uint32_t count, int *parityError, uint32_t *parityResult, volatile int *resetFlag)
{
// Currently this method just reads from the PIO RX fifo directly in software loop.
// The SD card access is parallelized using DMA, so there is limited benefit from using DMA here.
Expand Down Expand Up @@ -117,8 +118,8 @@ uint32_t scsi_accel_host_read(uint8_t *buf, uint32_t count, int *parityError, vo
uint8_t byte1 = ~(paritycheck >> 16);
if (paritycheck != ((g_scsi_parity_lookup[byte1] << 16) | g_scsi_parity_lookup[byte0]))
{
log("Parity error in scsi_accel_host_read(): ", paritycheck);
*parityError = 1;
*parityResult = paritycheck;
}

g_scsi_host_state = SCSIHOST_IDLE;
Expand Down
2 changes: 1 addition & 1 deletion lib/BlueSCSI_platform_RP2040/scsi_accel_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ void scsi_accel_host_init();

// Read data from SCSI bus.
// Number of bytes to read must be divisible by two.
uint32_t scsi_accel_host_read(uint8_t *buf, uint32_t count, int *parityError, volatile int *resetFlag);
uint32_t scsi_accel_host_read(uint8_t *buf, uint32_t count, int *parityError, uint32_t *parityResult, volatile int *resetFlag);
5 changes: 5 additions & 0 deletions src/BlueSCSI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,11 @@ extern "C" void bluescsi_setup(void)
if (ini_getbool("SCSI", "InitiatorMode", false, CONFIGFILE))
{
platform_enable_initiator_mode();
if (! ini_getbool("SCSI", "InitiatorParity", true, CONFIGFILE))
{
log("Initiator Mode Skipping Parity Check.");
setInitiatorModeParityCheck(false);
}
}
if (SD.clusterCount() == 0)
{
Expand Down

0 comments on commit 85dc3c4

Please sign in to comment.