scsi & lsi53c895a fixes
cover scsi & lsi53c895a fixes
This series is required to use the lsi53c895a emulation with an old proprietary driver. All changes should move the emulation closer to the spec and the real hardware.
Find the patches also at git://git.kiszka.org/qemu.git queues/scsi
Laszlo Ast (7):
SCSI: Fix Standard INQUIRY data
lsi53c895a: Whitespace and typo fixes
lsi53c895a: Add support for LSI53C700 Family Compatibility bit
lsi53c895a: Fix message code of DISCONNECT
lsi53c895a: Fix SDID in SELECT ID command
lsi53c895a: Use alternative address when already reselected
lsi53c895a: Implement IRQ on reselection
hw/lsi53c895a.c | 66 +++++++++++++++++++++++++++++++++++++++++++++---------- hw/scsi-disk.c | 6 ++-- 2 files changed, 57 insertions(+), 15 deletions(-)
PATCH 1/7 SCSI: Fix Standard INQUIRY data
From: Laszlo Ast <[email protected]>
Vendor identification, product identification and product revision level should be padded with spaces without a terminating NULL character, see SCSI-2 standard, 8.2.5.1 Standard INQUIRY data.
---
hw/scsi-disk.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
hw/scsi-disk.c +3 -3
@@ -593,12 +593,12 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, }else if (bdrv_get_type_hint (s->dinfo->bdrv) ==BDRV_TYPE_CDROM ) { outbuf[0 ] =5 ; outbuf[1 ] =0x80 ; -memcpy (&outbuf[16 ],"QEMU CD-ROM " ,16 ); +memcpy (&outbuf[16 ],"QEMU CD-ROM " ,16 ); }else { outbuf[0 ] =0 ; -memcpy (&outbuf[16 ],"QEMU HARDDISK " ,16 ); +memcpy (&outbuf[16 ],"QEMU HARDDISK " ,16 ); } -memcpy (&outbuf[8 ],"QEMU " ,8 ); +memcpy (&outbuf[8 ],"QEMU " ,8 );memcpy (&outbuf[32 ],QEMU_VERSION ,4 );/* Identify device as SCSI-3 rev 1. Some later commands are also implemented. */
PATCH 2/7 lsi53c895a: Whitespace and typo fixes
In reply to Jan KiszkaFrom: Laszlo Ast <[email protected]>
---
hw/lsi53c895a.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
hw/lsi53c895a.c +5 -5
@@ -10,7 +10,7 @@/* ??? Need to check if the {read,write}[wl] routines work properly on big-endian targets. */ -#include <assert.h> \ +#include <assert.h> #include "hw.h" #include "pci.h"
@@ -183,7 +183,7 @@ typedef struct {int carry;/* ??? Should this be an a visible register somewhere? */ int sense;/* Action to take at the end of a MSG IN phase. -0 = COMMAND, 1 = disconect, 2 = DATA OUT, 3 = DATA IN. */ +0 = COMMAND, 1 = disconnect, 2 = DATA OUT, 3 = DATA IN. */ int msg_action;int msg_len;uint8_t msg[LSI_MAX_MSGIN_LEN ];
@@ -1060,7 +1060,7 @@ again:lsi_set_phase (s,PHASE_MO );break ;case 1 :/* Disconnect */ -DPRINTF ("Wait Disconect\n" ); +DPRINTF ("Wait Disconnect\n" ); s->scntl1 &= ~LSI_SCNTL1_CON ;break ;case 2 :/* Wait Reselect */
@@ -1552,9 +1552,9 @@ static void lsi_reg_writeb(LSIState *s, int offset, uint8_t val)SCRIPTS register move instructions are. */ s->sfbr = val;break ; -case 0x0a :case 0x0b : +case 0x0a :case 0x0b :/* Openserver writes to these readonly registers on startup */ -return ; +return ;case 0x0c :case 0x0d :case 0x0e :case 0x0f :/* Linux writes to these readonly registers on startup. */ return ;
PATCH 3/7 lsi53c895a: Add support for LSI53C700 Family Compatibility bit
In reply to Jan KiszkaFrom: Laszlo Ast <[email protected]>
---
hw/lsi53c895a.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
hw/lsi53c895a.c +4 -0
@@ -583,6 +583,10 @@ static void lsi_reselect(LSIState *s, uint32_t tag) } id = (tag >>8 ) &0xf ; s->ssid = id |0x80 ; +/* LSI53C700 Family Compatibility, see LSI53C895A 4-73 */ +if (!s->dcntl &LSI_DCNTL_COM ) { + s->sfbr =1 << (id &0x7 ); + }DPRINTF ("Reselected target %d\n" , id); s->current_dev = s->bus.devs[id]; s->current_tag = tag;
PATCH 4/7 lsi53c895a: Fix message code of DISCONNECT
In reply to Jan KiszkaFrom: Laszlo Ast <[email protected]>
See SCSI-2, 6.5 Message system description/message codes.
---
hw/lsi53c895a.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/lsi53c895a.c +1 -1
@@ -788,7 +788,7 @@ static void lsi_do_msgout(LSIState *s) s->sfbr = msg;switch (msg) { -case 0x00 : +case 0x04 :DPRINTF ("MSG: Disconnect\n" );lsi_disconnect (s);break ;
PATCH 5/7 lsi53c895a: Fix SDID in SELECT ID command
In reply to Jan KiszkaFrom: Laszlo Ast <[email protected]>
See SCRIPTS Programming Guide, 3.2.17 SELECT.
---
hw/lsi53c895a.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/lsi53c895a.c +1 -1
@@ -1028,7 +1028,7 @@ again:if (insn & (1 <<25 )) { id =read_dword (s, s->dsa +sxt24 (insn)); }else { - id = addr; + id = insn; } id = (id >>16 ) &0xf ;if (insn & (1 <<26 )) {
PATCH 6/7 lsi53c895a: Use alternative address when already reselected
In reply to Jan KiszkaFrom: Laszlo Ast <[email protected]>
See SCRIPTS, 3.2.17 SELECT.
---
hw/lsi53c895a.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
hw/lsi53c895a.c +3 -2
@@ -1038,8 +1038,9 @@ again:switch (opcode) {case 0 :/* Select */ s->sdid = id; -if (s->current_dma_len && (s->ssid &0xf ) == id) { -DPRINTF ("Already reselected by target %d\n" , id); +if (s->scntl1 &LSI_SCNTL1_CON ) { +DPRINTF ("Already reselected, jumping to alternative address\n" ); + s->dsp = s->dnad;break ; } s->sstat0 |=LSI_SSTAT0_WOA ;
PATCH 7/7 lsi53c895a: Implement IRQ on reselection
In reply to Jan KiszkaFrom: Laszlo Ast <[email protected]>
The critical part of this change is how to deal with simultaneaous generation of interrupts. The only (normal) case when this happens in the emulation is near simultaneous reselection + selection. If selection comes first, there is no problem, since the target attempting reselection loses the arbitration (in the emulation it only means that the reselect function will not be started). In the worst case the host adapter is reselected, but the device driver already started a selection, so we jump to the alternative address to handle the situation.
The SCRIPTS code can trigger another interrupt to notify the driver that the new task has to be postponed. I suppose that on real hardware there is enough time after the reselection interrupt to set the SIP bit before the next interrupt comes, so it would result in 2 stacked interrupts (a SCSI and a DMA one). However, in the emulation there is no interrupt stacking, so there is a good chance that the 2 interrupts will get to the interrupt handler at the same time.
Nevertheless, it should not make a big difference in interrupt handling, since in both cases both interrupts have to be fetched first, and after that the new task (that failed during the selection phase) has to be prepared/reset for a later restart, and the reconnected device has to be serviced.
The changes do not modify the host adapter's behavior if this interrupt is not enabled.
See also LSI53C895A technical manual, SCID and SIEN0.
---
hw/lsi53c895a.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 40 insertions(+), 3 deletions(-)
hw/lsi53c895a.c +40 -3
@@ -152,6 +152,9 @@ do { fprintf(stderr, "lsi_scsi: error: " fmt , ## __VA_ARGS__);} while (0)#define LSI_CCNTL1_DDAC 0x08#define LSI_CCNTL1_ZMOD 0x80 +/* Enable Response to Reselection */ +#define LSI_SCID_RRE 0x60 +#define LSI_CCNTL1_40BIT (LSI_CCNTL1_EN64TIBMV|LSI_CCNTL1_64TIMOD)#define PHASE_DO 0
@@ -270,6 +273,11 @@ typedef struct {uint32_t script_ram[2048 ]; } LSIState; +static inline int lsi_irq_on_rsl (LSIState *s) +{ +return (s->sien0 &LSI_SIST0_RSL ) && (s->scid &LSI_SCID_RRE ); +} +static void lsi_soft_reset (LSIState *s) {DPRINTF ("Reset\n" );
@@ -360,6 +368,7 @@ static int lsi_dma_64bit(LSIState *s)static uint8_t lsi_reg_readb (LSIState *s,int offset);static void lsi_reg_writeb (LSIState *s,int offset,uint8_t val);static void lsi_execute_script (LSIState *s); +static void lsi_reselect (LSIState *s,uint32_t tag);static inline uint32_t read_dword (LSIState *s,uint32_t addr) {
@@ -380,6 +389,7 @@ static void lsi_stop_script(LSIState *s)static void lsi_update_irq (LSIState *s) { +int i;int level;static int last_level;
@@ -411,6 +421,17 @@ static void lsi_update_irq(LSIState *s) last_level = level; }qemu_set_irq (s->dev.irq[0 ], level); + +if (!level &&lsi_irq_on_rsl (s) && !(s->scntl1 &LSI_SCNTL1_CON )) { +DPRINTF ("Handled IRQs & disconnected, looking for pending " +"processes\n" ); +for (i =0 ; i < s->active_commands; i++) { +if (s->queue[i].pending) { +lsi_reselect (s, s->queue[i].tag); +break ; + } + } + } }/* Stop SCRIPTS execution and raise a SCSI interrupt. */
@@ -605,6 +626,10 @@ static void lsi_reselect(LSIState *s, uint32_t tag)if (n != s->active_commands) { s->queue[n] = s->queue[s->active_commands]; } + +if (lsi_irq_on_rsl (s)) { +lsi_script_scsi_interrupt (s,LSI_SIST0_RSL ,0 ); + } }/* Record that data is available for a queued command. Returns zero if
@@ -620,7 +645,14 @@ static int lsi_queue_tag(LSIState *s, uint32_t tag, uint32_t arg)BADF ("Multiple IO pending for tag %d\n" , tag); } p->pending = arg; -if (s->waiting ==1 ) { +/* Reselect if waiting for it, or if reselection triggers an IRQ +and the bus is free. +Since no interrupt stacking is implemented in the emulation, it +is also required that there are no pending interrupts waiting +for service from the device driver. */ +if (s->waiting ==1 || + (lsi_irq_on_rsl (s) && !(s->scntl1 &LSI_SCNTL1_CON ) && + !(s->istat0 & (LSI_ISTAT0_SIP |LSI_ISTAT0_DIP )))) {/* Reselect device. */ lsi_reselect (s, tag);return 0 ;
@@ -657,10 +689,13 @@ static void lsi_command_complete(SCSIBus *bus, int reason, uint32_t tag,return ; } -if (s->waiting ==1 || tag != s->current_tag) { +if (s->waiting ==1 || tag != s->current_tag || + (lsi_irq_on_rsl (s) && !(s->scntl1 &LSI_SCNTL1_CON ))) {if (lsi_queue_tag (s, tag, arg))return ; } + +/* host adapter (re)connected */ DPRINTF ("Data ready tag=0x%x len=%d\n" , tag, arg); s->current_dma_len = arg; s->command_complete =1 ;
@@ -1069,7 +1104,9 @@ again: s->scntl1 &= ~LSI_SCNTL1_CON ;break ;case 2 :/* Wait Reselect */ -lsi_wait_reselect (s); +if (!lsi_irq_on_rsl (s)) { +lsi_wait_reselect (s); + }break ;case 3 :/* Set */ DPRINTF("Set%s%s%s%s\n",