/drivers/scsi/arm/acornscsi.c
http://github.com/mirrors/linux · C · 3013 lines · 1938 code · 411 blank · 664 comment · 268 complexity · 294037fe137c2819fa624c5a905159b9 MD5 · raw file
Large files are truncated click here to view the full file
- // SPDX-License-Identifier: GPL-2.0-only
- /*
- * linux/drivers/acorn/scsi/acornscsi.c
- *
- * Acorn SCSI 3 driver
- * By R.M.King.
- *
- * Abandoned using the Select and Transfer command since there were
- * 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
- * for this command, some of them quite nasty...
- *
- * Changelog:
- * 26-Sep-1997 RMK Re-jigged to use the queue module.
- * Re-coded state machine to be based on driver
- * state not scsi state. Should be easier to debug.
- * Added acornscsi_release to clean up properly.
- * Updated proc/scsi reporting.
- * 05-Oct-1997 RMK Implemented writing to SCSI devices.
- * 06-Oct-1997 RMK Corrected small (non-serious) bug with the connect/
- * reconnect race condition causing a warning message.
- * 12-Oct-1997 RMK Added catch for re-entering interrupt routine.
- * 15-Oct-1997 RMK Improved handling of commands.
- * 27-Jun-1998 RMK Changed asm/delay.h to linux/delay.h.
- * 13-Dec-1998 RMK Better abort code and command handling. Extra state
- * transitions added to allow dodgy devices to work.
- */
- #define DEBUG_NO_WRITE 1
- #define DEBUG_QUEUES 2
- #define DEBUG_DMA 4
- #define DEBUG_ABORT 8
- #define DEBUG_DISCON 16
- #define DEBUG_CONNECT 32
- #define DEBUG_PHASES 64
- #define DEBUG_WRITE 128
- #define DEBUG_LINK 256
- #define DEBUG_MESSAGES 512
- #define DEBUG_RESET 1024
- #define DEBUG_ALL (DEBUG_RESET|DEBUG_MESSAGES|DEBUG_LINK|DEBUG_WRITE|\
- DEBUG_PHASES|DEBUG_CONNECT|DEBUG_DISCON|DEBUG_ABORT|\
- DEBUG_DMA|DEBUG_QUEUES)
- /* DRIVER CONFIGURATION
- *
- * SCSI-II Tagged queue support.
- *
- * 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
- * devices). It is not fully implemented either - what happens when a
- * tagging device reconnects???
- *
- * 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
- * as '2 TAG'.
- *
- * Also note that CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE is normally set in the config
- * scripts, but disabled here. Once debugged, remove the #undef, otherwise to debug,
- * comment out the undef.
- */
- #undef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
- /*
- * SCSI-II Synchronous transfer support.
- *
- * Tried and tested...
- *
- * SDTR_SIZE - maximum number of un-acknowledged bytes (0 = off, 12 = max)
- * SDTR_PERIOD - period of REQ signal (min=125, max=1020)
- * DEFAULT_PERIOD - default REQ period.
- */
- #define SDTR_SIZE 12
- #define SDTR_PERIOD 125
- #define DEFAULT_PERIOD 500
- /*
- * Debugging information
- *
- * DEBUG - bit mask from list above
- * DEBUG_TARGET - is defined to the target number if you want to debug
- * a specific target. [only recon/write/dma].
- */
- #define DEBUG (DEBUG_RESET|DEBUG_WRITE|DEBUG_NO_WRITE)
- /* only allow writing to SCSI device 0 */
- #define NO_WRITE 0xFE
- /*#define DEBUG_TARGET 2*/
- /*
- * Select timeout time (in 10ms units)
- *
- * This is the timeout used between the start of selection and the WD33C93
- * chip deciding that the device isn't responding.
- */
- #define TIMEOUT_TIME 10
- /*
- * Define this if you want to have verbose explanation of SCSI
- * status/messages.
- */
- #undef CONFIG_ACORNSCSI_CONSTANTS
- /*
- * Define this if you want to use the on board DMAC [don't remove this option]
- * If not set, then use PIO mode (not currently supported).
- */
- #define USE_DMAC
- /*
- * ====================================================================================
- */
- #ifdef DEBUG_TARGET
- #define DBG(cmd,xxx...) \
- if (cmd->device->id == DEBUG_TARGET) { \
- xxx; \
- }
- #else
- #define DBG(cmd,xxx...) xxx
- #endif
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/string.h>
- #include <linux/signal.h>
- #include <linux/errno.h>
- #include <linux/proc_fs.h>
- #include <linux/ioport.h>
- #include <linux/blkdev.h>
- #include <linux/delay.h>
- #include <linux/interrupt.h>
- #include <linux/init.h>
- #include <linux/bitops.h>
- #include <linux/stringify.h>
- #include <linux/io.h>
- #include <asm/ecard.h>
- #include "../scsi.h"
- #include <scsi/scsi_dbg.h>
- #include <scsi/scsi_host.h>
- #include <scsi/scsi_transport_spi.h>
- #include "acornscsi.h"
- #include "msgqueue.h"
- #include "scsi.h"
- #include <scsi/scsicam.h>
- #define VER_MAJOR 2
- #define VER_MINOR 0
- #define VER_PATCH 6
- #ifndef ABORT_TAG
- #define ABORT_TAG 0xd
- #else
- #error "Yippee! ABORT TAG is now defined! Remove this error!"
- #endif
- #ifdef USE_DMAC
- /*
- * DMAC setup parameters
- */
- #define INIT_DEVCON0 (DEVCON0_RQL|DEVCON0_EXW|DEVCON0_CMP)
- #define INIT_DEVCON1 (DEVCON1_BHLD)
- #define DMAC_READ (MODECON_READ)
- #define DMAC_WRITE (MODECON_WRITE)
- #define INIT_SBICDMA (CTRL_DMABURST)
- #define scsi_xferred have_data_in
- /*
- * Size of on-board DMA buffer
- */
- #define DMAC_BUFFER_SIZE 65536
- #endif
- #define STATUS_BUFFER_TO_PRINT 24
- unsigned int sdtr_period = SDTR_PERIOD;
- unsigned int sdtr_size = SDTR_SIZE;
- static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
- unsigned int result);
- static int acornscsi_reconnect_finish(AS_Host *host);
- static void acornscsi_dma_cleanup(AS_Host *host);
- static void acornscsi_abortcmd(AS_Host *host, unsigned char tag);
- /* ====================================================================================
- * Miscellaneous
- */
- /* Offsets from MEMC base */
- #define SBIC_REGIDX 0x2000
- #define SBIC_REGVAL 0x2004
- #define DMAC_OFFSET 0x3000
- /* Offsets from FAST IOC base */
- #define INT_REG 0x2000
- #define PAGE_REG 0x3000
- static inline void sbic_arm_write(AS_Host *host, unsigned int reg, unsigned int value)
- {
- writeb(reg, host->base + SBIC_REGIDX);
- writeb(value, host->base + SBIC_REGVAL);
- }
- static inline int sbic_arm_read(AS_Host *host, unsigned int reg)
- {
- if(reg == SBIC_ASR)
- return readl(host->base + SBIC_REGIDX) & 255;
- writeb(reg, host->base + SBIC_REGIDX);
- return readl(host->base + SBIC_REGVAL) & 255;
- }
- #define sbic_arm_writenext(host, val) writeb((val), (host)->base + SBIC_REGVAL)
- #define sbic_arm_readnext(host) readb((host)->base + SBIC_REGVAL)
- #ifdef USE_DMAC
- #define dmac_read(host,reg) \
- readb((host)->base + DMAC_OFFSET + ((reg) << 2))
- #define dmac_write(host,reg,value) \
- ({ writeb((value), (host)->base + DMAC_OFFSET + ((reg) << 2)); })
- #define dmac_clearintr(host) writeb(0, (host)->fast + INT_REG)
- static inline unsigned int dmac_address(AS_Host *host)
- {
- return dmac_read(host, DMAC_TXADRHI) << 16 |
- dmac_read(host, DMAC_TXADRMD) << 8 |
- dmac_read(host, DMAC_TXADRLO);
- }
- static
- void acornscsi_dumpdma(AS_Host *host, char *where)
- {
- unsigned int mode, addr, len;
- mode = dmac_read(host, DMAC_MODECON);
- addr = dmac_address(host);
- len = dmac_read(host, DMAC_TXCNTHI) << 8 |
- dmac_read(host, DMAC_TXCNTLO);
- printk("scsi%d: %s: DMAC %02x @%06x+%04x msk %02x, ",
- host->host->host_no, where,
- mode, addr, (len + 1) & 0xffff,
- dmac_read(host, DMAC_MASKREG));
- printk("DMA @%06x, ", host->dma.start_addr);
- printk("BH @%p +%04x, ", host->scsi.SCp.ptr,
- host->scsi.SCp.this_residual);
- printk("DT @+%04x ST @+%04x", host->dma.transferred,
- host->scsi.SCp.scsi_xferred);
- printk("\n");
- }
- #endif
- static
- unsigned long acornscsi_sbic_xfcount(AS_Host *host)
- {
- unsigned long length;
- length = sbic_arm_read(host, SBIC_TRANSCNTH) << 16;
- length |= sbic_arm_readnext(host) << 8;
- length |= sbic_arm_readnext(host);
- return length;
- }
- static int
- acornscsi_sbic_wait(AS_Host *host, int stat_mask, int stat, int timeout, char *msg)
- {
- int asr;
- do {
- asr = sbic_arm_read(host, SBIC_ASR);
- if ((asr & stat_mask) == stat)
- return 0;
- udelay(1);
- } while (--timeout);
- printk("scsi%d: timeout while %s\n", host->host->host_no, msg);
- return -1;
- }
- static
- int acornscsi_sbic_issuecmd(AS_Host *host, int command)
- {
- if (acornscsi_sbic_wait(host, ASR_CIP, 0, 1000, "issuing command"))
- return -1;
- sbic_arm_write(host, SBIC_CMND, command);
- return 0;
- }
- static void
- acornscsi_csdelay(unsigned int cs)
- {
- unsigned long target_jiffies, flags;
- target_jiffies = jiffies + 1 + cs * HZ / 100;
- local_save_flags(flags);
- local_irq_enable();
- while (time_before(jiffies, target_jiffies)) barrier();
- local_irq_restore(flags);
- }
- static
- void acornscsi_resetcard(AS_Host *host)
- {
- unsigned int i, timeout;
- /* assert reset line */
- host->card.page_reg = 0x80;
- writeb(host->card.page_reg, host->fast + PAGE_REG);
- /* wait 3 cs. SCSI standard says 25ms. */
- acornscsi_csdelay(3);
- host->card.page_reg = 0;
- writeb(host->card.page_reg, host->fast + PAGE_REG);
- /*
- * Should get a reset from the card
- */
- timeout = 1000;
- do {
- if (readb(host->fast + INT_REG) & 8)
- break;
- udelay(1);
- } while (--timeout);
- if (timeout == 0)
- printk("scsi%d: timeout while resetting card\n",
- host->host->host_no);
- sbic_arm_read(host, SBIC_ASR);
- sbic_arm_read(host, SBIC_SSR);
- /* setup sbic - WD33C93A */
- sbic_arm_write(host, SBIC_OWNID, OWNID_EAF | host->host->this_id);
- sbic_arm_write(host, SBIC_CMND, CMND_RESET);
- /*
- * Command should cause a reset interrupt
- */
- timeout = 1000;
- do {
- if (readb(host->fast + INT_REG) & 8)
- break;
- udelay(1);
- } while (--timeout);
- if (timeout == 0)
- printk("scsi%d: timeout while resetting card\n",
- host->host->host_no);
- sbic_arm_read(host, SBIC_ASR);
- if (sbic_arm_read(host, SBIC_SSR) != 0x01)
- printk(KERN_CRIT "scsi%d: WD33C93A didn't give enhanced reset interrupt\n",
- host->host->host_no);
- sbic_arm_write(host, SBIC_CTRL, INIT_SBICDMA | CTRL_IDI);
- sbic_arm_write(host, SBIC_TIMEOUT, TIMEOUT_TIME);
- sbic_arm_write(host, SBIC_SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
- sbic_arm_write(host, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
- host->card.page_reg = 0x40;
- writeb(host->card.page_reg, host->fast + PAGE_REG);
- /* setup dmac - uPC71071 */
- dmac_write(host, DMAC_INIT, 0);
- #ifdef USE_DMAC
- dmac_write(host, DMAC_INIT, INIT_8BIT);
- dmac_write(host, DMAC_CHANNEL, CHANNEL_0);
- dmac_write(host, DMAC_DEVCON0, INIT_DEVCON0);
- dmac_write(host, DMAC_DEVCON1, INIT_DEVCON1);
- #endif
- host->SCpnt = NULL;
- host->scsi.phase = PHASE_IDLE;
- host->scsi.disconnectable = 0;
- memset(host->busyluns, 0, sizeof(host->busyluns));
- for (i = 0; i < 8; i++) {
- host->device[i].sync_state = SYNC_NEGOCIATE;
- host->device[i].disconnect_ok = 1;
- }
- /* wait 25 cs. SCSI standard says 250ms. */
- acornscsi_csdelay(25);
- }
- /*=============================================================================================
- * Utility routines (eg. debug)
- */
- #ifdef CONFIG_ACORNSCSI_CONSTANTS
- static char *acornscsi_interrupttype[] = {
- "rst", "suc", "p/a", "3",
- "term", "5", "6", "7",
- "serv", "9", "a", "b",
- "c", "d", "e", "f"
- };
- static signed char acornscsi_map[] = {
- 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,
- 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,
- 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,
- 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
- };
- static char *acornscsi_interruptcode[] = {
- /* 0 */
- "reset - normal mode", /* 00 */
- "reset - advanced mode", /* 01 */
- /* 2 */
- "sel", /* 11 */
- "sel+xfer", /* 16 */
- "data-out", /* 18 */
- "data-in", /* 19 */
- "cmd", /* 1A */
- "stat", /* 1B */
- "??-out", /* 1C */
- "??-in", /* 1D */
- "msg-out", /* 1E */
- "msg-in", /* 1F */
- /* 12 */
- "/ACK asserted", /* 20 */
- "save-data-ptr", /* 21 */
- "{re}sel", /* 22 */
- /* 15 */
- "inv cmd", /* 40 */
- "unexpected disconnect", /* 41 */
- "sel timeout", /* 42 */
- "P err", /* 43 */
- "P err+ATN", /* 44 */
- "bad status byte", /* 47 */
- /* 21 */
- "resel, no id", /* 80 */
- "resel", /* 81 */
- "discon", /* 85 */
- };
- static
- void print_scsi_status(unsigned int ssr)
- {
- if (acornscsi_map[ssr] != -1)
- printk("%s:%s",
- acornscsi_interrupttype[(ssr >> 4)],
- acornscsi_interruptcode[acornscsi_map[ssr]]);
- else
- printk("%X:%X", ssr >> 4, ssr & 0x0f);
- }
- #endif
- static
- void print_sbic_status(int asr, int ssr, int cmdphase)
- {
- #ifdef CONFIG_ACORNSCSI_CONSTANTS
- printk("sbic: %c%c%c%c%c%c ",
- asr & ASR_INT ? 'I' : 'i',
- asr & ASR_LCI ? 'L' : 'l',
- asr & ASR_BSY ? 'B' : 'b',
- asr & ASR_CIP ? 'C' : 'c',
- asr & ASR_PE ? 'P' : 'p',
- asr & ASR_DBR ? 'D' : 'd');
- printk("scsi: ");
- print_scsi_status(ssr);
- printk(" ph %02X\n", cmdphase);
- #else
- printk("sbic: %02X scsi: %X:%X ph: %02X\n",
- asr, (ssr & 0xf0)>>4, ssr & 0x0f, cmdphase);
- #endif
- }
- static void
- acornscsi_dumplogline(AS_Host *host, int target, int line)
- {
- unsigned long prev;
- signed int ptr;
- ptr = host->status_ptr[target] - STATUS_BUFFER_TO_PRINT;
- if (ptr < 0)
- ptr += STATUS_BUFFER_SIZE;
- printk("%c: %3s:", target == 8 ? 'H' : '0' + target,
- line == 0 ? "ph" : line == 1 ? "ssr" : "int");
- prev = host->status[target][ptr].when;
- for (; ptr != host->status_ptr[target]; ptr = (ptr + 1) & (STATUS_BUFFER_SIZE - 1)) {
- unsigned long time_diff;
- if (!host->status[target][ptr].when)
- continue;
- switch (line) {
- case 0:
- printk("%c%02X", host->status[target][ptr].irq ? '-' : ' ',
- host->status[target][ptr].ph);
- break;
- case 1:
- printk(" %02X", host->status[target][ptr].ssr);
- break;
- case 2:
- time_diff = host->status[target][ptr].when - prev;
- prev = host->status[target][ptr].when;
- if (time_diff == 0)
- printk("==^");
- else if (time_diff >= 100)
- printk(" ");
- else
- printk(" %02ld", time_diff);
- break;
- }
- }
- printk("\n");
- }
- static
- void acornscsi_dumplog(AS_Host *host, int target)
- {
- do {
- acornscsi_dumplogline(host, target, 0);
- acornscsi_dumplogline(host, target, 1);
- acornscsi_dumplogline(host, target, 2);
- if (target == 8)
- break;
- target = 8;
- } while (1);
- }
- static
- char acornscsi_target(AS_Host *host)
- {
- if (host->SCpnt)
- return '0' + host->SCpnt->device->id;
- return 'H';
- }
- /*
- * Prototype: cmdtype_t acornscsi_cmdtype(int command)
- * Purpose : differentiate READ from WRITE from other commands
- * Params : command - command to interpret
- * Returns : CMD_READ - command reads data,
- * CMD_WRITE - command writes data,
- * CMD_MISC - everything else
- */
- static inline
- cmdtype_t acornscsi_cmdtype(int command)
- {
- switch (command) {
- case WRITE_6: case WRITE_10: case WRITE_12:
- return CMD_WRITE;
- case READ_6: case READ_10: case READ_12:
- return CMD_READ;
- default:
- return CMD_MISC;
- }
- }
- /*
- * Prototype: int acornscsi_datadirection(int command)
- * Purpose : differentiate between commands that have a DATA IN phase
- * and a DATA OUT phase
- * Params : command - command to interpret
- * Returns : DATADIR_OUT - data out phase expected
- * DATADIR_IN - data in phase expected
- */
- static
- datadir_t acornscsi_datadirection(int command)
- {
- switch (command) {
- case CHANGE_DEFINITION: case COMPARE: case COPY:
- case COPY_VERIFY: case LOG_SELECT: case MODE_SELECT:
- case MODE_SELECT_10: case SEND_DIAGNOSTIC: case WRITE_BUFFER:
- case FORMAT_UNIT: case REASSIGN_BLOCKS: case RESERVE:
- case SEARCH_EQUAL: case SEARCH_HIGH: case SEARCH_LOW:
- case WRITE_6: case WRITE_10: case WRITE_VERIFY:
- case UPDATE_BLOCK: case WRITE_LONG: case WRITE_SAME:
- case SEARCH_HIGH_12: case SEARCH_EQUAL_12: case SEARCH_LOW_12:
- case WRITE_12: case WRITE_VERIFY_12: case SET_WINDOW:
- case MEDIUM_SCAN: case SEND_VOLUME_TAG: case 0xea:
- return DATADIR_OUT;
- default:
- return DATADIR_IN;
- }
- }
- /*
- * Purpose : provide values for synchronous transfers with 33C93.
- * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
- * Modified by Russell King for 8MHz WD33C93A
- */
- static struct sync_xfer_tbl {
- unsigned int period_ns;
- unsigned char reg_value;
- } sync_xfer_table[] = {
- { 1, 0x20 }, { 249, 0x20 }, { 374, 0x30 },
- { 499, 0x40 }, { 624, 0x50 }, { 749, 0x60 },
- { 874, 0x70 }, { 999, 0x00 }, { 0, 0 }
- };
- /*
- * Prototype: int acornscsi_getperiod(unsigned char syncxfer)
- * Purpose : period for the synchronous transfer setting
- * Params : syncxfer SYNCXFER register value
- * Returns : period in ns.
- */
- static
- int acornscsi_getperiod(unsigned char syncxfer)
- {
- int i;
- syncxfer &= 0xf0;
- if (syncxfer == 0x10)
- syncxfer = 0;
- for (i = 1; sync_xfer_table[i].period_ns; i++)
- if (syncxfer == sync_xfer_table[i].reg_value)
- return sync_xfer_table[i].period_ns;
- return 0;
- }
- /*
- * Prototype: int round_period(unsigned int period)
- * Purpose : return index into above table for a required REQ period
- * Params : period - time (ns) for REQ
- * Returns : table index
- * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
- */
- static inline
- int round_period(unsigned int period)
- {
- int i;
- for (i = 1; sync_xfer_table[i].period_ns; i++) {
- if ((period <= sync_xfer_table[i].period_ns) &&
- (period > sync_xfer_table[i - 1].period_ns))
- return i;
- }
- return 7;
- }
- /*
- * Prototype: unsigned char calc_sync_xfer(unsigned int period, unsigned int offset)
- * Purpose : calculate value for 33c93s SYNC register
- * Params : period - time (ns) for REQ
- * offset - offset in bytes between REQ/ACK
- * Returns : value for SYNC register
- * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
- */
- static
- unsigned char __maybe_unused calc_sync_xfer(unsigned int period,
- unsigned int offset)
- {
- return sync_xfer_table[round_period(period)].reg_value |
- ((offset < SDTR_SIZE) ? offset : SDTR_SIZE);
- }
- /* ====================================================================================
- * Command functions
- */
- /*
- * Function: acornscsi_kick(AS_Host *host)
- * Purpose : kick next command to interface
- * Params : host - host to send command to
- * Returns : INTR_IDLE if idle, otherwise INTR_PROCESSING
- * Notes : interrupts are always disabled!
- */
- static
- intr_ret_t acornscsi_kick(AS_Host *host)
- {
- int from_queue = 0;
- struct scsi_cmnd *SCpnt;
- /* first check to see if a command is waiting to be executed */
- SCpnt = host->origSCpnt;
- host->origSCpnt = NULL;
- /* retrieve next command */
- if (!SCpnt) {
- SCpnt = queue_remove_exclude(&host->queues.issue, host->busyluns);
- if (!SCpnt)
- return INTR_IDLE;
- from_queue = 1;
- }
- if (host->scsi.disconnectable && host->SCpnt) {
- queue_add_cmd_tail(&host->queues.disconnected, host->SCpnt);
- host->scsi.disconnectable = 0;
- #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
- DBG(host->SCpnt, printk("scsi%d.%c: moved command to disconnected queue\n",
- host->host->host_no, acornscsi_target(host)));
- #endif
- host->SCpnt = NULL;
- }
- /*
- * If we have an interrupt pending, then we may have been reselected.
- * In this case, we don't want to write to the registers
- */
- if (!(sbic_arm_read(host, SBIC_ASR) & (ASR_INT|ASR_BSY|ASR_CIP))) {
- sbic_arm_write(host, SBIC_DESTID, SCpnt->device->id);
- sbic_arm_write(host, SBIC_CMND, CMND_SELWITHATN);
- }
- /*
- * claim host busy - all of these must happen atomically wrt
- * our interrupt routine. Failure means command loss.
- */
- host->scsi.phase = PHASE_CONNECTING;
- host->SCpnt = SCpnt;
- host->scsi.SCp = SCpnt->SCp;
- host->dma.xfer_setup = 0;
- host->dma.xfer_required = 0;
- host->dma.xfer_done = 0;
- #if (DEBUG & (DEBUG_ABORT|DEBUG_CONNECT))
- DBG(SCpnt,printk("scsi%d.%c: starting cmd %02X\n",
- host->host->host_no, '0' + SCpnt->device->id,
- SCpnt->cmnd[0]));
- #endif
- if (from_queue) {
- #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
- /*
- * tagged queueing - allocate a new tag to this command
- */
- if (SCpnt->device->simple_tags) {
- SCpnt->device->current_tag += 1;
- if (SCpnt->device->current_tag == 0)
- SCpnt->device->current_tag = 1;
- SCpnt->tag = SCpnt->device->current_tag;
- } else
- #endif
- set_bit(SCpnt->device->id * 8 +
- (u8)(SCpnt->device->lun & 0x07), host->busyluns);
- host->stats.removes += 1;
- switch (acornscsi_cmdtype(SCpnt->cmnd[0])) {
- case CMD_WRITE:
- host->stats.writes += 1;
- break;
- case CMD_READ:
- host->stats.reads += 1;
- break;
- case CMD_MISC:
- host->stats.miscs += 1;
- break;
- }
- }
- return INTR_PROCESSING;
- }
- /*
- * Function: void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp, unsigned int result)
- * Purpose : complete processing for command
- * Params : host - interface that completed
- * result - driver byte of result
- */
- static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
- unsigned int result)
- {
- struct scsi_cmnd *SCpnt = *SCpntp;
- /* clean up */
- sbic_arm_write(host, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
- host->stats.fins += 1;
- if (SCpnt) {
- *SCpntp = NULL;
- acornscsi_dma_cleanup(host);
- SCpnt->result = result << 16 | host->scsi.SCp.Message << 8 | host->scsi.SCp.Status;
- /*
- * In theory, this should not happen. In practice, it seems to.
- * Only trigger an error if the device attempts to report all happy
- * but with untransferred buffers... If we don't do something, then
- * data loss will occur. Should we check SCpnt->underflow here?
- * It doesn't appear to be set to something meaningful by the higher
- * levels all the time.
- */
- if (result == DID_OK) {
- int xfer_warn = 0;
- if (SCpnt->underflow == 0) {
- if (host->scsi.SCp.ptr &&
- acornscsi_cmdtype(SCpnt->cmnd[0]) != CMD_MISC)
- xfer_warn = 1;
- } else {
- if (host->scsi.SCp.scsi_xferred < SCpnt->underflow ||
- host->scsi.SCp.scsi_xferred != host->dma.transferred)
- xfer_warn = 1;
- }
- /* ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.6)
- * Targets which break data transfers into multiple
- * connections shall end each successful connection
- * (except possibly the last) with a SAVE DATA
- * POINTER - DISCONNECT message sequence.
- *
- * This makes it difficult to ensure that a transfer has
- * completed. If we reach the end of a transfer during
- * the command, then we can only have finished the transfer.
- * therefore, if we seem to have some data remaining, this
- * is not a problem.
- */
- if (host->dma.xfer_done)
- xfer_warn = 0;
- if (xfer_warn) {
- switch (status_byte(SCpnt->result)) {
- case CHECK_CONDITION:
- case COMMAND_TERMINATED:
- case BUSY:
- case QUEUE_FULL:
- case RESERVATION_CONFLICT:
- break;
- default:
- scmd_printk(KERN_ERR, SCpnt,
- "incomplete data transfer detected: "
- "result=%08X", SCpnt->result);
- scsi_print_command(SCpnt);
- acornscsi_dumpdma(host, "done");
- acornscsi_dumplog(host, SCpnt->device->id);
- set_host_byte(SCpnt, DID_ERROR);
- }
- }
- }
- if (!SCpnt->scsi_done)
- panic("scsi%d.H: null scsi_done function in acornscsi_done", host->host->host_no);
- clear_bit(SCpnt->device->id * 8 +
- (u8)(SCpnt->device->lun & 0x7), host->busyluns);
- SCpnt->scsi_done(SCpnt);
- } else
- printk("scsi%d: null command in acornscsi_done", host->host->host_no);
- host->scsi.phase = PHASE_IDLE;
- }
- /* ====================================================================================
- * DMA routines
- */
- /*
- * Purpose : update SCSI Data Pointer
- * Notes : this will only be one SG entry or less
- */
- static
- void acornscsi_data_updateptr(AS_Host *host, struct scsi_pointer *SCp, unsigned int length)
- {
- SCp->ptr += length;
- SCp->this_residual -= length;
- if (SCp->this_residual == 0 && next_SCp(SCp) == 0)
- host->dma.xfer_done = 1;
- }
- /*
- * Prototype: void acornscsi_data_read(AS_Host *host, char *ptr,
- * unsigned int start_addr, unsigned int length)
- * Purpose : read data from DMA RAM
- * Params : host - host to transfer from
- * ptr - DRAM address
- * start_addr - host mem address
- * length - number of bytes to transfer
- * Notes : this will only be one SG entry or less
- */
- static
- void acornscsi_data_read(AS_Host *host, char *ptr,
- unsigned int start_addr, unsigned int length)
- {
- extern void __acornscsi_in(void __iomem *, char *buf, int len);
- unsigned int page, offset, len = length;
- page = (start_addr >> 12);
- offset = start_addr & ((1 << 12) - 1);
- writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
- while (len > 0) {
- unsigned int this_len;
- if (len + offset > (1 << 12))
- this_len = (1 << 12) - offset;
- else
- this_len = len;
- __acornscsi_in(host->base + (offset << 1), ptr, this_len);
- offset += this_len;
- ptr += this_len;
- len -= this_len;
- if (offset == (1 << 12)) {
- offset = 0;
- page ++;
- writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
- }
- }
- writeb(host->card.page_reg, host->fast + PAGE_REG);
- }
- /*
- * Prototype: void acornscsi_data_write(AS_Host *host, char *ptr,
- * unsigned int start_addr, unsigned int length)
- * Purpose : write data to DMA RAM
- * Params : host - host to transfer from
- * ptr - DRAM address
- * start_addr - host mem address
- * length - number of bytes to transfer
- * Notes : this will only be one SG entry or less
- */
- static
- void acornscsi_data_write(AS_Host *host, char *ptr,
- unsigned int start_addr, unsigned int length)
- {
- extern void __acornscsi_out(void __iomem *, char *buf, int len);
- unsigned int page, offset, len = length;
- page = (start_addr >> 12);
- offset = start_addr & ((1 << 12) - 1);
- writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
- while (len > 0) {
- unsigned int this_len;
- if (len + offset > (1 << 12))
- this_len = (1 << 12) - offset;
- else
- this_len = len;
- __acornscsi_out(host->base + (offset << 1), ptr, this_len);
- offset += this_len;
- ptr += this_len;
- len -= this_len;
- if (offset == (1 << 12)) {
- offset = 0;
- page ++;
- writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
- }
- }
- writeb(host->card.page_reg, host->fast + PAGE_REG);
- }
- /* =========================================================================================
- * On-board DMA routines
- */
- #ifdef USE_DMAC
- /*
- * Prototype: void acornscsi_dmastop(AS_Host *host)
- * Purpose : stop all DMA
- * Params : host - host on which to stop DMA
- * Notes : This is called when leaving DATA IN/OUT phase,
- * or when interface is RESET
- */
- static inline
- void acornscsi_dma_stop(AS_Host *host)
- {
- dmac_write(host, DMAC_MASKREG, MASK_ON);
- dmac_clearintr(host);
- #if (DEBUG & DEBUG_DMA)
- DBG(host->SCpnt, acornscsi_dumpdma(host, "stop"));
- #endif
- }
- /*
- * Function: void acornscsi_dma_setup(AS_Host *host, dmadir_t direction)
- * Purpose : setup DMA controller for data transfer
- * Params : host - host to setup
- * direction - data transfer direction
- * Notes : This is called when entering DATA I/O phase, not
- * while we're in a DATA I/O phase
- */
- static
- void acornscsi_dma_setup(AS_Host *host, dmadir_t direction)
- {
- unsigned int address, length, mode;
- host->dma.direction = direction;
- dmac_write(host, DMAC_MASKREG, MASK_ON);
- if (direction == DMA_OUT) {
- #if (DEBUG & DEBUG_NO_WRITE)
- if (NO_WRITE & (1 << host->SCpnt->device->id)) {
- printk(KERN_CRIT "scsi%d.%c: I can't handle DMA_OUT!\n",
- host->host->host_no, acornscsi_target(host));
- return;
- }
- #endif
- mode = DMAC_WRITE;
- } else
- mode = DMAC_READ;
- /*
- * Allocate some buffer space, limited to half the buffer size
- */
- length = min_t(unsigned int, host->scsi.SCp.this_residual, DMAC_BUFFER_SIZE / 2);
- if (length) {
- host->dma.start_addr = address = host->dma.free_addr;
- host->dma.free_addr = (host->dma.free_addr + length) &
- (DMAC_BUFFER_SIZE - 1);
- /*
- * Transfer data to DMA memory
- */
- if (direction == DMA_OUT)
- acornscsi_data_write(host, host->scsi.SCp.ptr, host->dma.start_addr,
- length);
- length -= 1;
- dmac_write(host, DMAC_TXCNTLO, length);
- dmac_write(host, DMAC_TXCNTHI, length >> 8);
- dmac_write(host, DMAC_TXADRLO, address);
- dmac_write(host, DMAC_TXADRMD, address >> 8);
- dmac_write(host, DMAC_TXADRHI, 0);
- dmac_write(host, DMAC_MODECON, mode);
- dmac_write(host, DMAC_MASKREG, MASK_OFF);
- #if (DEBUG & DEBUG_DMA)
- DBG(host->SCpnt, acornscsi_dumpdma(host, "strt"));
- #endif
- host->dma.xfer_setup = 1;
- }
- }
- /*
- * Function: void acornscsi_dma_cleanup(AS_Host *host)
- * Purpose : ensure that all DMA transfers are up-to-date & host->scsi.SCp is correct
- * Params : host - host to finish
- * Notes : This is called when a command is:
- * terminating, RESTORE_POINTERS, SAVE_POINTERS, DISCONNECT
- * : This must not return until all transfers are completed.
- */
- static
- void acornscsi_dma_cleanup(AS_Host *host)
- {
- dmac_write(host, DMAC_MASKREG, MASK_ON);
- dmac_clearintr(host);
- /*
- * Check for a pending transfer
- */
- if (host->dma.xfer_required) {
- host->dma.xfer_required = 0;
- if (host->dma.direction == DMA_IN)
- acornscsi_data_read(host, host->dma.xfer_ptr,
- host->dma.xfer_start, host->dma.xfer_length);
- }
- /*
- * Has a transfer been setup?
- */
- if (host->dma.xfer_setup) {
- unsigned int transferred;
- host->dma.xfer_setup = 0;
- #if (DEBUG & DEBUG_DMA)
- DBG(host->SCpnt, acornscsi_dumpdma(host, "cupi"));
- #endif
- /*
- * Calculate number of bytes transferred from DMA.
- */
- transferred = dmac_address(host) - host->dma.start_addr;
- host->dma.transferred += transferred;
- if (host->dma.direction == DMA_IN)
- acornscsi_data_read(host, host->scsi.SCp.ptr,
- host->dma.start_addr, transferred);
- /*
- * Update SCSI pointers
- */
- acornscsi_data_updateptr(host, &host->scsi.SCp, transferred);
- #if (DEBUG & DEBUG_DMA)
- DBG(host->SCpnt, acornscsi_dumpdma(host, "cupo"));
- #endif
- }
- }
- /*
- * Function: void acornscsi_dmacintr(AS_Host *host)
- * Purpose : handle interrupts from DMAC device
- * Params : host - host to process
- * Notes : If reading, we schedule the read to main memory &
- * allow the transfer to continue.
- * : If writing, we fill the onboard DMA memory from main
- * memory.
- * : Called whenever DMAC finished it's current transfer.
- */
- static
- void acornscsi_dma_intr(AS_Host *host)
- {
- unsigned int address, length, transferred;
- #if (DEBUG & DEBUG_DMA)
- DBG(host->SCpnt, acornscsi_dumpdma(host, "inti"));
- #endif
- dmac_write(host, DMAC_MASKREG, MASK_ON);
- dmac_clearintr(host);
- /*
- * Calculate amount transferred via DMA
- */
- transferred = dmac_address(host) - host->dma.start_addr;
- host->dma.transferred += transferred;
- /*
- * Schedule DMA transfer off board
- */
- if (host->dma.direction == DMA_IN) {
- host->dma.xfer_start = host->dma.start_addr;
- host->dma.xfer_length = transferred;
- host->dma.xfer_ptr = host->scsi.SCp.ptr;
- host->dma.xfer_required = 1;
- }
- acornscsi_data_updateptr(host, &host->scsi.SCp, transferred);
- /*
- * Allocate some buffer space, limited to half the on-board RAM size
- */
- length = min_t(unsigned int, host->scsi.SCp.this_residual, DMAC_BUFFER_SIZE / 2);
- if (length) {
- host->dma.start_addr = address = host->dma.free_addr;
- host->dma.free_addr = (host->dma.free_addr + length) &
- (DMAC_BUFFER_SIZE - 1);
- /*
- * Transfer data to DMA memory
- */
- if (host->dma.direction == DMA_OUT)
- acornscsi_data_write(host, host->scsi.SCp.ptr, host->dma.start_addr,
- length);
- length -= 1;
- dmac_write(host, DMAC_TXCNTLO, length);
- dmac_write(host, DMAC_TXCNTHI, length >> 8);
- dmac_write(host, DMAC_TXADRLO, address);
- dmac_write(host, DMAC_TXADRMD, address >> 8);
- dmac_write(host, DMAC_TXADRHI, 0);
- dmac_write(host, DMAC_MASKREG, MASK_OFF);
- #if (DEBUG & DEBUG_DMA)
- DBG(host->SCpnt, acornscsi_dumpdma(host, "into"));
- #endif
- } else {
- host->dma.xfer_setup = 0;
- #if 0
- /*
- * If the interface still wants more, then this is an error.
- * We give it another byte, but we also attempt to raise an
- * attention condition. We continue giving one byte until
- * the device recognises the attention.
- */
- if (dmac_read(host, DMAC_STATUS) & STATUS_RQ0) {
- acornscsi_abortcmd(host, host->SCpnt->tag);
- dmac_write(host, DMAC_TXCNTLO, 0);
- dmac_write(host, DMAC_TXCNTHI, 0);
- dmac_write(host, DMAC_TXADRLO, 0);
- dmac_write(host, DMAC_TXADRMD, 0);
- dmac_write(host, DMAC_TXADRHI, 0);
- dmac_write(host, DMAC_MASKREG, MASK_OFF);
- }
- #endif
- }
- }
- /*
- * Function: void acornscsi_dma_xfer(AS_Host *host)
- * Purpose : transfer data between AcornSCSI and memory
- * Params : host - host to process
- */
- static
- void acornscsi_dma_xfer(AS_Host *host)
- {
- host->dma.xfer_required = 0;
- if (host->dma.direction == DMA_IN)
- acornscsi_data_read(host, host->dma.xfer_ptr,
- host->dma.xfer_start, host->dma.xfer_length);
- }
- /*
- * Function: void acornscsi_dma_adjust(AS_Host *host)
- * Purpose : adjust DMA pointers & count for bytes transferred to
- * SBIC but not SCSI bus.
- * Params : host - host to adjust DMA count for
- */
- static
- void acornscsi_dma_adjust(AS_Host *host)
- {
- if (host->dma.xfer_setup) {
- signed long transferred;
- #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
- DBG(host->SCpnt, acornscsi_dumpdma(host, "adji"));
- #endif
- /*
- * Calculate correct DMA address - DMA is ahead of SCSI bus while
- * writing.
- * host->scsi.SCp.scsi_xferred is the number of bytes
- * actually transferred to/from the SCSI bus.
- * host->dma.transferred is the number of bytes transferred
- * over DMA since host->dma.start_addr was last set.
- *
- * real_dma_addr = host->dma.start_addr + host->scsi.SCp.scsi_xferred
- * - host->dma.transferred
- */
- transferred = host->scsi.SCp.scsi_xferred - host->dma.transferred;
- if (transferred < 0)
- printk("scsi%d.%c: Ack! DMA write correction %ld < 0!\n",
- host->host->host_no, acornscsi_target(host), transferred);
- else if (transferred == 0)
- host->dma.xfer_setup = 0;
- else {
- transferred += host->dma.start_addr;
- dmac_write(host, DMAC_TXADRLO, transferred);
- dmac_write(host, DMAC_TXADRMD, transferred >> 8);
- dmac_write(host, DMAC_TXADRHI, transferred >> 16);
- #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
- DBG(host->SCpnt, acornscsi_dumpdma(host, "adjo"));
- #endif
- }
- }
- }
- #endif
- /* =========================================================================================
- * Data I/O
- */
- static int
- acornscsi_write_pio(AS_Host *host, char *bytes, int *ptr, int len, unsigned int max_timeout)
- {
- unsigned int asr, timeout = max_timeout;
- int my_ptr = *ptr;
- while (my_ptr < len) {
- asr = sbic_arm_read(host, SBIC_ASR);
- if (asr & ASR_DBR) {
- timeout = max_timeout;
- sbic_arm_write(host, SBIC_DATA, bytes[my_ptr++]);
- } else if (asr & ASR_INT)
- break;
- else if (--timeout == 0)
- break;
- udelay(1);
- }
- *ptr = my_ptr;
- return (timeout == 0) ? -1 : 0;
- }
- /*
- * Function: void acornscsi_sendcommand(AS_Host *host)
- * Purpose : send a command to a target
- * Params : host - host which is connected to target
- */
- static void
- acornscsi_sendcommand(AS_Host *host)
- {
- struct scsi_cmnd *SCpnt = host->SCpnt;
- sbic_arm_write(host, SBIC_TRANSCNTH, 0);
- sbic_arm_writenext(host, 0);
- sbic_arm_writenext(host, SCpnt->cmd_len - host->scsi.SCp.sent_command);
- acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
- if (acornscsi_write_pio(host, SCpnt->cmnd,
- (int *)&host->scsi.SCp.sent_command, SCpnt->cmd_len, 1000000))
- printk("scsi%d: timeout while sending command\n", host->host->host_no);
- host->scsi.phase = PHASE_COMMAND;
- }
- static
- void acornscsi_sendmessage(AS_Host *host)
- {
- unsigned int message_length = msgqueue_msglength(&host->scsi.msgs);
- unsigned int msgnr;
- struct message *msg;
- #if (DEBUG & DEBUG_MESSAGES)
- printk("scsi%d.%c: sending message ",
- host->host->host_no, acornscsi_target(host));
- #endif
- switch (message_length) {
- case 0:
- acornscsi_sbic_issuecmd(host, CMND_XFERINFO | CMND_SBT);
- acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "sending message 1");
- sbic_arm_write(host, SBIC_DATA, NOP);
- host->scsi.last_message = NOP;
- #if (DEBUG & DEBUG_MESSAGES)
- printk("NOP");
- #endif
- break;
- case 1:
- acornscsi_sbic_issuecmd(host, CMND_XFERINFO | CMND_SBT);
- msg = msgqueue_getmsg(&host->scsi.msgs, 0);
- acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "sending message 2");
- sbic_arm_write(host, SBIC_DATA, msg->msg[0]);
- host->scsi.last_message = msg->msg[0];
- #if (DEBUG & DEBUG_MESSAGES)
- spi_print_msg(msg->msg);
- #endif
- break;
- default:
- /*
- * ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.14)
- * 'When a target sends this (MESSAGE_REJECT) message, it
- * shall change to MESSAGE IN phase and send this message
- * prior to requesting additional message bytes from the
- * initiator. This provides an interlock so that the
- * initiator can determine which message byte is rejected.
- */
- sbic_arm_write(host, SBIC_TRANSCNTH, 0);
- sbic_arm_writenext(host, 0);
- sbic_arm_writenext(host, message_length);
- acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
- msgnr = 0;
- while ((msg = msgqueue_getmsg(&host->scsi.msgs, msgnr++)) != NULL) {
- unsigned int i;
- #if (DEBUG & DEBUG_MESSAGES)
- spi_print_msg(msg);
- #endif
- i = 0;
- if (acornscsi_write_pio(host, msg->msg, &i, msg->length, 1000000))
- printk("scsi%d: timeout while sending message\n", host->host->host_no);
- host->scsi.last_message = msg->msg[0];
- if (msg->msg[0] == EXTENDED_MESSAGE)
- host->scsi.last_message |= msg->msg[2] << 8;
- if (i != msg->length)
- break;
- }
- break;
- }
- #if (DEBUG & DEBUG_MESSAGES)
- printk("\n");
- #endif
- }
- /*
- * Function: void acornscsi_readstatusbyte(AS_Host *host)
- * Purpose : Read status byte from connected target
- * Params : host - host connected to target
- */
- static
- void acornscsi_readstatusbyte(AS_Host *host)
- {
- acornscsi_sbic_issuecmd(host, CMND_XFERINFO|CMND_SBT);
- acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "reading status byte");
- host->scsi.SCp.Status = sbic_arm_read(host, SBIC_DATA);
- }
- /*
- * Function: unsigned char acornscsi_readmessagebyte(AS_Host *host)
- * Purpose : Read one message byte from connected target
- * Params : host - host connected to target
- */
- static
- unsigned char acornscsi_readmessagebyte(AS_Host *host)
- {
- unsigned char message;
- acornscsi_sbic_issuecmd(host, CMND_XFERINFO | CMND_SBT);
- acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "for message byte");
- message = sbic_arm_read(host, SBIC_DATA);
- /* wait for MSGIN-XFER-PAUSED */
- acornscsi_sbic_wait(host, ASR_INT, ASR_INT, 1000, "for interrupt after message byte");
- sbic_arm_read(host, SBIC_SSR);
- return message;
- }
- /*
- * Function: void acornscsi_message(AS_Host *host)
- * Purpose : Read complete message from connected target & action message
- * Params : host - host connected to target
- */
- static
- void acornscsi_message(AS_Host *host)
- {
- unsigned char message[16];
- unsigned int msgidx = 0, msglen = 1;
- do {
- message[msgidx] = acornscsi_readmessagebyte(host);
- switch (msgidx) {
- case 0:
- if (message[0] == EXTENDED_MESSAGE ||
- (message[0] >= 0x20 && message[0] <= 0x2f))
- msglen = 2;
- break;
- case 1:
- if (message[0] == EXTENDED_MESSAGE)
- msglen += message[msgidx];
- break;
- }
- msgidx += 1;
- if (msgidx < msglen) {
- acornscsi_sbic_issuecmd(host, CMND_NEGATEACK);
- /* wait for next msg-in */
- acornscsi_sbic_wait(host, ASR_INT, ASR_INT, 1000, "for interrupt after negate ack");
- sbic_arm_read(host, SBIC_SSR);
- }
- } while (msgidx < msglen);
- #if (DEBUG & DEBUG_MESSAGES)
- printk("scsi%d.%c: message in: ",
- host->host->host_no, acornscsi_target(host));
- spi_print_msg(message);
- printk("\n");
- #endif
- if (host->scsi.phase == PHASE_RECONNECTED) {
- /*
- * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
- * 'Whenever a target reconnects to an initiator to continue
- * a tagged I/O process, the SIMPLE QUEUE TAG message shall
- * be sent immediately following the IDENTIFY message...'
- */
- if (message[0] == SIMPLE_QUEUE_TAG)
- host->scsi.reconnected.tag = message[1];
- if (acornscsi_reconnect_finish(host))
- host->scsi.phase = PHASE_MSGIN;
- }
- switch (message[0]) {
- case ABORT:
- case ABORT_TAG:
- case COMMAND_COMPLETE:
- if (host->scsi.phase != PHASE_STATUSIN) {
- printk(KERN_ERR "scsi%d.%c: command complete following non-status in phase?\n",
- host->host->host_no, acornscsi_target(host));
- acornscsi_dumplog(host, host->SCpnt->device->id);
- }
- host->scsi.phase = PHASE_DONE;
- host->scsi.SCp.Message = message[0];
- break;
- case SAVE_POINTERS:
- /*
- * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.20)
- * 'The SAVE DATA POINTER message is sent from a target to
- * direct the initiator to copy the active data pointer to
- * the saved data pointer for the current I/O process.
- */
- acornscsi_dma_cleanup(host);
- host->SCpnt->SCp = host->scsi.SCp;
- host->SCpnt->SCp.sent_command = 0;
- host->scsi.phase = PHASE_MSGIN;
- break;
- case RESTORE_POINTERS:
- /*
- * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.19)
- * 'The RESTORE POINTERS message is sent from a target to
- * direct the initiator to copy the most recently saved
- * command, data, and status pointers for the I/O process
- * to the corresponding active pointers. The command and
- * status pointers shall be restored to the beginning of
- * the present command and status areas.'
- */
- acornscsi_dma_cleanup(host);
- host->scsi.SCp = host->SCpnt->SCp;
- host->scsi.phase = PHASE_MSGIN;
- break;
- case DISCONNECT:
- /*
- * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 6.4.2)
- * 'On those occasions when an error or exception condition occurs
- * and the target elects to repeat the information transfer, the
- * target may repeat the transfer either issuing a RESTORE POINTERS
- * message or by disconnecting without issuing a SAVE POINTERS
- * message. When reconnection is completed, the most recent
- * saved pointer values are restored.'
- */
- acornscsi_dma_cleanup(host);
- host->scsi.phase = PHASE_DISCONNECT;
- break;
- case MESSAGE_REJECT:
- #if 0 /* this isn't needed any more */
- /*
- * 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
- * transfer. Re-initiate sync transfer negotiation now, and if
- * we got a REJECT in response to SDTR, then it'll be set to DONE.
- */
- if (host->device[host->SCpnt->device->id].sync_state == SYNC_SENT_REQUEST)
- host->device[host->SCpnt->device->id].sync_state = SYNC_NEGOCIATE;
- #endif
- /*
- * If we have any messages waiting to go out, then assert ATN now
- */
- if (msgqueue_msglength(&host->scsi.msgs))
- acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
- switch (host->scsi.last_message) {
- #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
- case HEAD_OF_QUEUE_TAG:
- case ORDERED_QUEUE_TAG:
- case SIMPLE_QUEUE_TAG:
- /*
- * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
- * If a target does not implement tagged queuing and a queue tag
- * message is received, it shall respond with a MESSAGE REJECT
- * message and accept the I/O process as if it were untagged.
- */
- printk(KERN_NOTICE "scsi%d.%c: disabling tagged queueing\n",
- host->host->host_no, acornscsi_target(host));
- host->SCpnt->device->simple_tags = 0;
- set_bit(host->SCpnt->device->id * 8 +
- (u8)(host->SCpnt->device->lun & 0x7), host->busyluns);
- break;
- #endif
- case EXTENDED_MESSAGE | (EXTENDED_SDTR << 8):
- /*
- * Target can't handle synchronous transfers
- */
- printk(KERN_NOTICE "scsi%d.%c: Using asynchronous transfer\n",
- host->host->host_no, acornscsi_target(host));
- host->device[host->SCpnt->device->id].sync_xfer = SYNCHTRANSFER_2DBA;
- host->device[host->SCpnt->device->id].sync_state = SYNC_ASYNCHRONOUS;
- sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
- break;
- default:
- break;
- }
- break;
- case QUEUE_FULL:
- /* TODO: target queue is full */
- break;
- case SIMPLE_QUEUE_TAG:
- /* tag queue reconnect... message[1] = queue tag. Print something to indicate something happened! */
- printk("scsi%d.%c: reconnect queue tag %02X\n",
- host->host->host_no, acornscsi_target(host),
- message[1]);
- break;
- case EXTENDED_MESSAGE:
- switch (message[2]) {
- #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
- case EXTENDED_SDTR:
- if (host->device[host->SCpnt->device->id].sync_state == SYNC_SENT_REQUEST) {
- /*
- * We requested synchronous transfers. This isn't quite right...
- * 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,
- * and the target retries fail, then we fallback to asynchronous mode
- */
- host->device[host->SCpnt->device->id].sync_state = SYNC_COMPLETED;
- printk(KERN_NOTICE "scsi%d.%c: Using synchronous transfer, offset %d, %d ns\n",
- host->host->host_no, acornscsi_target(host),
- message[4], message[3] * 4);
- host->device[host->SCpnt->device->id].sync_xfer =
- calc_sync_xfer(message[3] * 4, message[4]);
- } else {
- unsigned char period, length;
- /*
- * Target requested synchronous transfers. The agreement is only
- * to be in operation AFTER the target leaves message out phase.
- */
- acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
- period = max_t(unsigned int, message[3], sdtr_period / 4);
- length = min_t(unsigned int, message[4], sdtr_size);
- msgqueue_addmsg(&host->scsi.msgs, 5, EXTENDED_MESSAGE, 3,
- EXTENDED_SDTR, period, length);
- host->device[host->SCpnt->device->id].sync_xfer =
- calc_sync_xfer(period * 4, length);
- }
- sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
- break;
- #else
- /* We do not accept synchronous transfers. Respond with a
- * MESSAGE_REJECT.
- */
- #endif
- case EXTENDED_WDTR:
- /* The WD33C93A is only 8-bit. We respond with a MESSAGE_REJECT
- * to a wide data transfer request.
- */
- default:
- acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
- msgqueue_flush(&host->scsi.msgs);
- msgqueue_addmsg(&host->scsi.msgs, 1, MESSAGE_REJECT);
- break;
- }
- break;
- default: /* reject message */
- printk(KERN_ERR "scsi%d.%c: unrecognised message %02X, rejecting\n",
- host->host->host_no, acornscsi_target(host),
- message[0]);
- acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
- msgqueue_flush(&host->scsi.msgs);
- msgqueue_addmsg(&host->scsi.msgs, 1, MESSAGE_REJECT);
- host->scsi.phase = PHASE_MSGIN;
- break;
- }
- acornscsi_sbic_issuecmd(host, CMND_NEGATEACK);
- }
- /*
- * Function: int acornscsi_buildmessages(AS_Host *host)
- * Purpose : build the connection messages for a host
- * Params : host - host to add messages to
- */
- static
- void acornscsi_buildmessages(AS_Host *host)
- {
- #if 0
- /* does the device need resetting? */
- if (cmd_reset) {
- msgqueue_addmsg(&host->scsi.msgs, 1, BUS_DEVICE_RESET);
- return;
- }
- #endif
- msgqueue_addmsg(&host->scsi.msgs, 1,
- IDENTIFY(host->device[host->SCpnt->device->id].disconnect_ok,
- host->SCpnt->device->lun));
- #if 0
- /* does the device need the current command aborted */
- if (cmd_aborted) {
- acornscsi_abortcmd(host->SCpnt->tag);
- return;
- }
- #endif
- #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
- if (host->SCpnt->tag) {
- unsigned int tag_type;
- if (host->SCpnt->cmnd[0] == REQUEST_SENSE ||
- host->SCpnt->cmnd[0] == TEST_UNIT_READY ||
- host->SCpnt->cmnd[0] == INQUIRY)
- tag_type = HEAD_OF_QUEUE_TAG;
- else
- tag_type = SIMPLE_QUEUE_TAG;
- msgqueue_addmsg(&host->scsi.msgs, 2, tag_type, host->SCpnt->tag);
- }
- #endif
- #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
- if (host->device[host->SCpnt->device->id].sync_state == SYNC_NEGOCIATE) {
- host->device[host->SCpnt->device->id].sync_state = SYNC_SENT_REQUEST;
- msgqueue_addmsg(&host->scsi.msgs, 5,
- EXTENDED_MESSAGE, 3, EXTENDED_SDTR,
- sdtr_period / 4, sdtr_size);
- }
- #endif
- }
- /*
- * Function: int acornscsi_starttransfer(AS_Host *host)
- * Purpose : transfer data to/from connected target
- * Params : host - host to which target is connected
- * Returns : 0 if failure
- */
- static
- int acornscsi_starttransfer(AS_Host *host)
- {
- int residual;
- if (!host->scsi.SCp.ptr /*&& host->scsi.SCp.this_residual*/) {
- printk(KERN_ERR "scsi%d.%c: null buffer passed to acornscsi_starttransfer\n",
- host->host->host_no, acornscsi_target(host));
- return 0;
- }
- residual = scsi_bufflen(host->SCpnt) - host->scsi.SCp.scsi_xferred;
- sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
- sbic_arm_writenext(host, residual >> 16);
- sbic_arm_writenext(host, residual >> 8);
- sbic_arm_writenext(host, residual);
- acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
- return 1;
- }
- /* =========================================================================================
- * Connection & Disconnection
- */
- /*
- * Function : acornscsi_reconnect(AS_Host *host)
- * Purpose : reconnect a previously disconnected command
- * Params : host - host specific data
- * Remarks : SCSI spec says:
- * 'The set of active pointers is restored from the set
- * of saved pointers upon reconnection of the I/O proces…