Untitled diff

Created Diff never expires
diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
/*
index f088d06..9d3c44d 100644
* QEMU LSI53C895A SCSI Host Bus Adapter emulation
--- a/hw/lsi53c895a.c
*
+++ b/hw/lsi53c895a.c
* Copyright (c) 2006 CodeSourcery.
@@ -175,7 +175,6 @@ do { fprintf(stderr, "lsi_scsi: error: " fmt , ## __VA_ARGS__);} while (0)
* Written by Paul Brook
*
typedef struct lsi_request {
* This code is licensed under the LGPL.
uint32_t tag;
*/
- SCSIDevice *dev;
uint32_t dma_len;
/* Note:
uint8_t *dma_buf;
* LSI53C810 emulation is incorrect, in the sense that it supports
uint32_t pending;
* features added in later evolutions. This should not be a problem,
@@ -202,7 +201,6 @@ typedef struct {
* as well-behaved operating systems will not try to use them.
* 3 if a DMA operation is in progress. */
*/
int waiting;
SCSIBus bus;
#include <assert.h>
- SCSIDevice *select_dev;
int current_lun;
#include "qemuuaeglue.h"
/* The tag is a combination of the device ID and the SCSI tag. */
#include "queue.h"
uint32_t select_tag;
@@ -518,11 +516,25 @@ static void lsi_resume_script(LSIState *s)
//#include "hw/hw.h"
}
//#include "hw/pci/pci.h"
}
#include "scsi/scsi.h"
//#include "sysemu/dma.h"
+static void lsi_disconnect(LSIState *s)
+{
//#define DEBUG_LSI
+ s->scntl1 &= ~LSI_SCNTL1_CON;
//#define DEBUG_LSI_REG
+ s->sstat1 &= ~PHASE_MASK;
+}
#ifdef DEBUG_LSI
+
#define DPRINTF(fmt, ...) \
+static void lsi_bad_selection(LSIState *s, uint32_t id)
do { write_log("lsi_scsi: " fmt , ## __VA_ARGS__); } while (0)
+{
#define BADF(fmt, ...) \
+ DPRINTF("Selected absent target %d\n", id);
do { write_log("lsi_scsi: error: " fmt , ## __VA_ARGS__); } while (0)
+ lsi_script_scsi_interrupt(s, 0, LSI_SIST1_STO);
#else
+ lsi_disconnect(s);
#define DPRINTF(fmt, ...) do {} while(0)
+}
#define BADF(fmt, ...) \
+
do { write_log("lsi_scsi: error: " fmt , ## __VA_ARGS__); } while (0)
/* Initiate a SCSI layer data transfer. */
#endif
static void lsi_do_dma(LSIState *s, int out)
{
#define LSI_MAX_DEVS 7
- uint32_t count;
+ uint32_t count, id;
#define LSI_SCNTL0_TRG 0x01
target_phys_addr_t addr;
#define LSI_SCNTL0_AAP 0x02
+ SCSIDevice *dev;
#define LSI_SCNTL0_EPC 0x08
#define LSI_SCNTL0_WATN 0x10
assert(s->current);
#define LSI_SCNTL0_START 0x20
if (!s->current->dma_len) {
@@ -531,6 +543,13 @@ static void lsi_do_dma(LSIState *s, int out)
#define LSI_SCNTL1_SST 0x01
return;
#define LSI_SCNTL1_IARB 0x02
}
#define LSI_SCNTL1_AESP 0x04
#define LSI_SCNTL1_RST 0x08
+ id = s->current->tag >> 8;
#define LSI_SCNTL1_CON 0x10
+ dev = s->bus.devs[id];
#define LSI_SCNTL1_DHP 0x20
+ if (!dev) {
#define LSI_SCNTL1_ADB 0x40
+ lsi_bad_selection(s, id);
#define LSI_SCNTL1_EXC 0x80
+ return;
+ }
#define LSI_SCNTL2_WSR 0x01
+
#define LSI_SCNTL2_VUE0 0x02
count = s->dbc;
#define LSI_SCNTL2_VUE1 0x04
if (count > s->current->dma_len)
#define LSI_SCNTL2_WSS 0x08
count = s->current->dma_len;
#define LSI_SCNTL2_SLPHBEN 0x10
@@ -550,8 +569,7 @@ static void lsi_do_dma(LSIState *s, int out)
#define LSI_SCNTL2_SLPMD 0x20
s->dbc -= count;
#define LSI_SCNTL2_CHM 0x40
#define LSI_SCNTL2_SDU 0x80
#define LSI_ISTAT0_DIP 0x01
#define LSI_ISTAT0_SIP 0x02
#define LSI_ISTAT0_INTF 0x04
#define LSI_ISTAT0_CON 0x08
#define LSI_ISTAT0_SEM 0x10
#define LSI_ISTAT0_SIGP 0x20
#define LSI_ISTAT0_SRST 0x40
#define LSI_ISTAT0_ABRT 0x80
#define LSI_ISTAT1_SI 0x01
#define LSI_ISTAT1_SRUN 0x02
#define LSI_ISTAT1_FLSH 0x04
#define LSI_SSTAT0_SDP0 0x01
#define LSI_SSTAT0_RST 0x02
#define LSI_SSTAT0_WOA 0x04
#define LSI_SSTAT0_LOA 0x08
#define LSI_SSTAT0_AIP 0x10
#define LSI_SSTAT0_OLF 0x20
#define LSI_SSTAT0_ORF 0x40
#define LSI_SSTAT0_ILF 0x80
#define LSI_SIST0_PAR 0x01
#define LSI_SIST0_RST 0x02
#define LSI_SIST0_UDC 0x04
#define LSI_SIST0_SGE 0x08
#define LSI_SIST0_RSL 0x10
#define LSI_SIST0_SEL 0x20
#define LSI_SIST0_CMP 0x40
#define LSI_SIST0_MA 0x80
#define LSI_SIST1_HTH 0x01
#define LSI_SIST1_GEN 0x02
#define LSI_SIST1_STO 0x04
#define LSI_SIST1_SBMC 0x10
#define LSI_SOCL_IO 0x01
#define LSI_SOCL_CD 0x02
#define LSI_SOCL_MSG 0x04
#define LSI_SOCL_ATN 0x08
#define LSI_SOCL_SEL 0x10
#define LSI_SOCL_BSY 0x20
#define LSI_SOCL_ACK 0x40
#define LSI_SOCL_REQ 0x80
#define LSI_DSTAT_IID 0x01
#define LSI_DSTAT_SIR 0x04
#define LSI_DSTAT_SSI 0x08
#define LSI_DSTAT_ABRT 0x10
#define LSI_DSTAT_BF 0x20
#define LSI_DSTAT_MDPE 0x40
#define LSI_DSTAT_DFE 0x80
#define LSI_DCNTL_COM 0x01
#define LSI_DCNTL_IRQD 0x02
#define LSI_DCNTL_STD 0x04
#define LSI_DCNTL_IRQM 0x08
#define LSI_DCNTL_SSM 0x10
#define LSI_DCNTL_PFEN 0x20
#define LSI_DCNTL_PFF 0x40
#define LSI_DCNTL_CLSE 0x80
#define LSI_DMODE_MAN 0x01
#define LSI_DMODE_BOF 0x02
#define LSI_DMODE_ERMP 0x04
#define LSI_DMODE_ERL 0x08
#define LSI_DMODE_DIOM 0x10
#define LSI_DMODE_SIOM 0x20
#define LSI_CTEST2_DACK 0x01
#define LSI_CTEST2_DREQ 0x02
#define LSI_CTEST2_TEOP 0x04
#define LSI_CTEST2_PCICIE 0x08
#define LSI_CTEST2_CM 0x10
#define LSI_CTEST2_CIO 0x20
#define LSI_CTEST2_SIGP 0x40
#define LSI_CTEST2_DDIR 0x80
#define LSI_CTEST5_BL2 0x04
#define LSI_CTEST5_DDIR 0x08
#define LSI_CTEST5_MASR 0x10
#define LSI_CTEST5_DFSN 0x20
#define LSI_CTEST5_BBCK 0x40
#define LSI_CTEST5_ADCK 0x80
#define LSI_CCNTL0_DILS 0x01
#define LSI_CCNTL0_DISFC 0x10
#define LSI_CCNTL0_ENNDJ 0x20
#define LSI_CCNTL0_PMJCTL 0x40
#define LSI_CCNTL0_ENPMJ 0x80
#define LSI_CCNTL1_EN64DBMV 0x01
#define LSI_CCNTL1_EN64TIBMV 0x02
#define LSI_CCNTL1_64TIMOD 0x04
#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
#define PHASE_DI 1
#define PHASE_CMD 2
#define PHASE_ST 3
#define PHASE_MO 6
#define PHASE_MI 7
#define PHASE_MASK 7
/* Maximum length of MSG IN data. */
#define LSI_MAX_MSGIN_LEN 8
/* Flag set if this is a tagged command. */
#define LSI_TAG_VALID (1 << 16)
typedef struct lsi_request {
SCSIRequest *req;
uint32_t tag;
uint32_t dma_len;
uint8_t *dma_buf;
uint32_t pending;
int out;
QTAILQ_ENTRY(lsi_request) next;
} lsi_request;
typedef struct {
/*< private >*/
// PCIDevice parent_obj;
/*< public >*/
//MemoryRegion mmio_io;
//MemoryRegion ram_io;
//MemoryRegion io_io;
int carry; /* ??? Should this be an a visible register somewhere? */
int status;
/* Action to take at the end of a MSG IN phase.
0 = COMMAND, 1 = disconnect, 2 = DATA OUT, 3 = DATA IN. */
int msg_action;
int msg_len;
uint8_t msg[LSI_MAX_MSGIN_LEN];
/* 0 if SCRIPTS are running or stopped.
* 1 if a Wait Reselect instruction has been issued.
* 2 if processing DMA from lsi_execute_script.
* 3 if a DMA operation is in progress. */
int waiting;
SCSIBus bus;
int current_lun;
/* The tag is a combination of the device ID and the SCSI tag. */
uint32_t select_tag;
int command_complete;
QTAILQ_HEAD(, lsi_request) queue;
lsi_request *current;
uint32_t dsa;
uint32_t temp;
uint32_t dnad;
uint32_t dbc;
uint8_t istat0;
uint8_t istat1;
uint8_t dcmd;
uint8_t dstat;
uint8_t dien;
uint8_t sist0;
uint8_t sist1;
uint8_t sien0;
uint8_t sien1;
uint8_t mbox0;
uint8_t mbox1;
uint8_t dfifo;
uint8_t ctest2;
uint8_t ctest3;
uint8_t ctest4;
uint8_t ctest5;
uint8_t ccntl0;
uint8_t ccntl1;
uint32_t dsp;
uint32_t dsps;
uint8_t dmode;
uint8_t dcntl;
uint8_t scntl0;
uint8_t scntl1;
uint8_t scntl2;
uint8_t scntl3;
uint8_t sstat0;
uint8_t sstat1;
uint8_t scid;
uint8_t sxfer;
uint8_t socl;
uint8_t sdid;
uint8_t ssid;
uint8_t sfbr;
uint8_t stest1;
uint8_t stest2;
uint8_t stest3;
uint8_t sidl;
uint8_t stime0;
uint8_t respid0;
uint8_t respid1;
uint32_t mmrs;
uint32_t mmws;
uint32_t sfs;
uint32_t drs;
uint32_t sbms;
uint32_t dbms;
uint32_t dnad64;
uint32_t pmjad1;
uint32_t pmjad2;
uint32_t rbc;
uint32_t ua;
uint32_t ia;
uint32_t sbc;
uint32_t csbc;
uint32_t scratch[18]; /* SCRATCHA-SCRATCHR */
uint8_t sbr;
uint8_t chip_rev;
int last_level;
/* Script ram is stored as 32-bit words in host byteorder. */
uint32_t script_ram[2048];
} LSIState;
#define TYPE_LSI53C810 "lsi53c810"
#define TYPE_LSI53C895A "lsi53c895a"
#define LSI53C895A(obj) (LSIState*)obj->lsistate
// OBJECT_CHECK(LSIState, (obj), TYPE_LSI53C895A)
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");
s->carry = 0;
s->msg_action = 0;
s->msg_len = 0;
s->waiting = 0;
s->dsa = 0;
s->dnad = 0;
s->dbc = 0;
s->temp = 0;
memset(s->scratch, 0, sizeof(s->scratch));
s->istat0 = 0;
s->istat1 = 0;
s->dcmd = 0x40;
s->dstat = LSI_DSTAT_DFE;
s->dien = 0;
s->sist0 = 0;
s->sist1 = 0;
s->sien0 = 0;
s->sien1 = 0;
s->mbox0 = 0;
s->mbox1 = 0;
s->dfifo = 0;
s->ctest2 = LSI_CTEST2_DACK;
s->ctest3 = 0;
s->ctest4 = 0;
s->ctest5 = 0;
s->ccntl0 = 0;
s->ccntl1 = 0;
s->dsp = 0;
s->dsps = 0;
s->dmode = 0;
s->dcntl = 0;
s->scntl0 = 0xc0;
s->scntl1 = 0;
s->scntl2 = 0;
s->scntl3 = 0;
s->sstat0 = 0;
s->sstat1 = 0;
s->scid = 7;
s->sxfer = 0;
s->socl = 0;
s->sdid = 0;
s->ssid = 0;
s->stest1 = 0;
s->stest2 = 0;
s->stest3 = 0;
s->sidl = 0;
s->stime0 = 0;
s->respid0 = 0x80;
s->respid1 = 0;
s->mmrs = 0;
s->mmws = 0;
s->sfs = 0;
s->drs = 0;
s->sbms = 0;
s->dbms = 0;
s->dnad64 = 0;
s->pmjad1 = 0;
s->pmjad2 = 0;
s->rbc = 0;
s->ua = 0;
s->ia = 0;
s->sbc = 0;
s->csbc = 0;
s->sbr = 0;
assert(QTAILQ_EMPTY(&s->queue));
assert(!s->current);
}
static int lsi_dma_40bit(LSIState *s)
{
if ((s->ccntl1 & LSI_CCNTL1_40BIT) == LSI_CCNTL1_40BIT)
return 1;
return 0;
}
static int lsi_dma_ti64bit(LSIState *s)
{
if ((s->ccntl1 & LSI_CCNTL1_EN64TIBMV) == LSI_CCNTL1_EN64TIBMV)
return 1;
return 0;
}
static int lsi_dma_64bit(LSIState *s)
{
if ((s->ccntl1 & LSI_CCNTL1_EN64DBMV) == LSI_CCNTL1_EN64DBMV)
return 1;
return 0;
}
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, lsi_request *p);
static inline uint32_t read_dword(LSIState *s, uint32_t addr)
{
uint32_t buf;
pci_dma_read(PCI_DEVICE(s), addr, &buf, 4);
return cpu_to_le32(buf);
}
static void lsi_stop_script(LSIState *s)
{
s->istat1 &= ~LSI_ISTAT1_SRUN;
}
static void do_irq(LSIState *s, int level)
{
PCIDevice *d = PCI_DEVICE(s);
if (level != s->last_level) {
DPRINTF("Update IRQ level %d dstat %02x sist %02x%02x\n",
level, s->dstat, s->sist1, s->sist0);
s->last_level = level;
}
pci_set_irq(d, level);
}
static void lsi_update_irq(LSIState *s)
{
int level;
lsi_request *p;
/* It's unclear whether the DIP/SIP bits should be cleared when the
Interrupt Status Registers are cleared or when istat0 is read.
We currently do the formwer, which seems to work. */
level = 0;
if (s->dstat) {
if (s->dstat & s->dien)
level = 1;
s->istat0 |= LSI_ISTAT0_DIP;
} else {
s->istat0 &= ~LSI_ISTAT0_DIP;
}
if (s->sist0 || s->sist1) {
if ((s->sist0 & s->sien0) || (s->sist1 & s->sien1))
level = 1;
s->istat0 |= LSI_ISTAT0_SIP;
} else {
s->istat0 &= ~LSI_ISTAT0_SIP;
}
if (s->istat0 & LSI_ISTAT0_INTF)
level = 1;
do_irq(s, level);
if (!level && lsi_irq_on_rsl(s) && !(s->scntl1 & LSI_SCNTL1_CON)) {
DPRINTF("Handled IRQs & disconnected, looking for pending "
"processes\n");
QTAILQ_FOREACH(p, &s->queue, next) {
if (p->pending) {
lsi_reselect(s, p);
break;
}
}
}
}
/* Stop SCRIPTS execution and raise a SCSI interrupt. */
static void lsi_script_scsi_interrupt(LSIState *s, int stat0, int stat1)
{
uint32_t mask0;
uint32_t mask1;
DPRINTF("SCSI Interrupt 0x%02x%02x prev 0x%02x%02x\n",
stat1, stat0, s->sist1, s->sist0);
s->sist0 |= stat0;
s->sist1 |= stat1;
/* Stop processor on fatal or unmasked interrupt. As a special hack
we don't stop processing when raising STO. Instead continue
execution and stop at the next insn that accesses the SCSI bus. */
mask0 = s->sien0 | ~(LSI_SIST0_CMP | LSI_SIST0_SEL | LSI_SIST0_RSL);
mask1 = s->sien1 | ~(LSI_SIST1_GEN | LSI_SIST1_HTH);
mask1 &= ~LSI_SIST1_STO;
if (s->sist0 & mask0 || s->sist1 & mask1) {
lsi_stop_script(s);
}
lsi_update_irq(s);
}
/* Stop SCRIPTS execution and raise a DMA interrupt. */
static void lsi_script_dma_interrupt(LSIState *s, int stat)
{
DPRINTF("DMA Interrupt 0x%x prev 0x%x\n", stat, s->dstat);
s->dstat |= stat;
lsi_update_irq(s);
lsi_stop_script(s);
}
static inline void lsi_set_phase(LSIState *s, int phase)
{
s->sstat1 = (s->sstat1 & ~PHASE_MASK) | phase;
}
static void lsi_bad_phase(LSIState *s, int out, int new_phase)
{
/* Trigger a phase mismatch. */
if (s->ccntl0 & LSI_CCNTL0_ENPMJ) {
if ((s->ccntl0 & LSI_CCNTL0_PMJCTL)) {
s->dsp = out ? s->pmjad1 : s->pmjad2;
} else {
s->dsp = (s->scntl2 & LSI_SCNTL2_WSR ? s->pmjad2 : s->pmjad1);
}
DPRINTF("Data phase mismatch jump to %08x\n", s->dsp);
} else {
DPRINTF("Phase mismatch interrupt\n");
lsi_script_scsi_interrupt(s, LSI_SIST0_MA, 0);
lsi_stop_script(s);
}
lsi_set_phase(s, new_phase);
}
/* Resume SCRIPTS execution after a DMA operation. */
static void lsi_resume_script(LSIState *s)
{
if (s->waiting != 2) {
s->waiting = 0;
lsi_execute_script(s);
} else {
s->waiting = 0;
}
}
static void lsi_disconnect(LSIState *s)
{
s->scntl1 &= ~LSI_SCNTL1_CON;
s->sstat1 &= ~PHASE_MASK;
}
static void lsi_bad_selection(LSIState *s, uint32_t id)
{
DPRINTF("Selected absent target %d\n", id);
lsi_script_scsi_interrupt(s, 0, LSI_SIST1_STO);
lsi_disconnect(s);
}
/* Initiate a SCSI layer data transfer. */
static void lsi_do_dma(LSIState *s, int out)
{
PCIDevice *pci_dev;
uint32_t count;
dma_addr_t addr;
SCSIDevice *dev;
assert(s->current);
if (!s->current->dma_len) {
/* Wait until data is available. */
DPRINTF("DMA no data available\n");
return;
}
pci_dev = PCI_DEVICE(s);
dev = s->current->req->dev;
assert(dev);
count = s->dbc;
if (count > s->current->dma_len)
count = s->current->dma_len;
addr = s->dnad;
/* both 40 and Table Indirect 64-bit DMAs store upper bits in dnad64 */
if (lsi_dma_40bit(s) || lsi_dma_ti64bit(s))
addr |= ((uint64_t)s->dnad64 << 32);
else if (s->dbms)
addr |= ((uint64_t)s->dbms << 32);
else if (s->sbms)
addr |= ((uint64_t)s->sbms << 32);
DPRINTF("DMA addr=0x" DMA_ADDR_FMT " len=%d\n", addr, count);
s->csbc += count;
s->dnad += count;
s->dbc -= count;
if (s->current->dma_buf == NULL) {
if (s->current->dma_buf == NULL) {
- s->current->dma_buf = s->current->dev->info->get_buf(s->current->dev,
s->current->dma_buf = scsi_req_get_buf(s->current->req);
- s->current->tag);
}
+ s->current->dma_buf = dev->info->get_buf(dev, s->current->tag);
/* ??? Set SFBR to first data byte. */
}
if (out) {
pci_dma_read(pci_dev, addr, s->current->dma_buf, count);
/* ??? Set SFBR to first data byte. */
} else {
@@ -565,10 +583,10 @@ static void lsi_do_dma(LSIState *s, int out)
pci_dma_write(pci_dev, addr, s->current->dma_buf, count);
s->current->dma_buf = NULL;
}
if (out) {
s->current->dma_len -= count;
/* Write the data. */
if (s->current->dma_len == 0) {
- s->current->dev->info->write_data(s->current->dev, s->current->tag);
s->current->dma_buf = NULL;
+ dev->info->write_data(dev, s->current->tag);
scsi_req_continue(s->current->req);
} else {
} else {
/* Request any remaining data. */
s->current->dma_buf += count;
- s->current->dev->info->read_data(s->current->dev, s->current->tag);
lsi_resume_script(s);
+ dev->info->read_data(dev, s->current->tag);
}
}
}
} else {
s->current->dma_buf += count;
@@ -715,7 +733,9 @@ static void lsi_command_complete(SCSIBus *bus, int reason, uint32_t tag,
/* Add a command to the queue. */
static void lsi_queue_command(LSIState *s)
static void lsi_do_command(LSIState *s)
{
{
lsi_request *p = s->current;
+ SCSIDevice *dev;
uint8_t buf[16];
DPRINTF("Queueing tag=0x%x\n", p->tag);
+ uint32_t id;
assert(s->current != NULL);
int n;
assert(s->current->dma_len == 0);
QTAILQ_INSERT_TAIL(&s->queue, s->current, next);
DPRINTF("Send command len=%d\n", s->dbc);
s->current = NULL;
@@ -725,19 +745,24 @@ static void lsi_do_command(LSIState *s)
s->sfbr = buf[0];
p->pending = 0;
s->command_complete = 0;
p->out = (s->sstat1 & PHASE_MASK) == PHASE_DO;
}
+ id = s->select_tag >> 8;
+ dev = s->bus.devs[id];
/* Queue a byte for a MSG IN phase. */
+ if (!dev) {
static void lsi_add_msg_byte(LSIState *s, uint8_t data)
+ lsi_bad_selection(s, id);
{
+ return;
if (s->msg_len >= LSI_MAX_MSGIN_LEN) {
+ }
BADF("MSG IN data too long\n");
+
} else {
assert(s->current == NULL);
DPRINTF("MSG IN 0x%02x\n", data);
s->current = qemu_mallocz(sizeof(lsi_request));
s->msg[s->msg_len++] = data;
s->current->tag = s->select_tag;
}
- s->current->dev = s->select_dev;
}
- n = s->current->dev->info->send_command(s->current->dev, s->current->tag, buf,
/* Perform reselection to continue a command. */
- s->current_lun);
static void lsi_reselect(LSIState *s, lsi_request *p)
+ n = dev->info->send_command(dev, s->current->tag, buf, s->current_lun);
{
if (n > 0) {
int id;
lsi_set_phase(s, PHASE_DI);
- s->current->dev->info->read_data(s->current->dev, s->current->tag);
assert(s->current == NULL);
+ dev->info->read_data(dev, s->current->tag);
QTAILQ_REMOVE(&s->queue, p, next);
} else if (n < 0) {
s->current = p;
lsi_set_phase(s, PHASE_DO);
- s->current->dev->info->write_data(s->current->dev, s->current->tag);
id = (p->tag >> 8) & 0xf;
+ dev->info->write_data(dev, s->current->tag);
s->ssid = id | 0x80;
}
/* LSI53C700 Family Compatibility, see LSI53C895A 4-73 */
if (!(s->dcntl & LSI_DCNTL_COM)) {
if (!s->command_complete) {
s->sfbr = 1 << (id & 0x7);
@@ -771,12 +796,6 @@ static void lsi_do_status(LSIState *s)
}
lsi_add_msg_byte(s, 0); /* COMMAND COMPLETE */
DPRINTF("Reselected target %d\n", id);
}
s->scntl1 |= LSI_SCNTL1_CON;
lsi_set_phase(s, PHASE_MI);
-static void lsi_disconnect(LSIState *s)
s->msg_action = p->out ? 2 : 3;
-{
s->current->dma_len = p->pending;
- s->scntl1 &= ~LSI_SCNTL1_CON;
lsi_add_msg_byte(s, 0x80);
- s->sstat1 &= ~PHASE_MASK;
if (s->current->tag & LSI_TAG_VALID) {
-}
lsi_add_msg_byte(s, 0x20);
-
lsi_add_msg_byte(s, p->tag & 0xff);
static void lsi_do_msgin(LSIState *s)
}
{
int len;
if (lsi_irq_on_rsl(s)) {
@@ -1092,9 +1111,7 @@ again:
lsi_script_scsi_interrupt(s, LSI_SIST0_RSL, 0);
s->sstat0 |= LSI_SSTAT0_WOA;
}
s->scntl1 &= ~LSI_SCNTL1_IARB;
}
if (id >= LSI_MAX_DEVS || !s->bus.devs[id]) {
- DPRINTF("Selected absent target %d\n", id);
static lsi_request *lsi_find_by_tag(LSIState *s, uint32_t tag)
- lsi_script_scsi_interrupt(s, 0, LSI_SIST1_STO);
{
- lsi_disconnect(s);
lsi_request *p;
+ lsi_bad_selection(s, id);
break;
QTAILQ_FOREACH(p, &s->queue, next) {
}
if (p->tag == tag) {
DPRINTF("Selected target %d%s\n",
return p;
@@ -1102,7 +1119,6 @@ again:
}
/* ??? Linux drivers compain when this is set. Maybe
}
it only applies in low-level mode (unimplemented).
lsi_script_scsi_interrupt(s, LSI_SIST0_CMP, 0); */
return NULL;
- s->select_dev = s->bus.devs[id];
}
s->select_tag = id << 8;
s->scntl1 |= LSI_SCNTL1_CON;
static void lsi_request_free(LSIState *s, lsi_request *p)
if (insn & (1 << 3)) {
{
--
if (p == s->current) {
1.9.3.dirty
s->current = NULL;
} else {
QTAILQ_REMOVE(&s->queue, p, next);
}
g_free(p);
}
void lsi_request_cancelled(SCSIRequest *req)
{
LSIState *s = LSI53C895A(req->bus->qbus.parent);
lsi_request *p = (lsi_request*)req->hba_private;
req->hba_private = NULL;
lsi_request_free(s, p);
scsi_req_unref(req);
}
/* Record that data is available for a queued command. Returns zero if
the device was reselected, nonzero if the IO is deferred. */
static int lsi_queue_req(LSIState *s, SCSIRequest *req, uint32_t len)
{
lsi_request *p = (lsi_request*)req->hba_private;
if (p->pending) {
BADF("Multiple IO pending for request %p\n", p);
}
p->pending = len;
/* 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, p);
return 0;
} else {
DPRINTF("Queueing IO tag=0x%x\n", p->tag);
p->pending = len;
return 1;
}
}
/* Callback to indicate that the SCSI layer has completed a command. */
void lsi_command_complete(SCSIRequest *req, uint32_t status, size_t resid)
{
LSIState *s = LSI53C895A(req->bus->qbus.parent);
int out;
out = (s->sstat1 & PHASE_MASK) == PHASE_DO;
DPRINTF("Command complete status=%d\n", (int)status);
s->status = status;
s->command_complete = 2;
if (s->waiting && s->dbc != 0) {
/* Raise phase mismatch for short transfers. */
lsi_bad_phase(s, out, PHASE_ST);
} else {
lsi_set_phase(s, PHASE_ST);
}
if (req->hba_private == s->current) {
req->hba_private = NULL;
lsi_request_free(s, s->current);
scsi_req_unref(req);
}
lsi_resume_script(s);
}
/* Callback to indicate that the SCSI layer has completed a transfer. */
void lsi_transfer_data(SCSIRequest *req, uint32_t len)
{
LSIState *s = LSI53C895A(req->bus->qbus.parent);
int out;
assert(req->hba_private);
if (s->waiting == 1 || req->hba_private != s->current ||
(lsi_irq_on_rsl(s) && !(s->scntl1 & LSI_SCNTL1_CON))) {
if (lsi_queue_req(s, req, len)) {
return;
}
}
out = (s->sstat1 & PHASE_MASK) == PHASE_DO;
/* host adapter (re)connected */
DPRINTF("Data ready tag=0x%x len=%d\n", req->tag, len);
s->current->dma_len = len;
s->command_complete = 1;
if (s->waiting) {
if (s->waiting == 1 || s->dbc == 0) {
lsi_resume_script(s);
} else {
lsi_do_dma(s, out);
}
}
}
static void lsi_do_command(LSIState *s)
{
SCSIDevice *dev;
uint8_t buf[16];
uint32_t id;
int n;
DPRINTF("Send command len=%d\n", s->dbc);
if (s->dbc > 16)
s->dbc = 16;
pci_dma_read(PCI_DEVICE(s), s->dnad, buf, s->dbc);
s->sfbr = buf[0];
s->command_complete = 0;
id = (s->select_tag >> 8) & 0xf;
dev = scsi_device_find(&s->bus, 0, id, s->current_lun);
if (!dev) {
lsi_bad_selection(s, id);
return;
}
assert(s->current == NULL);
s->current = (lsi_request*)calloc(sizeof(lsi_request), 1);
s->current->tag = s->select_tag;
s->current->req = scsi_req_new(dev, s->current->tag, s->current_lun, buf, s->dbc, s->current);
n = scsi_req_enqueue(s->current->req);
if (n) {
if (n > 0) {
lsi_set_phase(s, PHASE_DI);
} else if (n < 0) {
lsi_set_phase(s, PHASE_DO);
}
scsi_req_continue(s->current->req);
}
if (!s->command_complete) {
if (n) {
/* Command did not complete immediately so disconnect. */
lsi_add_msg_byte(s, 2); /* SAVE DATA POINTER */
lsi_add_msg_byte(s, 4); /* DISCONNECT */
/* wait data */
lsi_set_phase(s, PHASE_MI);
s->msg_action = 1;
lsi_queue_command(s);
} else {
/* wait command complete */
lsi_set_phase(s, PHASE_DI);
}
}
}
static void lsi_do_status(LSIState *s)
{
uint8_t status;
DPRINTF("Get status len=%d status=%d\n", s->dbc, s->status);
if (s->dbc != 1)
BADF("Bad Status move\n");
s->dbc = 1;
status = s->status;
s->sfbr = status;
pci_dma_write(PCI_DEVICE(s), s->dnad, &status, 1);
lsi_set_phase(s, PHASE_MI);
s->msg_action = 1;
lsi_add_msg_byte(s, 0); /* COMMAND COMPLETE */
}
static void lsi_do_msgin(LSIState *s)
{
int len;
DPRINTF("Message in len=%d/%d\n", s->dbc, s->msg_len);
s->sfbr = s->msg[0];
len = s->msg_len;
if (len > s->dbc)
len = s->dbc;
pci_dma_write(PCI_DEVICE(s), s->dnad, s->msg, len);
/* Linux drivers rely on the last byte being in the SIDL. */
s->sidl = s->msg[len - 1];
s->msg_len -= len;
if (s->msg_len) {
memmove(s->msg, s->msg + len, s->msg_len);
} else {
/* ??? Check if ATN (not yet implemented) is asserted and maybe
switch to PHASE_MO. */
switch (s->msg_action) {
case 0:
lsi_set_phase(s, PHASE_CMD);
break;
case 1:
lsi_disconnect(s);
break;
case 2:
lsi_set_phase(s, PHASE_DO);
break;
case 3:
lsi_set_phase(s, PHASE_DI);
break;
default:
abort();
}
}
}
/* Read the next byte during a MSGOUT phase. */
static uint8_t lsi_get_msgbyte(LSIState *s)
{
uint8_t data;
pci_dma_read(PCI_DEVICE(s), s->dnad, &data, 1);
s->dnad++;
s->dbc--;
return data;
}
/* Skip the next n bytes during a MSGOUT phase. */
static void lsi_skip_msgbytes(LSIState *s, unsigned int n)
{
s->dnad += n;
s->dbc -= n;
}
static void lsi_do_msgout(LSIState *s)
{
uint8_t msg;
int len;
uint32_t current_tag;
lsi_request *current_req, *p, *p_next;
if (s->current) {
current_tag = s->current->tag;
current_req = s->current;
} else {
current_tag = s->select_tag;
current_req = lsi_find_by_tag(s, current_tag);
}
DPRINTF("MSG out len=%d\n", s->dbc);
while (s->dbc) {
msg = lsi_get_msgbyte(s);
s->sfbr = msg;
switch (msg) {
case 0x04:
DPRINTF("MSG: Disconnect\n");
lsi_disconnect(s);
break;
case 0x08:
DPRINTF("MSG: No Operation\n");
lsi_set_phase(s, PHASE_CMD);
break;
case 0x01:
len = lsi_get_msgbyte(s);
msg = lsi_get_msgbyte(s);
(void)len; /* avoid a warning about unused variable*/
DPRINTF("Extended message 0x%x (len %d)\n", msg, len);
switch (msg) {
case 1:
DPRINTF("SDTR (ignored)\n");
lsi_skip_msgbytes(s, 2);
break;
case 3:
DPRINTF("WDTR (ignored)\n");
lsi_skip_msgbytes(s, 1);
break;
default:
goto bad;