Skip to content

Commit

Permalink
Re-added bpi code fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Nov 22, 2023
1 parent fa2fd4d commit a9289a6
Show file tree
Hide file tree
Showing 33 changed files with 1,910 additions and 3,336 deletions.
31 changes: 9 additions & 22 deletions cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ SCSICTL = scsictl
SCSIDUMP = scsidump
SCSIMON = scsimon
PISCSI_TEST = piscsi_test
SCSILOOP = scsiloop

SYSTEMD_CONF = /etc/systemd/system/piscsi.service
RSYSLOG_CONF = /etc/rsyslog.d/piscsi.conf
Expand All @@ -66,8 +65,7 @@ BINDIR := bin
BIN_ALL = \
$(BINDIR)/$(PISCSI) \
$(BINDIR)/$(SCSICTL) \
$(BINDIR)/$(SCSIMON) \
$(BINDIR)/$(SCSILOOP)
$(BINDIR)/$(SCSIMON)

# scsidump requires initiator support
ifeq ($(CONNECT_TYPE), FULLSPEC)
Expand Down Expand Up @@ -108,14 +106,10 @@ SRC_SCSIDUMP += $(shell find ./hal -name '*.cpp')
SRC_PISCSI_TEST = $(shell find ./test -name '*.cpp')
SRC_PISCSI_TEST += $(shell find ./scsidump -name '*.cpp' | grep -v scsidump.cpp)

SRC_SCSILOOP = scsiloop/scsiloop.cpp
SRC_SCSILOOP += $(shell find ./scsiloop -name '*.cpp' | grep -v scsiloop.cpp)
SRC_SCSILOOP += $(shell find ./hal -name '*.cpp')

vpath %.h ./shared ./controllers ./devices ./scsimon ./hal \
./hal/pi_defs ./piscsi ./scsictl ./scsidump ./scsiloop
./hal/pi_defs ./piscsi ./scsictl ./scsidump
vpath %.cpp ./shared ./controllers ./devices ./scsimon ./hal \
./hal/pi_defs ./piscsi ./scsictl ./scsidump ./scsiloop ./test
./hal/pi_defs ./piscsi ./scsictl ./scsidump ./test
vpath %.o ./$(OBJDIR)
vpath ./$(BINDIR)

Expand All @@ -127,23 +121,20 @@ OBJ_SCSICTL := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SCSICTL:%.cpp=%.o)))
OBJ_SCSIDUMP := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SCSIDUMP:%.cpp=%.o)))
OBJ_SCSIMON := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SCSIMON:%.cpp=%.o)))
OBJ_PISCSI_TEST := $(addprefix $(OBJDIR)/,$(notdir $(SRC_PISCSI_TEST:%.cpp=%.o)))
OBJ_SCSILOOP := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SCSILOOP:%.cpp=%.o)))
OBJ_SHARED := $(addprefix $(OBJDIR)/,$(notdir $(SRC_SHARED:%.cpp=%.o)))
OBJ_PROTOBUF := $(addprefix $(OBJDIR)/,$(notdir $(SRC_PROTOBUF:%.cpp=%.o)))
OBJ_GENERATED := $(addprefix $(OBJDIR)/,$(notdir $(SRC_GENERATED:%.cpp=%.o)))

BINARIES = $(USR_LOCAL_BIN)/$(SCSICTL) \
$(USR_LOCAL_BIN)/$(PISCSI) \
$(USR_LOCAL_BIN)/$(SCSIMON) \
$(USR_LOCAL_BIN)/$(SCSILOOP)
$(USR_LOCAL_BIN)/$(SCSIMON)
ifeq ($(CONNECT_TYPE), FULLSPEC)
BINARIES += $(USR_LOCAL_BIN)/$(SCSIDUMP)
endif

MAN_PAGES = $(MAN_PAGE_DIR)/piscsi.1 \
$(MAN_PAGE_DIR)/scsictl.1 \
$(MAN_PAGE_DIR)/scsimon.1 \
$(MAN_PAGE_DIR)/scsiloop.1
$(MAN_PAGE_DIR)/scsimon.1
ifeq ($(CONNECT_TYPE), FULLSPEC)
MAN_PAGES += $(MAN_PAGE_DIR)/scsidump.1
endif
Expand All @@ -157,7 +148,7 @@ TEST_WRAPS = -Wl,--wrap=fopen64

# The following will include all of the auto-generated dependency files (*.d)
# if they exist. This will trigger a rebuild of a source file if a header changes
ALL_DEPS := $(patsubst %.o,%.d,$(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI) $(OBJ_SCSICTL) $(OBJ_SCSIDUMP) $(OBJ_SCSIMON) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_PISCSI_TEST) $(OBJ_SCSILOOP))
ALL_DEPS := $(patsubst %.o,%.d,$(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI) $(OBJ_SCSICTL) $(OBJ_SCSIDUMP) $(OBJ_SCSIMON) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_PISCSI_TEST))
-include $(ALL_DEPS)

$(OBJDIR) $(BINDIR):
Expand Down Expand Up @@ -188,7 +179,7 @@ $(OBJ_GENERATED) : $(SRC_GENERATED) | $(OBJDIR)
.DEFAULT_GOAL := all
.PHONY: all docs test coverage lcov

all: $(SRC_GENERATED) $(BIN_ALL) docs
all: $(SRC_GENERATED) $(PISCSI)

test: $(SRC_GENERATED) $(BINDIR)/$(PISCSI_TEST)
$(BINDIR)/$(PISCSI_TEST)
Expand All @@ -201,7 +192,7 @@ lcov: test
lcov -q -c -d . --include '*/cpp/*' -o $(COVERAGE_FILE) --exclude '*/test/*' --exclude '*/interfaces/*' --exclude '*/piscsi_interface.pb*'
genhtml -q -o $(COVERAGE_DIR) --legend $(COVERAGE_FILE)

docs: $(DOC_DIR)/piscsi_man_page.txt $(DOC_DIR)/scsictl_man_page.txt $(DOC_DIR)/scsimon_man_page.txt $(DOC_DIR)/scsidump_man_page.txt $(DOC_DIR)/scsiloop_man_page.txt
docs: $(DOC_DIR)/piscsi_man_page.txt $(DOC_DIR)/scsictl_man_page.txt $(DOC_DIR)/scsimon_man_page.txt $(DOC_DIR)/scsidump_man_page.txt

$(SRC_PISCSI_CORE) $(SRC_SCSICTL_CORE) : $(OBJ_GENERATED)

Expand All @@ -217,20 +208,16 @@ $(BINDIR)/$(SCSIDUMP): $(OBJ_SCSIDUMP) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENER
$(BINDIR)/$(SCSIMON): $(OBJ_SCSIMON) $(OBJ_SHARED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_SCSIMON) $(OBJ_SHARED)

$(BINDIR)/$(SCSILOOP): $(OBJ_SHARED) $(OBJ_SCSILOOP) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_SHARED) $(OBJ_SCSILOOP)

$(BINDIR)/$(PISCSI_TEST): $(OBJ_GENERATED) $(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI_TEST) $(OBJ_SCSICTL_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(TEST_WRAPS) -o $@ $(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lpcap -lprotobuf -lgmock -lgtest

# Phony rules for building individual utilities
.PHONY: $(PISCSI) $(SCSICTL) $(SCSIDUMP) $(SCSIMON) $(PISCSI_TEST) $(SCSILOOP)
.PHONY: $(PISCSI) $(SCSICTL) $(SCSIDUMP) $(SCSIMON) $(PISCSI_TEST)
$(PISCSI) : $(BINDIR)/$(PISCSI)
$(SCSICTL) : $(BINDIR)/$(SCSICTL)
$(SCSIDUMP) : $(BINDIR)/$(SCSIDUMP)
$(SCSIMON) : $(BINDIR)/$(SCSIMON)
$(PISCSI_TEST): $(BINDIR)/$(PISCSI_TEST)
$(SCSILOOP) : $(BINDIR)/$(SCSILOOP)

## clean : Remove all of the object files, intermediate
## compiler files and executable files
Expand Down
29 changes: 0 additions & 29 deletions cpp/controllers/scsi_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include "shared/piscsi_exceptions.h"
#include "hal/gpiobus.h"
#include "hal/systimer.h"
#include "devices/scsi_host_bridge.h"
#include "devices/scsi_daynaport.h"
#include "devices/mode_page_device.h"
Expand All @@ -33,7 +32,6 @@ void ScsiController::Reset()
{
AbstractController::Reset();

execstart = 0;
identified_lun = -1;
initiator_id = UNKNOWN_INITIATOR_ID;

Expand Down Expand Up @@ -177,7 +175,6 @@ void ScsiController::Execute()
// Initialization for data transfer
ResetOffset();
SetBlocks(1);
execstart = SysTimer::GetTimerLow();

// Discard pending sense data from the previous command if the current command is not REQUEST SENSE
if (GetOpcode() != scsi_command::eCmdRequestSense) {
Expand Down Expand Up @@ -231,14 +228,6 @@ void ScsiController::Execute()
void ScsiController::Status()
{
if (!IsStatus()) {
// Minimum execution time
// TODO Why is a delay needed? Is this covered by the SCSI specification?
if (execstart > 0) {
Sleep();
} else {
SysTimer::SleepUsec(5);
}

stringstream s;
s << "Status phase, status is $" << setfill('0') << setw(2) << hex << static_cast<int>(GetStatus());
LogTrace(s.str());
Expand Down Expand Up @@ -309,11 +298,6 @@ void ScsiController::MsgOut()
void ScsiController::DataIn()
{
if (!IsDataIn()) {
// Minimum execution time
if (execstart > 0) {
Sleep();
}

// If the length is 0, go to the status phase
if (!HasValidLength()) {
Status();
Expand All @@ -338,11 +322,6 @@ void ScsiController::DataIn()
void ScsiController::DataOut()
{
if (!IsDataOut()) {
// Minimum execution time
if (execstart > 0) {
Sleep();
}

// If the length is 0, go to the status phase
if (!HasValidLength()) {
Status();
Expand Down Expand Up @@ -968,11 +947,3 @@ int ScsiController::GetEffectiveLun() const
// Return LUN from IDENTIFY message, or return the LUN from the CDB as fallback
return identified_lun != -1 ? identified_lun : GetLun();
}

void ScsiController::Sleep()
{
if (const uint32_t time = SysTimer::GetTimerLow() - execstart; time < MIN_EXEC_TIME) {
SysTimer::SleepUsec(MIN_EXEC_TIME - time);
}
execstart = 0;
}
6 changes: 0 additions & 6 deletions cpp/controllers/scsi_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ class ScsiController : public AbstractController

private:

// Execution start time
uint32_t execstart = 0;

// The initiator ID may be unavailable, e.g. with Atari ACSI and old host adapters
int initiator_id = UNKNOWN_INITIATOR_ID;

Expand All @@ -95,15 +92,12 @@ class ScsiController : public AbstractController
void DataOutNonBlockOriented() const;
void Receive();

// TODO Make non-virtual as soon as SysTimer calls do not segfault anymore on a regular PC, e.g. by using ifdef __arm__.
virtual void Execute();

void ProcessCommand();
void ParseMessage();
void ProcessMessage();

void Sleep();

scsi_t scsi = {};
};

31 changes: 31 additions & 0 deletions cpp/hal/connection_type/connection_aibom.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#pragma once

#include "hal/pi_defs/bpi-m2p.h"
#include <string>

//
Expand Down Expand Up @@ -54,3 +55,33 @@ const static int PIN_CD = 11; // CD
const static int PIN_IO = 23; // IO
const static int PIN_BSY = 24; // BSY
const static int PIN_SEL = 8; // SEL

// Warning: The Allwinner/Banana Pi GPIO numbers DO NOT correspond to
// the Raspberry Pi GPIO numbers.
// For example, Pin 7 is GPIO4 on a Raspberry Pi. Its GPIO 6 on a Banana Pi
// For Banana Pi, the pins are specified by physical pin number, NOT GPIO number
// (The Macro's convert the pin number to logical BPi GPIO number)
const static int BPI_PIN_ACT = BPI_M2P_07; // ACTIVE
const static int BPI_PIN_ENB = BPI_M2P_11; // ENABLE
const static int BPI_PIN_IND = BPI_M2P_13; // INITIATOR CTRL DIRECTION
const static int BPI_PIN_TAD = -1; // TARGET CTRL DIRECTION
const static int BPI_PIN_DTD = BPI_M2P_12; // DATA DIRECTION

const static int BPI_PIN_DT0 = BPI_M2P_31; // Data 0
const static int BPI_PIN_DT1 = BPI_M2P_32; // Data 1
const static int BPI_PIN_DT2 = BPI_M2P_33; // Data 2
const static int BPI_PIN_DT3 = BPI_M2P_36; // Data 3
const static int BPI_PIN_DT4 = BPI_M2P_35; // Data 4
const static int BPI_PIN_DT5 = BPI_M2P_38; // Data 5
const static int BPI_PIN_DT6 = BPI_M2P_37; // Data 6
const static int BPI_PIN_DT7 = BPI_M2P_40; // Data 7
const static int BPI_PIN_DP = BPI_M2P_29; // Data parity
const static int BPI_PIN_ATN = BPI_M2P_15; // ATN
const static int BPI_PIN_RST = BPI_M2P_22; // RST
const static int BPI_PIN_ACK = BPI_M2P_19; // ACK
const static int BPI_PIN_REQ = BPI_M2P_26; // REQ
const static int BPI_PIN_MSG = BPI_M2P_21; // MSG
const static int BPI_PIN_CD = BPI_M2P_23; // CD
const static int BPI_PIN_IO = BPI_M2P_16; // IO
const static int BPI_PIN_BSY = BPI_M2P_18; // BSY
const static int BPI_PIN_SEL = BPI_M2P_24; // SEL
31 changes: 31 additions & 0 deletions cpp/hal/connection_type/connection_fullspec.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#pragma once

#include "hal/pi_defs/bpi-m2p.h"
#include <string>

//
Expand Down Expand Up @@ -54,3 +55,33 @@ const static int PIN_CD = 24; // CD
const static int PIN_IO = 25; // IO
const static int PIN_BSY = 26; // BSY
const static int PIN_SEL = 27; // SEL

// Warning: The Allwinner/Banana Pi GPIO numbers DO NOT correspond to
// the Raspberry Pi GPIO numbers.
// For example, Pin 7 is GPIO4 on a Raspberry Pi. Its GPIO 6 on a Banana Pi
// For Banana Pi, the pins are specified by physical pin number, NOT GPIO number
// (The Macro's convert the pin number to logical BPi GPIO number)
const static int BPI_PIN_ACT = BPI_M2P_07; // ACTIVE
const static int BPI_PIN_ENB = BPI_M2P_29; // ENABLE
const static int BPI_PIN_IND = BPI_M2P_31; // INITIATOR CTRL DIRECTION
const static int BPI_PIN_TAD = BPI_M2P_26; // TARGET CTRL DIRECTION
const static int BPI_PIN_DTD = BPI_M2P_24; // DATA DIRECTION

const static int BPI_PIN_DT0 = BPI_M2P_19; // Data 0
const static int BPI_PIN_DT1 = BPI_M2P_23; // Data 1
const static int BPI_PIN_DT2 = BPI_M2P_32; // Data 2
const static int BPI_PIN_DT3 = BPI_M2P_33; // Data 3
const static int BPI_PIN_DT4 = BPI_M2P_08; // Data 4
const static int BPI_PIN_DT5 = BPI_M2P_10; // Data 5
const static int BPI_PIN_DT6 = BPI_M2P_36; // Data 6
const static int BPI_PIN_DT7 = BPI_M2P_11; // Data 7
const static int BPI_PIN_DP = BPI_M2P_12; // Data parity
const static int BPI_PIN_ATN = BPI_M2P_35; // ATN
const static int BPI_PIN_RST = BPI_M2P_38; // RST
const static int BPI_PIN_ACK = BPI_M2P_40; // ACK
const static int BPI_PIN_REQ = BPI_M2P_15; // REQ
const static int BPI_PIN_MSG = BPI_M2P_16; // MSG
const static int BPI_PIN_CD = BPI_M2P_18; // CD
const static int BPI_PIN_IO = BPI_M2P_22; // IO
const static int BPI_PIN_BSY = BPI_M2P_37; // BSY
const static int BPI_PIN_SEL = BPI_M2P_13; // SEL
31 changes: 31 additions & 0 deletions cpp/hal/connection_type/connection_gamernium.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#pragma once

#include "hal/pi_defs/bpi-m2p.h"
#include <string>

//
Expand Down Expand Up @@ -54,3 +55,33 @@ const static int PIN_CD = 18; // CD
const static int PIN_IO = 4; // IO
const static int PIN_BSY = 27; // BSY
const static int PIN_SEL = 23; // SEL

// Warning: The Allwinner/Banana Pi GPIO numbers DO NOT correspond to
// the Raspberry Pi GPIO numbers.
// For example, Pin 7 is GPIO4 on a Raspberry Pi. Its GPIO 6 on a Banana Pi
// For Banana Pi, the pins are specified by physical pin number, NOT GPIO number
// (The Macro's convert the pin number to logical BPi GPIO number)
const static int BPI_PIN_ACT = BPI_M2P_08; // ACTIVE
const static int BPI_PIN_ENB = BPI_M2P_31; // ENABLE
const static int BPI_PIN_IND = BPI_M2P_04; // INITIATOR CTRL DIRECTION
const static int BPI_PIN_TAD = BPI_M2P_24; // TARGET CTRL DIRECTION
const static int BPI_PIN_DTD = BPI_M2P_29; // DATA DIRECTION

const static int BPI_PIN_DT0 = BPI_M2P_40; // Data 0
const static int BPI_PIN_DT1 = BPI_M2P_37; // Data 1
const static int BPI_PIN_DT2 = BPI_M2P_38; // Data 2
const static int BPI_PIN_DT3 = BPI_M2P_35; // Data 3
const static int BPI_PIN_DT4 = BPI_M2P_36; // Data 4
const static int BPI_PIN_DT5 = BPI_M2P_33; // Data 5
const static int BPI_PIN_DT6 = BPI_M2P_32; // Data 6
const static int BPI_PIN_DT7 = BPI_M2P_23; // Data 7
const static int BPI_PIN_DP = BPI_M2P_22; // Data parity
const static int BPI_PIN_ATN = BPI_M2P_19; // ATN
const static int BPI_PIN_RST = BPI_M2P_15; // RST
const static int BPI_PIN_ACK = BPI_M2P_18; // ACK
const static int BPI_PIN_REQ = BPI_M2P_10; // REQ
const static int BPI_PIN_MSG = BPI_M2P_11; // MSG
const static int BPI_PIN_CD = BPI_M2P_12; // CD
const static int BPI_PIN_IO = BPI_M2P_07; // IO
const static int BPI_PIN_BSY = BPI_M2P_13; // BSY
const static int BPI_PIN_SEL = BPI_M2P_16; // SEL
31 changes: 31 additions & 0 deletions cpp/hal/connection_type/connection_standard.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#pragma once

#include "hal/pi_defs/bpi-m2p.h"
#include <string>

//
Expand Down Expand Up @@ -54,3 +55,33 @@ const static int PIN_CD = 24; // CD
const static int PIN_IO = 25; // IO
const static int PIN_BSY = 26; // BSY
const static int PIN_SEL = 27; // SEL

// Warning: The Allwinner/Banana Pi GPIO numbers DO NOT correspond to
// the Raspberry Pi GPIO numbers.
// For example, Pin 7 is GPIO4 on a Raspberry Pi. Its GPIO 6 on a Banana Pi
// For Banana Pi, the pins are specified by physical pin number, NOT GPIO number
// (The Macro's convert the pin number to logical BPi GPIO number)
const static int BPI_PIN_ACT = BPI_M2P_07; // ACTIVE
const static int BPI_PIN_ENB = BPI_M2P_29; // ENABLE
const static int BPI_PIN_IND = -1; // INITIATOR CTRL DIRECTION
const static int BPI_PIN_TAD = -1; // TARGET CTRL DIRECTION
const static int BPI_PIN_DTD = -1; // DATA DIRECTION

const static int BPI_PIN_DT0 = BPI_M2P_19; // Data 0
const static int BPI_PIN_DT1 = BPI_M2P_23; // Data 1
const static int BPI_PIN_DT2 = BPI_M2P_32; // Data 2
const static int BPI_PIN_DT3 = BPI_M2P_33; // Data 3
const static int BPI_PIN_DT4 = BPI_M2P_08; // Data 4
const static int BPI_PIN_DT5 = BPI_M2P_10; // Data 5
const static int BPI_PIN_DT6 = BPI_M2P_36; // Data 6
const static int BPI_PIN_DT7 = BPI_M2P_11; // Data 7
const static int BPI_PIN_DP = BPI_M2P_12; // Data parity
const static int BPI_PIN_ATN = BPI_M2P_35; // ATN
const static int BPI_PIN_RST = BPI_M2P_38; // RST
const static int BPI_PIN_ACK = BPI_M2P_40; // ACK
const static int BPI_PIN_REQ = BPI_M2P_15; // REQ
const static int BPI_PIN_MSG = BPI_M2P_16; // MSG
const static int BPI_PIN_CD = BPI_M2P_18; // CD
const static int BPI_PIN_IO = BPI_M2P_22; // IO
const static int BPI_PIN_BSY = BPI_M2P_37; // BSY
const static int BPI_PIN_SEL = BPI_M2P_13; // SEL
Loading

0 comments on commit a9289a6

Please sign in to comment.