/*
|
/*
|
* linux/arch/arm/drivers/scsi/acornscsi.c
|
* linux/arch/arm/drivers/scsi/acornscsi.c
|
*
|
*
|
* Acorn SCSI 3 driver
|
* Acorn SCSI 3 driver
|
* By R.M.King.
|
* By R.M.King.
|
*
|
*
|
* Abandoned using the Select and Transfer command since there were
|
* Abandoned using the Select and Transfer command since there were
|
* some nasty races between our software and the target devices that
|
* some nasty races between our software and the target devices that
|
* were not easy to solve, and the device errata had a lot of entries
|
* were not easy to solve, and the device errata had a lot of entries
|
* for this command, some of them quite nasty...
|
* for this command, some of them quite nasty...
|
*
|
*
|
* Changelog:
|
* Changelog:
|
* 26-Sep-1997 RMK Re-jigged to use the queue module.
|
* 26-Sep-1997 RMK Re-jigged to use the queue module.
|
* Re-coded state machine to be based on driver
|
* Re-coded state machine to be based on driver
|
* state not scsi state. Should be easier to debug.
|
* state not scsi state. Should be easier to debug.
|
* Added acornscsi_release to clean up properly.
|
* Added acornscsi_release to clean up properly.
|
* Updated proc/scsi reporting.
|
* Updated proc/scsi reporting.
|
* 05-Oct-1997 RMK Implemented writing to SCSI devices.
|
* 05-Oct-1997 RMK Implemented writing to SCSI devices.
|
* 06-Oct-1997 RMK Corrected small (non-serious) bug with the connect/
|
* 06-Oct-1997 RMK Corrected small (non-serious) bug with the connect/
|
* reconnect race condition causing a warning message.
|
* reconnect race condition causing a warning message.
|
* 12-Oct-1997 RMK Added catch for re-entering interrupt routine.
|
* 12-Oct-1997 RMK Added catch for re-entering interrupt routine.
|
* 15-Oct-1997 RMK Improved handling of commands.
|
* 15-Oct-1997 RMK Improved handling of commands.
|
*/
|
*/
|
#define DEBUG_NO_WRITE 1
|
#define DEBUG_NO_WRITE 1
|
#define DEBUG_QUEUES 2
|
#define DEBUG_QUEUES 2
|
#define DEBUG_DMA 4
|
#define DEBUG_DMA 4
|
#define DEBUG_ABORT 8
|
#define DEBUG_ABORT 8
|
#define DEBUG_DISCON 16
|
#define DEBUG_DISCON 16
|
#define DEBUG_CONNECT 32
|
#define DEBUG_CONNECT 32
|
#define DEBUG_PHASES 64
|
#define DEBUG_PHASES 64
|
#define DEBUG_WRITE 128
|
#define DEBUG_WRITE 128
|
#define DEBUG_LINK 256
|
#define DEBUG_LINK 256
|
#define DEBUG_MESSAGES 512
|
#define DEBUG_MESSAGES 512
|
#define DEBUG_RESET 1024
|
#define DEBUG_RESET 1024
|
#define DEBUG_ALL (DEBUG_RESET|DEBUG_MESSAGES|DEBUG_LINK|DEBUG_WRITE|\
|
#define DEBUG_ALL (DEBUG_RESET|DEBUG_MESSAGES|DEBUG_LINK|DEBUG_WRITE|\
|
DEBUG_PHASES|DEBUG_CONNECT|DEBUG_DISCON|DEBUG_ABORT|\
|
DEBUG_PHASES|DEBUG_CONNECT|DEBUG_DISCON|DEBUG_ABORT|\
|
DEBUG_DMA|DEBUG_QUEUES|DEBUG_NO_WRITE)
|
DEBUG_DMA|DEBUG_QUEUES|DEBUG_NO_WRITE)
|
|
|
/* DRIVER CONFIGURATION
|
/* DRIVER CONFIGURATION
|
*
|
*
|
* SCSI-II Tagged queue support.
|
* SCSI-II Tagged queue support.
|
*
|
*
|
* I don't have any SCSI devices that support it, so it is totally untested
|
* I don't have any SCSI devices that support it, so it is totally untested
|
* (except to make sure that it doesn't interfere with any non-tagging
|
* (except to make sure that it doesn't interfere with any non-tagging
|
* devices). It is not fully implemented either - what happens when a
|
* devices). It is not fully implemented either - what happens when a
|
* tagging device reconnects???
|
* tagging device reconnects???
|
*
|
*
|
* You can tell if you have a device that supports tagged queueing my
|
* You can tell if you have a device that supports tagged queueing my
|
* cating (eg) /proc/scsi/acornscsi/0 and see if the SCSI revision is reported
|
* cating (eg) /proc/scsi/acornscsi/0 and see if the SCSI revision is reported
|
* as '2 TAG'.
|
* as '2 TAG'.
|
*/
|
*/
|
#define SCSI2_TAG
|
#define SCSI2_TAG
|
/*
|
/*
|
* SCSI-II Linked command support.
|
* SCSI-II Linked command support.
|
*
|
*
|
* The higher level code doesn't support linked commands yet.
|
* The higher level code doesn't support linked commands yet.
|
*/
|
*/
|
#undef SCSI2_LINK
|
#undef SCSI2_LINK
|
/*
|
/*
|
* SCSI-II Synchronous transfer support.
|
* SCSI-II Synchronous transfer support.
|
*
|
*
|
* Tried and tested...
|
* Tried and tested...
|
*
|
*
|
* SDTR_SIZE - maximum number of un-acknowledged bytes (0 = off, 12 = max)
|
* SDTR_SIZE - maximum number of un-acknowledged bytes (0 = off, 12 = max)
|
* SDTR_PERIOD - period of REQ signal (min=125, max=1020)
|
* SDTR_PERIOD - period of REQ signal (min=125, max=1020)
|
* DEFAULT_PERIOD - default REQ period.
|
* DEFAULT_PERIOD - default REQ period.
|
*/
|
*/
|
#define SCSI2_SYNC
|
#define SCSI2_SYNC
|
#define SDTR_SIZE 12
|
#define SDTR_SIZE 12
|
#define SDTR_PERIOD 125
|
#define SDTR_PERIOD 125
|
#define DEFAULT_PERIOD 500
|
#define DEFAULT_PERIOD 500
|
|
|
/*
|
/*
|
* Debugging information
|
* Debugging information
|
*
|
*
|
* DEBUG - bit mask from list above
|
* DEBUG - bit mask from list above
|
* DEBUG_TARGET - is defined to the target number if you want to debug
|
* DEBUG_TARGET - is defined to the target number if you want to debug
|
* a specific target. [only recon/write/dma].
|
* a specific target. [only recon/write/dma].
|
*/
|
*/
|
#define DEBUG (DEBUG_RESET|DEBUG_WRITE|DEBUG_NO_WRITE)
|
#define DEBUG (DEBUG_RESET|DEBUG_WRITE|DEBUG_NO_WRITE)
|
/* only allow writing to SCSI device 0 */
|
/* only allow writing to SCSI device 0 */
|
#define NO_WRITE 0xFE
|
#define NO_WRITE 0xFE
|
|
|
/*#define DEBUG_TARGET 2*/
|
/*#define DEBUG_TARGET 2*/
|
/*
|
/*
|
* Select timeout time (in 10ms units)
|
* Select timeout time (in 10ms units)
|
*
|
*
|
* This is the timeout used between the start of selection and the WD33C93
|
* This is the timeout used between the start of selection and the WD33C93
|
* chip deciding that the device isn't responding.
|
* chip deciding that the device isn't responding.
|
*/
|
*/
|
#define TIMEOUT_TIME 10
|
#define TIMEOUT_TIME 10
|
/*
|
/*
|
* Define this if you want to have verbose explaination of SCSI
|
* Define this if you want to have verbose explaination of SCSI
|
* status/messages.
|
* status/messages.
|
*/
|
*/
|
#undef CONFIG_ACORNSCSI_CONSTANTS
|
#undef CONFIG_ACORNSCSI_CONSTANTS
|
/*
|
/*
|
* Define this if you want to use the on board DMAC
|
* Define this if you want to use the on board DMAC
|
*/
|
*/
|
#define USE_DMAC
|
#define USE_DMAC
|
/*
|
/*
|
* List of devices that the driver will recognise
|
* List of devices that the driver will recognise
|
*/
|
*/
|
#define ACORNSCSI_LIST { MANU_ACORN, PROD_ACORN_SCSI }
|
#define ACORNSCSI_LIST { MANU_ACORN, PROD_ACORN_SCSI }
|
/*
|
/*
|
* ====================================================================================
|
* ====================================================================================
|
*/
|
*/
|
|
|
#ifdef DEBUG_TARGET
|
#ifdef DEBUG_TARGET
|
#define DBG(cmd,xxx...) \
|
#define DBG(cmd,xxx...) \
|
if (cmd->target == DEBUG_TARGET) { \
|
if (cmd->target == DEBUG_TARGET) { \
|
xxx; \
|
xxx; \
|
}
|
}
|
#else
|
#else
|
#define DBG(cmd,xxx...) xxx
|
#define DBG(cmd,xxx...) xxx
|
#endif
|
#endif
|
|
|
#ifndef STRINGIFY
|
#ifndef STRINGIFY
|
#define STRINGIFY(x) #x
|
#define STRINGIFY(x) #x
|
#endif
|
#endif
|
#define STR(x) STRINGIFY(x)
|
#define STR(x) STRINGIFY(x)
|
#define NO_WRITE_STR STR(NO_WRITE)
|
#define NO_WRITE_STR STR(NO_WRITE)
|
|
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
#include
|
|
|
#include "../block/blk.h"
|
#include "../block/blk.h"
|
#include "scsi.h"
|
#include "scsi.h"
|
#include "hosts.h"
|
#include "hosts.h"
|
#include "acornscsi.h"
|
#include "acornscsi.h"
|
#include "constants.h"
|
#include "constants.h"
|
#include "msgqueue.h"
|
#include "msgqueue.h"
|
|
|
#define VER_MAJOR 2
|
#define VER_MAJOR 2
|
#define VER_MINOR 0
|
#define VER_MINOR 0
|
#define VER_PATCH 4
|
#define VER_PATCH 4
|
|
|
#ifndef ABORT_TAG
|
#ifndef ABORT_TAG
|
#define ABORT_TAG 0xd
|
#define ABORT_TAG 0xd
|
#else
|
#else
|
#error "Yippee! ABORT TAG is now defined! Remove this error!"
|
#error "Yippee! ABORT TAG is now defined! Remove this error!"
|
#endif
|
#endif
|
|
|
#ifndef NO_IRQ
|
#ifndef NO_IRQ
|
#define NO_IRQ 255
|
#define NO_IRQ 255
|
#endif
|
#endif
|
|
|
/*
|
/*
|
* DMAC setup parameters
|
* DMAC setup parameters
|
*/
|
*/
|
#define INIT_DEVCON0 (DEVCON0_RQL|DEVCON0_EXW|DEVCON0_CMP)
|
#define INIT_DEVCON0 (DEVCON0_RQL|DEVCON0_EXW|DEVCON0_CMP)
|
#define INIT_DEVCON1 (DEVCON1_BHLD)
|
#define INIT_DEVCON1 (DEVCON1_BHLD)
|
#define DMAC_READ (MODECON_READ)
|
#define DMAC_READ (MODECON_READ)
|
#define DMAC_WRITE (MODECON_WRITE)
|
#define DMAC_WRITE (MODECON_WRITE)
|
#define INIT_SBICDMA (CTRL_DMABURST)
|
#define INIT_SBICDMA (CTRL_DMABURST)
|
|
|
#ifdef SCSI2_LINK
|
#ifdef SCSI2_LINK
|
#error SCSI2 LINKed commands not supported (yet)!
|
#error SCSI2 LINKed commands not supported (yet)!
|
#endif
|
#endif
|
|
|
/*
|
/*
|
* Size of on-board DMA buffer
|
* Size of on-board DMA buffer
|
*/
|
*/
|
#define DMAC_BUFFER_SIZE 65536
|
#define DMAC_BUFFER_SIZE 65536
|
|
|
/*
|
/*
|
* This is used to dump the previous states of the SBIC
|
* This is used to dump the previous states of the SBIC
|
*/
|
*/
|
static struct status_entry {
|
static struct status_entry {
|
unsigned long when;
|
unsigned long when;
|
unsigned char ssr;
|
unsigned char ssr;
|
unsigned char ph;
|
unsigned char ph;
|
unsigned char irq;
|
unsigned char irq;
|
unsigned char unused;
|
unsigned char unused;
|
} status[9][16];
|
} status[9][16];
|
static unsigned char status_ptr[9];
|
static unsigned char status_ptr[9];
|
|
|
#define ADD_STATUS(_q,_ssr,_ph,_irq) \
|
#define ADD_STATUS(_q,_ssr,_ph,_irq) \
|
({ \
|
({ \
|
status[(_q)][status_ptr[(_q)]].when = jiffies; \
|
status[(_q)][status_ptr[(_q)]].when = jiffies; \
|
status[(_q)][status_ptr[(_q)]].ssr = (_ssr); \
|
status[(_q)][status_ptr[(_q)]].ssr = (_ssr); \
|
status[(_q)][status_ptr[(_q)]].ph = (_ph); \
|
status[(_q)][status_ptr[(_q)]].ph = (_ph); \
|
status[(_q)][status_ptr[(_q)]].irq = (_irq); \
|
status[(_q)][status_ptr[(_q)]].irq = (_irq); \
|
status_ptr[(_q)] = (status_ptr[(_q)] + 1) & 15; \
|
status_ptr[(_q)] = (status_ptr[(_q)] + 1) & 15; \
|
})
|
})
|
|
|
unsigned int sdtr_period = SDTR_PERIOD;
|
unsigned int sdtr_period = SDTR_PERIOD;
|
unsigned int sdtr_size = SDTR_SIZE;
|
unsigned int sdtr_size = SDTR_SIZE;
|
|
|
static struct proc_dir_entry proc_scsi_acornscsi = {
|
static struct proc_dir_entry proc_scsi_acornscsi = {
|
PROC_SCSI_EATA, 9, "acornscsi", S_IFDIR | S_IRUGO | S_IXUGO, 2
|
PROC_SCSI_EATA, 9, "acornscsi", S_IFDIR | S_IRUGO | S_IXUGO, 2
|
};
|
};
|
|
|
static void acornscsi_done (AS_Host *host, Scsi_Cmnd **SCpntp, unsigned int result);
|
static void acornscsi_done (AS_Host *host, Scsi_Cmnd **SCpntp, unsigned int result);
|
static int acornscsi_reconnect_finish (AS_Host *host);
|
static int acornscsi_reconnect_finish (AS_Host *host);
|
static void acornscsi_dma_cleanup (AS_Host *host);
|
static void acornscsi_dma_cleanup (AS_Host *host);
|
static void acornscsi_abortcmd (AS_Host *host, unsigned char tag);
|
static void acornscsi_abortcmd (AS_Host *host, unsigned char tag);
|
|
|
/* ====================================================================================
|
/* ====================================================================================
|
* Miscellaneous
|
* Miscellaneous
|
*/
|
*/
|
|
|
static inline void
|
static inline void
|
sbic_arm_write (unsigned int io_port, int reg, int value)
|
sbic_arm_write (unsigned int io_port, int reg, int value)
|
{
|
{
|
outb_t (reg, io_port);
|
outb_t (reg, io_port);
|
outb_t (value, io_port + 4);
|
outb_t (value, io_port + 4);
|
}
|
}
|
|
|
#define sbic_arm_writenext(io,val) \
|
#define sbic_arm_writenext(io,val) \
|
outb_t ((val), (io) + 4)
|
outb_t ((val), (io) + 4)
|
|
|
static inline
|
static inline
|
int sbic_arm_read (unsigned int io_port, int reg)
|
int sbic_arm_read (unsigned int io_port, int reg)
|
{
|
{
|
if(reg == ASR)
|
if(reg == ASR)
|
return inl_t(io_port) & 255;
|
return inl_t(io_port) & 255;
|
outb_t(reg, io_port);
|
outb_t(reg, io_port);
|
return inl_t(io_port + 4) & 255;
|
return inl_t(io_port + 4) & 255;
|
}
|
}
|
|
|
#define sbic_arm_readnext(io) \
|
#define sbic_arm_readnext(io) \
|
inb_t((io) + 4)
|
inb_t((io) + 4)
|
|
|
#define dmac_read(io_port,reg) \
|
#define dmac_read(io_port,reg) \
|
inb ((io_port) + (reg))
|
inb ((io_port) + (reg))
|
|
|
#define dmac_write(io_port,reg,value) \
|
#define dmac_write(io_port,reg,value) \
|
({ outb ((value), (io_port) + (reg)); })
|
({ outb ((value), (io_port) + (reg)); })
|
|
|
#define dmac_clearintr(io_port) \
|
#define dmac_clearintr(io_port) \
|
({ outb (0, (io_port)); })
|
({ outb (0, (io_port)); })
|
|
|
static inline
|
static inline
|
unsigned int dmac_address (unsigned int io_port)
|
unsigned int dmac_address (unsigned int io_port)
|
{
|
{
|
return dmac_read (io_port, TXADRHI) << 16 |
|
return dmac_read (io_port, TXADRHI) << 16 |
|
dmac_read (io_port, TXADRMD) << 8 |
|
dmac_read (io_port, TXADRMD) << 8 |
|
dmac_read (io_port, TXADRLO);
|
dmac_read (io_port, TXADRLO);
|
}
|
}
|
|
|
static
|
static
|
unsigned long acornscsi_sbic_xfcount (AS_Host *host)
|
unsigned long acornscsi_sbic_xfcount (AS_Host *host)
|
{
|
{
|
unsigned long length;
|
unsigned long length;
|
|
|
length = sbic_arm_read (host->scsi.io_port, TRANSCNTH) << 16;
|
length = sbic_arm_read (host->scsi.io_port, TRANSCNTH) << 16;
|
length |= sbic_arm_readnext (host->scsi.io_port) << 8;
|
length |= sbic_arm_readnext (host->scsi.io_port) << 8;
|
length |= sbic_arm_readnext (host->scsi.io_port);
|
length |= sbic_arm_readnext (host->scsi.io_port);
|
|
|
return length;
|
return length;
|
}
|
}
|
|
|
static
|
static
|
int acornscsi_sbic_issuecmd (AS_Host *host, int command)
|
int acornscsi_sbic_issuecmd (AS_Host *host, int command)
|
{
|
{
|
int asr;
|
int asr;
|
|
|
do {
|
do {
|
asr = sbic_arm_read (host->scsi.io_port, ASR);
|
asr = sbic_arm_read (host->scsi.io_port, ASR);
|
} while (asr & ASR_CIP);
|
} while (asr & ASR_CIP);
|
|
|
sbic_arm_write (host->scsi.io_port, CMND, command);
|
sbic_arm_write (host->scsi.io_port, CMND, command);
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
static void
|
static void
|
acornscsi_csdelay (unsigned int cs)
|
acornscsi_csdelay (unsigned int cs)
|
{
|
{
|
unsigned long target_jiffies, flags;
|
unsigned long target_jiffies, flags;
|
|
|
target_jiffies = jiffies + 1 + cs * HZ / 100;
|
target_jiffies = jiffies + 1 + cs * HZ / 100;
|
|
|
save_flags (flags);
|
save_flags (flags);
|
sti ();
|
sti ();
|
|
|
while (jiffies < target_jiffies) barrier();
|
while (jiffies < target_jiffies) barrier();
|
|
|
restore_flags (flags);
|
restore_flags (flags);
|
}
|
}
|
|
|
static
|
static
|
void acornscsi_resetcard (AS_Host *host)
|
void acornscsi_resetcard (AS_Host *host)
|
{
|
{
|
unsigned int i;
|
unsigned int i;
|
|
|
/* assert reset line */
|
/* assert reset line */
|
host->card.page_reg = 0x80;
|
host->card.page_reg = 0x80;
|
outb (host->card.page_reg, host->card.io_page);
|
outb (host->card.page_reg, host->card.io_page);
|
|
|
/* wait 3 cs. SCSI standard says 25ms. */
|
/* wait 3 cs. SCSI standard says 25ms. */
|
acornscsi_csdelay (3);
|
acornscsi_csdelay (3);
|
|
|
host->card.page_reg = 0;
|
host->card.page_reg = 0;
|
outb (host->card.page_reg, host->card.io_page);
|
outb (host->card.page_reg, host->card.io_page);
|
|
|
/*
|
/*
|
* Should get a reset from the card
|
* Should get a reset from the card
|
*/
|
*/
|
while (!(inb (host->card.io_intr) & 8));
|
while (!(inb (host->card.io_intr) & 8));
|
sbic_arm_read (host->scsi.io_port, ASR);
|
sbic_arm_read (host->scsi.io_port, ASR);
|
sbic_arm_read (host->scsi.io_port, SSR);
|
sbic_arm_read (host->scsi.io_port, SSR);
|
|
|
/* setup sbic - WD33C93A */
|
/* setup sbic - WD33C93A */
|
sbic_arm_write (host->scsi.io_port, OWNID, OWNID_EAF | host->host->this_id);
|
sbic_arm_write (host->scsi.io_port, OWNID, OWNID_EAF | host->host->this_id);
|
sbic_arm_write (host->scsi.io_port, CMND, CMND_RESET);
|
sbic_arm_write (host->scsi.io_port, CMND, CMND_RESET);
|
|
|
/*
|
/*
|
* Command should cause a reset interrupt
|
* Command should cause a reset interrupt
|
*/
|
*/
|
while (!(inb (host->card.io_intr) & 8));
|
while (!(inb (host->card.io_intr) & 8));
|
sbic_arm_read (host->scsi.io_port, ASR);
|
sbic_arm_read (host->scsi.io_port, ASR);
|
if (sbic_arm_read (host->scsi.io_port, SSR) != 0x01)
|
if (sbic_arm_read (host->scsi.io_port, SSR) != 0x01)
|
printk (KERN_CRIT "scsi%d: WD33C93A didn't give enhanced reset interrupt\n",
|
printk (KERN_CRIT "scsi%d: WD33C93A didn't give enhanced reset interrupt\n",
|
host->host->host_no);
|
host->host->host_no);
|
|
|
sbic_arm_write (host->scsi.io_port, CTRL, INIT_SBICDMA | CTRL_IDI);
|
sbic_arm_write (host->scsi.io_port, CTRL, INIT_SBICDMA | CTRL_IDI);
|
sbic_arm_write (host->scsi.io_port, TIMEOUT, TIMEOUT_TIME);
|
sbic_arm_write (host->scsi.io_port, TIMEOUT, TIMEOUT_TIME);
|
sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
|
sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
|
sbic_arm_write (host->scsi.io_port, SOURCEID, SOURCEID_ER | SOURCEID_DSP);
|
sbic_arm_write (host->scsi.io_port, SOURCEID, SOURCEID_ER | SOURCEID_DSP);
|
|
|
host->card.page_reg = 0x40;
|
host->card.page_reg = 0x40;
|
outb (host->card.page_reg, host->card.io_page);
|
outb (host->card.page_reg, host->card.io_page);
|
|
|
/* setup dmac - uPC71071 */
|
/* setup dmac - uPC71071 */
|
dmac_write (host->dma.io_port, INIT, 0);
|
dmac_write (host->dma.io_port, INIT, 0);
|
dmac_write (host->dma.io_port, INIT, INIT_8BIT);
|
dmac_write (host->dma.io_port, INIT, INIT_8BIT);
|
dmac_write (host->dma.io_port, CHANNEL, CHANNEL_0);
|
dmac_write (host->dma.io_port, CHANNEL, CHANNEL_0);
|
dmac_write (host->dma.io_port, DEVCON0, INIT_DEVCON0);
|
dmac_write (host->dma.io_port, DEVCON0, INIT_DEVCON0);
|
dmac_write (host->dma.io_port, DEVCON1, INIT_DEVCON1);
|
dmac_write (host->dma.io_port, DEVCON1, INIT_DEVCON1);
|
|
|
host->SCpnt = NULL;
|
host->SCpnt = NULL;
|
host->scsi.phase = PHASE_IDLE;
|
host->scsi.phase = PHASE_IDLE;
|
host->scsi.disconnectable = 0;
|
host->scsi.disconnectable = 0;
|
|
|
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
host->busyluns[i] = 0;
|
host->busyluns[i] = 0;
|
host->device[i].sync_state = SYNC_NEGOCIATE;
|
host->device[i].sync_state = SYNC_NEGOCIATE;
|
host->device[i].disconnect_ok = 1;
|
host->device[i].disconnect_ok = 1;
|
}
|
}
|
|
|
/* wait 25 cs. SCSI standard says 250ms. */
|
/* wait 25 cs. SCSI standard says 250ms. */
|
acornscsi_csdelay (25);
|
acornscsi_csdelay (25);
|
}
|
}
|
|
|
/*=============================================================================================
|
/*=============================================================================================
|
* Utility routines (eg. debug)
|
* Utility routines (eg. debug)
|
*/
|
*/
|
#ifdef CONFIG_ACORNSCSI_CONSTANTS
|
#ifdef CONFIG_ACORNSCSI_CONSTANTS
|
static char *acornscsi_interrupttype[] = {
|
static char *acornscsi_interrupttype[] = {
|
"rst", "suc", "p/a", "3",
|
"rst", "suc", "p/a", "3",
|
"term", "5", "6", "7",
|
"term", "5", "6", "7",
|
"serv", "9", "a", "b",
|
"serv", "9", "a", "b",
|
"c", "d", "e", "f"
|
"c", "d", "e", "f"
|
};
|
};
|
|
|
static signed char acornscsi_map[] = {
|
static signed char acornscsi_map[] = {
|
0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, 2, -1, -1, -1, -1, 3, -1, 4, 5, 6, 7, 8, 9, 10, 11,
|
-1, 2, -1, -1, -1, -1, 3, -1, 4, 5, 6, 7, 8, 9, 10, 11,
|
12, 13, 14, -1, -1, -1, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11,
|
12, 13, 14, -1, -1, -1, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
15, 16, 17, 18, 19, -1, -1, 20, 4, 5, 6, 7, 8, 9, 10, 11,
|
15, 16, 17, 18, 19, -1, -1, 20, 4, 5, 6, 7, 8, 9, 10, 11,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
21, 22, -1, -1, -1, 23, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11,
|
21, 22, -1, -1, -1, 23, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
|
};
|
};
|
|
|
static char *acornscsi_interruptcode[] = {
|
static char *acornscsi_interruptcode[] = {
|
/* 0 */
|
/* 0 */
|
"reset - normal mode", /* 00 */
|
"reset - normal mode", /* 00 */
|
"reset - advanced mode", /* 01 */
|
"reset - advanced mode", /* 01 */
|
|
|
/* 2 */
|
/* 2 */
|
"sel", /* 11 */
|
"sel", /* 11 */
|
"sel+xfer", /* 16 */
|
"sel+xfer", /* 16 */
|
"data-out", /* 18 */
|
"data-out", /* 18 */
|
"data-in", /* 19 */
|
"data-in", /* 19 */
|
"cmd", /* 1A */
|
"cmd", /* 1A */
|
"stat", /* 1B */
|
"stat", /* 1B */
|
"??-out", /* 1C */
|
"??-out", /* 1C */
|
"??-in", /* 1D */
|
"??-in", /* 1D */
|
"msg-out", /* 1E */
|
"msg-out", /* 1E */
|
"msg-in", /* 1F */
|
"msg-in", /* 1F */
|
|
|
/* 12 */
|
/* 12 */
|
"/ACK asserted", /* 20 */
|
"/ACK asserted", /* 20 */
|
"save-data-ptr", /* 21 */
|
"save-data-ptr", /* 21 */
|
"{re}sel", /* 22 */
|
"{re}sel", /* 22 */
|
|
|
/* 15 */
|
/* 15 */
|
"inv cmd", /* 40 */
|
"inv cmd", /* 40 */
|
"unexpected disconnect", /* 41 */
|
"unexpected disconnect", /* 41 */
|
"sel timeout", /* 42 */
|
"sel timeout", /* 42 */
|
"P err", /* 43 */
|
"P err", /* 43 */
|
"P err+ATN", /* 44 */
|
"P err+ATN", /* 44 */
|
"bad status byte", /* 47 */
|
"bad status byte", /* 47 */
|
|
|
/* 21 */
|
/* 21 */
|
"resel, no id", /* 80 */
|
"resel, no id", /* 80 */
|
"resel", /* 81 */
|
"resel", /* 81 */
|
"discon", /* 85 */
|
"discon", /* 85 */
|
};
|
};
|
|
|
static
|
static
|
void print_scsi_status (unsigned int ssr)
|
void print_scsi_status (unsigned int ssr)
|
{
|
{
|
if (acornscsi_map[ssr] != -1)
|
if (acornscsi_map[ssr] != -1)
|
printk ("%s:%s",
|
printk ("%s:%s",
|
acornscsi_interrupttype[(ssr >> 4)],
|
acornscsi_interrupttype[(ssr >> 4)],
|
acornscsi_interruptcode[acornscsi_map[ssr]]);
|
acornscsi_interruptcode[acornscsi_map[ssr]]);
|
else
|
else
|
printk ("%X:%X", ssr >> 4, ssr & 0x0f);
|
printk ("%X:%X", ssr >> 4, ssr & 0x0f);
|
}
|
}
|
#endif
|
#endif
|
|
|
static
|
static
|
void print_sbic_status (int asr, int ssr, int cmdphase)
|
void print_sbic_status (int asr, int ssr, int cmdphase)
|
{
|
{
|
#ifdef CONFIG_ACORNSCSI_CONSTANTS
|
#ifdef CONFIG_ACORNSCSI_CONSTANTS
|
printk ("sbic: %c%c%c%c%c%c ",
|
printk ("sbic: %c%c%c%c%c%c ",
|
asr & ASR_INT ? 'I' : 'i',
|
asr & ASR_INT ? 'I' : 'i',
|
asr & ASR_LCI ? 'L' : 'l',
|
asr & ASR_LCI ? 'L' : 'l',
|
asr & ASR_BSY ? 'B' : 'b',
|
asr & ASR_BSY ? 'B' : 'b',
|
asr & ASR_CIP ? 'C' : 'c',
|
asr & ASR_CIP ? 'C' : 'c',
|
asr & ASR_PE ? 'P' : 'p',
|
asr & ASR_PE ? 'P' : 'p',
|
asr & ASR_DBR ? 'D' : 'd');
|
asr & ASR_DBR ? 'D' : 'd');
|
printk ("scsi: ");
|
printk ("scsi: ");
|
print_scsi_status (ssr);
|
print_scsi_status (ssr);
|
printk (" ph %02X\n", cmdphase);
|
printk (" ph %02X\n", cmdphase);
|
#else
|
#else
|
printk ("sbic: %02X scsi: %X:%X ph: %02X\n",
|
printk ("sbic: %02X scsi: %X:%X ph: %02X\n",
|
asr, (ssr & 0xf0)>>4, ssr & 0x0f, cmdphase);
|
asr, (ssr & 0xf0)>>4, ssr & 0x0f, cmdphase);
|
#endif
|
#endif
|
}
|
}
|
|
|
static
|
static
|
void acornscsi_dumplog (AS_Host *host, int target)
|
void acornscsi_dumplog (AS_Host *host, int target)
|
{
|
{
|
unsigned int prev;
|
unsigned int prev;
|
do {
|
do {
|
signed int statptr;
|
signed int statptr;
|
|
|
printk ("%c:", target == 8 ? 'H' : ('0' + target));
|
printk ("%c:", target == 8 ? 'H' : ('0' + target));
|
statptr = status_ptr[target] - 10;
|
statptr = status_ptr[target] - 10;
|
|
|
if (statptr < 0)
|
if (statptr < 0)
|
statptr += 16;
|
statptr += 16;
|
|
|
prev = status[target][statptr].when;
|
prev = status[target][statptr].when;
|
|
|
for (; statptr != status_ptr[target]; statptr = (statptr + 1) & 15) {
|
for (; statptr != status_ptr[target]; statptr = (statptr + 1) & 15) {
|
if (status[target][statptr].when) {
|
if (status[target][statptr].when) {
|
#ifdef CONFIG_ACORNSCSI_CONSTANTS
|
#ifdef CONFIG_ACORNSCSI_CONSTANTS
|
printk ("%c%02X:S=",
|
printk ("%c%02X:S=",
|
status[target][statptr].irq ? '-' : ' ',
|
status[target][statptr].irq ? '-' : ' ',
|
status[target][statptr].ph);
|
status[target][statptr].ph);
|
print_scsi_status (status[target][statptr].ssr);
|
print_scsi_status (status[target][statptr].ssr);
|
#else
|
#else
|
printk ("%c%02X:%02X",
|
printk ("%c%02X:%02X",
|
status[target][statptr].irq ? '-' : ' ',
|
status[target][statptr].irq ? '-' : ' ',
|
status[target][statptr].ph,
|
status[target][statptr].ph,
|
status[target][statptr].ssr);
|
status[target][statptr].ssr);
|
#endif
|
#endif
|
printk ("+%02ld",
|
printk ("+%02ld",
|
(status[target][statptr].when - prev) < 100 ?
|
(status[target][statptr].when - prev) < 100 ?
|
(status[target][statptr].when - prev) : 99);
|
(status[target][statptr].when - prev) : 99);
|
prev = status[target][statptr].when;
|
prev = status[target][statptr].when;
|
}
|
}
|
}
|
}
|
printk ("\n");
|
printk ("\n");
|
if (target == 8)
|
if (target == 8)
|
break;
|
break;
|
target = 8;
|
target = 8;
|
} while (1);
|
} while (1);
|
}
|
}
|
|
|
static
|
static
|
char acornscsi_target (AS_Host *host)
|
char acornscsi_target (AS_Host *host)
|
{
|
{
|
if (host->SCpnt)
|
if (host->SCpnt)
|
return '0' + host->SCpnt->target;
|
return '0' + host->SCpnt->target;
|
return 'H';
|
return 'H';
|
}
|
}
|
|
|
static
|
static
|
void acornscsi_dumpdma (AS_Host *host, char *where)
|
void acornscsi_dumpdma (AS_Host *host, char *where)
|
{
|
{
|
unsigned int mode, addr, len;
|
unsigned int mode, addr, len;
|
|
|
mode = dmac_read (host->dma.io_port, MODECON);
|
mode = dmac_read (host->dma.io_port, MODECON);
|
addr = dmac_address (host->dma.io_port);
|
addr = dmac_address (host->dma.io_port);
|
len = dmac_read (host->dma.io_port, TXCNTHI) << 8 |
|
len = dmac_read (host->dma.io_port, TXCNTHI) << 8 |
|
dmac_read (host->dma.io_port, TXCNTLO);
|
dmac_read (host->dma.io_port, TXCNTLO);
|
|
|
printk ("scsi%d: %s: DMAC %02x @%06x+%04x msk %02x, ",
|
printk ("scsi%d: %s: DMAC %02x @%06x+%04x msk %02x, ",
|
host->host->host_no, where,
|
host->host->host_no, where,
|
mode, addr, (len + 1) & 0xffff,
|
mode, addr, (len + 1) & 0xffff,
|
dmac_read (host->dma.io_port, MASKREG));
|
dmac_read (host->dma.io_port, MASKREG));
|
|
|
printk ("DMA @%06x, ", host->dma.start_addr);
|
printk ("DMA @%06x, ", host->dma.start_addr);
|
printk ("BH @%p +%04x, ", host->scsi.SCp.ptr,
|
printk ("BH @%p +%04x, ", host->scsi.SCp.ptr,
|
host->scsi.SCp.this_residual);
|
host->scsi.SCp.this_residual);
|
printk ("DT @+%04x ST @+%04x", host->dma.transferred,
|
printk ("DT @+%04x ST @+%04x", host->dma.transferred,
|
host->scsi.SCp.have_data_in);
|
host->scsi.SCp.have_data_in);
|
printk ("\n");
|
printk ("\n");
|
}
|
}
|
|
|
/*
|
/*
|
* Prototype: cmdtype_t acornscsi_cmdtype (int command)
|
* Prototype: cmdtype_t acornscsi_cmdtype (int command)
|
* Purpose : differentiate READ from WRITE from other commands
|
* Purpose : differentiate READ from WRITE from other commands
|
* Params : command - command to interpret
|
* Params : command - command to interpret
|
* Returns : CMD_READ - command reads data,
|
* Returns : CMD_READ - command reads data,
|
* CMD_WRITE - command writes data,
|
* CMD_WRITE - command writes data,
|
* CMD_MISC - everything else
|
* CMD_MISC - everything else
|
*/
|
*/
|
static inline
|
static inline
|
cmdtype_t acornscsi_cmdtype (int command)
|
cmdtype_t acornscsi_cmdtype (int command)
|
{
|
{
|
switch (command) {
|
switch (command) {
|
case WRITE_6: case WRITE_10: case WRITE_12:
|
case WRITE_6: case WRITE_10: case WRITE_12:
|
return CMD_WRITE;
|
return CMD_WRITE;
|
case READ_6: case READ_10: case READ_12:
|
case READ_6: case READ_10: case READ_12:
|
return CMD_READ;
|
return CMD_READ;
|
default:
|
default:
|
return CMD_MISC;
|
return CMD_MISC;
|
}
|
}
|
}
|
}
|
|
|
/*
|
/*
|
* Prototype: int acornscsi_datadirection (int command)
|
* Prototype: int acornscsi_datadirection (int command)
|
* Purpose : differentiate between commands that have a DATA IN phase
|
* Purpose : differentiate between commands that have a DATA IN phase
|
* and a DATA OUT phase
|
* and a DATA OUT phase
|
* Params : command - command to interpret
|
* Params : command - command to interpret
|
* Returns : DATADIR_OUT - data out phase expected
|
* Returns : DATADIR_OUT - data out phase expected
|
* DATADIR_IN - data in phase expected
|
* DATADIR_IN - data in phase expected
|
*/
|
*/
|
static
|
static
|
datadir_t acornscsi_datadirection (int command)
|
datadir_t acornscsi_datadirection (int command)
|
{
|
{
|
switch (command) {
|
switch (command) {
|
case CHANGE_DEFINITION: case COMPARE: case COPY:
|
case CHANGE_DEFINITION: case COMPARE: case COPY:
|
case COPY_VERIFY: case LOG_SELECT: case MODE_SELECT:
|
case COPY_VERIFY: case LOG_SELECT: case MODE_SELECT:
|
case MODE_SELECT_10: case SEND_DIAGNOSTIC: case WRITE_BUFFER:
|
case MODE_SELECT_10: case SEND_DIAGNOSTIC: case WRITE_BUFFER:
|
case FORMAT_UNIT: case REASSIGN_BLOCKS: case RESERVE:
|
case FORMAT_UNIT: case REASSIGN_BLOCKS: case RESERVE:
|
case SEARCH_EQUAL: case SEARCH_HIGH: case SEARCH_LOW:
|
case SEARCH_EQUAL: case SEARCH_HIGH: case SEARCH_LOW:
|
case WRITE_6: case WRITE_10: case WRITE_VERIFY:
|
case WRITE_6: case WRITE_10: case WRITE_VERIFY:
|
case UPDATE_BLOCK: case WRITE_LONG: case WRITE_SAME:
|
case UPDATE_BLOCK: case WRITE_LONG: case WRITE_SAME:
|
case SEARCH_HIGH_12: case SEARCH_EQUAL_12: case SEARCH_LOW_12:
|
case SEARCH_HIGH_12: case SEARCH_EQUAL_12: case SEARCH_LOW_12:
|
case WRITE_12: case WRITE_VERIFY_12: case SET_WINDOW:
|
case WRITE_12: case WRITE_VERIFY_12: case SET_WINDOW:
|
case MEDIUM_SCAN: case SEND_VOLUME_TAG: case 0xea:
|
case MEDIUM_SCAN: case SEND_VOLUME_TAG: case 0xea:
|
return DATADIR_OUT;
|
return DATADIR_OUT;
|
default:
|
default:
|
return DATADIR_IN;
|
return DATADIR_IN;
|
}
|
}
|
}
|
}
|
|
|
/*
|
/*
|
* Purpose : provide values for synchronous transfers with 33C93.
|
* Purpose : provide values for synchronous transfers with 33C93.
|
* Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
|
* Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
|
* Modified by Russell King for 8MHz WD33C93A
|
* Modified by Russell King for 8MHz WD33C93A
|
*/
|
*/
|
static struct sync_xfer_tbl {
|
static struct sync_xfer_tbl {
|
unsigned int period_ns;
|
unsigned int period_ns;
|
unsigned char reg_value;
|
unsigned char reg_value;
|
} sync_xfer_table[] = {
|
} sync_xfer_table[] = {
|
{ 1, 0x20 }, { 249, 0x20 }, { 374, 0x30 },
|
{ 1, 0x20 }, { 249, 0x20 }, { 374, 0x30 },
|
{ 499, 0x40 }, { 624, 0x50 }, { 749, 0x60 },
|
{ 499, 0x40 }, { 624, 0x50 }, { 749, 0x60 },
|
{ 874, 0x70 }, { 999, 0x00 }, { 0, 0 }
|
{ 874, 0x70 }, { 999, 0x00 }, { 0, 0 }
|
};
|
};
|
|
|
/*
|
/*
|
* Prototype: int acornscsi_getperiod (unsigned char syncxfer)
|
* Prototype: int acornscsi_getperiod (unsigned char syncxfer)
|
* Purpose : period for the synchronous transfer setting
|
* Purpose : period for the synchronous transfer setting
|
* Params : syncxfer SYNCXFER register value
|
* Params : syncxfer SYNCXFER register value
|
* Returns : period in ns.
|
* Returns : period in ns.
|
*/
|
*/
|
static
|
static
|
int acornscsi_getperiod (unsigned char syncxfer)
|
int acornscsi_getperiod (unsigned char syncxfer)
|
{
|
{
|
int i;
|
int i;
|
|
|
syncxfer &= 0xf0;
|
syncxfer &= 0xf0;
|
if (syncxfer == 0x10)
|
if (syncxfer == 0x10)
|
syncxfer = 0;
|
syncxfer = 0;
|
|
|
for (i = 1; sync_xfer_table[i].period_ns; i++)
|
for (i = 1; sync_xfer_table[i].period_ns; i++)
|
if (syncxfer == sync_xfer_table[i].reg_value)
|
if (syncxfer == sync_xfer_table[i].reg_value)
|
return sync_xfer_table[i].period_ns;
|
return sync_xfer_table[i].period_ns;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*
|
/*
|
* Prototype: int round_period (unsigned int period)
|
* Prototype: int round_period (unsigned int period)
|
* Purpose : return index into above table for a required REQ period
|
* Purpose : return index into above table for a required REQ period
|
* Params : period - time (ns) for REQ
|
* Params : period - time (ns) for REQ
|
* Returns : table index
|
* Returns : table index
|
* Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
|
* Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
|
*/
|
*/
|
static inline
|
static inline
|
int round_period (unsigned int period)
|
int round_period (unsigned int period)
|
{
|
{
|
int i;
|
int i;
|
|
|
for (i = 1; sync_xfer_table[i].period_ns; i++) {
|
for (i = 1; sync_xfer_table[i].period_ns; i++) {
|
if ((period <= sync_xfer_table[i].period_ns) &&
|
if ((period <= sync_xfer_table[i].period_ns) &&
|
(period > sync_xfer_table[i - 1].period_ns))
|
(period > sync_xfer_table[i - 1].period_ns))
|
return i;
|
return i;
|
}
|
}
|
return 7;
|
return 7;
|
}
|
}
|
|
|
/*
|
/*
|
* Prototype: unsigned char calc_sync_xfer (unsigned int period, unsigned int offset)
|
* Prototype: unsigned char calc_sync_xfer (unsigned int period, unsigned int offset)
|
* Purpose : calculate value for 33c93s SYNC register
|
* Purpose : calculate value for 33c93s SYNC register
|
* Params : period - time (ns) for REQ
|
* Params : period - time (ns) for REQ
|
* offset - offset in bytes between REQ/ACK
|
* offset - offset in bytes between REQ/ACK
|
* Returns : value for SYNC register
|
* Returns : value for SYNC register
|
* Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
|
* Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
|
*/
|
*/
|
static
|
static
|
unsigned char calc_sync_xfer (unsigned int period, unsigned int offset)
|
unsigned char calc_sync_xfer (unsigned int period, unsigned int offset)
|
{
|
{
|
return sync_xfer_table[round_period(period)].reg_value |
|
return sync_xfer_table[round_period(period)].reg_value |
|
((offset < SDTR_SIZE) ? offset : SDTR_SIZE);
|
((offset < SDTR_SIZE) ? offset : SDTR_SIZE);
|
}
|
}
|
|
|
/* ====================================================================================
|
/* ====================================================================================
|
* Command functions
|
* Command functions
|
*/
|
*/
|
/*
|
/*
|
* Function: acornscsi_kick (AS_Host *host)
|
* Function: acornscsi_kick (AS_Host *host)
|
* Purpose : kick next command to interface
|
* Purpose : kick next command to interface
|
* Params : host - host to send command to
|
* Params : host - host to send command to
|
* Returns : INTR_IDLE if idle, otherwise INTR_PROCESSING
|
* Returns : INTR_IDLE if idle, otherwise INTR_PROCESSING
|
* Notes : interrupts are always disabled!
|
* Notes : interrupts are always disabled!
|
*/
|
*/
|
static
|
static
|
intr_ret_t acornscsi_kick (AS_Host *host)
|
intr_ret_t acornscsi_kick (AS_Host *host)
|
{
|
{
|
int from_queue = 0;
|
int from_queue = 0;
|
Scsi_Cmnd *SCpnt;
|
Scsi_Cmnd *SCpnt;
|
|
|
/* first check to see if a command is waiting to be executed */
|
/* first check to see if a command is waiting to be executed */
|
SCpnt = host->origSCpnt;
|
SCpnt = host->origSCpnt;
|
host->origSCpnt = NULL;
|
host->origSCpnt = NULL;
|
|
|
/* retrieve next command */
|
/* retrieve next command */
|
if (!SCpnt) {
|
if (!SCpnt) {
|
SCpnt = queue_remove_exclude (&host->queues.issue, host->busyluns);
|
SCpnt = queue_remove_exclude (&host->queues.issue, host->busyluns);
|
if (!SCpnt)
|
if (!SCpnt)
|
return INTR_IDLE;
|
return INTR_IDLE;
|
|
|
from_queue = 1;
|
from_queue = 1;
|
}
|
}
|
|
|
if (host->scsi.disconnectable && host->SCpnt) {
|
if (host->scsi.disconnectable && host->SCpnt) {
|
queue_add_cmd_tail (&host->queues.disconnected, host->SCpnt);
|
queue_add_cmd_tail (&host->queues.disconnected, host->SCpnt);
|
host->scsi.disconnectable = 0;
|
host->scsi.disconnectable = 0;
|
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
|
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
|
DBG(host->SCpnt, printk ("scsi%d.%c: moved command to disconnected queue\n",
|
DBG(host->SCpnt, printk ("scsi%d.%c: moved command to disconnected queue\n",
|
host->host->host_no, acornscsi_target (host)));
|
host->host->host_no, acornscsi_target (host)));
|
#endif
|
#endif
|
host->SCpnt = NULL;
|
host->SCpnt = NULL;
|
}
|
}
|
|
|
/*
|
/*
|
* If we have an interrupt pending, then we may have been reselected.
|
* If we have an interrupt pending, then we may have been reselected.
|
* In this case, we don't want to write to the registers
|
* In this case, we don't want to write to the registers
|
*/
|
*/
|
if (!(sbic_arm_read (host->scsi.io_port, ASR) & (ASR_INT|ASR_BSY|ASR_CIP))) {
|
if (!(sbic_arm_read (host->scsi.io_port, ASR) & (ASR_INT|ASR_BSY|ASR_CIP))) {
|
sbic_arm_write (host->scsi.io_port, DESTID, SCpnt->target);
|
sbic_arm_write (host->scsi.io_port, DESTID, SCpnt->target);
|
sbic_arm_write (host->scsi.io_port, CMND, CMND_SELWITHATN);
|
sbic_arm_write (host->scsi.io_port, CMND, CMND_SELWITHATN);
|
}
|
}
|
|
|
/*
|
/*
|
* claim host busy - all of these must happen atomically wrt
|
* claim host busy - all of these must happen atomically wrt
|
* our interrupt routine. Failure means command loss.
|
* our interrupt routine. Failure means command loss.
|
*/
|
*/
|
host->scsi.phase = PHASE_CONNECTING;
|
host->scsi.phase = PHASE_CONNECTING;
|
host->SCpnt = SCpnt;
|
host->SCpnt = SCpnt;
|
host->scsi.SCp = SCpnt->SCp;
|
host->scsi.SCp = SCpnt->SCp;
|
host->dma.xfer_setup = 0;
|
host->dma.xfer_setup = 0;
|
host->dma.xfer_required = 0;
|
host->dma.xfer_required = 0;
|
|
|
#if (DEBUG & (DEBUG_ABORT|DEBUG_CONNECT))
|
#if (DEBUG & (DEBUG_ABORT|DEBUG_CONNECT))
|
DBG(SCpnt,printk ("scsi%d.%c: starting cmd %02X\n",
|
DBG(SCpnt,printk ("scsi%d.%c: starting cmd %02X\n",
|
host->host->host_no, '0' + SCpnt->target,
|
host->host->host_no, '0' + SCpnt->target,
|
SCpnt->cmnd[0]));
|
SCpnt->cmnd[0]));
|
#endif
|
#endif
|
|
|
if (from_queue) {
|
if (from_queue) {
|
#ifdef SCSI2_TAG
|
#ifdef SCSI2_TAG
|
/*
|
/*
|
* tagged queueing - allocate a new tag to this command
|
* tagged queueing - allocate a new tag to this command
|
*/
|
*/
|
if (SCpnt->device->tagged_queue) {
|
if (SCpnt->device->tagged_queue) {
|
SCpnt->device->current_tag += 1;
|
SCpnt->device->current_tag += 1;
|
if (SCpnt->device->current_tag == 0)
|
if (SCpnt->device->current_tag == 0)
|
SCpnt->device->current_tag = 1;
|
SCpnt->device->current_tag = 1;
|
SCpnt->tag = SCpnt->device->current_tag;
|
SCpnt->tag = SCpnt->device->current_tag;
|
} else
|
} else
|
#endif
|
#endif
|
set_bit (SCpnt->target * 8 + SCpnt->lun, host->busyluns);
|
set_bit (SCpnt->target * 8 + SCpnt->lun, host->busyluns);
|
|
|
host->stats.removes += 1;
|
host->stats.removes += 1;
|
|
|
switch (acornscsi_cmdtype (SCpnt->cmnd[0])) {
|
switch (acornscsi_cmdtype (SCpnt->cmnd[0])) {
|
case CMD_WRITE:
|
case CMD_WRITE:
|
host->stats.writes += 1;
|
host->stats.writes += 1;
|
break;
|
break;
|
case CMD_READ:
|
case CMD_READ:
|
host->stats.reads += 1;
|
host->stats.reads += 1;
|
break;
|
break;
|
case CMD_MISC:
|
case CMD_MISC:
|
host->stats.miscs += 1;
|
host->stats.miscs += 1;
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
return INTR_PROCESSING;
|
return INTR_PROCESSING;
|
}
|
}
|
|
|
/*
|
/*
|
* Function: void acornscsi_done (AS_Host *host, Scsi_Cmnd **SCpntp, unsigned int result)
|
* Function: void acornscsi_done (AS_Host *host, Scsi_Cmnd **SCpntp, unsigned int result)
|
* Purpose : complete processing for command
|
* Purpose : complete processing for command
|
* Params : host - interface that completed
|
* Params : host - interface that completed
|
* result - driver byte of result
|
* result - driver byte of result
|
*/
|
*/
|
static
|
static
|
void acornscsi_done (AS_Host *host, Scsi_Cmnd **SCpntp, unsigned int result)
|
void acornscsi_done (AS_Host *host, Scsi_Cmnd **SCpntp, unsigned int result)
|
{
|
{
|
Scsi_Cmnd *SCpnt = *SCpntp;
|
Scsi_Cmnd *SCpnt = *SCpntp;
|
|
|
/* clean up */
|
/* clean up */
|
sbic_arm_write (host->scsi.io_port, SOURCEID, SOURCEID_ER | SOURCEID_DSP);
|
sbic_arm_write (host->scsi.io_port, SOURCEID, SOURCEID_ER | SOURCEID_DSP);
|
|
|
host->stats.fins += 1;
|
host->stats.fins += 1;
|
|
|
if (SCpnt) {
|
if (SCpnt) {
|
*SCpntp = NULL;
|
*SCpntp = NULL;
|
|
|
acornscsi_dma_cleanup (host);
|
acornscsi_dma_cleanup (host);
|
|
|
SCpnt->result = result << 16 | host->scsi.SCp.Message << 8 | host->scsi.SCp.Status;
|
SCpnt->result = result << 16 | host->scsi.SCp.Message << 8 | host->scsi.SCp.Status;
|
|
|
/*
|
/*
|
* In theory, this should not happen. In practice, it seems to.
|
* In theory, this should not happen. In practice, it seems to.
|
* Only trigger an error if the device attempts to report all happy
|
* Only trigger an error if the device attempts to report all happy
|
* but with untransferred buffers... If we don't do something, then
|
* but with untransferred buffers... If we don't do something, then
|
* data loss will occur. Should we check SCpnt->underflow here?
|
* data loss will occur. Should we check SCpnt->underflow here?
|
* It doesn't appear to be set to something meaningful by the higher
|
* It doesn't appear to be set to something meaningful by the higher
|
* levels all the time.
|
* levels all the time.
|
*/
|
*/
|
if (host->scsi.SCp.ptr && result == DID_OK &&
|
if (host->scsi.SCp.ptr && result == DID_OK &&
|
acornscsi_cmdtype (SCpnt->cmnd[0]) != CMD_MISC) {
|
acornscsi_cmdtype (SCpnt->cmnd[0]) != CMD_MISC) {
|
switch (status_byte (SCpnt->result)) {
|
switch (status_byte (SCpnt->result)) {
|
case CHECK_CONDITION:
|
case CHECK_CONDITION:
|
case COMMAND_TERMINATED:
|
case COMMAND_TERMINATED:
|
case BUSY:
|
case BUSY:
|
case QUEUE_FULL:
|
case QUEUE_FULL:
|
case RESERVATION_CONFLICT:
|
case RESERVATION_CONFLICT:
|
break;
|
break;
|
|
|
default:
|
default:
|
printk (KERN_ERR "scsi%d.H: incomplete data transfer detected: result=%08X command=",
|
printk (KERN_ERR "scsi%d.H: incomplete data transfer detected: result=%08X command=",
|
host->host->host_no, SCpnt->result);
|
host->host->host_no, SCpnt->result);
|
print_command (SCpnt->cmnd);
|
print_command (SCpnt->cmnd);
|
acornscsi_dumpdma (host, "done");
|
acornscsi_dumpdma (host, "done");
|
acornscsi_dumplog (host, SCpnt->target);
|
acornscsi_dumplog (host, SCpnt->target);
|
SCpnt->result &= 0xffff;
|
SCpnt->result &= 0xffff;
|
SCpnt->result |= DID_ERROR << 16;
|
SCpnt->result |= DID_ERROR << 16;
|
}
|
}
|
}
|
}
|
|
|
if (!SCpnt->scsi_done)
|
if (!SCpnt->scsi_done)
|
panic ("scsi%d.H: null scsi_done function in acornscsi_done", host->host->host_no);
|
panic ("scsi%d.H: null scsi_done function in acornscsi_done", host->host->host_no);
|
|
|
clear_bit (SCpnt->target * 8 + SCpnt->lun, host->busyluns);
|
clear_bit (SCpnt->target * 8 + SCpnt->lun, host->busyluns);
|
|
|
SCpnt->scsi_done (SCpnt);
|
SCpnt->scsi_done (SCpnt);
|
} else
|
} else
|
printk ("scsi%d: null command in acornscsi_done", host->host->host_no);
|
printk ("scsi%d: null command in acornscsi_done", host->host->host_no);
|
|
|
host->scsi.phase = PHASE_IDLE;
|
host->scsi.phase = PHASE_IDLE;
|
}
|
}
|
|
|
/* ====================================================================================
|
/* ====================================================================================
|
* DMA routines
|
* DMA routines
|
*/
|
*/
|
/*
|
/*
|
* Purpose : update SCSI Data Pointer
|
* Purpose : update SCSI Data Pointer
|
* Notes : this will only be one SG entry or less
|
* Notes : this will only be one SG entry or less
|
*/
|
*/
|
static
|
static
|
void acornscsi_data_updateptr (AS_Host *host, Scsi_Pointer *SCp, unsigned int length)
|
void acornscsi_data_updateptr (AS_Host *host, Scsi_Pointer *SCp, unsigned int length)
|
{
|
{
|
SCp->ptr += length;
|
SCp->ptr += length;
|
SCp->this_residual -= length;
|
SCp->this_residual -= length;
|
|
|
if (!SCp->this_residual) {
|
if (!SCp->this_residual) {
|
if (SCp->buffers_residual) {
|
if (SCp->buffers_residual) {
|
SCp->buffer++;
|
SCp->buffer++;
|
SCp->buffers_residual--;
|
SCp->buffers_residual--;
|
SCp->ptr = (char *)SCp->buffer->address;
|
SCp->ptr = (char *)SCp->buffer->address;
|
SCp->this_residual = SCp->buffer->length;
|
SCp->this_residual = SCp->buffer->length;
|
} else
|
} else
|
SCp->ptr = NULL;
|
SCp->ptr = NULL;
|
}
|
}
|
}
|
}
|
|
|
/*
|
/*
|
* Prototype: void acornscsi_data_read (AS_Host *host, char *ptr,
|
* Prototype: void acornscsi_data_read (AS_Host *host, char *ptr,
|
* unsigned int start_addr, unsigned int length)
|
* unsigned int start_addr, unsigned int length)
|
* Purpose : read data from DMA RAM
|
* Purpose : read data from DMA RAM
|
* Params : host - host to transfer from
|
* Params : host - host to transfer from
|
* ptr - DRAM address
|
* ptr - DRAM address
|
* start_addr - host mem address
|
* start_addr - host mem address
|
* length - number of bytes to transfer
|
* length - number of bytes to transfer
|
* Notes : this will only be one SG entry or less
|
* Notes : this will only be one SG entry or less
|
*/
|
*/
|
static
|
static
|
void acornscsi_data_read (AS_Host *host, char *ptr,
|
void acornscsi_data_read (AS_Host *host, char *ptr,
|
unsigned int start_addr, unsigned int length)
|
unsigned int start_addr, unsigned int length)
|
{
|
{
|
extern void __acornscsi_in (int port, char *buf, int len);
|
extern void __acornscsi_in (int port, char *buf, int len);
|
unsigned int page, offset, len = length;
|
unsigned int page, offset, len = length;
|
|
|
page = (start_addr >> 12);
|
page = (start_addr >> 12);
|
offset = start_addr & ((1 << 12) - 1);
|
offset = start_addr & ((1 << 12) - 1);
|
|
|
outb ((page & 0x3f) | host->card.page_reg, host->card.io_page);
|
outb ((page & 0x3f) | host->card.page_reg, host->card.io_page);
|
|
|
while (len > 0) {
|
while (len > 0) {
|
unsigned int this_len;
|
unsigned int this_len;
|
|
|
if (len + offset > (1 << 12))
|
if (len + offset > (1 << 12))
|
this_len = (1 << 12) - offset;
|
this_len = (1 << 12) - offset;
|
else
|
else
|
this_len = len;
|
this_len = len;
|
|
|
__acornscsi_in (host->card.io_ram + (offset << 1), ptr, this_len);
|
__acornscsi_in (host->card.io_ram + (offset << 1), ptr, this_len);
|
|
|
offset += this_len;
|
offset += this_len;
|
ptr += this_len;
|
ptr += this_len;
|
len -= this_len;
|
len -= this_len;
|
|
|
if (offset == (1 << 12)) {
|
if (offset == (1 << 12)) {
|
offset = 0;
|
offset = 0;
|
page ++;
|
page ++;
|
outb ((page & 0x3f) | host->card.page_reg, host->card.io_page);
|
outb ((page & 0x3f) | host->card.page_reg, host->card.io_page);
|
}
|
}
|
}
|
}
|
outb (host->card.page_reg, host->card.io_page);
|
outb (host->card.page_reg, host->card.io_page);
|
}
|
}
|
|
|
/*
|
/*
|
* Prototype: void acornscsi_data_write (AS_Host *host, char *ptr,
|
* Prototype: void acornscsi_data_write (AS_Host *host, char *ptr,
|
* unsigned int start_addr, unsigned int length)
|
* unsigned int start_addr, unsigned int length)
|
* Purpose : write data to DMA RAM
|
* Purpose : write data to DMA RAM
|
* Params : host - host to transfer from
|
* Params : host - host to transfer from
|
* ptr - DRAM address
|
* ptr - DRAM address
|
* start_addr - host mem address
|
* start_addr - host mem address
|
* length - number of bytes to transfer
|
* length - number of bytes to transfer
|
* Notes : this will only be one SG entry or less
|
* Notes : this will only be one SG entry or less
|
*/
|
*/
|
static
|
static
|
void acornscsi_data_write (AS_Host *host, char *ptr,
|
void acornscsi_data_write (AS_Host *host, char *ptr,
|
unsigned int start_addr, unsigned int length)
|
unsigned int start_addr, unsigned int length)
|
{
|
{
|
extern void __acornscsi_out (int port, char *buf, int len);
|
extern void __acornscsi_out (int port, char *buf, int len);
|
unsigned int page, offset, len = length;
|
unsigned int page, offset, len = length;
|
|
|
page = (start_addr >> 12);
|
page = (start_addr >> 12);
|
offset = start_addr & ((1 << 12) - 1);
|
offset = start_addr & ((1 << 12) - 1);
|
|
|
outb ((page & 0x3f) | host->card.page_reg, host->card.io_page);
|
outb ((page & 0x3f) | host->card.page_reg, host->card.io_page);
|
|
|
while (len > 0) {
|
while (len > 0) {
|
unsigned int this_len;
|
unsigned int this_len;
|
|
|
if (len + offset > (1 << 12))
|
if (len + offset > (1 << 12))
|
this_len = (1 << 12) - offset;
|
this_len = (1 << 12) - offset;
|
else
|
else
|
this_len = len;
|
this_len = len;
|
|
|
__acornscsi_out (host->card.io_ram + (offset << 1), ptr, this_len);
|
__acornscsi_out (host->card.io_ram + (offset << 1), ptr, this_len);
|
|
|
offset += this_len;
|
offset += this_len;
|
ptr += this_len;
|
ptr += this_len;
|
len -= this_len;
|
len -= this_len;
|
|
|
if (offset == (1 << 12)) {
|
if (offset == (1 << 12)) {
|
offset = 0;
|
offset = 0;
|
page ++;
|
page ++;
|
outb ((page & 0x3f) | host->card.page_reg, host->card.io_page);
|
outb ((page & 0x3f) | host->card.page_reg, host->card.io_page);
|
}
|
}
|
}
|
}
|
outb (host->card.page_reg, host->card.io_page);
|
outb (host->card.page_reg, host->card.io_page);
|
}
|
}
|
|
|
/* =========================================================================================
|
/* =========================================================================================
|
* On-board DMA routines
|
* On-board DMA routines
|
*/
|
*/
|
/*
|
/*
|
* Prototype: void acornscsi_dmastop (AS_Host *host)
|
* Prototype: void acornscsi_dmastop (AS_Host *host)
|
* Purpose : stop all DMA
|
* Purpose : stop all DMA
|
* Params : host - host on which to stop DMA
|
* Params : host - host on which to stop DMA
|
* Notes : This is called when leaving DATA IN/OUT phase,
|
* Notes : This is called when leaving DATA IN/OUT phase,
|
* or when interface is RESET
|
* or when interface is RESET
|
*/
|
*/
|
static inline
|
static inline
|
void acornscsi_dma_stop (AS_Host *host)
|
void acornscsi_dma_stop (AS_Host *host)
|
{
|
{
|
dmac_write (host->dma.io_port, MASKREG, MASK_ON);
|
dmac_write (host->dma.io_port, MASKREG, MASK_ON);
|
dmac_clearintr (host->dma.io_intr_clear);
|
dmac_clearintr (host->dma.io_intr_clear);
|
|
|
#if (DEBUG & DEBUG_DMA)
|
#if (DEBUG & DEBUG_DMA)
|
DBG(host->SCpnt, acornscsi_dumpdma (host, "stop"));
|
DBG(host->SCpnt, acornscsi_dumpdma (host, "stop"));
|
#endif
|
#endif
|
}
|
}
|
|
|
/*
|
/*
|
* Function: void acornscsi_dma_setup (AS_Host *host, dmadir_t direction)
|
* Function: void acornscsi_dma_setup (AS_Host *host, dmadir_t direction)
|
* Purpose : setup DMA controller for data transfer
|
* Purpose : setup DMA controller for data transfer
|
* Params : host - host to setup
|
* Params : host - host to setup
|
* direction - data transfer direction
|
* direction - data transfer direction
|
* Notes : This is called when entering DATA I/O phase, not
|
* Notes : This is called when entering DATA I/O phase, not
|
* while we're in a DATA I/O phase
|
* while we're in a DATA I/O phase
|
*/
|
*/
|
static
|
static
|
void acornscsi_dma_setup (AS_Host *host, dmadir_t direction)
|
void acornscsi_dma_setup (AS_Host *host, dmadir_t direction)
|
{
|
{
|
unsigned int address, length, mode;
|
unsigned int address, length, mode;
|
|
|
host->dma.direction = direction;
|
host->dma.direction = direction;
|
|
|
dmac_write (host->dma.io_port, MASKREG, MASK_ON);
|
dmac_write (host->dma.io_port, MASKREG, MASK_ON);
|
|
|
if (direction == DMA_OUT) {
|
if (direction == DMA_OUT) {
|
#if (DEBUG & DEBUG_NO_WRITE)
|
#if (DEBUG & DEBUG_NO_WRITE)
|
if (NO_WRITE & (1 << host->SCpnt->target)) {
|
if (NO_WRITE & (1 << host->SCpnt->target)) {
|
printk (KERN_CRIT "scsi%d.%c: I can't handle DMA_OUT!\n",
|
printk (KERN_CRIT "scsi%d.%c: I can't handle DMA_OUT!\n",
|
host->host->host_no, acornscsi_target (host));
|
host->host->host_no, acornscsi_target (host));
|
return;
|
return;
|
}
|
}
|
#endif
|
#endif
|
mode = DMAC_WRITE;
|
mode = DMAC_WRITE;
|
} else
|
} else
|
mode = DMAC_READ;
|
mode = DMAC_READ;
|
|
|
/*
|
/*
|
* Allocate some buffer space, limited to half the buffer size
|
* Allocate some buffer space, limited to half the buffer size
|
*/
|
*/
|
length = min (host->scsi.SCp.this_residual, DMAC_BUFFER_SIZE / 2);
|
length = min (host->scsi.SCp.this_residual, DMAC_BUFFER_SIZE / 2);
|
if (length) {
|
if (length) {
|
host->dma.start_addr = address = host->dma.free_addr;
|
host->dma.start_addr = address = host->dma.free_addr;
|
host->dma.free_addr = (host->dma.free_addr + length) &
|
host->dma.free_addr = (host->dma.free_addr + length) &
|
(DMAC_BUFFER_SIZE - 1);
|
(DMAC_BUFFER_SIZE - 1);
|
|
|
/*
|
/*
|
* Transfer data to DMA memory
|
* Transfer data to DMA memory
|
*/
|
*/
|
if (direction == DMA_OUT)
|
if (direction == DMA_OUT)
|
acornscsi_data_write (host, host->scsi.SCp.ptr, host->dma.start_addr,
|
acornscsi_data_write (host, host->scsi.SCp.ptr, host->dma.start_addr,
|
length);
|
length);
|
|
|
length -= 1;
|
length -= 1;
|
dmac_write (host->dma.io_port, TXCNTLO, length);
|
dmac_write (host->dma.io_port, TXCNTLO, length);
|
dmac_write (host->dma.io_port, TXCNTHI, length >> 8);
|
dmac_write (host->dma.io_port, TXCNTHI, length >> 8);
|
dmac_write (host->dma.io_port, TXADRLO, address);
|
dmac_write (host->dma.io_port, TXADRLO, address);
|
dmac_write (host->dma.io_port, TXADRMD, address >> 8);
|
dmac_write (host->dma.io_port, TXADRMD, address >> 8);
|
dmac_write (host->dma.io_port, TXADRHI, 0);
|
dmac_write (host->dma.io_port, TXADRHI, 0);
|
dmac_write (host->dma.io_port, MODECON, mode);
|
dmac_write (host->dma.io_port, MODECON, mode);
|
dmac_write (host->dma.io_port, MASKREG, MASK_OFF);
|
dmac_write (host->dma.io_port, MASKREG, MASK_OFF);
|
|
|
#if (DEBUG & DEBUG_DMA)
|
#if (DEBUG & DEBUG_DMA)
|
DBG(host->SCpnt, acornscsi_dumpdma (host, "strt"));
|
DBG(host->SCpnt, acornscsi_dumpdma (host, "strt"));
|
#endif
|
#endif
|
host->dma.xfer_setup = 1;
|
host->dma.xfer_setup = 1;
|
}
|
}
|
}
|
}
|
|
|
/*
|
/*
|
* Function: void acornscsi_dma_cleanup (AS_Host *host)
|
* Function: void acornscsi_dma_cleanup (AS_Host *host)
|
* Purpose : ensure that all DMA transfers are up-to-date & host->scsi.SCp is correct
|
* Purpose : ensure that all DMA transfers are up-to-date & host->scsi.SCp is correct
|
* Params : host - host to finish
|
* Params : host - host to finish
|
* Notes : This is called when a command is:
|
* Notes : This is called when a command is:
|
* terminating, RESTORE_POINTERS, SAVE_POINTERS, DISCONECT
|
* terminating, RESTORE_POINTERS, SAVE_POINTERS, DISCONECT
|
* : This must not return until all transfers are completed.
|
* : This must not return until all transfers are completed.
|
*/
|
*/
|
static
|
static
|
void acornscsi_dma_cleanup (AS_Host *host)
|
void acornscsi_dma_cleanup (AS_Host *host)
|
{
|
{
|
dmac_write (host->dma.io_port, MASKREG, MASK_ON);
|
dmac_write (host->dma.io_port, MASKREG, MASK_ON);
|
dmac_clearintr (host->dma.io_intr_clear);
|
dmac_clearintr (host->dma.io_intr_clear);
|
|
|
/*
|
/*
|
* Check for a pending transfer
|
* Check for a pending transfer
|
*/
|
*/
|
if (host->dma.xfer_required) {
|
if (host->dma.xfer_required) {
|
host->dma.xfer_required = 0;
|
host->dma.xfer_required = 0;
|
if (host->dma.direction == DMA_IN)
|
if (host->dma.direction == DMA_IN)
|
acornscsi_data_read (host, host->dma.xfer_ptr,
|
acornscsi_data_read (host, host->dma.xfer_ptr,
|
host->dma.xfer_start, host->dma.xfer_length);
|
host->dma.xfer_start, host->dma.xfer_length);
|
}
|
}
|
|
|
/*
|
/*
|
* Has a transfer been setup?
|
* Has a transfer been setup?
|
*/
|
*/
|
if (host->dma.xfer_setup) {
|
if (host->dma.xfer_setup) {
|
unsigned int transferred;
|
unsigned int transferred;
|
|
|
host->dma.xfer_setup = 0;
|
host->dma.xfer_setup = 0;
|
|
|
#if (DEBUG & DEBUG_DMA)
|
#if (DEBUG & DEBUG_DMA)
|
DBG(host->SCpnt, acornscsi_dumpdma (host, "clup"));
|
DBG(host->SCpnt, acornscsi_dumpdma (host, "clup"));
|
#endif
|
#endif
|
|
|
/*
|
/*
|
* Calculate number of bytes transferred from DMA.
|
* Calculate number of bytes transferred from DMA.
|
*/
|
*/
|
transferred = dmac_address (host->dma.io_port) - host->dma.start_addr;
|
transferred = dmac_address (host->dma.io_port) - host->dma.start_addr;
|
host->dma.transferred += transferred;
|
host->dma.transferred += transferred;
|
|
|
if (host->dma.direction == DMA_IN)
|
if (host->dma.direction == DMA_IN)
|
acornscsi_data_read (host, host->scsi.SCp.ptr,
|
acornscsi_data_read (host, host->scsi.SCp.ptr,
|
host->dma.start_addr, transferred);
|
host->dma.start_addr, transferred);
|
|
|
/*
|
/*
|
* Update SCSI pointers
|
* Update SCSI pointers
|
*/
|
*/
|
acornscsi_data_updateptr (host, &host->scsi.SCp, transferred);
|
acornscsi_data_updateptr (host, &host->scsi.SCp, transferred);
|
}
|
}
|
}
|
}
|
|
|
/*
|
/*
|
* Function: void acornscsi_dmacintr (AS_Host *host)
|
* Function: void acornscsi_dmacintr (AS_Host *host)
|
* Purpose : handle interrupts from DMAC device
|
* Purpose : handle interrupts from DMAC device
|
* Params : host - host to process
|
* Params : host - host to process
|
* Notes : If reading, we schedule the read to main memory &
|
* Notes : If reading, we schedule the read to main memory &
|
* allow the transfer to continue.
|
* allow the transfer to continue.
|
* : If writing, we fill the onboard DMA memory from main
|
* : If writing, we fill the onboard DMA memory from main
|
* memory.
|
* memory.
|
* : Called whenever DMAC finished it's current transfer.
|
* : Called whenever DMAC finished it's current transfer.
|
*/
|
*/
|
static
|
static
|
void acornscsi_dma_intr (AS_Host *host)
|
void acornscsi_dma_intr (AS_Host *host)
|
{
|
{
|
unsigned int address, length, transferred;
|
unsigned int address, length, transferred;
|
|
|
#if (DEBUG & DEBUG_DMA)
|
#if (DEBUG & DEBUG_DMA)
|
DBG(host->SCpnt, acornscsi_dumpdma (host, "inti"));
|
DBG(host->SCpnt, acornscsi_dumpdma (host, "inti"));
|
#endif
|
#endif
|
|
|
dmac_write (host->dma.io_port, MASKREG, MASK_ON);
|
dmac_write (host->dma.io_port, MASKREG, MASK_ON);
|
dmac_clearintr (host->dma.io_intr_clear);
|
dmac_clearintr (host->dma.io_intr_clear);
|
|
|
/*
|
/*
|
* Calculate amount transferred via DMA
|
* Calculate amount transferred via DMA
|
*/
|
*/
|
transferred = dmac_address (host->dma.io_port) - host->dma.start_addr;
|
transferred = dmac_address (host->dma.io_port) - host->dma.start_addr;
|
host->dma.transferred += transferred;
|
host->dma.transferred += transferred;
|
|
|
/*
|
/*
|
* Schedule DMA transfer off board
|
* Schedule DMA transfer off board
|
*/
|
*/
|
if (host->dma.direction == DMA_IN) {
|
if (host->dma.direction == DMA_IN) {
|
host->dma.xfer_start = host->dma.start_addr;
|
host->dma.xfer_start = host->dma.start_addr;
|
host->dma.xfer_length = transferred;
|
host->dma.xfer_length = transferred;
|
host->dma.xfer_ptr = host->scsi.SCp.ptr;
|
host->dma.xfer_ptr = host->scsi.SCp.ptr;
|
host->dma.xfer_required = 1;
|
host->dma.xfer_required = 1;
|
}
|
}
|
|
|
acornscsi_data_updateptr (host, &host->scsi.SCp, transferred);
|
acornscsi_data_updateptr (host, &host->scsi.SCp, transferred);
|
|
|
/*
|
/*
|
* Allocate some buffer space, limited to half the on-board RAM size
|
* Allocate some buffer space, limited to half the on-board RAM size
|
*/
|
*/
|
length = min (host->scsi.SCp.this_residual, DMAC_BUFFER_SIZE / 2);
|
length = min (host->scsi.SCp.this_residual, DMAC_BUFFER_SIZE / 2);
|
if (length) {
|
if (length) {
|
host->dma.start_addr = address = host->dma.free_addr;
|
host->dma.start_addr = address = host->dma.free_addr;
|
host->dma.free_addr = (host->dma.free_addr + length) &
|
host->dma.free_addr = (host->dma.free_addr + length) &
|
(DMAC_BUFFER_SIZE - 1);
|
(DMAC_BUFFER_SIZE - 1);
|
|
|
/*
|
/*
|
* Transfer data to DMA memory
|
* Transfer data to DMA memory
|
*/
|
*/
|
if (host->dma.direction == DMA_OUT)
|
if (host->dma.direction == DMA_OUT)
|
acornscsi_data_write (host, host->scsi.SCp.ptr, host->dma.start_addr,
|
acornscsi_data_write (host, host->scsi.SCp.ptr, host->dma.start_addr,
|
length);
|
length);
|
|
|
length -= 1;
|
length -= 1;
|
dmac_write (host->dma.io_port, TXCNTLO, length);
|
dmac_write (host->dma.io_port, TXCNTLO, length);
|
dmac_write (host->dma.io_port, TXCNTHI, length >> 8);
|
dmac_write (host->dma.io_port, TXCNTHI, length >> 8);
|
dmac_write (host->dma.io_port, TXADRLO, address);
|
dmac_write (host->dma.io_port, TXADRLO, address);
|
dmac_write (host->dma.io_port, TXADRMD, address >> 8);
|
dmac_write (host->dma.io_port, TXADRMD, address >> 8);
|
dmac_write (host->dma.io_port, TXADRHI, 0);
|
dmac_write (host->dma.io_port, TXADRHI, 0);
|
dmac_write (host->dma.io_port, MASKREG, MASK_OFF);
|
dmac_write (host->dma.io_port, MASKREG, MASK_OFF);
|
|
|
#if (DEBUG & DEBUG_DMA)
|
#if (DEBUG & DEBUG_DMA)
|
DBG(host->SCpnt, acornscsi_dumpdma (host, "into"));
|
DBG(host->SCpnt, acornscsi_dumpdma (host, "into"));
|
#endif
|
#endif
|
} else {
|
} else {
|
host->dma.xfer_setup = 0;
|
host->dma.xfer_setup = 0;
|
#if 0
|
#if 0
|
/*
|
/*
|
* If the interface still wants more, then this is an error.
|
* If the interface still wants more, then this is an error.
|
* We give it another byte, but we also attempt to raise an
|
* We give it another byte, but we also attempt to raise an
|
* attention condition. We continue giving one byte until
|
* attention condition. We continue giving one byte until
|
* the device recognises the attention.
|
* the device recognises the attention.
|
*/
|
*/
|
if (dmac_read (host->dma.io_port, STATUS) & STATUS_RQ0) {
|
if (dmac_read (host->dma.io_port, STATUS) & STATUS_RQ0) {
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
|
|
dmac_write (host->dma.io_port, TXCNTLO, 0);
|
dmac_write (host->dma.io_port, TXCNTLO, 0);
|
dmac_write (host->dma.io_port, TXCNTHI, 0);
|
dmac_write (host->dma.io_port, TXCNTHI, 0);
|
dmac_write (host->dma.io_port, TXADRLO, 0);
|
dmac_write (host->dma.io_port, TXADRLO, 0);
|
dmac_write (host->dma.io_port, TXADRMD, 0);
|
dmac_write (host->dma.io_port, TXADRMD, 0);
|
dmac_write (host->dma.io_port, TXADRHI, 0);
|
dmac_write (host->dma.io_port, TXADRHI, 0);
|
dmac_write (host->dma.io_port, MASKREG, MASK_OFF);
|
dmac_write (host->dma.io_port, MASKREG, MASK_OFF);
|
}
|
}
|
#endif
|
#endif
|
}
|
}
|
}
|
}
|
|
|
/*
|
/*
|
* Function: void acornscsi_dma_xfer (AS_Host *host)
|
* Function: void acornscsi_dma_xfer (AS_Host *host)
|
* Purpose : transfer data between AcornSCSI and memory
|
* Purpose : transfer data between AcornSCSI and memory
|
* Params : host - host to process
|
* Params : host - host to process
|
*/
|
*/
|
static
|
static
|
void acornscsi_dma_xfer (AS_Host *host)
|
void acornscsi_dma_xfer (AS_Host *host)
|
{
|
{
|
host->dma.xfer_required = 0;
|
host->dma.xfer_required = 0;
|
|
|
if (host->dma.direction == DMA_IN)
|
if (host->dma.direction == DMA_IN)
|
acornscsi_data_read (host, host->dma.xfer_ptr,
|
acornscsi_data_read (host, host->dma.xfer_ptr,
|
host->dma.xfer_start, host->dma.xfer_length);
|
host->dma.xfer_start, host->dma.xfer_length);
|
}
|
}
|
|
|
/*
|
/*
|
* Function: void acornscsi_dma_adjust (AS_Host *host)
|
* Function: void acornscsi_dma_adjust (AS_Host *host)
|
* Purpose : adjust DMA pointers & count for bytes transfered to
|
* Purpose : adjust DMA pointers & count for bytes transfered to
|
* SBIC but not SCSI bus.
|
* SBIC but not SCSI bus.
|
* Params : host - host to adjust DMA count for
|
* Params : host - host to adjust DMA count for
|
*/
|
*/
|
static
|
static
|
void acornscsi_dma_adjust (AS_Host *host)
|
void acornscsi_dma_adjust (AS_Host *host)
|
{
|
{
|
if (host->dma.xfer_setup) {
|
if (host->dma.xfer_setup) {
|
signed long transferred;
|
signed long transferred;
|
#if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
|
#if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
|
DBG(host->SCpnt, acornscsi_dumpdma (host, "adji"));
|
DBG(host->SCpnt, acornscsi_dumpdma (host, "adji"));
|
#endif
|
#endif
|
/*
|
/*
|
* Calculate correct DMA address - DMA is ahead of SCSI bus while
|
* Calculate correct DMA address - DMA is ahead of SCSI bus while
|
* writing.
|
* writing.
|
* host->scsi.SCp.have_data_in is the number of bytes
|
* host->scsi.SCp.have_data_in is the number of bytes
|
* actually transferred to/from the SCSI bus.
|
* actually transferred to/from the SCSI bus.
|
* host->dma.transferred is the number of bytes transferred
|
* host->dma.transferred is the number of bytes transferred
|
* over DMA since host->dma.start_addr was last set.
|
* over DMA since host->dma.start_addr was last set.
|
*
|
*
|
* real_dma_addr = host->dma.start_addr + host->scsi.SCp.have_data_in
|
* real_dma_addr = host->dma.start_addr + host->scsi.SCp.have_data_in
|
* - host->dma.transferred
|
* - host->dma.transferred
|
*/
|
*/
|
transferred = host->scsi.SCp.have_data_in - host->dma.transferred;
|
transferred = host->scsi.SCp.have_data_in - host->dma.transferred;
|
if (transferred < 0)
|
if (transferred < 0)
|
printk ("scsi%d.%c: Ack! DMA write correction %ld < 0!\n",
|
printk ("scsi%d.%c: Ack! DMA write correction %ld < 0!\n",
|
host->host->host_no, acornscsi_target (host), transferred);
|
host->host->host_no, acornscsi_target (host), transferred);
|
else if (transferred == 0)
|
else if (transferred == 0)
|
host->dma.xfer_setup = 0;
|
host->dma.xfer_setup = 0;
|
else {
|
else {
|
transferred += host->dma.start_addr;
|
transferred += host->dma.start_addr;
|
dmac_write (host->dma.io_port, TXADRLO, transferred);
|
dmac_write (host->dma.io_port, TXADRLO, transferred);
|
dmac_write (host->dma.io_port, TXADRMD, transferred >> 8);
|
dmac_write (host->dma.io_port, TXADRMD, transferred >> 8);
|
dmac_write (host->dma.io_port, TXADRHI, transferred >> 16);
|
dmac_write (host->dma.io_port, TXADRHI, transferred >> 16);
|
#if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
|
#if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
|
DBG(host->SCpnt, acornscsi_dumpdma (host, "adjo"));
|
DBG(host->SCpnt, acornscsi_dumpdma (host, "adjo"));
|
#endif
|
#endif
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
/* =========================================================================================
|
/* =========================================================================================
|
* Data I/O
|
* Data I/O
|
*/
|
*/
|
/*
|
/*
|
* Function: void acornscsi_sendcommand (AS_Host *host)
|
* Function: void acornscsi_sendcommand (AS_Host *host)
|
* Purpose : send a command to a target
|
* Purpose : send a command to a target
|
* Params : host - host which is connected to target
|
* Params : host - host which is connected to target
|
*/
|
*/
|
static
|
static
|
void acornscsi_sendcommand (AS_Host *host)
|
void acornscsi_sendcommand (AS_Host *host)
|
{
|
{
|
Scsi_Cmnd *SCpnt = host->SCpnt;
|
Scsi_Cmnd *SCpnt = host->SCpnt;
|
unsigned int asr;
|
unsigned int asr;
|
unsigned char *cmdptr, *cmdend;
|
unsigned char *cmdptr, *cmdend;
|
|
|
sbic_arm_write (host->scsi.io_port, TRANSCNTH, 0);
|
sbic_arm_write (host->scsi.io_port, TRANSCNTH, 0);
|
sbic_arm_writenext (host->scsi.io_port, 0);
|
sbic_arm_writenext (host->scsi.io_port, 0);
|
sbic_arm_writenext (host->scsi.io_port, SCpnt->cmd_len - host->scsi.SCp.sent_command);
|
sbic_arm_writenext (host->scsi.io_port, SCpnt->cmd_len - host->scsi.SCp.sent_command);
|
acornscsi_sbic_issuecmd (host, CMND_XFERINFO);
|
acornscsi_sbic_issuecmd (host, CMND_XFERINFO);
|
|
|
cmdptr = SCpnt->cmnd + host->scsi.SCp.sent_command;
|
cmdptr = SCpnt->cmnd + host->scsi.SCp.sent_command;
|
cmdend = SCpnt->cmnd + SCpnt->cmd_len;
|
cmdend = SCpnt->cmnd + SCpnt->cmd_len;
|
|
|
while (cmdptr < cmdend) {
|
while (cmdptr < cmdend) {
|
asr = sbic_arm_read (host->scsi.io_port, ASR);
|
asr = sbic_arm_read (host->scsi.io_port, ASR);
|
if (asr & ASR_DBR)
|
if (asr & ASR_DBR)
|
sbic_arm_write (host->scsi.io_port, DATA, *cmdptr++);
|
sbic_arm_write (host->scsi.io_port, DATA, *cmdptr++);
|
else if (asr & ASR_INT)
|
else if (asr & ASR_INT)
|
break;
|
break;
|
}
|
}
|
if (cmdptr >= cmdend)
|
if (cmdptr >= cmdend)
|
host->scsi.SCp.sent_command = cmdptr - SCpnt->cmnd;
|
host->scsi.SCp.sent_command = cmdptr - SCpnt->cmnd;
|
host->scsi.phase = PHASE_COMMAND;
|
host->scsi.phase = PHASE_COMMAND;
|
}
|
}
|
|
|
static
|
static
|
void acornscsi_sendmessage (AS_Host *host)
|
void acornscsi_sendmessage (AS_Host *host)
|
{
|
{
|
unsigned int message_length = msgqueue_msglength (&host->scsi.msgs);
|
unsigned int message_length = msgqueue_msglength (&host->scsi.msgs);
|
int msgnr;
|
int msgnr;
|
struct message *msg;
|
struct message *msg;
|
|
|
#if (DEBUG & DEBUG_MESSAGES)
|
#if (DEBUG & DEBUG_MESSAGES)
|
printk ("scsi%d.%c: sending message ",
|
printk ("scsi%d.%c: sending message ",
|
host->host->host_no, acornscsi_target (host));
|
host->host->host_no, acornscsi_target (host));
|
#endif
|
#endif
|
|
|
switch (message_length) {
|
switch (message_length) {
|
case 0:
|
case 0:
|
acornscsi_sbic_issuecmd (host, CMND_XFERINFO | CMND_SBT);
|
acornscsi_sbic_issuecmd (host, CMND_XFERINFO | CMND_SBT);
|
while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_DBR) == 0);
|
while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_DBR) == 0);
|
sbic_arm_write (host->scsi.io_port, DATA, NOP);
|
sbic_arm_write (host->scsi.io_port, DATA, NOP);
|
host->scsi.last_message = NOP;
|
host->scsi.last_message = NOP;
|
#if (DEBUG & DEBUG_MESSAGES)
|
#if (DEBUG & DEBUG_MESSAGES)
|
printk ("NOP");
|
printk ("NOP");
|
#endif
|
#endif
|
break;
|
break;
|
|
|
case 1:
|
case 1:
|
acornscsi_sbic_issuecmd (host, CMND_XFERINFO | CMND_SBT);
|
acornscsi_sbic_issuecmd (host, CMND_XFERINFO | CMND_SBT);
|
msg = msgqueue_getmsg (&host->scsi.msgs, 0);
|
msg = msgqueue_getmsg (&host->scsi.msgs, 0);
|
while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_DBR) == 0);
|
while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_DBR) == 0);
|
sbic_arm_write (host->scsi.io_port, DATA, msg->msg[0]);
|
sbic_arm_write (host->scsi.io_port, DATA, msg->msg[0]);
|
host->scsi.last_message = msg->msg[0];
|
host->scsi.last_message = msg->msg[0];
|
#if (DEBUG & DEBUG_MESSAGES)
|
#if (DEBUG & DEBUG_MESSAGES)
|
print_msg (msg->msg);
|
print_msg (msg->msg);
|
#endif
|
#endif
|
break;
|
break;
|
|
|
default:
|
default:
|
/*
|
/*
|
* ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.14)
|
* ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.14)
|
* 'When a target sends this (MESSAGE_REJECT) message, it
|
* 'When a target sends this (MESSAGE_REJECT) message, it
|
* shall change to MESSAGE IN phase and send this message
|
* shall change to MESSAGE IN phase and send this message
|
* prior to requesting additional message bytes from the
|
* prior to requesting additional message bytes from the
|
* initiator. This provides an interlock so that the
|
* initiator. This provides an interlock so that the
|
* initiator can determine which message byte is rejected.
|
* initiator can determine which message byte is rejected.
|
*/
|
*/
|
sbic_arm_write (host->scsi.io_port, TRANSCNTH, 0);
|
sbic_arm_write (host->scsi.io_port, TRANSCNTH, 0);
|
sbic_arm_writenext (host->scsi.io_port, 0);
|
sbic_arm_writenext (host->scsi.io_port, 0);
|
sbic_arm_writenext (host->scsi.io_port, message_length);
|
sbic_arm_writenext (host->scsi.io_port, message_length);
|
acornscsi_sbic_issuecmd (host, CMND_XFERINFO);
|
acornscsi_sbic_issuecmd (host, CMND_XFERINFO);
|
|
|
msgnr = 0;
|
msgnr = 0;
|
while ((msg = msgqueue_getmsg (&host->scsi.msgs, msgnr++)) != NULL) {
|
while ((msg = msgqueue_getmsg (&host->scsi.msgs, msgnr++)) != NULL) {
|
unsigned int asr, i;
|
unsigned int asr, i;
|
#if (DEBUG & DEBUG_MESSAGES)
|
#if (DEBUG & DEBUG_MESSAGES)
|
print_msg (msg);
|
print_msg (msg);
|
#endif
|
#endif
|
for (i = 0; i < msg->length;) {
|
for (i = 0; i < msg->length;) {
|
asr = sbic_arm_read(host->scsi.io_port, ASR);
|
asr = sbic_arm_read(host->scsi.io_port, ASR);
|
if (asr & ASR_DBR)
|
if (asr & ASR_DBR)
|
sbic_arm_write(host->scsi.io_port, DATA, msg->msg[i++]);
|
sbic_arm_write(host->scsi.io_port, DATA, msg->msg[i++]);
|
if (asr & ASR_INT)
|
if (asr & ASR_INT)
|
break;
|
break;
|
}
|
}
|
host->scsi.last_message = msg->msg[0];
|
host->scsi.last_message = msg->msg[0];
|
if (msg->msg[0] == EXTENDED_MESSAGE)
|
if (msg->msg[0] == EXTENDED_MESSAGE)
|
host->scsi.last_message |= msg->msg[2] << 8;
|
host->scsi.last_message |= msg->msg[2] << 8;
|
if (asr & ASR_INT)
|
if (asr & ASR_INT)
|
break;
|
break;
|
}
|
}
|
break;
|
break;
|
}
|
}
|
#if (DEBUG & DEBUG_MESSAGES)
|
#if (DEBUG & DEBUG_MESSAGES)
|
printk ("\n");
|
printk ("\n");
|
#endif
|
#endif
|
}
|
}
|
|
|
/*
|
/*
|
* Function: void acornscsi_readstatusbyte (AS_Host *host)
|
* Function: void acornscsi_readstatusbyte (AS_Host *host)
|
* Purpose : Read status byte from connected target
|
* Purpose : Read status byte from connected target
|
* Params : host - host connected to target
|
* Params : host - host connected to target
|
*/
|
*/
|
static
|
static
|
void acornscsi_readstatusbyte (AS_Host *host)
|
void acornscsi_readstatusbyte (AS_Host *host)
|
{
|
{
|
acornscsi_sbic_issuecmd (host, CMND_XFERINFO|CMND_SBT);
|
acornscsi_sbic_issuecmd (host, CMND_XFERINFO|CMND_SBT);
|
while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_DBR) == 0);
|
while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_DBR) == 0);
|
|
|
host->scsi.SCp.Status = sbic_arm_read (host->scsi.io_port, DATA);
|
host->scsi.SCp.Status = sbic_arm_read (host->scsi.io_port, DATA);
|
}
|
}
|
|
|
/*
|
/*
|
* Function: unsigned char acornscsi_readmessagebyte (AS_Host *host)
|
* Function: unsigned char acornscsi_readmessagebyte (AS_Host *host)
|
* Purpose : Read one message byte from connected target
|
* Purpose : Read one message byte from connected target
|
* Params : host - host connected to target
|
* Params : host - host connected to target
|
*/
|
*/
|
static
|
static
|
unsigned char acornscsi_readmessagebyte (AS_Host *host)
|
unsigned char acornscsi_readmessagebyte (AS_Host *host)
|
{
|
{
|
unsigned char message;
|
unsigned char message;
|
|
|
acornscsi_sbic_issuecmd (host, CMND_XFERINFO | CMND_SBT);
|
acornscsi_sbic_issuecmd (host, CMND_XFERINFO | CMND_SBT);
|
while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_DBR) == 0);
|
while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_DBR) == 0);
|
|
|
message = sbic_arm_read (host->scsi.io_port, DATA);
|
message = sbic_arm_read (host->scsi.io_port, DATA);
|
|
|
/* wait for MSGIN-XFER-PAUSED */
|
/* wait for MSGIN-XFER-PAUSED */
|
while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_INT) == 0);
|
while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_INT) == 0);
|
sbic_arm_read (host->scsi.io_port, SSR);
|
sbic_arm_read (host->scsi.io_port, SSR);
|
|
|
return message;
|
return message;
|
}
|
}
|
|
|
/*
|
/*
|
* Function: void acornscsi_message (AS_Host *host)
|
* Function: void acornscsi_message (AS_Host *host)
|
* Purpose : Read complete message from connected target & action message
|
* Purpose : Read complete message from connected target & action message
|
* Params : host - host connected to target
|
* Params : host - host connected to target
|
*/
|
*/
|
static
|
static
|
void acornscsi_message (AS_Host *host)
|
void acornscsi_message (AS_Host *host)
|
{
|
{
|
unsigned char message[16];
|
unsigned char message[16];
|
unsigned int msgidx = 0, msglen = 1;
|
unsigned int msgidx = 0, msglen = 1;
|
|
|
do {
|
do {
|
message[msgidx] = acornscsi_readmessagebyte (host);
|
message[msgidx] = acornscsi_readmessagebyte (host);
|
|
|
switch (msgidx) {
|
switch (msgidx) {
|
case 0:
|
case 0:
|
if (message[0] == EXTENDED_MESSAGE ||
|
if (message[0] == EXTENDED_MESSAGE ||
|
(message[0] >= 0x20 && message[0] <= 0x2f))
|
(message[0] >= 0x20 && message[0] <= 0x2f))
|
msglen = 2;
|
msglen = 2;
|
break;
|
break;
|
|
|
case 1:
|
case 1:
|
if (message[0] == EXTENDED_MESSAGE)
|
if (message[0] == EXTENDED_MESSAGE)
|
msglen += message[msgidx];
|
msglen += message[msgidx];
|
break;
|
break;
|
}
|
}
|
msgidx += 1;
|
msgidx += 1;
|
if (msgidx < msglen) {
|
if (msgidx < msglen) {
|
acornscsi_sbic_issuecmd (host, CMND_NEGATEACK);
|
acornscsi_sbic_issuecmd (host, CMND_NEGATEACK);
|
|
|
/* wait for next msg-in */
|
/* wait for next msg-in */
|
while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_INT) == 0);
|
while ((sbic_arm_read (host->scsi.io_port, ASR) & ASR_INT) == 0);
|
sbic_arm_read (host->scsi.io_port, SSR);
|
sbic_arm_read (host->scsi.io_port, SSR);
|
}
|
}
|
} while (msgidx < msglen);
|
} while (msgidx < msglen);
|
|
|
#if (DEBUG & DEBUG_MESSAGES)
|
#if (DEBUG & DEBUG_MESSAGES)
|
printk (KERN_DEBUG "scsi%d.%c: message in: ",
|
printk (KERN_DEBUG "scsi%d.%c: message in: ",
|
host->host->host_no, acornscsi_target (host));
|
host->host->host_no, acornscsi_target (host));
|
print_msg (message);
|
print_msg (message);
|
printk ("\n");
|
printk ("\n");
|
#endif
|
#endif
|
|
|
if (host->scsi.phase == PHASE_RECONNECTED) {
|
if (host->scsi.phase == PHASE_RECONNECTED) {
|
/*
|
/*
|
* ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
|
* ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
|
* 'Whenever a target reconnects to an initiator to continue
|
* 'Whenever a target reconnects to an initiator to continue
|
* a tagged I/O process, the SIMPLE QUEUE TAG message shall
|
* a tagged I/O process, the SIMPLE QUEUE TAG message shall
|
* be sent immediately following the IDENTIFY message...'
|
* be sent immediately following the IDENTIFY message...'
|
*/
|
*/
|
if (message[0] == SIMPLE_QUEUE_TAG)
|
if (message[0] == SIMPLE_QUEUE_TAG)
|
host->scsi.reconnected.tag = message[1];
|
host->scsi.reconnected.tag = message[1];
|
if (acornscsi_reconnect_finish (host))
|
if (acornscsi_reconnect_finish (host))
|
host->scsi.phase = PHASE_MSGIN;
|
host->scsi.phase = PHASE_MSGIN;
|
}
|
}
|
|
|
switch (message[0]) {
|
switch (message[0]) {
|
case ABORT:
|
case ABORT:
|
case ABORT_TAG:
|
case ABORT_TAG:
|
case COMMAND_COMPLETE:
|
case COMMAND_COMPLETE:
|
if (host->scsi.phase != PHASE_STATUSIN)
|
if (host->scsi.phase != PHASE_STATUSIN)
|
printk (KERN_ERR "scsi%d.%c: command complete following non-status in phase?\n",
|
printk (KERN_ERR "scsi%d.%c: command complete following non-status in phase?\n",
|
host->host->host_no, acornscsi_target (host));
|
host->host->host_no, acornscsi_target (host));
|
host->scsi.phase = PHASE_DONE;
|
host->scsi.phase = PHASE_DONE;
|
host->scsi.SCp.Message = message[0];
|
host->scsi.SCp.Message = message[0];
|
break;
|
break;
|
|
|
case SAVE_POINTERS:
|
case SAVE_POINTERS:
|
/*
|
/*
|
* ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.20)
|
* ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.20)
|
* 'The SAVE DATA POINTER message is sent from a target to
|
* 'The SAVE DATA POINTER message is sent from a target to
|
* direct the initiator to copy the active data pointer to
|
* direct the initiator to copy the active data pointer to
|
* the saved data pointer for the current I/O process.
|
* the saved data pointer for the current I/O process.
|
*/
|
*/
|
acornscsi_dma_cleanup (host);
|
acornscsi_dma_cleanup (host);
|
host->SCpnt->SCp = host->scsi.SCp;
|
host->SCpnt->SCp = host->scsi.SCp;
|
host->SCpnt->SCp.sent_command = 0;
|
host->SCpnt->SCp.sent_command = 0;
|
host->scsi.phase = PHASE_MSGIN;
|
host->scsi.phase = PHASE_MSGIN;
|
break;
|
break;
|
|
|
case RESTORE_POINTERS:
|
case RESTORE_POINTERS:
|
/*
|
/*
|
* ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.19)
|
* ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.19)
|
* 'The RESTORE POINTERS message is sent from a target to
|
* 'The RESTORE POINTERS message is sent from a target to
|
* direct the initiator to copy the most recently saved
|
* direct the initiator to copy the most recently saved
|
* command, data, and status pointers for the I/O process
|
* command, data, and status pointers for the I/O process
|
* to the corresponding active pointers. The command and
|
* to the corresponding active pointers. The command and
|
* status pointers shall be restored to the beginning of
|
* status pointers shall be restored to the beginning of
|
* the present command and status areas.'
|
* the present command and status areas.'
|
*/
|
*/
|
acornscsi_dma_cleanup (host);
|
acornscsi_dma_cleanup (host);
|
host->scsi.SCp = host->SCpnt->SCp;
|
host->scsi.SCp = host->SCpnt->SCp;
|
host->scsi.phase = PHASE_MSGIN;
|
host->scsi.phase = PHASE_MSGIN;
|
break;
|
break;
|
|
|
case DISCONNECT:
|
case DISCONNECT:
|
/*
|
/*
|
* ANSI standard says: (Section SCSI-2 Rev. 10c Sect 6.4.2)
|
* ANSI standard says: (Section SCSI-2 Rev. 10c Sect 6.4.2)
|
* 'On those occasions when an error or exception condition occurs
|
* 'On those occasions when an error or exception condition occurs
|
* and the target elects to repeat the information transfer, the
|
* and the target elects to repeat the information transfer, the
|
* target may repeat the transfer either issuing a RESTORE POINTERS
|
* target may repeat the transfer either issuing a RESTORE POINTERS
|
* message or by disconnecting without issuing a SAVE POINTERS
|
* message or by disconnecting without issuing a SAVE POINTERS
|
* message. When reconnection is completed, the most recent
|
* message. When reconnection is completed, the most recent
|
* saved pointer values are restored.'
|
* saved pointer values are restored.'
|
*/
|
*/
|
acornscsi_dma_cleanup (host);
|
acornscsi_dma_cleanup (host);
|
host->scsi.phase = PHASE_DISCONNECT;
|
host->scsi.phase = PHASE_DISCONNECT;
|
break;
|
break;
|
|
|
case MESSAGE_REJECT:
|
case MESSAGE_REJECT:
|
#if 0 /* this isn't needed any more */
|
#if 0 /* this isn't needed any more */
|
/*
|
/*
|
* If we were negociating sync transfer, we don't yet know if
|
* If we were negociating sync transfer, we don't yet know if
|
* this REJECT is for the sync transfer or for the tagged queue/wide
|
* this REJECT is for the sync transfer or for the tagged queue/wide
|
* transfer. Re-initiate sync transfer negociation now, and if
|
* transfer. Re-initiate sync transfer negociation now, and if
|
* we got a REJECT in response to SDTR, then it'll be set to DONE.
|
* we got a REJECT in response to SDTR, then it'll be set to DONE.
|
*/
|
*/
|
if (host->device[host->SCpnt->target].sync_state == SYNC_SENT_REQUEST)
|
if (host->device[host->SCpnt->target].sync_state == SYNC_SENT_REQUEST)
|
host->device[host->SCpnt->target].sync_state = SYNC_NEGOCIATE;
|
host->device[host->SCpnt->target].sync_state = SYNC_NEGOCIATE;
|
#endif
|
#endif
|
|
|
/*
|
/*
|
* If we have any messages waiting to go out, then assert ATN now
|
* If we have any messages waiting to go out, then assert ATN now
|
*/
|
*/
|
if (msgqueue_msglength (&host->scsi.msgs))
|
if (msgqueue_msglength (&host->scsi.msgs))
|
acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
|
acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
|
|
|
switch (host->scsi.last_message) {
|
switch (host->scsi.last_message) {
|
#ifdef SCSI2_TAG
|
#ifdef SCSI2_TAG
|
case HEAD_OF_QUEUE_TAG:
|
case HEAD_OF_QUEUE_TAG:
|
case ORDERED_QUEUE_TAG:
|
case ORDERED_QUEUE_TAG:
|
case SIMPLE_QUEUE_TAG:
|
case SIMPLE_QUEUE_TAG:
|
/*
|
/*
|
* ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
|
* ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
|
* If a target does not implement tagged queuing and a queue tag
|
* If a target does not implement tagged queuing and a queue tag
|
* message is received, it shall respond with a MESSAGE REJECT
|
* message is received, it shall respond with a MESSAGE REJECT
|
* message and accept the I/O process as if it were untagged.
|
* message and accept the I/O process as if it were untagged.
|
*/
|
*/
|
printk (KERN_NOTICE "scsi%d.%c: disabling tagged queueing\n",
|
printk (KERN_NOTICE "scsi%d.%c: disabling tagged queueing\n",
|
host->host->host_no, acornscsi_target (host));
|
host->host->host_no, acornscsi_target (host));
|
host->SCpnt->device->tagged_queue = 0;
|
host->SCpnt->device->tagged_queue = 0;
|
set_bit (host->SCpnt->target * 8 + host->SCpnt->lun, &host->busyluns);
|
set_bit (host->SCpnt->target * 8 + host->SCpnt->lun, &host->busyluns);
|
break;
|
break;
|
#endif
|
#endif
|
case EXTENDED_MESSAGE | (EXTENDED_SDTR << 8):
|
case EXTENDED_MESSAGE | (EXTENDED_SDTR << 8):
|
/*
|
/*
|
* Target can't handle synchronous transfers
|
* Target can't handle synchronous transfers
|
*/
|
*/
|
printk (KERN_NOTICE "scsi%d.%c: Using asynchronous transfer\n",
|
printk (KERN_NOTICE "scsi%d.%c: Using asynchronous transfer\n",
|
host->host->host_no, acornscsi_target (host));
|
host->host->host_no, acornscsi_target (host));
|
host->device[host->SCpnt->target].sync_xfer = SYNCHTRANSFER_2DBA;
|
host->device[host->SCpnt->target].sync_xfer = SYNCHTRANSFER_2DBA;
|
host->device[host->SCpnt->target].sync_state = SYNC_ASYNCHRONOUS;
|
host->device[host->SCpnt->target].sync_state = SYNC_ASYNCHRONOUS;
|
sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, host->device[host->SCpnt->target].sync_xfer);
|
sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, host->device[host->SCpnt->target].sync_xfer);
|
break;
|
break;
|
|
|
default:
|
default:
|
break;
|
break;
|
}
|
}
|
break;
|
break;
|
|
|
case QUEUE_FULL:
|
case QUEUE_FULL:
|
/* TODO: target queue is full */
|
/* TODO: target queue is full */
|
break;
|
break;
|
|
|
case SIMPLE_QUEUE_TAG:
|
case SIMPLE_QUEUE_TAG:
|
/* tag queue reconnect... message[1] = queue tag. Print something to indicate something happened! */
|
/* tag queue reconnect... message[1] = queue tag. Print something to indicate something happened! */
|
printk ("scsi%d.%c: reconnect queue tag %02X\n",
|
printk ("scsi%d.%c: reconnect queue tag %02X\n",
|
host->host->host_no, acornscsi_target (host),
|
host->host->host_no, acornscsi_target (host),
|
message[1]);
|
message[1]);
|
break;
|
break;
|
|
|
case EXTENDED_MESSAGE:
|
case EXTENDED_MESSAGE:
|
switch (message[2]) {
|
switch (message[2]) {
|
#ifdef SCSI2_SYNC
|
#ifdef SCSI2_SYNC
|
case EXTENDED_SDTR:
|
case EXTENDED_SDTR:
|
if (host->device[host->SCpnt->target].sync_state == SYNC_SENT_REQUEST) {
|
if (host->device[host->SCpnt->target].sync_state == SYNC_SENT_REQUEST) {
|
/*
|
/*
|
* We requested synchronous transfers. This isn't quite right...
|
* We requested synchronous transfers. This isn't quite right...
|
* We can only say if this succeeded if we proceed on to execute the
|
* We can only say if this succeeded if we proceed on to execute the
|
* command from this message. If we get a MESSAGE PARITY ERROR,
|
* command from this message. If we get a MESSAGE PARITY ERROR,
|
* and the target retries fail, then we fallback to asynchronous mode
|
* and the target retries fail, then we fallback to asynchronous mode
|
*/
|
*/
|
host->device[host->SCpnt->target].sync_state = SYNC_COMPLETED;
|
host->device[host->SCpnt->target].sync_state = SYNC_COMPLETED;
|
printk (KERN_NOTICE "scsi%d.%c: Using synchronous transfer, offset %d, %d ns\n",
|
printk (KERN_NOTICE "scsi%d.%c: Using synchronous transfer, offset %d, %d ns\n",
|
host->host->host_no, acornscsi_target(host),
|
host->host->host_no, acornscsi_target(host),
|
message[4], message[3] * 4);
|
message[4], message[3] * 4);
|
host->device[host->SCpnt->target].sync_xfer =
|
host->device[host->SCpnt->target].sync_xfer =
|
calc_sync_xfer (message[3] * 4, message[4]);
|
calc_sync_xfer (message[3] * 4, message[4]);
|
} else {
|
} else {
|
unsigned char period, length;
|
unsigned char period, length;
|
/*
|
/*
|
* Target requested synchronous transfers. The agreement is only
|
* Target requested synchronous transfers. The agreement is only
|
* to be in operation AFTER the target leaves message out phase.
|
* to be in operation AFTER the target leaves message out phase.
|
*/
|
*/
|
acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
|
acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
|
period = max (message[3], sdtr_period / 4);
|
period = max (message[3], sdtr_period / 4);
|
length = min (message[4], sdtr_size);
|
length = min (message[4], sdtr_size);
|
msgqueue_addmsg (&host->scsi.msgs, 5, EXTENDED_MESSAGE, 3,
|
msgqueue_addmsg (&host->scsi.msgs, 5, EXTENDED_MESSAGE, 3,
|
EXTENDED_SDTR, period, length);
|
EXTENDED_SDTR, period, length);
|
host->device[host->SCpnt->target].sync_xfer =
|
host->device[host->SCpnt->target].sync_xfer =
|
calc_sync_xfer (period * 4, length);
|
calc_sync_xfer (period * 4, length);
|
}
|
}
|
sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, host->device[host->SCpnt->target].sync_xfer);
|
sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, host->device[host->SCpnt->target].sync_xfer);
|
break;
|
break;
|
#else
|
#else
|
/* We do not accept synchronous transfers. Respond with a
|
/* We do not accept synchronous transfers. Respond with a
|
* MESSAGE_REJECT.
|
* MESSAGE_REJECT.
|
*/
|
*/
|
#endif
|
#endif
|
|
|
case EXTENDED_WDTR:
|
case EXTENDED_WDTR:
|
/* The WD33C93A is only 8-bit. We respond with a MESSAGE_REJECT
|
/* The WD33C93A is only 8-bit. We respond with a MESSAGE_REJECT
|
* to a wide data transfer request.
|
* to a wide data transfer request.
|
*/
|
*/
|
default:
|
default:
|
acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
|
acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
|
msgqueue_flush (&host->scsi.msgs);
|
msgqueue_flush (&host->scsi.msgs);
|
msgqueue_addmsg (&host->scsi.msgs, 1, MESSAGE_REJECT);
|
msgqueue_addmsg (&host->scsi.msgs, 1, MESSAGE_REJECT);
|
break;
|
break;
|
}
|
}
|
break;
|
break;
|
|
|
#ifdef SCSI2_LINK
|
#ifdef SCSI2_LINK
|
case LINKED_CMD_COMPLETE:
|
case LINKED_CMD_COMPLETE:
|
case LINKED_FLG_CMD_COMPLETE:
|
case LINKED_FLG_CMD_COMPLETE:
|
/*
|
/*
|
* We don't support linked commands yet
|
* We don't support linked commands yet
|
*/
|
*/
|
if (0) {
|
if (0) {
|
#if (DEBUG & DEBUG_LINK)
|
#if (DEBUG & DEBUG_LINK)
|
printk (KERN_DEBUG "scsi%d.%c: lun %d tag %d linked command complete\n",
|
printk (KERN_DEBUG "scsi%d.%c: lun %d tag %d linked command complete\n",
|
host->host->host_no, acornscsi_target(host), host->SCpnt->tag);
|
host->host->host_no, acornscsi_target(host), host->SCpnt->tag);
|
#endif
|
#endif
|
/*
|
/*
|
* A linked command should only terminate with one of these messages
|
* A linked command should only terminate with one of these messages
|
* if there are more linked commands available.
|
* if there are more linked commands available.
|
*/
|
*/
|
if (!host->SCpnt->next_link) {
|
if (!host->SCpnt->next_link) {
|
printk (KERN_WARNING "scsi%d.%c: lun %d tag %d linked command complete, but no next_link\n",
|
printk (KERN_WARNING "scsi%d.%c: lun %d tag %d linked command complete, but no next_link\n",
|
instance->host_no, acornscsi_target (host), host->SCpnt->tag);
|
instance->host_no, acornscsi_target (host), host->SCpnt->tag);
|
acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
|
acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
|
msgqueue_addmsg (&host->scsi.msgs, 1, ABORT);
|
msgqueue_addmsg (&host->scsi.msgs, 1, ABORT);
|
} else {
|
} else {
|
Scsi_Cmnd *SCpnt = host->SCpnt;
|
Scsi_Cmnd *SCpnt = host->SCpnt;
|
|
|
acornscsi_dma_cleanup (host);
|
acornscsi_dma_cleanup (host);
|
|
|
host->SCpnt = host->SCpnt->next_link;
|
host->SCpnt = host->SCpnt->next_link;
|
host->SCpnt->tag = SCpnt->tag;
|
host->SCpnt->tag = SCpnt->tag;
|
SCpnt->result = DID_OK | host->scsi.SCp.Message << 8 | host->Scsi.SCp.Status;
|
SCpnt->result = DID_OK | host->scsi.SCp.Message << 8 | host->Scsi.SCp.Status;
|
SCpnt->done (SCpnt);
|
SCpnt->done (SCpnt);
|
|
|
/* initialise host->SCpnt->SCp */
|
/* initialise host->SCpnt->SCp */
|
}
|
}
|
break;
|
break;
|
}
|
}
|
#endif
|
#endif
|
|
|
default: /* reject message */
|
default: /* reject message */
|
printk (KERN_ERR "scsi%d.%c: unrecognised message %02X, rejecting\n",
|
printk (KERN_ERR "scsi%d.%c: unrecognised message %02X, rejecting\n",
|
host->host->host_no, acornscsi_target (host),
|
host->host->host_no, acornscsi_target (host),
|
message[0]);
|
message[0]);
|
acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
|
acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
|
msgqueue_flush (&host->scsi.msgs);
|
msgqueue_flush (&host->scsi.msgs);
|
msgqueue_addmsg (&host->scsi.msgs, 1, MESSAGE_REJECT);
|
msgqueue_addmsg (&host->scsi.msgs, 1, MESSAGE_REJECT);
|
host->scsi.phase = PHASE_MSGIN;
|
host->scsi.phase = PHASE_MSGIN;
|
break;
|
break;
|
}
|
}
|
acornscsi_sbic_issuecmd (host, CMND_NEGATEACK);
|
acornscsi_sbic_issuecmd (host, CMND_NEGATEACK);
|
}
|
}
|
|
|
/*
|
/*
|
* Function: int acornscsi_buildmessages (AS_Host *host)
|
* Function: int acornscsi_buildmessages (AS_Host *host)
|
* Purpose : build the connection messages for a host
|
* Purpose : build the connection messages for a host
|
* Params : host - host to add messages to
|
* Params : host - host to add messages to
|
*/
|
*/
|
static
|
static
|
void acornscsi_buildmessages (AS_Host *host)
|
void acornscsi_buildmessages (AS_Host *host)
|
{
|
{
|
#if 0
|
#if 0
|
/* does the device need resetting? */
|
/* does the device need resetting? */
|
if (cmd_reset) {
|
if (cmd_reset) {
|
msgqueue_addmsg (&host->scsi.msgs, 1, BUS_DEVICE_RESET);
|
msgqueue_addmsg (&host->scsi.msgs, 1, BUS_DEVICE_RESET);
|
return;
|
return;
|
}
|
}
|
#endif
|
#endif
|
|
|
msgqueue_addmsg (&host->scsi.msgs, 1,
|
msgqueue_addmsg (&host->scsi.msgs, 1,
|
IDENTIFY(host->device[host->SCpnt->target].disconnect_ok,
|
IDENTIFY(host->device[host->SCpnt->target].disconnect_ok,
|
host->SCpnt->lun));
|
host->SCpnt->lun));
|
|
|
#if 0
|
#if 0
|
/* does the device need the current command aborted */
|
/* does the device need the current command aborted */
|
if (cmd_aborted) {
|
if (cmd_aborted) {
|
acornscsi_abortcmd (host->SCpnt->tag);
|
acornscsi_abortcmd (host->SCpnt->tag);
|
return;
|
return;
|
}
|
}
|
#endif
|
#endif
|
|
|
#ifdef SCSI2_TAG
|
#ifdef SCSI2_TAG
|
if (host->SCpnt->tag) {
|
if (host->SCpnt->tag) {
|
unsigned int tag_type;
|
unsigned int tag_type;
|
|
|
if (host->SCpnt->cmnd[0] == REQUEST_SENSE ||
|
if (host->SCpnt->cmnd[0] == REQUEST_SENSE ||
|
host->SCpnt->cmnd[0] == TEST_UNIT_READY ||
|
host->SCpnt->cmnd[0] == TEST_UNIT_READY ||
|
host->SCpnt->cmnd[0] == INQUIRY)
|
host->SCpnt->cmnd[0] == INQUIRY)
|
tag_type = HEAD_OF_QUEUE_TAG;
|
tag_type = HEAD_OF_QUEUE_TAG;
|
else
|
else
|
tag_type = SIMPLE_QUEUE_TAG;
|
tag_type = SIMPLE_QUEUE_TAG;
|
msgqueue_addmsg (&host->scsi.msgs, 2, tag_type, host->SCpnt->tag);
|
msgqueue_addmsg (&host->scsi.msgs, 2, tag_type, host->SCpnt->tag);
|
}
|
}
|
#endif
|
#endif
|
|
|
#ifdef SCSI2_SYNC
|
#ifdef SCSI2_SYNC
|
if (host->device[host->SCpnt->target].sync_state == SYNC_NEGOCIATE) {
|
if (host->device[host->SCpnt->target].sync_state == SYNC_NEGOCIATE) {
|
host->device[host->SCpnt->target].sync_state = SYNC_SENT_REQUEST;
|
host->device[host->SCpnt->target].sync_state = SYNC_SENT_REQUEST;
|
msgqueue_addmsg (&host->scsi.msgs, 5,
|
msgqueue_addmsg (&host->scsi.msgs, 5,
|
EXTENDED_MESSAGE, 3, EXTENDED_SDTR,
|
EXTENDED_MESSAGE, 3, EXTENDED_SDTR,
|
sdtr_period / 4, sdtr_size);
|
sdtr_period / 4, sdtr_size);
|
}
|
}
|
#endif
|
#endif
|
}
|
}
|
|
|
/*
|
/*
|
* Function: int acornscsi_starttransfer (AS_Host *host)
|
* Function: int acornscsi_starttransfer (AS_Host *host)
|
* Purpose : transfer data to/from connected target
|
* Purpose : transfer data to/from connected target
|
* Params : host - host to which target is connected
|
* Params : host - host to which target is connected
|
* Returns : 0 if failure
|
* Returns : 0 if failure
|
*/
|
*/
|
static
|
static
|
int acornscsi_starttransfer (AS_Host *host)
|
int acornscsi_starttransfer (AS_Host *host)
|
{
|
{
|
int residual;
|
int residual;
|
|
|
if (!host->scsi.SCp.ptr /*&& host->scsi.SCp.this_residual*/) {
|
if (!host->scsi.SCp.ptr /*&& host->scsi.SCp.this_residual*/) {
|
printk (KERN_ERR "scsi%d.%c: null buffer passed to acornscsi_starttransfer\n",
|
printk (KERN_ERR "scsi%d.%c: null buffer passed to acornscsi_starttransfer\n",
|
host->host->host_no, acornscsi_target (host));
|
host->host->host_no, acornscsi_target (host));
|
return 0;
|
return 0;
|
}
|
}
|
|
|
residual = host->SCpnt->request_bufflen - host->scsi.SCp.have_data_in;
|
residual = host->SCpnt->request_bufflen - host->scsi.SCp.have_data_in;
|
|
|
sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, host->device[host->SCpnt->target].sync_xfer);
|
sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, host->device[host->SCpnt->target].sync_xfer);
|
sbic_arm_writenext (host->scsi.io_port, residual >> 16);
|
sbic_arm_writenext (host->scsi.io_port, residual >> 16);
|
sbic_arm_writenext (host->scsi.io_port, residual >> 8);
|
sbic_arm_writenext (host->scsi.io_port, residual >> 8);
|
sbic_arm_writenext (host->scsi.io_port, residual);
|
sbic_arm_writenext (host->scsi.io_port, residual);
|
acornscsi_sbic_issuecmd (host, CMND_XFERINFO);
|
acornscsi_sbic_issuecmd (host, CMND_XFERINFO);
|
return 1;
|
return 1;
|
}
|
}
|
|
|
/* =========================================================================================
|
/* =========================================================================================
|
* Connection & Disconnection
|
* Connection & Disconnection
|
*/
|
*/
|
/*
|
/*
|
* Function : acornscsi_reconnect (AS_Host *host)
|
* Function : acornscsi_reconnect (AS_Host *host)
|
* Purpose : reconnect a previously disconnected command
|
* Purpose : reconnect a previously disconnected command
|
* Params : host - host specific data
|
* Params : host - host specific data
|
* Remarks : SCSI spec says:
|
* Remarks : SCSI spec says:
|
* 'The set of active pointers is restored from the set
|
* 'The set of active pointers is restored from the set
|
* of saved pointers upon reconnection of the I/O process'
|
* of saved pointers upon reconnection of the I/O process'
|
*/
|
*/
|
static
|
static
|
int acornscsi_reconnect (AS_Host *host)
|
int acornscsi_reconnect (AS_Host *host)
|
{
|
{
|
unsigned int target, lun, ok = 0;
|
unsigned int target, lun, ok = 0;
|
|
|
target = sbic_arm_read (host->scsi.io_port, SOURCEID);
|
target = sbic_arm_read (host->scsi.io_port, SOURCEID);
|
|
|
if (!(target & 8))
|
if (!(target & 8))
|
printk (KERN_ERR "scsi%d: invalid source id after reselection "
|
printk (KERN_ERR "scsi%d: invalid source id after reselection "
|
"- device fault?\n",
|
"- device fault?\n",
|
host->host->host_no);
|
host->host->host_no);
|
|
|
target &= 7;
|
target &= 7;
|
|
|
if (host->SCpnt && !host->scsi.disconnectable) {
|
if (host->SCpnt && !host->scsi.disconnectable) {
|
printk (KERN_ERR "scsi%d.%d: reconnected while command in "
|
printk (KERN_ERR "scsi%d.%d: reconnected while command in "
|
"progress to target %d?\n",
|
"progress to target %d?\n",
|
host->host->host_no, target, host->SCpnt->target);
|
host->host->host_no, target, host->SCpnt->target);
|
host->SCpnt = NULL;
|
host->SCpnt = NULL;
|
}
|
}
|
|
|
lun = sbic_arm_read (host->scsi.io_port, DATA) & 7;
|
lun = sbic_arm_read (host->scsi.io_port, DATA) & 7;
|
|
|
host->scsi.reconnected.target = target;
|
host->scsi.reconnected.target = target;
|
host->scsi.reconnected.lun = lun;
|
host->scsi.reconnected.lun = lun;
|
host->scsi.reconnected.tag = 0;
|
host->scsi.reconnected.tag = 0;
|
|
|
if (host->scsi.disconnectable && host->SCpnt &&
|
if (host->scsi.disconnectable && host->SCpnt &&
|
host->SCpnt->target == target && host->SCpnt->lun == lun)
|
host->SCpnt->target == target && host->SCpnt->lun == lun)
|
ok = 1;
|
ok = 1;
|
|
|
if (!ok && queue_probetgtlun (&host->queues.disconnected, target, lun))
|
if (!ok && queue_probetgtlun (&host->queues.disconnected, target, lun))
|
ok = 1;
|
ok = 1;
|
|
|
ADD_STATUS(target, 0x81, host->scsi.phase, 0);
|
ADD_STATUS(target, 0x81, host->scsi.phase, 0);
|
|
|
if (ok) {
|
if (ok) {
|
host->scsi.phase = PHASE_RECONNECTED;
|
host->scsi.phase = PHASE_RECONNECTED;
|
} else {
|
} else {
|
/* this doesn't seem to work */
|
/* this doesn't seem to work */
|
printk (KERN_ERR "scsi%d.%c: reselected with no command "
|
printk (KERN_ERR "scsi%d.%c: reselected with no command "
|
"to reconnect with\n",
|
"to reconnect with\n",
|
host->host->host_no, '0' + target);
|
host->host->host_no, '0' + target);
|
acornscsi_dumplog (host, target);
|
acornscsi_dumplog (host, target);
|
acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
|
acornscsi_sbic_issuecmd (host, CMND_ASSERTATN);
|
msgqueue_addmsg (&host->scsi.msgs, 1, ABORT);
|
msgqueue_addmsg (&host->scsi.msgs, 1, ABORT);
|
host->scsi.phase = PHASE_ABORTED;
|
host->scsi.phase = PHASE_ABORTED;
|
}
|
}
|
acornscsi_sbic_issuecmd (host, CMND_NEGATEACK);
|
acornscsi_sbic_issuecmd (host, CMND_NEGATEACK);
|
return !ok;
|
return !ok;
|
}
|
}
|
|
|
/*
|
/*
|
* Function: int acornscsi_reconect_finish (AS_Host *host)
|
* Function: int acornscsi_reconect_finish (AS_Host *host)
|
* Purpose : finish reconnecting a command
|
* Purpose : finish reconnecting a command
|
* Params : host - host to complete
|
* Params : host - host to complete
|
* Returns : 0 if failed
|
* Returns : 0 if failed
|
*/
|
*/
|
static
|
static
|
int acornscsi_reconnect_finish (AS_Host *host)
|
int acornscsi_reconnect_finish (AS_Host *host)
|
{
|
{
|
if (host->scsi.disconnectable && host->SCpnt) {
|
if (host->scsi.disconnectable && host->SCpnt) {
|
host->scsi.disconnectable = 0;
|
host->scsi.disconnectable = 0;
|
if (host->SCpnt->target == host->scsi.reconnected.target &&
|
if (host->SCpnt->target == host->scsi.reconnected.target &&
|
host->SCpnt->lun == host->scsi.reconnected.lun &&
|
host->SCpnt->lun == host->scsi.reconnected.lun &&
|
host->SCpnt->tag == host->scsi.reconnected.tag) {
|
host->SCpnt->tag == host->scsi.reconnected.tag) {
|
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
|
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
|
DBG(host->SCpnt, printk ("scsi%d.%c: reconnected",
|
DBG(host->SCpnt, printk ("scsi%d.%c: reconnected",
|
host->host->host_no, acornscsi_target (host)));
|
host->host->host_no, acornscsi_target (host)));
|
#endif
|
#endif
|
} else {
|
} else {
|
queue_add_cmd_tail (&host->queues.disconnected, host->SCpnt);
|
queue_add_cmd_tail (&host->queues.disconnected, host->SCpnt);
|
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
|
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
|
DBG(host->SCpnt, printk ("scsi%d.%c: had to move command "
|
DBG(host->SCpnt, printk ("scsi%d.%c: had to move command "
|
"to disconnected queue\n",
|
"to disconnected queue\n",
|
host->host->host_no, acornscsi_target (host)));
|
host->host->host_no, acornscsi_target (host)));
|
#endif
|
#endif
|
host->SCpnt = NULL;
|
host->SCpnt = NULL;
|
}
|
}
|
}
|
}
|
if (!host->SCpnt) {
|
if (!host->SCpnt) {
|
host->SCpnt = queue_remove_tgtluntag (&host->queues.disconnected,
|
host->SCpnt = queue_remove_tgtluntag (&host->queues.disconnected,
|
host->scsi.reconnected.target,
|
host->scsi.reconnected.target,
|
host->scsi.reconnected.lun,
|
host->scsi.reconnected.lun,
|
host->scsi.reconnected.tag);
|
host->scsi.reconnected.tag);
|
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
|
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
|
DBG(host->SCpnt, printk ("scsi%d.%c: had to get command",
|
DBG(host->SCpnt, printk ("scsi%d.%c: had to get command",
|
host->host->host_no, acornscsi_target (host)));
|
host->host->host_no, acornscsi_target (host)));
|
#endif
|
#endif
|
}
|
}
|
|
|
if (!host->SCpnt) {
|
if (!host->SCpnt) {
|
acornscsi_abortcmd (host, host->scsi.reconnected.tag);
|
acornscsi_abortcmd (host, host->scsi.reconnected.tag);
|
host->scsi.phase = PHASE_ABORTED;
|
host->scsi.phase = PHASE_ABORTED;
|
} else {
|
} else {
|
/*
|
/*
|
* Restore data pointer from SAVED pointers.
|
* Restore data pointer from SAVED pointers.
|
*/
|
*/
|
host->scsi.SCp = host->SCpnt->SCp;
|
host->scsi.SCp = host->SCpnt->SCp;
|
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
|
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
|
printk (", data pointers: [%p, %X]",
|
printk (", data pointers: [%p, %X]",
|
host->scsi.SCp.ptr, host->scsi.SCp.this_residual);
|
host->scsi.SCp.ptr, host->scsi.SCp.this_residual);
|
#endif
|
#endif
|
}
|
}
|
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
|
#if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
|
printk ("\n");
|
printk ("\n");
|
#endif
|
#endif
|
|
|
host->dma.transferred = host->scsi.SCp.have_data_in;
|
host->dma.transferred = host->scsi.SCp.have_data_in;
|
|
|
return host->SCpnt != NULL;
|
return host->SCpnt != NULL;
|
}
|
}
|
|
|
/*
|
/*
|
* Function: void acornscsi_disconnect_unexpected (AS_Host *host)
|
* Function: void acornscsi_disconnect_unexpected (AS_Host *host)
|
* Purpose : handle an unexpected disconnect
|
* Purpose : handle an unexpected disconnect
|
* Params : host - host on which disconnect occurred
|
* Params : host - host on which disconnect occurred
|
*/
|
*/
|
static
|
static
|
void acornscsi_disconnect_unexpected (AS_Host *host)
|
void acornscsi_disconnect_unexpected (AS_Host *host)
|
{
|
{
|
printk (KERN_ERR "scsi%d.%c: unexpected disconnect\n",
|
printk (KERN_ERR "scsi%d.%c: unexpected disconnect\n",
|
host->host->host_no, acornscsi_target (host));
|
host->host->host_no, acornscsi_target (host));
|
#if (DEBUG & DEBUG_ABORT)
|
#if (DEBUG & DEBUG_ABORT)
|
acornscsi_dumplog (host, 8);
|
acornscsi_dumplog (host, 8);
|
#endif
|
#endif
|
|
|
acornscsi_done (host, &host->SCpnt, DID_ABORT);
|
acornscsi_done (host, &host->SCpnt, DID_ABORT);
|
}
|
}
|
|
|
/*
|
/*
|
* Function: void acornscsi_abortcmd (AS_host *host, unsigned char tag)
|
* Function: void acornscsi_abortcmd (AS_host *host, unsigned char tag)
|
* Purpose : abort a currently executing command
|
* Purpose : abort a currently executing command
|
* Params : host - host with connected command to abort
|
* Params : host - host with connected command to abort
|
* tag - tag to abort
|
* tag - tag to abort
|
*/
|
*/
|
static
|
static
|
void acornscsi_abortcmd (AS_Host *host, unsigned char tag)
|
void acornscsi_abortcmd (AS_Host *host, unsigned char tag)
|
{
|
{
|
sbic_arm_write (host->scsi.io_port, CMND, CMND_ASSERTATN);
|
sbic_arm_write (host->scsi.io_port, CMND, CMND_ASSERTATN);
|
|
|
msgqueue_flush (&host->scsi.msgs);
|
msgqueue_flush (&host->scsi.msgs);
|
#ifdef SCSI2_TAG
|
#ifdef SCSI2_TAG
|
if (tag)
|
if (tag)
|
msgqueue_addmsg (&host->scsi.msgs, 2, ABORT_TAG, tag);
|
msgqueue_addmsg (&host->scsi.msgs, 2, ABORT_TAG, tag);
|
else
|
else
|
#endif
|
#endif
|
msgqueue_addmsg (&host->scsi.msgs, 1, ABORT);
|
msgqueue_addmsg (&host->scsi.msgs, 1, ABORT);
|
}
|
}
|
|
|
/* ==========================================================================================
|
/* ==========================================================================================
|
* Interrupt routines.
|
* Interrupt routines.
|
*/
|
*/
|
/*
|
/*
|
* Function: int acornscsi_sbicintr (AS_Host *host)
|
* Function: int acornscsi_sbicintr (AS_Host *host)
|
* Purpose : handle interrupts from SCSI device
|
* Purpose : handle interrupts from SCSI device
|
* Params : host - host to process
|
* Params : host - host to process
|
* Returns : INTR_PROCESS if expecting another SBIC interrupt
|
* Returns : INTR_PROCESS if expecting another SBIC interrupt
|
* INTR_IDLE if no interrupt
|
* INTR_IDLE if no interrupt
|
* INTR_NEXT_COMMAND if we have finished processing the command
|
* INTR_NEXT_COMMAND if we have finished processing the command
|
*/
|
*/
|
static
|
static
|
intr_ret_t acornscsi_sbicintr (AS_Host *host, int in_irq)
|
intr_ret_t acornscsi_sbicintr (AS_Host *host, int in_irq)
|
{
|
{
|
unsigned int asr, ssr;
|
unsigned int asr, ssr;
|
|
|
asr = sbic_arm_read (host->scsi.io_port, ASR);
|
asr = sbic_arm_read (host->scsi.io_port, ASR);
|
if (!(asr & ASR_INT))
|
if (!(asr & ASR_INT))
|
return INTR_IDLE;
|
return INTR_IDLE;
|
|
|
ssr = sbic_arm_read (host->scsi.io_port, SSR);
|
ssr = sbic_arm_read (host->scsi.io_port, SSR);
|
|
|
#if (DEBUG & DEBUG_PHASES)
|
#if (DEBUG & DEBUG_PHASES)
|
print_sbic_status(asr, ssr, host->scsi.phase);
|
print_sbic_status(asr, ssr, host->scsi.phase);
|
#endif
|
#endif
|
|
|
ADD_STATUS(8, ssr, host->scsi.phase, in_irq);
|
ADD_STATUS(8, ssr, host->scsi.phase, in_irq);
|
|
|
if (host->SCpnt && !host->scsi.disconnectable)
|
if (host->SCpnt && !host->scsi.disconnectable)
|
ADD_STATUS(host->SCpnt->target, ssr, host->scsi.phase, in_irq);
|
ADD_STATUS(host->SCpnt->target, ssr, host->scsi.phase, in_irq);
|
|
|
switch (ssr) {
|
switch (ssr) {
|
case 0x00: /* reset state - not advanced */
|
case 0x00: /* reset state - not advanced */
|
printk (KERN_ERR "scsi%d: reset in standard mode but wanted advanced mode.\n",
|
printk (KERN_ERR "scsi%d: reset in standard mode but wanted advanced mode.\n",
|
host->host->host_no);
|
host->host->host_no);
|
/* setup sbic - WD33C93A */
|
/* setup sbic - WD33C93A */
|
sbic_arm_write (host->scsi.io_port, OWNID, OWNID_EAF | host->host->this_id);
|
sbic_arm_write (host->scsi.io_port, OWNID, OWNID_EAF | host->host->this_id);
|
sbic_arm_write (host->scsi.io_port, CMND, CMND_RESET);
|
sbic_arm_write (host->scsi.io_port, CMND, CMND_RESET);
|
return INTR_IDLE;
|
return INTR_IDLE;
|
|
|
case 0x01: /* reset state - advanced */
|
case 0x01: /* reset state - advanced */
|
sbic_arm_write (host->scsi.io_port, CTRL, INIT_SBICDMA | CTRL_IDI);
|
sbic_arm_write (host->scsi.io_port, CTRL, INIT_SBICDMA | CTRL_IDI);
|
sbic_arm_write (host->scsi.io_port, TIMEOUT, TIMEOUT_TIME);
|
sbic_arm_write (host->scsi.io_port, TIMEOUT, TIMEOUT_TIME);
|
sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
|
sbic_arm_write (host->scsi.io_port, SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
|
sbic_arm_write (host->scsi.io_port, SOURCEID, SOURCEID_ER | SOURCEID_DSP);
|
sbic_arm_write (host->scsi.io_port, SOURCEID, SOURCEID_ER | SOURCEID_DSP);
|
msgqueue_flush (&host->scsi.msgs);
|
msgqueue_flush (&host->scsi.msgs);
|
return INTR_IDLE;
|
return INTR_IDLE;
|
|
|
case 0x41: /* unexpected disconnect aborted command */
|
case 0x41: /* unexpected disconnect aborted command */
|
acornscsi_disconnect_unexpected (host);
|
acornscsi_disconnect_unexpected (host);
|
return INTR_NEXT_COMMAND;
|
return INTR_NEXT_COMMAND;
|
}
|
}
|
|
|
switch (host->scsi.phase) {
|
switch (host->scsi.phase) {
|
case PHASE_CONNECTING: /* STATE: command removed from issue queue */
|
case PHASE_CONNECTING: /* STATE: command removed from issue queue */
|
switch (ssr) {
|
switch (ssr) {
|
case 0x11: /* -> PHASE_CONNECTED */
|
case 0x11: /* -> PHASE_CONNECTED */
|
/* BUS FREE -> SELECTION */
|
/* BUS FREE -> SELECTION */
|
host->scsi.phase = PHASE_CONNECTED;
|
host->scsi.phase = PHASE_CONNECTED;
|
msgqueue_flush (&host->scsi.msgs);
|
msgqueue_flush (&host->scsi.msgs);
|
host->dma.transferred = host->scsi.SCp.have_data_in;
|
host->dma.transferred = host->scsi.SCp.have_data_in;
|
/* 33C93 gives next interrupt indicating bus phase */
|
/* 33C93 gives next interrupt indicating bus phase */
|
asr = sbic_arm_read (host->scsi.io_port, ASR);
|
asr = sbic_arm_read (host->scsi.io_port, ASR);
|
if (!(asr & ASR_INT))
|
if (!(asr & ASR_INT))
|
break;
|
break;
|
ssr = sbic_arm_read (host->scsi.io_port, SSR);
|
ssr = sbic_arm_read (host->scsi.io_port, SSR);
|
ADD_STATUS(8, ssr, host->scsi.phase, 1);
|
ADD_STATUS(8, ssr, host->scsi.phase, 1);
|
ADD_STATUS(host->SCpnt->target, ssr, host->scsi.phase, 1);
|
ADD_STATUS(host->SCpnt->target, ssr, host->scsi.phase, 1);
|
goto connected;
|
goto connected;
|
|
|
case 0x42: /* select timed out */
|
case 0x42: /* select timed out */
|
/* -> PHASE_IDLE */
|
/* -> PHASE_IDLE */
|
acornscsi_done (host, &host->SCpnt, DID_NO_CONNECT);
|
acornscsi_done (host, &host->SCpnt, DID_NO_CONNECT);
|
return INTR_NEXT_COMMAND;
|
return INTR_NEXT_COMMAND;
|
|
|
case 0x81: /* -> PHASE_RECONNECTED or PHASE_ABORTED */
|
case 0x81: /* -> PHASE_RECONNECTED or PHASE_ABORTED */
|
/* BUS FREE -> RESELECTION */
|
/* BUS FREE -> RESELECTION */
|
host->origSCpnt = host->SCpnt;
|
host->origSCpnt = host->SCpnt;
|
host->SCpnt = NULL;
|
host->SCpnt = NULL;
|
msgqueue_flush (&host->scsi.msgs);
|
msgqueue_flush (&host->scsi.msgs);
|
acornscsi_reconnect (host);
|
acornscsi_reconnect (host);
|
break;
|
break;
|
|
|
default:
|
default:
|
printk (KERN_ERR "scsi%d.%c: PHASE_CONNECTING, SSR %02X?\n",
|
printk (KERN_ERR "scsi%d.%c: PHASE_CONNECTING, SSR %02X?\n",
|
host->host->host_no, acornscsi_target (host), ssr);
|
host->host->host_no, acornscsi_target (host), ssr);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
}
|
}
|
return INTR_PROCESSING;
|
return INTR_PROCESSING;
|
|
|
connected:
|
connected:
|
case PHASE_CONNECTED: /* STATE: device selected ok */
|
case PHASE_CONNECTED: /* STATE: device selected ok */
|
switch (ssr) {
|
switch (ssr) {
|
#ifdef NONSTANDARD
|
#ifdef NONSTANDARD
|
case 0x8a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
|
case 0x8a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
|
/* SELECTION -> COMMAND */
|
/* SELECTION -> COMMAND */
|
acornscsi_sendcommand (host);
|
acornscsi_sendcommand (host);
|
break;
|
break;
|
|
|
case 0x8b: /* -> PHASE_STATUS */
|
case 0x8b: /* -> PHASE_STATUS */
|
/* SELECTION -> STATUS */
|
/* SELECTION -> STATUS */
|
acornscsi_readstatusbyte (host);
|
acornscsi_readstatusbyte (host);
|
host->scsi.phase = PHASE_STATUSIN;
|
host->scsi.phase = PHASE_STATUSIN;
|
break;
|
break;
|
#endif
|
#endif
|
|
|
case 0x8e: /* -> PHASE_MSGOUT */
|
case 0x8e: /* -> PHASE_MSGOUT */
|
/* SELECTION ->MESSAGE OUT */
|
/* SELECTION ->MESSAGE OUT */
|
host->scsi.phase = PHASE_MSGOUT;
|
host->scsi.phase = PHASE_MSGOUT;
|
acornscsi_buildmessages (host);
|
acornscsi_buildmessages (host);
|
acornscsi_sendmessage (host);
|
acornscsi_sendmessage (host);
|
break;
|
break;
|
|
|
/* these should not happen */
|
/* these should not happen */
|
case 0x85: /* target disconnected */
|
case 0x85: /* target disconnected */
|
acornscsi_done (host, &host->SCpnt, DID_ERROR);
|
acornscsi_done (host, &host->SCpnt, DID_ERROR);
|
break;
|
break;
|
|
|
default:
|
default:
|
printk (KERN_ERR "scsi%d.%c: PHASE_CONNECTED, SSR %02X?\n",
|
printk (KERN_ERR "scsi%d.%c: PHASE_CONNECTED, SSR %02X?\n",
|
host->host->host_no, acornscsi_target (host), ssr);
|
host->host->host_no, acornscsi_target (host), ssr);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
}
|
}
|
return INTR_PROCESSING;
|
return INTR_PROCESSING;
|
|
|
case PHASE_MSGOUT: /* STATE: connected & sent IDENTIFY message */
|
case PHASE_MSGOUT: /* STATE: connected & sent IDENTIFY message */
|
/*
|
/*
|
* SCSI standard says th at a MESSAGE OUT phases can be followed by a DATA phase
|
* SCSI standard says th at a MESSAGE OUT phases can be followed by a DATA phase
|
*/
|
*/
|
switch (ssr) {
|
switch (ssr) {
|
case 0x8a:
|
case 0x8a:
|
case 0x1a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
|
case 0x1a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
|
/* MESSAGE OUT -> COMMAND */
|
/* MESSAGE OUT -> COMMAND */
|
acornscsi_sendcommand (host);
|
acornscsi_sendcommand (host);
|
break;
|
break;
|
|
|
case 0x1b: /* -> PHASE_STATUS */
|
case 0x1b: /* -> PHASE_STATUS */
|
/* MESSAGE OUT -> STATUS */
|
/* MESSAGE OUT -> STATUS */
|
acornscsi_readstatusbyte (host);
|
acornscsi_readstatusbyte (host);
|
host->scsi.phase = PHASE_STATUSIN;
|
host->scsi.phase = PHASE_STATUSIN;
|
break;
|
break;
|
|
|
case 0x8e: /* -> PHASE_MSGOUT */
|
case 0x8e: /* -> PHASE_MSGOUT */
|
/* MESSAGE_OUT(MESSAGE_IN) ->MESSAGE OUT */
|
/* MESSAGE_OUT(MESSAGE_IN) ->MESSAGE OUT */
|
acornscsi_sendmessage (host);
|
acornscsi_sendmessage (host);
|
break;
|
break;
|
|
|
case 0x4f:
|
case 0x4f:
|
case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
|
case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
|
/* MESSAGE OUT -> MESSAGE IN */
|
/* MESSAGE OUT -> MESSAGE IN */
|
acornscsi_message (host);
|
acornscsi_message (host);
|
break;
|
break;
|
|
|
default:
|
default:
|
printk (KERN_ERR "scsi%d.%c: PHASE_MSGOUT, SSR %02X?\n",
|
printk (KERN_ERR "scsi%d.%c: PHASE_MSGOUT, SSR %02X?\n",
|
host->host->host_no, acornscsi_target (host), ssr);
|
host->host->host_no, acornscsi_target (host), ssr);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
}
|
}
|
return INTR_PROCESSING;
|
return INTR_PROCESSING;
|
|
|
case PHASE_COMMAND: /* STATE: connected & command sent */
|
case PHASE_COMMAND: /* STATE: connected & command sent */
|
switch (ssr) {
|
switch (ssr) {
|
case 0x18: /* -> PHASE_DATAOUT */
|
case 0x18: /* -> PHASE_DATAOUT */
|
/* COMMAND -> DATA OUT */
|
/* COMMAND -> DATA OUT */
|
if (host->scsi.SCp.sent_command != host->SCpnt->cmd_len)
|
if (host->scsi.SCp.sent_command != host->SCpnt->cmd_len)
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
acornscsi_dma_setup (host, DMA_OUT);
|
acornscsi_dma_setup (host, DMA_OUT);
|
if (!acornscsi_starttransfer (host))
|
if (!acornscsi_starttransfer (host))
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
host->scsi.phase = PHASE_DATAOUT;
|
host->scsi.phase = PHASE_DATAOUT;
|
return INTR_IDLE;
|
return INTR_IDLE;
|
|
|
case 0x19: /* -> PHASE_DATAIN */
|
case 0x19: /* -> PHASE_DATAIN */
|
/* COMMAND -> DATA IN */
|
/* COMMAND -> DATA IN */
|
if (host->scsi.SCp.sent_command != host->SCpnt->cmd_len)
|
if (host->scsi.SCp.sent_command != host->SCpnt->cmd_len)
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
acornscsi_dma_setup (host, DMA_IN);
|
acornscsi_dma_setup (host, DMA_IN);
|
if (!acornscsi_starttransfer (host))
|
if (!acornscsi_starttransfer (host))
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
host->scsi.phase = PHASE_DATAIN;
|
host->scsi.phase = PHASE_DATAIN;
|
return INTR_IDLE;
|
return INTR_IDLE;
|
|
|
case 0x1b: /* -> PHASE_STATUS */
|
case 0x1b: /* -> PHASE_STATUS */
|
/* COMMAND -> STATUS */
|
/* COMMAND -> STATUS */
|
acornscsi_readstatusbyte (host);
|
acornscsi_readstatusbyte (host);
|
host->scsi.phase = PHASE_STATUSIN;
|
host->scsi.phase = PHASE_STATUSIN;
|
break;
|
break;
|
|
|
case 0x1e: /* -> PHASE_MSGOUT */
|
case 0x1e: /* -> PHASE_MSGOUT */
|
/* COMMAND -> MESSAGE OUT */
|
/* COMMAND -> MESSAGE OUT */
|
acornscsi_sendmessage (host);
|
acornscsi_sendmessage (host);
|
break;
|
break;
|
|
|
case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
|
case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
|
/* COMMAND -> MESSAGE IN */
|
/* COMMAND -> MESSAGE IN */
|
acornscsi_message (host);
|
acornscsi_message (host);
|
break;
|
break;
|
|
|
default:
|
default:
|
printk (KERN_ERR "scsi%d.%c: PHASE_COMMAND, SSR %02X?\n",
|
printk (KERN_ERR "scsi%d.%c: PHASE_COMMAND, SSR %02X?\n",
|
host->host->host_no, acornscsi_target (host), ssr);
|
host->host->host_no, acornscsi_target (host), ssr);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
}
|
}
|
return INTR_PROCESSING;
|
return INTR_PROCESSING;
|
|
|
case PHASE_DISCONNECT: /* STATE: connected, received DISCONNECT msg */
|
case PHASE_DISCONNECT: /* STATE: connected, received DISCONNECT msg */
|
if (ssr == 0x85) { /* -> PHASE_IDLE */
|
if (ssr == 0x85) { /* -> PHASE_IDLE */
|
host->scsi.disconnectable = 1;
|
host->scsi.disconnectable = 1;
|
host->scsi.reconnected.tag = 0;
|
host->scsi.reconnected.tag = 0;
|
host->scsi.phase = PHASE_IDLE;
|
host->scsi.phase = PHASE_IDLE;
|
host->stats.disconnects += 1;
|
host->stats.disconnects += 1;
|
} else {
|
} else {
|
printk (KERN_ERR "scsi%d.%c: PHASE_DISCONNECT, SSR %02X instead of disconnect?\n",
|
printk (KERN_ERR "scsi%d.%c: PHASE_DISCONNECT, SSR %02X instead of disconnect?\n",
|
host->host->host_no, acornscsi_target (host), ssr);
|
host->host->host_no, acornscsi_target (host), ssr);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
}
|
}
|
return INTR_NEXT_COMMAND;
|
return INTR_NEXT_COMMAND;
|
|
|
case PHASE_IDLE: /* STATE: disconnected */
|
case PHASE_IDLE: /* STATE: disconnected */
|
if (ssr == 0x81) /* -> PHASE_RECONNECTED or PHASE_ABORTED */
|
if (ssr == 0x81) /* -> PHASE_RECONNECTED or PHASE_ABORTED */
|
acornscsi_reconnect (host);
|
acornscsi_reconnect (host);
|
else {
|
else {
|
printk (KERN_ERR "scsi%d.%c: PHASE_IDLE, SSR %02X while idle?\n",
|
printk (KERN_ERR "scsi%d.%c: PHASE_IDLE, SSR %02X while idle?\n",
|
host->host->host_no, acornscsi_target (host), ssr);
|
host->host->host_no, acornscsi_target (host), ssr);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
}
|
}
|
return INTR_PROCESSING;
|
return INTR_PROCESSING;
|
|
|
case PHASE_RECONNECTED: /* STATE: device reconnected to initiator */
|
case PHASE_RECONNECTED: /* STATE: device reconnected to initiator */
|
/*
|
/*
|
* Command reconnected - if MESGIN, get message - it may be
|
* Command reconnected - if MESGIN, get message - it may be
|
* the tag. If not, get command out of disconnected queue
|
* the tag. If not, get command out of disconnected queue
|
*/
|
*/
|
/*
|
/*
|
* If we reconnected and we're not in MESSAGE IN phase after IDENTIFY,
|
* If we reconnected and we're not in MESSAGE IN phase after IDENTIFY,
|
* reconnect I_T_L command
|
* reconnect I_T_L command
|
*/
|
*/
|
if (ssr != 0x8f && !acornscsi_reconnect_finish (host))
|
if (ssr != 0x8f && !acornscsi_reconnect_finish (host))
|
return INTR_IDLE;
|
return INTR_IDLE;
|
ADD_STATUS(host->SCpnt->target, ssr, host->scsi.phase, in_irq);
|
ADD_STATUS(host->SCpnt->target, ssr, host->scsi.phase, in_irq);
|
switch (ssr) {
|
switch (ssr) {
|
case 0x88: /* data out phase */
|
case 0x88: /* data out phase */
|
/* -> PHASE_DATAOUT */
|
/* -> PHASE_DATAOUT */
|
/* MESSAGE IN -> DATA OUT */
|
/* MESSAGE IN -> DATA OUT */
|
acornscsi_dma_setup (host, DMA_OUT);
|
acornscsi_dma_setup (host, DMA_OUT);
|
if (!acornscsi_starttransfer (host))
|
if (!acornscsi_starttransfer (host))
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
host->scsi.phase = PHASE_DATAOUT;
|
host->scsi.phase = PHASE_DATAOUT;
|
return INTR_IDLE;
|
return INTR_IDLE;
|
|
|
case 0x89: /* data in phase */
|
case 0x89: /* data in phase */
|
/* -> PHASE_DATAIN */
|
/* -> PHASE_DATAIN */
|
/* MESSAGE IN -> DATA IN */
|
/* MESSAGE IN -> DATA IN */
|
acornscsi_dma_setup (host, DMA_IN);
|
acornscsi_dma_setup (host, DMA_IN);
|
if (!acornscsi_starttransfer (host))
|
if (!acornscsi_starttransfer (host))
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
host->scsi.phase = PHASE_DATAIN;
|
host->scsi.phase = PHASE_DATAIN;
|
return INTR_IDLE;
|
return INTR_IDLE;
|
|
|
case 0x8a: /* command out */
|
case 0x8a: /* command out */
|
/* MESSAGE IN -> COMMAND */
|
/* MESSAGE IN -> COMMAND */
|
acornscsi_sendcommand (host);/* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
|
acornscsi_sendcommand (host);/* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
|
break;
|
break;
|
|
|
case 0x8b: /* status in */
|
case 0x8b: /* status in */
|
/* -> PHASE_STATUSIN */
|
/* -> PHASE_STATUSIN */
|
/* MESSAGE IN -> STATUS */
|
/* MESSAGE IN -> STATUS */
|
acornscsi_readstatusbyte (host);
|
acornscsi_readstatusbyte (host);
|
host->scsi.phase = PHASE_STATUSIN;
|
host->scsi.phase = PHASE_STATUSIN;
|
break;
|
break;
|
|
|
case 0x8e: /* message out */
|
case 0x8e: /* message out */
|
/* -> PHASE_MSGOUT */
|
/* -> PHASE_MSGOUT */
|
/* MESSAGE IN -> MESSAGE OUT */
|
/* MESSAGE IN -> MESSAGE OUT */
|
acornscsi_sendmessage (host);
|
acornscsi_sendmessage (host);
|
break;
|
break;
|
|
|
case 0x8f: /* message in */
|
case 0x8f: /* message in */
|
acornscsi_message (host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
|
acornscsi_message (host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
|
break;
|
break;
|
|
|
default:
|
default:
|
printk (KERN_ERR "scsi%d.%c: PHASE_RECONNECTED, SSR %02X after reconnect?\n",
|
printk (KERN_ERR "scsi%d.%c: PHASE_RECONNECTED, SSR %02X after reconnect?\n",
|
host->host->host_no, acornscsi_target (host), ssr);
|
host->host->host_no, acornscsi_target (host), ssr);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
}
|
}
|
return INTR_PROCESSING;
|
return INTR_PROCESSING;
|
|
|
case PHASE_DATAIN: /* STATE: transferred data in */
|
case PHASE_DATAIN: /* STATE: transferred data in */
|
/*
|
/*
|
* This is simple - if we disconnect then the DMA address & count is
|
* This is simple - if we disconnect then the DMA address & count is
|
* correct.
|
* correct.
|
*/
|
*/
|
switch (ssr) {
|
switch (ssr) {
|
case 0x19: /* -> PHASE_DATAIN */
|
case 0x19: /* -> PHASE_DATAIN */
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
return INTR_IDLE;
|
return INTR_IDLE;
|
|
|
case 0x4b: /* -> PHASE_STATUSIN */
|
case 0x4b: /* -> PHASE_STATUSIN */
|
case 0x1b: /* -> PHASE_STATUSIN */
|
case 0x1b: /* -> PHASE_STATUSIN */
|
/* DATA IN -> STATUS */
|
/* DATA IN -> STATUS */
|
host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
|
host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
|
acornscsi_sbic_xfcount (host);
|
acornscsi_sbic_xfcount (host);
|
acornscsi_dma_stop (host);
|
acornscsi_dma_stop (host);
|
acornscsi_readstatusbyte (host);
|
acornscsi_readstatusbyte (host);
|
host->scsi.phase = PHASE_STATUSIN;
|
host->scsi.phase = PHASE_STATUSIN;
|
break;
|
break;
|
|
|
case 0x1e: /* -> PHASE_MSGOUT */
|
case 0x1e: /* -> PHASE_MSGOUT */
|
case 0x4e: /* -> PHASE_MSGOUT */
|
case 0x4e: /* -> PHASE_MSGOUT */
|
/* DATA IN -> MESSAGE OUT */
|
/* DATA IN -> MESSAGE OUT */
|
host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
|
host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
|
acornscsi_sbic_xfcount (host);
|
acornscsi_sbic_xfcount (host);
|
acornscsi_dma_stop (host);
|
acornscsi_dma_stop (host);
|
acornscsi_sendmessage (host);
|
acornscsi_sendmessage (host);
|
break;
|
break;
|
|
|
case 0x1f: /* message in */
|
case 0x1f: /* message in */
|
case 0x4f: /* message in */
|
case 0x4f: /* message in */
|
/* DATA IN -> MESSAGE IN */
|
/* DATA IN -> MESSAGE IN */
|
host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
|
host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
|
acornscsi_sbic_xfcount (host);
|
acornscsi_sbic_xfcount (host);
|
acornscsi_dma_stop (host);
|
acornscsi_dma_stop (host);
|
acornscsi_message (host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
|
acornscsi_message (host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
|
break;
|
break;
|
|
|
default:
|
default:
|
printk (KERN_ERR "scsi%d.%c: PHASE_DATAIN, SSR %02X?\n",
|
printk (KERN_ERR "scsi%d.%c: PHASE_DATAIN, SSR %02X?\n",
|
host->host->host_no, acornscsi_target (host), ssr);
|
host->host->host_no, acornscsi_target (host), ssr);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
}
|
}
|
return INTR_PROCESSING;
|
return INTR_PROCESSING;
|
|
|
case PHASE_DATAOUT: /* STATE: transferred data out */
|
case PHASE_DATAOUT: /* STATE: transferred data out */
|
/*
|
/*
|
* This is more complicated - if we disconnect, the DMA could be 12
|
* This is more complicated - if we disconnect, the DMA could be 12
|
* bytes ahead of us. We need to correct this.
|
* bytes ahead of us. We need to correct this.
|
*/
|
*/
|
switch (ssr) {
|
switch (ssr) {
|
case 0x18: /* -> PHASE_DATAOUT */
|
case 0x18: /* -> PHASE_DATAOUT */
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
return INTR_IDLE;
|
return INTR_IDLE;
|
|
|
case 0x4b: /* -> PHASE_STATUSIN */
|
case 0x4b: /* -> PHASE_STATUSIN */
|
case 0x1b: /* -> PHASE_STATUSIN */
|
case 0x1b: /* -> PHASE_STATUSIN */
|
/* DATA OUT -> STATUS */
|
/* DATA OUT -> STATUS */
|
host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
|
host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
|
acornscsi_sbic_xfcount (host);
|
acornscsi_sbic_xfcount (host);
|
acornscsi_dma_stop (host);
|
acornscsi_dma_stop (host);
|
acornscsi_dma_adjust (host);
|
acornscsi_dma_adjust (host);
|
acornscsi_readstatusbyte (host);
|
acornscsi_readstatusbyte (host);
|
host->scsi.phase = PHASE_STATUSIN;
|
host->scsi.phase = PHASE_STATUSIN;
|
break;
|
break;
|
|
|
case 0x1e: /* -> PHASE_MSGOUT */
|
case 0x1e: /* -> PHASE_MSGOUT */
|
case 0x4e: /* -> PHASE_MSGOUT */
|
case 0x4e: /* -> PHASE_MSGOUT */
|
/* DATA OUT -> MESSAGE OUT */
|
/* DATA OUT -> MESSAGE OUT */
|
host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
|
host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
|
acornscsi_sbic_xfcount (host);
|
acornscsi_sbic_xfcount (host);
|
acornscsi_dma_stop (host);
|
acornscsi_dma_stop (host);
|
acornscsi_dma_adjust (host);
|
acornscsi_dma_adjust (host);
|
acornscsi_sendmessage (host);
|
acornscsi_sendmessage (host);
|
break;
|
break;
|
|
|
case 0x1f: /* message in */
|
case 0x1f: /* message in */
|
case 0x4f: /* message in */
|
case 0x4f: /* message in */
|
/* DATA OUT -> MESSAGE IN */
|
/* DATA OUT -> MESSAGE IN */
|
host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
|
host->scsi.SCp.have_data_in = host->SCpnt->request_bufflen -
|
acornscsi_sbic_xfcount (host);
|
acornscsi_sbic_xfcount (host);
|
acornscsi_dma_stop (host);
|
acornscsi_dma_stop (host);
|
acornscsi_dma_adjust (host);
|
acornscsi_dma_adjust (host);
|
acornscsi_message (host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
|
acornscsi_message (host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
|
break;
|
break;
|
|
|
default:
|
default:
|
printk (KERN_ERR "scsi%d.%c: PHASE_DATAOUT, SSR %02X?\n",
|
printk (KERN_ERR "scsi%d.%c: PHASE_DATAOUT, SSR %02X?\n",
|
host->host->host_no, acornscsi_target (host), ssr);
|
host->host->host_no, acornscsi_target (host), ssr);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
}
|
}
|
return INTR_PROCESSING;
|
return INTR_PROCESSING;
|
|
|
case PHASE_STATUSIN: /* STATE: status in complete */
|
case PHASE_STATUSIN: /* STATE: status in complete */
|
if (ssr == 0x1f) /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
|
if (ssr == 0x1f) /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
|
/* STATUS -> MESSAGE IN */
|
/* STATUS -> MESSAGE IN */
|
acornscsi_message (host);
|
acornscsi_message (host);
|
else if (ssr == 0x1e) /* -> PHASE_MSGOUT */
|
else if (ssr == 0x1e) /* -> PHASE_MSGOUT */
|
/* STATUS -> MESSAGE OUT */
|
/* STATUS -> MESSAGE OUT */
|
acornscsi_sendmessage (host);
|
acornscsi_sendmessage (host);
|
else {
|
else {
|
printk (KERN_ERR "scsi%d.%c: PHASE_STATUSIN, SSR %02X instead of MESSAGE_IN?\n",
|
printk (KERN_ERR "scsi%d.%c: PHASE_STATUSIN, SSR %02X instead of MESSAGE_IN?\n",
|
host->host->host_no, acornscsi_target (host), ssr);
|
host->host->host_no, acornscsi_target (host), ssr);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
}
|
}
|
return INTR_PROCESSING;
|
return INTR_PROCESSING;
|
|
|
case PHASE_MSGIN: /* STATE: message in */
|
case PHASE_MSGIN: /* STATE: message in */
|
switch (ssr) {
|
switch (ssr) {
|
case 0x1e: /* -> PHASE_MSGOUT */
|
case 0x1e: /* -> PHASE_MSGOUT */
|
case 0x4e: /* -> PHASE_MSGOUT */
|
case 0x4e: /* -> PHASE_MSGOUT */
|
/* MESSAGE IN -> MESSAGE OUT */
|
/* MESSAGE IN -> MESSAGE OUT */
|
acornscsi_sendmessage (host);
|
acornscsi_sendmessage (host);
|
break;
|
break;
|
|
|
case 0x1f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
|
case 0x1f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
|
case 0x2f:
|
case 0x2f:
|
case 0x4f:
|
case 0x4f:
|
case 0x8f:
|
case 0x8f:
|
acornscsi_message (host);
|
acornscsi_message (host);
|
break;
|
break;
|
|
|
default:
|
default:
|
printk (KERN_ERR "scsi%d.%c: PHASE_MSGIN, SSR %02X after message in?\n",
|
printk (KERN_ERR "scsi%d.%c: PHASE_MSGIN, SSR %02X after message in?\n",
|
host->host->host_no, acornscsi_target (host), ssr);
|
host->host->host_no, acornscsi_target (host), ssr);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
}
|
}
|
return INTR_PROCESSING;
|
return INTR_PROCESSING;
|
|
|
case PHASE_DONE: /* STATE: received status & message */
|
case PHASE_DONE: /* STATE: received status & message */
|
switch (ssr) {
|
switch (ssr) {
|
case 0x85: /* -> PHASE_IDLE */
|
case 0x85: /* -> PHASE_IDLE */
|
acornscsi_done (host, &host->SCpnt, DID_OK);
|
acornscsi_done (host, &host->SCpnt, DID_OK);
|
return INTR_NEXT_COMMAND;
|
return INTR_NEXT_COMMAND;
|
|
|
case 0x8e:
|
case 0x8e:
|
acornscsi_sendmessage (host);
|
acornscsi_sendmessage (host);
|
break;
|
break;
|
|
|
default:
|
default:
|
printk (KERN_ERR "scsi%d.%c: PHASE_DONE, SSR %02X instead of disconnect?\n",
|
printk (KERN_ERR "scsi%d.%c: PHASE_DONE, SSR %02X instead of disconnect?\n",
|
host->host->host_no, acornscsi_target (host), ssr);
|
host->host->host_no, acornscsi_target (host), ssr);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
}
|
}
|
return INTR_PROCESSING;
|
return INTR_PROCESSING;
|
|
|
case PHASE_ABORTED:
|
case PHASE_ABORTED:
|
switch (ssr) {
|
switch (ssr) {
|
case 0x85:
|
case 0x85:
|
acornscsi_done (host, &host->SCpnt, DID_ABORT);
|
acornscsi_done (host, &host->SCpnt, DID_ABORT);
|
return INTR_NEXT_COMMAND;
|
return INTR_NEXT_COMMAND;
|
|
|
case 0x1e:
|
case 0x1e:
|
case 0x2e:
|
case 0x2e:
|
case 0x4e:
|
case 0x4e:
|
case 0x8e:
|
case 0x8e:
|
acornscsi_sendmessage (host);
|
acornscsi_sendmessage (host);
|
break;
|
break;
|
|
|
default:
|
default:
|
printk (KERN_ERR "scsi%d.%c: PHASE_ABORTED, SSR %02X?\n",
|
printk (KERN_ERR "scsi%d.%c: PHASE_ABORTED, SSR %02X?\n",
|
host->host->host_no, acornscsi_target (host), ssr);
|
host->host->host_no, acornscsi_target (host), ssr);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
}
|
}
|
return INTR_PROCESSING;
|
return INTR_PROCESSING;
|
|
|
default:
|
default:
|
printk (KERN_ERR "scsi%d.%c: unknown driver phase %d\n",
|
printk (KERN_ERR "scsi%d.%c: unknown driver phase %d\n",
|
host->host->host_no, acornscsi_target (host), ssr);
|
host->host->host_no, acornscsi_target (host), ssr);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
acornscsi_dumplog (host, host->SCpnt ? host->SCpnt->target : 8);
|
}
|
}
|
return INTR_PROCESSING;
|
return INTR_PROCESSING;
|
}
|
}
|
|
|
/*
|
/*
|
* Prototype: void acornscsi_intr (int irq, void *dev_id, struct pt_regs *regs)
|
* Prototype: void acornscsi_intr (int irq, void *dev_id, struct pt_regs *regs)
|
* Purpose : handle interrupts from Acorn SCSI card
|
* Purpose : handle interrupts from Acorn SCSI card
|
* Params : irq - interrupt number
|
* Params : irq - interrupt number
|
* dev_id - device specific data (AS_Host structure)
|
* dev_id - device specific data (AS_Host structure)
|
* regs - processor registers when interrupt occurred
|
* regs - processor registers when interrupt occurred
|
*/
|
*/
|
static
|
static
|
void acornscsi_intr (int irq, void *dev_id, struct pt_regs *regs)
|
void acornscsi_intr (int irq, void *dev_id, struct pt_regs *regs)
|
{
|
{
|
AS_Host *host = (AS_Host *)dev_id;
|
AS_Host *host = (AS_Host *)dev_id;
|
intr_ret_t ret;
|
intr_ret_t ret;
|
int iostatus;
|
int iostatus;
|
int in_irq = 0;
|
int in_irq = 0;
|
|
|
if (host->scsi.interrupt)
|
if (host->scsi.interrupt)
|
printk ("scsi%d: interrupt re-entered\n", host->host->host_no);
|
printk ("scsi%d: interrupt re-entered\n", host->host->host_no);
|
host->scsi.interrupt = 1;
|
host->scsi.interrupt = 1;
|
|
|
do {
|
do {
|
ret = INTR_IDLE;
|
ret = INTR_IDLE;
|
|
|
iostatus = inb (host->card.io_intr);
|
iostatus = inb (host->card.io_intr);
|
|
|
if (iostatus & 2) {
|
if (iostatus & 2) {
|
acornscsi_dma_intr (host);
|
acornscsi_dma_intr (host);
|
iostatus = inb (host->card.io_intr);
|
iostatus = inb (host->card.io_intr);
|
}
|
}
|
|
|
if (iostatus & 8)
|
if (iostatus & 8)
|
ret = acornscsi_sbicintr (host, in_irq);
|
ret = acornscsi_sbicintr (host, in_irq);
|
|
|
/*
|
/*
|
* If we have a transfer pending, start it.
|
* If we have a transfer pending, start it.
|
* Only start it if the interface has already started transferring
|
* Only start it if the interface has already started transferring
|
* it's data
|
* it's data
|
*/
|
*/
|
if (host->dma.xfer_required)
|
if (host->dma.xfer_required)
|
acornscsi_dma_xfer (host);
|
acornscsi_dma_xfer (host);
|
|
|
if (ret == INTR_NEXT_COMMAND)
|
if (ret == INTR_NEXT_COMMAND)
|
ret = acornscsi_kick (host);
|
ret = acornscsi_kick (host);
|
|
|
in_irq = 1;
|
in_irq = 1;
|
} while (ret != INTR_IDLE);
|
} while (ret != INTR_IDLE);
|
|
|
host->scsi.interrupt = 0;
|
host->scsi.interrupt = 0;
|
}
|
}
|
|
|
/*=============================================================================================
|
/*=============================================================================================
|
* Interfaces between interrupt handler and rest of scsi code
|
* Interfaces between interrupt handler and rest of scsi code
|
*/
|
*/
|
|
|
/*
|
/*
|
* Function : acornscsi_queuecmd (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
|
* Function : acornscsi_queuecmd (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
|
* Purpose : queues a SCSI command
|
* Purpose : queues a SCSI command
|
* Params : cmd - SCSI command
|
* Params : cmd - SCSI command
|
* done - function called on completion, with pointer to command descriptor
|
* done - function called on completion, with pointer to command descriptor
|
* Returns : 0, or < 0 on error.
|
* Returns : 0, or < 0 on error.
|
*/
|
*/
|
int acornscsi_queuecmd (Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
|
int acornscsi_queuecmd (Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
|
{
|
{
|
AS_Host *host = (AS_Host *)SCpnt->host->hostdata;
|
AS_Host *host = (AS_Host *)SCpnt->host->hostdata;
|
|
|
if (!done) {
|
if (!done) {
|
/* there should be some way of rejecting errors like this without panicing... */
|
/* there should be some way of rejecting errors like this without panicing... */
|
panic ("scsi%d: queuecommand called with NULL done function [cmd=%p]",
|
panic ("scsi%d: queuecommand called with NULL done function [cmd=%p]",
|
SCpnt->host->host_no, SCpnt);
|
SCpnt->host->host_no, SCpnt);
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
|
|
#if (DEBUG & DEBUG_NO_WRITE)
|
#if (DEBUG & DEBUG_NO_WRITE)
|
if (acornscsi_cmdtype (SCpnt->cmnd[0]) == CMD_WRITE && (NO_WRITE & (1 << SCpnt->target))) {
|
if (acornscsi_cmdtype (SCpnt->cmnd[0]) == CMD_WRITE && (NO_WRITE & (1 << SCpnt->target))) {
|
printk (KERN_CRIT "scsi%d.%c: WRITE attempted with NO_WRITE flag set\n",
|
printk (KERN_CRIT "scsi%d.%c: WRITE attempted with NO_WRITE flag set\n",
|
SCpnt->host->host_no, '0' + SCpnt->target);
|
SCpnt->host->host_no, '0' + SCpnt->target);
|
SCpnt->result = DID_NO_CONNECT << 16;
|
SCpnt->result = DID_NO_CONNECT << 16;
|
done (SCpnt);
|
done (SCpnt);
|
return 0;
|
return 0;
|
}
|
}
|
#endif
|
#endif
|
|
|
SCpnt->scsi_done = done;
|
SCpnt->scsi_done = done;
|
SCpnt->host_scribble = NULL;
|
SCpnt->host_scribble = NULL;
|
SCpnt->result = 0;
|
SCpnt->result = 0;
|
SCpnt->tag = 0;
|
SCpnt->tag = 0;
|
SCpnt->SCp.phase = (int)acornscsi_datadirection (SCpnt->cmnd[0]);
|
SCpnt->SCp.phase = (int)acornscsi_datadirection (SCpnt->cmnd[0]);
|
SCpnt->SCp.sent_command = 0;
|
SCpnt->SCp.sent_command = 0;
|
SCpnt->SCp.have_data_in = 0;
|
SCpnt->SCp.have_data_in = 0;
|
SCpnt->SCp.Status = 0;
|
SCpnt->SCp.Status = 0;
|
SCpnt->SCp.Message = 0;
|
SCpnt->SCp.Message = 0;
|
|
|
if (SCpnt->use_sg) {
|
if (SCpnt->use_sg) {
|
SCpnt->SCp.buffer = (struct scatterlist *) SCpnt->buffer;
|
SCpnt->SCp.buffer = (struct scatterlist *) SCpnt->buffer;
|
SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1;
|
SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1;
|
SCpnt->SCp.ptr = (char *) SCpnt->SCp.buffer->address;
|
SCpnt->SCp.ptr = (char *) SCpnt->SCp.buffer->address;
|
SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
|
SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
|
} else {
|
} else {
|
SCpnt->SCp.buffer = NULL;
|
SCpnt->SCp.buffer = NULL;
|
SCpnt->SCp.buffers_residual = 0;
|
SCpnt->SCp.buffers_residual = 0;
|
SCpnt->SCp.ptr = (char *) SCpnt->request_buffer;
|
SCpnt->SCp.ptr = (char *) SCpnt->request_buffer;
|
SCpnt->SCp.this_residual = SCpnt->request_bufflen;
|
SCpnt->SCp.this_residual = SCpnt->request_bufflen;
|
}
|
}
|
|
|
host->stats.queues += 1;
|
host->stats.queues += 1;
|
|
|
{
|
{
|
unsigned long flags;
|
unsigned long flags;
|
|
|
if (!queue_add_cmd_ordered (&host->queues.issue, SCpnt)) {
|
if (!queue_add_cmd_ordered (&host->queues.issue, SCpnt)) {
|
SCpnt->result = DID_ERROR << 16;
|
SCpnt->result = DID_ERROR << 16;
|
done (SCpnt);
|
done (SCpnt);
|
return 0;
|
return 0;
|
}
|
}
|
save_flags_cli (flags);
|
save_flags_cli (flags);
|
if (host->scsi.phase == PHASE_IDLE)
|
if (host->scsi.phase == PHASE_IDLE)
|
acornscsi_kick (host);
|
acornscsi_kick (host);
|
restore_flags (flags);
|
restore_flags (flags);
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*
|
/*
|
* Prototype: void acornscsi_reportstatus (Scsi_Cmnd **SCpntp1, Scsi_Cmnd **SCpntp2, int result)
|
* Prototype: void acornscsi_reportstatus (Scsi_Cmnd **SCpntp1, Scsi_Cmnd **SCpntp2, int result)
|
* Purpose : pass a result to *SCpntp1, and check if *SCpntp1 = *SCpntp2
|
* Purpose : pass a result to *SCpntp1, and check if *SCpntp1 = *SCpntp2
|
* Params : SCpntp1 - pointer to command to return
|
* Params : SCpntp1 - pointer to command to return
|
* SCpntp2 - pointer to command to check
|
* SCpntp2 - pointer to command to check
|
* result - result to pass back to mid-level done function
|
* result - result to pass back to mid-level done function
|
* Returns : *SCpntp2 = NULL if *SCpntp1 is the same command structure as *SCpntp2.
|
* Returns : *SCpntp2 = NULL if *SCpntp1 is the same command structure as *SCpntp2.
|
*/
|
*/
|
static inline
|
static inline
|
void acornscsi_reportstatus (Scsi_Cmnd **SCpntp1, Scsi_Cmnd **SCpntp2, int result)
|
void acornscsi_reportstatus (Scsi_Cmnd **SCpntp1, Scsi_Cmnd **SCpntp2, int result)
|
{
|
{
|
Scsi_Cmnd *SCpnt = *SCpntp1;
|
Scsi_Cmnd *SCpnt = *SCpntp1;
|
|
|
if (SCpnt) {
|
if (SCpnt) {
|
*SCpntp1 = NULL;
|
*SCpntp1 = NULL;
|
|
|
SCpnt->result = result;
|
SCpnt->result = result;
|
SCpnt->scsi_done (SCpnt);
|
SCpnt->scsi_done (SCpnt);
|
}
|
}
|
|
|
if (SCpnt == *SCpntp2)
|
if (SCpnt == *SCpntp2)
|
*SCpntp2 = NULL;
|
*SCpntp2 = NULL;
|
}
|
}
|
|
|
/*
|
/*
|
* Prototype: int acornscsi_abort (Scsi_Cmnd *SCpnt)
|
* Prototype: int acornscsi_abort (Scsi_Cmnd *SCpnt)
|
* Purpose : abort a command on this host
|
* Purpose : abort a command on this host
|
* Params : SCpnt - command to abort
|
* Params : SCpnt - command to abort
|
* Returns : one of SCSI_ABORT_ macros
|
* Returns : one of SCSI_ABORT_ macros
|
*/
|
*/
|
int acornscsi_abort (Scsi_Cmnd *SCpnt)
|
int acornscsi_abort (Scsi_Cmnd *SCpnt)
|
{
|
{
|
AS_Host *host = (AS_Host *) SCpnt->host->hostdata;
|
AS_Host *host = (AS_Host *) SCpnt->host->hostdata;
|
int result = SCSI_ABORT_NOT_RUNNING;
|
int result = SCSI_ABORT_NOT_RUNNING;
|
|
|
host->stats.aborts += 1;
|
host->stats.aborts += 1;
|
|
|
#if (DEBUG & DEBUG_ABORT)
|
#if (DEBUG & DEBUG_ABORT)
|
{
|
{
|
int asr, ssr;
|
int asr, ssr;
|
asr = sbic_arm_read (host->scsi.io_port, ASR);
|
asr = sbic_arm_read (host->scsi.io_port, ASR);
|
ssr = sbic_arm_read (host->scsi.io_port, SSR);
|
ssr = sbic_arm_read (host->scsi.io_port, SSR);
|
|
|
printk (KERN_WARNING "acornscsi_abort: ");
|
printk (KERN_WARNING "acornscsi_abort: ");
|
print_sbic_status(asr, ssr, host->scsi.phase);
|
print_sbic_status(asr, ssr, host->scsi.phase);
|
acornscsi_dumplog (host, SCpnt->target);
|
acornscsi_dumplog (host, SCpnt->target);
|
}
|
}
|
#endif
|
#endif
|
|
|
if (queue_removecmd (&host->queues.issue, SCpnt)) {
|
if (queue_removecmd (&host->queues.issue, SCpnt)) {
|
SCpnt->result = DID_ABORT << 16;
|
SCpnt->result = DID_ABORT << 16;
|
SCpnt->scsi_done (SCpnt);
|
SCpnt->scsi_done (SCpnt);
|
#if (DEBUG & DEBUG_ABORT)
|
#if (DEBUG & DEBUG_ABORT)
|
printk ("scsi%d: command on issue queue\n", host->host->host_no);
|
printk ("scsi%d: command on issue queue\n", host->host->host_no);
|
#endif
|
#endif
|
result = SCSI_ABORT_SUCCESS;
|
result = SCSI_ABORT_SUCCESS;
|
} else if (queue_cmdonqueue (&host->queues.disconnected, SCpnt)) {
|
} else if (queue_cmdonqueue (&host->queues.disconnected, SCpnt)) {
|
printk ("scsi%d: command on disconnected queue\n", host->host->host_no);
|
printk ("scsi%d: command on disconnected queue\n", host->host->host_no);
|
result = SCSI_ABORT_SNOOZE;
|
result = SCSI_ABORT_SNOOZE;
|
} else if (host->SCpnt == SCpnt) {
|
} else if (host->SCpnt == SCpnt) {
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
acornscsi_abortcmd (host, host->SCpnt->tag);
|
printk ("scsi%d: command executing\n", host->host->host_no);
|
printk ("scsi%d: command executing\n", host->host->host_no);
|
result = SCSI_ABORT_SNOOZE;
|
result = SCSI_ABORT_SNOOZE;
|
} else if (host->origSCpnt == SCpnt) {
|
} else if (host->origSCpnt == SCpnt) {
|
host->origSCpnt = NULL;
|
host->origSCpnt = NULL;
|
SCpnt->result = DID_ABORT << 16;
|
SCpnt->result = DID_ABORT << 16;
|
SCpnt->scsi_done (SCpnt);
|
SCpnt->scsi_done (SCpnt);
|
#if (DEBUG & DEBUG_ABORT)
|
#if (DEBUG & DEBUG_ABORT)
|
printk ("scsi%d: command waiting for execution\n", host->host->host_no);
|
printk ("scsi%d: command waiting for execution\n", host->host->host_no);
|
#endif
|
#endif
|
result = SCSI_ABORT_SUCCESS;
|
result = SCSI_ABORT_SUCCESS;
|
}
|
}
|
|
|
if (result == SCSI_ABORT_NOT_RUNNING) {
|
if (result == SCSI_ABORT_NOT_RUNNING) {
|
printk ("scsi%d: abort(): command not running\n", host->host->host_no);
|
printk ("scsi%d: abort(): command not running\n", host->host->host_no);
|
acornscsi_dumplog (host, SCpnt->target);
|
acornscsi_dumplog (host, SCpnt->target);
|
#if (DEBUG & DEBUG_ABORT)
|
#if (DEBUG & DEBUG_ABORT)
|
result = SCSI_ABORT_SNOOZE;
|
result = SCSI_ABORT_SNOOZE;
|
#endif
|
#endif
|
}
|
}
|
return result;
|
return result;
|
}
|
}
|
|
|
/*
|
/*
|
* Prototype: int acornscsi_reset (Scsi_Cmnd *SCpnt, unsigned int reset_flags)
|
* Prototype: int acornscsi_reset (Scsi_Cmnd *SCpnt, unsigned int reset_flags)
|
* Purpose : reset a command on this host/reset this host
|
* Purpose : reset a command on this host/reset this host
|
* Params : SCpnt - command causing reset
|
* Params : SCpnt - command causing reset
|
* result - what type of reset to perform
|
* result - what type of reset to perform
|
* Returns : one of SCSI_RESET_ macros
|
* Returns : one of SCSI_RESET_ macros
|
*/
|
*/
|
int acornscsi_reset (Scsi_Cmnd *SCpnt, unsigned int reset_flags)
|
int acornscsi_reset (Scsi_Cmnd *SCpnt, unsigned int reset_flags)
|
{
|
{
|
AS_Host *host = (AS_Host *)SCpnt->host->hostdata;
|
AS_Host *host = (AS_Host *)SCpnt->host->hostdata;
|
Scsi_Cmnd *SCptr;
|
Scsi_Cmnd *SCptr;
|
|
|
host->stats.resets += 1;
|
host->stats.resets += 1;
|
|
|
#if (DEBUG & DEBUG_RESET)
|
#if (DEBUG & DEBUG_RESET)
|
{
|
{
|
int asr, ssr;
|
int asr, ssr;
|
|
|
asr = sbic_arm_read (host->scsi.io_port, ASR);
|
asr = sbic_arm_read (host->scsi.io_port, ASR);
|
ssr = sbic_arm_read (host->scsi.io_port, SSR);
|
ssr = sbic_arm_read (host->scsi.io_port, SSR);
|
|
|
printk (KERN_WARNING "acornscsi_reset: ");
|
printk (KERN_WARNING "acornscsi_reset: ");
|
print_sbic_status(asr, ssr, host->scsi.phase);
|
print_sbic_status(asr, ssr, host->scsi.phase);
|
acornscsi_dumplog (host, SCpnt->target);
|
acornscsi_dumplog (host, SCpnt->target);
|
}
|
}
|
#endif
|
#endif
|
|
|
acornscsi_dma_stop (host);
|
acornscsi_dma_stop (host);
|
|
|
SCptr = host->SCpnt;
|
SCptr = host->SCpnt;
|
|
|
/*
|
/*
|
* do hard reset. This resets all devices on this host, and so we
|
* do hard reset. This resets all devices on this host, and so we
|
* must set the reset status on all commands.
|
* must set the reset status on all commands.
|
*/
|
*/
|
acornscsi_resetcard (host);
|
acornscsi_resetcard (host);
|
|
|
/*
|
/*
|
* report reset on commands current connected/disconnected
|
* report reset on commands current connected/disconnected
|
*/
|
*/
|
acornscsi_reportstatus (&host->SCpnt, &SCptr, DID_RESET);
|
acornscsi_reportstatus (&host->SCpnt, &SCptr, DID_RESET);
|
|
|
while ((SCptr = queue_remove (&host->queues.disconnected)) != NULL)
|
while ((SCptr = queue_remove (&host->queues.disconnected)) != NULL)
|
acornscsi_reportstatus (&SCptr, &SCpnt, DID_RESET);
|
acornscsi_reportstatus (&SCptr, &SCpnt, DID_RESET);
|
|
|
if (SCpnt) {
|
if (SCpnt) {
|
SCpnt->result = DID_RESET << 16;
|
SCpnt->result = DID_RESET << 16;
|
SCpnt->scsi_done (SCpnt);
|
SCpnt->scsi_done (SCpnt);
|
}
|
}
|
while (1);
|
while (1);
|
return SCSI_RESET_BUS_RESET | SCSI_RESET_HOST_RESET | SCSI_RESET_SUCCESS;
|
return SCSI_RESET_BUS_RESET | SCSI_RESET_HOST_RESET | SCSI_RESET_SUCCESS;
|
}
|
}
|
|
|
/*==============================================================================================
|
/*==============================================================================================
|
* initialisation & miscellaneous support
|
* initialisation & miscellaneous support
|
*/
|
*/
|
static struct expansion_card *ecs[MAX_ECARDS];
|
static struct expansion_card *ecs[MAX_ECARDS];
|
|
|
/*
|
/*
|
* Prototype: void acornscsi_init (AS_Host *host)
|
* Prototype: void acornscsi_init (AS_Host *host)
|
* Purpose : initialise the AS_Host structure for one interface & setup hardware
|
* Purpose : initialise the AS_Host structure for one interface & setup hardware
|
* Params : host - host to setup
|
* Params : host - host to setup
|
*/
|
*/
|
static
|
static
|
void acornscsi_init (AS_Host *host)
|
void acornscsi_init (AS_Host *host)
|
{
|
{
|
memset (&host->stats, 0, sizeof (host->stats));
|
memset (&host->stats, 0, sizeof (host->stats));
|
queue_initialise (&host->queues.issue);
|
queue_initialise (&host->queues.issue);
|
queue_initialise (&host->queues.disconnected);
|
queue_initialise (&host->queues.disconnected);
|
msgqueue_initialise (&host->scsi.msgs);
|
msgqueue_initialise (&host->scsi.msgs);
|
|
|
acornscsi_resetcard (host);
|
acornscsi_resetcard (host);
|
}
|
}
|
|
|
int acornscsi_detect(Scsi_Host_Template * tpnt)
|
int acornscsi_detect(Scsi_Host_Template * tpnt)
|
{
|
{
|
static const card_ids acornscsi_cids[] = { ACORNSCSI_LIST, { 0xffff, 0xffff } };
|
static const card_ids acornscsi_cids[] = { ACORNSCSI_LIST, { 0xffff, 0xffff } };
|
int i, count = 0;
|
int i, count = 0;
|
struct Scsi_Host *instance;
|
struct Scsi_Host *instance;
|
AS_Host *host;
|
AS_Host *host;
|
|
|
tpnt->proc_dir = &proc_scsi_acornscsi;
|
tpnt->proc_dir = &proc_scsi_acornscsi;
|
|
|
for (i = 0; i < MAX_ECARDS; i++)
|
for (i = 0; i < MAX_ECARDS; i++)
|
ecs[i] = NULL;
|
ecs[i] = NULL;
|
|
|
ecard_startfind ();
|
ecard_startfind ();
|
|
|
while(1) {
|
while(1) {
|
ecs[count] = ecard_find(0, acornscsi_cids);
|
ecs[count] = ecard_find(0, acornscsi_cids);
|
if (!ecs[count])
|
if (!ecs[count])
|
break;
|
break;
|
|
|
if (ecs[count]->irq == 0xff) {
|
if (ecs[count]->irq == 0xff) {
|
printk ("scsi: WD33C93 does not have IRQ enabled - ignoring\n");
|
printk ("scsi: WD33C93 does not have IRQ enabled - ignoring\n");
|
continue;
|
continue;
|
}
|
}
|
|
|
ecard_claim(ecs[count]); /* Must claim here - card produces irq on reset */
|
ecard_claim(ecs[count]); /* Must claim here - card produces irq on reset */
|
|
|
instance = scsi_register (tpnt, sizeof(AS_Host));
|
instance = scsi_register (tpnt, sizeof(AS_Host));
|
host = (AS_Host *)instance->hostdata;
|
host = (AS_Host *)instance->hostdata;
|
|
|
instance->io_port = ecard_address (ecs[count], ECARD_MEMC, 0);
|
instance->io_port = ecard_address (ecs[count], ECARD_MEMC, 0);
|
instance->irq = ecs[count]->irq;
|
instance->irq = ecs[count]->irq;
|
|
|
host->host = instance;
|
host->host = instance;
|
host->scsi.io_port = ioaddr (instance->io_port + 0x800);
|
host->scsi.io_port = ioaddr (instance->io_port + 0x800);
|
host->scsi.irq = instance->irq;
|
host->scsi.irq = instance->irq;
|
host->card.io_intr = POD_SPACE(instance->io_port) + 0x800;
|
host->card.io_intr = POD_SPACE(instance->io_port) + 0x800;
|
host->card.io_page = POD_SPACE(instance->io_port) + 0xc00;
|
host->card.io_page = POD_SPACE(instance->io_port) + 0xc00;
|
host->card.io_ram = ioaddr (instance->io_port);
|
host->card.io_ram = ioaddr (instance->io_port);
|
host->dma.io_port = instance->io_port + 0xc00;
|
host->dma.io_port = instance->io_port + 0xc00;
|
host->dma.io_intr_clear = POD_SPACE(instance->io_port) + 0x800;
|
host->dma.io_intr_clear = POD_SPACE(instance->io_port) + 0x800;
|
|
|
request_region (instance->io_port + 0x800, 2, "acornscsi(sbic)");
|
request_region (instance->io_port + 0x800, 2, "acornscsi(sbic)");
|
request_region (host->card.io_intr, 1, "acornscsi(intr)");
|
request_region (host->card.io_intr, 1, "acornscsi(intr)");
|
request_region (host->card.io_page, 1, "acornscsi(page)");
|
request_region (host->card.io_page, 1, "acornscsi(page)");
|
request_region (host->dma.io_port, 256, "acornscsi(dmac)");
|
request_region (host->dma.io_port, 256, "acornscsi(dmac)");
|
request_region (instance->io_port, 2048, "acornscsi(ram)");
|
request_region (instance->io_port, 2048, "acornscsi(ram)");
|
|
|
if (request_irq(host->scsi.irq, acornscsi_intr, SA_INTERRUPT, "acornscsi", host)) {
|
if (request_irq(host->scsi.irq, acornscsi_intr, SA_INTERRUPT, "acornscsi", host)) {
|
printk(KERN_CRIT "scsi%d: IRQ%d not free, interrupts disabled\n",
|
printk(KERN_CRIT "scsi%d: IRQ%d not free, interrupts disabled\n",
|
instance->host_no, host->scsi.irq);
|
instance->host_no, host->scsi.irq);
|
host->scsi.irq = NO_IRQ;
|
host->scsi.irq = NO_IRQ;
|
}
|
}
|
|
|
acornscsi_init (host);
|
acornscsi_init (host);
|
|
|
++count;
|
++count;
|
}
|
}
|
return count;
|
return count;
|
}
|
}
|
|
|
/*
|
/*
|
* Function: int acornscsi_release (struct Scsi_Host *host)
|
* Function: int acornscsi_release (struct Scsi_Host *host)
|
* Purpose : release all resources used by this adapter
|
* Purpose : release all resources used by this adapter
|
* Params : host - driver structure to release
|
* Params : host - driver structure to release
|
* Returns : nothing of any consequence
|
* Returns : nothing of any consequence
|
*/
|
*/
|
int acornscsi_release (struct Scsi_Host *instance)
|
int acornscsi_release (struct Scsi_Host *instance)
|
{
|
{
|
AS_Host *host = (AS_Host *)instance->hostdata;
|
AS_Host *host = (AS_Host *)instance->hostdata;
|
int i;
|
int i;
|
|
|
/*
|
/*
|
* Put card into RESET state
|
* Put card into RESET state
|
*/
|
*/
|
outb (0x80, host->card.io_page);
|
outb (0x80, host->card.io_page);
|
|
|
if (host->scsi.irq != NO_IRQ)
|
if (host->scsi.irq != NO_IRQ)
|
free_irq (host->scsi.irq, host);
|
free_irq (host->scsi.irq, host);
|
|
|
release_region (instance->io_port + 0x800, 2);
|
release_region (instance->io_port + 0x800, 2);
|
release_region (host->card.io_intr, 1);
|
release_region (host->card.io_intr, 1);
|
release_region (host->card.io_page, 1);
|
release_region (host->card.io_page, 1);
|
release_region (host->dma.io_port, 256);
|
release_region (host->dma.io_port, 256);
|
release_region (instance->io_port, 2048);
|
release_region (instance->io_port, 2048);
|
|
|
for (i = 0; i < MAX_ECARDS; i++)
|
for (i = 0; i < MAX_ECARDS; i++)
|
if (ecs[i] && instance->io_port == ecard_address (ecs[i], ECARD_MEMC, 0))
|
if (ecs[i] && instance->io_port == ecard_address (ecs[i], ECARD_MEMC, 0))
|
ecard_release (ecs[i]);
|
ecard_release (ecs[i]);
|
|
|
msgqueue_free (&host->scsi.msgs);
|
msgqueue_free (&host->scsi.msgs);
|
queue_free (&host->queues.disconnected);
|
queue_free (&host->queues.disconnected);
|
queue_free (&host->queues.issue);
|
queue_free (&host->queues.issue);
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*
|
/*
|
* Function: char *acornscsi_info (struct Scsi_Host *host)
|
* Function: char *acornscsi_info (struct Scsi_Host *host)
|
* Purpose : return a string describing this interface
|
* Purpose : return a string describing this interface
|
* Params : host - host to give information on
|
* Params : host - host to give information on
|
* Returns : a constant string
|
* Returns : a constant string
|
*/
|
*/
|
const
|
const
|
char *acornscsi_info(struct Scsi_Host *host)
|
char *acornscsi_info(struct Scsi_Host *host)
|
{
|
{
|
static char string[100], *p;
|
static char string[100], *p;
|
|
|
p = string;
|
p = string;
|
|
|
p += sprintf (string, "%s at port %X irq %d v%d.%d.%d"
|
p += sprintf (string, "%s at port %X irq %d v%d.%d.%d"
|
#ifdef SCSI2_SYNC
|
#ifdef SCSI2_SYNC
|
" SYNC"
|
" SYNC"
|
#endif
|
#endif
|
#ifdef SCSI2_TAG
|
#ifdef SCSI2_TAG
|
" TAG"
|
" TAG"
|
#endif
|
#endif
|
#ifdef SCSI2_LINK
|
#ifdef SCSI2_LINK
|
" LINK"
|
" LINK"
|
#endif
|
#endif
|
#if (DEBUG & DEBUG_NO_WRITE)
|
#if (DEBUG & DEBUG_NO_WRITE)
|
" NOWRITE ("NO_WRITE_STR")"
|
" NOWRITE ("NO_WRITE_STR")"
|
#endif
|
#endif
|
, host->hostt->name, host->io_port, host->irq,
|
, host->hostt->name, host->io_port, host->irq,
|
VER_MAJOR, VER_MINOR, VER_PATCH);
|
VER_MAJOR, VER_MINOR, VER_PATCH);
|
return string;
|
return string;
|
}
|
}
|
|
|
int acornscsi_proc_info(char *buffer, char **start, off_t offset,
|
int acornscsi_proc_info(char *buffer, char **start, off_t offset,
|
int length, int host_no, int inout)
|
int length, int host_no, int inout)
|
{
|
{
|
int pos, begin = 0, first;
|
int pos, begin = 0, first;
|
struct Scsi_Host *instance = scsi_hostlist;
|
struct Scsi_Host *instance = scsi_hostlist;
|
Scsi_Device *scd = scsi_devices;
|
Scsi_Device *scd = scsi_devices;
|
AS_Host *host;
|
AS_Host *host;
|
char *p = buffer;
|
char *p = buffer;
|
|
|
for (instance = scsi_hostlist;
|
for (instance = scsi_hostlist;
|
instance && instance->host_no != host_no;
|
instance && instance->host_no != host_no;
|
instance = instance->next);
|
instance = instance->next);
|
|
|
if (inout == 1 || !instance)
|
if (inout == 1 || !instance)
|
return -EINVAL;
|
return -EINVAL;
|
|
|
host = (AS_Host *)instance->hostdata;
|
host = (AS_Host *)instance->hostdata;
|
|
|
p += sprintf (p, "AcornSCSI driver v%d.%d.%d"
|
p += sprintf (p, "AcornSCSI driver v%d.%d.%d"
|
#ifdef SCSI2_SYNC
|
#ifdef SCSI2_SYNC
|
" SYNC"
|
" SYNC"
|
#endif
|
#endif
|
#ifdef SCSI2_TAG
|
#ifdef SCSI2_TAG
|
" TAG"
|
" TAG"
|
#endif
|
#endif
|
#ifdef SCSI2_LINK
|
#ifdef SCSI2_LINK
|
" LINK"
|
" LINK"
|
#endif
|
#endif
|
#if (DEBUG & DEBUG_NO_WRITE)
|
#if (DEBUG & DEBUG_NO_WRITE)
|
" NOWRITE ("NO_WRITE_STR")"
|
" NOWRITE ("NO_WRITE_STR")"
|
#endif
|
#endif
|
"\n\n", VER_MAJOR, VER_MINOR, VER_PATCH);
|
"\n\n", VER_MAJOR, VER_MINOR, VER_PATCH);
|
|
|
p += sprintf (p, "SBIC: WD33C93A Address: %08X IRQ : %d\n"
|
p += sprintf (p, "SBIC: WD33C93A Address: %08X IRQ : %d\n"
|
"DMAC: uPC71071 Address: %08X IRQ : %d\n\n"
|
"DMAC: uPC71071 Address: %08X IRQ : %d\n\n"
|
"Statistics:\n",
|
"Statistics:\n",
|
host->scsi.io_port, host->scsi.irq,
|
host->scsi.io_port, host->scsi.irq,
|
host->dma.io_port, host->scsi.irq);
|
host->dma.io_port, host->scsi.irq);
|
|
|
p += sprintf (p, "Queued commands: %-10ld Issued commands: %-10ld\n"
|
p += sprintf (p, "Queued commands: %-10ld Issued commands: %-10ld\n"
|
"Done commands : %-10ld Reads : %-10ld\n"
|
"Done commands : %-10ld Reads : %-10ld\n"
|
"Writes : %-10ld Others : %-10ld\n"
|
"Writes : %-10ld Others : %-10ld\n"
|
"Disconnects : %-10ld Aborts : %-10ld\n"
|
"Disconnects : %-10ld Aborts : %-10ld\n"
|
"Resets : %-10ld\n\nLast phases:",
|
"Resets : %-10ld\n\nLast phases:",
|
host->stats.queues, host->stats.removes,
|
host->stats.queues, host->stats.removes,
|
host->stats.fins, host->stats.reads,
|
host->stats.fins, host->stats.reads,
|
host->stats.writes, host->stats.miscs,
|
host->stats.writes, host->stats.miscs,
|
host->stats.disconnects, host->stats.aborts,
|
host->stats.disconnects, host->stats.aborts,
|
host->stats.resets);
|
host->stats.resets);
|
|
|
for (first = 0; first < 9; first ++) {
|
for (first = 0; first < 9; first ++) {
|
unsigned int statptr, prev;
|
unsigned int statptr, prev;
|
|
|
p += sprintf (p, "\n%c:", first == 8 ? 'H' : ('0' + first));
|
p += sprintf (p, "\n%c:", first == 8 ? 'H' : ('0' + first));
|
statptr = status_ptr[first] - 10;
|
statptr = status_ptr[first] - 10;
|
|
|
if ((signed int)statptr < 0)
|
if ((signed int)statptr < 0)
|
statptr += 16;
|
statptr += 16;
|
|
|
prev = status[first][statptr].when;
|
prev = status[first][statptr].when;
|
|
|
for (; statptr != status_ptr[first]; statptr = (statptr + 1) & 15) {
|
for (; statptr != status_ptr[first]; statptr = (statptr + 1) & 15) {
|
if (status[first][statptr].when) {
|
if (status[first][statptr].when) {
|
p += sprintf (p, "%c%02X:%02X+%2ld",
|
p += sprintf (p, "%c%02X:%02X+%2ld",
|
status[first][statptr].irq ? '-' : ' ',
|
status[first][statptr].irq ? '-' : ' ',
|
status[first][statptr].ph,
|
status[first][statptr].ph,
|
status[first][statptr].ssr,
|
status[first][statptr].ssr,
|
(status[first][statptr].when - prev) < 100 ?
|
(status[first][statptr].when - prev) < 100 ?
|
(status[first][statptr].when - prev) : 99);
|
(status[first][statptr].when - prev) : 99);
|
prev = status[first][statptr].when;
|
prev = status[first][statptr].when;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
first = 1;
|
first = 1;
|
p += sprintf (p, "\nAttached devices:");
|
p += sprintf (p, "\nAttached devices:");
|
while (scd) {
|
while (scd) {
|
if (scd->host == instance) {
|
if (scd->host == instance) {
|
int len;
|
int len;
|
if (first) {
|
if (first) {
|
p += sprintf (p, "\n");
|
p += sprintf (p, "\n");
|
first = 0;
|
first = 0;
|
}
|
}
|
|
|
proc_print_scsidevice (scd, p, &len, 0);
|
proc_print_scsidevice (scd, p, &len, 0);
|
p += len;
|
p += len;
|
|
|
p += sprintf (p, "Extensions: ");
|
p += sprintf (p, "Extensions: ");
|
|
|
if (scd->tagged_supported)
|
if (scd->tagged_supported)
|
p += sprintf (p, "TAG %sabled [%d] ",
|
p += sprintf (p, "TAG %sabled [%d] ",
|
scd->tagged_queue ? "en" : "dis", scd->current_tag);
|
scd->tagged_queue ? "en" : "dis", scd->current_tag);
|
p += sprintf (p, "\nTransfers: ");
|
p += sprintf (p, "\nTransfers: ");
|
if (host->device[scd->id].sync_xfer & 15)
|
if (host->device[scd->id].sync_xfer & 15)
|
p += sprintf (p, "sync, offset %d, %d ns\n",
|
p += sprintf (p, "sync, offset %d, %d ns\n",
|
host->device[scd->id].sync_xfer & 15,
|
host->device[scd->id].sync_xfer & 15,
|
acornscsi_getperiod (host->device[scd->id].sync_xfer));
|
acornscsi_getperiod (host->device[scd->id].sync_xfer));
|
else
|
else
|
p += sprintf (p, "async\n");
|
p += sprintf (p, "async\n");
|
|
|
pos = p - buffer;
|
pos = p - buffer;
|
if (pos + begin < offset) {
|
if (pos + begin < offset) {
|
begin += pos;
|
begin += pos;
|
p = buffer;
|
p = buffer;
|
}
|
}
|
pos = p - buffer;
|
pos = p - buffer;
|
if (pos + begin > offset + length)
|
if (pos + begin > offset + length)
|
break;
|
break;
|
}
|
}
|
scd = scd->next;
|
scd = scd->next;
|
}
|
}
|
|
|
if (first)
|
if (first)
|
p += sprintf(p, " none\n");
|
p += sprintf(p, " none\n");
|
|
|
pos = p - buffer;
|
pos = p - buffer;
|
|
|
*start = buffer + (offset - begin);
|
*start = buffer + (offset - begin);
|
pos -= offset - begin;
|
pos -= offset - begin;
|
|
|
if (pos > length)
|
if (pos > length)
|
pos = length;
|
pos = length;
|
|
|
return pos;
|
return pos;
|
}
|
}
|
|
|
#ifdef MODULE
|
#ifdef MODULE
|
|
|
Scsi_Host_Template driver_template = ACORNSCSI_3;
|
Scsi_Host_Template driver_template = ACORNSCSI_3;
|
|
|
#include "scsi_module.c"
|
#include "scsi_module.c"
|
#endif
|
#endif
|
|
|