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 "acornscsi.h"
156 #include "msgqueue.h"
159 #include <scsi/scsicam.h>
166 #define ABORT_TAG 0xd
168 #error "Yippee! ABORT TAG is now defined! Remove this error!"
171 #ifdef CONFIG_SCSI_ACORNSCSI_LINK
172 #error SCSI2 LINKed commands not supported (yet)!
177 * DMAC setup parameters
179 #define INIT_DEVCON0 (DEVCON0_RQL|DEVCON0_EXW|DEVCON0_CMP)
180 #define INIT_DEVCON1 (DEVCON1_BHLD)
181 #define DMAC_READ (MODECON_READ)
182 #define DMAC_WRITE (MODECON_WRITE)
183 #define INIT_SBICDMA (CTRL_DMABURST)
185 #define scsi_xferred have_data_in
188 * Size of on-board DMA buffer
190 #define DMAC_BUFFER_SIZE 65536
193 #define STATUS_BUFFER_TO_PRINT 24
195 unsigned int sdtr_period
= SDTR_PERIOD
;
196 unsigned int sdtr_size
= SDTR_SIZE
;
198 static void acornscsi_done(AS_Host
*host
, Scsi_Cmnd
**SCpntp
, unsigned int result
);
199 static int acornscsi_reconnect_finish(AS_Host
*host
);
200 static void acornscsi_dma_cleanup(AS_Host
*host
);
201 static void acornscsi_abortcmd(AS_Host
*host
, unsigned char tag
);
203 /* ====================================================================================
208 sbic_arm_write(unsigned int io_port
, int reg
, int value
)
210 __raw_writeb(reg
, io_port
);
211 __raw_writeb(value
, io_port
+ 4);
214 #define sbic_arm_writenext(io,val) \
215 __raw_writeb((val), (io) + 4)
218 int sbic_arm_read(unsigned int io_port
, int reg
)
221 return __raw_readl(io_port
) & 255;
222 __raw_writeb(reg
, io_port
);
223 return __raw_readl(io_port
+ 4) & 255;
226 #define sbic_arm_readnext(io) \
227 __raw_readb((io) + 4)
230 #define dmac_read(io_port,reg) \
231 inb((io_port) + (reg))
233 #define dmac_write(io_port,reg,value) \
234 ({ outb((value), (io_port) + (reg)); })
236 #define dmac_clearintr(io_port) \
237 ({ outb(0, (io_port)); })
240 unsigned int dmac_address(unsigned int io_port
)
242 return dmac_read(io_port
, DMAC_TXADRHI
) << 16 |
243 dmac_read(io_port
, DMAC_TXADRMD
) << 8 |
244 dmac_read(io_port
, DMAC_TXADRLO
);
248 void acornscsi_dumpdma(AS_Host
*host
, char *where
)
250 unsigned int mode
, addr
, len
;
252 mode
= dmac_read(host
->dma
.io_port
, DMAC_MODECON
);
253 addr
= dmac_address(host
->dma
.io_port
);
254 len
= dmac_read(host
->dma
.io_port
, DMAC_TXCNTHI
) << 8 |
255 dmac_read(host
->dma
.io_port
, DMAC_TXCNTLO
);
257 printk("scsi%d: %s: DMAC %02x @%06x+%04x msk %02x, ",
258 host
->host
->host_no
, where
,
259 mode
, addr
, (len
+ 1) & 0xffff,
260 dmac_read(host
->dma
.io_port
, DMAC_MASKREG
));
262 printk("DMA @%06x, ", host
->dma
.start_addr
);
263 printk("BH @%p +%04x, ", host
->scsi
.SCp
.ptr
,
264 host
->scsi
.SCp
.this_residual
);
265 printk("DT @+%04x ST @+%04x", host
->dma
.transferred
,
266 host
->scsi
.SCp
.scsi_xferred
);
272 unsigned long acornscsi_sbic_xfcount(AS_Host
*host
)
274 unsigned long length
;
276 length
= sbic_arm_read(host
->scsi
.io_port
, SBIC_TRANSCNTH
) << 16;
277 length
|= sbic_arm_readnext(host
->scsi
.io_port
) << 8;
278 length
|= sbic_arm_readnext(host
->scsi
.io_port
);
284 acornscsi_sbic_wait(AS_Host
*host
, int stat_mask
, int stat
, int timeout
, char *msg
)
289 asr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
291 if ((asr
& stat_mask
) == stat
)
297 printk("scsi%d: timeout while %s\n", host
->host
->host_no
, msg
);
303 int acornscsi_sbic_issuecmd(AS_Host
*host
, int command
)
305 if (acornscsi_sbic_wait(host
, ASR_CIP
, 0, 1000, "issuing command"))
308 sbic_arm_write(host
->scsi
.io_port
, SBIC_CMND
, command
);
314 acornscsi_csdelay(unsigned int cs
)
316 unsigned long target_jiffies
, flags
;
318 target_jiffies
= jiffies
+ 1 + cs
* HZ
/ 100;
320 local_save_flags(flags
);
323 while (time_before(jiffies
, target_jiffies
)) barrier();
325 local_irq_restore(flags
);
329 void acornscsi_resetcard(AS_Host
*host
)
331 unsigned int i
, timeout
;
333 /* assert reset line */
334 host
->card
.page_reg
= 0x80;
335 outb(host
->card
.page_reg
, host
->card
.io_page
);
337 /* wait 3 cs. SCSI standard says 25ms. */
338 acornscsi_csdelay(3);
340 host
->card
.page_reg
= 0;
341 outb(host
->card
.page_reg
, host
->card
.io_page
);
344 * Should get a reset from the card
348 if (inb(host
->card
.io_intr
) & 8)
354 printk("scsi%d: timeout while resetting card\n",
355 host
->host
->host_no
);
357 sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
358 sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
);
360 /* setup sbic - WD33C93A */
361 sbic_arm_write(host
->scsi
.io_port
, SBIC_OWNID
, OWNID_EAF
| host
->host
->this_id
);
362 sbic_arm_write(host
->scsi
.io_port
, SBIC_CMND
, CMND_RESET
);
365 * Command should cause a reset interrupt
369 if (inb(host
->card
.io_intr
) & 8)
375 printk("scsi%d: timeout while resetting card\n",
376 host
->host
->host_no
);
378 sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
379 if (sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
) != 0x01)
380 printk(KERN_CRIT
"scsi%d: WD33C93A didn't give enhanced reset interrupt\n",
381 host
->host
->host_no
);
383 sbic_arm_write(host
->scsi
.io_port
, SBIC_CTRL
, INIT_SBICDMA
| CTRL_IDI
);
384 sbic_arm_write(host
->scsi
.io_port
, SBIC_TIMEOUT
, TIMEOUT_TIME
);
385 sbic_arm_write(host
->scsi
.io_port
, SBIC_SYNCHTRANSFER
, SYNCHTRANSFER_2DBA
);
386 sbic_arm_write(host
->scsi
.io_port
, SBIC_SOURCEID
, SOURCEID_ER
| SOURCEID_DSP
);
388 host
->card
.page_reg
= 0x40;
389 outb(host
->card
.page_reg
, host
->card
.io_page
);
391 /* setup dmac - uPC71071 */
392 dmac_write(host
->dma
.io_port
, DMAC_INIT
, 0);
394 dmac_write(host
->dma
.io_port
, DMAC_INIT
, INIT_8BIT
);
395 dmac_write(host
->dma
.io_port
, DMAC_CHANNEL
, CHANNEL_0
);
396 dmac_write(host
->dma
.io_port
, DMAC_DEVCON0
, INIT_DEVCON0
);
397 dmac_write(host
->dma
.io_port
, DMAC_DEVCON1
, INIT_DEVCON1
);
401 host
->scsi
.phase
= PHASE_IDLE
;
402 host
->scsi
.disconnectable
= 0;
404 memset(host
->busyluns
, 0, sizeof(host
->busyluns
));
406 for (i
= 0; i
< 8; i
++) {
407 host
->device
[i
].sync_state
= SYNC_NEGOCIATE
;
408 host
->device
[i
].disconnect_ok
= 1;
411 /* wait 25 cs. SCSI standard says 250ms. */
412 acornscsi_csdelay(25);
415 /*=============================================================================================
416 * Utility routines (eg. debug)
418 #ifdef CONFIG_ACORNSCSI_CONSTANTS
419 static char *acornscsi_interrupttype
[] = {
420 "rst", "suc", "p/a", "3",
421 "term", "5", "6", "7",
422 "serv", "9", "a", "b",
426 static signed char acornscsi_map
[] = {
427 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
428 -1, 2, -1, -1, -1, -1, 3, -1, 4, 5, 6, 7, 8, 9, 10, 11,
429 12, 13, 14, -1, -1, -1, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11,
430 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
431 15, 16, 17, 18, 19, -1, -1, 20, 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 21, 22, -1, -1, -1, 23, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11,
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,
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
445 static char *acornscsi_interruptcode
[] = {
447 "reset - normal mode", /* 00 */
448 "reset - advanced mode", /* 01 */
463 "/ACK asserted", /* 20 */
464 "save-data-ptr", /* 21 */
469 "unexpected disconnect", /* 41 */
470 "sel timeout", /* 42 */
472 "P err+ATN", /* 44 */
473 "bad status byte", /* 47 */
476 "resel, no id", /* 80 */
482 void print_scsi_status(unsigned int ssr
)
484 if (acornscsi_map
[ssr
] != -1)
486 acornscsi_interrupttype
[(ssr
>> 4)],
487 acornscsi_interruptcode
[acornscsi_map
[ssr
]]);
489 printk("%X:%X", ssr
>> 4, ssr
& 0x0f);
494 void print_sbic_status(int asr
, int ssr
, int cmdphase
)
496 #ifdef CONFIG_ACORNSCSI_CONSTANTS
497 printk("sbic: %c%c%c%c%c%c ",
498 asr
& ASR_INT
? 'I' : 'i',
499 asr
& ASR_LCI
? 'L' : 'l',
500 asr
& ASR_BSY
? 'B' : 'b',
501 asr
& ASR_CIP
? 'C' : 'c',
502 asr
& ASR_PE
? 'P' : 'p',
503 asr
& ASR_DBR
? 'D' : 'd');
505 print_scsi_status(ssr
);
506 printk(" ph %02X\n", cmdphase
);
508 printk("sbic: %02X scsi: %X:%X ph: %02X\n",
509 asr
, (ssr
& 0xf0)>>4, ssr
& 0x0f, cmdphase
);
514 acornscsi_dumplogline(AS_Host
*host
, int target
, int line
)
519 ptr
= host
->status_ptr
[target
] - STATUS_BUFFER_TO_PRINT
;
521 ptr
+= STATUS_BUFFER_SIZE
;
523 printk("%c: %3s:", target
== 8 ? 'H' : '0' + target
,
524 line
== 0 ? "ph" : line
== 1 ? "ssr" : "int");
526 prev
= host
->status
[target
][ptr
].when
;
528 for (; ptr
!= host
->status_ptr
[target
]; ptr
= (ptr
+ 1) & (STATUS_BUFFER_SIZE
- 1)) {
529 unsigned long time_diff
;
531 if (!host
->status
[target
][ptr
].when
)
536 printk("%c%02X", host
->status
[target
][ptr
].irq
? '-' : ' ',
537 host
->status
[target
][ptr
].ph
);
541 printk(" %02X", host
->status
[target
][ptr
].ssr
);
545 time_diff
= host
->status
[target
][ptr
].when
- prev
;
546 prev
= host
->status
[target
][ptr
].when
;
549 else if (time_diff
>= 100)
552 printk(" %02ld", time_diff
);
561 void acornscsi_dumplog(AS_Host
*host
, int target
)
564 acornscsi_dumplogline(host
, target
, 0);
565 acornscsi_dumplogline(host
, target
, 1);
566 acornscsi_dumplogline(host
, target
, 2);
576 char acornscsi_target(AS_Host
*host
)
579 return '0' + host
->SCpnt
->device
->id
;
584 * Prototype: cmdtype_t acornscsi_cmdtype(int command)
585 * Purpose : differentiate READ from WRITE from other commands
586 * Params : command - command to interpret
587 * Returns : CMD_READ - command reads data,
588 * CMD_WRITE - command writes data,
589 * CMD_MISC - everything else
592 cmdtype_t
acornscsi_cmdtype(int command
)
595 case WRITE_6
: case WRITE_10
: case WRITE_12
:
597 case READ_6
: case READ_10
: case READ_12
:
605 * Prototype: int acornscsi_datadirection(int command)
606 * Purpose : differentiate between commands that have a DATA IN phase
607 * and a DATA OUT phase
608 * Params : command - command to interpret
609 * Returns : DATADIR_OUT - data out phase expected
610 * DATADIR_IN - data in phase expected
613 datadir_t
acornscsi_datadirection(int command
)
616 case CHANGE_DEFINITION
: case COMPARE
: case COPY
:
617 case COPY_VERIFY
: case LOG_SELECT
: case MODE_SELECT
:
618 case MODE_SELECT_10
: case SEND_DIAGNOSTIC
: case WRITE_BUFFER
:
619 case FORMAT_UNIT
: case REASSIGN_BLOCKS
: case RESERVE
:
620 case SEARCH_EQUAL
: case SEARCH_HIGH
: case SEARCH_LOW
:
621 case WRITE_6
: case WRITE_10
: case WRITE_VERIFY
:
622 case UPDATE_BLOCK
: case WRITE_LONG
: case WRITE_SAME
:
623 case SEARCH_HIGH_12
: case SEARCH_EQUAL_12
: case SEARCH_LOW_12
:
624 case WRITE_12
: case WRITE_VERIFY_12
: case SET_WINDOW
:
625 case MEDIUM_SCAN
: case SEND_VOLUME_TAG
: case 0xea:
633 * Purpose : provide values for synchronous transfers with 33C93.
634 * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
635 * Modified by Russell King for 8MHz WD33C93A
637 static struct sync_xfer_tbl
{
638 unsigned int period_ns
;
639 unsigned char reg_value
;
640 } sync_xfer_table
[] = {
641 { 1, 0x20 }, { 249, 0x20 }, { 374, 0x30 },
642 { 499, 0x40 }, { 624, 0x50 }, { 749, 0x60 },
643 { 874, 0x70 }, { 999, 0x00 }, { 0, 0 }
647 * Prototype: int acornscsi_getperiod(unsigned char syncxfer)
648 * Purpose : period for the synchronous transfer setting
649 * Params : syncxfer SYNCXFER register value
650 * Returns : period in ns.
653 int acornscsi_getperiod(unsigned char syncxfer
)
658 if (syncxfer
== 0x10)
661 for (i
= 1; sync_xfer_table
[i
].period_ns
; i
++)
662 if (syncxfer
== sync_xfer_table
[i
].reg_value
)
663 return sync_xfer_table
[i
].period_ns
;
668 * Prototype: int round_period(unsigned int period)
669 * Purpose : return index into above table for a required REQ period
670 * Params : period - time (ns) for REQ
671 * Returns : table index
672 * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
675 int round_period(unsigned int period
)
679 for (i
= 1; sync_xfer_table
[i
].period_ns
; i
++) {
680 if ((period
<= sync_xfer_table
[i
].period_ns
) &&
681 (period
> sync_xfer_table
[i
- 1].period_ns
))
688 * Prototype: unsigned char calc_sync_xfer(unsigned int period, unsigned int offset)
689 * Purpose : calculate value for 33c93s SYNC register
690 * Params : period - time (ns) for REQ
691 * offset - offset in bytes between REQ/ACK
692 * Returns : value for SYNC register
693 * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
696 unsigned char calc_sync_xfer(unsigned int period
, unsigned int offset
)
698 return sync_xfer_table
[round_period(period
)].reg_value
|
699 ((offset
< SDTR_SIZE
) ? offset
: SDTR_SIZE
);
702 /* ====================================================================================
706 * Function: acornscsi_kick(AS_Host *host)
707 * Purpose : kick next command to interface
708 * Params : host - host to send command to
709 * Returns : INTR_IDLE if idle, otherwise INTR_PROCESSING
710 * Notes : interrupts are always disabled!
713 intr_ret_t
acornscsi_kick(AS_Host
*host
)
718 /* first check to see if a command is waiting to be executed */
719 SCpnt
= host
->origSCpnt
;
720 host
->origSCpnt
= NULL
;
722 /* retrieve next command */
724 SCpnt
= queue_remove_exclude(&host
->queues
.issue
, host
->busyluns
);
731 if (host
->scsi
.disconnectable
&& host
->SCpnt
) {
732 queue_add_cmd_tail(&host
->queues
.disconnected
, host
->SCpnt
);
733 host
->scsi
.disconnectable
= 0;
734 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
735 DBG(host
->SCpnt
, printk("scsi%d.%c: moved command to disconnected queue\n",
736 host
->host
->host_no
, acornscsi_target(host
)));
742 * If we have an interrupt pending, then we may have been reselected.
743 * In this case, we don't want to write to the registers
745 if (!(sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
) & (ASR_INT
|ASR_BSY
|ASR_CIP
))) {
746 sbic_arm_write(host
->scsi
.io_port
, SBIC_DESTID
, SCpnt
->device
->id
);
747 sbic_arm_write(host
->scsi
.io_port
, SBIC_CMND
, CMND_SELWITHATN
);
751 * claim host busy - all of these must happen atomically wrt
752 * our interrupt routine. Failure means command loss.
754 host
->scsi
.phase
= PHASE_CONNECTING
;
756 host
->scsi
.SCp
= SCpnt
->SCp
;
757 host
->dma
.xfer_setup
= 0;
758 host
->dma
.xfer_required
= 0;
759 host
->dma
.xfer_done
= 0;
761 #if (DEBUG & (DEBUG_ABORT|DEBUG_CONNECT))
762 DBG(SCpnt
,printk("scsi%d.%c: starting cmd %02X\n",
763 host
->host
->host_no
, '0' + SCpnt
->device
->id
,
768 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
770 * tagged queueing - allocate a new tag to this command
772 if (SCpnt
->device
->simple_tags
) {
773 SCpnt
->device
->current_tag
+= 1;
774 if (SCpnt
->device
->current_tag
== 0)
775 SCpnt
->device
->current_tag
= 1;
776 SCpnt
->tag
= SCpnt
->device
->current_tag
;
779 set_bit(SCpnt
->device
->id
* 8 + SCpnt
->device
->lun
, host
->busyluns
);
781 host
->stats
.removes
+= 1;
783 switch (acornscsi_cmdtype(SCpnt
->cmnd
[0])) {
785 host
->stats
.writes
+= 1;
788 host
->stats
.reads
+= 1;
791 host
->stats
.miscs
+= 1;
796 return INTR_PROCESSING
;
800 * Function: void acornscsi_done(AS_Host *host, Scsi_Cmnd **SCpntp, unsigned int result)
801 * Purpose : complete processing for command
802 * Params : host - interface that completed
803 * result - driver byte of result
806 void acornscsi_done(AS_Host
*host
, Scsi_Cmnd
**SCpntp
, unsigned int result
)
808 Scsi_Cmnd
*SCpnt
= *SCpntp
;
811 sbic_arm_write(host
->scsi
.io_port
, SBIC_SOURCEID
, SOURCEID_ER
| SOURCEID_DSP
);
813 host
->stats
.fins
+= 1;
818 acornscsi_dma_cleanup(host
);
820 SCpnt
->result
= result
<< 16 | host
->scsi
.SCp
.Message
<< 8 | host
->scsi
.SCp
.Status
;
823 * In theory, this should not happen. In practice, it seems to.
824 * Only trigger an error if the device attempts to report all happy
825 * but with untransferred buffers... If we don't do something, then
826 * data loss will occur. Should we check SCpnt->underflow here?
827 * It doesn't appear to be set to something meaningful by the higher
828 * levels all the time.
830 if (result
== DID_OK
) {
833 if (SCpnt
->underflow
== 0) {
834 if (host
->scsi
.SCp
.ptr
&&
835 acornscsi_cmdtype(SCpnt
->cmnd
[0]) != CMD_MISC
)
838 if (host
->scsi
.SCp
.scsi_xferred
< SCpnt
->underflow
||
839 host
->scsi
.SCp
.scsi_xferred
!= host
->dma
.transferred
)
843 /* ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.6)
844 * Targets which break data transfers into multiple
845 * connections shall end each successful connection
846 * (except possibly the last) with a SAVE DATA
847 * POINTER - DISCONNECT message sequence.
849 * This makes it difficult to ensure that a transfer has
850 * completed. If we reach the end of a transfer during
851 * the command, then we can only have finished the transfer.
852 * therefore, if we seem to have some data remaining, this
855 if (host
->dma
.xfer_done
)
859 switch (status_byte(SCpnt
->result
)) {
860 case CHECK_CONDITION
:
861 case COMMAND_TERMINATED
:
864 case RESERVATION_CONFLICT
:
868 printk(KERN_ERR
"scsi%d.H: incomplete data transfer detected: result=%08X command=",
869 host
->host
->host_no
, SCpnt
->result
);
870 __scsi_print_command(SCpnt
->cmnd
);
871 acornscsi_dumpdma(host
, "done");
872 acornscsi_dumplog(host
, SCpnt
->device
->id
);
873 SCpnt
->result
&= 0xffff;
874 SCpnt
->result
|= DID_ERROR
<< 16;
879 if (!SCpnt
->scsi_done
)
880 panic("scsi%d.H: null scsi_done function in acornscsi_done", host
->host
->host_no
);
882 clear_bit(SCpnt
->device
->id
* 8 + SCpnt
->device
->lun
, host
->busyluns
);
884 SCpnt
->scsi_done(SCpnt
);
886 printk("scsi%d: null command in acornscsi_done", host
->host
->host_no
);
888 host
->scsi
.phase
= PHASE_IDLE
;
891 /* ====================================================================================
895 * Purpose : update SCSI Data Pointer
896 * Notes : this will only be one SG entry or less
899 void acornscsi_data_updateptr(AS_Host
*host
, Scsi_Pointer
*SCp
, unsigned int length
)
902 SCp
->this_residual
-= length
;
904 if (SCp
->this_residual
== 0 && next_SCp(SCp
) == 0)
905 host
->dma
.xfer_done
= 1;
909 * Prototype: void acornscsi_data_read(AS_Host *host, char *ptr,
910 * unsigned int start_addr, unsigned int length)
911 * Purpose : read data from DMA RAM
912 * Params : host - host to transfer from
914 * start_addr - host mem address
915 * length - number of bytes to transfer
916 * Notes : this will only be one SG entry or less
919 void acornscsi_data_read(AS_Host
*host
, char *ptr
,
920 unsigned int start_addr
, unsigned int length
)
922 extern void __acornscsi_in(int port
, char *buf
, int len
);
923 unsigned int page
, offset
, len
= length
;
925 page
= (start_addr
>> 12);
926 offset
= start_addr
& ((1 << 12) - 1);
928 outb((page
& 0x3f) | host
->card
.page_reg
, host
->card
.io_page
);
931 unsigned int this_len
;
933 if (len
+ offset
> (1 << 12))
934 this_len
= (1 << 12) - offset
;
938 __acornscsi_in(host
->card
.io_ram
+ (offset
<< 1), ptr
, this_len
);
944 if (offset
== (1 << 12)) {
947 outb((page
& 0x3f) | host
->card
.page_reg
, host
->card
.io_page
);
950 outb(host
->card
.page_reg
, host
->card
.io_page
);
954 * Prototype: void acornscsi_data_write(AS_Host *host, char *ptr,
955 * unsigned int start_addr, unsigned int length)
956 * Purpose : write data to DMA RAM
957 * Params : host - host to transfer from
959 * start_addr - host mem address
960 * length - number of bytes to transfer
961 * Notes : this will only be one SG entry or less
964 void acornscsi_data_write(AS_Host
*host
, char *ptr
,
965 unsigned int start_addr
, unsigned int length
)
967 extern void __acornscsi_out(int port
, char *buf
, int len
);
968 unsigned int page
, offset
, len
= length
;
970 page
= (start_addr
>> 12);
971 offset
= start_addr
& ((1 << 12) - 1);
973 outb((page
& 0x3f) | host
->card
.page_reg
, host
->card
.io_page
);
976 unsigned int this_len
;
978 if (len
+ offset
> (1 << 12))
979 this_len
= (1 << 12) - offset
;
983 __acornscsi_out(host
->card
.io_ram
+ (offset
<< 1), ptr
, this_len
);
989 if (offset
== (1 << 12)) {
992 outb((page
& 0x3f) | host
->card
.page_reg
, host
->card
.io_page
);
995 outb(host
->card
.page_reg
, host
->card
.io_page
);
998 /* =========================================================================================
999 * On-board DMA routines
1003 * Prototype: void acornscsi_dmastop(AS_Host *host)
1004 * Purpose : stop all DMA
1005 * Params : host - host on which to stop DMA
1006 * Notes : This is called when leaving DATA IN/OUT phase,
1007 * or when interface is RESET
1010 void acornscsi_dma_stop(AS_Host
*host
)
1012 dmac_write(host
->dma
.io_port
, DMAC_MASKREG
, MASK_ON
);
1013 dmac_clearintr(host
->dma
.io_intr_clear
);
1015 #if (DEBUG & DEBUG_DMA)
1016 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "stop"));
1021 * Function: void acornscsi_dma_setup(AS_Host *host, dmadir_t direction)
1022 * Purpose : setup DMA controller for data transfer
1023 * Params : host - host to setup
1024 * direction - data transfer direction
1025 * Notes : This is called when entering DATA I/O phase, not
1026 * while we're in a DATA I/O phase
1029 void acornscsi_dma_setup(AS_Host
*host
, dmadir_t direction
)
1031 unsigned int address
, length
, mode
;
1033 host
->dma
.direction
= direction
;
1035 dmac_write(host
->dma
.io_port
, DMAC_MASKREG
, MASK_ON
);
1037 if (direction
== DMA_OUT
) {
1038 #if (DEBUG & DEBUG_NO_WRITE)
1039 if (NO_WRITE
& (1 << host
->SCpnt
->device
->id
)) {
1040 printk(KERN_CRIT
"scsi%d.%c: I can't handle DMA_OUT!\n",
1041 host
->host
->host_no
, acornscsi_target(host
));
1050 * Allocate some buffer space, limited to half the buffer size
1052 length
= min_t(unsigned int, host
->scsi
.SCp
.this_residual
, DMAC_BUFFER_SIZE
/ 2);
1054 host
->dma
.start_addr
= address
= host
->dma
.free_addr
;
1055 host
->dma
.free_addr
= (host
->dma
.free_addr
+ length
) &
1056 (DMAC_BUFFER_SIZE
- 1);
1059 * Transfer data to DMA memory
1061 if (direction
== DMA_OUT
)
1062 acornscsi_data_write(host
, host
->scsi
.SCp
.ptr
, host
->dma
.start_addr
,
1066 dmac_write(host
->dma
.io_port
, DMAC_TXCNTLO
, length
);
1067 dmac_write(host
->dma
.io_port
, DMAC_TXCNTHI
, length
>> 8);
1068 dmac_write(host
->dma
.io_port
, DMAC_TXADRLO
, address
);
1069 dmac_write(host
->dma
.io_port
, DMAC_TXADRMD
, address
>> 8);
1070 dmac_write(host
->dma
.io_port
, DMAC_TXADRHI
, 0);
1071 dmac_write(host
->dma
.io_port
, DMAC_MODECON
, mode
);
1072 dmac_write(host
->dma
.io_port
, DMAC_MASKREG
, MASK_OFF
);
1074 #if (DEBUG & DEBUG_DMA)
1075 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "strt"));
1077 host
->dma
.xfer_setup
= 1;
1082 * Function: void acornscsi_dma_cleanup(AS_Host *host)
1083 * Purpose : ensure that all DMA transfers are up-to-date & host->scsi.SCp is correct
1084 * Params : host - host to finish
1085 * Notes : This is called when a command is:
1086 * terminating, RESTORE_POINTERS, SAVE_POINTERS, DISCONECT
1087 * : This must not return until all transfers are completed.
1090 void acornscsi_dma_cleanup(AS_Host
*host
)
1092 dmac_write(host
->dma
.io_port
, DMAC_MASKREG
, MASK_ON
);
1093 dmac_clearintr(host
->dma
.io_intr_clear
);
1096 * Check for a pending transfer
1098 if (host
->dma
.xfer_required
) {
1099 host
->dma
.xfer_required
= 0;
1100 if (host
->dma
.direction
== DMA_IN
)
1101 acornscsi_data_read(host
, host
->dma
.xfer_ptr
,
1102 host
->dma
.xfer_start
, host
->dma
.xfer_length
);
1106 * Has a transfer been setup?
1108 if (host
->dma
.xfer_setup
) {
1109 unsigned int transferred
;
1111 host
->dma
.xfer_setup
= 0;
1113 #if (DEBUG & DEBUG_DMA)
1114 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "cupi"));
1118 * Calculate number of bytes transferred from DMA.
1120 transferred
= dmac_address(host
->dma
.io_port
) - host
->dma
.start_addr
;
1121 host
->dma
.transferred
+= transferred
;
1123 if (host
->dma
.direction
== DMA_IN
)
1124 acornscsi_data_read(host
, host
->scsi
.SCp
.ptr
,
1125 host
->dma
.start_addr
, transferred
);
1128 * Update SCSI pointers
1130 acornscsi_data_updateptr(host
, &host
->scsi
.SCp
, transferred
);
1131 #if (DEBUG & DEBUG_DMA)
1132 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "cupo"));
1138 * Function: void acornscsi_dmacintr(AS_Host *host)
1139 * Purpose : handle interrupts from DMAC device
1140 * Params : host - host to process
1141 * Notes : If reading, we schedule the read to main memory &
1142 * allow the transfer to continue.
1143 * : If writing, we fill the onboard DMA memory from main
1145 * : Called whenever DMAC finished it's current transfer.
1148 void acornscsi_dma_intr(AS_Host
*host
)
1150 unsigned int address
, length
, transferred
;
1152 #if (DEBUG & DEBUG_DMA)
1153 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "inti"));
1156 dmac_write(host
->dma
.io_port
, DMAC_MASKREG
, MASK_ON
);
1157 dmac_clearintr(host
->dma
.io_intr_clear
);
1160 * Calculate amount transferred via DMA
1162 transferred
= dmac_address(host
->dma
.io_port
) - host
->dma
.start_addr
;
1163 host
->dma
.transferred
+= transferred
;
1166 * Schedule DMA transfer off board
1168 if (host
->dma
.direction
== DMA_IN
) {
1169 host
->dma
.xfer_start
= host
->dma
.start_addr
;
1170 host
->dma
.xfer_length
= transferred
;
1171 host
->dma
.xfer_ptr
= host
->scsi
.SCp
.ptr
;
1172 host
->dma
.xfer_required
= 1;
1175 acornscsi_data_updateptr(host
, &host
->scsi
.SCp
, transferred
);
1178 * Allocate some buffer space, limited to half the on-board RAM size
1180 length
= min_t(unsigned int, host
->scsi
.SCp
.this_residual
, DMAC_BUFFER_SIZE
/ 2);
1182 host
->dma
.start_addr
= address
= host
->dma
.free_addr
;
1183 host
->dma
.free_addr
= (host
->dma
.free_addr
+ length
) &
1184 (DMAC_BUFFER_SIZE
- 1);
1187 * Transfer data to DMA memory
1189 if (host
->dma
.direction
== DMA_OUT
)
1190 acornscsi_data_write(host
, host
->scsi
.SCp
.ptr
, host
->dma
.start_addr
,
1194 dmac_write(host
->dma
.io_port
, DMAC_TXCNTLO
, length
);
1195 dmac_write(host
->dma
.io_port
, DMAC_TXCNTHI
, length
>> 8);
1196 dmac_write(host
->dma
.io_port
, DMAC_TXADRLO
, address
);
1197 dmac_write(host
->dma
.io_port
, DMAC_TXADRMD
, address
>> 8);
1198 dmac_write(host
->dma
.io_port
, DMAC_TXADRHI
, 0);
1199 dmac_write(host
->dma
.io_port
, DMAC_MASKREG
, MASK_OFF
);
1201 #if (DEBUG & DEBUG_DMA)
1202 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "into"));
1205 host
->dma
.xfer_setup
= 0;
1208 * If the interface still wants more, then this is an error.
1209 * We give it another byte, but we also attempt to raise an
1210 * attention condition. We continue giving one byte until
1211 * the device recognises the attention.
1213 if (dmac_read(host
->dma
.io_port
, DMAC_STATUS
) & STATUS_RQ0
) {
1214 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
1216 dmac_write(host
->dma
.io_port
, DMAC_TXCNTLO
, 0);
1217 dmac_write(host
->dma
.io_port
, DMAC_TXCNTHI
, 0);
1218 dmac_write(host
->dma
.io_port
, DMAC_TXADRLO
, 0);
1219 dmac_write(host
->dma
.io_port
, DMAC_TXADRMD
, 0);
1220 dmac_write(host
->dma
.io_port
, DMAC_TXADRHI
, 0);
1221 dmac_write(host
->dma
.io_port
, DMAC_MASKREG
, MASK_OFF
);
1228 * Function: void acornscsi_dma_xfer(AS_Host *host)
1229 * Purpose : transfer data between AcornSCSI and memory
1230 * Params : host - host to process
1233 void acornscsi_dma_xfer(AS_Host
*host
)
1235 host
->dma
.xfer_required
= 0;
1237 if (host
->dma
.direction
== DMA_IN
)
1238 acornscsi_data_read(host
, host
->dma
.xfer_ptr
,
1239 host
->dma
.xfer_start
, host
->dma
.xfer_length
);
1243 * Function: void acornscsi_dma_adjust(AS_Host *host)
1244 * Purpose : adjust DMA pointers & count for bytes transferred to
1245 * SBIC but not SCSI bus.
1246 * Params : host - host to adjust DMA count for
1249 void acornscsi_dma_adjust(AS_Host
*host
)
1251 if (host
->dma
.xfer_setup
) {
1252 signed long transferred
;
1253 #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
1254 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "adji"));
1257 * Calculate correct DMA address - DMA is ahead of SCSI bus while
1259 * host->scsi.SCp.scsi_xferred is the number of bytes
1260 * actually transferred to/from the SCSI bus.
1261 * host->dma.transferred is the number of bytes transferred
1262 * over DMA since host->dma.start_addr was last set.
1264 * real_dma_addr = host->dma.start_addr + host->scsi.SCp.scsi_xferred
1265 * - host->dma.transferred
1267 transferred
= host
->scsi
.SCp
.scsi_xferred
- host
->dma
.transferred
;
1268 if (transferred
< 0)
1269 printk("scsi%d.%c: Ack! DMA write correction %ld < 0!\n",
1270 host
->host
->host_no
, acornscsi_target(host
), transferred
);
1271 else if (transferred
== 0)
1272 host
->dma
.xfer_setup
= 0;
1274 transferred
+= host
->dma
.start_addr
;
1275 dmac_write(host
->dma
.io_port
, DMAC_TXADRLO
, transferred
);
1276 dmac_write(host
->dma
.io_port
, DMAC_TXADRMD
, transferred
>> 8);
1277 dmac_write(host
->dma
.io_port
, DMAC_TXADRHI
, transferred
>> 16);
1278 #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
1279 DBG(host
->SCpnt
, acornscsi_dumpdma(host
, "adjo"));
1286 /* =========================================================================================
1290 acornscsi_write_pio(AS_Host
*host
, char *bytes
, int *ptr
, int len
, unsigned int max_timeout
)
1292 unsigned int asr
, timeout
= max_timeout
;
1295 while (my_ptr
< len
) {
1296 asr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
1298 if (asr
& ASR_DBR
) {
1299 timeout
= max_timeout
;
1301 sbic_arm_write(host
->scsi
.io_port
, SBIC_DATA
, bytes
[my_ptr
++]);
1302 } else if (asr
& ASR_INT
)
1304 else if (--timeout
== 0)
1311 return (timeout
== 0) ? -1 : 0;
1315 * Function: void acornscsi_sendcommand(AS_Host *host)
1316 * Purpose : send a command to a target
1317 * Params : host - host which is connected to target
1320 acornscsi_sendcommand(AS_Host
*host
)
1322 Scsi_Cmnd
*SCpnt
= host
->SCpnt
;
1324 sbic_arm_write(host
->scsi
.io_port
, SBIC_TRANSCNTH
, 0);
1325 sbic_arm_writenext(host
->scsi
.io_port
, 0);
1326 sbic_arm_writenext(host
->scsi
.io_port
, SCpnt
->cmd_len
- host
->scsi
.SCp
.sent_command
);
1328 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
);
1330 if (acornscsi_write_pio(host
, SCpnt
->cmnd
,
1331 (int *)&host
->scsi
.SCp
.sent_command
, SCpnt
->cmd_len
, 1000000))
1332 printk("scsi%d: timeout while sending command\n", host
->host
->host_no
);
1334 host
->scsi
.phase
= PHASE_COMMAND
;
1338 void acornscsi_sendmessage(AS_Host
*host
)
1340 unsigned int message_length
= msgqueue_msglength(&host
->scsi
.msgs
);
1342 struct message
*msg
;
1344 #if (DEBUG & DEBUG_MESSAGES)
1345 printk("scsi%d.%c: sending message ",
1346 host
->host
->host_no
, acornscsi_target(host
));
1349 switch (message_length
) {
1351 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
| CMND_SBT
);
1353 acornscsi_sbic_wait(host
, ASR_DBR
, ASR_DBR
, 1000, "sending message 1");
1355 sbic_arm_write(host
->scsi
.io_port
, SBIC_DATA
, NOP
);
1357 host
->scsi
.last_message
= NOP
;
1358 #if (DEBUG & DEBUG_MESSAGES)
1364 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
| CMND_SBT
);
1365 msg
= msgqueue_getmsg(&host
->scsi
.msgs
, 0);
1367 acornscsi_sbic_wait(host
, ASR_DBR
, ASR_DBR
, 1000, "sending message 2");
1369 sbic_arm_write(host
->scsi
.io_port
, SBIC_DATA
, msg
->msg
[0]);
1371 host
->scsi
.last_message
= msg
->msg
[0];
1372 #if (DEBUG & DEBUG_MESSAGES)
1373 scsi_print_msg(msg
->msg
);
1379 * ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.14)
1380 * 'When a target sends this (MESSAGE_REJECT) message, it
1381 * shall change to MESSAGE IN phase and send this message
1382 * prior to requesting additional message bytes from the
1383 * initiator. This provides an interlock so that the
1384 * initiator can determine which message byte is rejected.
1386 sbic_arm_write(host
->scsi
.io_port
, SBIC_TRANSCNTH
, 0);
1387 sbic_arm_writenext(host
->scsi
.io_port
, 0);
1388 sbic_arm_writenext(host
->scsi
.io_port
, message_length
);
1389 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
);
1392 while ((msg
= msgqueue_getmsg(&host
->scsi
.msgs
, msgnr
++)) != NULL
) {
1394 #if (DEBUG & DEBUG_MESSAGES)
1395 scsi_print_msg(msg
);
1398 if (acornscsi_write_pio(host
, msg
->msg
, &i
, msg
->length
, 1000000))
1399 printk("scsi%d: timeout while sending message\n", host
->host
->host_no
);
1401 host
->scsi
.last_message
= msg
->msg
[0];
1402 if (msg
->msg
[0] == EXTENDED_MESSAGE
)
1403 host
->scsi
.last_message
|= msg
->msg
[2] << 8;
1405 if (i
!= msg
->length
)
1410 #if (DEBUG & DEBUG_MESSAGES)
1416 * Function: void acornscsi_readstatusbyte(AS_Host *host)
1417 * Purpose : Read status byte from connected target
1418 * Params : host - host connected to target
1421 void acornscsi_readstatusbyte(AS_Host
*host
)
1423 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
|CMND_SBT
);
1424 acornscsi_sbic_wait(host
, ASR_DBR
, ASR_DBR
, 1000, "reading status byte");
1425 host
->scsi
.SCp
.Status
= sbic_arm_read(host
->scsi
.io_port
, SBIC_DATA
);
1429 * Function: unsigned char acornscsi_readmessagebyte(AS_Host *host)
1430 * Purpose : Read one message byte from connected target
1431 * Params : host - host connected to target
1434 unsigned char acornscsi_readmessagebyte(AS_Host
*host
)
1436 unsigned char message
;
1438 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
| CMND_SBT
);
1440 acornscsi_sbic_wait(host
, ASR_DBR
, ASR_DBR
, 1000, "for message byte");
1442 message
= sbic_arm_read(host
->scsi
.io_port
, SBIC_DATA
);
1444 /* wait for MSGIN-XFER-PAUSED */
1445 acornscsi_sbic_wait(host
, ASR_INT
, ASR_INT
, 1000, "for interrupt after message byte");
1447 sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
);
1453 * Function: void acornscsi_message(AS_Host *host)
1454 * Purpose : Read complete message from connected target & action message
1455 * Params : host - host connected to target
1458 void acornscsi_message(AS_Host
*host
)
1460 unsigned char message
[16];
1461 unsigned int msgidx
= 0, msglen
= 1;
1464 message
[msgidx
] = acornscsi_readmessagebyte(host
);
1468 if (message
[0] == EXTENDED_MESSAGE
||
1469 (message
[0] >= 0x20 && message
[0] <= 0x2f))
1474 if (message
[0] == EXTENDED_MESSAGE
)
1475 msglen
+= message
[msgidx
];
1479 if (msgidx
< msglen
) {
1480 acornscsi_sbic_issuecmd(host
, CMND_NEGATEACK
);
1482 /* wait for next msg-in */
1483 acornscsi_sbic_wait(host
, ASR_INT
, ASR_INT
, 1000, "for interrupt after negate ack");
1484 sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
);
1486 } while (msgidx
< msglen
);
1488 #if (DEBUG & DEBUG_MESSAGES)
1489 printk("scsi%d.%c: message in: ",
1490 host
->host
->host_no
, acornscsi_target(host
));
1491 scsi_print_msg(message
);
1495 if (host
->scsi
.phase
== PHASE_RECONNECTED
) {
1497 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
1498 * 'Whenever a target reconnects to an initiator to continue
1499 * a tagged I/O process, the SIMPLE QUEUE TAG message shall
1500 * be sent immediately following the IDENTIFY message...'
1502 if (message
[0] == SIMPLE_QUEUE_TAG
)
1503 host
->scsi
.reconnected
.tag
= message
[1];
1504 if (acornscsi_reconnect_finish(host
))
1505 host
->scsi
.phase
= PHASE_MSGIN
;
1508 switch (message
[0]) {
1511 case COMMAND_COMPLETE
:
1512 if (host
->scsi
.phase
!= PHASE_STATUSIN
) {
1513 printk(KERN_ERR
"scsi%d.%c: command complete following non-status in phase?\n",
1514 host
->host
->host_no
, acornscsi_target(host
));
1515 acornscsi_dumplog(host
, host
->SCpnt
->device
->id
);
1517 host
->scsi
.phase
= PHASE_DONE
;
1518 host
->scsi
.SCp
.Message
= message
[0];
1523 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.20)
1524 * 'The SAVE DATA POINTER message is sent from a target to
1525 * direct the initiator to copy the active data pointer to
1526 * the saved data pointer for the current I/O process.
1528 acornscsi_dma_cleanup(host
);
1529 host
->SCpnt
->SCp
= host
->scsi
.SCp
;
1530 host
->SCpnt
->SCp
.sent_command
= 0;
1531 host
->scsi
.phase
= PHASE_MSGIN
;
1534 case RESTORE_POINTERS
:
1536 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.19)
1537 * 'The RESTORE POINTERS message is sent from a target to
1538 * direct the initiator to copy the most recently saved
1539 * command, data, and status pointers for the I/O process
1540 * to the corresponding active pointers. The command and
1541 * status pointers shall be restored to the beginning of
1542 * the present command and status areas.'
1544 acornscsi_dma_cleanup(host
);
1545 host
->scsi
.SCp
= host
->SCpnt
->SCp
;
1546 host
->scsi
.phase
= PHASE_MSGIN
;
1551 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 6.4.2)
1552 * 'On those occasions when an error or exception condition occurs
1553 * and the target elects to repeat the information transfer, the
1554 * target may repeat the transfer either issuing a RESTORE POINTERS
1555 * message or by disconnecting without issuing a SAVE POINTERS
1556 * message. When reconnection is completed, the most recent
1557 * saved pointer values are restored.'
1559 acornscsi_dma_cleanup(host
);
1560 host
->scsi
.phase
= PHASE_DISCONNECT
;
1563 case MESSAGE_REJECT
:
1564 #if 0 /* this isn't needed any more */
1566 * If we were negociating sync transfer, we don't yet know if
1567 * this REJECT is for the sync transfer or for the tagged queue/wide
1568 * transfer. Re-initiate sync transfer negociation now, and if
1569 * we got a REJECT in response to SDTR, then it'll be set to DONE.
1571 if (host
->device
[host
->SCpnt
->device
->id
].sync_state
== SYNC_SENT_REQUEST
)
1572 host
->device
[host
->SCpnt
->device
->id
].sync_state
= SYNC_NEGOCIATE
;
1576 * If we have any messages waiting to go out, then assert ATN now
1578 if (msgqueue_msglength(&host
->scsi
.msgs
))
1579 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1581 switch (host
->scsi
.last_message
) {
1582 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
1583 case HEAD_OF_QUEUE_TAG
:
1584 case ORDERED_QUEUE_TAG
:
1585 case SIMPLE_QUEUE_TAG
:
1587 * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
1588 * If a target does not implement tagged queuing and a queue tag
1589 * message is received, it shall respond with a MESSAGE REJECT
1590 * message and accept the I/O process as if it were untagged.
1592 printk(KERN_NOTICE
"scsi%d.%c: disabling tagged queueing\n",
1593 host
->host
->host_no
, acornscsi_target(host
));
1594 host
->SCpnt
->device
->simple_tags
= 0;
1595 set_bit(host
->SCpnt
->device
->id
* 8 + host
->SCpnt
->device
->lun
, host
->busyluns
);
1598 case EXTENDED_MESSAGE
| (EXTENDED_SDTR
<< 8):
1600 * Target can't handle synchronous transfers
1602 printk(KERN_NOTICE
"scsi%d.%c: Using asynchronous transfer\n",
1603 host
->host
->host_no
, acornscsi_target(host
));
1604 host
->device
[host
->SCpnt
->device
->id
].sync_xfer
= SYNCHTRANSFER_2DBA
;
1605 host
->device
[host
->SCpnt
->device
->id
].sync_state
= SYNC_ASYNCHRONOUS
;
1606 sbic_arm_write(host
->scsi
.io_port
, SBIC_SYNCHTRANSFER
, host
->device
[host
->SCpnt
->device
->id
].sync_xfer
);
1615 /* TODO: target queue is full */
1618 case SIMPLE_QUEUE_TAG
:
1619 /* tag queue reconnect... message[1] = queue tag. Print something to indicate something happened! */
1620 printk("scsi%d.%c: reconnect queue tag %02X\n",
1621 host
->host
->host_no
, acornscsi_target(host
),
1625 case EXTENDED_MESSAGE
:
1626 switch (message
[2]) {
1627 #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
1629 if (host
->device
[host
->SCpnt
->device
->id
].sync_state
== SYNC_SENT_REQUEST
) {
1631 * We requested synchronous transfers. This isn't quite right...
1632 * We can only say if this succeeded if we proceed on to execute the
1633 * command from this message. If we get a MESSAGE PARITY ERROR,
1634 * and the target retries fail, then we fallback to asynchronous mode
1636 host
->device
[host
->SCpnt
->device
->id
].sync_state
= SYNC_COMPLETED
;
1637 printk(KERN_NOTICE
"scsi%d.%c: Using synchronous transfer, offset %d, %d ns\n",
1638 host
->host
->host_no
, acornscsi_target(host
),
1639 message
[4], message
[3] * 4);
1640 host
->device
[host
->SCpnt
->device
->id
].sync_xfer
=
1641 calc_sync_xfer(message
[3] * 4, message
[4]);
1643 unsigned char period
, length
;
1645 * Target requested synchronous transfers. The agreement is only
1646 * to be in operation AFTER the target leaves message out phase.
1648 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1649 period
= max_t(unsigned int, message
[3], sdtr_period
/ 4);
1650 length
= min_t(unsigned int, message
[4], sdtr_size
);
1651 msgqueue_addmsg(&host
->scsi
.msgs
, 5, EXTENDED_MESSAGE
, 3,
1652 EXTENDED_SDTR
, period
, length
);
1653 host
->device
[host
->SCpnt
->device
->id
].sync_xfer
=
1654 calc_sync_xfer(period
* 4, length
);
1656 sbic_arm_write(host
->scsi
.io_port
, SBIC_SYNCHTRANSFER
, host
->device
[host
->SCpnt
->device
->id
].sync_xfer
);
1659 /* We do not accept synchronous transfers. Respond with a
1665 /* The WD33C93A is only 8-bit. We respond with a MESSAGE_REJECT
1666 * to a wide data transfer request.
1669 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1670 msgqueue_flush(&host
->scsi
.msgs
);
1671 msgqueue_addmsg(&host
->scsi
.msgs
, 1, MESSAGE_REJECT
);
1676 #ifdef CONFIG_SCSI_ACORNSCSI_LINK
1677 case LINKED_CMD_COMPLETE
:
1678 case LINKED_FLG_CMD_COMPLETE
:
1680 * We don't support linked commands yet
1683 #if (DEBUG & DEBUG_LINK)
1684 printk("scsi%d.%c: lun %d tag %d linked command complete\n",
1685 host
->host
->host_no
, acornscsi_target(host
), host
->SCpnt
->tag
);
1688 * A linked command should only terminate with one of these messages
1689 * if there are more linked commands available.
1691 if (!host
->SCpnt
->next_link
) {
1692 printk(KERN_WARNING
"scsi%d.%c: lun %d tag %d linked command complete, but no next_link\n",
1693 instance
->host_no
, acornscsi_target(host
), host
->SCpnt
->tag
);
1694 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1695 msgqueue_addmsg(&host
->scsi
.msgs
, 1, ABORT
);
1697 Scsi_Cmnd
*SCpnt
= host
->SCpnt
;
1699 acornscsi_dma_cleanup(host
);
1701 host
->SCpnt
= host
->SCpnt
->next_link
;
1702 host
->SCpnt
->tag
= SCpnt
->tag
;
1703 SCpnt
->result
= DID_OK
| host
->scsi
.SCp
.Message
<< 8 | host
->Scsi
.SCp
.Status
;
1706 /* initialise host->SCpnt->SCp */
1712 default: /* reject message */
1713 printk(KERN_ERR
"scsi%d.%c: unrecognised message %02X, rejecting\n",
1714 host
->host
->host_no
, acornscsi_target(host
),
1716 acornscsi_sbic_issuecmd(host
, CMND_ASSERTATN
);
1717 msgqueue_flush(&host
->scsi
.msgs
);
1718 msgqueue_addmsg(&host
->scsi
.msgs
, 1, MESSAGE_REJECT
);
1719 host
->scsi
.phase
= PHASE_MSGIN
;
1722 acornscsi_sbic_issuecmd(host
, CMND_NEGATEACK
);
1726 * Function: int acornscsi_buildmessages(AS_Host *host)
1727 * Purpose : build the connection messages for a host
1728 * Params : host - host to add messages to
1731 void acornscsi_buildmessages(AS_Host
*host
)
1734 /* does the device need resetting? */
1736 msgqueue_addmsg(&host
->scsi
.msgs
, 1, BUS_DEVICE_RESET
);
1741 msgqueue_addmsg(&host
->scsi
.msgs
, 1,
1742 IDENTIFY(host
->device
[host
->SCpnt
->device
->id
].disconnect_ok
,
1743 host
->SCpnt
->device
->lun
));
1746 /* does the device need the current command aborted */
1748 acornscsi_abortcmd(host
->SCpnt
->tag
);
1753 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
1754 if (host
->SCpnt
->tag
) {
1755 unsigned int tag_type
;
1757 if (host
->SCpnt
->cmnd
[0] == REQUEST_SENSE
||
1758 host
->SCpnt
->cmnd
[0] == TEST_UNIT_READY
||
1759 host
->SCpnt
->cmnd
[0] == INQUIRY
)
1760 tag_type
= HEAD_OF_QUEUE_TAG
;
1762 tag_type
= SIMPLE_QUEUE_TAG
;
1763 msgqueue_addmsg(&host
->scsi
.msgs
, 2, tag_type
, host
->SCpnt
->tag
);
1767 #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
1768 if (host
->device
[host
->SCpnt
->device
->id
].sync_state
== SYNC_NEGOCIATE
) {
1769 host
->device
[host
->SCpnt
->device
->id
].sync_state
= SYNC_SENT_REQUEST
;
1770 msgqueue_addmsg(&host
->scsi
.msgs
, 5,
1771 EXTENDED_MESSAGE
, 3, EXTENDED_SDTR
,
1772 sdtr_period
/ 4, sdtr_size
);
1778 * Function: int acornscsi_starttransfer(AS_Host *host)
1779 * Purpose : transfer data to/from connected target
1780 * Params : host - host to which target is connected
1781 * Returns : 0 if failure
1784 int acornscsi_starttransfer(AS_Host
*host
)
1788 if (!host
->scsi
.SCp
.ptr
/*&& host->scsi.SCp.this_residual*/) {
1789 printk(KERN_ERR
"scsi%d.%c: null buffer passed to acornscsi_starttransfer\n",
1790 host
->host
->host_no
, acornscsi_target(host
));
1794 residual
= host
->SCpnt
->request_bufflen
- host
->scsi
.SCp
.scsi_xferred
;
1796 sbic_arm_write(host
->scsi
.io_port
, SBIC_SYNCHTRANSFER
, host
->device
[host
->SCpnt
->device
->id
].sync_xfer
);
1797 sbic_arm_writenext(host
->scsi
.io_port
, residual
>> 16);
1798 sbic_arm_writenext(host
->scsi
.io_port
, residual
>> 8);
1799 sbic_arm_writenext(host
->scsi
.io_port
, residual
);
1800 acornscsi_sbic_issuecmd(host
, CMND_XFERINFO
);
1804 /* =========================================================================================
1805 * Connection & Disconnection
1808 * Function : acornscsi_reconnect(AS_Host *host)
1809 * Purpose : reconnect a previously disconnected command
1810 * Params : host - host specific data
1811 * Remarks : SCSI spec says:
1812 * 'The set of active pointers is restored from the set
1813 * of saved pointers upon reconnection of the I/O process'
1816 int acornscsi_reconnect(AS_Host
*host
)
1818 unsigned int target
, lun
, ok
= 0;
1820 target
= sbic_arm_read(host
->scsi
.io_port
, SBIC_SOURCEID
);
1823 printk(KERN_ERR
"scsi%d: invalid source id after reselection "
1824 "- device fault?\n",
1825 host
->host
->host_no
);
1829 if (host
->SCpnt
&& !host
->scsi
.disconnectable
) {
1830 printk(KERN_ERR
"scsi%d.%d: reconnected while command in "
1831 "progress to target %d?\n",
1832 host
->host
->host_no
, target
, host
->SCpnt
->device
->id
);
1836 lun
= sbic_arm_read(host
->scsi
.io_port
, SBIC_DATA
) & 7;
1838 host
->scsi
.reconnected
.target
= target
;
1839 host
->scsi
.reconnected
.lun
= lun
;
1840 host
->scsi
.reconnected
.tag
= 0;
1842 if (host
->scsi
.disconnectable
&& host
->SCpnt
&&
1843 host
->SCpnt
->device
->id
== target
&& host
->SCpnt
->device
->lun
== lun
)
1846 if (!ok
&& queue_probetgtlun(&host
->queues
.disconnected
, target
, lun
))
1849 ADD_STATUS(target
, 0x81, host
->scsi
.phase
, 0);
1852 host
->scsi
.phase
= PHASE_RECONNECTED
;
1854 /* this doesn't seem to work */
1855 printk(KERN_ERR
"scsi%d.%c: reselected with no command "
1856 "to reconnect with\n",
1857 host
->host
->host_no
, '0' + target
);
1858 acornscsi_dumplog(host
, target
);
1859 acornscsi_abortcmd(host
, 0);
1861 queue_add_cmd_tail(&host
->queues
.disconnected
, host
->SCpnt
);
1865 acornscsi_sbic_issuecmd(host
, CMND_NEGATEACK
);
1870 * Function: int acornscsi_reconect_finish(AS_Host *host)
1871 * Purpose : finish reconnecting a command
1872 * Params : host - host to complete
1873 * Returns : 0 if failed
1876 int acornscsi_reconnect_finish(AS_Host
*host
)
1878 if (host
->scsi
.disconnectable
&& host
->SCpnt
) {
1879 host
->scsi
.disconnectable
= 0;
1880 if (host
->SCpnt
->device
->id
== host
->scsi
.reconnected
.target
&&
1881 host
->SCpnt
->device
->lun
== host
->scsi
.reconnected
.lun
&&
1882 host
->SCpnt
->tag
== host
->scsi
.reconnected
.tag
) {
1883 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1884 DBG(host
->SCpnt
, printk("scsi%d.%c: reconnected",
1885 host
->host
->host_no
, acornscsi_target(host
)));
1888 queue_add_cmd_tail(&host
->queues
.disconnected
, host
->SCpnt
);
1889 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1890 DBG(host
->SCpnt
, printk("scsi%d.%c: had to move command "
1891 "to disconnected queue\n",
1892 host
->host
->host_no
, acornscsi_target(host
)));
1898 host
->SCpnt
= queue_remove_tgtluntag(&host
->queues
.disconnected
,
1899 host
->scsi
.reconnected
.target
,
1900 host
->scsi
.reconnected
.lun
,
1901 host
->scsi
.reconnected
.tag
);
1902 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1903 DBG(host
->SCpnt
, printk("scsi%d.%c: had to get command",
1904 host
->host
->host_no
, acornscsi_target(host
)));
1909 acornscsi_abortcmd(host
, host
->scsi
.reconnected
.tag
);
1912 * Restore data pointer from SAVED pointers.
1914 host
->scsi
.SCp
= host
->SCpnt
->SCp
;
1915 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1916 printk(", data pointers: [%p, %X]",
1917 host
->scsi
.SCp
.ptr
, host
->scsi
.SCp
.this_residual
);
1920 #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
1924 host
->dma
.transferred
= host
->scsi
.SCp
.scsi_xferred
;
1926 return host
->SCpnt
!= NULL
;
1930 * Function: void acornscsi_disconnect_unexpected(AS_Host *host)
1931 * Purpose : handle an unexpected disconnect
1932 * Params : host - host on which disconnect occurred
1935 void acornscsi_disconnect_unexpected(AS_Host
*host
)
1937 printk(KERN_ERR
"scsi%d.%c: unexpected disconnect\n",
1938 host
->host
->host_no
, acornscsi_target(host
));
1939 #if (DEBUG & DEBUG_ABORT)
1940 acornscsi_dumplog(host
, 8);
1943 acornscsi_done(host
, &host
->SCpnt
, DID_ERROR
);
1947 * Function: void acornscsi_abortcmd(AS_host *host, unsigned char tag)
1948 * Purpose : abort a currently executing command
1949 * Params : host - host with connected command to abort
1950 * tag - tag to abort
1953 void acornscsi_abortcmd(AS_Host
*host
, unsigned char tag
)
1955 host
->scsi
.phase
= PHASE_ABORTED
;
1956 sbic_arm_write(host
->scsi
.io_port
, SBIC_CMND
, CMND_ASSERTATN
);
1958 msgqueue_flush(&host
->scsi
.msgs
);
1959 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
1961 msgqueue_addmsg(&host
->scsi
.msgs
, 2, ABORT_TAG
, tag
);
1964 msgqueue_addmsg(&host
->scsi
.msgs
, 1, ABORT
);
1967 /* ==========================================================================================
1968 * Interrupt routines.
1971 * Function: int acornscsi_sbicintr(AS_Host *host)
1972 * Purpose : handle interrupts from SCSI device
1973 * Params : host - host to process
1974 * Returns : INTR_PROCESS if expecting another SBIC interrupt
1975 * INTR_IDLE if no interrupt
1976 * INTR_NEXT_COMMAND if we have finished processing the command
1979 intr_ret_t
acornscsi_sbicintr(AS_Host
*host
, int in_irq
)
1981 unsigned int asr
, ssr
;
1983 asr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
1984 if (!(asr
& ASR_INT
))
1987 ssr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
);
1989 #if (DEBUG & DEBUG_PHASES)
1990 print_sbic_status(asr
, ssr
, host
->scsi
.phase
);
1993 ADD_STATUS(8, ssr
, host
->scsi
.phase
, in_irq
);
1995 if (host
->SCpnt
&& !host
->scsi
.disconnectable
)
1996 ADD_STATUS(host
->SCpnt
->device
->id
, ssr
, host
->scsi
.phase
, in_irq
);
1999 case 0x00: /* reset state - not advanced */
2000 printk(KERN_ERR
"scsi%d: reset in standard mode but wanted advanced mode.\n",
2001 host
->host
->host_no
);
2002 /* setup sbic - WD33C93A */
2003 sbic_arm_write(host
->scsi
.io_port
, SBIC_OWNID
, OWNID_EAF
| host
->host
->this_id
);
2004 sbic_arm_write(host
->scsi
.io_port
, SBIC_CMND
, CMND_RESET
);
2007 case 0x01: /* reset state - advanced */
2008 sbic_arm_write(host
->scsi
.io_port
, SBIC_CTRL
, INIT_SBICDMA
| CTRL_IDI
);
2009 sbic_arm_write(host
->scsi
.io_port
, SBIC_TIMEOUT
, TIMEOUT_TIME
);
2010 sbic_arm_write(host
->scsi
.io_port
, SBIC_SYNCHTRANSFER
, SYNCHTRANSFER_2DBA
);
2011 sbic_arm_write(host
->scsi
.io_port
, SBIC_SOURCEID
, SOURCEID_ER
| SOURCEID_DSP
);
2012 msgqueue_flush(&host
->scsi
.msgs
);
2015 case 0x41: /* unexpected disconnect aborted command */
2016 acornscsi_disconnect_unexpected(host
);
2017 return INTR_NEXT_COMMAND
;
2020 switch (host
->scsi
.phase
) {
2021 case PHASE_CONNECTING
: /* STATE: command removed from issue queue */
2023 case 0x11: /* -> PHASE_CONNECTED */
2024 /* BUS FREE -> SELECTION */
2025 host
->scsi
.phase
= PHASE_CONNECTED
;
2026 msgqueue_flush(&host
->scsi
.msgs
);
2027 host
->dma
.transferred
= host
->scsi
.SCp
.scsi_xferred
;
2028 /* 33C93 gives next interrupt indicating bus phase */
2029 asr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
2030 if (!(asr
& ASR_INT
))
2032 ssr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
);
2033 ADD_STATUS(8, ssr
, host
->scsi
.phase
, 1);
2034 ADD_STATUS(host
->SCpnt
->device
->id
, ssr
, host
->scsi
.phase
, 1);
2037 case 0x42: /* select timed out */
2039 acornscsi_done(host
, &host
->SCpnt
, DID_NO_CONNECT
);
2040 return INTR_NEXT_COMMAND
;
2042 case 0x81: /* -> PHASE_RECONNECTED or PHASE_ABORTED */
2043 /* BUS FREE -> RESELECTION */
2044 host
->origSCpnt
= host
->SCpnt
;
2046 msgqueue_flush(&host
->scsi
.msgs
);
2047 acornscsi_reconnect(host
);
2051 printk(KERN_ERR
"scsi%d.%c: PHASE_CONNECTING, SSR %02X?\n",
2052 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2053 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2054 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2056 return INTR_PROCESSING
;
2059 case PHASE_CONNECTED
: /* STATE: device selected ok */
2062 case 0x8a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
2063 /* SELECTION -> COMMAND */
2064 acornscsi_sendcommand(host
);
2067 case 0x8b: /* -> PHASE_STATUS */
2068 /* SELECTION -> STATUS */
2069 acornscsi_readstatusbyte(host
);
2070 host
->scsi
.phase
= PHASE_STATUSIN
;
2074 case 0x8e: /* -> PHASE_MSGOUT */
2075 /* SELECTION ->MESSAGE OUT */
2076 host
->scsi
.phase
= PHASE_MSGOUT
;
2077 acornscsi_buildmessages(host
);
2078 acornscsi_sendmessage(host
);
2081 /* these should not happen */
2082 case 0x85: /* target disconnected */
2083 acornscsi_done(host
, &host
->SCpnt
, DID_ERROR
);
2087 printk(KERN_ERR
"scsi%d.%c: PHASE_CONNECTED, SSR %02X?\n",
2088 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2089 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2090 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2092 return INTR_PROCESSING
;
2094 case PHASE_MSGOUT
: /* STATE: connected & sent IDENTIFY message */
2096 * SCSI standard says that MESSAGE OUT phases can be followed by a
2097 * DATA phase, STATUS phase, MESSAGE IN phase or COMMAND phase
2100 case 0x8a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
2101 case 0x1a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
2102 /* MESSAGE OUT -> COMMAND */
2103 acornscsi_sendcommand(host
);
2106 case 0x8b: /* -> PHASE_STATUS */
2107 case 0x1b: /* -> PHASE_STATUS */
2108 /* MESSAGE OUT -> STATUS */
2109 acornscsi_readstatusbyte(host
);
2110 host
->scsi
.phase
= PHASE_STATUSIN
;
2113 case 0x8e: /* -> PHASE_MSGOUT */
2114 /* MESSAGE_OUT(MESSAGE_IN) ->MESSAGE OUT */
2115 acornscsi_sendmessage(host
);
2118 case 0x4f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2119 case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2120 /* MESSAGE OUT -> MESSAGE IN */
2121 acornscsi_message(host
);
2125 printk(KERN_ERR
"scsi%d.%c: PHASE_MSGOUT, SSR %02X?\n",
2126 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2127 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2129 return INTR_PROCESSING
;
2131 case PHASE_COMMAND
: /* STATE: connected & command sent */
2133 case 0x18: /* -> PHASE_DATAOUT */
2134 /* COMMAND -> DATA OUT */
2135 if (host
->scsi
.SCp
.sent_command
!= host
->SCpnt
->cmd_len
)
2136 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2137 acornscsi_dma_setup(host
, DMA_OUT
);
2138 if (!acornscsi_starttransfer(host
))
2139 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2140 host
->scsi
.phase
= PHASE_DATAOUT
;
2143 case 0x19: /* -> PHASE_DATAIN */
2144 /* COMMAND -> DATA IN */
2145 if (host
->scsi
.SCp
.sent_command
!= host
->SCpnt
->cmd_len
)
2146 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2147 acornscsi_dma_setup(host
, DMA_IN
);
2148 if (!acornscsi_starttransfer(host
))
2149 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2150 host
->scsi
.phase
= PHASE_DATAIN
;
2153 case 0x1b: /* -> PHASE_STATUS */
2154 /* COMMAND -> STATUS */
2155 acornscsi_readstatusbyte(host
);
2156 host
->scsi
.phase
= PHASE_STATUSIN
;
2159 case 0x1e: /* -> PHASE_MSGOUT */
2160 /* COMMAND -> MESSAGE OUT */
2161 acornscsi_sendmessage(host
);
2164 case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2165 /* COMMAND -> MESSAGE IN */
2166 acornscsi_message(host
);
2170 printk(KERN_ERR
"scsi%d.%c: PHASE_COMMAND, SSR %02X?\n",
2171 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2172 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2174 return INTR_PROCESSING
;
2176 case PHASE_DISCONNECT
: /* STATE: connected, received DISCONNECT msg */
2177 if (ssr
== 0x85) { /* -> PHASE_IDLE */
2178 host
->scsi
.disconnectable
= 1;
2179 host
->scsi
.reconnected
.tag
= 0;
2180 host
->scsi
.phase
= PHASE_IDLE
;
2181 host
->stats
.disconnects
+= 1;
2183 printk(KERN_ERR
"scsi%d.%c: PHASE_DISCONNECT, SSR %02X instead of disconnect?\n",
2184 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2185 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2187 return INTR_NEXT_COMMAND
;
2189 case PHASE_IDLE
: /* STATE: disconnected */
2190 if (ssr
== 0x81) /* -> PHASE_RECONNECTED or PHASE_ABORTED */
2191 acornscsi_reconnect(host
);
2193 printk(KERN_ERR
"scsi%d.%c: PHASE_IDLE, SSR %02X while idle?\n",
2194 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2195 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2197 return INTR_PROCESSING
;
2199 case PHASE_RECONNECTED
: /* STATE: device reconnected to initiator */
2201 * Command reconnected - if MESGIN, get message - it may be
2202 * the tag. If not, get command out of disconnected queue
2205 * If we reconnected and we're not in MESSAGE IN phase after IDENTIFY,
2206 * reconnect I_T_L command
2208 if (ssr
!= 0x8f && !acornscsi_reconnect_finish(host
))
2210 ADD_STATUS(host
->SCpnt
->device
->id
, ssr
, host
->scsi
.phase
, in_irq
);
2212 case 0x88: /* data out phase */
2213 /* -> PHASE_DATAOUT */
2214 /* MESSAGE IN -> DATA OUT */
2215 acornscsi_dma_setup(host
, DMA_OUT
);
2216 if (!acornscsi_starttransfer(host
))
2217 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2218 host
->scsi
.phase
= PHASE_DATAOUT
;
2221 case 0x89: /* data in phase */
2222 /* -> PHASE_DATAIN */
2223 /* MESSAGE IN -> DATA IN */
2224 acornscsi_dma_setup(host
, DMA_IN
);
2225 if (!acornscsi_starttransfer(host
))
2226 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2227 host
->scsi
.phase
= PHASE_DATAIN
;
2230 case 0x8a: /* command out */
2231 /* MESSAGE IN -> COMMAND */
2232 acornscsi_sendcommand(host
);/* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
2235 case 0x8b: /* status in */
2236 /* -> PHASE_STATUSIN */
2237 /* MESSAGE IN -> STATUS */
2238 acornscsi_readstatusbyte(host
);
2239 host
->scsi
.phase
= PHASE_STATUSIN
;
2242 case 0x8e: /* message out */
2243 /* -> PHASE_MSGOUT */
2244 /* MESSAGE IN -> MESSAGE OUT */
2245 acornscsi_sendmessage(host
);
2248 case 0x8f: /* message in */
2249 acornscsi_message(host
); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2253 printk(KERN_ERR
"scsi%d.%c: PHASE_RECONNECTED, SSR %02X after reconnect?\n",
2254 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2255 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2257 return INTR_PROCESSING
;
2259 case PHASE_DATAIN
: /* STATE: transferred data in */
2261 * This is simple - if we disconnect then the DMA address & count is
2265 case 0x19: /* -> PHASE_DATAIN */
2266 case 0x89: /* -> PHASE_DATAIN */
2267 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2270 case 0x1b: /* -> PHASE_STATUSIN */
2271 case 0x4b: /* -> PHASE_STATUSIN */
2272 case 0x8b: /* -> PHASE_STATUSIN */
2273 /* DATA IN -> STATUS */
2274 host
->scsi
.SCp
.scsi_xferred
= host
->SCpnt
->request_bufflen
-
2275 acornscsi_sbic_xfcount(host
);
2276 acornscsi_dma_stop(host
);
2277 acornscsi_readstatusbyte(host
);
2278 host
->scsi
.phase
= PHASE_STATUSIN
;
2281 case 0x1e: /* -> PHASE_MSGOUT */
2282 case 0x4e: /* -> PHASE_MSGOUT */
2283 case 0x8e: /* -> PHASE_MSGOUT */
2284 /* DATA IN -> MESSAGE OUT */
2285 host
->scsi
.SCp
.scsi_xferred
= host
->SCpnt
->request_bufflen
-
2286 acornscsi_sbic_xfcount(host
);
2287 acornscsi_dma_stop(host
);
2288 acornscsi_sendmessage(host
);
2291 case 0x1f: /* message in */
2292 case 0x4f: /* message in */
2293 case 0x8f: /* message in */
2294 /* DATA IN -> MESSAGE IN */
2295 host
->scsi
.SCp
.scsi_xferred
= host
->SCpnt
->request_bufflen
-
2296 acornscsi_sbic_xfcount(host
);
2297 acornscsi_dma_stop(host
);
2298 acornscsi_message(host
); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2302 printk(KERN_ERR
"scsi%d.%c: PHASE_DATAIN, SSR %02X?\n",
2303 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2304 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2306 return INTR_PROCESSING
;
2308 case PHASE_DATAOUT
: /* STATE: transferred data out */
2310 * This is more complicated - if we disconnect, the DMA could be 12
2311 * bytes ahead of us. We need to correct this.
2314 case 0x18: /* -> PHASE_DATAOUT */
2315 case 0x88: /* -> PHASE_DATAOUT */
2316 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2319 case 0x1b: /* -> PHASE_STATUSIN */
2320 case 0x4b: /* -> PHASE_STATUSIN */
2321 case 0x8b: /* -> PHASE_STATUSIN */
2322 /* DATA OUT -> STATUS */
2323 host
->scsi
.SCp
.scsi_xferred
= host
->SCpnt
->request_bufflen
-
2324 acornscsi_sbic_xfcount(host
);
2325 acornscsi_dma_stop(host
);
2326 acornscsi_dma_adjust(host
);
2327 acornscsi_readstatusbyte(host
);
2328 host
->scsi
.phase
= PHASE_STATUSIN
;
2331 case 0x1e: /* -> PHASE_MSGOUT */
2332 case 0x4e: /* -> PHASE_MSGOUT */
2333 case 0x8e: /* -> PHASE_MSGOUT */
2334 /* DATA OUT -> MESSAGE OUT */
2335 host
->scsi
.SCp
.scsi_xferred
= host
->SCpnt
->request_bufflen
-
2336 acornscsi_sbic_xfcount(host
);
2337 acornscsi_dma_stop(host
);
2338 acornscsi_dma_adjust(host
);
2339 acornscsi_sendmessage(host
);
2342 case 0x1f: /* message in */
2343 case 0x4f: /* message in */
2344 case 0x8f: /* message in */
2345 /* DATA OUT -> MESSAGE IN */
2346 host
->scsi
.SCp
.scsi_xferred
= host
->SCpnt
->request_bufflen
-
2347 acornscsi_sbic_xfcount(host
);
2348 acornscsi_dma_stop(host
);
2349 acornscsi_dma_adjust(host
);
2350 acornscsi_message(host
); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
2354 printk(KERN_ERR
"scsi%d.%c: PHASE_DATAOUT, SSR %02X?\n",
2355 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2356 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2358 return INTR_PROCESSING
;
2360 case PHASE_STATUSIN
: /* STATE: status in complete */
2362 case 0x1f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
2363 case 0x8f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
2364 /* STATUS -> MESSAGE IN */
2365 acornscsi_message(host
);
2368 case 0x1e: /* -> PHASE_MSGOUT */
2369 case 0x8e: /* -> PHASE_MSGOUT */
2370 /* STATUS -> MESSAGE OUT */
2371 acornscsi_sendmessage(host
);
2375 printk(KERN_ERR
"scsi%d.%c: PHASE_STATUSIN, SSR %02X instead of MESSAGE_IN?\n",
2376 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2377 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2379 return INTR_PROCESSING
;
2381 case PHASE_MSGIN
: /* STATE: message in */
2383 case 0x1e: /* -> PHASE_MSGOUT */
2384 case 0x4e: /* -> PHASE_MSGOUT */
2385 case 0x8e: /* -> PHASE_MSGOUT */
2386 /* MESSAGE IN -> MESSAGE OUT */
2387 acornscsi_sendmessage(host
);
2390 case 0x1f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
2394 acornscsi_message(host
);
2398 printk("scsi%d.%c: strange message in disconnection\n",
2399 host
->host
->host_no
, acornscsi_target(host
));
2400 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2401 acornscsi_done(host
, &host
->SCpnt
, DID_ERROR
);
2405 printk(KERN_ERR
"scsi%d.%c: PHASE_MSGIN, SSR %02X after message in?\n",
2406 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2407 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2409 return INTR_PROCESSING
;
2411 case PHASE_DONE
: /* STATE: received status & message */
2413 case 0x85: /* -> PHASE_IDLE */
2414 acornscsi_done(host
, &host
->SCpnt
, DID_OK
);
2415 return INTR_NEXT_COMMAND
;
2419 acornscsi_sendmessage(host
);
2423 printk(KERN_ERR
"scsi%d.%c: PHASE_DONE, SSR %02X instead of disconnect?\n",
2424 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2425 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2427 return INTR_PROCESSING
;
2433 acornscsi_done(host
, &host
->SCpnt
, DID_ABORT
);
2435 clear_bit(host
->scsi
.reconnected
.target
* 8 + host
->scsi
.reconnected
.lun
,
2437 host
->scsi
.phase
= PHASE_IDLE
;
2439 return INTR_NEXT_COMMAND
;
2445 acornscsi_sendmessage(host
);
2449 printk(KERN_ERR
"scsi%d.%c: PHASE_ABORTED, SSR %02X?\n",
2450 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2451 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2453 return INTR_PROCESSING
;
2456 printk(KERN_ERR
"scsi%d.%c: unknown driver phase %d\n",
2457 host
->host
->host_no
, acornscsi_target(host
), ssr
);
2458 acornscsi_dumplog(host
, host
->SCpnt
? host
->SCpnt
->device
->id
: 8);
2460 return INTR_PROCESSING
;
2464 * Prototype: void acornscsi_intr(int irq, void *dev_id, struct pt_regs *regs)
2465 * Purpose : handle interrupts from Acorn SCSI card
2466 * Params : irq - interrupt number
2467 * dev_id - device specific data (AS_Host structure)
2468 * regs - processor registers when interrupt occurred
2471 acornscsi_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
2473 AS_Host
*host
= (AS_Host
*)dev_id
;
2481 iostatus
= inb(host
->card
.io_intr
);
2484 acornscsi_dma_intr(host
);
2485 iostatus
= inb(host
->card
.io_intr
);
2489 ret
= acornscsi_sbicintr(host
, in_irq
);
2492 * If we have a transfer pending, start it.
2493 * Only start it if the interface has already started transferring
2496 if (host
->dma
.xfer_required
)
2497 acornscsi_dma_xfer(host
);
2499 if (ret
== INTR_NEXT_COMMAND
)
2500 ret
= acornscsi_kick(host
);
2503 } while (ret
!= INTR_IDLE
);
2508 /*=============================================================================================
2509 * Interfaces between interrupt handler and rest of scsi code
2513 * Function : acornscsi_queuecmd(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
2514 * Purpose : queues a SCSI command
2515 * Params : cmd - SCSI command
2516 * done - function called on completion, with pointer to command descriptor
2517 * Returns : 0, or < 0 on error.
2519 int acornscsi_queuecmd(Scsi_Cmnd
*SCpnt
, void (*done
)(Scsi_Cmnd
*))
2521 AS_Host
*host
= (AS_Host
*)SCpnt
->device
->host
->hostdata
;
2524 /* there should be some way of rejecting errors like this without panicing... */
2525 panic("scsi%d: queuecommand called with NULL done function [cmd=%p]",
2526 host
->host
->host_no
, SCpnt
);
2530 #if (DEBUG & DEBUG_NO_WRITE)
2531 if (acornscsi_cmdtype(SCpnt
->cmnd
[0]) == CMD_WRITE
&& (NO_WRITE
& (1 << SCpnt
->device
->id
))) {
2532 printk(KERN_CRIT
"scsi%d.%c: WRITE attempted with NO_WRITE flag set\n",
2533 host
->host
->host_no
, '0' + SCpnt
->device
->id
);
2534 SCpnt
->result
= DID_NO_CONNECT
<< 16;
2540 SCpnt
->scsi_done
= done
;
2541 SCpnt
->host_scribble
= NULL
;
2544 SCpnt
->SCp
.phase
= (int)acornscsi_datadirection(SCpnt
->cmnd
[0]);
2545 SCpnt
->SCp
.sent_command
= 0;
2546 SCpnt
->SCp
.scsi_xferred
= 0;
2550 host
->stats
.queues
+= 1;
2553 unsigned long flags
;
2555 if (!queue_add_cmd_ordered(&host
->queues
.issue
, SCpnt
)) {
2556 SCpnt
->result
= DID_ERROR
<< 16;
2560 local_irq_save(flags
);
2561 if (host
->scsi
.phase
== PHASE_IDLE
)
2562 acornscsi_kick(host
);
2563 local_irq_restore(flags
);
2569 * Prototype: void acornscsi_reportstatus(Scsi_Cmnd **SCpntp1, Scsi_Cmnd **SCpntp2, int result)
2570 * Purpose : pass a result to *SCpntp1, and check if *SCpntp1 = *SCpntp2
2571 * Params : SCpntp1 - pointer to command to return
2572 * SCpntp2 - pointer to command to check
2573 * result - result to pass back to mid-level done function
2574 * Returns : *SCpntp2 = NULL if *SCpntp1 is the same command structure as *SCpntp2.
2577 void acornscsi_reportstatus(Scsi_Cmnd
**SCpntp1
, Scsi_Cmnd
**SCpntp2
, int result
)
2579 Scsi_Cmnd
*SCpnt
= *SCpntp1
;
2584 SCpnt
->result
= result
;
2585 SCpnt
->scsi_done(SCpnt
);
2588 if (SCpnt
== *SCpntp2
)
2592 enum res_abort
{ res_not_running
, res_success
, res_success_clear
, res_snooze
};
2595 * Prototype: enum res acornscsi_do_abort(Scsi_Cmnd *SCpnt)
2596 * Purpose : abort a command on this host
2597 * Params : SCpnt - command to abort
2598 * Returns : our abort status
2600 static enum res_abort
2601 acornscsi_do_abort(AS_Host
*host
, Scsi_Cmnd
*SCpnt
)
2603 enum res_abort res
= res_not_running
;
2605 if (queue_remove_cmd(&host
->queues
.issue
, SCpnt
)) {
2607 * The command was on the issue queue, and has not been
2608 * issued yet. We can remove the command from the queue,
2609 * and acknowledge the abort. Neither the devices nor the
2610 * interface know about the command.
2612 //#if (DEBUG & DEBUG_ABORT)
2613 printk("on issue queue ");
2616 } else if (queue_remove_cmd(&host
->queues
.disconnected
, SCpnt
)) {
2618 * The command was on the disconnected queue. Simply
2619 * acknowledge the abort condition, and when the target
2620 * reconnects, we will give it an ABORT message. The
2621 * target should then disconnect, and we will clear
2624 //#if (DEBUG & DEBUG_ABORT)
2625 printk("on disconnected queue ");
2628 } else if (host
->SCpnt
== SCpnt
) {
2629 unsigned long flags
;
2631 //#if (DEBUG & DEBUG_ABORT)
2632 printk("executing ");
2635 local_irq_save(flags
);
2636 switch (host
->scsi
.phase
) {
2638 * If the interface is idle, and the command is 'disconnectable',
2639 * then it is the same as on the disconnected queue. We simply
2640 * remove all traces of the command. When the target reconnects,
2641 * we will give it an ABORT message since the command could not
2642 * be found. When the target finally disconnects, we will clear
2646 if (host
->scsi
.disconnectable
) {
2647 host
->scsi
.disconnectable
= 0;
2654 * If the command has connected and done nothing further,
2655 * simply force a disconnect. We also need to clear the
2658 case PHASE_CONNECTED
:
2659 sbic_arm_write(host
->scsi
.io_port
, SBIC_CMND
, CMND_DISCONNECT
);
2661 res
= res_success_clear
;
2665 acornscsi_abortcmd(host
, host
->SCpnt
->tag
);
2668 local_irq_restore(flags
);
2669 } else if (host
->origSCpnt
== SCpnt
) {
2671 * The command will be executed next, but a command
2672 * is currently using the interface. This is similar to
2673 * being on the issue queue, except the busylun bit has
2676 host
->origSCpnt
= NULL
;
2677 //#if (DEBUG & DEBUG_ABORT)
2678 printk("waiting for execution ");
2680 res
= res_success_clear
;
2688 * Prototype: int acornscsi_abort(Scsi_Cmnd *SCpnt)
2689 * Purpose : abort a command on this host
2690 * Params : SCpnt - command to abort
2691 * Returns : one of SCSI_ABORT_ macros
2693 int acornscsi_abort(Scsi_Cmnd
*SCpnt
)
2695 AS_Host
*host
= (AS_Host
*) SCpnt
->device
->host
->hostdata
;
2698 host
->stats
.aborts
+= 1;
2700 #if (DEBUG & DEBUG_ABORT)
2703 asr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
2704 ssr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
);
2706 printk(KERN_WARNING
"acornscsi_abort: ");
2707 print_sbic_status(asr
, ssr
, host
->scsi
.phase
);
2708 acornscsi_dumplog(host
, SCpnt
->device
->id
);
2712 printk("scsi%d: ", host
->host
->host_no
);
2714 switch (acornscsi_do_abort(host
, SCpnt
)) {
2716 * We managed to find the command and cleared it out.
2717 * We do not expect the command to be executing on the
2718 * target, but we have set the busylun bit.
2720 case res_success_clear
:
2721 //#if (DEBUG & DEBUG_ABORT)
2724 clear_bit(SCpnt
->device
->id
* 8 + SCpnt
->device
->lun
, host
->busyluns
);
2727 * We found the command, and cleared it out. Either
2728 * the command is still known to be executing on the
2729 * target, or the busylun bit is not set.
2732 //#if (DEBUG & DEBUG_ABORT)
2733 printk("success\n");
2735 SCpnt
->result
= DID_ABORT
<< 16;
2736 SCpnt
->scsi_done(SCpnt
);
2737 result
= SCSI_ABORT_SUCCESS
;
2741 * We did find the command, but unfortunately we couldn't
2742 * unhook it from ourselves. Wait some more, and if it
2743 * still doesn't complete, reset the interface.
2746 //#if (DEBUG & DEBUG_ABORT)
2749 result
= SCSI_ABORT_SNOOZE
;
2753 * The command could not be found (either because it completed,
2754 * or it got dropped.
2757 case res_not_running
:
2758 acornscsi_dumplog(host
, SCpnt
->device
->id
);
2759 #if (DEBUG & DEBUG_ABORT)
2760 result
= SCSI_ABORT_SNOOZE
;
2762 result
= SCSI_ABORT_NOT_RUNNING
;
2764 //#if (DEBUG & DEBUG_ABORT)
2765 printk("not running\n");
2774 * Prototype: int acornscsi_reset(Scsi_Cmnd *SCpnt, unsigned int reset_flags)
2775 * Purpose : reset a command on this host/reset this host
2776 * Params : SCpnt - command causing reset
2777 * result - what type of reset to perform
2778 * Returns : one of SCSI_RESET_ macros
2780 int acornscsi_reset(Scsi_Cmnd
*SCpnt
, unsigned int reset_flags
)
2782 AS_Host
*host
= (AS_Host
*)SCpnt
->device
->host
->hostdata
;
2785 host
->stats
.resets
+= 1;
2787 #if (DEBUG & DEBUG_RESET)
2791 asr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_ASR
);
2792 ssr
= sbic_arm_read(host
->scsi
.io_port
, SBIC_SSR
);
2794 printk(KERN_WARNING
"acornscsi_reset: ");
2795 print_sbic_status(asr
, ssr
, host
->scsi
.phase
);
2796 acornscsi_dumplog(host
, SCpnt
->device
->id
);
2800 acornscsi_dma_stop(host
);
2802 SCptr
= host
->SCpnt
;
2805 * do hard reset. This resets all devices on this host, and so we
2806 * must set the reset status on all commands.
2808 acornscsi_resetcard(host
);
2811 * report reset on commands current connected/disconnected
2813 acornscsi_reportstatus(&host
->SCpnt
, &SCptr
, DID_RESET
);
2815 while ((SCptr
= queue_remove(&host
->queues
.disconnected
)) != NULL
)
2816 acornscsi_reportstatus(&SCptr
, &SCpnt
, DID_RESET
);
2819 SCpnt
->result
= DID_RESET
<< 16;
2820 SCpnt
->scsi_done(SCpnt
);
2823 return SCSI_RESET_BUS_RESET
| SCSI_RESET_HOST_RESET
| SCSI_RESET_SUCCESS
;
2826 /*==============================================================================================
2827 * initialisation & miscellaneous support
2831 * Function: char *acornscsi_info(struct Scsi_Host *host)
2832 * Purpose : return a string describing this interface
2833 * Params : host - host to give information on
2834 * Returns : a constant string
2837 char *acornscsi_info(struct Scsi_Host
*host
)
2839 static char string
[100], *p
;
2843 p
+= sprintf(string
, "%s at port %08lX irq %d v%d.%d.%d"
2844 #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
2847 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
2850 #ifdef CONFIG_SCSI_ACORNSCSI_LINK
2853 #if (DEBUG & DEBUG_NO_WRITE)
2854 " NOWRITE ("NO_WRITE_STR
")"
2856 , host
->hostt
->name
, host
->io_port
, host
->irq
,
2857 VER_MAJOR
, VER_MINOR
, VER_PATCH
);
2861 int acornscsi_proc_info(struct Scsi_Host
*instance
, char *buffer
, char **start
, off_t offset
,
2862 int length
, int inout
)
2864 int pos
, begin
= 0, devidx
;
2872 host
= (AS_Host
*)instance
->hostdata
;
2874 p
+= sprintf(p
, "AcornSCSI driver v%d.%d.%d"
2875 #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
2878 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
2881 #ifdef CONFIG_SCSI_ACORNSCSI_LINK
2884 #if (DEBUG & DEBUG_NO_WRITE)
2885 " NOWRITE ("NO_WRITE_STR
")"
2887 "\n\n", VER_MAJOR
, VER_MINOR
, VER_PATCH
);
2889 p
+= sprintf(p
, "SBIC: WD33C93A Address: %08X IRQ : %d\n",
2890 host
->scsi
.io_port
, host
->scsi
.irq
);
2892 p
+= sprintf(p
, "DMAC: uPC71071 Address: %08X IRQ : %d\n\n",
2893 host
->dma
.io_port
, host
->scsi
.irq
);
2896 p
+= sprintf(p
, "Statistics:\n"
2897 "Queued commands: %-10u Issued commands: %-10u\n"
2898 "Done commands : %-10u Reads : %-10u\n"
2899 "Writes : %-10u Others : %-10u\n"
2900 "Disconnects : %-10u Aborts : %-10u\n"
2901 "Resets : %-10u\n\nLast phases:",
2902 host
->stats
.queues
, host
->stats
.removes
,
2903 host
->stats
.fins
, host
->stats
.reads
,
2904 host
->stats
.writes
, host
->stats
.miscs
,
2905 host
->stats
.disconnects
, host
->stats
.aborts
,
2906 host
->stats
.resets
);
2908 for (devidx
= 0; devidx
< 9; devidx
++) {
2909 unsigned int statptr
, prev
;
2911 p
+= sprintf(p
, "\n%c:", devidx
== 8 ? 'H' : ('0' + devidx
));
2912 statptr
= host
->status_ptr
[devidx
] - 10;
2914 if ((signed int)statptr
< 0)
2915 statptr
+= STATUS_BUFFER_SIZE
;
2917 prev
= host
->status
[devidx
][statptr
].when
;
2919 for (; statptr
!= host
->status_ptr
[devidx
]; statptr
= (statptr
+ 1) & (STATUS_BUFFER_SIZE
- 1)) {
2920 if (host
->status
[devidx
][statptr
].when
) {
2921 p
+= sprintf(p
, "%c%02X:%02X+%2ld",
2922 host
->status
[devidx
][statptr
].irq
? '-' : ' ',
2923 host
->status
[devidx
][statptr
].ph
,
2924 host
->status
[devidx
][statptr
].ssr
,
2925 (host
->status
[devidx
][statptr
].when
- prev
) < 100 ?
2926 (host
->status
[devidx
][statptr
].when
- prev
) : 99);
2927 prev
= host
->status
[devidx
][statptr
].when
;
2932 p
+= sprintf(p
, "\nAttached devices:\n");
2934 shost_for_each_device(scd
, instance
) {
2935 p
+= sprintf(p
, "Device/Lun TaggedQ Sync\n");
2936 p
+= sprintf(p
, " %d/%d ", scd
->id
, scd
->lun
);
2937 if (scd
->tagged_supported
)
2938 p
+= sprintf(p
, "%3sabled(%3d) ",
2939 scd
->simple_tags
? "en" : "dis",
2942 p
+= sprintf(p
, "unsupported ");
2944 if (host
->device
[scd
->id
].sync_xfer
& 15)
2945 p
+= sprintf(p
, "offset %d, %d ns\n",
2946 host
->device
[scd
->id
].sync_xfer
& 15,
2947 acornscsi_getperiod(host
->device
[scd
->id
].sync_xfer
));
2949 p
+= sprintf(p
, "async\n");
2952 if (pos
+ begin
< offset
) {
2957 if (pos
+ begin
> offset
+ length
) {
2958 scsi_device_put(scd
);
2965 *start
= buffer
+ (offset
- begin
);
2966 pos
-= offset
- begin
;
2974 static Scsi_Host_Template acornscsi_template
= {
2975 .module
= THIS_MODULE
,
2976 .proc_info
= acornscsi_proc_info
,
2977 .name
= "AcornSCSI",
2978 .info
= acornscsi_info
,
2979 .queuecommand
= acornscsi_queuecmd
,
2981 .abort
= acornscsi_abort
,
2982 .reset
= acornscsi_reset
,
2985 .sg_tablesize
= SG_ALL
,
2987 .unchecked_isa_dma
= 0,
2988 .use_clustering
= DISABLE_CLUSTERING
,
2989 .proc_name
= "acornscsi",
2992 static int __devinit
2993 acornscsi_probe(struct expansion_card
*ec
, const struct ecard_id
*id
)
2995 struct Scsi_Host
*host
;
2999 host
= scsi_host_alloc(&acornscsi_template
, sizeof(AS_Host
));
3003 ashost
= (AS_Host
*)host
->hostdata
;
3005 host
->io_port
= ecard_address(ec
, ECARD_MEMC
, 0);
3006 host
->irq
= ec
->irq
;
3008 ashost
->host
= host
;
3009 ashost
->scsi
.io_port
= ioaddr(host
->io_port
+ 0x800);
3010 ashost
->scsi
.irq
= host
->irq
;
3011 ashost
->card
.io_intr
= POD_SPACE(host
->io_port
) + 0x800;
3012 ashost
->card
.io_page
= POD_SPACE(host
->io_port
) + 0xc00;
3013 ashost
->card
.io_ram
= ioaddr(host
->io_port
);
3014 ashost
->dma
.io_port
= host
->io_port
+ 0xc00;
3015 ashost
->dma
.io_intr_clear
= POD_SPACE(host
->io_port
) + 0x800;
3017 ec
->irqaddr
= (char *)ioaddr(ashost
->card
.io_intr
);
3021 if (!request_region(host
->io_port
+ 0x800, 2, "acornscsi(sbic)"))
3023 if (!request_region(ashost
->card
.io_intr
, 1, "acornscsi(intr)"))
3025 if (!request_region(ashost
->card
.io_page
, 1, "acornscsi(page)"))
3028 if (!request_region(ashost
->dma
.io_port
, 256, "acornscsi(dmac)"))
3031 if (!request_region(host
->io_port
, 2048, "acornscsi(ram)"))
3034 ret
= request_irq(host
->irq
, acornscsi_intr
, SA_INTERRUPT
, "acornscsi", ashost
);
3036 printk(KERN_CRIT
"scsi%d: IRQ%d not free: %d\n",
3037 host
->host_no
, ashost
->scsi
.irq
, ret
);
3041 memset(&ashost
->stats
, 0, sizeof (ashost
->stats
));
3042 queue_initialise(&ashost
->queues
.issue
);
3043 queue_initialise(&ashost
->queues
.disconnected
);
3044 msgqueue_initialise(&ashost
->scsi
.msgs
);
3046 acornscsi_resetcard(ashost
);
3048 ret
= scsi_add_host(host
, &ec
->dev
);
3052 scsi_scan_host(host
);
3056 free_irq(host
->irq
, ashost
);
3058 release_region(host
->io_port
, 2048);
3061 release_region(ashost
->dma
.io_port
, 256);
3064 release_region(ashost
->card
.io_page
, 1);
3066 release_region(ashost
->card
.io_intr
, 1);
3068 release_region(host
->io_port
+ 0x800, 2);
3070 scsi_host_put(host
);
3075 static void __devexit
acornscsi_remove(struct expansion_card
*ec
)
3077 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
3078 AS_Host
*ashost
= (AS_Host
*)host
->hostdata
;
3080 ecard_set_drvdata(ec
, NULL
);
3081 scsi_remove_host(host
);
3084 * Put card into RESET state
3086 outb(0x80, ashost
->card
.io_page
);
3088 free_irq(host
->irq
, ashost
);
3090 release_region(host
->io_port
+ 0x800, 2);
3091 release_region(ashost
->card
.io_intr
, 1);
3092 release_region(ashost
->card
.io_page
, 1);
3093 release_region(ashost
->dma
.io_port
, 256);
3094 release_region(host
->io_port
, 2048);
3096 msgqueue_free(&ashost
->scsi
.msgs
);
3097 queue_free(&ashost
->queues
.disconnected
);
3098 queue_free(&ashost
->queues
.issue
);
3099 scsi_host_put(host
);
3102 static const struct ecard_id acornscsi_cids
[] = {
3103 { MANU_ACORN
, PROD_ACORN_SCSI
},
3107 static struct ecard_driver acornscsi_driver
= {
3108 .probe
= acornscsi_probe
,
3109 .remove
= __devexit_p(acornscsi_remove
),
3110 .id_table
= acornscsi_cids
,
3112 .name
= "acornscsi",
3116 static int __init
acornscsi_init(void)
3118 return ecard_register_driver(&acornscsi_driver
);
3121 static void __exit
acornscsi_exit(void)
3123 ecard_remove_driver(&acornscsi_driver
);
3126 module_init(acornscsi_init
);
3127 module_exit(acornscsi_exit
);
3129 MODULE_AUTHOR("Russell King");
3130 MODULE_DESCRIPTION("AcornSCSI driver");
3131 MODULE_LICENSE("GPL");