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
127 #define STRINGIFY(x) #x
129 #define STRx(x) STRINGIFY(x)
130 #define NO_WRITE_STR STRx(NO_WRITE)
132 #include <linux/config.h>
133 #include <linux/module.h>
134 #include <linux/kernel.h>
135 #include <linux/sched.h>
136 #include <linux/string.h>
137 #include <linux/signal.h>
138 #include <linux/errno.h>
139 #include <linux/proc_fs.h>
140 #include <linux/ioport.h>
141 #include <linux/blkdev.h>
142 #include <linux/delay.h>
143 #include <linux/interrupt.h>
144 #include <linux/init.h>
145 #include <linux/bitops.h>
147 #include <asm/system.h>
150 #include <asm/ecard.h>
153 #include <scsi/scsi_dbg.h>
154 #include <scsi/scsi_host.h>
155 #include <scsi/scsi_transport_spi.h>
156 #include "acornscsi.h"
157 #include "msgqueue.h"
160 #include <scsi/scsicam.h>
167 #define ABORT_TAG 0xd
169 #error "Yippee! ABORT TAG is now defined! Remove this error!"
172 #ifdef CONFIG_SCSI_ACORNSCSI_LINK
173 #error SCSI2 LINKed commands not supported (yet)!
178 * DMAC setup parameters
180 #define INIT_DEVCON0 (DEVCON0_RQL|DEVCON0_EXW|DEVCON0_CMP)
181 #define INIT_DEVCON1 (DEVCON1_BHLD)
182 #define DMAC_READ (MODECON_READ)
183 #define DMAC_WRITE (MODECON_WRITE)
184 #define INIT_SBICDMA (CTRL_DMABURST)
186 #define scsi_xferred have_data_in
189 * Size of on-board DMA buffer
191 #define DMAC_BUFFER_SIZE 65536
194 #define STATUS_BUFFER_TO_PRINT 24
196 unsigned int sdtr_period
= SDTR_PERIOD
;
197 unsigned int sdtr_size
= SDTR_SIZE
;
199 static void acornscsi_done(AS_Host
*host
, Scsi_Cmnd
**SCpntp
, unsigned int result
);
200 static int acornscsi_reconnect_finish(AS_Host
*host
);
201 static void acornscsi_dma_cleanup(AS_Host
*host
);
202 static void acornscsi_abortcmd(AS_Host
*host
, unsigned char tag
);
204 /* ====================================================================================
209 sbic_arm_write(unsigned int io_port
, int reg
, int value
)
211 __raw_writeb(reg
, io_port
);
212 __raw_writeb(value
, io_port
+ 4);
215 #define sbic_arm_writenext(io,val) \
216 __raw_writeb((val), (io) + 4)
219 int sbic_arm_read(unsigned int io_port
, int reg
)
222 return __raw_readl(io_port
) & 255;
223 __raw_writeb(reg
, io_port
);
224 return __raw_readl(io_port
+ 4) & 255;
227 #define sbic_arm_readnext(io) \
228 __raw_readb((io) + 4)
231 #define dmac_read(io_port,reg) \
232 inb((io_port) + (reg))
234 #define dmac_write(io_port,reg,value) \
235 ({ outb((value), (io_port) + (reg)); })
237 #define dmac_clearintr(io_port) \
238 ({ outb(0, (io_port)); })
241 unsigned int dmac_address(unsigned int io_port
)
243 return dmac_read(io_port
, DMAC_TXADRHI
) << 16 |
244 dmac_read(io_port
, DMAC_TXADRMD
) << 8 |
245 dmac_read(io_port
, DMAC_TXADRLO
);
249 void acornscsi_dumpdma(AS_Host
*host
, char *where
)
251 unsigned int mode
, addr
, len
;
253 mode
= dmac_read(host
->dma
.io_port
, DMAC_MODECON
);
254 addr
= dmac_address(host
->dma
.io_port
);
255 len
= dmac_read(host
->dma
.io_port
, DMAC_TXCNTHI
) << 8 |
256 dmac_read(host
->dma
.io_port
, DMAC_TXCNTLO
);
258 printk("scsi%d: %s: DMAC %02x @%06x+%04x msk %02x, ",
259 host
->host
->host_no
, where
,
260 mode
, addr
, (len
+ 1) & 0xffff,
261 dmac_read(host
->dma
.io_port
, DMAC_MASKREG
));
263 printk("DMA @%06x, ", host
->dma
.start_addr
);
264 printk("BH @%p +%04x, ", host
->scsi
.SCp
.ptr
,
265 host
->scsi
.SCp
.this_residual
);
266 printk("DT @+%04x ST @+%04x", host
->dma
.transferred
,
267 host
->scsi
.SCp
.scsi_xferred
);
273 unsigned long acornscsi_sbic_xfcount(AS_Host
*host
)
275 unsigned long length
;
277 length
= sbic_arm_read(host
->scsi
.io_port
, SBIC_TRANSCNTH
) << 16;
278 length
|= sbic_arm_readnext(host
->scsi
.io_port
) << 8;
279 length
|= sbic_arm_readnext(host
->scsi
.io_port
);
285 acornscsi_sbic_wait(AS_Host
*host
, int stat_mask
, int stat
, int timeout
, char *msg
)
290 asr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
292 if ((asr
& stat_mask
) == stat
)
298 printk("scsi%d: timeout while %s\n", host
->host
->host_no
, msg
);
304 int acornscsi_sbic_issuecmd(AS_Host
*host
, int command
)
306 if (acornscsi_sbic_wait(host
, ASR_CIP
, 0, 1000, "issuing command"))
309 sbic_arm_write(host
->scsi
.io_port
, SBIC_CMND
, command
);
315 acornscsi_csdelay(unsigned int cs
)
317 unsigned long target_jiffies
, flags
;
319 target_jiffies
= jiffies
+ 1 + cs
* HZ
/ 100;
321 local_save_flags(flags
);
324 while (time_before(jiffies
, target_jiffies
)) barrier();
326 local_irq_restore(flags
);
330 void acornscsi_resetcard(AS_Host
*host
)
332 unsigned int i
, timeout
;
334 /* assert reset line */
335 host
->card
.page_reg
= 0x80;
336 outb(host
->card
.page_reg
, host
->card
.io_page
);
338 /* wait 3 cs. SCSI standard says 25ms. */
339 acornscsi_csdelay(3);
341 host
->card
.page_reg
= 0;
342 outb(host
->card
.page_reg
, host
->card
.io_page
);
345 * Should get a reset from the card
349 if (inb(host
->card
.io_intr
) & 8)
355 printk("scsi%d: timeout while resetting card\n",
356 host
->host
->host_no
);
358 sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
359 sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
);
361 /* setup sbic - WD33C93A */
362 sbic_arm_write(host
->scsi
.io_port
, SBIC_OWNID
, OWNID_EAF
| host
->host
->this_id
);
363 sbic_arm_write(host
->scsi
.io_port
, SBIC_CMND
, CMND_RESET
);
366 * Command should cause a reset interrupt
370 if (inb(host
->card
.io_intr
) & 8)
376 printk("scsi%d: timeout while resetting card\n",
377 host
->host
->host_no
);
379 sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
380 if (sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
) != 0x01)
381 printk(KERN_CRIT
"scsi%d: WD33C93A didn't give enhanced reset interrupt\n",
382 host
->host
->host_no
);
384 sbic_arm_write(host
->scsi
.io_port
, SBIC_CTRL
, INIT_SBICDMA
| CTRL_IDI
);
385 sbic_arm_write(host
->scsi
.io_port
, SBIC_TIMEOUT
, TIMEOUT_TIME
);
386 sbic_arm_write(host
->scsi
.io_port
, SBIC_SYNCHTRANSFER
, SYNCHTRANSFER_2DBA
);
387 sbic_arm_write(host
->scsi
.io_port
, SBIC_SOURCEID
, SOURCEID_ER
| SOURCEID_DSP
);
389 host
->card
.page_reg
= 0x40;
390 outb(host
->card
.page_reg
, host
->card
.io_page
);
392 /* setup dmac - uPC71071 */
393 dmac_write(host
->dma
.io_port
, DMAC_INIT
, 0);
395 dmac_write(host
->dma
.io_port
, DMAC_INIT
, INIT_8BIT
);
396 dmac_write(host
->dma
.io_port
, DMAC_CHANNEL
, CHANNEL_0
);
397 dmac_write(host
->dma
.io_port
, DMAC_DEVCON0
, INIT_DEVCON0
);
398 dmac_write(host
->dma
.io_port
, DMAC_DEVCON1
, INIT_DEVCON1
);
402 host
->scsi
.phase
= PHASE_IDLE
;
403 host
->scsi
.disconnectable
= 0;
405 memset(host
->busyluns
, 0, sizeof(host
->busyluns
));
407 for (i
= 0; i
< 8; i
++) {
408 host
->device
[i
].sync_state
= SYNC_NEGOCIATE
;
409 host
->device
[i
].disconnect_ok
= 1;
412 /* wait 25 cs. SCSI standard says 250ms. */
413 acornscsi_csdelay(25);
416 /*=============================================================================================
417 * Utility routines (eg. debug)
419 #ifdef CONFIG_ACORNSCSI_CONSTANTS
420 static char *acornscsi_interrupttype
[] = {
421 "rst", "suc", "p/a", "3",
422 "term", "5", "6", "7",
423 "serv", "9", "a", "b",
427 static signed char acornscsi_map
[] = {
428 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
429 -1, 2, -1, -1, -1, -1, 3, -1, 4, 5, 6, 7, 8, 9, 10, 11,
430 12, 13, 14, -1, -1, -1, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11,
431 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
432 15, 16, 17, 18, 19, -1, -1, 20, 4, 5, 6, 7, 8, 9, 10, 11,
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 21, 22, -1, -1, -1, 23, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11,
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,
439 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
440 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
441 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
442 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
443 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
446 static char *acornscsi_interruptcode
[] = {
448 "reset - normal mode", /* 00 */
449 "reset - advanced mode", /* 01 */
464 "/ACK asserted", /* 20 */
465 "save-data-ptr", /* 21 */
470 "unexpected disconnect", /* 41 */
471 "sel timeout", /* 42 */
473 "P err+ATN", /* 44 */
474 "bad status byte", /* 47 */
477 "resel, no id", /* 80 */
483 void print_scsi_status(unsigned int ssr
)
485 if (acornscsi_map
[ssr
] != -1)
487 acornscsi_interrupttype
[(ssr
>> 4)],
488 acornscsi_interruptcode
[acornscsi_map
[ssr
]]);
490 printk("%X:%X", ssr
>> 4, ssr
& 0x0f);
495 void print_sbic_status(int asr
, int ssr
, int cmdphase
)
497 #ifdef CONFIG_ACORNSCSI_CONSTANTS
498 printk("sbic: %c%c%c%c%c%c ",
499 asr
& ASR_INT
? 'I' : 'i',
500 asr
& ASR_LCI
? 'L' : 'l',
501 asr
& ASR_BSY
? 'B' : 'b',
502 asr
& ASR_CIP
? 'C' : 'c',
503 asr
& ASR_PE
? 'P' : 'p',
504 asr
& ASR_DBR
? 'D' : 'd');
506 print_scsi_status(ssr
);
507 printk(" ph %02X\n", cmdphase
);
509 printk("sbic: %02X scsi: %X:%X ph: %02X\n",
510 asr
, (ssr
& 0xf0)>>4, ssr
& 0x0f, cmdphase
);
515 acornscsi_dumplogline(AS_Host
*host
, int target
, int line
)
520 ptr
= host
->status_ptr
[target
] - STATUS_BUFFER_TO_PRINT
;
522 ptr
+= STATUS_BUFFER_SIZE
;
524 printk("%c: %3s:", target
== 8 ? 'H' : '0' + target
,
525 line
== 0 ? "ph" : line
== 1 ? "ssr" : "int");
527 prev
= host
->status
[target
][ptr
].when
;
529 for (; ptr
!= host
->status_ptr
[target
]; ptr
= (ptr
+ 1) & (STATUS_BUFFER_SIZE
- 1)) {
530 unsigned long time_diff
;
532 if (!host
->status
[target
][ptr
].when
)
537 printk("%c%02X", host
->status
[target
][ptr
].irq
? '-' : ' ',
538 host
->status
[target
][ptr
].ph
);
542 printk(" %02X", host
->status
[target
][ptr
].ssr
);
546 time_diff
= host
->status
[target
][ptr
].when
- prev
;
547 prev
= host
->status
[target
][ptr
].when
;
550 else if (time_diff
>= 100)
553 printk(" %02ld", time_diff
);
562 void acornscsi_dumplog(AS_Host
*host
, int target
)
565 acornscsi_dumplogline(host
, target
, 0);
566 acornscsi_dumplogline(host
, target
, 1);
567 acornscsi_dumplogline(host
, target
, 2);
577 char acornscsi_target(AS_Host
*host
)
580 return '0' + host
->SCpnt
->device
->id
;
585 * Prototype: cmdtype_t acornscsi_cmdtype(int command)
586 * Purpose : differentiate READ from WRITE from other commands
587 * Params : command - command to interpret
588 * Returns : CMD_READ - command reads data,
589 * CMD_WRITE - command writes data,
590 * CMD_MISC - everything else
593 cmdtype_t
acornscsi_cmdtype(int command
)
596 case WRITE_6
: case WRITE_10
: case WRITE_12
:
598 case READ_6
: case READ_10
: case READ_12
:
606 * Prototype: int acornscsi_datadirection(int command)
607 * Purpose : differentiate between commands that have a DATA IN phase
608 * and a DATA OUT phase
609 * Params : command - command to interpret
610 * Returns : DATADIR_OUT - data out phase expected
611 * DATADIR_IN - data in phase expected
614 datadir_t
acornscsi_datadirection(int command
)
617 case CHANGE_DEFINITION
: case COMPARE
: case COPY
:
618 case COPY_VERIFY
: case LOG_SELECT
: case MODE_SELECT
:
619 case MODE_SELECT_10
: case SEND_DIAGNOSTIC
: case WRITE_BUFFER
:
620 case FORMAT_UNIT
: case REASSIGN_BLOCKS
: case RESERVE
:
621 case SEARCH_EQUAL
: case SEARCH_HIGH
: case SEARCH_LOW
:
622 case WRITE_6
: case WRITE_10
: case WRITE_VERIFY
:
623 case UPDATE_BLOCK
: case WRITE_LONG
: case WRITE_SAME
:
624 case SEARCH_HIGH_12
: case SEARCH_EQUAL_12
: case SEARCH_LOW_12
:
625 case WRITE_12
: case WRITE_VERIFY_12
: case SET_WINDOW
:
626 case MEDIUM_SCAN
: case SEND_VOLUME_TAG
: case 0xea:
634 * Purpose : provide values for synchronous transfers with 33C93.
635 * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
636 * Modified by Russell King for 8MHz WD33C93A
638 static struct sync_xfer_tbl
{
639 unsigned int period_ns
;
640 unsigned char reg_value
;
641 } sync_xfer_table
[] = {
642 { 1, 0x20 }, { 249, 0x20 }, { 374, 0x30 },
643 { 499, 0x40 }, { 624, 0x50 }, { 749, 0x60 },
644 { 874, 0x70 }, { 999, 0x00 }, { 0, 0 }
648 * Prototype: int acornscsi_getperiod(unsigned char syncxfer)
649 * Purpose : period for the synchronous transfer setting
650 * Params : syncxfer SYNCXFER register value
651 * Returns : period in ns.
654 int acornscsi_getperiod(unsigned char syncxfer
)
659 if (syncxfer
== 0x10)
662 for (i
= 1; sync_xfer_table
[i
].period_ns
; i
++)
663 if (syncxfer
== sync_xfer_table
[i
].reg_value
)
664 return sync_xfer_table
[i
].period_ns
;
669 * Prototype: int round_period(unsigned int period)
670 * Purpose : return index into above table for a required REQ period
671 * Params : period - time (ns) for REQ
672 * Returns : table index
673 * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
676 int round_period(unsigned int period
)
680 for (i
= 1; sync_xfer_table
[i
].period_ns
; i
++) {
681 if ((period
<= sync_xfer_table
[i
].period_ns
) &&
682 (period
> sync_xfer_table
[i
- 1].period_ns
))
689 * Prototype: unsigned char calc_sync_xfer(unsigned int period, unsigned int offset)
690 * Purpose : calculate value for 33c93s SYNC register
691 * Params : period - time (ns) for REQ
692 * offset - offset in bytes between REQ/ACK
693 * Returns : value for SYNC register
694 * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
697 unsigned char calc_sync_xfer(unsigned int period
, unsigned int offset
)
699 return sync_xfer_table
[round_period(period
)].reg_value
|
700 ((offset
< SDTR_SIZE
) ? offset
: SDTR_SIZE
);
703 /* ====================================================================================
707 * Function: acornscsi_kick(AS_Host *host)
708 * Purpose : kick next command to interface
709 * Params : host - host to send command to
710 * Returns : INTR_IDLE if idle, otherwise INTR_PROCESSING
711 * Notes : interrupts are always disabled!
714 intr_ret_t
acornscsi_kick(AS_Host
*host
)
719 /* first check to see if a command is waiting to be executed */
720 SCpnt
= host
->origSCpnt
;
721 host
->origSCpnt
= NULL
;
723 /* retrieve next command */
725 SCpnt
= queue_remove_exclude(&host
->queues
.issue
, host
->busyluns
);
732 if (host
->scsi
.disconnectable
&& host
->SCpnt
) {
733 queue_add_cmd_tail(&host
->queues
.disconnected
, host
->SCpnt
);
734 host
->scsi
.disconnectable
= 0;
735 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
736 DBG(host
->SCpnt
, printk("scsi%d.%c: moved command to disconnected queue\n",
737 host
->host
->host_no
, acornscsi_target(host
)));
743 * If we have an interrupt pending, then we may have been reselected.
744 * In this case, we don't want to write to the registers
746 if (!(sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
) & (ASR_INT
|ASR_BSY
|ASR_CIP
))) {
747 sbic_arm_write(host
->scsi
.io_port
, SBIC_DESTID
, SCpnt
->device
->id
);
748 sbic_arm_write(host
->scsi
.io_port
, SBIC_CMND
, CMND_SELWITHATN
);
752 * claim host busy - all of these must happen atomically wrt
753 * our interrupt routine. Failure means command loss.
755 host
->scsi
.phase
= PHASE_CONNECTING
;
757 host
->scsi
.SCp
= SCpnt
->SCp
;
758 host
->dma
.xfer_setup
= 0;
759 host
->dma
.xfer_required
= 0;
760 host
->dma
.xfer_done
= 0;
762 #if (DEBUG & (DEBUG_ABORT|DEBUG_CONNECT))
763 DBG(SCpnt
,printk("scsi%d.%c: starting cmd %02X\n",
764 host
->host
->host_no
, '0' + SCpnt
->device
->id
,
769 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
771 * tagged queueing - allocate a new tag to this command
773 if (SCpnt
->device
->simple_tags
) {
774 SCpnt
->device
->current_tag
+= 1;
775 if (SCpnt
->device
->current_tag
== 0)
776 SCpnt
->device
->current_tag
= 1;
777 SCpnt
->tag
= SCpnt
->device
->current_tag
;
780 set_bit(SCpnt
->device
->id
* 8 + SCpnt
->device
->lun
, host
->busyluns
);
782 host
->stats
.removes
+= 1;
784 switch (acornscsi_cmdtype(SCpnt
->cmnd
[0])) {
786 host
->stats
.writes
+= 1;
789 host
->stats
.reads
+= 1;
792 host
->stats
.miscs
+= 1;
797 return INTR_PROCESSING
;
801 * Function: void acornscsi_done(AS_Host *host, Scsi_Cmnd **SCpntp, unsigned int result)
802 * Purpose : complete processing for command
803 * Params : host - interface that completed
804 * result - driver byte of result
807 void acornscsi_done(AS_Host
*host
, Scsi_Cmnd
**SCpntp
, unsigned int result
)
809 Scsi_Cmnd
*SCpnt
= *SCpntp
;
812 sbic_arm_write(host
->scsi
.io_port
, SBIC_SOURCEID
, SOURCEID_ER
| SOURCEID_DSP
);
814 host
->stats
.fins
+= 1;
819 acornscsi_dma_cleanup(host
);
821 SCpnt
->result
= result
<< 16 | host
->scsi
.SCp
.Message
<< 8 | host
->scsi
.SCp
.Status
;
824 * In theory, this should not happen. In practice, it seems to.
825 * Only trigger an error if the device attempts to report all happy
826 * but with untransferred buffers... If we don't do something, then
827 * data loss will occur. Should we check SCpnt->underflow here?
828 * It doesn't appear to be set to something meaningful by the higher
829 * levels all the time.
831 if (result
== DID_OK
) {
834 if (SCpnt
->underflow
== 0) {
835 if (host
->scsi
.SCp
.ptr
&&
836 acornscsi_cmdtype(SCpnt
->cmnd
[0]) != CMD_MISC
)
839 if (host
->scsi
.SCp
.scsi_xferred
< SCpnt
->underflow
||
840 host
->scsi
.SCp
.scsi_xferred
!= host
->dma
.transferred
)
844 /* ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.6)
845 * Targets which break data transfers into multiple
846 * connections shall end each successful connection
847 * (except possibly the last) with a SAVE DATA
848 * POINTER - DISCONNECT message sequence.
850 * This makes it difficult to ensure that a transfer has
851 * completed. If we reach the end of a transfer during
852 * the command, then we can only have finished the transfer.
853 * therefore, if we seem to have some data remaining, this
856 if (host
->dma
.xfer_done
)
860 switch (status_byte(SCpnt
->result
)) {
861 case CHECK_CONDITION
:
862 case COMMAND_TERMINATED
:
865 case RESERVATION_CONFLICT
:
869 printk(KERN_ERR
"scsi%d.H: incomplete data transfer detected: result=%08X command=",
870 host
->host
->host_no
, SCpnt
->result
);
871 __scsi_print_command(SCpnt
->cmnd
);
872 acornscsi_dumpdma(host
, "done");
873 acornscsi_dumplog(host
, SCpnt
->device
->id
);
874 SCpnt
->result
&= 0xffff;
875 SCpnt
->result
|= DID_ERROR
<< 16;
880 if (!SCpnt
->scsi_done
)
881 panic("scsi%d.H: null scsi_done function in acornscsi_done", host
->host
->host_no
);
883 clear_bit(SCpnt
->device
->id
* 8 + SCpnt
->device
->lun
, host
->busyluns
);
885 SCpnt
->scsi_done(SCpnt
);
887 printk("scsi%d: null command in acornscsi_done", host
->host
->host_no
);
889 host
->scsi
.phase
= PHASE_IDLE
;
892 /* ====================================================================================
896 * Purpose : update SCSI Data Pointer
897 * Notes : this will only be one SG entry or less
900 void acornscsi_data_updateptr(AS_Host
*host
, struct scsi_pointer
*SCp
, unsigned int length
)
903 SCp
->this_residual
-= length
;
905 if (SCp
->this_residual
== 0 && next_SCp(SCp
) == 0)
906 host
->dma
.xfer_done
= 1;
910 * Prototype: void acornscsi_data_read(AS_Host *host, char *ptr,
911 * unsigned int start_addr, unsigned int length)
912 * Purpose : read data from DMA RAM
913 * Params : host - host to transfer from
915 * start_addr - host mem address
916 * length - number of bytes to transfer
917 * Notes : this will only be one SG entry or less
920 void acornscsi_data_read(AS_Host
*host
, char *ptr
,
921 unsigned int start_addr
, unsigned int length
)
923 extern void __acornscsi_in(int port
, char *buf
, int len
);
924 unsigned int page
, offset
, len
= length
;
926 page
= (start_addr
>> 12);
927 offset
= start_addr
& ((1 << 12) - 1);
929 outb((page
& 0x3f) | host
->card
.page_reg
, host
->card
.io_page
);
932 unsigned int this_len
;
934 if (len
+ offset
> (1 << 12))
935 this_len
= (1 << 12) - offset
;
939 __acornscsi_in(host
->card
.io_ram
+ (offset
<< 1), ptr
, this_len
);
945 if (offset
== (1 << 12)) {
948 outb((page
& 0x3f) | host
->card
.page_reg
, host
->card
.io_page
);
951 outb(host
->card
.page_reg
, host
->card
.io_page
);
955 * Prototype: void acornscsi_data_write(AS_Host *host, char *ptr,
956 * unsigned int start_addr, unsigned int length)
957 * Purpose : write data to DMA RAM
958 * Params : host - host to transfer from
960 * start_addr - host mem address
961 * length - number of bytes to transfer
962 * Notes : this will only be one SG entry or less
965 void acornscsi_data_write(AS_Host
*host
, char *ptr
,
966 unsigned int start_addr
, unsigned int length
)
968 extern void __acornscsi_out(int port
, char *buf
, int len
);
969 unsigned int page
, offset
, len
= length
;
971 page
= (start_addr
>> 12);
972 offset
= start_addr
& ((1 << 12) - 1);
974 outb((page
& 0x3f) | host
->card
.page_reg
, host
->card
.io_page
);
977 unsigned int this_len
;
979 if (len
+ offset
> (1 << 12))
980 this_len
= (1 << 12) - offset
;
984 __acornscsi_out(host
->card
.io_ram
+ (offset
<< 1), ptr
, this_len
);
990 if (offset
== (1 << 12)) {
993 outb((page
& 0x3f) | host
->card
.page_reg
, host
->card
.io_page
);
996 outb(host
->card
.page_reg
, host
->card
.io_page
);
999 /* =========================================================================================
1000 * On-board DMA routines
1004 * Prototype: void acornscsi_dmastop(AS_Host *host)
1005 * Purpose : stop all DMA
1006 * Params : host - host on which to stop DMA
1007 * Notes : This is called when leaving DATA IN/OUT phase,
1008 * or when interface is RESET
1011 void acornscsi_dma_stop(AS_Host
*host
)
1013 dmac_write(host
->dma
.io_port
, DMAC_MASKREG
, MASK_ON
);
1014 dmac_clearintr(host
->dma
.io_intr_clear
);
1016 #if (DEBUG & DEBUG_DMA)
1017 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "stop"));
1022 * Function: void acornscsi_dma_setup(AS_Host *host, dmadir_t direction)
1023 * Purpose : setup DMA controller for data transfer
1024 * Params : host - host to setup
1025 * direction - data transfer direction
1026 * Notes : This is called when entering DATA I/O phase, not
1027 * while we're in a DATA I/O phase
1030 void acornscsi_dma_setup(AS_Host
*host
, dmadir_t direction
)
1032 unsigned int address
, length
, mode
;
1034 host
->dma
.direction
= direction
;
1036 dmac_write(host
->dma
.io_port
, DMAC_MASKREG
, MASK_ON
);
1038 if (direction
== DMA_OUT
) {
1039 #if (DEBUG & DEBUG_NO_WRITE)
1040 if (NO_WRITE
& (1 << host
->SCpnt
->device
->id
)) {
1041 printk(KERN_CRIT
"scsi%d.%c: I can't handle DMA_OUT!\n",
1042 host
->host
->host_no
, acornscsi_target(host
));
1051 * Allocate some buffer space, limited to half the buffer size
1053 length
= min_t(unsigned int, host
->scsi
.SCp
.this_residual
, DMAC_BUFFER_SIZE
/ 2);
1055 host
->dma
.start_addr
= address
= host
->dma
.free_addr
;
1056 host
->dma
.free_addr
= (host
->dma
.free_addr
+ length
) &
1057 (DMAC_BUFFER_SIZE
- 1);
1060 * Transfer data to DMA memory
1062 if (direction
== DMA_OUT
)
1063 acornscsi_data_write(host
, host
->scsi
.SCp
.ptr
, host
->dma
.start_addr
,
1067 dmac_write(host
->dma
.io_port
, DMAC_TXCNTLO
, length
);
1068 dmac_write(host
->dma
.io_port
, DMAC_TXCNTHI
, length
>> 8);
1069 dmac_write(host
->dma
.io_port
, DMAC_TXADRLO
, address
);
1070 dmac_write(host
->dma
.io_port
, DMAC_TXADRMD
, address
>> 8);
1071 dmac_write(host
->dma
.io_port
, DMAC_TXADRHI
, 0);
1072 dmac_write(host
->dma
.io_port
, DMAC_MODECON
, mode
);
1073 dmac_write(host
->dma
.io_port
, DMAC_MASKREG
, MASK_OFF
);
1075 #if (DEBUG & DEBUG_DMA)
1076 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "strt"));
1078 host
->dma
.xfer_setup
= 1;
1083 * Function: void acornscsi_dma_cleanup(AS_Host *host)
1084 * Purpose : ensure that all DMA transfers are up-to-date & host->scsi.SCp is correct
1085 * Params : host - host to finish
1086 * Notes : This is called when a command is:
1087 * terminating, RESTORE_POINTERS, SAVE_POINTERS, DISCONECT
1088 * : This must not return until all transfers are completed.
1091 void acornscsi_dma_cleanup(AS_Host
*host
)
1093 dmac_write(host
->dma
.io_port
, DMAC_MASKREG
, MASK_ON
);
1094 dmac_clearintr(host
->dma
.io_intr_clear
);
1097 * Check for a pending transfer
1099 if (host
->dma
.xfer_required
) {
1100 host
->dma
.xfer_required
= 0;
1101 if (host
->dma
.direction
== DMA_IN
)
1102 acornscsi_data_read(host
, host
->dma
.xfer_ptr
,
1103 host
->dma
.xfer_start
, host
->dma
.xfer_length
);
1107 * Has a transfer been setup?
1109 if (host
->dma
.xfer_setup
) {
1110 unsigned int transferred
;
1112 host
->dma
.xfer_setup
= 0;
1114 #if (DEBUG & DEBUG_DMA)
1115 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "cupi"));
1119 * Calculate number of bytes transferred from DMA.
1121 transferred
= dmac_address(host
->dma
.io_port
) - host
->dma
.start_addr
;
1122 host
->dma
.transferred
+= transferred
;
1124 if (host
->dma
.direction
== DMA_IN
)
1125 acornscsi_data_read(host
, host
->scsi
.SCp
.ptr
,
1126 host
->dma
.start_addr
, transferred
);
1129 * Update SCSI pointers
1131 acornscsi_data_updateptr(host
, &host
->scsi
.SCp
, transferred
);
1132 #if (DEBUG & DEBUG_DMA)
1133 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "cupo"));
1139 * Function: void acornscsi_dmacintr(AS_Host *host)
1140 * Purpose : handle interrupts from DMAC device
1141 * Params : host - host to process
1142 * Notes : If reading, we schedule the read to main memory &
1143 * allow the transfer to continue.
1144 * : If writing, we fill the onboard DMA memory from main
1146 * : Called whenever DMAC finished it's current transfer.
1149 void acornscsi_dma_intr(AS_Host
*host
)
1151 unsigned int address
, length
, transferred
;
1153 #if (DEBUG & DEBUG_DMA)
1154 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "inti"));
1157 dmac_write(host
->dma
.io_port
, DMAC_MASKREG
, MASK_ON
);
1158 dmac_clearintr(host
->dma
.io_intr_clear
);
1161 * Calculate amount transferred via DMA
1163 transferred
= dmac_address(host
->dma
.io_port
) - host
->dma
.start_addr
;
1164 host
->dma
.transferred
+= transferred
;
1167 * Schedule DMA transfer off board
1169 if (host
->dma
.direction
== DMA_IN
) {
1170 host
->dma
.xfer_start
= host
->dma
.start_addr
;
1171 host
->dma
.xfer_length
= transferred
;
1172 host
->dma
.xfer_ptr
= host
->scsi
.SCp
.ptr
;
1173 host
->dma
.xfer_required
= 1;
1176 acornscsi_data_updateptr(host
, &host
->scsi
.SCp
, transferred
);
1179 * Allocate some buffer space, limited to half the on-board RAM size
1181 length
= min_t(unsigned int, host
->scsi
.SCp
.this_residual
, DMAC_BUFFER_SIZE
/ 2);
1183 host
->dma
.start_addr
= address
= host
->dma
.free_addr
;
1184 host
->dma
.free_addr
= (host
->dma
.free_addr
+ length
) &
1185 (DMAC_BUFFER_SIZE
- 1);
1188 * Transfer data to DMA memory
1190 if (host
->dma
.direction
== DMA_OUT
)
1191 acornscsi_data_write(host
, host
->scsi
.SCp
.ptr
, host
->dma
.start_addr
,
1195 dmac_write(host
->dma
.io_port
, DMAC_TXCNTLO
, length
);
1196 dmac_write(host
->dma
.io_port
, DMAC_TXCNTHI
, length
>> 8);
1197 dmac_write(host
->dma
.io_port
, DMAC_TXADRLO
, address
);
1198 dmac_write(host
->dma
.io_port
, DMAC_TXADRMD
, address
>> 8);
1199 dmac_write(host
->dma
.io_port
, DMAC_TXADRHI
, 0);
1200 dmac_write(host
->dma
.io_port
, DMAC_MASKREG
, MASK_OFF
);
1202 #if (DEBUG & DEBUG_DMA)
1203 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "into"));
1206 host
->dma
.xfer_setup
= 0;
1209 * If the interface still wants more, then this is an error.
1210 * We give it another byte, but we also attempt to raise an
1211 * attention condition. We continue giving one byte until
1212 * the device recognises the attention.
1214 if (dmac_read(host
->dma
.io_port
, DMAC_STATUS
) & STATUS_RQ0
) {
1215 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
1217 dmac_write(host
->dma
.io_port
, DMAC_TXCNTLO
, 0);
1218 dmac_write(host
->dma
.io_port
, DMAC_TXCNTHI
, 0);
1219 dmac_write(host
->dma
.io_port
, DMAC_TXADRLO
, 0);
1220 dmac_write(host
->dma
.io_port
, DMAC_TXADRMD
, 0);
1221 dmac_write(host
->dma
.io_port
, DMAC_TXADRHI
, 0);
1222 dmac_write(host
->dma
.io_port
, DMAC_MASKREG
, MASK_OFF
);
1229 * Function: void acornscsi_dma_xfer(AS_Host *host)
1230 * Purpose : transfer data between AcornSCSI and memory
1231 * Params : host - host to process
1234 void acornscsi_dma_xfer(AS_Host
*host
)
1236 host
->dma
.xfer_required
= 0;
1238 if (host
->dma
.direction
== DMA_IN
)
1239 acornscsi_data_read(host
, host
->dma
.xfer_ptr
,
1240 host
->dma
.xfer_start
, host
->dma
.xfer_length
);
1244 * Function: void acornscsi_dma_adjust(AS_Host *host)
1245 * Purpose : adjust DMA pointers & count for bytes transferred to
1246 * SBIC but not SCSI bus.
1247 * Params : host - host to adjust DMA count for
1250 void acornscsi_dma_adjust(AS_Host
*host
)
1252 if (host
->dma
.xfer_setup
) {
1253 signed long transferred
;
1254 #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
1255 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "adji"));
1258 * Calculate correct DMA address - DMA is ahead of SCSI bus while
1260 * host->scsi.SCp.scsi_xferred is the number of bytes
1261 * actually transferred to/from the SCSI bus.
1262 * host->dma.transferred is the number of bytes transferred
1263 * over DMA since host->dma.start_addr was last set.
1265 * real_dma_addr = host->dma.start_addr + host->scsi.SCp.scsi_xferred
1266 * - host->dma.transferred
1268 transferred
= host
->scsi
.SCp
.scsi_xferred
- host
->dma
.transferred
;
1269 if (transferred
< 0)
1270 printk("scsi%d.%c: Ack! DMA write correction %ld < 0!\n",
1271 host
->host
->host_no
, acornscsi_target(host
), transferred
);
1272 else if (transferred
== 0)
1273 host
->dma
.xfer_setup
= 0;
1275 transferred
+= host
->dma
.start_addr
;
1276 dmac_write(host
->dma
.io_port
, DMAC_TXADRLO
, transferred
);
1277 dmac_write(host
->dma
.io_port
, DMAC_TXADRMD
, transferred
>> 8);
1278 dmac_write(host
->dma
.io_port
, DMAC_TXADRHI
, transferred
>> 16);
1279 #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
1280 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "adjo"));
1287 /* =========================================================================================
1291 acornscsi_write_pio(AS_Host
*host
, char *bytes
, int *ptr
, int len
, unsigned int max_timeout
)
1293 unsigned int asr
, timeout
= max_timeout
;
1296 while (my_ptr
< len
) {
1297 asr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
1299 if (asr
& ASR_DBR
) {
1300 timeout
= max_timeout
;
1302 sbic_arm_write(host
->scsi
.io_port
, SBIC_DATA
, bytes
[my_ptr
++]);
1303 } else if (asr
& ASR_INT
)
1305 else if (--timeout
== 0)
1312 return (timeout
== 0) ? -1 : 0;
1316 * Function: void acornscsi_sendcommand(AS_Host *host)
1317 * Purpose : send a command to a target
1318 * Params : host - host which is connected to target
1321 acornscsi_sendcommand(AS_Host
*host
)
1323 Scsi_Cmnd
*SCpnt
= host
->SCpnt
;
1325 sbic_arm_write(host
->scsi
.io_port
, SBIC_TRANSCNTH
, 0);
1326 sbic_arm_writenext(host
->scsi
.io_port
, 0);
1327 sbic_arm_writenext(host
->scsi
.io_port
, SCpnt
->cmd_len
- host
->scsi
.SCp
.sent_command
);
1329 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
);
1331 if (acornscsi_write_pio(host
, SCpnt
->cmnd
,
1332 (int *)&host
->scsi
.SCp
.sent_command
, SCpnt
->cmd_len
, 1000000))
1333 printk("scsi%d: timeout while sending command\n", host
->host
->host_no
);
1335 host
->scsi
.phase
= PHASE_COMMAND
;
1339 void acornscsi_sendmessage(AS_Host
*host
)
1341 unsigned int message_length
= msgqueue_msglength(&host
->scsi
.msgs
);
1343 struct message
*msg
;
1345 #if (DEBUG & DEBUG_MESSAGES)
1346 printk("scsi%d.%c: sending message ",
1347 host
->host
->host_no
, acornscsi_target(host
));
1350 switch (message_length
) {
1352 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
| CMND_SBT
);
1354 acornscsi_sbic_wait(host
, ASR_DBR
, ASR_DBR
, 1000, "sending message 1");
1356 sbic_arm_write(host
->scsi
.io_port
, SBIC_DATA
, NOP
);
1358 host
->scsi
.last_message
= NOP
;
1359 #if (DEBUG & DEBUG_MESSAGES)
1365 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
| CMND_SBT
);
1366 msg
= msgqueue_getmsg(&host
->scsi
.msgs
, 0);
1368 acornscsi_sbic_wait(host
, ASR_DBR
, ASR_DBR
, 1000, "sending message 2");
1370 sbic_arm_write(host
->scsi
.io_port
, SBIC_DATA
, msg
->msg
[0]);
1372 host
->scsi
.last_message
= msg
->msg
[0];
1373 #if (DEBUG & DEBUG_MESSAGES)
1374 spi_print_msg(msg
->msg
);
1380 * ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.14)
1381 * 'When a target sends this (MESSAGE_REJECT) message, it
1382 * shall change to MESSAGE IN phase and send this message
1383 * prior to requesting additional message bytes from the
1384 * initiator. This provides an interlock so that the
1385 * initiator can determine which message byte is rejected.
1387 sbic_arm_write(host
->scsi
.io_port
, SBIC_TRANSCNTH
, 0);
1388 sbic_arm_writenext(host
->scsi
.io_port
, 0);
1389 sbic_arm_writenext(host
->scsi
.io_port
, message_length
);
1390 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
);
1393 while ((msg
= msgqueue_getmsg(&host
->scsi
.msgs
, msgnr
++)) != NULL
) {
1395 #if (DEBUG & DEBUG_MESSAGES)
1399 if (acornscsi_write_pio(host
, msg
->msg
, &i
, msg
->length
, 1000000))
1400 printk("scsi%d: timeout while sending message\n", host
->host
->host_no
);
1402 host
->scsi
.last_message
= msg
->msg
[0];
1403 if (msg
->msg
[0] == EXTENDED_MESSAGE
)
1404 host
->scsi
.last_message
|= msg
->msg
[2] << 8;
1406 if (i
!= msg
->length
)
1411 #if (DEBUG & DEBUG_MESSAGES)
1417 * Function: void acornscsi_readstatusbyte(AS_Host *host)
1418 * Purpose : Read status byte from connected target
1419 * Params : host - host connected to target
1422 void acornscsi_readstatusbyte(AS_Host
*host
)
1424 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
|CMND_SBT
);
1425 acornscsi_sbic_wait(host
, ASR_DBR
, ASR_DBR
, 1000, "reading status byte");
1426 host
->scsi
.SCp
.Status
= sbic_arm_read(host
->scsi
.io_port
, SBIC_DATA
);
1430 * Function: unsigned char acornscsi_readmessagebyte(AS_Host *host)
1431 * Purpose : Read one message byte from connected target
1432 * Params : host - host connected to target
1435 unsigned char acornscsi_readmessagebyte(AS_Host
*host
)
1437 unsigned char message
;
1439 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
| CMND_SBT
);
1441 acornscsi_sbic_wait(host
, ASR_DBR
, ASR_DBR
, 1000, "for message byte");
1443 message
= sbic_arm_read(host
->scsi
.io_port
, SBIC_DATA
);
1445 /* wait for MSGIN-XFER-PAUSED */
1446 acornscsi_sbic_wait(host
, ASR_INT
, ASR_INT
, 1000, "for interrupt after message byte");
1448 sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
);
1454 * Function: void acornscsi_message(AS_Host *host)
1455 * Purpose : Read complete message from connected target & action message
1456 * Params : host - host connected to target
1459 void acornscsi_message(AS_Host
*host
)
1461 unsigned char message
[16];
1462 unsigned int msgidx
= 0, msglen
= 1;
1465 message
[msgidx
] = acornscsi_readmessagebyte(host
);
1469 if (message
[0] == EXTENDED_MESSAGE
||
1470 (message
[0] >= 0x20 && message
[0] <= 0x2f))
1475 if (message
[0] == EXTENDED_MESSAGE
)
1476 msglen
+= message
[msgidx
];
1480 if (msgidx
< msglen
) {
1481 acornscsi_sbic_issuecmd(host
, CMND_NEGATEACK
);
1483 /* wait for next msg-in */
1484 acornscsi_sbic_wait(host
, ASR_INT
, ASR_INT
, 1000, "for interrupt after negate ack");
1485 sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
);
1487 } while (msgidx
< msglen
);
1489 #if (DEBUG & DEBUG_MESSAGES)
1490 printk("scsi%d.%c: message in: ",
1491 host
->host
->host_no
, acornscsi_target(host
));
1492 spi_print_msg(message
);
1496 if (host
->scsi
.phase
== PHASE_RECONNECTED
) {
1498 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
1499 * 'Whenever a target reconnects to an initiator to continue
1500 * a tagged I/O process, the SIMPLE QUEUE TAG message shall
1501 * be sent immediately following the IDENTIFY message...'
1503 if (message
[0] == SIMPLE_QUEUE_TAG
)
1504 host
->scsi
.reconnected
.tag
= message
[1];
1505 if (acornscsi_reconnect_finish(host
))
1506 host
->scsi
.phase
= PHASE_MSGIN
;
1509 switch (message
[0]) {
1512 case COMMAND_COMPLETE
:
1513 if (host
->scsi
.phase
!= PHASE_STATUSIN
) {
1514 printk(KERN_ERR
"scsi%d.%c: command complete following non-status in phase?\n",
1515 host
->host
->host_no
, acornscsi_target(host
));
1516 acornscsi_dumplog(host
, host
->SCpnt
->device
->id
);
1518 host
->scsi
.phase
= PHASE_DONE
;
1519 host
->scsi
.SCp
.Message
= message
[0];
1524 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.20)
1525 * 'The SAVE DATA POINTER message is sent from a target to
1526 * direct the initiator to copy the active data pointer to
1527 * the saved data pointer for the current I/O process.
1529 acornscsi_dma_cleanup(host
);
1530 host
->SCpnt
->SCp
= host
->scsi
.SCp
;
1531 host
->SCpnt
->SCp
.sent_command
= 0;
1532 host
->scsi
.phase
= PHASE_MSGIN
;
1535 case RESTORE_POINTERS
:
1537 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.19)
1538 * 'The RESTORE POINTERS message is sent from a target to
1539 * direct the initiator to copy the most recently saved
1540 * command, data, and status pointers for the I/O process
1541 * to the corresponding active pointers. The command and
1542 * status pointers shall be restored to the beginning of
1543 * the present command and status areas.'
1545 acornscsi_dma_cleanup(host
);
1546 host
->scsi
.SCp
= host
->SCpnt
->SCp
;
1547 host
->scsi
.phase
= PHASE_MSGIN
;
1552 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 6.4.2)
1553 * 'On those occasions when an error or exception condition occurs
1554 * and the target elects to repeat the information transfer, the
1555 * target may repeat the transfer either issuing a RESTORE POINTERS
1556 * message or by disconnecting without issuing a SAVE POINTERS
1557 * message. When reconnection is completed, the most recent
1558 * saved pointer values are restored.'
1560 acornscsi_dma_cleanup(host
);
1561 host
->scsi
.phase
= PHASE_DISCONNECT
;
1564 case MESSAGE_REJECT
:
1565 #if 0 /* this isn't needed any more */
1567 * If we were negociating sync transfer, we don't yet know if
1568 * this REJECT is for the sync transfer or for the tagged queue/wide
1569 * transfer. Re-initiate sync transfer negociation now, and if
1570 * we got a REJECT in response to SDTR, then it'll be set to DONE.
1572 if (host
->device
[host
->SCpnt
->device
->id
].sync_state
== SYNC_SENT_REQUEST
)
1573 host
->device
[host
->SCpnt
->device
->id
].sync_state
= SYNC_NEGOCIATE
;
1577 * If we have any messages waiting to go out, then assert ATN now
1579 if (msgqueue_msglength(&host
->scsi
.msgs
))
1580 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1582 switch (host
->scsi
.last_message
) {
1583 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
1584 case HEAD_OF_QUEUE_TAG
:
1585 case ORDERED_QUEUE_TAG
:
1586 case SIMPLE_QUEUE_TAG
:
1588 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
1589 * If a target does not implement tagged queuing and a queue tag
1590 * message is received, it shall respond with a MESSAGE REJECT
1591 * message and accept the I/O process as if it were untagged.
1593 printk(KERN_NOTICE
"scsi%d.%c: disabling tagged queueing\n",
1594 host
->host
->host_no
, acornscsi_target(host
));
1595 host
->SCpnt
->device
->simple_tags
= 0;
1596 set_bit(host
->SCpnt
->device
->id
* 8 + host
->SCpnt
->device
->lun
, host
->busyluns
);
1599 case EXTENDED_MESSAGE
| (EXTENDED_SDTR
<< 8):
1601 * Target can't handle synchronous transfers
1603 printk(KERN_NOTICE
"scsi%d.%c: Using asynchronous transfer\n",
1604 host
->host
->host_no
, acornscsi_target(host
));
1605 host
->device
[host
->SCpnt
->device
->id
].sync_xfer
= SYNCHTRANSFER_2DBA
;
1606 host
->device
[host
->SCpnt
->device
->id
].sync_state
= SYNC_ASYNCHRONOUS
;
1607 sbic_arm_write(host
->scsi
.io_port
, SBIC_SYNCHTRANSFER
, host
->device
[host
->SCpnt
->device
->id
].sync_xfer
);
1616 /* TODO: target queue is full */
1619 case SIMPLE_QUEUE_TAG
:
1620 /* tag queue reconnect... message[1] = queue tag. Print something to indicate something happened! */
1621 printk("scsi%d.%c: reconnect queue tag %02X\n",
1622 host
->host
->host_no
, acornscsi_target(host
),
1626 case EXTENDED_MESSAGE
:
1627 switch (message
[2]) {
1628 #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
1630 if (host
->device
[host
->SCpnt
->device
->id
].sync_state
== SYNC_SENT_REQUEST
) {
1632 * We requested synchronous transfers. This isn't quite right...
1633 * We can only say if this succeeded if we proceed on to execute the
1634 * command from this message. If we get a MESSAGE PARITY ERROR,
1635 * and the target retries fail, then we fallback to asynchronous mode
1637 host
->device
[host
->SCpnt
->device
->id
].sync_state
= SYNC_COMPLETED
;
1638 printk(KERN_NOTICE
"scsi%d.%c: Using synchronous transfer, offset %d, %d ns\n",
1639 host
->host
->host_no
, acornscsi_target(host
),
1640 message
[4], message
[3] * 4);
1641 host
->device
[host
->SCpnt
->device
->id
].sync_xfer
=
1642 calc_sync_xfer(message
[3] * 4, message
[4]);
1644 unsigned char period
, length
;
1646 * Target requested synchronous transfers. The agreement is only
1647 * to be in operation AFTER the target leaves message out phase.
1649 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1650 period
= max_t(unsigned int, message
[3], sdtr_period
/ 4);
1651 length
= min_t(unsigned int, message
[4], sdtr_size
);
1652 msgqueue_addmsg(&host
->scsi
.msgs
, 5, EXTENDED_MESSAGE
, 3,
1653 EXTENDED_SDTR
, period
, length
);
1654 host
->device
[host
->SCpnt
->device
->id
].sync_xfer
=
1655 calc_sync_xfer(period
* 4, length
);
1657 sbic_arm_write(host
->scsi
.io_port
, SBIC_SYNCHTRANSFER
, host
->device
[host
->SCpnt
->device
->id
].sync_xfer
);
1660 /* We do not accept synchronous transfers. Respond with a
1666 /* The WD33C93A is only 8-bit. We respond with a MESSAGE_REJECT
1667 * to a wide data transfer request.
1670 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1671 msgqueue_flush(&host
->scsi
.msgs
);
1672 msgqueue_addmsg(&host
->scsi
.msgs
, 1, MESSAGE_REJECT
);
1677 #ifdef CONFIG_SCSI_ACORNSCSI_LINK
1678 case LINKED_CMD_COMPLETE
:
1679 case LINKED_FLG_CMD_COMPLETE
:
1681 * We don't support linked commands yet
1684 #if (DEBUG & DEBUG_LINK)
1685 printk("scsi%d.%c: lun %d tag %d linked command complete\n",
1686 host
->host
->host_no
, acornscsi_target(host
), host
->SCpnt
->tag
);
1689 * A linked command should only terminate with one of these messages
1690 * if there are more linked commands available.
1692 if (!host
->SCpnt
->next_link
) {
1693 printk(KERN_WARNING
"scsi%d.%c: lun %d tag %d linked command complete, but no next_link\n",
1694 instance
->host_no
, acornscsi_target(host
), host
->SCpnt
->tag
);
1695 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1696 msgqueue_addmsg(&host
->scsi
.msgs
, 1, ABORT
);
1698 Scsi_Cmnd
*SCpnt
= host
->SCpnt
;
1700 acornscsi_dma_cleanup(host
);
1702 host
->SCpnt
= host
->SCpnt
->next_link
;
1703 host
->SCpnt
->tag
= SCpnt
->tag
;
1704 SCpnt
->result
= DID_OK
| host
->scsi
.SCp
.Message
<< 8 | host
->Scsi
.SCp
.Status
;
1707 /* initialise host->SCpnt->SCp */
1713 default: /* reject message */
1714 printk(KERN_ERR
"scsi%d.%c: unrecognised message %02X, rejecting\n",
1715 host
->host
->host_no
, acornscsi_target(host
),
1717 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1718 msgqueue_flush(&host
->scsi
.msgs
);
1719 msgqueue_addmsg(&host
->scsi
.msgs
, 1, MESSAGE_REJECT
);
1720 host
->scsi
.phase
= PHASE_MSGIN
;
1723 acornscsi_sbic_issuecmd(host
, CMND_NEGATEACK
);
1727 * Function: int acornscsi_buildmessages(AS_Host *host)
1728 * Purpose : build the connection messages for a host
1729 * Params : host - host to add messages to
1732 void acornscsi_buildmessages(AS_Host
*host
)
1735 /* does the device need resetting? */
1737 msgqueue_addmsg(&host
->scsi
.msgs
, 1, BUS_DEVICE_RESET
);
1742 msgqueue_addmsg(&host
->scsi
.msgs
, 1,
1743 IDENTIFY(host
->device
[host
->SCpnt
->device
->id
].disconnect_ok
,
1744 host
->SCpnt
->device
->lun
));
1747 /* does the device need the current command aborted */
1749 acornscsi_abortcmd(host
->SCpnt
->tag
);
1754 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
1755 if (host
->SCpnt
->tag
) {
1756 unsigned int tag_type
;
1758 if (host
->SCpnt
->cmnd
[0] == REQUEST_SENSE
||
1759 host
->SCpnt
->cmnd
[0] == TEST_UNIT_READY
||
1760 host
->SCpnt
->cmnd
[0] == INQUIRY
)
1761 tag_type
= HEAD_OF_QUEUE_TAG
;
1763 tag_type
= SIMPLE_QUEUE_TAG
;
1764 msgqueue_addmsg(&host
->scsi
.msgs
, 2, tag_type
, host
->SCpnt
->tag
);
1768 #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
1769 if (host
->device
[host
->SCpnt
->device
->id
].sync_state
== SYNC_NEGOCIATE
) {
1770 host
->device
[host
->SCpnt
->device
->id
].sync_state
= SYNC_SENT_REQUEST
;
1771 msgqueue_addmsg(&host
->scsi
.msgs
, 5,
1772 EXTENDED_MESSAGE
, 3, EXTENDED_SDTR
,
1773 sdtr_period
/ 4, sdtr_size
);
1779 * Function: int acornscsi_starttransfer(AS_Host *host)
1780 * Purpose : transfer data to/from connected target
1781 * Params : host - host to which target is connected
1782 * Returns : 0 if failure
1785 int acornscsi_starttransfer(AS_Host
*host
)
1789 if (!host
->scsi
.SCp
.ptr
/*&& host->scsi.SCp.this_residual*/) {
1790 printk(KERN_ERR
"scsi%d.%c: null buffer passed to acornscsi_starttransfer\n",
1791 host
->host
->host_no
, acornscsi_target(host
));
1795 residual
= host
->SCpnt
->request_bufflen
- host
->scsi
.SCp
.scsi_xferred
;
1797 sbic_arm_write(host
->scsi
.io_port
, SBIC_SYNCHTRANSFER
, host
->device
[host
->SCpnt
->device
->id
].sync_xfer
);
1798 sbic_arm_writenext(host
->scsi
.io_port
, residual
>> 16);
1799 sbic_arm_writenext(host
->scsi
.io_port
, residual
>> 8);
1800 sbic_arm_writenext(host
->scsi
.io_port
, residual
);
1801 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
);
1805 /* =========================================================================================
1806 * Connection & Disconnection
1809 * Function : acornscsi_reconnect(AS_Host *host)
1810 * Purpose : reconnect a previously disconnected command
1811 * Params : host - host specific data
1812 * Remarks : SCSI spec says:
1813 * 'The set of active pointers is restored from the set
1814 * of saved pointers upon reconnection of the I/O process'
1817 int acornscsi_reconnect(AS_Host
*host
)
1819 unsigned int target
, lun
, ok
= 0;
1821 target
= sbic_arm_read(host
->scsi
.io_port
, SBIC_SOURCEID
);
1824 printk(KERN_ERR
"scsi%d: invalid source id after reselection "
1825 "- device fault?\n",
1826 host
->host
->host_no
);
1830 if (host
->SCpnt
&& !host
->scsi
.disconnectable
) {
1831 printk(KERN_ERR
"scsi%d.%d: reconnected while command in "
1832 "progress to target %d?\n",
1833 host
->host
->host_no
, target
, host
->SCpnt
->device
->id
);
1837 lun
= sbic_arm_read(host
->scsi
.io_port
, SBIC_DATA
) & 7;
1839 host
->scsi
.reconnected
.target
= target
;
1840 host
->scsi
.reconnected
.lun
= lun
;
1841 host
->scsi
.reconnected
.tag
= 0;
1843 if (host
->scsi
.disconnectable
&& host
->SCpnt
&&
1844 host
->SCpnt
->device
->id
== target
&& host
->SCpnt
->device
->lun
== lun
)
1847 if (!ok
&& queue_probetgtlun(&host
->queues
.disconnected
, target
, lun
))
1850 ADD_STATUS(target
, 0x81, host
->scsi
.phase
, 0);
1853 host
->scsi
.phase
= PHASE_RECONNECTED
;
1855 /* this doesn't seem to work */
1856 printk(KERN_ERR
"scsi%d.%c: reselected with no command "
1857 "to reconnect with\n",
1858 host
->host
->host_no
, '0' + target
);
1859 acornscsi_dumplog(host
, target
);
1860 acornscsi_abortcmd(host
, 0);
1862 queue_add_cmd_tail(&host
->queues
.disconnected
, host
->SCpnt
);
1866 acornscsi_sbic_issuecmd(host
, CMND_NEGATEACK
);
1871 * Function: int acornscsi_reconect_finish(AS_Host *host)
1872 * Purpose : finish reconnecting a command
1873 * Params : host - host to complete
1874 * Returns : 0 if failed
1877 int acornscsi_reconnect_finish(AS_Host
*host
)
1879 if (host
->scsi
.disconnectable
&& host
->SCpnt
) {
1880 host
->scsi
.disconnectable
= 0;
1881 if (host
->SCpnt
->device
->id
== host
->scsi
.reconnected
.target
&&
1882 host
->SCpnt
->device
->lun
== host
->scsi
.reconnected
.lun
&&
1883 host
->SCpnt
->tag
== host
->scsi
.reconnected
.tag
) {
1884 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1885 DBG(host
->SCpnt
, printk("scsi%d.%c: reconnected",
1886 host
->host
->host_no
, acornscsi_target(host
)));
1889 queue_add_cmd_tail(&host
->queues
.disconnected
, host
->SCpnt
);
1890 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1891 DBG(host
->SCpnt
, printk("scsi%d.%c: had to move command "
1892 "to disconnected queue\n",
1893 host
->host
->host_no
, acornscsi_target(host
)));
1899 host
->SCpnt
= queue_remove_tgtluntag(&host
->queues
.disconnected
,
1900 host
->scsi
.reconnected
.target
,
1901 host
->scsi
.reconnected
.lun
,
1902 host
->scsi
.reconnected
.tag
);
1903 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1904 DBG(host
->SCpnt
, printk("scsi%d.%c: had to get command",
1905 host
->host
->host_no
, acornscsi_target(host
)));
1910 acornscsi_abortcmd(host
, host
->scsi
.reconnected
.tag
);
1913 * Restore data pointer from SAVED pointers.
1915 host
->scsi
.SCp
= host
->SCpnt
->SCp
;
1916 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1917 printk(", data pointers: [%p, %X]",
1918 host
->scsi
.SCp
.ptr
, host
->scsi
.SCp
.this_residual
);
1921 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1925 host
->dma
.transferred
= host
->scsi
.SCp
.scsi_xferred
;
1927 return host
->SCpnt
!= NULL
;
1931 * Function: void acornscsi_disconnect_unexpected(AS_Host *host)
1932 * Purpose : handle an unexpected disconnect
1933 * Params : host - host on which disconnect occurred
1936 void acornscsi_disconnect_unexpected(AS_Host
*host
)
1938 printk(KERN_ERR
"scsi%d.%c: unexpected disconnect\n",
1939 host
->host
->host_no
, acornscsi_target(host
));
1940 #if (DEBUG & DEBUG_ABORT)
1941 acornscsi_dumplog(host
, 8);
1944 acornscsi_done(host
, &host
->SCpnt
, DID_ERROR
);
1948 * Function: void acornscsi_abortcmd(AS_host *host, unsigned char tag)
1949 * Purpose : abort a currently executing command
1950 * Params : host - host with connected command to abort
1951 * tag - tag to abort
1954 void acornscsi_abortcmd(AS_Host
*host
, unsigned char tag
)
1956 host
->scsi
.phase
= PHASE_ABORTED
;
1957 sbic_arm_write(host
->scsi
.io_port
, SBIC_CMND
, CMND_ASSERTATN
);
1959 msgqueue_flush(&host
->scsi
.msgs
);
1960 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
1962 msgqueue_addmsg(&host
->scsi
.msgs
, 2, ABORT_TAG
, tag
);
1965 msgqueue_addmsg(&host
->scsi
.msgs
, 1, ABORT
);
1968 /* ==========================================================================================
1969 * Interrupt routines.
1972 * Function: int acornscsi_sbicintr(AS_Host *host)
1973 * Purpose : handle interrupts from SCSI device
1974 * Params : host - host to process
1975 * Returns : INTR_PROCESS if expecting another SBIC interrupt
1976 * INTR_IDLE if no interrupt
1977 * INTR_NEXT_COMMAND if we have finished processing the command
1980 intr_ret_t
acornscsi_sbicintr(AS_Host
*host
, int in_irq
)
1982 unsigned int asr
, ssr
;
1984 asr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
1985 if (!(asr
& ASR_INT
))
1988 ssr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
);
1990 #if (DEBUG & DEBUG_PHASES)
1991 print_sbic_status(asr
, ssr
, host
->scsi
.phase
);
1994 ADD_STATUS(8, ssr
, host
->scsi
.phase
, in_irq
);
1996 if (host
->SCpnt
&& !host
->scsi
.disconnectable
)
1997 ADD_STATUS(host
->SCpnt
->device
->id
, ssr
, host
->scsi
.phase
, in_irq
);
2000 case 0x00: /* reset state - not advanced */
2001 printk(KERN_ERR
"scsi%d: reset in standard mode but wanted advanced mode.\n",
2002 host
->host
->host_no
);
2003 /* setup sbic - WD33C93A */
2004 sbic_arm_write(host
->scsi
.io_port
, SBIC_OWNID
, OWNID_EAF
| host
->host
->this_id
);
2005 sbic_arm_write(host
->scsi
.io_port
, SBIC_CMND
, CMND_RESET
);
2008 case 0x01: /* reset state - advanced */
2009 sbic_arm_write(host
->scsi
.io_port
, SBIC_CTRL
, INIT_SBICDMA
| CTRL_IDI
);
2010 sbic_arm_write(host
->scsi
.io_port
, SBIC_TIMEOUT
, TIMEOUT_TIME
);
2011 sbic_arm_write(host
->scsi
.io_port
, SBIC_SYNCHTRANSFER
, SYNCHTRANSFER_2DBA
);
2012 sbic_arm_write(host
->scsi
.io_port
, SBIC_SOURCEID
, SOURCEID_ER
| SOURCEID_DSP
);
2013 msgqueue_flush(&host
->scsi
.msgs
);
2016 case 0x41: /* unexpected disconnect aborted command */
2017 acornscsi_disconnect_unexpected(host
);
2018 return INTR_NEXT_COMMAND
;
2021 switch (host
->scsi
.phase
) {
2022 case PHASE_CONNECTING
: /* STATE: command removed from issue queue */
2024 case 0x11: /* -> PHASE_CONNECTED */
2025 /* BUS FREE -> SELECTION */
2026 host
->scsi
.phase
= PHASE_CONNECTED
;
2027 msgqueue_flush(&host
->scsi
.msgs
);
2028 host
->dma
.transferred
= host
->scsi
.SCp
.scsi_xferred
;
2029 /* 33C93 gives next interrupt indicating bus phase */
2030 asr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
2031 if (!(asr
& ASR_INT
))
2033 ssr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
);
2034 ADD_STATUS(8, ssr
, host
->scsi
.phase
, 1);
2035 ADD_STATUS(host
->SCpnt
->device
->id
, ssr
, host
->scsi
.phase
, 1);
2038 case 0x42: /* select timed out */
2040 acornscsi_done(host
, &host
->SCpnt
, DID_NO_CONNECT
);
2041 return INTR_NEXT_COMMAND
;
2043 case 0x81: /* -> PHASE_RECONNECTED or PHASE_ABORTED */
2044 /* BUS FREE -> RESELECTION */
2045 host
->origSCpnt
= host
->SCpnt
;
2047 msgqueue_flush(&host
->scsi
.msgs
);
2048 acornscsi_reconnect(host
);
2052 printk(KERN_ERR
"scsi%d.%c: PHASE_CONNECTING, SSR %02X?\n",
2053 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2054 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2055 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2057 return INTR_PROCESSING
;
2060 case PHASE_CONNECTED
: /* STATE: device selected ok */
2063 case 0x8a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
2064 /* SELECTION -> COMMAND */
2065 acornscsi_sendcommand(host
);
2068 case 0x8b: /* -> PHASE_STATUS */
2069 /* SELECTION -> STATUS */
2070 acornscsi_readstatusbyte(host
);
2071 host
->scsi
.phase
= PHASE_STATUSIN
;
2075 case 0x8e: /* -> PHASE_MSGOUT */
2076 /* SELECTION ->MESSAGE OUT */
2077 host
->scsi
.phase
= PHASE_MSGOUT
;
2078 acornscsi_buildmessages(host
);
2079 acornscsi_sendmessage(host
);
2082 /* these should not happen */
2083 case 0x85: /* target disconnected */
2084 acornscsi_done(host
, &host
->SCpnt
, DID_ERROR
);
2088 printk(KERN_ERR
"scsi%d.%c: PHASE_CONNECTED, SSR %02X?\n",
2089 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2090 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2091 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2093 return INTR_PROCESSING
;
2095 case PHASE_MSGOUT
: /* STATE: connected & sent IDENTIFY message */
2097 * SCSI standard says that MESSAGE OUT phases can be followed by a
2098 * DATA phase, STATUS phase, MESSAGE IN phase or COMMAND phase
2101 case 0x8a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
2102 case 0x1a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
2103 /* MESSAGE OUT -> COMMAND */
2104 acornscsi_sendcommand(host
);
2107 case 0x8b: /* -> PHASE_STATUS */
2108 case 0x1b: /* -> PHASE_STATUS */
2109 /* MESSAGE OUT -> STATUS */
2110 acornscsi_readstatusbyte(host
);
2111 host
->scsi
.phase
= PHASE_STATUSIN
;
2114 case 0x8e: /* -> PHASE_MSGOUT */
2115 /* MESSAGE_OUT(MESSAGE_IN) ->MESSAGE OUT */
2116 acornscsi_sendmessage(host
);
2119 case 0x4f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2120 case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2121 /* MESSAGE OUT -> MESSAGE IN */
2122 acornscsi_message(host
);
2126 printk(KERN_ERR
"scsi%d.%c: PHASE_MSGOUT, SSR %02X?\n",
2127 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2128 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2130 return INTR_PROCESSING
;
2132 case PHASE_COMMAND
: /* STATE: connected & command sent */
2134 case 0x18: /* -> PHASE_DATAOUT */
2135 /* COMMAND -> DATA OUT */
2136 if (host
->scsi
.SCp
.sent_command
!= host
->SCpnt
->cmd_len
)
2137 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2138 acornscsi_dma_setup(host
, DMA_OUT
);
2139 if (!acornscsi_starttransfer(host
))
2140 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2141 host
->scsi
.phase
= PHASE_DATAOUT
;
2144 case 0x19: /* -> PHASE_DATAIN */
2145 /* COMMAND -> DATA IN */
2146 if (host
->scsi
.SCp
.sent_command
!= host
->SCpnt
->cmd_len
)
2147 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2148 acornscsi_dma_setup(host
, DMA_IN
);
2149 if (!acornscsi_starttransfer(host
))
2150 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2151 host
->scsi
.phase
= PHASE_DATAIN
;
2154 case 0x1b: /* -> PHASE_STATUS */
2155 /* COMMAND -> STATUS */
2156 acornscsi_readstatusbyte(host
);
2157 host
->scsi
.phase
= PHASE_STATUSIN
;
2160 case 0x1e: /* -> PHASE_MSGOUT */
2161 /* COMMAND -> MESSAGE OUT */
2162 acornscsi_sendmessage(host
);
2165 case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2166 /* COMMAND -> MESSAGE IN */
2167 acornscsi_message(host
);
2171 printk(KERN_ERR
"scsi%d.%c: PHASE_COMMAND, SSR %02X?\n",
2172 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2173 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2175 return INTR_PROCESSING
;
2177 case PHASE_DISCONNECT
: /* STATE: connected, received DISCONNECT msg */
2178 if (ssr
== 0x85) { /* -> PHASE_IDLE */
2179 host
->scsi
.disconnectable
= 1;
2180 host
->scsi
.reconnected
.tag
= 0;
2181 host
->scsi
.phase
= PHASE_IDLE
;
2182 host
->stats
.disconnects
+= 1;
2184 printk(KERN_ERR
"scsi%d.%c: PHASE_DISCONNECT, SSR %02X instead of disconnect?\n",
2185 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2186 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2188 return INTR_NEXT_COMMAND
;
2190 case PHASE_IDLE
: /* STATE: disconnected */
2191 if (ssr
== 0x81) /* -> PHASE_RECONNECTED or PHASE_ABORTED */
2192 acornscsi_reconnect(host
);
2194 printk(KERN_ERR
"scsi%d.%c: PHASE_IDLE, SSR %02X while idle?\n",
2195 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2196 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2198 return INTR_PROCESSING
;
2200 case PHASE_RECONNECTED
: /* STATE: device reconnected to initiator */
2202 * Command reconnected - if MESGIN, get message - it may be
2203 * the tag. If not, get command out of disconnected queue
2206 * If we reconnected and we're not in MESSAGE IN phase after IDENTIFY,
2207 * reconnect I_T_L command
2209 if (ssr
!= 0x8f && !acornscsi_reconnect_finish(host
))
2211 ADD_STATUS(host
->SCpnt
->device
->id
, ssr
, host
->scsi
.phase
, in_irq
);
2213 case 0x88: /* data out phase */
2214 /* -> PHASE_DATAOUT */
2215 /* MESSAGE IN -> DATA OUT */
2216 acornscsi_dma_setup(host
, DMA_OUT
);
2217 if (!acornscsi_starttransfer(host
))
2218 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2219 host
->scsi
.phase
= PHASE_DATAOUT
;
2222 case 0x89: /* data in phase */
2223 /* -> PHASE_DATAIN */
2224 /* MESSAGE IN -> DATA IN */
2225 acornscsi_dma_setup(host
, DMA_IN
);
2226 if (!acornscsi_starttransfer(host
))
2227 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2228 host
->scsi
.phase
= PHASE_DATAIN
;
2231 case 0x8a: /* command out */
2232 /* MESSAGE IN -> COMMAND */
2233 acornscsi_sendcommand(host
);/* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
2236 case 0x8b: /* status in */
2237 /* -> PHASE_STATUSIN */
2238 /* MESSAGE IN -> STATUS */
2239 acornscsi_readstatusbyte(host
);
2240 host
->scsi
.phase
= PHASE_STATUSIN
;
2243 case 0x8e: /* message out */
2244 /* -> PHASE_MSGOUT */
2245 /* MESSAGE IN -> MESSAGE OUT */
2246 acornscsi_sendmessage(host
);
2249 case 0x8f: /* message in */
2250 acornscsi_message(host
); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2254 printk(KERN_ERR
"scsi%d.%c: PHASE_RECONNECTED, SSR %02X after reconnect?\n",
2255 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2256 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2258 return INTR_PROCESSING
;
2260 case PHASE_DATAIN
: /* STATE: transferred data in */
2262 * This is simple - if we disconnect then the DMA address & count is
2266 case 0x19: /* -> PHASE_DATAIN */
2267 case 0x89: /* -> PHASE_DATAIN */
2268 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2271 case 0x1b: /* -> PHASE_STATUSIN */
2272 case 0x4b: /* -> PHASE_STATUSIN */
2273 case 0x8b: /* -> PHASE_STATUSIN */
2274 /* DATA IN -> STATUS */
2275 host
->scsi
.SCp
.scsi_xferred
= host
->SCpnt
->request_bufflen
-
2276 acornscsi_sbic_xfcount(host
);
2277 acornscsi_dma_stop(host
);
2278 acornscsi_readstatusbyte(host
);
2279 host
->scsi
.phase
= PHASE_STATUSIN
;
2282 case 0x1e: /* -> PHASE_MSGOUT */
2283 case 0x4e: /* -> PHASE_MSGOUT */
2284 case 0x8e: /* -> PHASE_MSGOUT */
2285 /* DATA IN -> MESSAGE OUT */
2286 host
->scsi
.SCp
.scsi_xferred
= host
->SCpnt
->request_bufflen
-
2287 acornscsi_sbic_xfcount(host
);
2288 acornscsi_dma_stop(host
);
2289 acornscsi_sendmessage(host
);
2292 case 0x1f: /* message in */
2293 case 0x4f: /* message in */
2294 case 0x8f: /* message in */
2295 /* DATA IN -> MESSAGE IN */
2296 host
->scsi
.SCp
.scsi_xferred
= host
->SCpnt
->request_bufflen
-
2297 acornscsi_sbic_xfcount(host
);
2298 acornscsi_dma_stop(host
);
2299 acornscsi_message(host
); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2303 printk(KERN_ERR
"scsi%d.%c: PHASE_DATAIN, SSR %02X?\n",
2304 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2305 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2307 return INTR_PROCESSING
;
2309 case PHASE_DATAOUT
: /* STATE: transferred data out */
2311 * This is more complicated - if we disconnect, the DMA could be 12
2312 * bytes ahead of us. We need to correct this.
2315 case 0x18: /* -> PHASE_DATAOUT */
2316 case 0x88: /* -> PHASE_DATAOUT */
2317 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2320 case 0x1b: /* -> PHASE_STATUSIN */
2321 case 0x4b: /* -> PHASE_STATUSIN */
2322 case 0x8b: /* -> PHASE_STATUSIN */
2323 /* DATA OUT -> STATUS */
2324 host
->scsi
.SCp
.scsi_xferred
= host
->SCpnt
->request_bufflen
-
2325 acornscsi_sbic_xfcount(host
);
2326 acornscsi_dma_stop(host
);
2327 acornscsi_dma_adjust(host
);
2328 acornscsi_readstatusbyte(host
);
2329 host
->scsi
.phase
= PHASE_STATUSIN
;
2332 case 0x1e: /* -> PHASE_MSGOUT */
2333 case 0x4e: /* -> PHASE_MSGOUT */
2334 case 0x8e: /* -> PHASE_MSGOUT */
2335 /* DATA OUT -> MESSAGE OUT */
2336 host
->scsi
.SCp
.scsi_xferred
= host
->SCpnt
->request_bufflen
-
2337 acornscsi_sbic_xfcount(host
);
2338 acornscsi_dma_stop(host
);
2339 acornscsi_dma_adjust(host
);
2340 acornscsi_sendmessage(host
);
2343 case 0x1f: /* message in */
2344 case 0x4f: /* message in */
2345 case 0x8f: /* message in */
2346 /* DATA OUT -> MESSAGE IN */
2347 host
->scsi
.SCp
.scsi_xferred
= host
->SCpnt
->request_bufflen
-
2348 acornscsi_sbic_xfcount(host
);
2349 acornscsi_dma_stop(host
);
2350 acornscsi_dma_adjust(host
);
2351 acornscsi_message(host
); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2355 printk(KERN_ERR
"scsi%d.%c: PHASE_DATAOUT, SSR %02X?\n",
2356 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2357 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2359 return INTR_PROCESSING
;
2361 case PHASE_STATUSIN
: /* STATE: status in complete */
2363 case 0x1f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
2364 case 0x8f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
2365 /* STATUS -> MESSAGE IN */
2366 acornscsi_message(host
);
2369 case 0x1e: /* -> PHASE_MSGOUT */
2370 case 0x8e: /* -> PHASE_MSGOUT */
2371 /* STATUS -> MESSAGE OUT */
2372 acornscsi_sendmessage(host
);
2376 printk(KERN_ERR
"scsi%d.%c: PHASE_STATUSIN, SSR %02X instead of MESSAGE_IN?\n",
2377 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2378 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2380 return INTR_PROCESSING
;
2382 case PHASE_MSGIN
: /* STATE: message in */
2384 case 0x1e: /* -> PHASE_MSGOUT */
2385 case 0x4e: /* -> PHASE_MSGOUT */
2386 case 0x8e: /* -> PHASE_MSGOUT */
2387 /* MESSAGE IN -> MESSAGE OUT */
2388 acornscsi_sendmessage(host
);
2391 case 0x1f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
2395 acornscsi_message(host
);
2399 printk("scsi%d.%c: strange message in disconnection\n",
2400 host
->host
->host_no
, acornscsi_target(host
));
2401 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2402 acornscsi_done(host
, &host
->SCpnt
, DID_ERROR
);
2406 printk(KERN_ERR
"scsi%d.%c: PHASE_MSGIN, SSR %02X after message in?\n",
2407 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2408 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2410 return INTR_PROCESSING
;
2412 case PHASE_DONE
: /* STATE: received status & message */
2414 case 0x85: /* -> PHASE_IDLE */
2415 acornscsi_done(host
, &host
->SCpnt
, DID_OK
);
2416 return INTR_NEXT_COMMAND
;
2420 acornscsi_sendmessage(host
);
2424 printk(KERN_ERR
"scsi%d.%c: PHASE_DONE, SSR %02X instead of disconnect?\n",
2425 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2426 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2428 return INTR_PROCESSING
;
2434 acornscsi_done(host
, &host
->SCpnt
, DID_ABORT
);
2436 clear_bit(host
->scsi
.reconnected
.target
* 8 + host
->scsi
.reconnected
.lun
,
2438 host
->scsi
.phase
= PHASE_IDLE
;
2440 return INTR_NEXT_COMMAND
;
2446 acornscsi_sendmessage(host
);
2450 printk(KERN_ERR
"scsi%d.%c: PHASE_ABORTED, SSR %02X?\n",
2451 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2452 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2454 return INTR_PROCESSING
;
2457 printk(KERN_ERR
"scsi%d.%c: unknown driver phase %d\n",
2458 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2459 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2461 return INTR_PROCESSING
;
2465 * Prototype: void acornscsi_intr(int irq, void *dev_id, struct pt_regs *regs)
2466 * Purpose : handle interrupts from Acorn SCSI card
2467 * Params : irq - interrupt number
2468 * dev_id - device specific data (AS_Host structure)
2469 * regs - processor registers when interrupt occurred
2472 acornscsi_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
2474 AS_Host
*host
= (AS_Host
*)dev_id
;
2482 iostatus
= inb(host
->card
.io_intr
);
2485 acornscsi_dma_intr(host
);
2486 iostatus
= inb(host
->card
.io_intr
);
2490 ret
= acornscsi_sbicintr(host
, in_irq
);
2493 * If we have a transfer pending, start it.
2494 * Only start it if the interface has already started transferring
2497 if (host
->dma
.xfer_required
)
2498 acornscsi_dma_xfer(host
);
2500 if (ret
== INTR_NEXT_COMMAND
)
2501 ret
= acornscsi_kick(host
);
2504 } while (ret
!= INTR_IDLE
);
2509 /*=============================================================================================
2510 * Interfaces between interrupt handler and rest of scsi code
2514 * Function : acornscsi_queuecmd(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
2515 * Purpose : queues a SCSI command
2516 * Params : cmd - SCSI command
2517 * done - function called on completion, with pointer to command descriptor
2518 * Returns : 0, or < 0 on error.
2520 int acornscsi_queuecmd(Scsi_Cmnd
*SCpnt
, void (*done
)(Scsi_Cmnd
*))
2522 AS_Host
*host
= (AS_Host
*)SCpnt
->device
->host
->hostdata
;
2525 /* there should be some way of rejecting errors like this without panicing... */
2526 panic("scsi%d: queuecommand called with NULL done function [cmd=%p]",
2527 host
->host
->host_no
, SCpnt
);
2531 #if (DEBUG & DEBUG_NO_WRITE)
2532 if (acornscsi_cmdtype(SCpnt
->cmnd
[0]) == CMD_WRITE
&& (NO_WRITE
& (1 << SCpnt
->device
->id
))) {
2533 printk(KERN_CRIT
"scsi%d.%c: WRITE attempted with NO_WRITE flag set\n",
2534 host
->host
->host_no
, '0' + SCpnt
->device
->id
);
2535 SCpnt
->result
= DID_NO_CONNECT
<< 16;
2541 SCpnt
->scsi_done
= done
;
2542 SCpnt
->host_scribble
= NULL
;
2545 SCpnt
->SCp
.phase
= (int)acornscsi_datadirection(SCpnt
->cmnd
[0]);
2546 SCpnt
->SCp
.sent_command
= 0;
2547 SCpnt
->SCp
.scsi_xferred
= 0;
2551 host
->stats
.queues
+= 1;
2554 unsigned long flags
;
2556 if (!queue_add_cmd_ordered(&host
->queues
.issue
, SCpnt
)) {
2557 SCpnt
->result
= DID_ERROR
<< 16;
2561 local_irq_save(flags
);
2562 if (host
->scsi
.phase
== PHASE_IDLE
)
2563 acornscsi_kick(host
);
2564 local_irq_restore(flags
);
2570 * Prototype: void acornscsi_reportstatus(Scsi_Cmnd **SCpntp1, Scsi_Cmnd **SCpntp2, int result)
2571 * Purpose : pass a result to *SCpntp1, and check if *SCpntp1 = *SCpntp2
2572 * Params : SCpntp1 - pointer to command to return
2573 * SCpntp2 - pointer to command to check
2574 * result - result to pass back to mid-level done function
2575 * Returns : *SCpntp2 = NULL if *SCpntp1 is the same command structure as *SCpntp2.
2578 void acornscsi_reportstatus(Scsi_Cmnd
**SCpntp1
, Scsi_Cmnd
**SCpntp2
, int result
)
2580 Scsi_Cmnd
*SCpnt
= *SCpntp1
;
2585 SCpnt
->result
= result
;
2586 SCpnt
->scsi_done(SCpnt
);
2589 if (SCpnt
== *SCpntp2
)
2593 enum res_abort
{ res_not_running
, res_success
, res_success_clear
, res_snooze
};
2596 * Prototype: enum res acornscsi_do_abort(Scsi_Cmnd *SCpnt)
2597 * Purpose : abort a command on this host
2598 * Params : SCpnt - command to abort
2599 * Returns : our abort status
2601 static enum res_abort
2602 acornscsi_do_abort(AS_Host
*host
, Scsi_Cmnd
*SCpnt
)
2604 enum res_abort res
= res_not_running
;
2606 if (queue_remove_cmd(&host
->queues
.issue
, SCpnt
)) {
2608 * The command was on the issue queue, and has not been
2609 * issued yet. We can remove the command from the queue,
2610 * and acknowledge the abort. Neither the devices nor the
2611 * interface know about the command.
2613 //#if (DEBUG & DEBUG_ABORT)
2614 printk("on issue queue ");
2617 } else if (queue_remove_cmd(&host
->queues
.disconnected
, SCpnt
)) {
2619 * The command was on the disconnected queue. Simply
2620 * acknowledge the abort condition, and when the target
2621 * reconnects, we will give it an ABORT message. The
2622 * target should then disconnect, and we will clear
2625 //#if (DEBUG & DEBUG_ABORT)
2626 printk("on disconnected queue ");
2629 } else if (host
->SCpnt
== SCpnt
) {
2630 unsigned long flags
;
2632 //#if (DEBUG & DEBUG_ABORT)
2633 printk("executing ");
2636 local_irq_save(flags
);
2637 switch (host
->scsi
.phase
) {
2639 * If the interface is idle, and the command is 'disconnectable',
2640 * then it is the same as on the disconnected queue. We simply
2641 * remove all traces of the command. When the target reconnects,
2642 * we will give it an ABORT message since the command could not
2643 * be found. When the target finally disconnects, we will clear
2647 if (host
->scsi
.disconnectable
) {
2648 host
->scsi
.disconnectable
= 0;
2655 * If the command has connected and done nothing further,
2656 * simply force a disconnect. We also need to clear the
2659 case PHASE_CONNECTED
:
2660 sbic_arm_write(host
->scsi
.io_port
, SBIC_CMND
, CMND_DISCONNECT
);
2662 res
= res_success_clear
;
2666 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2669 local_irq_restore(flags
);
2670 } else if (host
->origSCpnt
== SCpnt
) {
2672 * The command will be executed next, but a command
2673 * is currently using the interface. This is similar to
2674 * being on the issue queue, except the busylun bit has
2677 host
->origSCpnt
= NULL
;
2678 //#if (DEBUG & DEBUG_ABORT)
2679 printk("waiting for execution ");
2681 res
= res_success_clear
;
2689 * Prototype: int acornscsi_abort(Scsi_Cmnd *SCpnt)
2690 * Purpose : abort a command on this host
2691 * Params : SCpnt - command to abort
2692 * Returns : one of SCSI_ABORT_ macros
2694 int acornscsi_abort(Scsi_Cmnd
*SCpnt
)
2696 AS_Host
*host
= (AS_Host
*) SCpnt
->device
->host
->hostdata
;
2699 host
->stats
.aborts
+= 1;
2701 #if (DEBUG & DEBUG_ABORT)
2704 asr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
2705 ssr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
);
2707 printk(KERN_WARNING
"acornscsi_abort: ");
2708 print_sbic_status(asr
, ssr
, host
->scsi
.phase
);
2709 acornscsi_dumplog(host
, SCpnt
->device
->id
);
2713 printk("scsi%d: ", host
->host
->host_no
);
2715 switch (acornscsi_do_abort(host
, SCpnt
)) {
2717 * We managed to find the command and cleared it out.
2718 * We do not expect the command to be executing on the
2719 * target, but we have set the busylun bit.
2721 case res_success_clear
:
2722 //#if (DEBUG & DEBUG_ABORT)
2725 clear_bit(SCpnt
->device
->id
* 8 + SCpnt
->device
->lun
, host
->busyluns
);
2728 * We found the command, and cleared it out. Either
2729 * the command is still known to be executing on the
2730 * target, or the busylun bit is not set.
2733 //#if (DEBUG & DEBUG_ABORT)
2734 printk("success\n");
2736 SCpnt
->result
= DID_ABORT
<< 16;
2737 SCpnt
->scsi_done(SCpnt
);
2738 result
= SCSI_ABORT_SUCCESS
;
2742 * We did find the command, but unfortunately we couldn't
2743 * unhook it from ourselves. Wait some more, and if it
2744 * still doesn't complete, reset the interface.
2747 //#if (DEBUG & DEBUG_ABORT)
2750 result
= SCSI_ABORT_SNOOZE
;
2754 * The command could not be found (either because it completed,
2755 * or it got dropped.
2758 case res_not_running
:
2759 acornscsi_dumplog(host
, SCpnt
->device
->id
);
2760 #if (DEBUG & DEBUG_ABORT)
2761 result
= SCSI_ABORT_SNOOZE
;
2763 result
= SCSI_ABORT_NOT_RUNNING
;
2765 //#if (DEBUG & DEBUG_ABORT)
2766 printk("not running\n");
2775 * Prototype: int acornscsi_reset(Scsi_Cmnd *SCpnt, unsigned int reset_flags)
2776 * Purpose : reset a command on this host/reset this host
2777 * Params : SCpnt - command causing reset
2778 * result - what type of reset to perform
2779 * Returns : one of SCSI_RESET_ macros
2781 int acornscsi_reset(Scsi_Cmnd
*SCpnt
, unsigned int reset_flags
)
2783 AS_Host
*host
= (AS_Host
*)SCpnt
->device
->host
->hostdata
;
2786 host
->stats
.resets
+= 1;
2788 #if (DEBUG & DEBUG_RESET)
2792 asr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
2793 ssr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
);
2795 printk(KERN_WARNING
"acornscsi_reset: ");
2796 print_sbic_status(asr
, ssr
, host
->scsi
.phase
);
2797 acornscsi_dumplog(host
, SCpnt
->device
->id
);
2801 acornscsi_dma_stop(host
);
2803 SCptr
= host
->SCpnt
;
2806 * do hard reset. This resets all devices on this host, and so we
2807 * must set the reset status on all commands.
2809 acornscsi_resetcard(host
);
2812 * report reset on commands current connected/disconnected
2814 acornscsi_reportstatus(&host
->SCpnt
, &SCptr
, DID_RESET
);
2816 while ((SCptr
= queue_remove(&host
->queues
.disconnected
)) != NULL
)
2817 acornscsi_reportstatus(&SCptr
, &SCpnt
, DID_RESET
);
2820 SCpnt
->result
= DID_RESET
<< 16;
2821 SCpnt
->scsi_done(SCpnt
);
2824 return SCSI_RESET_BUS_RESET
| SCSI_RESET_HOST_RESET
| SCSI_RESET_SUCCESS
;
2827 /*==============================================================================================
2828 * initialisation & miscellaneous support
2832 * Function: char *acornscsi_info(struct Scsi_Host *host)
2833 * Purpose : return a string describing this interface
2834 * Params : host - host to give information on
2835 * Returns : a constant string
2838 char *acornscsi_info(struct Scsi_Host
*host
)
2840 static char string
[100], *p
;
2844 p
+= sprintf(string
, "%s at port %08lX irq %d v%d.%d.%d"
2845 #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
2848 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
2851 #ifdef CONFIG_SCSI_ACORNSCSI_LINK
2854 #if (DEBUG & DEBUG_NO_WRITE)
2855 " NOWRITE ("NO_WRITE_STR
")"
2857 , host
->hostt
->name
, host
->io_port
, host
->irq
,
2858 VER_MAJOR
, VER_MINOR
, VER_PATCH
);
2862 int acornscsi_proc_info(struct Scsi_Host
*instance
, char *buffer
, char **start
, off_t offset
,
2863 int length
, int inout
)
2865 int pos
, begin
= 0, devidx
;
2866 struct scsi_device
*scd
;
2873 host
= (AS_Host
*)instance
->hostdata
;
2875 p
+= sprintf(p
, "AcornSCSI driver v%d.%d.%d"
2876 #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
2879 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
2882 #ifdef CONFIG_SCSI_ACORNSCSI_LINK
2885 #if (DEBUG & DEBUG_NO_WRITE)
2886 " NOWRITE ("NO_WRITE_STR
")"
2888 "\n\n", VER_MAJOR
, VER_MINOR
, VER_PATCH
);
2890 p
+= sprintf(p
, "SBIC: WD33C93A Address: %08X IRQ : %d\n",
2891 host
->scsi
.io_port
, host
->scsi
.irq
);
2893 p
+= sprintf(p
, "DMAC: uPC71071 Address: %08X IRQ : %d\n\n",
2894 host
->dma
.io_port
, host
->scsi
.irq
);
2897 p
+= sprintf(p
, "Statistics:\n"
2898 "Queued commands: %-10u Issued commands: %-10u\n"
2899 "Done commands : %-10u Reads : %-10u\n"
2900 "Writes : %-10u Others : %-10u\n"
2901 "Disconnects : %-10u Aborts : %-10u\n"
2902 "Resets : %-10u\n\nLast phases:",
2903 host
->stats
.queues
, host
->stats
.removes
,
2904 host
->stats
.fins
, host
->stats
.reads
,
2905 host
->stats
.writes
, host
->stats
.miscs
,
2906 host
->stats
.disconnects
, host
->stats
.aborts
,
2907 host
->stats
.resets
);
2909 for (devidx
= 0; devidx
< 9; devidx
++) {
2910 unsigned int statptr
, prev
;
2912 p
+= sprintf(p
, "\n%c:", devidx
== 8 ? 'H' : ('0' + devidx
));
2913 statptr
= host
->status_ptr
[devidx
] - 10;
2915 if ((signed int)statptr
< 0)
2916 statptr
+= STATUS_BUFFER_SIZE
;
2918 prev
= host
->status
[devidx
][statptr
].when
;
2920 for (; statptr
!= host
->status_ptr
[devidx
]; statptr
= (statptr
+ 1) & (STATUS_BUFFER_SIZE
- 1)) {
2921 if (host
->status
[devidx
][statptr
].when
) {
2922 p
+= sprintf(p
, "%c%02X:%02X+%2ld",
2923 host
->status
[devidx
][statptr
].irq
? '-' : ' ',
2924 host
->status
[devidx
][statptr
].ph
,
2925 host
->status
[devidx
][statptr
].ssr
,
2926 (host
->status
[devidx
][statptr
].when
- prev
) < 100 ?
2927 (host
->status
[devidx
][statptr
].when
- prev
) : 99);
2928 prev
= host
->status
[devidx
][statptr
].when
;
2933 p
+= sprintf(p
, "\nAttached devices:\n");
2935 shost_for_each_device(scd
, instance
) {
2936 p
+= sprintf(p
, "Device/Lun TaggedQ Sync\n");
2937 p
+= sprintf(p
, " %d/%d ", scd
->id
, scd
->lun
);
2938 if (scd
->tagged_supported
)
2939 p
+= sprintf(p
, "%3sabled(%3d) ",
2940 scd
->simple_tags
? "en" : "dis",
2943 p
+= sprintf(p
, "unsupported ");
2945 if (host
->device
[scd
->id
].sync_xfer
& 15)
2946 p
+= sprintf(p
, "offset %d, %d ns\n",
2947 host
->device
[scd
->id
].sync_xfer
& 15,
2948 acornscsi_getperiod(host
->device
[scd
->id
].sync_xfer
));
2950 p
+= sprintf(p
, "async\n");
2953 if (pos
+ begin
< offset
) {
2958 if (pos
+ begin
> offset
+ length
) {
2959 scsi_device_put(scd
);
2966 *start
= buffer
+ (offset
- begin
);
2967 pos
-= offset
- begin
;
2975 static struct scsi_host_template acornscsi_template
= {
2976 .module
= THIS_MODULE
,
2977 .proc_info
= acornscsi_proc_info
,
2978 .name
= "AcornSCSI",
2979 .info
= acornscsi_info
,
2980 .queuecommand
= acornscsi_queuecmd
,
2982 .abort
= acornscsi_abort
,
2983 .reset
= acornscsi_reset
,
2986 .sg_tablesize
= SG_ALL
,
2988 .unchecked_isa_dma
= 0,
2989 .use_clustering
= DISABLE_CLUSTERING
,
2990 .proc_name
= "acornscsi",
2993 static int __devinit
2994 acornscsi_probe(struct expansion_card
*ec
, const struct ecard_id
*id
)
2996 struct Scsi_Host
*host
;
3000 host
= scsi_host_alloc(&acornscsi_template
, sizeof(AS_Host
));
3004 ashost
= (AS_Host
*)host
->hostdata
;
3006 host
->io_port
= ecard_address(ec
, ECARD_MEMC
, 0);
3007 host
->irq
= ec
->irq
;
3009 ashost
->host
= host
;
3010 ashost
->scsi
.io_port
= ioaddr(host
->io_port
+ 0x800);
3011 ashost
->scsi
.irq
= host
->irq
;
3012 ashost
->card
.io_intr
= POD_SPACE(host
->io_port
) + 0x800;
3013 ashost
->card
.io_page
= POD_SPACE(host
->io_port
) + 0xc00;
3014 ashost
->card
.io_ram
= ioaddr(host
->io_port
);
3015 ashost
->dma
.io_port
= host
->io_port
+ 0xc00;
3016 ashost
->dma
.io_intr_clear
= POD_SPACE(host
->io_port
) + 0x800;
3018 ec
->irqaddr
= (char *)ioaddr(ashost
->card
.io_intr
);
3022 if (!request_region(host
->io_port
+ 0x800, 2, "acornscsi(sbic)"))
3024 if (!request_region(ashost
->card
.io_intr
, 1, "acornscsi(intr)"))
3026 if (!request_region(ashost
->card
.io_page
, 1, "acornscsi(page)"))
3029 if (!request_region(ashost
->dma
.io_port
, 256, "acornscsi(dmac)"))
3032 if (!request_region(host
->io_port
, 2048, "acornscsi(ram)"))
3035 ret
= request_irq(host
->irq
, acornscsi_intr
, SA_INTERRUPT
, "acornscsi", ashost
);
3037 printk(KERN_CRIT
"scsi%d: IRQ%d not free: %d\n",
3038 host
->host_no
, ashost
->scsi
.irq
, ret
);
3042 memset(&ashost
->stats
, 0, sizeof (ashost
->stats
));
3043 queue_initialise(&ashost
->queues
.issue
);
3044 queue_initialise(&ashost
->queues
.disconnected
);
3045 msgqueue_initialise(&ashost
->scsi
.msgs
);
3047 acornscsi_resetcard(ashost
);
3049 ret
= scsi_add_host(host
, &ec
->dev
);
3053 scsi_scan_host(host
);
3057 free_irq(host
->irq
, ashost
);
3059 release_region(host
->io_port
, 2048);
3062 release_region(ashost
->dma
.io_port
, 256);
3065 release_region(ashost
->card
.io_page
, 1);
3067 release_region(ashost
->card
.io_intr
, 1);
3069 release_region(host
->io_port
+ 0x800, 2);
3071 scsi_host_put(host
);
3076 static void __devexit
acornscsi_remove(struct expansion_card
*ec
)
3078 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
3079 AS_Host
*ashost
= (AS_Host
*)host
->hostdata
;
3081 ecard_set_drvdata(ec
, NULL
);
3082 scsi_remove_host(host
);
3085 * Put card into RESET state
3087 outb(0x80, ashost
->card
.io_page
);
3089 free_irq(host
->irq
, ashost
);
3091 release_region(host
->io_port
+ 0x800, 2);
3092 release_region(ashost
->card
.io_intr
, 1);
3093 release_region(ashost
->card
.io_page
, 1);
3094 release_region(ashost
->dma
.io_port
, 256);
3095 release_region(host
->io_port
, 2048);
3097 msgqueue_free(&ashost
->scsi
.msgs
);
3098 queue_free(&ashost
->queues
.disconnected
);
3099 queue_free(&ashost
->queues
.issue
);
3100 scsi_host_put(host
);
3103 static const struct ecard_id acornscsi_cids
[] = {
3104 { MANU_ACORN
, PROD_ACORN_SCSI
},
3108 static struct ecard_driver acornscsi_driver
= {
3109 .probe
= acornscsi_probe
,
3110 .remove
= __devexit_p(acornscsi_remove
),
3111 .id_table
= acornscsi_cids
,
3113 .name
= "acornscsi",
3117 static int __init
acornscsi_init(void)
3119 return ecard_register_driver(&acornscsi_driver
);
3122 static void __exit
acornscsi_exit(void)
3124 ecard_remove_driver(&acornscsi_driver
);
3127 module_init(acornscsi_init
);
3128 module_exit(acornscsi_exit
);
3130 MODULE_AUTHOR("Russell King");
3131 MODULE_DESCRIPTION("AcornSCSI driver");
3132 MODULE_LICENSE("GPL");