LSI53C895A, IDE HDD detection under SCO OpenServer 5.0.5
Hey guys,
Well I've made some progress with getting the LSI53C895A emulated card working under Openserver. After going through the debug log and scratching my head for quite some time. I found the following:
The problem was with this block move:
lsi_scsi: SCRIPTS dsp=0fae8e50 opcode 01000028 arg 00f63c40lsi_scsi: DMA addr=0x00f63c40 len=36
The number of bytes to be transferred (len) should be 40 which corresponds to the block transfer of length 0x28 (from opcode 01000028). Instead we have a length of 36 (0x24). The code responsible for this is (in 'lsi_do_dma'):
if (count > s->current_dma_len)
count = s->current_dma_len;
Basically we're overwriting the length 40 with the value 36 which I think we just left over in that variable from an earlier transfer. In my patch below I initialize s->current_dma_len to s->dbc before we begin the DMA transfer during Data In phase.
The attached patch gets Openserver 5.0.5 past the hardware detection (and it lists the hard drive to boot, woohoo). It appears to stop a little while later (doesn't seem SCSI related), but it's been so long since I've booted Openserver I'm not sure what's supposted to happen after the HW detection using the boot/root disks.
Give it a shot. Hopefully it doesn't break other OS's, but I haven't checked myself. If what I did makes sense and doesn't break anything I'd like to see it get merged into mainline.
Props go to Craig for the initial post and the code that he posted some of which is in this patch.
lsi53c895a.c renamed from lsi53c895a.c.orig +22 -2
@@ -209,6 +209,7 @@uint8_t mbox0;uint8_t mbox1;uint8_t dfifo; +uint8_t ctest2;uint8_t ctest3;uint8_t ctest4;uint8_t ctest5;
@@ -280,6 +281,7 @@ s->mbox0 =0 ; s->mbox1 =0 ; s->dfifo =0 ; + s->ctest2 =0 ; s->ctest3 =0 ; s->ctest4 =0 ; s->ctest5 =0 ;
@@ -890,6 +892,7 @@break ;case PHASE_DI : s->waiting =2 ; + s->current_dma_len = s->dbc;lsi_do_dma (s,0 );if (s->waiting) s->waiting =3 ;
@@ -1279,7 +1282,7 @@case 0x19 :/* CTEST1 */ return 0 ;case 0x1a :/* CTEST2 */ - tmp =LSI_CTEST2_DACK |LSI_CTEST2_CM ; + tmp = s->ctest2 |LSI_CTEST2_DACK |LSI_CTEST2_CM ;if (s->istat0 &LSI_ISTAT0_SIGP ) { s->istat0 &= ~LSI_ISTAT0_SIGP ; tmp |=LSI_CTEST2_SIGP ;
@@ -1327,6 +1330,8 @@ s->sist1 =0 ;lsi_update_irq (s);return tmp; +case 0x46 :/* MACNTL */ +return 0x0f ;case 0x47 :/* GPCNTL0 */ return 0x0f ;case 0x48 :/* STIME0 */
@@ -1440,6 +1445,9 @@SCRIPTS register move instructions are. */ s->sfbr = val;break ; +case 0x0a :case 0x0b : +/* Openserver writes to these readonly registers on startup */ +return ;case 0x0c :case 0x0d :case 0x0e :case 0x0f :/* Linux writes to these readonly registers on startup. */ return ;
@@ -1469,6 +1477,9 @@case 0x17 :/* MBOX1 */ s->mbox1 = val;break ; +case 0x1a :/* CTEST2 */ + s->ctest2 = val &LSI_CTEST2_PCICIE ; +break ;case 0x1b :/* CTEST3 */ s->ctest3 = val &0x0f ;break ;
@@ -1869,12 +1880,21 @@return NULL ; } +/* PCI Vendor ID (word) */ s->pci_dev.config[0x00 ] =0x00 ; s->pci_dev.config[0x01 ] =0x10 ; +/* PCI device ID (word) */ s->pci_dev.config[0x02 ] =0x12 ; s->pci_dev.config[0x03 ] =0x00 ; +/* PCI base class code */ s->pci_dev.config[0x0b ] =0x01 ; - s->pci_dev.config[0x3d ] =0x01 ;/* interrupt pin 1 */ +/* PCI subsystem ID */ + s->pci_dev.config[0x2e ] =0x00 ; + s->pci_dev.config[0x2f ] =0x10 ; +/* PCI latency timer = 255 */ + s->pci_dev.config[0x0d ] =0xff ; +/* Interrupt pin 1 */ + s->pci_dev.config[0x3d ] =0x01 ; s->mmio_io_addr =cpu_register_io_memory (0 , lsi_mmio_readfn, lsi_mmio_writefn, s);
Quoted 6 lines · Justin Chevrier
Well I've made some progress with getting the LSI53C895A emulated card working under Openserver. After going through the debug log and scratching my head for quite some time. I found the following:
The problem was with this block move:
lsi_scsi: SCRIPTS dsp=0fae8e50 opcode 01000028 arg00f63c40lsi_scsi: DMA addr=0x00f63c40 len=36
Brilliant. I was just gearing up to start tracing the SCRIPTS stuff and figuring out how/where it was going wrong. I'm so very glad you decided to take a look at it, especially since I'm not sure I would've spotted that issue at all.
Quoted 5 lines
The attached patch gets Openserver 5.0.5 past the hardware detection (and it lists the hard drive to boot, woohoo). It appears to stop a little while later (doesn't seem SCSI related), but it's been so long since I've booted Openserver I'm not sure what's supposted to happen after the HW detection using the boot/root disks.
I'll try your changes and test from there. I have an image of an existing, working OpenServer install that I can try to boot by using "link=slha" on the boot command line and see how I go, and there's the install CD to test with as well.
--
Craig Ringer
Quoted 8 lines · Craig Ringer
Quoted 5 lines · Justin Chevrier
The attached patch gets Openserver 5.0.5 past the hardware detection (and it lists the hard drive to boot, woohoo). It appears to stop a little while later (doesn't seem SCSI related), but it's been so long since I've booted Openserver I'm not sure what's supposted to happen after the HW detection using the boot/root disks.
Quoted 4 lines
I'll try your changes and test from there. I have an image of an existing, working OpenServer install that I can try to boot by using "link=slha" on the boot command line and see how I go, and there's the install CD to test with as well.
OK, initial results:
With OpenServer 5.0.5 and slha driver version 4.11.00 (as a BTLD), the controller is not probed (beyond some poking into its PCI config space) unless the PCI latency on the device is set to non-zero, so I need to reapply the latency change to the default PCI config that was in my original patch.
The driver also accesses register 0x46, so I need to implement the register read for that (it just returns 0x0f, which seems like how the hardware should always respond in this case according to the docs). This looks like a pretty simple, safe and sensible change.
It looks like the OS & driver version I'm using must behave very differently to the one Justin Chevrier is working with, since he was able to get it to boot with only the changes he posted whereas OpenServer 5.0.5 with slha 4.11.00 won't even touch the controller registers until the PCI latency is changed.
Anyway, once I add support for reading register 0x46 it fails shortly after because it tries to write to register 0x1a (which is read only except for bit 3, PCICIE). If I ignore any writes that don't attempt to set bit 3, which is always reported as clear, execution continues for quite some time and it appears to be enumerating LUNs, etc.
After poking at LUNs 0 - 7, doing ... something ...., it returns to accessing LUN 0. At this point it's falling flat deep in some SCRIPTS code. I'm still trying to figure out exactly what is going on at this point, since it seems to be jumping into uninitialized system memory and running garbage at some point, but I haven't been able to trace back to why yet.
Before going completely insane it does things like a LOAD from 0x00000000 into register 0x64 then STOREs that into system memory at 0x0101e080 - I'm not sure if this might serve any purpose or if it's in the early(?) stages of it executing garbage. I suspect the latter.
So, anyway, ... what I'm seeing with OpenServer 5.0.5 and the slha BTLD is very different to what Justin Chevrier is encountering.
Justin, are you able to find out the exact version of OpenServer and the slha driver that you are using? Are you booting from CD (or CD image), or are you booting a copy installed on the hard disk? Are you using a BTLD for the slha driver?
If you're not using the latest slha BTLD from DPT it'd be really helpful if you could give it a go and see how it goes. Just launch qemu with the extra argument "-fda /path/to/btld/floppy/image" and at the boot: prompt enter "defbootstr link=slha" and press enter. If it asks you to replace existing symbols, enter the numbers it suggests; on my 5.0.5 system those are 28 and 2, but if there's an existing slha driver to replace it'll tell you where it's linked into on your image.
--
Craig Ringer
Hi,
2008/11/4 Justin Chevrier <[email protected]>:
Quoted 16 lines
Well I've made some progress with getting the LSI53C895A emulated card working under Openserver. After going through the debug log and scratching my head for quite some time. I found the following:
The problem was with this block move:
lsi_scsi: SCRIPTS dsp=0fae8e50 opcode 01000028 arg00f63c40lsi_scsi: DMA addr=0x00f63c40 len=36The number of bytes to be transferred (len) should be 40 which corresponds to the block transfer of length
0x28(from opcode 01000028). Instead we have a length of 36 (0x24). The code responsible for this is (in 'lsi_do_dma'):if (count >
s->current_dma_len)
count =s->current_dma_len;Basically we're overwriting the length 40 with the value 36 which I think we just left over in that variable from an earlier transfer. In my patch below I initialize
s->current_dma_lentos->dbcbefore we begin the DMA transfer during Data In phase.
Quoted 7 lines
The attached patch gets Openserver 5.0.5 past the hardware detection (and it lists the hard drive to boot, woohoo). It appears to stop a little while later (doesn't seem SCSI related), but it's been so long since I've booted Openserver I'm not sure what's supposted to happen after the HW detection using the boot/root disks.
Give it a shot. Hopefully it doesn't break other OS's, but I haven't checked myself. If what I did makes sense and doesn't break anything I'd like to see it get merged into mainline.
It makes sense and doesn't break x86/Linux for me, if there's no opposing comment for a moment, I'll merge this change.
Cheers
Quoted 2 lines · andrzej zaborowski
It makes sense and doesn't break x86/Linux for me, if there's no opposing comment for a moment, I'll merge this change.
That'd be rather helpful. Thanks.
There's still more to track down, but this clearly makes the virtual controller behave more like the real one in a number of ways.
--
Craig Ringer