2 * linux/drivers/acorn/scsi/acornscsi.c
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Abandoned using the Select and Transfer command since there were
12 * some nasty races between our software and the target devices that
13 * were not easy to solve, and the device errata had a lot of entries
14 * for this command, some of them quite nasty...
17 * 26-Sep-1997 RMK Re-jigged to use the queue module.
18 * Re-coded state machine to be based on driver
19 * state not scsi state. Should be easier to debug.
20 * Added acornscsi_release to clean up properly.
21 * Updated proc/scsi reporting.
22 * 05-Oct-1997 RMK Implemented writing to SCSI devices.
23 * 06-Oct-1997 RMK Corrected small (non-serious) bug with the connect/
24 * reconnect race condition causing a warning message.
25 * 12-Oct-1997 RMK Added catch for re-entering interrupt routine.
26 * 15-Oct-1997 RMK Improved handling of commands.
27 * 27-Jun-1998 RMK Changed asm/delay.h to linux/delay.h.
28 * 13-Dec-1998 RMK Better abort code and command handling. Extra state
29 * transitions added to allow dodgy devices to work.
31 #define DEBUG_NO_WRITE 1
32 #define DEBUG_QUEUES 2
35 #define DEBUG_DISCON 16
36 #define DEBUG_CONNECT 32
37 #define DEBUG_PHASES 64
38 #define DEBUG_WRITE 128
39 #define DEBUG_LINK 256
40 #define DEBUG_MESSAGES 512
41 #define DEBUG_RESET 1024
42 #define DEBUG_ALL (DEBUG_RESET|DEBUG_MESSAGES|DEBUG_LINK|DEBUG_WRITE|\
43 DEBUG_PHASES|DEBUG_CONNECT|DEBUG_DISCON|DEBUG_ABORT|\
44 DEBUG_DMA|DEBUG_QUEUES)
46 /* DRIVER CONFIGURATION
48 * SCSI-II Tagged queue support.
50 * I don't have any SCSI devices that support it, so it is totally untested
51 * (except to make sure that it doesn't interfere with any non-tagging
52 * devices). It is not fully implemented either - what happens when a
53 * tagging device reconnects???
55 * You can tell if you have a device that supports tagged queueing my
56 * cating (eg) /proc/scsi/acornscsi/0 and see if the SCSI revision is reported
59 * Also note that CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE is normally set in the config
60 * scripts, but disabled here. Once debugged, remove the #undef, otherwise to debug,
61 * comment out the undef.
63 #undef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
65 * SCSI-II Linked command support.
67 * The higher level code doesn't support linked commands yet, and so the option
70 #undef CONFIG_SCSI_ACORNSCSI_LINK
72 * SCSI-II Synchronous transfer support.
76 * SDTR_SIZE - maximum number of un-acknowledged bytes (0 = off, 12 = max)
77 * SDTR_PERIOD - period of REQ signal (min=125, max=1020)
78 * DEFAULT_PERIOD - default REQ period.
81 #define SDTR_PERIOD 125
82 #define DEFAULT_PERIOD 500
85 * Debugging information
87 * DEBUG - bit mask from list above
88 * DEBUG_TARGET - is defined to the target number if you want to debug
89 * a specific target. [only recon/write/dma].
91 #define DEBUG (DEBUG_RESET|DEBUG_WRITE|DEBUG_NO_WRITE)
92 /* only allow writing to SCSI device 0 */
94 /*#define DEBUG_TARGET 2*/
96 * Select timeout time (in 10ms units)
98 * This is the timeout used between the start of selection and the WD33C93
99 * chip deciding that the device isn't responding.
101 #define TIMEOUT_TIME 10
103 * Define this if you want to have verbose explaination of SCSI
106 #undef CONFIG_ACORNSCSI_CONSTANTS
108 * Define this if you want to use the on board DMAC [don't remove this option]
109 * If not set, then use PIO mode (not currently supported).
114 * ====================================================================================
118 #define DBG(cmd,xxx...) \
119 if (cmd->device->id == DEBUG_TARGET) { \
123 #define DBG(cmd,xxx...) xxx
126 #include <linux/module.h>
127 #include <linux/kernel.h>
128 #include <linux/string.h>
129 #include <linux/signal.h>
130 #include <linux/errno.h>
131 #include <linux/proc_fs.h>
132 #include <linux/ioport.h>
133 #include <linux/blkdev.h>
134 #include <linux/delay.h>
135 #include <linux/interrupt.h>
136 #include <linux/init.h>
137 #include <linux/bitops.h>
138 #include <linux/stringify.h>
139 #include <linux/io.h>
141 #include <asm/system.h>
142 #include <asm/ecard.h>
145 #include <scsi/scsi_dbg.h>
146 #include <scsi/scsi_host.h>
147 #include <scsi/scsi_transport_spi.h>
148 #include "acornscsi.h"
149 #include "msgqueue.h"
152 #include <scsi/scsicam.h>
159 #define ABORT_TAG 0xd
161 #error "Yippee! ABORT TAG is now defined! Remove this error!"
164 #ifdef CONFIG_SCSI_ACORNSCSI_LINK
165 #error SCSI2 LINKed commands not supported (yet)!
170 * DMAC setup parameters
172 #define INIT_DEVCON0 (DEVCON0_RQL|DEVCON0_EXW|DEVCON0_CMP)
173 #define INIT_DEVCON1 (DEVCON1_BHLD)
174 #define DMAC_READ (MODECON_READ)
175 #define DMAC_WRITE (MODECON_WRITE)
176 #define INIT_SBICDMA (CTRL_DMABURST)
178 #define scsi_xferred have_data_in
181 * Size of on-board DMA buffer
183 #define DMAC_BUFFER_SIZE 65536
186 #define STATUS_BUFFER_TO_PRINT 24
188 unsigned int sdtr_period
= SDTR_PERIOD
;
189 unsigned int sdtr_size
= SDTR_SIZE
;
191 static void acornscsi_done(AS_Host
*host
, struct scsi_cmnd
**SCpntp
,
192 unsigned int result
);
193 static int acornscsi_reconnect_finish(AS_Host
*host
);
194 static void acornscsi_dma_cleanup(AS_Host
*host
);
195 static void acornscsi_abortcmd(AS_Host
*host
, unsigned char tag
);
197 /* ====================================================================================
201 /* Offsets from MEMC base */
202 #define SBIC_REGIDX 0x2000
203 #define SBIC_REGVAL 0x2004
204 #define DMAC_OFFSET 0x3000
206 /* Offsets from FAST IOC base */
207 #define INT_REG 0x2000
208 #define PAGE_REG 0x3000
210 static inline void sbic_arm_write(AS_Host
*host
, unsigned int reg
, unsigned int value
)
212 writeb(reg
, host
->base
+ SBIC_REGIDX
);
213 writeb(value
, host
->base
+ SBIC_REGVAL
);
216 static inline int sbic_arm_read(AS_Host
*host
, unsigned int reg
)
219 return readl(host
->base
+ SBIC_REGIDX
) & 255;
220 writeb(reg
, host
->base
+ SBIC_REGIDX
);
221 return readl(host
->base
+ SBIC_REGVAL
) & 255;
224 #define sbic_arm_writenext(host, val) writeb((val), (host)->base + SBIC_REGVAL)
225 #define sbic_arm_readnext(host) readb((host)->base + SBIC_REGVAL)
228 #define dmac_read(host,reg) \
229 readb((host)->base + DMAC_OFFSET + ((reg) << 2))
231 #define dmac_write(host,reg,value) \
232 ({ writeb((value), (host)->base + DMAC_OFFSET + ((reg) << 2)); })
234 #define dmac_clearintr(host) writeb(0, (host)->fast + INT_REG)
236 static inline unsigned int dmac_address(AS_Host
*host
)
238 return dmac_read(host
, DMAC_TXADRHI
) << 16 |
239 dmac_read(host
, DMAC_TXADRMD
) << 8 |
240 dmac_read(host
, DMAC_TXADRLO
);
244 void acornscsi_dumpdma(AS_Host
*host
, char *where
)
246 unsigned int mode
, addr
, len
;
248 mode
= dmac_read(host
, DMAC_MODECON
);
249 addr
= dmac_address(host
);
250 len
= dmac_read(host
, DMAC_TXCNTHI
) << 8 |
251 dmac_read(host
, DMAC_TXCNTLO
);
253 printk("scsi%d: %s: DMAC %02x @%06x+%04x msk %02x, ",
254 host
->host
->host_no
, where
,
255 mode
, addr
, (len
+ 1) & 0xffff,
256 dmac_read(host
, DMAC_MASKREG
));
258 printk("DMA @%06x, ", host
->dma
.start_addr
);
259 printk("BH @%p +%04x, ", host
->scsi
.SCp
.ptr
,
260 host
->scsi
.SCp
.this_residual
);
261 printk("DT @+%04x ST @+%04x", host
->dma
.transferred
,
262 host
->scsi
.SCp
.scsi_xferred
);
268 unsigned long acornscsi_sbic_xfcount(AS_Host
*host
)
270 unsigned long length
;
272 length
= sbic_arm_read(host
, SBIC_TRANSCNTH
) << 16;
273 length
|= sbic_arm_readnext(host
) << 8;
274 length
|= sbic_arm_readnext(host
);
280 acornscsi_sbic_wait(AS_Host
*host
, int stat_mask
, int stat
, int timeout
, char *msg
)
285 asr
= sbic_arm_read(host
, SBIC_ASR
);
287 if ((asr
& stat_mask
) == stat
)
293 printk("scsi%d: timeout while %s\n", host
->host
->host_no
, msg
);
299 int acornscsi_sbic_issuecmd(AS_Host
*host
, int command
)
301 if (acornscsi_sbic_wait(host
, ASR_CIP
, 0, 1000, "issuing command"))
304 sbic_arm_write(host
, SBIC_CMND
, command
);
310 acornscsi_csdelay(unsigned int cs
)
312 unsigned long target_jiffies
, flags
;
314 target_jiffies
= jiffies
+ 1 + cs
* HZ
/ 100;
316 local_save_flags(flags
);
319 while (time_before(jiffies
, target_jiffies
)) barrier();
321 local_irq_restore(flags
);
325 void acornscsi_resetcard(AS_Host
*host
)
327 unsigned int i
, timeout
;
329 /* assert reset line */
330 host
->card
.page_reg
= 0x80;
331 writeb(host
->card
.page_reg
, host
->fast
+ PAGE_REG
);
333 /* wait 3 cs. SCSI standard says 25ms. */
334 acornscsi_csdelay(3);
336 host
->card
.page_reg
= 0;
337 writeb(host
->card
.page_reg
, host
->fast
+ PAGE_REG
);
340 * Should get a reset from the card
344 if (readb(host
->fast
+ INT_REG
) & 8)
350 printk("scsi%d: timeout while resetting card\n",
351 host
->host
->host_no
);
353 sbic_arm_read(host
, SBIC_ASR
);
354 sbic_arm_read(host
, SBIC_SSR
);
356 /* setup sbic - WD33C93A */
357 sbic_arm_write(host
, SBIC_OWNID
, OWNID_EAF
| host
->host
->this_id
);
358 sbic_arm_write(host
, SBIC_CMND
, CMND_RESET
);
361 * Command should cause a reset interrupt
365 if (readb(host
->fast
+ INT_REG
) & 8)
371 printk("scsi%d: timeout while resetting card\n",
372 host
->host
->host_no
);
374 sbic_arm_read(host
, SBIC_ASR
);
375 if (sbic_arm_read(host
, SBIC_SSR
) != 0x01)
376 printk(KERN_CRIT
"scsi%d: WD33C93A didn't give enhanced reset interrupt\n",
377 host
->host
->host_no
);
379 sbic_arm_write(host
, SBIC_CTRL
, INIT_SBICDMA
| CTRL_IDI
);
380 sbic_arm_write(host
, SBIC_TIMEOUT
, TIMEOUT_TIME
);
381 sbic_arm_write(host
, SBIC_SYNCHTRANSFER
, SYNCHTRANSFER_2DBA
);
382 sbic_arm_write(host
, SBIC_SOURCEID
, SOURCEID_ER
| SOURCEID_DSP
);
384 host
->card
.page_reg
= 0x40;
385 writeb(host
->card
.page_reg
, host
->fast
+ PAGE_REG
);
387 /* setup dmac - uPC71071 */
388 dmac_write(host
, DMAC_INIT
, 0);
390 dmac_write(host
, DMAC_INIT
, INIT_8BIT
);
391 dmac_write(host
, DMAC_CHANNEL
, CHANNEL_0
);
392 dmac_write(host
, DMAC_DEVCON0
, INIT_DEVCON0
);
393 dmac_write(host
, DMAC_DEVCON1
, INIT_DEVCON1
);
397 host
->scsi
.phase
= PHASE_IDLE
;
398 host
->scsi
.disconnectable
= 0;
400 memset(host
->busyluns
, 0, sizeof(host
->busyluns
));
402 for (i
= 0; i
< 8; i
++) {
403 host
->device
[i
].sync_state
= SYNC_NEGOCIATE
;
404 host
->device
[i
].disconnect_ok
= 1;
407 /* wait 25 cs. SCSI standard says 250ms. */
408 acornscsi_csdelay(25);
411 /*=============================================================================================
412 * Utility routines (eg. debug)
414 #ifdef CONFIG_ACORNSCSI_CONSTANTS
415 static char *acornscsi_interrupttype
[] = {
416 "rst", "suc", "p/a", "3",
417 "term", "5", "6", "7",
418 "serv", "9", "a", "b",
422 static signed char acornscsi_map
[] = {
423 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
424 -1, 2, -1, -1, -1, -1, 3, -1, 4, 5, 6, 7, 8, 9, 10, 11,
425 12, 13, 14, -1, -1, -1, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11,
426 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
427 15, 16, 17, 18, 19, -1, -1, 20, 4, 5, 6, 7, 8, 9, 10, 11,
428 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
429 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
430 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
431 21, 22, -1, -1, -1, 23, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11,
432 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
433 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
434 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
435 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
436 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
437 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
438 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
441 static char *acornscsi_interruptcode
[] = {
443 "reset - normal mode", /* 00 */
444 "reset - advanced mode", /* 01 */
459 "/ACK asserted", /* 20 */
460 "save-data-ptr", /* 21 */
465 "unexpected disconnect", /* 41 */
466 "sel timeout", /* 42 */
468 "P err+ATN", /* 44 */
469 "bad status byte", /* 47 */
472 "resel, no id", /* 80 */
478 void print_scsi_status(unsigned int ssr
)
480 if (acornscsi_map
[ssr
] != -1)
482 acornscsi_interrupttype
[(ssr
>> 4)],
483 acornscsi_interruptcode
[acornscsi_map
[ssr
]]);
485 printk("%X:%X", ssr
>> 4, ssr
& 0x0f);
490 void print_sbic_status(int asr
, int ssr
, int cmdphase
)
492 #ifdef CONFIG_ACORNSCSI_CONSTANTS
493 printk("sbic: %c%c%c%c%c%c ",
494 asr
& ASR_INT
? 'I' : 'i',
495 asr
& ASR_LCI
? 'L' : 'l',
496 asr
& ASR_BSY
? 'B' : 'b',
497 asr
& ASR_CIP
? 'C' : 'c',
498 asr
& ASR_PE
? 'P' : 'p',
499 asr
& ASR_DBR
? 'D' : 'd');
501 print_scsi_status(ssr
);
502 printk(" ph %02X\n", cmdphase
);
504 printk("sbic: %02X scsi: %X:%X ph: %02X\n",
505 asr
, (ssr
& 0xf0)>>4, ssr
& 0x0f, cmdphase
);
510 acornscsi_dumplogline(AS_Host
*host
, int target
, int line
)
515 ptr
= host
->status_ptr
[target
] - STATUS_BUFFER_TO_PRINT
;
517 ptr
+= STATUS_BUFFER_SIZE
;
519 printk("%c: %3s:", target
== 8 ? 'H' : '0' + target
,
520 line
== 0 ? "ph" : line
== 1 ? "ssr" : "int");
522 prev
= host
->status
[target
][ptr
].when
;
524 for (; ptr
!= host
->status_ptr
[target
]; ptr
= (ptr
+ 1) & (STATUS_BUFFER_SIZE
- 1)) {
525 unsigned long time_diff
;
527 if (!host
->status
[target
][ptr
].when
)
532 printk("%c%02X", host
->status
[target
][ptr
].irq
? '-' : ' ',
533 host
->status
[target
][ptr
].ph
);
537 printk(" %02X", host
->status
[target
][ptr
].ssr
);
541 time_diff
= host
->status
[target
][ptr
].when
- prev
;
542 prev
= host
->status
[target
][ptr
].when
;
545 else if (time_diff
>= 100)
548 printk(" %02ld", time_diff
);
557 void acornscsi_dumplog(AS_Host
*host
, int target
)
560 acornscsi_dumplogline(host
, target
, 0);
561 acornscsi_dumplogline(host
, target
, 1);
562 acornscsi_dumplogline(host
, target
, 2);
572 char acornscsi_target(AS_Host
*host
)
575 return '0' + host
->SCpnt
->device
->id
;
580 * Prototype: cmdtype_t acornscsi_cmdtype(int command)
581 * Purpose : differentiate READ from WRITE from other commands
582 * Params : command - command to interpret
583 * Returns : CMD_READ - command reads data,
584 * CMD_WRITE - command writes data,
585 * CMD_MISC - everything else
588 cmdtype_t
acornscsi_cmdtype(int command
)
591 case WRITE_6
: case WRITE_10
: case WRITE_12
:
593 case READ_6
: case READ_10
: case READ_12
:
601 * Prototype: int acornscsi_datadirection(int command)
602 * Purpose : differentiate between commands that have a DATA IN phase
603 * and a DATA OUT phase
604 * Params : command - command to interpret
605 * Returns : DATADIR_OUT - data out phase expected
606 * DATADIR_IN - data in phase expected
609 datadir_t
acornscsi_datadirection(int command
)
612 case CHANGE_DEFINITION
: case COMPARE
: case COPY
:
613 case COPY_VERIFY
: case LOG_SELECT
: case MODE_SELECT
:
614 case MODE_SELECT_10
: case SEND_DIAGNOSTIC
: case WRITE_BUFFER
:
615 case FORMAT_UNIT
: case REASSIGN_BLOCKS
: case RESERVE
:
616 case SEARCH_EQUAL
: case SEARCH_HIGH
: case SEARCH_LOW
:
617 case WRITE_6
: case WRITE_10
: case WRITE_VERIFY
:
618 case UPDATE_BLOCK
: case WRITE_LONG
: case WRITE_SAME
:
619 case SEARCH_HIGH_12
: case SEARCH_EQUAL_12
: case SEARCH_LOW_12
:
620 case WRITE_12
: case WRITE_VERIFY_12
: case SET_WINDOW
:
621 case MEDIUM_SCAN
: case SEND_VOLUME_TAG
: case 0xea:
629 * Purpose : provide values for synchronous transfers with 33C93.
630 * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
631 * Modified by Russell King for 8MHz WD33C93A
633 static struct sync_xfer_tbl
{
634 unsigned int period_ns
;
635 unsigned char reg_value
;
636 } sync_xfer_table
[] = {
637 { 1, 0x20 }, { 249, 0x20 }, { 374, 0x30 },
638 { 499, 0x40 }, { 624, 0x50 }, { 749, 0x60 },
639 { 874, 0x70 }, { 999, 0x00 }, { 0, 0 }
643 * Prototype: int acornscsi_getperiod(unsigned char syncxfer)
644 * Purpose : period for the synchronous transfer setting
645 * Params : syncxfer SYNCXFER register value
646 * Returns : period in ns.
649 int acornscsi_getperiod(unsigned char syncxfer
)
654 if (syncxfer
== 0x10)
657 for (i
= 1; sync_xfer_table
[i
].period_ns
; i
++)
658 if (syncxfer
== sync_xfer_table
[i
].reg_value
)
659 return sync_xfer_table
[i
].period_ns
;
664 * Prototype: int round_period(unsigned int period)
665 * Purpose : return index into above table for a required REQ period
666 * Params : period - time (ns) for REQ
667 * Returns : table index
668 * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
671 int round_period(unsigned int period
)
675 for (i
= 1; sync_xfer_table
[i
].period_ns
; i
++) {
676 if ((period
<= sync_xfer_table
[i
].period_ns
) &&
677 (period
> sync_xfer_table
[i
- 1].period_ns
))
684 * Prototype: unsigned char calc_sync_xfer(unsigned int period, unsigned int offset)
685 * Purpose : calculate value for 33c93s SYNC register
686 * Params : period - time (ns) for REQ
687 * offset - offset in bytes between REQ/ACK
688 * Returns : value for SYNC register
689 * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
692 unsigned char calc_sync_xfer(unsigned int period
, unsigned int offset
)
694 return sync_xfer_table
[round_period(period
)].reg_value
|
695 ((offset
< SDTR_SIZE
) ? offset
: SDTR_SIZE
);
698 /* ====================================================================================
702 * Function: acornscsi_kick(AS_Host *host)
703 * Purpose : kick next command to interface
704 * Params : host - host to send command to
705 * Returns : INTR_IDLE if idle, otherwise INTR_PROCESSING
706 * Notes : interrupts are always disabled!
709 intr_ret_t
acornscsi_kick(AS_Host
*host
)
712 struct scsi_cmnd
*SCpnt
;
714 /* first check to see if a command is waiting to be executed */
715 SCpnt
= host
->origSCpnt
;
716 host
->origSCpnt
= NULL
;
718 /* retrieve next command */
720 SCpnt
= queue_remove_exclude(&host
->queues
.issue
, host
->busyluns
);
727 if (host
->scsi
.disconnectable
&& host
->SCpnt
) {
728 queue_add_cmd_tail(&host
->queues
.disconnected
, host
->SCpnt
);
729 host
->scsi
.disconnectable
= 0;
730 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
731 DBG(host
->SCpnt
, printk("scsi%d.%c: moved command to disconnected queue\n",
732 host
->host
->host_no
, acornscsi_target(host
)));
738 * If we have an interrupt pending, then we may have been reselected.
739 * In this case, we don't want to write to the registers
741 if (!(sbic_arm_read(host
, SBIC_ASR
) & (ASR_INT
|ASR_BSY
|ASR_CIP
))) {
742 sbic_arm_write(host
, SBIC_DESTID
, SCpnt
->device
->id
);
743 sbic_arm_write(host
, SBIC_CMND
, CMND_SELWITHATN
);
747 * claim host busy - all of these must happen atomically wrt
748 * our interrupt routine. Failure means command loss.
750 host
->scsi
.phase
= PHASE_CONNECTING
;
752 host
->scsi
.SCp
= SCpnt
->SCp
;
753 host
->dma
.xfer_setup
= 0;
754 host
->dma
.xfer_required
= 0;
755 host
->dma
.xfer_done
= 0;
757 #if (DEBUG & (DEBUG_ABORT|DEBUG_CONNECT))
758 DBG(SCpnt
,printk("scsi%d.%c: starting cmd %02X\n",
759 host
->host
->host_no
, '0' + SCpnt
->device
->id
,
764 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
766 * tagged queueing - allocate a new tag to this command
768 if (SCpnt
->device
->simple_tags
) {
769 SCpnt
->device
->current_tag
+= 1;
770 if (SCpnt
->device
->current_tag
== 0)
771 SCpnt
->device
->current_tag
= 1;
772 SCpnt
->tag
= SCpnt
->device
->current_tag
;
775 set_bit(SCpnt
->device
->id
* 8 + SCpnt
->device
->lun
, host
->busyluns
);
777 host
->stats
.removes
+= 1;
779 switch (acornscsi_cmdtype(SCpnt
->cmnd
[0])) {
781 host
->stats
.writes
+= 1;
784 host
->stats
.reads
+= 1;
787 host
->stats
.miscs
+= 1;
792 return INTR_PROCESSING
;
796 * Function: void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp, unsigned int result)
797 * Purpose : complete processing for command
798 * Params : host - interface that completed
799 * result - driver byte of result
801 static void acornscsi_done(AS_Host
*host
, struct scsi_cmnd
**SCpntp
,
804 struct scsi_cmnd
*SCpnt
= *SCpntp
;
807 sbic_arm_write(host
, SBIC_SOURCEID
, SOURCEID_ER
| SOURCEID_DSP
);
809 host
->stats
.fins
+= 1;
814 acornscsi_dma_cleanup(host
);
816 SCpnt
->result
= result
<< 16 | host
->scsi
.SCp
.Message
<< 8 | host
->scsi
.SCp
.Status
;
819 * In theory, this should not happen. In practice, it seems to.
820 * Only trigger an error if the device attempts to report all happy
821 * but with untransferred buffers... If we don't do something, then
822 * data loss will occur. Should we check SCpnt->underflow here?
823 * It doesn't appear to be set to something meaningful by the higher
824 * levels all the time.
826 if (result
== DID_OK
) {
829 if (SCpnt
->underflow
== 0) {
830 if (host
->scsi
.SCp
.ptr
&&
831 acornscsi_cmdtype(SCpnt
->cmnd
[0]) != CMD_MISC
)
834 if (host
->scsi
.SCp
.scsi_xferred
< SCpnt
->underflow
||
835 host
->scsi
.SCp
.scsi_xferred
!= host
->dma
.transferred
)
839 /* ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.6)
840 * Targets which break data transfers into multiple
841 * connections shall end each successful connection
842 * (except possibly the last) with a SAVE DATA
843 * POINTER - DISCONNECT message sequence.
845 * This makes it difficult to ensure that a transfer has
846 * completed. If we reach the end of a transfer during
847 * the command, then we can only have finished the transfer.
848 * therefore, if we seem to have some data remaining, this
851 if (host
->dma
.xfer_done
)
855 switch (status_byte(SCpnt
->result
)) {
856 case CHECK_CONDITION
:
857 case COMMAND_TERMINATED
:
860 case RESERVATION_CONFLICT
:
864 printk(KERN_ERR
"scsi%d.H: incomplete data transfer detected: result=%08X command=",
865 host
->host
->host_no
, SCpnt
->result
);
866 __scsi_print_command(SCpnt
->cmnd
);
867 acornscsi_dumpdma(host
, "done");
868 acornscsi_dumplog(host
, SCpnt
->device
->id
);
869 SCpnt
->result
&= 0xffff;
870 SCpnt
->result
|= DID_ERROR
<< 16;
875 if (!SCpnt
->scsi_done
)
876 panic("scsi%d.H: null scsi_done function in acornscsi_done", host
->host
->host_no
);
878 clear_bit(SCpnt
->device
->id
* 8 + SCpnt
->device
->lun
, host
->busyluns
);
880 SCpnt
->scsi_done(SCpnt
);
882 printk("scsi%d: null command in acornscsi_done", host
->host
->host_no
);
884 host
->scsi
.phase
= PHASE_IDLE
;
887 /* ====================================================================================
891 * Purpose : update SCSI Data Pointer
892 * Notes : this will only be one SG entry or less
895 void acornscsi_data_updateptr(AS_Host
*host
, struct scsi_pointer
*SCp
, unsigned int length
)
898 SCp
->this_residual
-= length
;
900 if (SCp
->this_residual
== 0 && next_SCp(SCp
) == 0)
901 host
->dma
.xfer_done
= 1;
905 * Prototype: void acornscsi_data_read(AS_Host *host, char *ptr,
906 * unsigned int start_addr, unsigned int length)
907 * Purpose : read data from DMA RAM
908 * Params : host - host to transfer from
910 * start_addr - host mem address
911 * length - number of bytes to transfer
912 * Notes : this will only be one SG entry or less
915 void acornscsi_data_read(AS_Host
*host
, char *ptr
,
916 unsigned int start_addr
, unsigned int length
)
918 extern void __acornscsi_in(void __iomem
*, char *buf
, int len
);
919 unsigned int page
, offset
, len
= length
;
921 page
= (start_addr
>> 12);
922 offset
= start_addr
& ((1 << 12) - 1);
924 writeb((page
& 0x3f) | host
->card
.page_reg
, host
->fast
+ PAGE_REG
);
927 unsigned int this_len
;
929 if (len
+ offset
> (1 << 12))
930 this_len
= (1 << 12) - offset
;
934 __acornscsi_in(host
->base
+ (offset
<< 1), ptr
, this_len
);
940 if (offset
== (1 << 12)) {
943 writeb((page
& 0x3f) | host
->card
.page_reg
, host
->fast
+ PAGE_REG
);
946 writeb(host
->card
.page_reg
, host
->fast
+ PAGE_REG
);
950 * Prototype: void acornscsi_data_write(AS_Host *host, char *ptr,
951 * unsigned int start_addr, unsigned int length)
952 * Purpose : write data to DMA RAM
953 * Params : host - host to transfer from
955 * start_addr - host mem address
956 * length - number of bytes to transfer
957 * Notes : this will only be one SG entry or less
960 void acornscsi_data_write(AS_Host
*host
, char *ptr
,
961 unsigned int start_addr
, unsigned int length
)
963 extern void __acornscsi_out(void __iomem
*, char *buf
, int len
);
964 unsigned int page
, offset
, len
= length
;
966 page
= (start_addr
>> 12);
967 offset
= start_addr
& ((1 << 12) - 1);
969 writeb((page
& 0x3f) | host
->card
.page_reg
, host
->fast
+ PAGE_REG
);
972 unsigned int this_len
;
974 if (len
+ offset
> (1 << 12))
975 this_len
= (1 << 12) - offset
;
979 __acornscsi_out(host
->base
+ (offset
<< 1), ptr
, this_len
);
985 if (offset
== (1 << 12)) {
988 writeb((page
& 0x3f) | host
->card
.page_reg
, host
->fast
+ PAGE_REG
);
991 writeb(host
->card
.page_reg
, host
->fast
+ PAGE_REG
);
994 /* =========================================================================================
995 * On-board DMA routines
999 * Prototype: void acornscsi_dmastop(AS_Host *host)
1000 * Purpose : stop all DMA
1001 * Params : host - host on which to stop DMA
1002 * Notes : This is called when leaving DATA IN/OUT phase,
1003 * or when interface is RESET
1006 void acornscsi_dma_stop(AS_Host
*host
)
1008 dmac_write(host
, DMAC_MASKREG
, MASK_ON
);
1009 dmac_clearintr(host
);
1011 #if (DEBUG & DEBUG_DMA)
1012 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "stop"));
1017 * Function: void acornscsi_dma_setup(AS_Host *host, dmadir_t direction)
1018 * Purpose : setup DMA controller for data transfer
1019 * Params : host - host to setup
1020 * direction - data transfer direction
1021 * Notes : This is called when entering DATA I/O phase, not
1022 * while we're in a DATA I/O phase
1025 void acornscsi_dma_setup(AS_Host
*host
, dmadir_t direction
)
1027 unsigned int address
, length
, mode
;
1029 host
->dma
.direction
= direction
;
1031 dmac_write(host
, DMAC_MASKREG
, MASK_ON
);
1033 if (direction
== DMA_OUT
) {
1034 #if (DEBUG & DEBUG_NO_WRITE)
1035 if (NO_WRITE
& (1 << host
->SCpnt
->device
->id
)) {
1036 printk(KERN_CRIT
"scsi%d.%c: I can't handle DMA_OUT!\n",
1037 host
->host
->host_no
, acornscsi_target(host
));
1046 * Allocate some buffer space, limited to half the buffer size
1048 length
= min_t(unsigned int, host
->scsi
.SCp
.this_residual
, DMAC_BUFFER_SIZE
/ 2);
1050 host
->dma
.start_addr
= address
= host
->dma
.free_addr
;
1051 host
->dma
.free_addr
= (host
->dma
.free_addr
+ length
) &
1052 (DMAC_BUFFER_SIZE
- 1);
1055 * Transfer data to DMA memory
1057 if (direction
== DMA_OUT
)
1058 acornscsi_data_write(host
, host
->scsi
.SCp
.ptr
, host
->dma
.start_addr
,
1062 dmac_write(host
, DMAC_TXCNTLO
, length
);
1063 dmac_write(host
, DMAC_TXCNTHI
, length
>> 8);
1064 dmac_write(host
, DMAC_TXADRLO
, address
);
1065 dmac_write(host
, DMAC_TXADRMD
, address
>> 8);
1066 dmac_write(host
, DMAC_TXADRHI
, 0);
1067 dmac_write(host
, DMAC_MODECON
, mode
);
1068 dmac_write(host
, DMAC_MASKREG
, MASK_OFF
);
1070 #if (DEBUG & DEBUG_DMA)
1071 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "strt"));
1073 host
->dma
.xfer_setup
= 1;
1078 * Function: void acornscsi_dma_cleanup(AS_Host *host)
1079 * Purpose : ensure that all DMA transfers are up-to-date & host->scsi.SCp is correct
1080 * Params : host - host to finish
1081 * Notes : This is called when a command is:
1082 * terminating, RESTORE_POINTERS, SAVE_POINTERS, DISCONECT
1083 * : This must not return until all transfers are completed.
1086 void acornscsi_dma_cleanup(AS_Host
*host
)
1088 dmac_write(host
, DMAC_MASKREG
, MASK_ON
);
1089 dmac_clearintr(host
);
1092 * Check for a pending transfer
1094 if (host
->dma
.xfer_required
) {
1095 host
->dma
.xfer_required
= 0;
1096 if (host
->dma
.direction
== DMA_IN
)
1097 acornscsi_data_read(host
, host
->dma
.xfer_ptr
,
1098 host
->dma
.xfer_start
, host
->dma
.xfer_length
);
1102 * Has a transfer been setup?
1104 if (host
->dma
.xfer_setup
) {
1105 unsigned int transferred
;
1107 host
->dma
.xfer_setup
= 0;
1109 #if (DEBUG & DEBUG_DMA)
1110 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "cupi"));
1114 * Calculate number of bytes transferred from DMA.
1116 transferred
= dmac_address(host
) - host
->dma
.start_addr
;
1117 host
->dma
.transferred
+= transferred
;
1119 if (host
->dma
.direction
== DMA_IN
)
1120 acornscsi_data_read(host
, host
->scsi
.SCp
.ptr
,
1121 host
->dma
.start_addr
, transferred
);
1124 * Update SCSI pointers
1126 acornscsi_data_updateptr(host
, &host
->scsi
.SCp
, transferred
);
1127 #if (DEBUG & DEBUG_DMA)
1128 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "cupo"));
1134 * Function: void acornscsi_dmacintr(AS_Host *host)
1135 * Purpose : handle interrupts from DMAC device
1136 * Params : host - host to process
1137 * Notes : If reading, we schedule the read to main memory &
1138 * allow the transfer to continue.
1139 * : If writing, we fill the onboard DMA memory from main
1141 * : Called whenever DMAC finished it's current transfer.
1144 void acornscsi_dma_intr(AS_Host
*host
)
1146 unsigned int address
, length
, transferred
;
1148 #if (DEBUG & DEBUG_DMA)
1149 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "inti"));
1152 dmac_write(host
, DMAC_MASKREG
, MASK_ON
);
1153 dmac_clearintr(host
);
1156 * Calculate amount transferred via DMA
1158 transferred
= dmac_address(host
) - host
->dma
.start_addr
;
1159 host
->dma
.transferred
+= transferred
;
1162 * Schedule DMA transfer off board
1164 if (host
->dma
.direction
== DMA_IN
) {
1165 host
->dma
.xfer_start
= host
->dma
.start_addr
;
1166 host
->dma
.xfer_length
= transferred
;
1167 host
->dma
.xfer_ptr
= host
->scsi
.SCp
.ptr
;
1168 host
->dma
.xfer_required
= 1;
1171 acornscsi_data_updateptr(host
, &host
->scsi
.SCp
, transferred
);
1174 * Allocate some buffer space, limited to half the on-board RAM size
1176 length
= min_t(unsigned int, host
->scsi
.SCp
.this_residual
, DMAC_BUFFER_SIZE
/ 2);
1178 host
->dma
.start_addr
= address
= host
->dma
.free_addr
;
1179 host
->dma
.free_addr
= (host
->dma
.free_addr
+ length
) &
1180 (DMAC_BUFFER_SIZE
- 1);
1183 * Transfer data to DMA memory
1185 if (host
->dma
.direction
== DMA_OUT
)
1186 acornscsi_data_write(host
, host
->scsi
.SCp
.ptr
, host
->dma
.start_addr
,
1190 dmac_write(host
, DMAC_TXCNTLO
, length
);
1191 dmac_write(host
, DMAC_TXCNTHI
, length
>> 8);
1192 dmac_write(host
, DMAC_TXADRLO
, address
);
1193 dmac_write(host
, DMAC_TXADRMD
, address
>> 8);
1194 dmac_write(host
, DMAC_TXADRHI
, 0);
1195 dmac_write(host
, DMAC_MASKREG
, MASK_OFF
);
1197 #if (DEBUG & DEBUG_DMA)
1198 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "into"));
1201 host
->dma
.xfer_setup
= 0;
1206 * Function: void acornscsi_dma_xfer(AS_Host *host)
1207 * Purpose : transfer data between AcornSCSI and memory
1208 * Params : host - host to process
1211 void acornscsi_dma_xfer(AS_Host
*host
)
1213 host
->dma
.xfer_required
= 0;
1215 if (host
->dma
.direction
== DMA_IN
)
1216 acornscsi_data_read(host
, host
->dma
.xfer_ptr
,
1217 host
->dma
.xfer_start
, host
->dma
.xfer_length
);
1221 * Function: void acornscsi_dma_adjust(AS_Host *host)
1222 * Purpose : adjust DMA pointers & count for bytes transferred to
1223 * SBIC but not SCSI bus.
1224 * Params : host - host to adjust DMA count for
1227 void acornscsi_dma_adjust(AS_Host
*host
)
1229 if (host
->dma
.xfer_setup
) {
1230 signed long transferred
;
1231 #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
1232 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "adji"));
1235 * Calculate correct DMA address - DMA is ahead of SCSI bus while
1237 * host->scsi.SCp.scsi_xferred is the number of bytes
1238 * actually transferred to/from the SCSI bus.
1239 * host->dma.transferred is the number of bytes transferred
1240 * over DMA since host->dma.start_addr was last set.
1242 * real_dma_addr = host->dma.start_addr + host->scsi.SCp.scsi_xferred
1243 * - host->dma.transferred
1245 transferred
= host
->scsi
.SCp
.scsi_xferred
- host
->dma
.transferred
;
1246 if (transferred
< 0)
1247 printk("scsi%d.%c: Ack! DMA write correction %ld < 0!\n",
1248 host
->host
->host_no
, acornscsi_target(host
), transferred
);
1249 else if (transferred
== 0)
1250 host
->dma
.xfer_setup
= 0;
1252 transferred
+= host
->dma
.start_addr
;
1253 dmac_write(host
, DMAC_TXADRLO
, transferred
);
1254 dmac_write(host
, DMAC_TXADRMD
, transferred
>> 8);
1255 dmac_write(host
, DMAC_TXADRHI
, transferred
>> 16);
1256 #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
1257 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "adjo"));
1264 /* =========================================================================================
1268 acornscsi_write_pio(AS_Host
*host
, char *bytes
, int *ptr
, int len
, unsigned int max_timeout
)
1270 unsigned int asr
, timeout
= max_timeout
;
1273 while (my_ptr
< len
) {
1274 asr
= sbic_arm_read(host
, SBIC_ASR
);
1276 if (asr
& ASR_DBR
) {
1277 timeout
= max_timeout
;
1279 sbic_arm_write(host
, SBIC_DATA
, bytes
[my_ptr
++]);
1280 } else if (asr
& ASR_INT
)
1282 else if (--timeout
== 0)
1289 return (timeout
== 0) ? -1 : 0;
1293 * Function: void acornscsi_sendcommand(AS_Host *host)
1294 * Purpose : send a command to a target
1295 * Params : host - host which is connected to target
1298 acornscsi_sendcommand(AS_Host
*host
)
1300 struct scsi_cmnd
*SCpnt
= host
->SCpnt
;
1302 sbic_arm_write(host
, SBIC_TRANSCNTH
, 0);
1303 sbic_arm_writenext(host
, 0);
1304 sbic_arm_writenext(host
, SCpnt
->cmd_len
- host
->scsi
.SCp
.sent_command
);
1306 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
);
1308 if (acornscsi_write_pio(host
, SCpnt
->cmnd
,
1309 (int *)&host
->scsi
.SCp
.sent_command
, SCpnt
->cmd_len
, 1000000))
1310 printk("scsi%d: timeout while sending command\n", host
->host
->host_no
);
1312 host
->scsi
.phase
= PHASE_COMMAND
;
1316 void acornscsi_sendmessage(AS_Host
*host
)
1318 unsigned int message_length
= msgqueue_msglength(&host
->scsi
.msgs
);
1320 struct message
*msg
;
1322 #if (DEBUG & DEBUG_MESSAGES)
1323 printk("scsi%d.%c: sending message ",
1324 host
->host
->host_no
, acornscsi_target(host
));
1327 switch (message_length
) {
1329 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
| CMND_SBT
);
1331 acornscsi_sbic_wait(host
, ASR_DBR
, ASR_DBR
, 1000, "sending message 1");
1333 sbic_arm_write(host
, SBIC_DATA
, NOP
);
1335 host
->scsi
.last_message
= NOP
;
1336 #if (DEBUG & DEBUG_MESSAGES)
1342 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
| CMND_SBT
);
1343 msg
= msgqueue_getmsg(&host
->scsi
.msgs
, 0);
1345 acornscsi_sbic_wait(host
, ASR_DBR
, ASR_DBR
, 1000, "sending message 2");
1347 sbic_arm_write(host
, SBIC_DATA
, msg
->msg
[0]);
1349 host
->scsi
.last_message
= msg
->msg
[0];
1350 #if (DEBUG & DEBUG_MESSAGES)
1351 spi_print_msg(msg
->msg
);
1357 * ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.14)
1358 * 'When a target sends this (MESSAGE_REJECT) message, it
1359 * shall change to MESSAGE IN phase and send this message
1360 * prior to requesting additional message bytes from the
1361 * initiator. This provides an interlock so that the
1362 * initiator can determine which message byte is rejected.
1364 sbic_arm_write(host
, SBIC_TRANSCNTH
, 0);
1365 sbic_arm_writenext(host
, 0);
1366 sbic_arm_writenext(host
, message_length
);
1367 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
);
1370 while ((msg
= msgqueue_getmsg(&host
->scsi
.msgs
, msgnr
++)) != NULL
) {
1372 #if (DEBUG & DEBUG_MESSAGES)
1376 if (acornscsi_write_pio(host
, msg
->msg
, &i
, msg
->length
, 1000000))
1377 printk("scsi%d: timeout while sending message\n", host
->host
->host_no
);
1379 host
->scsi
.last_message
= msg
->msg
[0];
1380 if (msg
->msg
[0] == EXTENDED_MESSAGE
)
1381 host
->scsi
.last_message
|= msg
->msg
[2] << 8;
1383 if (i
!= msg
->length
)
1388 #if (DEBUG & DEBUG_MESSAGES)
1394 * Function: void acornscsi_readstatusbyte(AS_Host *host)
1395 * Purpose : Read status byte from connected target
1396 * Params : host - host connected to target
1399 void acornscsi_readstatusbyte(AS_Host
*host
)
1401 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
|CMND_SBT
);
1402 acornscsi_sbic_wait(host
, ASR_DBR
, ASR_DBR
, 1000, "reading status byte");
1403 host
->scsi
.SCp
.Status
= sbic_arm_read(host
, SBIC_DATA
);
1407 * Function: unsigned char acornscsi_readmessagebyte(AS_Host *host)
1408 * Purpose : Read one message byte from connected target
1409 * Params : host - host connected to target
1412 unsigned char acornscsi_readmessagebyte(AS_Host
*host
)
1414 unsigned char message
;
1416 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
| CMND_SBT
);
1418 acornscsi_sbic_wait(host
, ASR_DBR
, ASR_DBR
, 1000, "for message byte");
1420 message
= sbic_arm_read(host
, SBIC_DATA
);
1422 /* wait for MSGIN-XFER-PAUSED */
1423 acornscsi_sbic_wait(host
, ASR_INT
, ASR_INT
, 1000, "for interrupt after message byte");
1425 sbic_arm_read(host
, SBIC_SSR
);
1431 * Function: void acornscsi_message(AS_Host *host)
1432 * Purpose : Read complete message from connected target & action message
1433 * Params : host - host connected to target
1436 void acornscsi_message(AS_Host
*host
)
1438 unsigned char message
[16];
1439 unsigned int msgidx
= 0, msglen
= 1;
1442 message
[msgidx
] = acornscsi_readmessagebyte(host
);
1446 if (message
[0] == EXTENDED_MESSAGE
||
1447 (message
[0] >= 0x20 && message
[0] <= 0x2f))
1452 if (message
[0] == EXTENDED_MESSAGE
)
1453 msglen
+= message
[msgidx
];
1457 if (msgidx
< msglen
) {
1458 acornscsi_sbic_issuecmd(host
, CMND_NEGATEACK
);
1460 /* wait for next msg-in */
1461 acornscsi_sbic_wait(host
, ASR_INT
, ASR_INT
, 1000, "for interrupt after negate ack");
1462 sbic_arm_read(host
, SBIC_SSR
);
1464 } while (msgidx
< msglen
);
1466 #if (DEBUG & DEBUG_MESSAGES)
1467 printk("scsi%d.%c: message in: ",
1468 host
->host
->host_no
, acornscsi_target(host
));
1469 spi_print_msg(message
);
1473 if (host
->scsi
.phase
== PHASE_RECONNECTED
) {
1475 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
1476 * 'Whenever a target reconnects to an initiator to continue
1477 * a tagged I/O process, the SIMPLE QUEUE TAG message shall
1478 * be sent immediately following the IDENTIFY message...'
1480 if (message
[0] == SIMPLE_QUEUE_TAG
)
1481 host
->scsi
.reconnected
.tag
= message
[1];
1482 if (acornscsi_reconnect_finish(host
))
1483 host
->scsi
.phase
= PHASE_MSGIN
;
1486 switch (message
[0]) {
1489 case COMMAND_COMPLETE
:
1490 if (host
->scsi
.phase
!= PHASE_STATUSIN
) {
1491 printk(KERN_ERR
"scsi%d.%c: command complete following non-status in phase?\n",
1492 host
->host
->host_no
, acornscsi_target(host
));
1493 acornscsi_dumplog(host
, host
->SCpnt
->device
->id
);
1495 host
->scsi
.phase
= PHASE_DONE
;
1496 host
->scsi
.SCp
.Message
= message
[0];
1501 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.20)
1502 * 'The SAVE DATA POINTER message is sent from a target to
1503 * direct the initiator to copy the active data pointer to
1504 * the saved data pointer for the current I/O process.
1506 acornscsi_dma_cleanup(host
);
1507 host
->SCpnt
->SCp
= host
->scsi
.SCp
;
1508 host
->SCpnt
->SCp
.sent_command
= 0;
1509 host
->scsi
.phase
= PHASE_MSGIN
;
1512 case RESTORE_POINTERS
:
1514 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.19)
1515 * 'The RESTORE POINTERS message is sent from a target to
1516 * direct the initiator to copy the most recently saved
1517 * command, data, and status pointers for the I/O process
1518 * to the corresponding active pointers. The command and
1519 * status pointers shall be restored to the beginning of
1520 * the present command and status areas.'
1522 acornscsi_dma_cleanup(host
);
1523 host
->scsi
.SCp
= host
->SCpnt
->SCp
;
1524 host
->scsi
.phase
= PHASE_MSGIN
;
1529 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 6.4.2)
1530 * 'On those occasions when an error or exception condition occurs
1531 * and the target elects to repeat the information transfer, the
1532 * target may repeat the transfer either issuing a RESTORE POINTERS
1533 * message or by disconnecting without issuing a SAVE POINTERS
1534 * message. When reconnection is completed, the most recent
1535 * saved pointer values are restored.'
1537 acornscsi_dma_cleanup(host
);
1538 host
->scsi
.phase
= PHASE_DISCONNECT
;
1541 case MESSAGE_REJECT
:
1544 * If we have any messages waiting to go out, then assert ATN now
1546 if (msgqueue_msglength(&host
->scsi
.msgs
))
1547 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1549 switch (host
->scsi
.last_message
) {
1550 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
1551 case HEAD_OF_QUEUE_TAG
:
1552 case ORDERED_QUEUE_TAG
:
1553 case SIMPLE_QUEUE_TAG
:
1555 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
1556 * If a target does not implement tagged queuing and a queue tag
1557 * message is received, it shall respond with a MESSAGE REJECT
1558 * message and accept the I/O process as if it were untagged.
1560 printk(KERN_NOTICE
"scsi%d.%c: disabling tagged queueing\n",
1561 host
->host
->host_no
, acornscsi_target(host
));
1562 host
->SCpnt
->device
->simple_tags
= 0;
1563 set_bit(host
->SCpnt
->device
->id
* 8 + host
->SCpnt
->device
->lun
, host
->busyluns
);
1566 case EXTENDED_MESSAGE
| (EXTENDED_SDTR
<< 8):
1568 * Target can't handle synchronous transfers
1570 printk(KERN_NOTICE
"scsi%d.%c: Using asynchronous transfer\n",
1571 host
->host
->host_no
, acornscsi_target(host
));
1572 host
->device
[host
->SCpnt
->device
->id
].sync_xfer
= SYNCHTRANSFER_2DBA
;
1573 host
->device
[host
->SCpnt
->device
->id
].sync_state
= SYNC_ASYNCHRONOUS
;
1574 sbic_arm_write(host
, SBIC_SYNCHTRANSFER
, host
->device
[host
->SCpnt
->device
->id
].sync_xfer
);
1583 /* TODO: target queue is full */
1586 case SIMPLE_QUEUE_TAG
:
1587 /* tag queue reconnect... message[1] = queue tag. Print something to indicate something happened! */
1588 printk("scsi%d.%c: reconnect queue tag %02X\n",
1589 host
->host
->host_no
, acornscsi_target(host
),
1593 case EXTENDED_MESSAGE
:
1594 switch (message
[2]) {
1595 #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
1597 if (host
->device
[host
->SCpnt
->device
->id
].sync_state
== SYNC_SENT_REQUEST
) {
1599 * We requested synchronous transfers. This isn't quite right...
1600 * We can only say if this succeeded if we proceed on to execute the
1601 * command from this message. If we get a MESSAGE PARITY ERROR,
1602 * and the target retries fail, then we fallback to asynchronous mode
1604 host
->device
[host
->SCpnt
->device
->id
].sync_state
= SYNC_COMPLETED
;
1605 printk(KERN_NOTICE
"scsi%d.%c: Using synchronous transfer, offset %d, %d ns\n",
1606 host
->host
->host_no
, acornscsi_target(host
),
1607 message
[4], message
[3] * 4);
1608 host
->device
[host
->SCpnt
->device
->id
].sync_xfer
=
1609 calc_sync_xfer(message
[3] * 4, message
[4]);
1611 unsigned char period
, length
;
1613 * Target requested synchronous transfers. The agreement is only
1614 * to be in operation AFTER the target leaves message out phase.
1616 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1617 period
= max_t(unsigned int, message
[3], sdtr_period
/ 4);
1618 length
= min_t(unsigned int, message
[4], sdtr_size
);
1619 msgqueue_addmsg(&host
->scsi
.msgs
, 5, EXTENDED_MESSAGE
, 3,
1620 EXTENDED_SDTR
, period
, length
);
1621 host
->device
[host
->SCpnt
->device
->id
].sync_xfer
=
1622 calc_sync_xfer(period
* 4, length
);
1624 sbic_arm_write(host
, SBIC_SYNCHTRANSFER
, host
->device
[host
->SCpnt
->device
->id
].sync_xfer
);
1627 /* We do not accept synchronous transfers. Respond with a
1633 /* The WD33C93A is only 8-bit. We respond with a MESSAGE_REJECT
1634 * to a wide data transfer request.
1637 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1638 msgqueue_flush(&host
->scsi
.msgs
);
1639 msgqueue_addmsg(&host
->scsi
.msgs
, 1, MESSAGE_REJECT
);
1644 #ifdef CONFIG_SCSI_ACORNSCSI_LINK
1645 case LINKED_CMD_COMPLETE
:
1646 case LINKED_FLG_CMD_COMPLETE
:
1648 * We don't support linked commands yet
1651 #if (DEBUG & DEBUG_LINK)
1652 printk("scsi%d.%c: lun %d tag %d linked command complete\n",
1653 host
->host
->host_no
, acornscsi_target(host
), host
->SCpnt
->tag
);
1656 * A linked command should only terminate with one of these messages
1657 * if there are more linked commands available.
1659 if (!host
->SCpnt
->next_link
) {
1660 printk(KERN_WARNING
"scsi%d.%c: lun %d tag %d linked command complete, but no next_link\n",
1661 instance
->host_no
, acornscsi_target(host
), host
->SCpnt
->tag
);
1662 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1663 msgqueue_addmsg(&host
->scsi
.msgs
, 1, ABORT
);
1665 struct scsi_cmnd
*SCpnt
= host
->SCpnt
;
1667 acornscsi_dma_cleanup(host
);
1669 host
->SCpnt
= host
->SCpnt
->next_link
;
1670 host
->SCpnt
->tag
= SCpnt
->tag
;
1671 SCpnt
->result
= DID_OK
| host
->scsi
.SCp
.Message
<< 8 | host
->Scsi
.SCp
.Status
;
1674 /* initialise host->SCpnt->SCp */
1680 default: /* reject message */
1681 printk(KERN_ERR
"scsi%d.%c: unrecognised message %02X, rejecting\n",
1682 host
->host
->host_no
, acornscsi_target(host
),
1684 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1685 msgqueue_flush(&host
->scsi
.msgs
);
1686 msgqueue_addmsg(&host
->scsi
.msgs
, 1, MESSAGE_REJECT
);
1687 host
->scsi
.phase
= PHASE_MSGIN
;
1690 acornscsi_sbic_issuecmd(host
, CMND_NEGATEACK
);
1694 * Function: int acornscsi_buildmessages(AS_Host *host)
1695 * Purpose : build the connection messages for a host
1696 * Params : host - host to add messages to
1699 void acornscsi_buildmessages(AS_Host
*host
)
1702 msgqueue_addmsg(&host
->scsi
.msgs
, 1,
1703 IDENTIFY(host
->device
[host
->SCpnt
->device
->id
].disconnect_ok
,
1704 host
->SCpnt
->device
->lun
));
1707 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
1708 if (host
->SCpnt
->tag
) {
1709 unsigned int tag_type
;
1711 if (host
->SCpnt
->cmnd
[0] == REQUEST_SENSE
||
1712 host
->SCpnt
->cmnd
[0] == TEST_UNIT_READY
||
1713 host
->SCpnt
->cmnd
[0] == INQUIRY
)
1714 tag_type
= HEAD_OF_QUEUE_TAG
;
1716 tag_type
= SIMPLE_QUEUE_TAG
;
1717 msgqueue_addmsg(&host
->scsi
.msgs
, 2, tag_type
, host
->SCpnt
->tag
);
1721 #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
1722 if (host
->device
[host
->SCpnt
->device
->id
].sync_state
== SYNC_NEGOCIATE
) {
1723 host
->device
[host
->SCpnt
->device
->id
].sync_state
= SYNC_SENT_REQUEST
;
1724 msgqueue_addmsg(&host
->scsi
.msgs
, 5,
1725 EXTENDED_MESSAGE
, 3, EXTENDED_SDTR
,
1726 sdtr_period
/ 4, sdtr_size
);
1732 * Function: int acornscsi_starttransfer(AS_Host *host)
1733 * Purpose : transfer data to/from connected target
1734 * Params : host - host to which target is connected
1735 * Returns : 0 if failure
1738 int acornscsi_starttransfer(AS_Host
*host
)
1742 if (!host
->scsi
.SCp
.ptr
/*&& host->scsi.SCp.this_residual*/) {
1743 printk(KERN_ERR
"scsi%d.%c: null buffer passed to acornscsi_starttransfer\n",
1744 host
->host
->host_no
, acornscsi_target(host
));
1748 residual
= scsi_bufflen(host
->SCpnt
) - host
->scsi
.SCp
.scsi_xferred
;
1750 sbic_arm_write(host
, SBIC_SYNCHTRANSFER
, host
->device
[host
->SCpnt
->device
->id
].sync_xfer
);
1751 sbic_arm_writenext(host
, residual
>> 16);
1752 sbic_arm_writenext(host
, residual
>> 8);
1753 sbic_arm_writenext(host
, residual
);
1754 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
);
1758 /* =========================================================================================
1759 * Connection & Disconnection
1762 * Function : acornscsi_reconnect(AS_Host *host)
1763 * Purpose : reconnect a previously disconnected command
1764 * Params : host - host specific data
1765 * Remarks : SCSI spec says:
1766 * 'The set of active pointers is restored from the set
1767 * of saved pointers upon reconnection of the I/O process'
1770 int acornscsi_reconnect(AS_Host
*host
)
1772 unsigned int target
, lun
, ok
= 0;
1774 target
= sbic_arm_read(host
, SBIC_SOURCEID
);
1777 printk(KERN_ERR
"scsi%d: invalid source id after reselection "
1778 "- device fault?\n",
1779 host
->host
->host_no
);
1783 if (host
->SCpnt
&& !host
->scsi
.disconnectable
) {
1784 printk(KERN_ERR
"scsi%d.%d: reconnected while command in "
1785 "progress to target %d?\n",
1786 host
->host
->host_no
, target
, host
->SCpnt
->device
->id
);
1790 lun
= sbic_arm_read(host
, SBIC_DATA
) & 7;
1792 host
->scsi
.reconnected
.target
= target
;
1793 host
->scsi
.reconnected
.lun
= lun
;
1794 host
->scsi
.reconnected
.tag
= 0;
1796 if (host
->scsi
.disconnectable
&& host
->SCpnt
&&
1797 host
->SCpnt
->device
->id
== target
&& host
->SCpnt
->device
->lun
== lun
)
1800 if (!ok
&& queue_probetgtlun(&host
->queues
.disconnected
, target
, lun
))
1803 ADD_STATUS(target
, 0x81, host
->scsi
.phase
, 0);
1806 host
->scsi
.phase
= PHASE_RECONNECTED
;
1808 /* this doesn't seem to work */
1809 printk(KERN_ERR
"scsi%d.%c: reselected with no command "
1810 "to reconnect with\n",
1811 host
->host
->host_no
, '0' + target
);
1812 acornscsi_dumplog(host
, target
);
1813 acornscsi_abortcmd(host
, 0);
1815 queue_add_cmd_tail(&host
->queues
.disconnected
, host
->SCpnt
);
1819 acornscsi_sbic_issuecmd(host
, CMND_NEGATEACK
);
1824 * Function: int acornscsi_reconect_finish(AS_Host *host)
1825 * Purpose : finish reconnecting a command
1826 * Params : host - host to complete
1827 * Returns : 0 if failed
1830 int acornscsi_reconnect_finish(AS_Host
*host
)
1832 if (host
->scsi
.disconnectable
&& host
->SCpnt
) {
1833 host
->scsi
.disconnectable
= 0;
1834 if (host
->SCpnt
->device
->id
== host
->scsi
.reconnected
.target
&&
1835 host
->SCpnt
->device
->lun
== host
->scsi
.reconnected
.lun
&&
1836 host
->SCpnt
->tag
== host
->scsi
.reconnected
.tag
) {
1837 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1838 DBG(host
->SCpnt
, printk("scsi%d.%c: reconnected",
1839 host
->host
->host_no
, acornscsi_target(host
)));
1842 queue_add_cmd_tail(&host
->queues
.disconnected
, host
->SCpnt
);
1843 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1844 DBG(host
->SCpnt
, printk("scsi%d.%c: had to move command "
1845 "to disconnected queue\n",
1846 host
->host
->host_no
, acornscsi_target(host
)));
1852 host
->SCpnt
= queue_remove_tgtluntag(&host
->queues
.disconnected
,
1853 host
->scsi
.reconnected
.target
,
1854 host
->scsi
.reconnected
.lun
,
1855 host
->scsi
.reconnected
.tag
);
1856 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1857 DBG(host
->SCpnt
, printk("scsi%d.%c: had to get command",
1858 host
->host
->host_no
, acornscsi_target(host
)));
1863 acornscsi_abortcmd(host
, host
->scsi
.reconnected
.tag
);
1866 * Restore data pointer from SAVED pointers.
1868 host
->scsi
.SCp
= host
->SCpnt
->SCp
;
1869 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1870 printk(", data pointers: [%p, %X]",
1871 host
->scsi
.SCp
.ptr
, host
->scsi
.SCp
.this_residual
);
1874 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1878 host
->dma
.transferred
= host
->scsi
.SCp
.scsi_xferred
;
1880 return host
->SCpnt
!= NULL
;
1884 * Function: void acornscsi_disconnect_unexpected(AS_Host *host)
1885 * Purpose : handle an unexpected disconnect
1886 * Params : host - host on which disconnect occurred
1889 void acornscsi_disconnect_unexpected(AS_Host
*host
)
1891 printk(KERN_ERR
"scsi%d.%c: unexpected disconnect\n",
1892 host
->host
->host_no
, acornscsi_target(host
));
1893 #if (DEBUG & DEBUG_ABORT)
1894 acornscsi_dumplog(host
, 8);
1897 acornscsi_done(host
, &host
->SCpnt
, DID_ERROR
);
1901 * Function: void acornscsi_abortcmd(AS_host *host, unsigned char tag)
1902 * Purpose : abort a currently executing command
1903 * Params : host - host with connected command to abort
1904 * tag - tag to abort
1907 void acornscsi_abortcmd(AS_Host
*host
, unsigned char tag
)
1909 host
->scsi
.phase
= PHASE_ABORTED
;
1910 sbic_arm_write(host
, SBIC_CMND
, CMND_ASSERTATN
);
1912 msgqueue_flush(&host
->scsi
.msgs
);
1913 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
1915 msgqueue_addmsg(&host
->scsi
.msgs
, 2, ABORT_TAG
, tag
);
1918 msgqueue_addmsg(&host
->scsi
.msgs
, 1, ABORT
);
1921 /* ==========================================================================================
1922 * Interrupt routines.
1925 * Function: int acornscsi_sbicintr(AS_Host *host)
1926 * Purpose : handle interrupts from SCSI device
1927 * Params : host - host to process
1928 * Returns : INTR_PROCESS if expecting another SBIC interrupt
1929 * INTR_IDLE if no interrupt
1930 * INTR_NEXT_COMMAND if we have finished processing the command
1933 intr_ret_t
acornscsi_sbicintr(AS_Host
*host
, int in_irq
)
1935 unsigned int asr
, ssr
;
1937 asr
= sbic_arm_read(host
, SBIC_ASR
);
1938 if (!(asr
& ASR_INT
))
1941 ssr
= sbic_arm_read(host
, SBIC_SSR
);
1943 #if (DEBUG & DEBUG_PHASES)
1944 print_sbic_status(asr
, ssr
, host
->scsi
.phase
);
1947 ADD_STATUS(8, ssr
, host
->scsi
.phase
, in_irq
);
1949 if (host
->SCpnt
&& !host
->scsi
.disconnectable
)
1950 ADD_STATUS(host
->SCpnt
->device
->id
, ssr
, host
->scsi
.phase
, in_irq
);
1953 case 0x00: /* reset state - not advanced */
1954 printk(KERN_ERR
"scsi%d: reset in standard mode but wanted advanced mode.\n",
1955 host
->host
->host_no
);
1956 /* setup sbic - WD33C93A */
1957 sbic_arm_write(host
, SBIC_OWNID
, OWNID_EAF
| host
->host
->this_id
);
1958 sbic_arm_write(host
, SBIC_CMND
, CMND_RESET
);
1961 case 0x01: /* reset state - advanced */
1962 sbic_arm_write(host
, SBIC_CTRL
, INIT_SBICDMA
| CTRL_IDI
);
1963 sbic_arm_write(host
, SBIC_TIMEOUT
, TIMEOUT_TIME
);
1964 sbic_arm_write(host
, SBIC_SYNCHTRANSFER
, SYNCHTRANSFER_2DBA
);
1965 sbic_arm_write(host
, SBIC_SOURCEID
, SOURCEID_ER
| SOURCEID_DSP
);
1966 msgqueue_flush(&host
->scsi
.msgs
);
1969 case 0x41: /* unexpected disconnect aborted command */
1970 acornscsi_disconnect_unexpected(host
);
1971 return INTR_NEXT_COMMAND
;
1974 switch (host
->scsi
.phase
) {
1975 case PHASE_CONNECTING
: /* STATE: command removed from issue queue */
1977 case 0x11: /* -> PHASE_CONNECTED */
1978 /* BUS FREE -> SELECTION */
1979 host
->scsi
.phase
= PHASE_CONNECTED
;
1980 msgqueue_flush(&host
->scsi
.msgs
);
1981 host
->dma
.transferred
= host
->scsi
.SCp
.scsi_xferred
;
1982 /* 33C93 gives next interrupt indicating bus phase */
1983 asr
= sbic_arm_read(host
, SBIC_ASR
);
1984 if (!(asr
& ASR_INT
))
1986 ssr
= sbic_arm_read(host
, SBIC_SSR
);
1987 ADD_STATUS(8, ssr
, host
->scsi
.phase
, 1);
1988 ADD_STATUS(host
->SCpnt
->device
->id
, ssr
, host
->scsi
.phase
, 1);
1991 case 0x42: /* select timed out */
1993 acornscsi_done(host
, &host
->SCpnt
, DID_NO_CONNECT
);
1994 return INTR_NEXT_COMMAND
;
1996 case 0x81: /* -> PHASE_RECONNECTED or PHASE_ABORTED */
1997 /* BUS FREE -> RESELECTION */
1998 host
->origSCpnt
= host
->SCpnt
;
2000 msgqueue_flush(&host
->scsi
.msgs
);
2001 acornscsi_reconnect(host
);
2005 printk(KERN_ERR
"scsi%d.%c: PHASE_CONNECTING, SSR %02X?\n",
2006 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2007 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2008 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2010 return INTR_PROCESSING
;
2013 case PHASE_CONNECTED
: /* STATE: device selected ok */
2016 case 0x8a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
2017 /* SELECTION -> COMMAND */
2018 acornscsi_sendcommand(host
);
2021 case 0x8b: /* -> PHASE_STATUS */
2022 /* SELECTION -> STATUS */
2023 acornscsi_readstatusbyte(host
);
2024 host
->scsi
.phase
= PHASE_STATUSIN
;
2028 case 0x8e: /* -> PHASE_MSGOUT */
2029 /* SELECTION ->MESSAGE OUT */
2030 host
->scsi
.phase
= PHASE_MSGOUT
;
2031 acornscsi_buildmessages(host
);
2032 acornscsi_sendmessage(host
);
2035 /* these should not happen */
2036 case 0x85: /* target disconnected */
2037 acornscsi_done(host
, &host
->SCpnt
, DID_ERROR
);
2041 printk(KERN_ERR
"scsi%d.%c: PHASE_CONNECTED, SSR %02X?\n",
2042 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2043 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2044 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2046 return INTR_PROCESSING
;
2048 case PHASE_MSGOUT
: /* STATE: connected & sent IDENTIFY message */
2050 * SCSI standard says that MESSAGE OUT phases can be followed by a
2051 * DATA phase, STATUS phase, MESSAGE IN phase or COMMAND phase
2054 case 0x8a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
2055 case 0x1a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
2056 /* MESSAGE OUT -> COMMAND */
2057 acornscsi_sendcommand(host
);
2060 case 0x8b: /* -> PHASE_STATUS */
2061 case 0x1b: /* -> PHASE_STATUS */
2062 /* MESSAGE OUT -> STATUS */
2063 acornscsi_readstatusbyte(host
);
2064 host
->scsi
.phase
= PHASE_STATUSIN
;
2067 case 0x8e: /* -> PHASE_MSGOUT */
2068 /* MESSAGE_OUT(MESSAGE_IN) ->MESSAGE OUT */
2069 acornscsi_sendmessage(host
);
2072 case 0x4f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2073 case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2074 /* MESSAGE OUT -> MESSAGE IN */
2075 acornscsi_message(host
);
2079 printk(KERN_ERR
"scsi%d.%c: PHASE_MSGOUT, SSR %02X?\n",
2080 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2081 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2083 return INTR_PROCESSING
;
2085 case PHASE_COMMAND
: /* STATE: connected & command sent */
2087 case 0x18: /* -> PHASE_DATAOUT */
2088 /* COMMAND -> DATA OUT */
2089 if (host
->scsi
.SCp
.sent_command
!= host
->SCpnt
->cmd_len
)
2090 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2091 acornscsi_dma_setup(host
, DMA_OUT
);
2092 if (!acornscsi_starttransfer(host
))
2093 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2094 host
->scsi
.phase
= PHASE_DATAOUT
;
2097 case 0x19: /* -> PHASE_DATAIN */
2098 /* COMMAND -> DATA IN */
2099 if (host
->scsi
.SCp
.sent_command
!= host
->SCpnt
->cmd_len
)
2100 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2101 acornscsi_dma_setup(host
, DMA_IN
);
2102 if (!acornscsi_starttransfer(host
))
2103 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2104 host
->scsi
.phase
= PHASE_DATAIN
;
2107 case 0x1b: /* -> PHASE_STATUS */
2108 /* COMMAND -> STATUS */
2109 acornscsi_readstatusbyte(host
);
2110 host
->scsi
.phase
= PHASE_STATUSIN
;
2113 case 0x1e: /* -> PHASE_MSGOUT */
2114 /* COMMAND -> MESSAGE OUT */
2115 acornscsi_sendmessage(host
);
2118 case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2119 /* COMMAND -> MESSAGE IN */
2120 acornscsi_message(host
);
2124 printk(KERN_ERR
"scsi%d.%c: PHASE_COMMAND, SSR %02X?\n",
2125 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2126 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2128 return INTR_PROCESSING
;
2130 case PHASE_DISCONNECT
: /* STATE: connected, received DISCONNECT msg */
2131 if (ssr
== 0x85) { /* -> PHASE_IDLE */
2132 host
->scsi
.disconnectable
= 1;
2133 host
->scsi
.reconnected
.tag
= 0;
2134 host
->scsi
.phase
= PHASE_IDLE
;
2135 host
->stats
.disconnects
+= 1;
2137 printk(KERN_ERR
"scsi%d.%c: PHASE_DISCONNECT, SSR %02X instead of disconnect?\n",
2138 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2139 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2141 return INTR_NEXT_COMMAND
;
2143 case PHASE_IDLE
: /* STATE: disconnected */
2144 if (ssr
== 0x81) /* -> PHASE_RECONNECTED or PHASE_ABORTED */
2145 acornscsi_reconnect(host
);
2147 printk(KERN_ERR
"scsi%d.%c: PHASE_IDLE, SSR %02X while idle?\n",
2148 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2149 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2151 return INTR_PROCESSING
;
2153 case PHASE_RECONNECTED
: /* STATE: device reconnected to initiator */
2155 * Command reconnected - if MESGIN, get message - it may be
2156 * the tag. If not, get command out of disconnected queue
2159 * If we reconnected and we're not in MESSAGE IN phase after IDENTIFY,
2160 * reconnect I_T_L command
2162 if (ssr
!= 0x8f && !acornscsi_reconnect_finish(host
))
2164 ADD_STATUS(host
->SCpnt
->device
->id
, ssr
, host
->scsi
.phase
, in_irq
);
2166 case 0x88: /* data out phase */
2167 /* -> PHASE_DATAOUT */
2168 /* MESSAGE IN -> DATA OUT */
2169 acornscsi_dma_setup(host
, DMA_OUT
);
2170 if (!acornscsi_starttransfer(host
))
2171 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2172 host
->scsi
.phase
= PHASE_DATAOUT
;
2175 case 0x89: /* data in phase */
2176 /* -> PHASE_DATAIN */
2177 /* MESSAGE IN -> DATA IN */
2178 acornscsi_dma_setup(host
, DMA_IN
);
2179 if (!acornscsi_starttransfer(host
))
2180 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2181 host
->scsi
.phase
= PHASE_DATAIN
;
2184 case 0x8a: /* command out */
2185 /* MESSAGE IN -> COMMAND */
2186 acornscsi_sendcommand(host
);/* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
2189 case 0x8b: /* status in */
2190 /* -> PHASE_STATUSIN */
2191 /* MESSAGE IN -> STATUS */
2192 acornscsi_readstatusbyte(host
);
2193 host
->scsi
.phase
= PHASE_STATUSIN
;
2196 case 0x8e: /* message out */
2197 /* -> PHASE_MSGOUT */
2198 /* MESSAGE IN -> MESSAGE OUT */
2199 acornscsi_sendmessage(host
);
2202 case 0x8f: /* message in */
2203 acornscsi_message(host
); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2207 printk(KERN_ERR
"scsi%d.%c: PHASE_RECONNECTED, SSR %02X after reconnect?\n",
2208 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2209 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2211 return INTR_PROCESSING
;
2213 case PHASE_DATAIN
: /* STATE: transferred data in */
2215 * This is simple - if we disconnect then the DMA address & count is
2219 case 0x19: /* -> PHASE_DATAIN */
2220 case 0x89: /* -> PHASE_DATAIN */
2221 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2224 case 0x1b: /* -> PHASE_STATUSIN */
2225 case 0x4b: /* -> PHASE_STATUSIN */
2226 case 0x8b: /* -> PHASE_STATUSIN */
2227 /* DATA IN -> STATUS */
2228 host
->scsi
.SCp
.scsi_xferred
= scsi_bufflen(host
->SCpnt
) -
2229 acornscsi_sbic_xfcount(host
);
2230 acornscsi_dma_stop(host
);
2231 acornscsi_readstatusbyte(host
);
2232 host
->scsi
.phase
= PHASE_STATUSIN
;
2235 case 0x1e: /* -> PHASE_MSGOUT */
2236 case 0x4e: /* -> PHASE_MSGOUT */
2237 case 0x8e: /* -> PHASE_MSGOUT */
2238 /* DATA IN -> MESSAGE OUT */
2239 host
->scsi
.SCp
.scsi_xferred
= scsi_bufflen(host
->SCpnt
) -
2240 acornscsi_sbic_xfcount(host
);
2241 acornscsi_dma_stop(host
);
2242 acornscsi_sendmessage(host
);
2245 case 0x1f: /* message in */
2246 case 0x4f: /* message in */
2247 case 0x8f: /* message in */
2248 /* DATA IN -> MESSAGE IN */
2249 host
->scsi
.SCp
.scsi_xferred
= scsi_bufflen(host
->SCpnt
) -
2250 acornscsi_sbic_xfcount(host
);
2251 acornscsi_dma_stop(host
);
2252 acornscsi_message(host
); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2256 printk(KERN_ERR
"scsi%d.%c: PHASE_DATAIN, SSR %02X?\n",
2257 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2258 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2260 return INTR_PROCESSING
;
2262 case PHASE_DATAOUT
: /* STATE: transferred data out */
2264 * This is more complicated - if we disconnect, the DMA could be 12
2265 * bytes ahead of us. We need to correct this.
2268 case 0x18: /* -> PHASE_DATAOUT */
2269 case 0x88: /* -> PHASE_DATAOUT */
2270 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2273 case 0x1b: /* -> PHASE_STATUSIN */
2274 case 0x4b: /* -> PHASE_STATUSIN */
2275 case 0x8b: /* -> PHASE_STATUSIN */
2276 /* DATA OUT -> STATUS */
2277 host
->scsi
.SCp
.scsi_xferred
= scsi_bufflen(host
->SCpnt
) -
2278 acornscsi_sbic_xfcount(host
);
2279 acornscsi_dma_stop(host
);
2280 acornscsi_dma_adjust(host
);
2281 acornscsi_readstatusbyte(host
);
2282 host
->scsi
.phase
= PHASE_STATUSIN
;
2285 case 0x1e: /* -> PHASE_MSGOUT */
2286 case 0x4e: /* -> PHASE_MSGOUT */
2287 case 0x8e: /* -> PHASE_MSGOUT */
2288 /* DATA OUT -> MESSAGE OUT */
2289 host
->scsi
.SCp
.scsi_xferred
= scsi_bufflen(host
->SCpnt
) -
2290 acornscsi_sbic_xfcount(host
);
2291 acornscsi_dma_stop(host
);
2292 acornscsi_dma_adjust(host
);
2293 acornscsi_sendmessage(host
);
2296 case 0x1f: /* message in */
2297 case 0x4f: /* message in */
2298 case 0x8f: /* message in */
2299 /* DATA OUT -> MESSAGE IN */
2300 host
->scsi
.SCp
.scsi_xferred
= scsi_bufflen(host
->SCpnt
) -
2301 acornscsi_sbic_xfcount(host
);
2302 acornscsi_dma_stop(host
);
2303 acornscsi_dma_adjust(host
);
2304 acornscsi_message(host
); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2308 printk(KERN_ERR
"scsi%d.%c: PHASE_DATAOUT, SSR %02X?\n",
2309 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2310 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2312 return INTR_PROCESSING
;
2314 case PHASE_STATUSIN
: /* STATE: status in complete */
2316 case 0x1f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
2317 case 0x8f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
2318 /* STATUS -> MESSAGE IN */
2319 acornscsi_message(host
);
2322 case 0x1e: /* -> PHASE_MSGOUT */
2323 case 0x8e: /* -> PHASE_MSGOUT */
2324 /* STATUS -> MESSAGE OUT */
2325 acornscsi_sendmessage(host
);
2329 printk(KERN_ERR
"scsi%d.%c: PHASE_STATUSIN, SSR %02X instead of MESSAGE_IN?\n",
2330 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2331 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2333 return INTR_PROCESSING
;
2335 case PHASE_MSGIN
: /* STATE: message in */
2337 case 0x1e: /* -> PHASE_MSGOUT */
2338 case 0x4e: /* -> PHASE_MSGOUT */
2339 case 0x8e: /* -> PHASE_MSGOUT */
2340 /* MESSAGE IN -> MESSAGE OUT */
2341 acornscsi_sendmessage(host
);
2344 case 0x1f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
2348 acornscsi_message(host
);
2352 printk("scsi%d.%c: strange message in disconnection\n",
2353 host
->host
->host_no
, acornscsi_target(host
));
2354 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2355 acornscsi_done(host
, &host
->SCpnt
, DID_ERROR
);
2359 printk(KERN_ERR
"scsi%d.%c: PHASE_MSGIN, SSR %02X after message in?\n",
2360 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2361 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2363 return INTR_PROCESSING
;
2365 case PHASE_DONE
: /* STATE: received status & message */
2367 case 0x85: /* -> PHASE_IDLE */
2368 acornscsi_done(host
, &host
->SCpnt
, DID_OK
);
2369 return INTR_NEXT_COMMAND
;
2373 acornscsi_sendmessage(host
);
2377 printk(KERN_ERR
"scsi%d.%c: PHASE_DONE, SSR %02X instead of disconnect?\n",
2378 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2379 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2381 return INTR_PROCESSING
;
2387 acornscsi_done(host
, &host
->SCpnt
, DID_ABORT
);
2389 clear_bit(host
->scsi
.reconnected
.target
* 8 + host
->scsi
.reconnected
.lun
,
2391 host
->scsi
.phase
= PHASE_IDLE
;
2393 return INTR_NEXT_COMMAND
;
2399 acornscsi_sendmessage(host
);
2403 printk(KERN_ERR
"scsi%d.%c: PHASE_ABORTED, SSR %02X?\n",
2404 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2405 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2407 return INTR_PROCESSING
;
2410 printk(KERN_ERR
"scsi%d.%c: unknown driver phase %d\n",
2411 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2412 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2414 return INTR_PROCESSING
;
2418 * Prototype: void acornscsi_intr(int irq, void *dev_id)
2419 * Purpose : handle interrupts from Acorn SCSI card
2420 * Params : irq - interrupt number
2421 * dev_id - device specific data (AS_Host structure)
2424 acornscsi_intr(int irq
, void *dev_id
)
2426 AS_Host
*host
= (AS_Host
*)dev_id
;
2434 iostatus
= readb(host
->fast
+ INT_REG
);
2437 acornscsi_dma_intr(host
);
2438 iostatus
= readb(host
->fast
+ INT_REG
);
2442 ret
= acornscsi_sbicintr(host
, in_irq
);
2445 * If we have a transfer pending, start it.
2446 * Only start it if the interface has already started transferring
2449 if (host
->dma
.xfer_required
)
2450 acornscsi_dma_xfer(host
);
2452 if (ret
== INTR_NEXT_COMMAND
)
2453 ret
= acornscsi_kick(host
);
2456 } while (ret
!= INTR_IDLE
);
2461 /*=============================================================================================
2462 * Interfaces between interrupt handler and rest of scsi code
2466 * Function : acornscsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
2467 * Purpose : queues a SCSI command
2468 * Params : cmd - SCSI command
2469 * done - function called on completion, with pointer to command descriptor
2470 * Returns : 0, or < 0 on error.
2472 int acornscsi_queuecmd(struct scsi_cmnd
*SCpnt
,
2473 void (*done
)(struct scsi_cmnd
*))
2475 AS_Host
*host
= (AS_Host
*)SCpnt
->device
->host
->hostdata
;
2478 /* there should be some way of rejecting errors like this without panicing... */
2479 panic("scsi%d: queuecommand called with NULL done function [cmd=%p]",
2480 host
->host
->host_no
, SCpnt
);
2484 #if (DEBUG & DEBUG_NO_WRITE)
2485 if (acornscsi_cmdtype(SCpnt
->cmnd
[0]) == CMD_WRITE
&& (NO_WRITE
& (1 << SCpnt
->device
->id
))) {
2486 printk(KERN_CRIT
"scsi%d.%c: WRITE attempted with NO_WRITE flag set\n",
2487 host
->host
->host_no
, '0' + SCpnt
->device
->id
);
2488 SCpnt
->result
= DID_NO_CONNECT
<< 16;
2494 SCpnt
->scsi_done
= done
;
2495 SCpnt
->host_scribble
= NULL
;
2498 SCpnt
->SCp
.phase
= (int)acornscsi_datadirection(SCpnt
->cmnd
[0]);
2499 SCpnt
->SCp
.sent_command
= 0;
2500 SCpnt
->SCp
.scsi_xferred
= 0;
2504 host
->stats
.queues
+= 1;
2507 unsigned long flags
;
2509 if (!queue_add_cmd_ordered(&host
->queues
.issue
, SCpnt
)) {
2510 SCpnt
->result
= DID_ERROR
<< 16;
2514 local_irq_save(flags
);
2515 if (host
->scsi
.phase
== PHASE_IDLE
)
2516 acornscsi_kick(host
);
2517 local_irq_restore(flags
);
2523 * Prototype: void acornscsi_reportstatus(struct scsi_cmnd **SCpntp1, struct scsi_cmnd **SCpntp2, int result)
2524 * Purpose : pass a result to *SCpntp1, and check if *SCpntp1 = *SCpntp2
2525 * Params : SCpntp1 - pointer to command to return
2526 * SCpntp2 - pointer to command to check
2527 * result - result to pass back to mid-level done function
2528 * Returns : *SCpntp2 = NULL if *SCpntp1 is the same command structure as *SCpntp2.
2530 static inline void acornscsi_reportstatus(struct scsi_cmnd
**SCpntp1
,
2531 struct scsi_cmnd
**SCpntp2
,
2534 struct scsi_cmnd
*SCpnt
= *SCpntp1
;
2539 SCpnt
->result
= result
;
2540 SCpnt
->scsi_done(SCpnt
);
2543 if (SCpnt
== *SCpntp2
)
2547 enum res_abort
{ res_not_running
, res_success
, res_success_clear
, res_snooze
};
2550 * Prototype: enum res acornscsi_do_abort(struct scsi_cmnd *SCpnt)
2551 * Purpose : abort a command on this host
2552 * Params : SCpnt - command to abort
2553 * Returns : our abort status
2555 static enum res_abort
acornscsi_do_abort(AS_Host
*host
, struct scsi_cmnd
*SCpnt
)
2557 enum res_abort res
= res_not_running
;
2559 if (queue_remove_cmd(&host
->queues
.issue
, SCpnt
)) {
2561 * The command was on the issue queue, and has not been
2562 * issued yet. We can remove the command from the queue,
2563 * and acknowledge the abort. Neither the devices nor the
2564 * interface know about the command.
2566 //#if (DEBUG & DEBUG_ABORT)
2567 printk("on issue queue ");
2570 } else if (queue_remove_cmd(&host
->queues
.disconnected
, SCpnt
)) {
2572 * The command was on the disconnected queue. Simply
2573 * acknowledge the abort condition, and when the target
2574 * reconnects, we will give it an ABORT message. The
2575 * target should then disconnect, and we will clear
2578 //#if (DEBUG & DEBUG_ABORT)
2579 printk("on disconnected queue ");
2582 } else if (host
->SCpnt
== SCpnt
) {
2583 unsigned long flags
;
2585 //#if (DEBUG & DEBUG_ABORT)
2586 printk("executing ");
2589 local_irq_save(flags
);
2590 switch (host
->scsi
.phase
) {
2592 * If the interface is idle, and the command is 'disconnectable',
2593 * then it is the same as on the disconnected queue. We simply
2594 * remove all traces of the command. When the target reconnects,
2595 * we will give it an ABORT message since the command could not
2596 * be found. When the target finally disconnects, we will clear
2600 if (host
->scsi
.disconnectable
) {
2601 host
->scsi
.disconnectable
= 0;
2608 * If the command has connected and done nothing further,
2609 * simply force a disconnect. We also need to clear the
2612 case PHASE_CONNECTED
:
2613 sbic_arm_write(host
, SBIC_CMND
, CMND_DISCONNECT
);
2615 res
= res_success_clear
;
2619 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2622 local_irq_restore(flags
);
2623 } else if (host
->origSCpnt
== SCpnt
) {
2625 * The command will be executed next, but a command
2626 * is currently using the interface. This is similar to
2627 * being on the issue queue, except the busylun bit has
2630 host
->origSCpnt
= NULL
;
2631 //#if (DEBUG & DEBUG_ABORT)
2632 printk("waiting for execution ");
2634 res
= res_success_clear
;
2642 * Prototype: int acornscsi_abort(struct scsi_cmnd *SCpnt)
2643 * Purpose : abort a command on this host
2644 * Params : SCpnt - command to abort
2645 * Returns : one of SCSI_ABORT_ macros
2647 int acornscsi_abort(struct scsi_cmnd
*SCpnt
)
2649 AS_Host
*host
= (AS_Host
*) SCpnt
->device
->host
->hostdata
;
2652 host
->stats
.aborts
+= 1;
2654 #if (DEBUG & DEBUG_ABORT)
2657 asr
= sbic_arm_read(host
, SBIC_ASR
);
2658 ssr
= sbic_arm_read(host
, SBIC_SSR
);
2660 printk(KERN_WARNING
"acornscsi_abort: ");
2661 print_sbic_status(asr
, ssr
, host
->scsi
.phase
);
2662 acornscsi_dumplog(host
, SCpnt
->device
->id
);
2666 printk("scsi%d: ", host
->host
->host_no
);
2668 switch (acornscsi_do_abort(host
, SCpnt
)) {
2670 * We managed to find the command and cleared it out.
2671 * We do not expect the command to be executing on the
2672 * target, but we have set the busylun bit.
2674 case res_success_clear
:
2675 //#if (DEBUG & DEBUG_ABORT)
2678 clear_bit(SCpnt
->device
->id
* 8 + SCpnt
->device
->lun
, host
->busyluns
);
2681 * We found the command, and cleared it out. Either
2682 * the command is still known to be executing on the
2683 * target, or the busylun bit is not set.
2686 //#if (DEBUG & DEBUG_ABORT)
2687 printk("success\n");
2693 * We did find the command, but unfortunately we couldn't
2694 * unhook it from ourselves. Wait some more, and if it
2695 * still doesn't complete, reset the interface.
2698 //#if (DEBUG & DEBUG_ABORT)
2705 * The command could not be found (either because it completed,
2706 * or it got dropped.
2709 case res_not_running
:
2710 acornscsi_dumplog(host
, SCpnt
->device
->id
);
2712 //#if (DEBUG & DEBUG_ABORT)
2713 printk("not running\n");
2722 * Prototype: int acornscsi_reset(struct scsi_cmnd *SCpnt)
2723 * Purpose : reset a command on this host/reset this host
2724 * Params : SCpnt - command causing reset
2725 * Returns : one of SCSI_RESET_ macros
2727 int acornscsi_bus_reset(struct scsi_cmnd
*SCpnt
)
2729 AS_Host
*host
= (AS_Host
*)SCpnt
->device
->host
->hostdata
;
2730 struct scsi_cmnd
*SCptr
;
2732 host
->stats
.resets
+= 1;
2734 #if (DEBUG & DEBUG_RESET)
2738 asr
= sbic_arm_read(host
, SBIC_ASR
);
2739 ssr
= sbic_arm_read(host
, SBIC_SSR
);
2741 printk(KERN_WARNING
"acornscsi_reset: ");
2742 print_sbic_status(asr
, ssr
, host
->scsi
.phase
);
2743 acornscsi_dumplog(host
, SCpnt
->device
->id
);
2747 acornscsi_dma_stop(host
);
2750 * do hard reset. This resets all devices on this host, and so we
2751 * must set the reset status on all commands.
2753 acornscsi_resetcard(host
);
2755 while ((SCptr
= queue_remove(&host
->queues
.disconnected
)) != NULL
)
2761 /*==============================================================================================
2762 * initialisation & miscellaneous support
2766 * Function: char *acornscsi_info(struct Scsi_Host *host)
2767 * Purpose : return a string describing this interface
2768 * Params : host - host to give information on
2769 * Returns : a constant string
2772 char *acornscsi_info(struct Scsi_Host
*host
)
2774 static char string
[100], *p
;
2778 p
+= sprintf(string
, "%s at port %08lX irq %d v%d.%d.%d"
2779 #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
2782 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
2785 #ifdef CONFIG_SCSI_ACORNSCSI_LINK
2788 #if (DEBUG & DEBUG_NO_WRITE)
2789 " NOWRITE (" __stringify(NO_WRITE
) ")"
2791 , host
->hostt
->name
, host
->io_port
, host
->irq
,
2792 VER_MAJOR
, VER_MINOR
, VER_PATCH
);
2796 int acornscsi_proc_info(struct Scsi_Host
*instance
, char *buffer
, char **start
, off_t offset
,
2797 int length
, int inout
)
2799 int pos
, begin
= 0, devidx
;
2800 struct scsi_device
*scd
;
2807 host
= (AS_Host
*)instance
->hostdata
;
2809 p
+= sprintf(p
, "AcornSCSI driver v%d.%d.%d"
2810 #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
2813 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
2816 #ifdef CONFIG_SCSI_ACORNSCSI_LINK
2819 #if (DEBUG & DEBUG_NO_WRITE)
2820 " NOWRITE (" __stringify(NO_WRITE
) ")"
2822 "\n\n", VER_MAJOR
, VER_MINOR
, VER_PATCH
);
2824 p
+= sprintf(p
, "SBIC: WD33C93A Address: %p IRQ : %d\n",
2825 host
->base
+ SBIC_REGIDX
, host
->scsi
.irq
);
2827 p
+= sprintf(p
, "DMAC: uPC71071 Address: %p IRQ : %d\n\n",
2828 host
->base
+ DMAC_OFFSET
, host
->scsi
.irq
);
2831 p
+= sprintf(p
, "Statistics:\n"
2832 "Queued commands: %-10u Issued commands: %-10u\n"
2833 "Done commands : %-10u Reads : %-10u\n"
2834 "Writes : %-10u Others : %-10u\n"
2835 "Disconnects : %-10u Aborts : %-10u\n"
2836 "Resets : %-10u\n\nLast phases:",
2837 host
->stats
.queues
, host
->stats
.removes
,
2838 host
->stats
.fins
, host
->stats
.reads
,
2839 host
->stats
.writes
, host
->stats
.miscs
,
2840 host
->stats
.disconnects
, host
->stats
.aborts
,
2841 host
->stats
.resets
);
2843 for (devidx
= 0; devidx
< 9; devidx
++) {
2844 unsigned int statptr
, prev
;
2846 p
+= sprintf(p
, "\n%c:", devidx
== 8 ? 'H' : ('0' + devidx
));
2847 statptr
= host
->status_ptr
[devidx
] - 10;
2849 if ((signed int)statptr
< 0)
2850 statptr
+= STATUS_BUFFER_SIZE
;
2852 prev
= host
->status
[devidx
][statptr
].when
;
2854 for (; statptr
!= host
->status_ptr
[devidx
]; statptr
= (statptr
+ 1) & (STATUS_BUFFER_SIZE
- 1)) {
2855 if (host
->status
[devidx
][statptr
].when
) {
2856 p
+= sprintf(p
, "%c%02X:%02X+%2ld",
2857 host
->status
[devidx
][statptr
].irq
? '-' : ' ',
2858 host
->status
[devidx
][statptr
].ph
,
2859 host
->status
[devidx
][statptr
].ssr
,
2860 (host
->status
[devidx
][statptr
].when
- prev
) < 100 ?
2861 (host
->status
[devidx
][statptr
].when
- prev
) : 99);
2862 prev
= host
->status
[devidx
][statptr
].when
;
2867 p
+= sprintf(p
, "\nAttached devices:\n");
2869 shost_for_each_device(scd
, instance
) {
2870 p
+= sprintf(p
, "Device/Lun TaggedQ Sync\n");
2871 p
+= sprintf(p
, " %d/%d ", scd
->id
, scd
->lun
);
2872 if (scd
->tagged_supported
)
2873 p
+= sprintf(p
, "%3sabled(%3d) ",
2874 scd
->simple_tags
? "en" : "dis",
2877 p
+= sprintf(p
, "unsupported ");
2879 if (host
->device
[scd
->id
].sync_xfer
& 15)
2880 p
+= sprintf(p
, "offset %d, %d ns\n",
2881 host
->device
[scd
->id
].sync_xfer
& 15,
2882 acornscsi_getperiod(host
->device
[scd
->id
].sync_xfer
));
2884 p
+= sprintf(p
, "async\n");
2887 if (pos
+ begin
< offset
) {
2892 if (pos
+ begin
> offset
+ length
) {
2893 scsi_device_put(scd
);
2900 *start
= buffer
+ (offset
- begin
);
2901 pos
-= offset
- begin
;
2909 static struct scsi_host_template acornscsi_template
= {
2910 .module
= THIS_MODULE
,
2911 .proc_info
= acornscsi_proc_info
,
2912 .name
= "AcornSCSI",
2913 .info
= acornscsi_info
,
2914 .queuecommand
= acornscsi_queuecmd
,
2915 .eh_abort_handler
= acornscsi_abort
,
2916 .eh_bus_reset_handler
= acornscsi_bus_reset
,
2919 .sg_tablesize
= SG_ALL
,
2921 .use_clustering
= DISABLE_CLUSTERING
,
2922 .proc_name
= "acornscsi",
2925 static int __devinit
2926 acornscsi_probe(struct expansion_card
*ec
, const struct ecard_id
*id
)
2928 struct Scsi_Host
*host
;
2932 ret
= ecard_request_resources(ec
);
2936 host
= scsi_host_alloc(&acornscsi_template
, sizeof(AS_Host
));
2942 ashost
= (AS_Host
*)host
->hostdata
;
2944 ashost
->base
= ecardm_iomap(ec
, ECARD_RES_MEMC
, 0, 0);
2945 ashost
->fast
= ecardm_iomap(ec
, ECARD_RES_IOCFAST
, 0, 0);
2946 if (!ashost
->base
|| !ashost
->fast
)
2949 host
->irq
= ec
->irq
;
2950 ashost
->host
= host
;
2951 ashost
->scsi
.irq
= host
->irq
;
2953 ec
->irqaddr
= ashost
->fast
+ INT_REG
;
2956 ret
= request_irq(host
->irq
, acornscsi_intr
, IRQF_DISABLED
, "acornscsi", ashost
);
2958 printk(KERN_CRIT
"scsi%d: IRQ%d not free: %d\n",
2959 host
->host_no
, ashost
->scsi
.irq
, ret
);
2963 memset(&ashost
->stats
, 0, sizeof (ashost
->stats
));
2964 queue_initialise(&ashost
->queues
.issue
);
2965 queue_initialise(&ashost
->queues
.disconnected
);
2966 msgqueue_initialise(&ashost
->scsi
.msgs
);
2968 acornscsi_resetcard(ashost
);
2970 ret
= scsi_add_host(host
, &ec
->dev
);
2974 scsi_scan_host(host
);
2978 free_irq(host
->irq
, ashost
);
2979 msgqueue_free(&ashost
->scsi
.msgs
);
2980 queue_free(&ashost
->queues
.disconnected
);
2981 queue_free(&ashost
->queues
.issue
);
2983 ecardm_iounmap(ec
, ashost
->fast
);
2984 ecardm_iounmap(ec
, ashost
->base
);
2985 scsi_host_put(host
);
2987 ecard_release_resources(ec
);
2992 static void __devexit
acornscsi_remove(struct expansion_card
*ec
)
2994 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
2995 AS_Host
*ashost
= (AS_Host
*)host
->hostdata
;
2997 ecard_set_drvdata(ec
, NULL
);
2998 scsi_remove_host(host
);
3001 * Put card into RESET state
3003 writeb(0x80, ashost
->fast
+ PAGE_REG
);
3005 free_irq(host
->irq
, ashost
);
3007 msgqueue_free(&ashost
->scsi
.msgs
);
3008 queue_free(&ashost
->queues
.disconnected
);
3009 queue_free(&ashost
->queues
.issue
);
3010 ecardm_iounmap(ec
, ashost
->fast
);
3011 ecardm_iounmap(ec
, ashost
->base
);
3012 scsi_host_put(host
);
3013 ecard_release_resources(ec
);
3016 static const struct ecard_id acornscsi_cids
[] = {
3017 { MANU_ACORN
, PROD_ACORN_SCSI
},
3021 static struct ecard_driver acornscsi_driver
= {
3022 .probe
= acornscsi_probe
,
3023 .remove
= __devexit_p(acornscsi_remove
),
3024 .id_table
= acornscsi_cids
,
3026 .name
= "acornscsi",
3030 static int __init
acornscsi_init(void)
3032 return ecard_register_driver(&acornscsi_driver
);
3035 static void __exit
acornscsi_exit(void)
3037 ecard_remove_driver(&acornscsi_driver
);
3040 module_init(acornscsi_init
);
3041 module_exit(acornscsi_exit
);
3043 MODULE_AUTHOR("Russell King");
3044 MODULE_DESCRIPTION("AcornSCSI driver");
3045 MODULE_LICENSE("GPL");