Incompatibility: Yamaha EX5R synth/sampler
Likely one of the more rare use cases, I thought it might be useful to document the findings anyway.
Info
- Which version of Pi are you using: Raspberry Pi 3
- Which github revision of software: November 2021 Release
- Which board version: 2.4
- Which computer is the RaSCSI connected to: Yamaha EX5R synthesizer/sampler
Describe the issue
There is an incompatibility issue with the Yamaha EX5R synth/sampler.
Setup:
- RASCSI is connected through an internal SCSI cable. SCSI2SD works fine with the same cable and connection setup.
- Termination is enabled on the ASIB-1 SCSI expansion module for the synth. This is the setting that has worked correctly with SCSI2SD.
- Termination on the RASCSI is enabled
- One hard disk is configured: 1000MB generic hdd. I have tried as well: named hard drives with sizes from 500mb to 2000mb (max is 2gb according to what I have found). Removable drives don't work as well.
Steps:
- Go to disk
- Go to device format
- Select HD0 via rotary wheel
- Enter->Format disk->yes
Results:
- Device HD0 selected via rotary wheel works fine it seems (updated: I've written about an illegal disk error previously, this was not due to SCSI, but the disconnected floppy drive).
Dec 2 19:19:38 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:38.781] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing TestUnitReady ($00)
Dec 2 19:19:38 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:38.783] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $25
Dec 2 19:19:38 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:38.783] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing ReadCapacity10 ($25)
Dec 2 19:19:38 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:38.784] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $28
Dec 2 19:19:38 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:38.784] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing Read10 ($28)
Dec 2 19:19:38 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:38.784] [debug] virtual void Disk::Read10(SASIDEV*) READ(10) command record=$00000001 blocks=1
Dec 2 19:19:38 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:38.792] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $00
Dec 2 19:19:38 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:38.792] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing TestUnitReady ($00)
Dec 2 19:19:38 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:38.793] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $25
Dec 2 19:19:38 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:38.794] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing ReadCapacity10 ($25)
Dec 2 19:19:38 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:38.796] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $28
Dec 2 19:19:38 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:38.796] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing Read10 ($28)
Dec 2 19:19:38 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:38.796] [debug] virtual void Disk::Read10(SASIDEV*) READ(10) command record=$00000001 blocks=1
Dec 2 19:19:39 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:39.038] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $00
Dec 2 19:19:39 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:39.038] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing TestUnitReady ($00)
Dec 2 19:19:39 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:39.039] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $25
Dec 2 19:19:39 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:39.039] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing ReadCapacity10 ($25)
Dec 2 19:19:39 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:39.041] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $28
Dec 2 19:19:39 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:39.041] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing Read10 ($28)
Dec 2 19:19:39 rascsi-ex5r RASCSI[508]: [2021-12-02 19:19:39.042] [debug] virtual void Disk::Read10(SASIDEV*) READ(10) command record=$00000001 blocks=1
- Trying to format the HD0 disk yields a SCSI error. Trace logs for only the part starting after format->yes attached below.
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.607] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing TestUnitReady ($00)
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.609] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $25
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.609] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing ReadCapacity10 ($25)
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.610] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $28
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.611] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing Read10 ($28)
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.611] [debug] virtual void Disk::Read10(SASIDEV*) READ(10) command record=$00000001 blocks=1
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.731] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $2A
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.731] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing Write10 ($2A)
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.731] [debug] virtual void Disk::Write10(SASIDEV*) WRITE(10) command record=$00000001 blocks=1
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.849] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $2A
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.850] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing Write10 ($2A)
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.850] [debug] virtual void Disk::Write10(SASIDEV*) WRITE(10) command record=$00000100 blocks=1
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.975] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $2A
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.975] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing Write10 ($2A)
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.975] [debug] virtual void Disk::Write10(SASIDEV*) WRITE(10) command record=$00000102 blocks=8
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.985] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $2A
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.985] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing Write10 ($2A)
Dec 2 19:21:01 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:01.985] [debug] virtual void Disk::Write10(SASIDEV*) WRITE(10) command record=$000001FC blocks=8
Dec 2 19:21:02 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:02.114] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $2A
Dec 2 19:21:02 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:02.114] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing Write10 ($2A)
Dec 2 19:21:02 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:02.114] [debug] virtual void Disk::Write10(SASIDEV*) WRITE(10) command record=$0000010A blocks=8
Dec 2 19:21:05 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:05.606] [error] virtual void SCSIDEV::Receive() Not able to receive all data. Going to error
Dec 2 19:21:05 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:05.609] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $03
Dec 2 19:21:05 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:05.609] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing RequestSense ($03)
Dec 2 19:21:05 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:05.611] [debug] ++++ CMD ++++ virtual void SCSIDEV::Execute() Executing command $03
Dec 2 19:21:05 rascsi-ex5r RASCSI[508]: [2021-12-02 19:21:05.611] [debug] virtual bool Disk::Dispatch(SCSIDEV*) Executing RequestSense ($03)
Analysis results (TLD;R)
Exact reasons unknown and whether this is a correct fix, but setting GPIO_DATA_SETTLING to 400ns in gpiobus.h seems to solve the scsi error problem.
@bzeiss Can you please provide trace level logs as well?
Sure, I'm on it already.
Update: formatting scsi trace error attached.
The log effectively says that there is no issue when writing a single sector, but when writing 8 sectors RaSCSI claims that the device does not send enough data. This is not related to formatting (at least not to formatting on SCSI level), but to a regular write access. @bzeiss I added additional logging for a further analysis. Can you please create a log on trace level based on the "issue_504" branch? Only a small part of the log is relevant, namely about 100 lines before and after the log message that says "Going to error"
Absolutely, I'm happy to help any way I can.
trace log cut about +/- 100 lines around "going to error" (I tried to find some start point that looked reasonable):
full trace log:
@bzeiss Looks as if your device is sending only 511 instead of 512 bytes for a sector. At least RaSCSI is only receiving 512 bytes when there should been 512:
Dez 03 00:57:22 rascsi-ex5r RASCSI[526]: [2021-12-03 00:57:22.150] [trace] virtual void SCSIDEV::Receive() length is 512
Dez 03 00:57:26 rascsi-ex5r RASCSI[526]: [2021-12-03 00:57:26.024] [error] virtual void SCSIDEV::Receive() Not able to receive 512 data, only received 511. Going to error
I tend to say that this is not a general issue caused by RaSCSI, because in that case I would expect that RaSCSI not to work at all when writing data. Since you say that with SCSI2SD everything is fine I assume that this is some kind of a hardware-related error, e.g. with the RaSCSI hardware, cables or termination. Can you try your RaSCSI hardware with a different device, e.g. a regular computer?
By the way, with the latest log not even a single sector was transferred completely, whereas with the first log a single sector worked fine. This indicates that these errors are hardware-related, because the behavior is not predictable.
I have three RASCSI devices and lots of Pis to test with. I have my doubts that this is a hardware error, but I will double check nonetheless. Will report back later.
@bzeiss Sounds good. If you can reproduce the problem also with a different hardware combination it is likely that your Yamaha's SCSI signal handling slightly differs from the signal handling of other (working) computer hardware, and that the RaSCSI software (in contrast to SCSI2SD) has issues with this different signal handling, resulting in RaSCSI assuming an early end of the data transfer. In this case it might either be that your Yamaha is worng (regarding the usage of bus signals) or the RaSCSI software is.
So I have tried pi3, pi zero 2s and the three rascsi 2.4 hats in different kinds of combinations and also a different cable. I also went back and created a fresh sd card installation based on buster 32-bit rather than bullseye. The effect is still the same, and the same device format option on the EX5R tends to send different amounts of bytes which I do agree is a weird non-determinsm:
ez 03 11:35:48 raspberrypi RASCSI[470]: [2021-12-03 11:35:48.530] [trace] virtual void SCSIDEV::Receive() length is 512
Dez 03 11:35:51 raspberrypi RASCSI[470]: [2021-12-03 11:35:51.889] [error] virtual void SCSIDEV::Receive() Not able to receive 512 data, only received 510. Going to error
Dez 03 11:35:51 raspberrypi RASCSI[470]: [2021-12-03 11:35:51.889] [trace] virtual void SCSIDEV::Error(ERROR_CODES::sense_key, ERROR_CODES::asc) Error (to status phase)
Those ASIB-1 SCSI modules from Yamaha are known to be really slow (like almost floppy-disk slow) and weird. I think it's quite possible that there are small deviations from the standard SCSI implementation although usually standard MO drives or harddisks did work. I have no knowledge of the SCSI protocol whatsoever, but I do wonder though whether this is maybe some kind of sparse write where the missing bytes have to be filled up with zeros by the receiver or something like RASCSI giving up too quickly waiting for the data for the slow yamaha scsi module (as opposed to old mechanical SCSI hard disks) or something like that. I may know someone who has worked on a SCSI software for the Yamaha A-samplers. Those devices use the same SCSI module. Maybe he knows something about possible quirks of the Yamaha SCSI implementation. I'll try to get in touch with him.
Also I'll try to dump my scsi2sd partition to an image and try whether reading that disk works.
@bzeiss No, there is nothing like a sparse write. All bytes have to be transferred. Also, slow devices don't matter because there is a handshake based on SCSI signals. As long as a transfer does not take too long and a device explicitly reports a timeout (which is not the case here) speed does not matter. All in all from what we know by now there appears to be an issue with the handling of SCSi bus signals, resulting in incomplete transfers. Can you completely recompile RaSCSI after setting the DEBUG environment variable to 1, please? There are some assertions in the RaSCSI code that point out unexpected bus signals.
TL;DR: It started to work once I started writing new images to the sd card using dd or fill them up with shred. No bug in my opinion.
Long story:
Well this is weird: I compiled with the DEBUG flag and before taking a closer look a new logs, I did what I wrote above and copied back an image of my mo drive of the scsi2sd sd card (using dd, blocksize+sector count by looking that up in the scsi2sd xml file). I saved this as .hdr file to the rascsi sd images folder and I could use it just fine, i.e., read the files on it, even save them back and now comes the weird part: even formating that image worked without the problems above.
This caused me to double check whether .hdr files really would not work and I did the following:
- created a new .hdr file through the web interface of size 500mb which could then be formatted fine.
- Created a new 500MB harddisk --> formatting fine.
- Tried formatting the same harddisk image that previsouly failed --> formatting still fails.
- Created a new 1500MB harddisk --> formatting fine.
- Created a new 2000MB harddisk --> formatting fine.
If I hadn't used multiple sd cards during testing, I would think that there is something wrong with the sd card. I found this to be very weird. So I decided to overwrite the non-working image with random data using shred. After that, this bad image could be formatted as well.
So I guess what actually made this work was actually writing the data (or just data?) to the sdcard.
On my second bullseye image, it still doesn't work with shred or dd when creating images. I'm starting to think that the DEBUG environment variable did something.
@bzeiss In debug mode no optimized code is generated. Are you familiar with configuring compiler options? It would be interesting to learn whether this is a GCC optimizer issuue. The regular build optimizes with -O3, the debug build uses -O0. Can you try with -O2 and -O1 by changing the respective options directly in the Makefile before recompiling everything? In debug mode RaSCSI is also slower due to the lack of optimization, which might also have an effect. Are you running a 32 bit or a 64 bit OS, and what's your GCC version?
@rdmark Do you remember the optimizer issue I stumbled upon some months ago? If it turns out that there are also other issues we should consider using -O2 instead of -O3. -O3 is quite unusual, most projects use -O2.
Yes, I can try to modify that directly in the Makefile. I'm currently rebuilding with DEBUG=1 to test it, but I probably won't be able to do further tests until tomorrow.
So, I'm a bit puzzled. These are the results when trying to format the drive on 64bit bullseye, Pi3. Each with multiple tries:
- DEBUG --> works
- -O3 in Makefile CFLAGS and CXXFLAGS --> scsi error
- -O2 in Makefile CFLAGS and CXXFLAGS --> scsi error
- -O1 in Makefile CFLAGS and CXXFLAGS --> scsi error
- -O0 in Makefile CFLAGS and CXXFLAGS --> works
I'll continue to mess a little with the remaining flags.
gcc is gcc 10.2.1. Whether it's 64bit or 32bit doesn't matter as my tests prior to going back to 64bit were on 32bit buster.
@bzeiss So there are issues as soon as optimzed code is generated. Can you try the clang compiler instead of gcc? Just replace the compiler name in the Makefile after installing clang.
I have tried clang-11 and clang++-11 with -O3 and -O2. Still scsi error. Do you think it might be worth playing around with the systimer stuff? I have seen there is a gpio delay built into the receive function somewhere. Depending on how such delays are implemented, I can imagine such "empty" behavior is something where an optimizer might try to optimize too much.
@bzeiss As already mentioned SCSI data transfers use handshakes and should be timing independent. I don't know details on timers being used in the gpio-related code, but any usage of timers may indeed be relevant here. @akuker might be familiar with this code, he can probably comment.
So, I have managed to create the scsi error on -O0 (which previously worked). In gpiobus.cpp, I have commented out the GPIO_DATA_SETTLING sleep in ReceiveHandShake:
// Wait until the signal line stabilizes
// SysTimer::SleepNsec(GPIO_DATA_SETTLING);
after seeing how the wait in SleepNsec takes place:
// Start
DWORD start = armtaddr[ARMT_FREERUN];
// Loop until timer has elapsed
while ((armtaddr[ARMT_FREERUN] - start) < diff);
While not reading the code in detail, it kind of looked like a typical optimization target. Probably not a valid proof for anything, but it might be something. I'll probably try to replace the sleep code with something different tomorrow.
So I made it work with -O3 (essentially, with all the defaults in the Makefile). I started to mess with SleepNsec and thought that the while loop is optimized. So I have added stuff like asm volatile ("nop;"); or so into the while loop which supposedly let's the compiler think that there is code with side effects in there which can't be optimized. It didn't have any positive effect on the problem though. So I'm not sure that loop optimization is really the reason at this point. However, after being puzzled by that, I reverted those changes and started to mess with GPIO_DATA_SETTLING, set it to 200 first which didn't help and then tried out 1000ns which surprisingly worked. I will test this for stability and will try to find the value where it starts to work.
So, I have tried to find a lower GPIO_DATA_SETTLING by going in 50ns steps. 350ns does not work. 400ns does seem work stable after a few brief tests with both a Pi3 and a Pi Zero 2 with formatting, reading and writing typical workloads. It would be interesting to know whether setting this higher has side effects of any sort.