2 * 53c710 driver. Modified from Drew Eckhardts driver
3 * for 53c810 by Richard Hirst [richard@sleepie.demon.co.uk]
4 * Check out PERM_OPTIONS and EXPECTED_CLOCK, which may be defined in the
5 * relevant machine specific file (eg. mvme16x.[ch], amiga7xx.[ch]).
6 * There are also currently some defines at the top of 53c7xx.scr.
7 * The chip type is #defined in script_asm.pl, as well as the Makefile.
8 * Host scsi ID expected to be 7 - see NCR53c7x0_init().
10 * I have removed the PCI code and some of the 53c8xx specific code -
11 * simply to make this file smaller and easier to manage.
14 * Problems trying to read any chip registers in NCR53c7x0_init(), as they
15 * may never have been set by 16xBug (eg. If kernel has come in over tftp).
19 * Adapted for Linux/m68k Amiga platforms for the A4000T/A4091 and
20 * WarpEngine SCSI controllers.
21 * By Alan Hourihane <alanh@fairlite.demon.co.uk>
22 * Thanks to Richard Hirst for making it possible with the MVME additions
26 * 53c710 rev 0 doesn't support add with carry. Rev 1 and 2 does. To
27 * overcome this problem you can define FORCE_DSA_ALIGNMENT, which ensures
28 * that the DSA address is always xxxxxx00. If disconnection is not allowed,
29 * then the script only ever tries to add small (< 256) positive offsets to
30 * DSA, so lack of carry isn't a problem. FORCE_DSA_ALIGNMENT can, of course,
31 * be defined for all chip revisions at a small cost in memory usage.
34 #define FORCE_DSA_ALIGNMENT
37 * Selection timer does not always work on the 53c710, depending on the
38 * timing at the last disconnect, if this is a problem for you, try
39 * using validids as detailed below.
41 * Options for the NCR7xx driver
43 * noasync:0 - disables sync and asynchronous negotiation
44 * nosync:0 - disables synchronous negotiation (does async)
45 * nodisconnect:0 - disables disconnection
46 * validids:0x?? - Bitmask field that disallows certain ID's.
47 * - e.g. 0x03 allows ID 0,1
48 * - 0x1F allows ID 0,1,2,3,4
49 * opthi:n - replace top word of options with 'n'
50 * optlo:n - replace bottom word of options with 'n'
51 * - ALWAYS SPECIFY opthi THEN optlo <<<<<<<<<<
55 * PERM_OPTIONS are driver options which will be enabled for all NCR boards
56 * in the system at driver initialization time.
58 * Don't THINK about touching these in PERM_OPTIONS :
59 * OPTION_MEMORY_MAPPED
60 * 680x0 doesn't have an IO map!
63 * Test 1 does bus mastering and interrupt tests, which will help weed
64 * out brain damaged main boards.
66 * Other PERM_OPTIONS settings are listed below. Note the actual options
67 * required are set in the relevant file (mvme16x.c, amiga7xx.c, etc):
70 * Don't negotiate for asynchronous transfers on the first command
71 * when OPTION_ALWAYS_SYNCHRONOUS is set. Useful for dain bramaged
72 * devices which do something bad rather than sending a MESSAGE
73 * REJECT back to us like they should if they can't cope.
76 * Enable support for synchronous transfers. Target negotiated
77 * synchronous transfers will be responded to. To initiate
78 * a synchronous transfer request, call
80 * request_synchronous (hostno, target)
84 * OPTION_ALWAYS_SYNCHRONOUS
85 * Negotiate for synchronous transfers with every target after
86 * driver initialization or a SCSI bus reset. This is a bit dangerous,
87 * since there are some dain bramaged SCSI devices which will accept
88 * SDTR messages but keep talking asynchronously.
91 * Enable support for disconnect/reconnect. To change the
92 * default setting on a given host adapter, call
94 * request_disconnect (hostno, allow)
96 * where allow is non-zero to allow, 0 to disallow.
98 * If you really want to run 10MHz FAST SCSI-II transfers, you should
99 * know that the NCR driver currently ignores parity information. Most
100 * systems do 5MHz SCSI fine. I've seen a lot that have problems faster
101 * than 8MHz. To play it safe, we only request 5MHz transfers.
103 * If you'd rather get 10MHz transfers, edit sdtr_message and change
104 * the fourth byte from 50 to 25.
109 * iX Multiuser Multitasking Magazine
113 * Copyright 1993, 1994, 1995 Drew Eckhardt
114 * Visionary Computing
115 * (Unix and Linux consulting and custom programming)
116 * drew@PoohSticks.ORG
119 * TolerANT and SCSI SCRIPTS are registered trademarks of NCR Corporation.
121 * For more information, please consult
128 * PCI-SCSI I/O Processor
132 * PCI-SCSI I/O Processor Design In Guide
134 * For literature on Symbios Logic Inc. formerly NCR, SCSI,
135 * and Communication products please call (800) 334-5454 or
138 * PCI BIOS Specification Revision
139 * PCI Local Bus Specification
140 * PCI System Design Guide
142 * PCI Special Interest Group
144 * 5200 N.E. Elam Young Parkway
145 * Hillsboro, Oregon 97124-6497
152 * The cumulative latency needed to propagate a read/write request
153 * through the file system, buffer cache, driver stacks, SCSI host, and
154 * SCSI device is ultimately the limiting factor in throughput once we
155 * have a sufficiently fast host adapter.
157 * So, to maximize performance we want to keep the ratio of latency to data
158 * transfer time to a minimum by
159 * 1. Minimizing the total number of commands sent (typical command latency
160 * including drive and bus mastering host overhead is as high as 4.5ms)
161 * to transfer a given amount of data.
163 * This is accomplished by placing no arbitrary limit on the number
164 * of scatter/gather buffers supported, since we can transfer 1K
165 * per scatter/gather buffer without Eric's cluster patches,
168 * 2. Minimizing the number of fatal interrupts serviced, since
169 * fatal interrupts halt the SCSI I/O processor. Basically,
170 * this means offloading the practical maximum amount of processing
173 * On the NCR53c810/820/720, this is accomplished by using
174 * interrupt-on-the-fly signals when commands complete,
175 * and only handling fatal errors and SDTR / WDTR messages
178 * On the NCR53c710, interrupts are generated as on the NCR53c8x0,
179 * only the lack of a interrupt-on-the-fly facility complicates
180 * things. Also, SCSI ID registers and commands are
181 * bit fielded rather than binary encoded.
183 * On the NCR53c700 and NCR53c700-66, operations that are done via
184 * indirect, table mode on the more advanced chips must be
185 * replaced by calls through a jump table which
186 * acts as a surrogate for the DSA. Unfortunately, this
187 * will mean that we must service an interrupt for each
188 * disconnect/reconnect.
190 * 3. Eliminating latency by pipelining operations at the different levels.
192 * This driver allows a configurable number of commands to be enqueued
193 * for each target/lun combination (experimentally, I have discovered
194 * that two seems to work best) and will ultimately allow for
195 * SCSI-II tagged queuing.
199 * This driver is built around a Linux queue of commands waiting to
200 * be executed, and a shared Linux/NCR array of commands to start. Commands
201 * are transfered to the array by the run_process_issue_queue() function
202 * which is called whenever a command completes.
204 * As commands are completed, the interrupt routine is triggered,
205 * looks for commands in the linked list of completed commands with
206 * valid status, removes these commands from a list of running commands,
207 * calls the done routine, and flags their target/luns as not busy.
209 * Due to limitations in the intelligence of the NCR chips, certain
210 * concessions are made. In many cases, it is easier to dynamically
211 * generate/fix-up code rather than calculate on the NCR at run time.
212 * So, code is generated or fixed up for
214 * - Handling data transfers, using a variable number of MOVE instructions
215 * interspersed with CALL MSG_IN, WHEN MSGIN instructions.
217 * The DATAIN and DATAOUT routines are separate, so that an incorrect
218 * direction can be trapped, and space isn't wasted.
220 * It may turn out that we're better off using some sort
221 * of table indirect instruction in a loop with a variable
222 * sized table on the NCR53c710 and newer chips.
224 * - Checking for reselection (NCR53c710 and better)
226 * - Handling the details of SCSI context switches (NCR53c710 and better),
227 * such as reprogramming appropriate synchronous parameters,
228 * removing the dsa structure from the NCR's queue of outstanding
234 #include <linux/module.h>
237 #include <linux/config.h>
239 #include <linux/types.h>
240 #include <asm/setup.h>
243 #include <asm/system.h>
244 #include <linux/delay.h>
245 #include <linux/signal.h>
246 #include <linux/sched.h>
247 #include <linux/errno.h>
248 #include <linux/string.h>
249 #include <linux/malloc.h>
250 #include <linux/vmalloc.h>
251 #include <linux/mm.h>
252 #include <linux/ioport.h>
253 #include <linux/time.h>
254 #include <linux/blk.h>
255 #include <linux/spinlock.h>
256 #include <asm/pgtable.h>
259 #include <asm/amigahw.h>
260 #include <asm/amigaints.h>
267 #ifdef CONFIG_MVME16x
268 #include <asm/mvme16xhw.h>
275 #ifdef CONFIG_BVME6000
276 #include <asm/bvme6000hw.h>
286 #include "constants.h"
288 #include <linux/stat.h>
289 #include <linux/stddef.h>
293 * The following make the definitions in 53c7xx.h (write8, etc) smaller,
294 * we don't have separate i/o space anyway.
310 static int check_address (unsigned long addr
, int size
);
311 static void dump_events (struct Scsi_Host
*host
, int count
);
312 static Scsi_Cmnd
* return_outstanding_commands (struct Scsi_Host
*host
,
313 int free
, int issue
);
314 static void hard_reset (struct Scsi_Host
*host
);
315 static void ncr_scsi_reset (struct Scsi_Host
*host
);
316 static void print_lots (struct Scsi_Host
*host
);
317 static void set_synchronous (struct Scsi_Host
*host
, int target
, int sxfer
,
318 int scntl3
, int now_connected
);
319 static int datapath_residual (struct Scsi_Host
*host
);
320 static const char * sbcl_to_phase (int sbcl
);
321 static void print_progress (Scsi_Cmnd
*cmd
);
322 static void print_queues (struct Scsi_Host
*host
);
323 static void process_issue_queue (unsigned long flags
);
324 static int shutdown (struct Scsi_Host
*host
);
325 static void abnormal_finished (struct NCR53c7x0_cmd
*cmd
, int result
);
326 static int disable (struct Scsi_Host
*host
);
327 static int NCR53c7xx_run_tests (struct Scsi_Host
*host
);
328 static void NCR53c7x0_intr(int irq
, void *dev_id
, struct pt_regs
* regs
);
329 static void NCR53c7x0_intfly (struct Scsi_Host
*host
);
330 static int ncr_halt (struct Scsi_Host
*host
);
331 static void intr_phase_mismatch (struct Scsi_Host
*host
, struct NCR53c7x0_cmd
333 static void intr_dma (struct Scsi_Host
*host
, struct NCR53c7x0_cmd
*cmd
);
334 static void print_dsa (struct Scsi_Host
*host
, u32
*dsa
,
336 static int print_insn (struct Scsi_Host
*host
, const u32
*insn
,
337 const char *prefix
, int kernel
);
339 static void NCR53c7xx_dsa_fixup (struct NCR53c7x0_cmd
*cmd
);
340 static void NCR53c7x0_init_fixup (struct Scsi_Host
*host
);
341 static int NCR53c7x0_dstat_sir_intr (struct Scsi_Host
*host
, struct
343 static void NCR53c7x0_soft_reset (struct Scsi_Host
*host
);
345 /* Size of event list (per host adapter) */
346 static int track_events
= 0;
347 static struct Scsi_Host
*first_host
= NULL
; /* Head of list of NCR boards */
348 static Scsi_Host_Template
*the_template
= NULL
;
350 /* NCR53c710 script handling code */
352 #include "53c7xx_d.h"
353 #ifdef A_int_debug_sync
354 #define DEBUG_SYNC_INTR A_int_debug_sync
356 int NCR53c7xx_script_len
= sizeof (SCRIPT
);
357 int NCR53c7xx_dsa_len
= A_dsa_end
+ Ent_dsa_zero
- Ent_dsa_code_template
;
358 #ifdef FORCE_DSA_ALIGNMENT
359 int CmdPageStart
= (0 - Ent_dsa_zero
- sizeof(struct NCR53c7x0_cmd
)) & 0xff;
362 static char *setup_strings
[] =
363 {"","","","","","","",""};
365 #define MAX_SETUP_STRINGS (sizeof(setup_strings) / sizeof(char *))
366 #define SETUP_BUFFER_SIZE 200
367 static char setup_buffer
[SETUP_BUFFER_SIZE
];
368 static char setup_used
[MAX_SETUP_STRINGS
];
370 void ncr53c7xx_setup (char *str
, int *ints
)
378 strncpy(p1
, str
, SETUP_BUFFER_SIZE
- strlen(setup_buffer
));
379 setup_buffer
[SETUP_BUFFER_SIZE
- 1] = '\0';
382 while (*p1
&& (i
< MAX_SETUP_STRINGS
)) {
383 p2
= strchr(p1
, ',');
387 setup_strings
[i
] = p1
;
392 setup_strings
[i
] = p1
;
396 for (i
=0; i
<MAX_SETUP_STRINGS
; i
++)
401 /* check_setup_strings() returns index if key found, 0 if not
404 static int check_setup_strings(char *key
, int *flags
, int *val
, char *buf
)
409 for (x
=0; x
<MAX_SETUP_STRINGS
; x
++) {
412 if (!strncmp(setup_strings
[x
], key
, strlen(key
)))
414 if (!strncmp(setup_strings
[x
], "next", strlen("next")))
417 if (x
== MAX_SETUP_STRINGS
)
420 cp
= setup_strings
[x
] + strlen(key
);
425 if ((*cp
>= '0') && (*cp
<= '9')) {
426 *val
= simple_strtoul(cp
,NULL
,0);
435 * - There is some sort of conflict when the PPP driver is compiled with
436 * support for 16 channels?
438 * - On systems which predate the 1.3.x initialization order change,
439 * the NCR driver will cause Cannot get free page messages to appear.
440 * These are harmless, but I don't know of an easy way to avoid them.
442 * - With OPTION_DISCONNECT, on two systems under unknown circumstances,
443 * we get a PHASE MISMATCH with DSA set to zero (suggests that we
444 * are occurring somewhere in the reselection code) where
445 * DSP=some value DCMD|DBC=same value.
447 * Closer inspection suggests that we may be trying to execute
448 * some portion of the DSA?
449 * scsi0 : handling residual transfer (+ 0 bytes from DMA FIFO)
450 * scsi0 : handling residual transfer (+ 0 bytes from DMA FIFO)
451 * scsi0 : no current command : unexpected phase MSGIN.
452 * DSP=0x1c46cc, DCMD|DBC=0x1c46ac, DSA=0x0
453 * DSPS=0x0, TEMP=0x1c3e70, DMODE=0x80
455 * 001c46cc : 0x001c46cc 0x00000000
456 * 001c46d4 : 0x001c5ea0 0x000011f8
458 * Changed the print code in the phase_mismatch handler so
459 * that we call print_lots to try to diagnose this.
464 * Possible future direction of architecture for max performance :
466 * We're using a single start array for the NCR chip. This is
467 * sub-optimal, because we cannot add a command which would conflict with
468 * an executing command to this start queue, and therefore must insert the
469 * next command for a given I/T/L combination after the first has completed;
470 * incurring our interrupt latency between SCSI commands.
472 * To allow further pipelining of the NCR and host CPU operation, we want
473 * to set things up so that immediately on termination of a command destined
474 * for a given LUN, we get that LUN busy again.
476 * To do this, we need to add a 32 bit pointer to which is jumped to
477 * on completion of a command. If no new command is available, this
478 * would point to the usual DSA issue queue select routine.
480 * If one were, it would point to a per-NCR53c7x0_cmd select routine
481 * which starts execution immediately, inserting the command at the head
482 * of the start queue if the NCR chip is selected or reselected.
484 * We would change so that we keep a list of outstanding commands
485 * for each unit, rather than a single running_list. We'd insert
486 * a new command into the right running list; if the NCR didn't
487 * have something running for that yet, we'd put it in the
488 * start queue as well. Some magic needs to happen to handle the
489 * race condition between the first command terminating before the
490 * new one is written.
492 * Potential for profiling :
493 * Call do_gettimeofday(struct timeval *tv) to get 800ns resolution.
499 * 1. To support WIDE transfers, not much needs to happen. We
500 * should do CHMOVE instructions instead of MOVEs when
501 * we have scatter/gather segments of uneven length. When
502 * we do this, we need to handle the case where we disconnect
505 * 2. Currently, when Icky things happen we do a FATAL(). Instead,
506 * we want to do an integrity check on the parts of the NCR hostdata
507 * structure which were initialized at boot time; FATAL() if that
508 * fails, and otherwise try to recover. Keep track of how many
509 * times this has happened within a single SCSI command; if it
510 * gets excessive, then FATAL().
512 * 3. Parity checking is currently disabled, and a few things should
513 * happen here now that we support synchronous SCSI transfers :
514 * 1. On soft-reset, we shoould set the EPC (Enable Parity Checking)
515 * and AAP (Assert SATN/ on parity error) bits in SCNTL0.
517 * 2. We should enable the parity interrupt in the SIEN0 register.
519 * 3. intr_phase_mismatch() needs to believe that message out is
520 * always an "acceptable" phase to have a mismatch in. If
521 * the old phase was MSG_IN, we should send a MESSAGE PARITY
522 * error. If the old phase was something else, we should send
523 * a INITIATOR_DETECTED_ERROR message. Note that this could
524 * cause a RESTORE POINTERS message; so we should handle that
525 * correctly first. Instead, we should probably do an
528 * 4. MPEE bit of CTEST4 should be set so we get interrupted if
529 * we detect an error.
532 * 5. The initial code has been tested on the NCR53c810. I don't
533 * have access to NCR53c700, 700-66 (Forex boards), NCR53c710
534 * (NCR Pentium systems), NCR53c720, NCR53c820, or NCR53c825 boards to
535 * finish development on those platforms.
537 * NCR53c820/825/720 - need to add wide transfer support, including WDTR
538 * negotiation, programming of wide transfer capabilities
539 * on reselection and table indirect selection.
541 * NCR53c710 - need to add fatal interrupt or GEN code for
542 * command completion signaling. Need to modify all
543 * SDID, SCID, etc. registers, and table indirect select code
544 * since these use bit fielded (ie 1<<target) instead of
545 * binary encoded target ids. Need to accommodate
546 * different register mappings, probably scan through
547 * the SCRIPT code and change the non SFBR register operand
548 * of all MOVE instructions.
550 * It is rather worse than this actually, the 710 corrupts
551 * both TEMP and DSA when you do a MOVE MEMORY. This
552 * screws you up all over the place. MOVE MEMORY 4 with a
553 * destination of DSA seems to work OK, which helps some.
554 * Richard Hirst richard@sleepie.demon.co.uk
556 * NCR53c700/700-66 - need to add code to refix addresses on
557 * every nexus change, eliminate all table indirect code,
560 * 6. The NCR53c7x0 series is very popular on other platforms that
561 * could be running Linux - ie, some high performance AMIGA SCSI
564 * So, I should include #ifdef'd code so that it is
565 * compatible with these systems.
567 * Specifically, the little Endian assumptions I made in my
568 * bit fields need to change, and if the NCR doesn't see memory
569 * the right way, we need to provide options to reverse words
570 * when the scripts are relocated.
572 * 7. Use vremap() to access memory mapped boards.
576 * Allow for simultaneous existence of multiple SCSI scripts so we
577 * can have a single driver binary for all of the family.
579 * - one for NCR53c700 and NCR53c700-66 chips (not yet supported)
580 * - one for rest (only the NCR53c810, 815, 820, and 825 are currently
583 * So that we only need two SCSI scripts, we need to modify things so
584 * that we fixup register accesses in READ/WRITE instructions, and
585 * we'll also have to accommodate the bit vs. binary encoding of IDs
586 * with the 7xx chips.
589 #define ROUNDUP(adr,type) \
590 ((void *) (((long) (adr) + sizeof(type) - 1) & ~(sizeof(type) - 1)))
594 * Function: issue_to_cmd
596 * Purpose: convert jump instruction in issue array to NCR53c7x0_cmd
599 * Inputs; issue - pointer to start of NOP or JUMP instruction
602 * Returns: pointer to command on success; 0 if opcode is NOP.
605 static inline struct NCR53c7x0_cmd
*
606 issue_to_cmd (struct Scsi_Host
*host
, struct NCR53c7x0_hostdata
*hostdata
,
609 return (issue
[0] != hostdata
->NOP_insn
) ?
611 * If the IF TRUE bit is set, it's a JUMP instruction. The
612 * operand is a bus pointer to the dsa_begin routine for this DSA. The
613 * dsa field of the NCR53c7x0_cmd structure starts with the
614 * DSA code template. By converting to a virtual address,
615 * subtracting the code template size, and offset of the
616 * dsa field, we end up with a pointer to the start of the
617 * structure (alternatively, we could use the
618 * dsa_cmnd field, an anachronism from when we weren't
619 * sure what the relationship between the NCR structures
620 * and host structures were going to be.
622 (struct NCR53c7x0_cmd
*) ((char *) bus_to_virt (issue
[1]) -
623 (hostdata
->E_dsa_code_begin
- hostdata
->E_dsa_code_template
) -
624 offsetof(struct NCR53c7x0_cmd
, dsa
))
625 /* If the IF TRUE bit is not set, it's a NOP */
631 * FIXME: we should junk these, in favor of synchronous_want and
632 * wide_want in the NCR53c7x0_hostdata structure.
635 /* Template for "preferred" synchronous transfer parameters. */
637 static const unsigned char sdtr_message
[] = {
638 #ifdef CONFIG_SCSI_NCR53C7xx_FAST
639 EXTENDED_MESSAGE
, 3 /* length */, EXTENDED_SDTR
, 25 /* *4ns */, 8 /* off */
641 EXTENDED_MESSAGE
, 3 /* length */, EXTENDED_SDTR
, 50 /* *4ns */, 8 /* off */
645 /* Template to request asynchronous transfers */
647 static const unsigned char async_message
[] = {
648 EXTENDED_MESSAGE
, 3 /* length */, EXTENDED_SDTR
, 0, 0 /* asynchronous */
651 /* Template for "preferred" WIDE transfer parameters */
653 static const unsigned char wdtr_message
[] = {
654 EXTENDED_MESSAGE
, 2 /* length */, EXTENDED_WDTR
, 1 /* 2^1 bytes */
659 * Function : struct Scsi_Host *find_host (int host)
661 * Purpose : KGDB support function which translates a host number
662 * to a host structure.
664 * Inputs : host - number of SCSI host
666 * Returns : NULL on failure, pointer to host structure on success.
669 static struct Scsi_Host
*
670 find_host (int host
) {
672 for (h
= first_host
; h
&& h
->host_no
!= host
; h
= h
->next
);
674 printk (KERN_ALERT
"scsi%d not found\n", host
);
676 } else if (h
->hostt
!= the_template
) {
677 printk (KERN_ALERT
"scsi%d is not a NCR board\n", host
);
685 * Function : request_synchronous (int host, int target)
687 * Purpose : KGDB interface which will allow us to negotiate for
688 * synchronous transfers. This ill be replaced with a more
689 * integrated function; perhaps a new entry in the scsi_host
690 * structure, accessible via an ioctl() or perhaps /proc/scsi.
692 * Inputs : host - number of SCSI host; target - number of target.
694 * Returns : 0 when negotiation has been setup for next SCSI command,
699 request_synchronous (int host
, int target
) {
701 struct NCR53c7x0_hostdata
*hostdata
;
704 printk (KERN_ALERT
"target %d is bogus\n", target
);
707 if (!(h
= find_host (host
)))
709 else if (h
->this_id
== target
) {
710 printk (KERN_ALERT
"target %d is host ID\n", target
);
713 else if (target
> h
->max_id
) {
714 printk (KERN_ALERT
"target %d exceeds maximum of %d\n", target
,
718 hostdata
= (struct NCR53c7x0_hostdata
*)h
->hostdata
[0];
722 if (hostdata
->initiate_sdtr
& (1 << target
)) {
723 restore_flags(flags
);
724 printk (KERN_ALERT
"target %d already doing SDTR\n", target
);
727 hostdata
->initiate_sdtr
|= (1 << target
);
728 restore_flags(flags
);
734 * Function : request_disconnect (int host, int on_or_off)
736 * Purpose : KGDB support function, tells us to allow or disallow
739 * Inputs : host - number of SCSI host; on_or_off - non-zero to allow,
742 * Returns : 0 on success, * -1 on failure.
746 request_disconnect (int host
, int on_or_off
) {
748 struct NCR53c7x0_hostdata
*hostdata
;
749 if (!(h
= find_host (host
)))
751 hostdata
= (struct NCR53c7x0_hostdata
*) h
->hostdata
[0];
753 hostdata
->options
|= OPTION_DISCONNECT
;
755 hostdata
->options
&= ~OPTION_DISCONNECT
;
761 * Function : static void NCR53c7x0_driver_init (struct Scsi_Host *host)
763 * Purpose : Initialize internal structures, as required on startup, or
764 * after a SCSI bus reset.
766 * Inputs : host - pointer to this host adapter's structure
770 NCR53c7x0_driver_init (struct Scsi_Host
*host
) {
771 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
776 for (i
= 0; i
< 16; ++i
) {
777 hostdata
->request_sense
[i
] = 0;
778 for (j
= 0; j
< 8; ++j
)
779 hostdata
->busy
[i
][j
] = 0;
780 set_synchronous (host
, i
, /* sxfer */ 0, hostdata
->saved_scntl3
, 0);
782 hostdata
->issue_queue
= NULL
;
783 hostdata
->running_list
= hostdata
->finished_queue
=
784 hostdata
->ncrcurrent
= NULL
;
785 for (i
= 0, ncrcurrent
= (u32
*) hostdata
->schedule
;
786 i
< host
->can_queue
; ++i
, ncrcurrent
+= 2) {
787 ncrcurrent
[0] = hostdata
->NOP_insn
;
788 ncrcurrent
[1] = 0xdeadbeef;
790 ncrcurrent
[0] = ((DCMD_TYPE_TCI
|DCMD_TCI_OP_JUMP
) << 24) | DBC_TCI_TRUE
;
791 ncrcurrent
[1] = (u32
) virt_to_bus (hostdata
->script
) +
792 hostdata
->E_wait_reselect
;
793 hostdata
->reconnect_dsa_head
= 0;
794 hostdata
->addr_reconnect_dsa_head
= (u32
)
795 virt_to_bus((void *) &(hostdata
->reconnect_dsa_head
));
796 hostdata
->expecting_iid
= 0;
797 hostdata
->expecting_sto
= 0;
798 if (hostdata
->options
& OPTION_ALWAYS_SYNCHRONOUS
)
799 hostdata
->initiate_sdtr
= 0xffff;
801 hostdata
->initiate_sdtr
= 0;
802 hostdata
->talked_to
= 0;
807 * Function : static int clock_to_ccf_710 (int clock)
809 * Purpose : Return the clock conversion factor for a given SCSI clock.
811 * Inputs : clock - SCSI clock expressed in Hz.
813 * Returns : ccf on success, -1 on failure.
817 clock_to_ccf_710 (int clock
) {
818 if (clock
<= 16666666)
820 if (clock
<= 25000000)
821 return 2; /* Divide by 1.0 */
822 else if (clock
<= 37500000)
823 return 1; /* Divide by 1.5 */
824 else if (clock
<= 50000000)
825 return 0; /* Divide by 2.0 */
826 else if (clock
<= 66000000)
827 return 3; /* Divide by 3.0 */
833 * Function : static int NCR53c7x0_init (struct Scsi_Host *host)
835 * Purpose : initialize the internal structures for a given SCSI host
837 * Inputs : host - pointer to this host adapter's structure
839 * Preconditions : when this function is called, the chip_type
840 * field of the hostdata structure MUST have been set.
842 * Returns : 0 on success, -1 on failure.
846 NCR53c7x0_init (struct Scsi_Host
*host
) {
847 NCR53c7x0_local_declare();
849 unsigned char revision
;
850 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
853 * There are some things which we need to know about in order to provide
854 * a semblance of support. Print 'em if they aren't what we expect,
855 * otherwise don't add to the noise.
857 * -1 means we don't know what to expect.
861 int expected_id
= -1;
862 int expected_clock
= -1;
863 int uninitialized
= 0;
865 int expected_mapping
= OPTION_MEMORY_MAPPED
;
867 int expected_mapping
= OPTION_IO_MAPPED
;
870 hostdata
->valid_ids
[i
] = 1; /* Default all ID's to scan */
872 /* Parse commandline flags */
873 if (check_setup_strings("noasync",&flags
,&val
,buf
))
875 hostdata
->options
|= OPTION_NO_ASYNC
;
876 hostdata
->options
&= ~(OPTION_SYNCHRONOUS
| OPTION_ALWAYS_SYNCHRONOUS
);
879 if (check_setup_strings("nosync",&flags
,&val
,buf
))
881 hostdata
->options
&= ~(OPTION_SYNCHRONOUS
| OPTION_ALWAYS_SYNCHRONOUS
);
884 if (check_setup_strings("nodisconnect",&flags
,&val
,buf
))
885 hostdata
->options
&= ~OPTION_DISCONNECT
;
887 if (check_setup_strings("validids",&flags
,&val
,buf
))
890 hostdata
->valid_ids
[i
] = val
& (1<<i
);
893 if ((i
= check_setup_strings("next",&flags
,&val
,buf
)))
899 if (check_setup_strings("opthi",&flags
,&val
,buf
))
900 hostdata
->options
= (long long)val
<< 32;
901 if (check_setup_strings("optlo",&flags
,&val
,buf
))
902 hostdata
->options
|= val
;
904 NCR53c7x0_local_setup(host
);
905 switch (hostdata
->chip
) {
908 hostdata
->dstat_sir_intr
= NCR53c7x0_dstat_sir_intr
;
909 hostdata
->init_save_regs
= NULL
;
910 hostdata
->dsa_fixup
= NCR53c7xx_dsa_fixup
;
911 hostdata
->init_fixup
= NCR53c7x0_init_fixup
;
912 hostdata
->soft_reset
= NCR53c7x0_soft_reset
;
913 hostdata
->run_tests
= NCR53c7xx_run_tests
;
914 expected_clock
= hostdata
->scsi_clock
;
918 printk ("scsi%d : chip type of %d is not supported yet, detaching.\n",
919 host
->host_no
, hostdata
->chip
);
920 scsi_unregister (host
);
924 /* Assign constants accessed by NCR */
925 hostdata
->NCR53c7xx_zero
= 0;
926 hostdata
->NCR53c7xx_msg_reject
= MESSAGE_REJECT
;
927 hostdata
->NCR53c7xx_msg_abort
= ABORT
;
928 hostdata
->NCR53c7xx_msg_nop
= NOP
;
929 hostdata
->NOP_insn
= (DCMD_TYPE_TCI
|DCMD_TCI_OP_JUMP
) << 24;
930 if (expected_mapping
== -1 ||
931 (hostdata
->options
& (OPTION_MEMORY_MAPPED
)) !=
932 (expected_mapping
& OPTION_MEMORY_MAPPED
))
933 printk ("scsi%d : using %s mapped access\n", host
->host_no
,
934 (hostdata
->options
& OPTION_MEMORY_MAPPED
) ? "memory" :
937 hostdata
->dmode
= (hostdata
->chip
== 700 || hostdata
->chip
== 70066) ?
938 DMODE_REG_00
: DMODE_REG_10
;
939 hostdata
->istat
= ((hostdata
->chip
/ 100) == 8) ?
940 ISTAT_REG_800
: ISTAT_REG_700
;
942 /* We have to assume that this may be the first access to the chip, so
943 * we must set EA in DCNTL. */
945 NCR53c7x0_write8 (DCNTL_REG
, DCNTL_10_EA
|DCNTL_10_COM
);
948 /* Only the ISTAT register is readable when the NCR is running, so make
953 * XXX - the NCR53c700 uses bitfielded registers for SCID, SDID, etc,
954 * as does the 710 with one bit per SCSI ID. Conversely, the NCR
955 * uses a normal, 3 bit binary representation of these values.
957 * Get the rest of the NCR documentation, and FIND OUT where the change
962 /* May not be able to do this - chip my not have been set up yet */
963 tmp
= hostdata
->this_id_mask
= NCR53c7x0_read8(SCID_REG
);
964 for (host
->this_id
= 0; tmp
!= 1; tmp
>>=1, ++host
->this_id
);
970 * Note : we should never encounter a board setup for ID0. So,
971 * if we see ID0, assume that it was uninitialized and set it
972 * to the industry standard 7.
974 if (!host
->this_id
) {
975 printk("scsi%d : initiator ID was %d, changing to 7\n",
976 host
->host_no
, host
->this_id
);
978 hostdata
->this_id_mask
= 1 << 7;
982 if (expected_id
== -1 || host
->this_id
!= expected_id
)
983 printk("scsi%d : using initiator ID %d\n", host
->host_no
,
987 * Save important registers to allow a soft reset.
991 * CTEST7 controls cache snooping, burst mode, and support for
992 * external differential drivers. This isn't currently used - the
993 * default value may not be optimal anyway.
994 * Even worse, it may never have been set up since reset.
996 hostdata
->saved_ctest7
= NCR53c7x0_read8(CTEST7_REG
) & CTEST7_SAVE
;
997 revision
= (NCR53c7x0_read8(CTEST8_REG
) & 0xF0) >> 4;
999 case 1: revision
= 0; break;
1000 case 2: revision
= 1; break;
1001 case 4: revision
= 2; break;
1002 case 8: revision
= 3; break;
1003 default: revision
= 255; break;
1005 printk("scsi%d: Revision 0x%x\n",host
->host_no
,revision
);
1007 if ((revision
== 0 || revision
== 255) && (hostdata
->options
& (OPTION_SYNCHRONOUS
|OPTION_DISCONNECT
|OPTION_ALWAYS_SYNCHRONOUS
)))
1009 printk ("scsi%d: Disabling sync working and disconnect/reselect\n",
1011 hostdata
->options
&= ~(OPTION_SYNCHRONOUS
|OPTION_DISCONNECT
|OPTION_ALWAYS_SYNCHRONOUS
);
1015 * On NCR53c700 series chips, DCNTL controls the SCSI clock divisor,
1016 * on 800 series chips, it allows for a totem-pole IRQ driver.
1017 * NOTE saved_dcntl currently overwritten in init function.
1018 * The value read here may be garbage anyway, MVME16x board at least
1019 * does not initialise chip if kernel arrived via tftp.
1022 hostdata
->saved_dcntl
= NCR53c7x0_read8(DCNTL_REG
);
1025 * DMODE controls DMA burst length, and on 700 series chips,
1026 * 286 mode and bus width
1027 * NOTE: On MVME16x, chip may have been reset, so this could be a
1028 * power-on/reset default value.
1030 hostdata
->saved_dmode
= NCR53c7x0_read8(hostdata
->dmode
);
1033 * Now that burst length and enabled/disabled status is known,
1034 * clue the user in on it.
1037 ccf
= clock_to_ccf_710 (expected_clock
);
1039 for (i
= 0; i
< 16; ++i
)
1040 hostdata
->cmd_allocated
[i
] = 0;
1042 if (hostdata
->init_save_regs
)
1043 hostdata
->init_save_regs (host
);
1044 if (hostdata
->init_fixup
)
1045 hostdata
->init_fixup (host
);
1047 if (!the_template
) {
1048 the_template
= host
->hostt
;
1053 * Linux SCSI drivers have always been plagued with initialization
1054 * problems - some didn't work with the BIOS disabled since they expected
1055 * initialization from it, some didn't work when the networking code
1056 * was enabled and registers got scrambled, etc.
1058 * To avoid problems like this, in the future, we will do a soft
1059 * reset on the SCSI chip, taking it back to a sane state.
1062 hostdata
->soft_reset (host
);
1065 hostdata
->debug_count_limit
= -1;
1067 hostdata
->debug_count_limit
= 1;
1069 hostdata
->intrs
= -1;
1070 hostdata
->resets
= -1;
1071 memcpy ((void *) hostdata
->synchronous_want
, (void *) sdtr_message
,
1072 sizeof (hostdata
->synchronous_want
));
1074 NCR53c7x0_driver_init (host
);
1076 if (request_irq(host
->irq
, NCR53c7x0_intr
, SA_SHIRQ
, "53c7xx", host
))
1078 printk("scsi%d : IRQ%d not free, detaching\n",
1079 host
->host_no
, host
->irq
);
1080 scsi_unregister (host
);
1084 if ((hostdata
->run_tests
&& hostdata
->run_tests(host
) == -1) ||
1085 (hostdata
->options
& OPTION_DEBUG_TESTS_ONLY
)) {
1086 /* XXX Should disable interrupts, etc. here */
1087 scsi_unregister (host
);
1090 if (host
->io_port
) {
1091 host
->n_io_port
= 128;
1092 request_region (host
->io_port
, host
->n_io_port
, "ncr53c7xx");
1096 if (NCR53c7x0_read8 (SBCL_REG
) & SBCL_BSY
) {
1097 printk ("scsi%d : bus wedge, doing SCSI reset\n", host
->host_no
);
1104 * Function : static int ncr53c7xx_init(Scsi_Host_Template *tpnt, int board,
1105 * int chip, u32 base, int io_port, int irq, int dma, long long options,
1108 * Purpose : initializes a NCR53c7,8x0 based on base addresses,
1109 * IRQ, and DMA channel.
1111 * Inputs : tpnt - Template for this SCSI adapter, board - board level
1112 * product, chip - 710
1114 * Returns : 0 on success, -1 on failure.
1119 ncr53c7xx_init (Scsi_Host_Template
*tpnt
, int board
, int chip
,
1120 u32 base
, int io_port
, int irq
, int dma
, long long options
, int clock
)
1122 struct Scsi_Host
*instance
;
1123 struct NCR53c7x0_hostdata
*hostdata
;
1125 int script_len
= 0, dsa_len
= 0, size
= 0, max_cmd_size
= 0,
1126 schedule_size
= 0, ok
= 0;
1133 schedule_size
= (tpnt
->can_queue
+ 1) * 8 /* JUMP instruction size */;
1134 script_len
= NCR53c7xx_script_len
;
1135 dsa_len
= NCR53c7xx_dsa_len
;
1136 options
|= OPTION_INTFLY
;
1137 sprintf (chip_str
, "NCR53c%d", chip
);
1140 printk("scsi-ncr53c7xx : unsupported SCSI chip %d\n", chip
);
1144 printk("scsi-ncr53c7xx : %s at memory 0x%x, io 0x%x, irq %d",
1145 chip_str
, (unsigned) base
, io_port
, irq
);
1146 if (dma
== DMA_NONE
)
1149 printk(", dma %d\n", dma
);
1151 if (options
& OPTION_DEBUG_PROBE_ONLY
) {
1152 printk ("scsi-ncr53c7xx : probe only enabled, aborting initialization\n");
1156 max_cmd_size
= sizeof(struct NCR53c7x0_cmd
) + dsa_len
+
1157 /* Size of dynamic part of command structure : */
1158 2 * /* Worst case : we don't know if we need DATA IN or DATA out */
1159 ( 2 * /* Current instructions per scatter/gather segment */
1160 tpnt
->sg_tablesize
+
1161 3 /* Current startup / termination required per phase */
1163 8 /* Each instruction is eight bytes */;
1165 /* Allocate fixed part of hostdata, dynamic part to hold appropriate
1166 SCSI SCRIPT(tm) plus a single, maximum-sized NCR53c7x0_cmd structure.
1168 We need a NCR53c7x0_cmd structure for scan_scsis() when we are
1169 not loaded as a module, and when we're loaded as a module, we
1170 can't use a non-dynamically allocated structure because modules
1171 are vmalloc()'d, which can allow structures to cross page
1172 boundaries and breaks our physical/virtual address assumptions
1175 So, we stick it past the end of our hostdata structure.
1178 Regardless of how many simultaneous SCSI commands we allow,
1179 the probe code only executes a _single_ instruction at a time,
1180 so we only need one here, and don't need to allocate NCR53c7x0_cmd
1181 structures for each target until we are no longer in scan_scsis
1182 and kmalloc() has become functional (memory_init() happens
1183 after all device driver initialization).
1186 size
= sizeof(struct NCR53c7x0_hostdata
) + script_len
+
1187 /* Note that alignment will be guaranteed, since we put the command
1188 allocated at probe time after the fixed-up SCSI script, which
1189 consists of 32 bit words, aligned on a 32 bit boundary. But
1190 on a 64bit machine we need 8 byte alignment for hostdata->free, so
1191 we add in another 4 bytes to take care of potential misalignment
1193 (sizeof(void *) - sizeof(u32
)) + max_cmd_size
+ schedule_size
;
1195 page
= __get_free_pages(GFP_ATOMIC
,1);
1198 printk(KERN_ERR
"53c7xx: out of memory.\n");
1201 #ifdef FORCE_DSA_ALIGNMENT
1203 * 53c710 rev.0 doesn't have an add-with-carry instruction.
1204 * Ensure we allocate enough memory to force DSA alignment.
1208 /* Size should be < 8K, so we can fit it in two pages. */
1210 panic("53c7xx: hostdata > 8K");
1211 instance
= scsi_register (tpnt
, 4);
1217 instance
->hostdata
[0] = page
;
1218 memset((void *)instance
->hostdata
[0], 0, 8192);
1219 cache_push(virt_to_phys((void *)(instance
->hostdata
[0])), 8192);
1220 cache_clear(virt_to_phys((void *)(instance
->hostdata
[0])), 8192);
1221 kernel_set_cachemode(instance
->hostdata
[0], 8192, IOMAP_NOCACHE_SER
);
1223 /* FIXME : if we ever support an ISA NCR53c7xx based board, we
1224 need to check if the chip is running in a 16 bit mode, and if so
1225 unregister it if it is past the 16M (0x1000000) mark */
1227 hostdata
= (struct NCR53c7x0_hostdata
*)instance
->hostdata
[0];
1228 hostdata
->size
= size
;
1229 hostdata
->script_count
= script_len
/ sizeof(u32
);
1230 hostdata
->board
= board
;
1231 hostdata
->chip
= chip
;
1234 * Being memory mapped is more desirable, since
1236 * - Memory accesses may be faster.
1238 * - The destination and source address spaces are the same for
1239 * all instructions, meaning we don't have to twiddle dmode or
1240 * any other registers.
1242 * So, we try for memory mapped, and if we don't get it,
1243 * we go for port mapped, and that failing we tell the user
1248 instance
->base
= (unsigned char *) (unsigned long) base
;
1249 /* Check for forced I/O mapping */
1250 if (!(options
& OPTION_IO_MAPPED
)) {
1251 options
|= OPTION_MEMORY_MAPPED
;
1255 options
&= ~OPTION_MEMORY_MAPPED
;
1259 instance
->io_port
= io_port
;
1260 options
|= OPTION_IO_MAPPED
;
1263 options
&= ~OPTION_IO_MAPPED
;
1267 printk ("scsi%d : not initializing, no I/O or memory mapping known \n",
1269 scsi_unregister (instance
);
1272 instance
->irq
= irq
;
1273 instance
->dma_channel
= dma
;
1275 hostdata
->options
= options
;
1276 hostdata
->dsa_len
= dsa_len
;
1277 hostdata
->max_cmd_size
= max_cmd_size
;
1278 hostdata
->num_cmds
= 1;
1279 hostdata
->scsi_clock
= clock
;
1280 /* Initialize single command */
1281 tmp
= (hostdata
->script
+ hostdata
->script_count
);
1282 #ifdef FORCE_DSA_ALIGNMENT
1284 void *t
= ROUNDUP(tmp
, void *);
1285 if (((u32
)t
& 0xff) > CmdPageStart
)
1286 t
= (void *)((u32
)t
+ 255);
1287 t
= (void *)(((u32
)t
& ~0xff) + CmdPageStart
);
1290 printk ("scsi: Registered size increased by 256 to %d\n", size
);
1291 printk ("scsi: CmdPageStart = 0x%02x\n", CmdPageStart
);
1292 printk ("scsi: tmp = 0x%08x, hostdata->free set to 0x%08x\n",
1297 hostdata
->free
= ROUNDUP(tmp
, void *);
1299 hostdata
->free
->real
= tmp
;
1300 hostdata
->free
->size
= max_cmd_size
;
1301 hostdata
->free
->free
= NULL
;
1302 hostdata
->free
->next
= NULL
;
1303 hostdata
->extra_allocate
= 0;
1305 /* Allocate command start code space */
1306 hostdata
->schedule
= (chip
== 700 || chip
== 70066) ?
1307 NULL
: (u32
*) ((char *)hostdata
->free
+ max_cmd_size
);
1310 * For diagnostic purposes, we don't really care how fast things blaze.
1311 * For profiling, we want to access the 800ns resolution system clock,
1312 * using a 'C' call on the host processor.
1314 * Therefore, there's no need for the NCR chip to directly manipulate
1315 * this data, and we should put it wherever is most convenient for
1319 hostdata
->events
= (struct NCR53c7x0_event
*) (track_events
?
1320 vmalloc (sizeof (struct NCR53c7x0_event
) * track_events
) : NULL
);
1322 hostdata
->events
= NULL
;
1324 if (hostdata
->events
) {
1325 memset ((void *) hostdata
->events
, 0, sizeof(struct NCR53c7x0_event
) *
1327 hostdata
->event_size
= track_events
;
1328 hostdata
->event_index
= 0;
1330 hostdata
->event_size
= 0;
1332 return NCR53c7x0_init(instance
);
1337 * Function : static void NCR53c7x0_init_fixup (struct Scsi_Host *host)
1339 * Purpose : copy and fixup the SCSI SCRIPTS(tm) code for this device.
1341 * Inputs : host - pointer to this host adapter's structure
1346 NCR53c7x0_init_fixup (struct Scsi_Host
*host
) {
1347 NCR53c7x0_local_declare();
1348 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
1351 int i
, ncr_to_memory
, memory_to_ncr
;
1353 NCR53c7x0_local_setup(host
);
1356 /* XXX - NOTE : this code MUST be made endian aware */
1357 /* Copy code into buffer that was allocated at detection time. */
1358 memcpy ((void *) hostdata
->script
, (void *) SCRIPT
,
1361 for (i
= 0; i
< PATCHES
; ++i
)
1362 hostdata
->script
[LABELPATCHES
[i
]] +=
1363 virt_to_bus(hostdata
->script
);
1364 /* Fixup addresses of constants that used to be EXTERNAL */
1366 patch_abs_32 (hostdata
->script
, 0, NCR53c7xx_msg_abort
,
1367 virt_to_bus(&(hostdata
->NCR53c7xx_msg_abort
)));
1368 patch_abs_32 (hostdata
->script
, 0, NCR53c7xx_msg_reject
,
1369 virt_to_bus(&(hostdata
->NCR53c7xx_msg_reject
)));
1370 patch_abs_32 (hostdata
->script
, 0, NCR53c7xx_zero
,
1371 virt_to_bus(&(hostdata
->NCR53c7xx_zero
)));
1372 patch_abs_32 (hostdata
->script
, 0, NCR53c7xx_sink
,
1373 virt_to_bus(&(hostdata
->NCR53c7xx_sink
)));
1374 patch_abs_32 (hostdata
->script
, 0, NOP_insn
,
1375 virt_to_bus(&(hostdata
->NOP_insn
)));
1376 patch_abs_32 (hostdata
->script
, 0, schedule
,
1377 virt_to_bus((void *) hostdata
->schedule
));
1379 /* Fixup references to external variables: */
1380 for (i
= 0; i
< EXTERNAL_PATCHES_LEN
; ++i
)
1381 hostdata
->script
[EXTERNAL_PATCHES
[i
].offset
] +=
1382 virt_to_bus(EXTERNAL_PATCHES
[i
].address
);
1385 * Fixup absolutes set at boot-time.
1387 * All non-code absolute variables suffixed with "dsa_" and "int_"
1388 * are constants, and need no fixup provided the assembler has done
1389 * it for us (I don't know what the "real" NCR assembler does in
1390 * this case, my assembler does the right magic).
1393 patch_abs_rwri_data (hostdata
->script
, 0, dsa_save_data_pointer
,
1394 Ent_dsa_code_save_data_pointer
- Ent_dsa_zero
);
1395 patch_abs_rwri_data (hostdata
->script
, 0, dsa_restore_pointers
,
1396 Ent_dsa_code_restore_pointers
- Ent_dsa_zero
);
1397 patch_abs_rwri_data (hostdata
->script
, 0, dsa_check_reselect
,
1398 Ent_dsa_code_check_reselect
- Ent_dsa_zero
);
1401 * Just for the hell of it, preserve the settings of
1402 * Burst Length and Enable Read Line bits from the DMODE
1403 * register. Make sure SCRIPTS start automagically.
1406 #if defined(CONFIG_MVME16x) || defined(CONFIG_BVME6000)
1407 /* We know better what we want than 16xBug does! */
1408 tmp
= DMODE_10_BL_8
| DMODE_10_FC2
;
1410 tmp
= NCR53c7x0_read8(DMODE_REG_10
);
1411 tmp
&= (DMODE_BL_MASK
| DMODE_10_FC2
| DMODE_10_FC1
| DMODE_710_PD
|
1415 if (!(hostdata
->options
& OPTION_MEMORY_MAPPED
)) {
1416 base
= (u32
) host
->io_port
;
1417 memory_to_ncr
= tmp
|DMODE_800_DIOM
;
1418 ncr_to_memory
= tmp
|DMODE_800_SIOM
;
1420 base
= virt_to_bus(host
->base
);
1421 memory_to_ncr
= ncr_to_memory
= tmp
;
1424 /* SCRATCHB_REG_10 == SCRATCHA_REG_800, as it happens */
1425 patch_abs_32 (hostdata
->script
, 0, addr_scratch
, base
+ SCRATCHA_REG_800
);
1426 patch_abs_32 (hostdata
->script
, 0, addr_temp
, base
+ TEMP_REG
);
1427 patch_abs_32 (hostdata
->script
, 0, addr_dsa
, base
+ DSA_REG
);
1430 * I needed some variables in the script to be accessible to
1431 * both the NCR chip and the host processor. For these variables,
1432 * I made the arbitrary decision to store them directly in the
1433 * hostdata structure rather than in the RELATIVE area of the
1438 patch_abs_rwri_data (hostdata
->script
, 0, dmode_memory_to_memory
, tmp
);
1439 patch_abs_rwri_data (hostdata
->script
, 0, dmode_memory_to_ncr
, memory_to_ncr
);
1440 patch_abs_rwri_data (hostdata
->script
, 0, dmode_ncr_to_memory
, ncr_to_memory
);
1442 patch_abs_32 (hostdata
->script
, 0, msg_buf
,
1443 virt_to_bus((void *)&(hostdata
->msg_buf
)));
1444 patch_abs_32 (hostdata
->script
, 0, reconnect_dsa_head
,
1445 virt_to_bus((void *)&(hostdata
->reconnect_dsa_head
)));
1446 patch_abs_32 (hostdata
->script
, 0, addr_reconnect_dsa_head
,
1447 virt_to_bus((void *)&(hostdata
->addr_reconnect_dsa_head
)));
1448 patch_abs_32 (hostdata
->script
, 0, reselected_identify
,
1449 virt_to_bus((void *)&(hostdata
->reselected_identify
)));
1450 /* reselected_tag is currently unused */
1452 patch_abs_32 (hostdata
->script
, 0, reselected_tag
,
1453 virt_to_bus((void *)&(hostdata
->reselected_tag
)));
1456 patch_abs_32 (hostdata
->script
, 0, test_dest
,
1457 virt_to_bus((void*)&hostdata
->test_dest
));
1458 patch_abs_32 (hostdata
->script
, 0, test_src
,
1459 virt_to_bus(&hostdata
->test_source
));
1460 patch_abs_32 (hostdata
->script
, 0, saved_dsa
,
1461 virt_to_bus(&hostdata
->saved2_dsa
));
1462 patch_abs_32 (hostdata
->script
, 0, emulfly
,
1463 virt_to_bus(&hostdata
->emulated_intfly
));
1465 patch_abs_rwri_data (hostdata
->script
, 0, dsa_check_reselect
,
1466 (unsigned char)(Ent_dsa_code_check_reselect
- Ent_dsa_zero
));
1468 /* These are for event logging; the ncr_event enum contains the
1469 actual interrupt numbers. */
1470 #ifdef A_int_EVENT_SELECT
1471 patch_abs_32 (hostdata
->script
, 0, int_EVENT_SELECT
, (u32
) EVENT_SELECT
);
1473 #ifdef A_int_EVENT_DISCONNECT
1474 patch_abs_32 (hostdata
->script
, 0, int_EVENT_DISCONNECT
, (u32
) EVENT_DISCONNECT
);
1476 #ifdef A_int_EVENT_RESELECT
1477 patch_abs_32 (hostdata
->script
, 0, int_EVENT_RESELECT
, (u32
) EVENT_RESELECT
);
1479 #ifdef A_int_EVENT_COMPLETE
1480 patch_abs_32 (hostdata
->script
, 0, int_EVENT_COMPLETE
, (u32
) EVENT_COMPLETE
);
1482 #ifdef A_int_EVENT_IDLE
1483 patch_abs_32 (hostdata
->script
, 0, int_EVENT_IDLE
, (u32
) EVENT_IDLE
);
1485 #ifdef A_int_EVENT_SELECT_FAILED
1486 patch_abs_32 (hostdata
->script
, 0, int_EVENT_SELECT_FAILED
,
1487 (u32
) EVENT_SELECT_FAILED
);
1489 #ifdef A_int_EVENT_BEFORE_SELECT
1490 patch_abs_32 (hostdata
->script
, 0, int_EVENT_BEFORE_SELECT
,
1491 (u32
) EVENT_BEFORE_SELECT
);
1493 #ifdef A_int_EVENT_RESELECT_FAILED
1494 patch_abs_32 (hostdata
->script
, 0, int_EVENT_RESELECT_FAILED
,
1495 (u32
) EVENT_RESELECT_FAILED
);
1499 * Make sure the NCR and Linux code agree on the location of
1503 hostdata
->E_accept_message
= Ent_accept_message
;
1504 hostdata
->E_command_complete
= Ent_command_complete
;
1505 hostdata
->E_cmdout_cmdout
= Ent_cmdout_cmdout
;
1506 hostdata
->E_data_transfer
= Ent_data_transfer
;
1507 hostdata
->E_debug_break
= Ent_debug_break
;
1508 hostdata
->E_dsa_code_template
= Ent_dsa_code_template
;
1509 hostdata
->E_dsa_code_template_end
= Ent_dsa_code_template_end
;
1510 hostdata
->E_end_data_transfer
= Ent_end_data_transfer
;
1511 hostdata
->E_initiator_abort
= Ent_initiator_abort
;
1512 hostdata
->E_msg_in
= Ent_msg_in
;
1513 hostdata
->E_other_transfer
= Ent_other_transfer
;
1514 hostdata
->E_other_in
= Ent_other_in
;
1515 hostdata
->E_other_out
= Ent_other_out
;
1516 hostdata
->E_reject_message
= Ent_reject_message
;
1517 hostdata
->E_respond_message
= Ent_respond_message
;
1518 hostdata
->E_select
= Ent_select
;
1519 hostdata
->E_select_msgout
= Ent_select_msgout
;
1520 hostdata
->E_target_abort
= Ent_target_abort
;
1522 hostdata
->E_test_0
= Ent_test_0
;
1524 hostdata
->E_test_1
= Ent_test_1
;
1525 hostdata
->E_test_2
= Ent_test_2
;
1527 hostdata
->E_test_3
= Ent_test_3
;
1529 hostdata
->E_wait_reselect
= Ent_wait_reselect
;
1530 hostdata
->E_dsa_code_begin
= Ent_dsa_code_begin
;
1532 hostdata
->dsa_cmdout
= A_dsa_cmdout
;
1533 hostdata
->dsa_cmnd
= A_dsa_cmnd
;
1534 hostdata
->dsa_datain
= A_dsa_datain
;
1535 hostdata
->dsa_dataout
= A_dsa_dataout
;
1536 hostdata
->dsa_end
= A_dsa_end
;
1537 hostdata
->dsa_msgin
= A_dsa_msgin
;
1538 hostdata
->dsa_msgout
= A_dsa_msgout
;
1539 hostdata
->dsa_msgout_other
= A_dsa_msgout_other
;
1540 hostdata
->dsa_next
= A_dsa_next
;
1541 hostdata
->dsa_select
= A_dsa_select
;
1542 hostdata
->dsa_start
= Ent_dsa_code_template
- Ent_dsa_zero
;
1543 hostdata
->dsa_status
= A_dsa_status
;
1544 hostdata
->dsa_jump_dest
= Ent_dsa_code_fix_jump
- Ent_dsa_zero
+
1545 8 /* destination operand */;
1548 if (A_dsa_fields_start
!= Ent_dsa_code_template_end
-
1550 printk("scsi%d : NCR dsa_fields start is %d not %d\n",
1551 host
->host_no
, A_dsa_fields_start
, Ent_dsa_code_template_end
-
1554 printk("scsi%d : NCR code relocated to 0x%lx (virt 0x%p)\n", host
->host_no
,
1555 virt_to_bus(hostdata
->script
), hostdata
->script
);
1559 * Function : static int NCR53c7xx_run_tests (struct Scsi_Host *host)
1561 * Purpose : run various verification tests on the NCR chip,
1562 * including interrupt generation, and proper bus mastering
1565 * Inputs : host - a properly initialized Scsi_Host structure
1567 * Preconditions : the NCR chip must be in a halted state.
1569 * Returns : 0 if all tests were successful, -1 on error.
1574 NCR53c7xx_run_tests (struct Scsi_Host
*host
) {
1575 NCR53c7x0_local_declare();
1576 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
1578 unsigned long timeout
;
1581 unsigned long flags
;
1582 NCR53c7x0_local_setup(host
);
1584 /* The NCR chip _must_ be idle to run the test scripts */
1588 if (!hostdata
->idle
) {
1589 printk ("scsi%d : chip not idle, aborting tests\n", host
->host_no
);
1590 restore_flags(flags
);
1595 * Check for functional interrupts, this could work as an
1596 * autoprobe routine.
1599 if ((hostdata
->options
& OPTION_DEBUG_TEST1
) &&
1600 hostdata
->state
!= STATE_DISABLED
) {
1602 hostdata
->test_running
= 1;
1603 hostdata
->test_completed
= -1;
1604 hostdata
->test_dest
= 0;
1605 hostdata
->test_source
= 0xdeadbeef;
1606 start
= virt_to_bus (hostdata
->script
) + hostdata
->E_test_1
;
1607 hostdata
->state
= STATE_RUNNING
;
1608 printk ("scsi%d : test 1", host
->host_no
);
1609 NCR53c7x0_write32 (DSP_REG
, start
);
1610 if (hostdata
->options
& OPTION_DEBUG_TRACE
)
1611 NCR53c7x0_write8 (DCNTL_REG
, hostdata
->saved_dcntl
| DCNTL_SSM
|
1613 printk (" started\n");
1614 restore_flags(flags
);
1617 * This is currently a .5 second timeout, since (in theory) no slow
1618 * board will take that long. In practice, we've seen one
1619 * pentium which occassionally fails with this, but works with
1623 timeout
= jiffies
+ 5 * HZ
/ 10;
1624 while ((hostdata
->test_completed
== -1) && jiffies
< timeout
)
1628 if (hostdata
->test_completed
== -1)
1629 printk ("scsi%d : driver test 1 timed out%s\n",host
->host_no
,
1630 (hostdata
->test_dest
== 0xdeadbeef) ?
1631 " due to lost interrupt.\n"
1632 " Please verify that the correct IRQ is being used for your board,\n"
1634 else if (hostdata
->test_completed
!= 1)
1635 printk ("scsi%d : test 1 bad interrupt value (%d)\n",
1636 host
->host_no
, hostdata
->test_completed
);
1638 failed
= (hostdata
->test_dest
!= 0xdeadbeef);
1640 if (hostdata
->test_dest
!= 0xdeadbeef) {
1641 printk ("scsi%d : driver test 1 read 0x%x instead of 0xdeadbeef indicating a\n"
1642 " probable cache invalidation problem. Please configure caching\n"
1643 " as write-through or disabled\n",
1644 host
->host_no
, hostdata
->test_dest
);
1648 printk ("scsi%d : DSP = 0x%p (script at 0x%p, start at 0x%x)\n",
1649 host
->host_no
, bus_to_virt(NCR53c7x0_read32(DSP_REG
)),
1650 hostdata
->script
, start
);
1651 printk ("scsi%d : DSPS = 0x%x\n", host
->host_no
,
1652 NCR53c7x0_read32(DSPS_REG
));
1653 restore_flags(flags
);
1656 hostdata
->test_running
= 0;
1659 if ((hostdata
->options
& OPTION_DEBUG_TEST2
) &&
1660 hostdata
->state
!= STATE_DISABLED
) {
1662 unsigned char identify
= IDENTIFY(0, 0);
1663 unsigned char cmd
[6];
1664 unsigned char data
[36];
1665 unsigned char status
= 0xff;
1666 unsigned char msg
= 0xff;
1669 cmd
[1] = cmd
[2] = cmd
[3] = cmd
[5] = 0;
1670 cmd
[4] = sizeof(data
);
1673 dsa
[3] = virt_to_bus(&identify
);
1675 dsa
[5] = virt_to_bus(&cmd
);
1676 dsa
[6] = sizeof(data
);
1677 dsa
[7] = virt_to_bus(&data
);
1679 dsa
[9] = virt_to_bus(&status
);
1681 dsa
[11] = virt_to_bus(&msg
);
1683 for (i
= 0; i
< 6; ++i
) {
1685 if (!hostdata
->valid_ids
[i
])
1689 if (!hostdata
->idle
) {
1690 printk ("scsi%d : chip not idle, aborting tests\n", host
->host_no
);
1691 restore_flags(flags
);
1695 /* 710: bit mapped scsi ID, async */
1696 dsa
[0] = (1 << i
) << 16;
1698 hostdata
->test_running
= 2;
1699 hostdata
->test_completed
= -1;
1700 start
= virt_to_bus(hostdata
->script
) + hostdata
->E_test_2
;
1701 hostdata
->state
= STATE_RUNNING
;
1702 NCR53c7x0_write32 (DSA_REG
, virt_to_bus(dsa
));
1703 NCR53c7x0_write32 (DSP_REG
, start
);
1704 if (hostdata
->options
& OPTION_DEBUG_TRACE
)
1705 NCR53c7x0_write8 (DCNTL_REG
, hostdata
->saved_dcntl
|
1706 DCNTL_SSM
| DCNTL_STD
);
1707 restore_flags(flags
);
1709 timeout
= jiffies
+ 5 * HZ
; /* arbitrary */
1710 while ((hostdata
->test_completed
== -1) && jiffies
< timeout
)
1713 NCR53c7x0_write32 (DSA_REG
, 0);
1715 if (hostdata
->test_completed
== 2) {
1717 printk ("scsi%d : test 2 INQUIRY to target %d, lun 0 : %s\n",
1718 host
->host_no
, i
, data
+ 8);
1719 printk ("scsi%d : status ", host
->host_no
);
1720 print_status (status
);
1721 printk ("\nscsi%d : message ", host
->host_no
);
1724 } else if (hostdata
->test_completed
== 3) {
1725 printk("scsi%d : test 2 no connection with target %d\n",
1727 if (!hostdata
->idle
) {
1728 printk("scsi%d : not idle\n", host
->host_no
);
1729 restore_flags(flags
);
1732 } else if (hostdata
->test_completed
== -1) {
1733 printk ("scsi%d : test 2 timed out\n", host
->host_no
);
1734 restore_flags(flags
);
1737 hostdata
->test_running
= 0;
1741 restore_flags(flags
);
1746 * Function : static void NCR53c7xx_dsa_fixup (struct NCR53c7x0_cmd *cmd)
1748 * Purpose : copy the NCR53c8xx dsa structure into cmd's dsa buffer,
1749 * performing all necessary relocation.
1751 * Inputs : cmd, a NCR53c7x0_cmd structure with a dsa area large
1752 * enough to hold the NCR53c8xx dsa.
1756 NCR53c7xx_dsa_fixup (struct NCR53c7x0_cmd
*cmd
) {
1757 Scsi_Cmnd
*c
= cmd
->cmd
;
1758 struct Scsi_Host
*host
= c
->host
;
1759 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
1763 memcpy (cmd
->dsa
, hostdata
->script
+ (hostdata
->E_dsa_code_template
/ 4),
1764 hostdata
->E_dsa_code_template_end
- hostdata
->E_dsa_code_template
);
1767 * Note : within the NCR 'C' code, dsa points to the _start_
1768 * of the DSA structure, and _not_ the offset of dsa_zero within
1769 * that structure used to facilitate shorter signed offsets
1770 * for the 8 bit ALU.
1772 * The implications of this are that
1774 * - 32 bit A_dsa_* absolute values require an additional
1775 * dsa_zero added to their value to be correct, since they are
1776 * relative to dsa_zero which is in essentially a separate
1777 * space from the code symbols.
1779 * - All other symbols require no special treatment.
1782 patch_abs_tci_data (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
1783 dsa_temp_lun
, c
->lun
);
1784 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
1785 dsa_temp_addr_next
, virt_to_bus(&cmd
->dsa_next_addr
));
1786 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
1787 dsa_temp_next
, virt_to_bus(cmd
->dsa
) + Ent_dsa_zero
-
1788 Ent_dsa_code_template
+ A_dsa_next
);
1789 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
1790 dsa_temp_sync
, virt_to_bus((void *)hostdata
->sync
[c
->target
].script
));
1791 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
1792 dsa_sscf_710
, virt_to_bus((void *)&hostdata
->sync
[c
->target
].sscf_710
));
1793 patch_abs_tci_data (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
1794 dsa_temp_target
, 1 << c
->target
);
1795 /* XXX - new pointer stuff */
1796 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
1797 dsa_temp_addr_saved_pointer
, virt_to_bus(&cmd
->saved_data_pointer
));
1798 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
1799 dsa_temp_addr_saved_residual
, virt_to_bus(&cmd
->saved_residual
));
1800 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
1801 dsa_temp_addr_residual
, virt_to_bus(&cmd
->residual
));
1803 /* XXX - new start stuff */
1805 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
1806 dsa_temp_addr_dsa_value
, virt_to_bus(&cmd
->dsa_addr
));
1810 * Function : run_process_issue_queue (void)
1812 * Purpose : insure that the coroutine is running and will process our
1813 * request. process_issue_queue_running is checked/set here (in an
1814 * inline function) rather than in process_issue_queue itself to reduce
1815 * the chances of stack overflow.
1819 static volatile int process_issue_queue_running
= 0;
1821 static __inline__
void
1822 run_process_issue_queue(void) {
1823 unsigned long flags
;
1826 if (!process_issue_queue_running
) {
1827 process_issue_queue_running
= 1;
1828 process_issue_queue(flags
);
1830 * process_issue_queue_running is cleared in process_issue_queue
1831 * once it can't do more work, and process_issue_queue exits with
1832 * interrupts disabled.
1835 restore_flags (flags
);
1839 * Function : static void abnormal_finished (struct NCR53c7x0_cmd *cmd, int
1842 * Purpose : mark SCSI command as finished, OR'ing the host portion
1843 * of the result word into the result field of the corresponding
1844 * Scsi_Cmnd structure, and removing it from the internal queues.
1846 * Inputs : cmd - command, result - entire result field
1848 * Preconditions : the NCR chip should be in a halted state when
1849 * abnormal_finished is run, since it modifies structures which
1850 * the NCR expects to have exclusive access to.
1854 abnormal_finished (struct NCR53c7x0_cmd
*cmd
, int result
) {
1855 Scsi_Cmnd
*c
= cmd
->cmd
;
1856 struct Scsi_Host
*host
= c
->host
;
1857 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
1859 unsigned long flags
;
1861 volatile struct NCR53c7x0_cmd
* linux_search
;
1862 volatile struct NCR53c7x0_cmd
* volatile *linux_prev
;
1863 volatile u32
*ncr_prev
, *ncrcurrent
, ncr_search
;
1866 printk ("scsi%d: abnormal finished\n", host
->host_no
);
1873 * Traverse the NCR issue array until we find a match or run out
1874 * of instructions. Instructions in the NCR issue array are
1875 * either JUMP or NOP instructions, which are 2 words in length.
1879 for (found
= 0, left
= host
->can_queue
, ncrcurrent
= hostdata
->schedule
;
1880 left
> 0; --left
, ncrcurrent
+= 2)
1882 if (issue_to_cmd (host
, hostdata
, (u32
*) ncrcurrent
) == cmd
)
1884 ncrcurrent
[0] = hostdata
->NOP_insn
;
1885 ncrcurrent
[1] = 0xdeadbeef;
1892 * Traverse the NCR reconnect list of DSA structures until we find
1893 * a pointer to this dsa or have found too many command structures.
1894 * We let prev point at the next field of the previous element or
1895 * head of the list, so we don't do anything different for removing
1899 for (left
= host
->can_queue
,
1900 ncr_search
= hostdata
->reconnect_dsa_head
,
1901 ncr_prev
= &hostdata
->reconnect_dsa_head
;
1902 left
>= 0 && ncr_search
&&
1903 ((char*)bus_to_virt(ncr_search
) + hostdata
->dsa_start
)
1904 != (char *) cmd
->dsa
;
1905 ncr_prev
= (u32
*) ((char*)bus_to_virt(ncr_search
) +
1906 hostdata
->dsa_next
), ncr_search
= *ncr_prev
, --left
);
1909 printk("scsi%d: loop detected in ncr reconncect list\n",
1911 else if (ncr_search
) {
1913 printk("scsi%d: scsi %ld in ncr issue array and reconnect lists\n",
1914 host
->host_no
, c
->pid
);
1916 volatile u32
* next
= (u32
*)
1917 ((char *)bus_to_virt(ncr_search
) + hostdata
->dsa_next
);
1919 /* If we're at the tail end of the issue queue, update that pointer too. */
1925 * Traverse the host running list until we find this command or discover
1926 * we have too many elements, pointing linux_prev at the next field of the
1927 * linux_previous element or head of the list, search at this element.
1930 for (left
= host
->can_queue
, linux_search
= hostdata
->running_list
,
1931 linux_prev
= &hostdata
->running_list
;
1932 left
>= 0 && linux_search
&& linux_search
!= cmd
;
1933 linux_prev
= &(linux_search
->next
),
1934 linux_search
= linux_search
->next
, --left
);
1937 printk ("scsi%d: loop detected in host running list for scsi pid %ld\n",
1938 host
->host_no
, c
->pid
);
1939 else if (linux_search
) {
1940 *linux_prev
= linux_search
->next
;
1941 --hostdata
->busy
[c
->target
][c
->lun
];
1944 /* Return the NCR command structure to the free list */
1945 cmd
->next
= hostdata
->free
;
1946 hostdata
->free
= cmd
;
1947 c
->host_scribble
= NULL
;
1953 restore_flags(flags
);
1954 run_process_issue_queue();
1958 * Function : static void intr_break (struct Scsi_Host *host,
1959 * struct NCR53c7x0_cmd *cmd)
1961 * Purpose : Handler for breakpoint interrupts from a SCSI script
1963 * Inputs : host - pointer to this host adapter's structure,
1964 * cmd - pointer to the command (if any) dsa was pointing
1970 intr_break (struct Scsi_Host
*host
, struct
1971 NCR53c7x0_cmd
*cmd
) {
1972 NCR53c7x0_local_declare();
1973 struct NCR53c7x0_break
*bp
;
1975 Scsi_Cmnd
*c
= cmd
? cmd
->cmd
: NULL
;
1978 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
1980 unsigned long flags
;
1981 NCR53c7x0_local_setup(host
);
1984 * Find the break point corresponding to this address, and
1985 * dump the appropriate debugging information to standard
1990 dsp
= (u32
*) bus_to_virt(NCR53c7x0_read32(DSP_REG
));
1991 for (bp
= hostdata
->breakpoints
; bp
&& bp
->address
!= dsp
;
1994 panic("scsi%d : break point interrupt from %p with no breakpoint!",
1995 host
->host_no
, dsp
);
1998 * Configure the NCR chip for manual start mode, so that we can
1999 * point the DSP register at the instruction that follows the
2000 * INT int_debug_break instruction.
2003 NCR53c7x0_write8 (hostdata
->dmode
,
2004 NCR53c7x0_read8(hostdata
->dmode
)|DMODE_MAN
);
2007 * And update the DSP register, using the size of the old
2008 * instruction in bytes.
2011 restore_flags(flags
);
2014 * Function : static void print_synchronous (const char *prefix,
2015 * const unsigned char *msg)
2017 * Purpose : print a pretty, user and machine parsable representation
2018 * of a SDTR message, including the "real" parameters, data
2019 * clock so we can tell transfer rate at a glance.
2021 * Inputs ; prefix - text to prepend, msg - SDTR message (5 bytes)
2025 print_synchronous (const char *prefix
, const unsigned char *msg
) {
2027 int Hz
= 1000000000 / (msg
[3] * 4);
2028 int integer
= Hz
/ 1000000;
2029 int fraction
= (Hz
- (integer
* 1000000)) / 10000;
2030 printk ("%speriod %dns offset %d %d.%02dMHz %s SCSI%s\n",
2031 prefix
, (int) msg
[3] * 4, (int) msg
[4], integer
, fraction
,
2032 (((msg
[3] * 4) < 200) ? "FAST" : "synchronous"),
2033 (((msg
[3] * 4) < 200) ? "-II" : ""));
2035 printk ("%sasynchronous SCSI\n", prefix
);
2039 * Function : static void set_synchronous (struct Scsi_Host *host,
2040 * int target, int sxfer, int scntl3, int now_connected)
2042 * Purpose : reprogram transfers between the selected SCSI initiator and
2043 * target with the given register values; in the indirect
2044 * select operand, reselection script, and chip registers.
2046 * Inputs : host - NCR53c7,8xx SCSI host, target - number SCSI target id,
2047 * sxfer and scntl3 - NCR registers. now_connected - if non-zero,
2048 * we should reprogram the registers now too.
2050 * NOTE: For 53c710, scntl3 is actually used for SCF bits from
2051 * SBCL, as we don't have a SCNTL3.
2055 set_synchronous (struct Scsi_Host
*host
, int target
, int sxfer
, int scntl3
,
2056 int now_connected
) {
2057 NCR53c7x0_local_declare();
2058 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
2061 NCR53c7x0_local_setup(host
);
2063 /* These are eight bit registers */
2067 hostdata
->sync
[target
].sxfer_sanity
= sxfer
;
2068 hostdata
->sync
[target
].scntl3_sanity
= scntl3
;
2071 * HARD CODED : synchronous script is EIGHT words long. This
2072 * must agree with 53c7.8xx.h
2075 if ((hostdata
->chip
!= 700) && (hostdata
->chip
!= 70066)) {
2076 hostdata
->sync
[target
].select_indirect
= (1 << target
) << 16 |
2078 hostdata
->sync
[target
].sscf_710
= scntl3
;
2080 script
= (u32
*) hostdata
->sync
[target
].script
;
2082 /* XXX - add NCR53c7x0 code to reprogram SCF bits if we want to */
2083 script
[0] = ((DCMD_TYPE_RWRI
| DCMD_RWRI_OPC_MODIFY
|
2084 DCMD_RWRI_OP_MOVE
) << 24) |
2085 (SBCL_REG
<< 16) | (scntl3
<< 8);
2089 script
[0] = ((DCMD_TYPE_RWRI
| DCMD_RWRI_OPC_MODIFY
|
2090 DCMD_RWRI_OP_MOVE
) << 24) |
2091 (SXFER_REG
<< 16) | (sxfer
<< 8);
2095 #ifdef DEBUG_SYNC_INTR
2096 if (hostdata
->options
& OPTION_DEBUG_DISCONNECT
) {
2097 script
[0] = ((DCMD_TYPE_TCI
|DCMD_TCI_OP_INT
) << 24) | DBC_TCI_TRUE
;
2098 script
[1] = DEBUG_SYNC_INTR
;
2103 script
[0] = ((DCMD_TYPE_TCI
|DCMD_TCI_OP_RETURN
) << 24) | DBC_TCI_TRUE
;
2108 if (hostdata
->options
& OPTION_DEBUG_SYNCHRONOUS
)
2109 printk ("scsi%d : target %d sync parameters are sxfer=0x%x, scntl3=0x%x\n",
2110 host
->host_no
, target
, sxfer
, scntl3
);
2112 if (now_connected
) {
2113 NCR53c7x0_write8(SBCL_REG
, scntl3
);
2114 NCR53c7x0_write8(SXFER_REG
, sxfer
);
2120 * Function : static int asynchronous (struct Scsi_Host *host, int target)
2122 * Purpose : reprogram between the selected SCSI Host adapter and target
2123 * (assumed to be currently connected) for asynchronous transfers.
2125 * Inputs : host - SCSI host structure, target - numeric target ID.
2127 * Preconditions : the NCR chip should be in one of the halted states
2131 asynchronous (struct Scsi_Host
*host
, int target
) {
2132 NCR53c7x0_local_declare();
2133 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
2135 NCR53c7x0_local_setup(host
);
2136 set_synchronous (host
, target
, /* no offset */ 0, hostdata
->saved_scntl3
,
2138 printk ("scsi%d : setting target %d to asynchronous SCSI\n",
2139 host
->host_no
, target
);
2143 * XXX - do we want to go out of our way (ie, add extra code to selection
2144 * in the NCR53c710/NCR53c720 script) to reprogram the synchronous
2145 * conversion bits, or can we be content in just setting the
2146 * sxfer bits? I chose to do so [richard@sleepie.demon.co.uk]
2149 /* Table for NCR53c8xx synchronous values */
2151 /* This table is also correct for 710, allowing that scf=4 is equivalent
2152 * of SSCF=0 (ie use DCNTL, divide by 3) for a 50.01-66.00MHz clock.
2153 * For any other clock values, we cannot use entries with SCF values of
2154 * 4. I guess that for a 66MHz clock, the slowest it will set is 2MHz,
2155 * and for a 50MHz clock, the slowest will be 2.27Mhz. Should check
2156 * that a device doesn't try and negotiate sync below these limits!
2159 static const struct {
2160 int div
; /* Total clock divisor * 10 */
2161 unsigned char scf
; /* */
2162 unsigned char tp
; /* 4 + tp = xferp divisor */
2164 /* div scf tp div scf tp div scf tp */
2165 { 40, 1, 0}, { 50, 1, 1}, { 60, 1, 2},
2166 { 70, 1, 3}, { 75, 2, 1}, { 80, 1, 4},
2167 { 90, 1, 5}, { 100, 1, 6}, { 105, 2, 3},
2168 { 110, 1, 7}, { 120, 2, 4}, { 135, 2, 5},
2169 { 140, 3, 3}, { 150, 2, 6}, { 160, 3, 4},
2170 { 165, 2, 7}, { 180, 3, 5}, { 200, 3, 6},
2171 { 210, 4, 3}, { 220, 3, 7}, { 240, 4, 4},
2172 { 270, 4, 5}, { 300, 4, 6}, { 330, 4, 7}
2176 * Function : static void synchronous (struct Scsi_Host *host, int target,
2179 * Purpose : reprogram transfers between the selected SCSI initiator and
2180 * target for synchronous SCSI transfers such that the synchronous
2181 * offset is less than that requested and period at least as long
2182 * as that requested. Also modify *msg such that it contains
2183 * an appropriate response.
2185 * Inputs : host - NCR53c7,8xx SCSI host, target - number SCSI target id,
2186 * msg - synchronous transfer request.
2191 synchronous (struct Scsi_Host
*host
, int target
, char *msg
) {
2192 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
2194 int desire
, divisor
, i
, limit
;
2195 unsigned char scntl3
, sxfer
;
2196 /* The diagnostic message fits on one line, even with max. width integers */
2199 /* Desired transfer clock in Hz */
2200 desire
= 1000000000L / (msg
[3] * 4);
2201 /* Scale the available SCSI clock by 10 so we get tenths */
2202 divisor
= (hostdata
->scsi_clock
* 10) / desire
;
2204 /* NCR chips can handle at most an offset of 8 */
2208 if (hostdata
->options
& OPTION_DEBUG_SDTR
)
2209 printk("scsi%d : optimal synchronous divisor of %d.%01d\n",
2210 host
->host_no
, divisor
/ 10, divisor
% 10);
2212 limit
= (sizeof(syncs
) / sizeof(syncs
[0]) -1);
2213 for (i
= 0; (i
< limit
) && (divisor
> syncs
[i
].div
); ++i
);
2215 if (hostdata
->options
& OPTION_DEBUG_SDTR
)
2216 printk("scsi%d : selected synchronous divisor of %d.%01d\n",
2217 host
->host_no
, syncs
[i
].div
/ 10, syncs
[i
].div
% 10);
2219 msg
[3] = ((1000000000L / hostdata
->scsi_clock
) * syncs
[i
].div
/ 10 / 4);
2221 if (hostdata
->options
& OPTION_DEBUG_SDTR
)
2222 printk("scsi%d : selected synchronous period of %dns\n", host
->host_no
,
2225 scntl3
= syncs
[i
].scf
;
2226 sxfer
= (msg
[4] << SXFER_MO_SHIFT
) | (syncs
[i
].tp
<< 4);
2227 if (hostdata
->options
& OPTION_DEBUG_SDTR
)
2228 printk ("scsi%d : sxfer=0x%x scntl3=0x%x\n",
2229 host
->host_no
, (int) sxfer
, (int) scntl3
);
2230 set_synchronous (host
, target
, sxfer
, scntl3
, 1);
2231 sprintf (buf
, "scsi%d : setting target %d to ", host
->host_no
, target
);
2232 print_synchronous (buf
, msg
);
2236 * Function : static int NCR53c7x0_dstat_sir_intr (struct Scsi_Host *host,
2237 * struct NCR53c7x0_cmd *cmd)
2239 * Purpose : Handler for INT generated instructions for the
2240 * NCR53c810/820 SCSI SCRIPT
2242 * Inputs : host - pointer to this host adapter's structure,
2243 * cmd - pointer to the command (if any) dsa was pointing
2249 NCR53c7x0_dstat_sir_intr (struct Scsi_Host
*host
, struct
2250 NCR53c7x0_cmd
*cmd
) {
2251 NCR53c7x0_local_declare();
2253 Scsi_Cmnd
*c
= cmd
? cmd
->cmd
: NULL
;
2254 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
2256 u32 dsps
,*dsp
; /* Argument of the INT instruction */
2258 NCR53c7x0_local_setup(host
);
2259 dsps
= NCR53c7x0_read32(DSPS_REG
);
2260 dsp
= (u32
*) bus_to_virt(NCR53c7x0_read32(DSP_REG
));
2262 /* RGH 150597: Frig. Commands which fail with Check Condition are
2263 * Flagged as successful - hack dsps to indicate check condition */
2265 /* RGH 200597: Need to disable for BVME6000, as it gets Check Conditions
2266 * and then dies. Seems to handle Check Condition at startup, but
2267 * not mid kernel build. */
2268 if (dsps
== A_int_norm_emulateintfly
&& cmd
&& cmd
->result
== 2)
2269 dsps
= A_int_err_check_condition
;
2272 if (hostdata
->options
& OPTION_DEBUG_INTR
)
2273 printk ("scsi%d : DSPS = 0x%x\n", host
->host_no
, dsps
);
2278 switch (hostdata
->msg_buf
[0]) {
2280 * Unless we've initiated synchronous negotiation, I don't
2281 * think that this should happen.
2283 case MESSAGE_REJECT
:
2284 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_accept_message
/
2286 hostdata
->dsp_changed
= 1;
2287 if (cmd
&& (cmd
->flags
& CMD_FLAG_SDTR
)) {
2288 printk ("scsi%d : target %d rejected SDTR\n", host
->host_no
,
2290 cmd
->flags
&= ~CMD_FLAG_SDTR
;
2291 asynchronous (host
, c
->target
);
2295 case INITIATE_RECOVERY
:
2296 printk ("scsi%d : extended contingent allegiance not supported yet, rejecting\n",
2298 /* Fall through to default */
2299 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_reject_message
/
2301 hostdata
->dsp_changed
= 1;
2304 printk ("scsi%d : unsupported message, rejecting\n",
2306 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_reject_message
/
2308 hostdata
->dsp_changed
= 1;
2311 printk ("scsi%d : received message", host
->host_no
);
2313 printk (" from target %d lun %d ", c
->target
, c
->lun
);
2314 print_msg ((unsigned char *) hostdata
->msg_buf
);
2318 return SPECIFIC_INT_NOTHING
;
2321 case A_int_msg_sdtr
:
2323 * At this point, hostdata->msg_buf contains
2324 * 0 EXTENDED MESSAGE
2333 sprintf (buf
, "scsi%d : target %d %s ", host
->host_no
, c
->target
,
2334 (cmd
->flags
& CMD_FLAG_SDTR
) ? "accepting" : "requesting");
2335 print_synchronous (buf
, (unsigned char *) hostdata
->msg_buf
);
2338 * Initiator initiated, won't happen unless synchronous
2339 * transfers are enabled. If we get a SDTR message in
2340 * response to our SDTR, we should program our parameters
2342 * offset <= requested offset
2343 * period >= requested period
2345 if (cmd
->flags
& CMD_FLAG_SDTR
) {
2346 cmd
->flags
&= ~CMD_FLAG_SDTR
;
2347 if (hostdata
->msg_buf
[4])
2348 synchronous (host
, c
->target
, (unsigned char *)
2351 asynchronous (host
, c
->target
);
2352 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_accept_message
/
2354 hostdata
->dsp_changed
= 1;
2355 return SPECIFIC_INT_NOTHING
;
2357 if (hostdata
->options
& OPTION_SYNCHRONOUS
) {
2358 cmd
->flags
|= CMD_FLAG_DID_SDTR
;
2359 synchronous (host
, c
->target
, (unsigned char *)
2362 hostdata
->msg_buf
[4] = 0; /* 0 offset = async */
2363 asynchronous (host
, c
->target
);
2365 patch_dsa_32 (cmd
->dsa
, dsa_msgout_other
, 0, 5);
2366 patch_dsa_32 (cmd
->dsa
, dsa_msgout_other
, 1, (u32
)
2367 virt_to_bus ((void *)&hostdata
->msg_buf
));
2368 hostdata
->dsp
= hostdata
->script
+
2369 hostdata
->E_respond_message
/ sizeof(u32
);
2370 hostdata
->dsp_changed
= 1;
2372 return SPECIFIC_INT_NOTHING
;
2374 /* Fall through to abort if we couldn't find a cmd, and
2375 therefore a dsa structure to twiddle */
2376 case A_int_msg_wdtr
:
2377 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_reject_message
/
2379 hostdata
->dsp_changed
= 1;
2380 return SPECIFIC_INT_NOTHING
;
2381 case A_int_err_unexpected_phase
:
2382 if (hostdata
->options
& OPTION_DEBUG_INTR
)
2383 printk ("scsi%d : unexpected phase\n", host
->host_no
);
2384 return SPECIFIC_INT_ABORT
;
2385 case A_int_err_selected
:
2386 if ((hostdata
->chip
/ 100) == 8)
2387 printk ("scsi%d : selected by target %d\n", host
->host_no
,
2388 (int) NCR53c7x0_read8(SDID_REG_800
) &7);
2390 printk ("scsi%d : selected by target LCRC=0x%02x\n", host
->host_no
,
2391 (int) NCR53c7x0_read8(LCRC_REG_10
));
2392 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_target_abort
/
2394 hostdata
->dsp_changed
= 1;
2395 return SPECIFIC_INT_NOTHING
;
2396 case A_int_err_unexpected_reselect
:
2397 if ((hostdata
->chip
/ 100) == 8)
2398 printk ("scsi%d : unexpected reselect by target %d lun %d\n",
2399 host
->host_no
, (int) NCR53c7x0_read8(SDID_REG_800
) & 7,
2400 hostdata
->reselected_identify
& 7);
2402 printk ("scsi%d : unexpected reselect LCRC=0x%02x\n", host
->host_no
,
2403 (int) NCR53c7x0_read8(LCRC_REG_10
));
2404 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_initiator_abort
/
2406 hostdata
->dsp_changed
= 1;
2407 return SPECIFIC_INT_NOTHING
;
2409 * Since contingent allegiance conditions are cleared by the next
2410 * command issued to a target, we must issue a REQUEST SENSE
2411 * command after receiving a CHECK CONDITION status, before
2412 * another command is issued.
2414 * Since this NCR53c7x0_cmd will be freed after use, we don't
2415 * care if we step on the various fields, so modify a few things.
2417 case A_int_err_check_condition
:
2419 if (hostdata
->options
& OPTION_DEBUG_INTR
)
2421 printk ("scsi%d : CHECK CONDITION\n", host
->host_no
);
2423 printk("scsi%d : CHECK CONDITION with no SCSI command\n",
2425 return SPECIFIC_INT_PANIC
;
2429 * FIXME : this uses the normal one-byte selection message.
2430 * We may want to renegotiate for synchronous & WIDE transfers
2431 * since these could be the crux of our problem.
2433 hostdata->NOP_insn* FIXME : once SCSI-II tagged queuing is implemented, we'll
2434 * have to set this up so that the rest of the DSA
2435 * agrees with this being an untagged queue'd command.
2438 patch_dsa_32 (cmd
->dsa
, dsa_msgout
, 0, 1);
2441 * Modify the table indirect for COMMAND OUT phase, since
2442 * Request Sense is a six byte command.
2445 patch_dsa_32 (cmd
->dsa
, dsa_cmdout
, 0, 6);
2448 * The CDB is now mirrored in our local non-cached
2449 * structure, but keep the old structure up to date as well,
2450 * just in case anyone looks at it.
2454 * XXX Need to worry about data buffer alignment/cache state
2455 * XXX here, but currently never get A_int_err_check_condition,
2456 * XXX so ignore problem for now.
2458 cmd
->cmnd
[0] = c
->cmnd
[0] = REQUEST_SENSE
;
2459 cmd
->cmnd
[0] = c
->cmnd
[1] &= 0xe0; /* Zero all but LUN */
2460 cmd
->cmnd
[0] = c
->cmnd
[2] = 0;
2461 cmd
->cmnd
[0] = c
->cmnd
[3] = 0;
2462 cmd
->cmnd
[0] = c
->cmnd
[4] = sizeof(c
->sense_buffer
);
2463 cmd
->cmnd
[0] = c
->cmnd
[5] = 0;
2466 * Disable dataout phase, and program datain to transfer to the
2467 * sense buffer, and add a jump to other_transfer after the
2468 * command so overflow/underrun conditions are detected.
2471 patch_dsa_32 (cmd
->dsa
, dsa_dataout
, 0,
2472 virt_to_bus(hostdata
->script
) + hostdata
->E_other_transfer
);
2473 patch_dsa_32 (cmd
->dsa
, dsa_datain
, 0,
2474 virt_to_bus(cmd
->data_transfer_start
));
2475 cmd
->data_transfer_start
[0] = (((DCMD_TYPE_BMI
| DCMD_BMI_OP_MOVE_I
|
2476 DCMD_BMI_IO
)) << 24) | sizeof(c
->sense_buffer
);
2477 cmd
->data_transfer_start
[1] = (u32
) virt_to_bus(c
->sense_buffer
);
2479 cmd
->data_transfer_start
[2] = ((DCMD_TYPE_TCI
| DCMD_TCI_OP_JUMP
)
2480 << 24) | DBC_TCI_TRUE
;
2481 cmd
->data_transfer_start
[3] = (u32
) virt_to_bus(hostdata
->script
) +
2482 hostdata
->E_other_transfer
;
2485 * Currently, this command is flagged as completed, ie
2486 * it has valid status and message data. Reflag it as
2487 * incomplete. Q - need to do something so that original
2488 * status, etc are used.
2491 cmd
->result
= cmd
->cmd
->result
= 0xffff;
2494 * Restart command as a REQUEST SENSE.
2496 hostdata
->dsp
= (u32
*) hostdata
->script
+ hostdata
->E_select
/
2498 hostdata
->dsp_changed
= 1;
2499 return SPECIFIC_INT_NOTHING
;
2500 case A_int_debug_break
:
2501 return SPECIFIC_INT_BREAK
;
2502 case A_int_norm_aborted
:
2503 hostdata
->dsp
= (u32
*) hostdata
->schedule
;
2504 hostdata
->dsp_changed
= 1;
2506 abnormal_finished (cmd
, DID_ERROR
<< 16);
2507 return SPECIFIC_INT_NOTHING
;
2508 case A_int_norm_emulateintfly
:
2509 NCR53c7x0_intfly(host
);
2510 return SPECIFIC_INT_NOTHING
;
2514 hostdata
->test_completed
= (dsps
- A_int_test_1
) / 0x00010000 + 1;
2515 if (hostdata
->options
& OPTION_DEBUG_INTR
)
2516 printk("scsi%d : test%d complete\n", host
->host_no
,
2517 hostdata
->test_completed
);
2518 return SPECIFIC_INT_NOTHING
;
2519 #ifdef A_int_debug_reselected_ok
2520 case A_int_debug_reselected_ok
:
2521 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
|
2522 OPTION_DEBUG_DISCONNECT
)) {
2524 * Note - this dsa is not based on location relative to
2525 * the command structure, but to location relative to the
2529 dsa
= (u32
*) bus_to_virt (NCR53c7x0_read32(DSA_REG
));
2531 printk("scsi%d : reselected_ok (DSA = 0x%x (virt 0x%p)\n",
2532 host
->host_no
, NCR53c7x0_read32(DSA_REG
), dsa
);
2533 printk("scsi%d : resume address is 0x%x (virt 0x%p)\n",
2534 host
->host_no
, cmd
->saved_data_pointer
,
2535 bus_to_virt(cmd
->saved_data_pointer
));
2536 print_insn (host
, hostdata
->script
+ Ent_reselected_ok
/
2537 sizeof(u32
), "", 1);
2538 if ((hostdata
->chip
/ 100) == 8)
2539 printk ("scsi%d : sxfer=0x%x, scntl3=0x%x\n",
2540 host
->host_no
, NCR53c7x0_read8(SXFER_REG
),
2541 NCR53c7x0_read8(SCNTL3_REG_800
));
2543 printk ("scsi%d : sxfer=0x%x, cannot read SBCL\n",
2544 host
->host_no
, NCR53c7x0_read8(SXFER_REG
));
2546 print_insn (host
, (u32
*)
2547 hostdata
->sync
[c
->target
].script
, "", 1);
2548 print_insn (host
, (u32
*)
2549 hostdata
->sync
[c
->target
].script
+ 2, "", 1);
2552 return SPECIFIC_INT_RESTART
;
2554 #ifdef A_int_debug_reselect_check
2555 case A_int_debug_reselect_check
:
2556 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
)) {
2562 * Note - this dsa is not based on location relative to
2563 * the command structure, but to location relative to the
2566 dsa
= bus_to_virt (NCR53c7x0_read32(DSA_REG
));
2567 printk("scsi%d : reselected_check_next (DSA = 0x%lx (virt 0x%p))\n",
2568 host
->host_no
, virt_to_bus(dsa
), dsa
);
2570 printk("scsi%d : resume address is 0x%x (virt 0x%p)\n",
2571 host
->host_no
, cmd
->saved_data_pointer
,
2572 bus_to_virt (cmd
->saved_data_pointer
));
2574 printk("scsi%d : template code :\n", host
->host_no
);
2575 for (code
= dsa
+ (Ent_dsa_code_check_reselect
- Ent_dsa_zero
)
2576 / sizeof(u32
); code
< (dsa
+ Ent_dsa_zero
/ sizeof(u32
));
2577 code
+= print_insn (host
, code
, "", 1));
2580 print_insn (host
, hostdata
->script
+ Ent_reselected_ok
/
2581 sizeof(u32
), "", 1);
2583 return SPECIFIC_INT_RESTART
;
2585 #ifdef A_int_debug_dsa_schedule
2586 case A_int_debug_dsa_schedule
:
2587 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
)) {
2590 * Note - this dsa is not based on location relative to
2591 * the command structure, but to location relative to the
2594 dsa
= (u32
*) bus_to_virt (NCR53c7x0_read32(DSA_REG
));
2595 printk("scsi%d : dsa_schedule (old DSA = 0x%lx (virt 0x%p))\n",
2596 host
->host_no
, virt_to_bus(dsa
), dsa
);
2598 printk("scsi%d : resume address is 0x%x (virt 0x%p)\n"
2599 " (temp was 0x%x (virt 0x%p))\n",
2600 host
->host_no
, cmd
->saved_data_pointer
,
2601 bus_to_virt (cmd
->saved_data_pointer
),
2602 NCR53c7x0_read32 (TEMP_REG
),
2603 bus_to_virt (NCR53c7x0_read32(TEMP_REG
)));
2605 return SPECIFIC_INT_RESTART
;
2607 #ifdef A_int_debug_scheduled
2608 case A_int_debug_scheduled
:
2609 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
)) {
2610 printk("scsi%d : new I/O 0x%x (virt 0x%p) scheduled\n",
2611 host
->host_no
, NCR53c7x0_read32(DSA_REG
),
2612 bus_to_virt(NCR53c7x0_read32(DSA_REG
)));
2614 return SPECIFIC_INT_RESTART
;
2616 #ifdef A_int_debug_idle
2617 case A_int_debug_idle
:
2618 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
)) {
2619 printk("scsi%d : idle\n", host
->host_no
);
2621 return SPECIFIC_INT_RESTART
;
2623 #ifdef A_int_debug_cmd
2624 case A_int_debug_cmd
:
2625 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
)) {
2626 printk("scsi%d : command sent\n");
2628 return SPECIFIC_INT_RESTART
;
2630 #ifdef A_int_debug_dsa_loaded
2631 case A_int_debug_dsa_loaded
:
2632 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
)) {
2633 printk("scsi%d : DSA loaded with 0x%x (virt 0x%p)\n", host
->host_no
,
2634 NCR53c7x0_read32(DSA_REG
),
2635 bus_to_virt(NCR53c7x0_read32(DSA_REG
)));
2637 return SPECIFIC_INT_RESTART
;
2639 #ifdef A_int_debug_reselected
2640 case A_int_debug_reselected
:
2641 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
|
2642 OPTION_DEBUG_DISCONNECT
)) {
2643 if ((hostdata
->chip
/ 100) == 8)
2644 printk("scsi%d : reselected by target %d lun %d\n",
2645 host
->host_no
, (int) NCR53c7x0_read8(SDID_REG_800
) & ~0x80,
2646 (int) hostdata
->reselected_identify
& 7);
2648 printk("scsi%d : reselected by LCRC=0x%02x lun %d\n",
2649 host
->host_no
, (int) NCR53c7x0_read8(LCRC_REG_10
),
2650 (int) hostdata
->reselected_identify
& 7);
2653 return SPECIFIC_INT_RESTART
;
2655 #ifdef A_int_debug_disconnect_msg
2656 case A_int_debug_disconnect_msg
:
2657 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
)) {
2659 printk("scsi%d : target %d lun %d disconnecting\n",
2660 host
->host_no
, c
->target
, c
->lun
);
2662 printk("scsi%d : unknown target disconnecting\n",
2665 return SPECIFIC_INT_RESTART
;
2667 #ifdef A_int_debug_disconnected
2668 case A_int_debug_disconnected
:
2669 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
|
2670 OPTION_DEBUG_DISCONNECT
)) {
2671 printk ("scsi%d : disconnected, new queues are\n",
2675 /* Not valid on ncr53c710! */
2676 printk ("scsi%d : sxfer=0x%x, scntl3=0x%x\n",
2677 host
->host_no
, NCR53c7x0_read8(SXFER_REG
),
2678 NCR53c7x0_read8(SCNTL3_REG_800
));
2681 print_insn (host
, (u32
*)
2682 hostdata
->sync
[c
->target
].script
, "", 1);
2683 print_insn (host
, (u32
*)
2684 hostdata
->sync
[c
->target
].script
+ 2, "", 1);
2687 return SPECIFIC_INT_RESTART
;
2689 #ifdef A_int_debug_panic
2690 case A_int_debug_panic
:
2691 printk("scsi%d : int_debug_panic received\n", host
->host_no
);
2693 return SPECIFIC_INT_PANIC
;
2695 #ifdef A_int_debug_saved
2696 case A_int_debug_saved
:
2697 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
|
2698 OPTION_DEBUG_DISCONNECT
)) {
2699 printk ("scsi%d : saved data pointer 0x%x (virt 0x%p)\n",
2700 host
->host_no
, cmd
->saved_data_pointer
,
2701 bus_to_virt (cmd
->saved_data_pointer
));
2704 return SPECIFIC_INT_RESTART
;
2706 #ifdef A_int_debug_restored
2707 case A_int_debug_restored
:
2708 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
|
2709 OPTION_DEBUG_DISCONNECT
)) {
2712 printk ("scsi%d : restored data pointer 0x%x (virt 0x%p)\n",
2713 host
->host_no
, cmd
->saved_data_pointer
, bus_to_virt (
2714 cmd
->saved_data_pointer
));
2715 size
= print_insn (host
, (u32
*)
2716 bus_to_virt(cmd
->saved_data_pointer
), "", 1);
2717 size
= print_insn (host
, (u32
*)
2718 bus_to_virt(cmd
->saved_data_pointer
) + size
, "", 1);
2722 printk ("scsi%d : datapath residual %d\n",
2723 host
->host_no
, datapath_residual (host
)) ;
2726 return SPECIFIC_INT_RESTART
;
2728 #ifdef A_int_debug_sync
2729 case A_int_debug_sync
:
2730 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
|
2731 OPTION_DEBUG_DISCONNECT
|OPTION_DEBUG_SDTR
)) {
2732 unsigned char sxfer
= NCR53c7x0_read8 (SXFER_REG
), scntl3
;
2733 if ((hostdata
->chip
/ 100) == 8) {
2734 scntl3
= NCR53c7x0_read8 (SCNTL3_REG_800
);
2736 if (sxfer
!= hostdata
->sync
[c
->target
].sxfer_sanity
||
2737 scntl3
!= hostdata
->sync
[c
->target
].scntl3_sanity
) {
2738 printk ("scsi%d : sync sanity check failed sxfer=0x%x, scntl3=0x%x",
2739 host
->host_no
, sxfer
, scntl3
);
2740 NCR53c7x0_write8 (SXFER_REG
, sxfer
);
2741 NCR53c7x0_write8 (SCNTL3_REG_800
, scntl3
);
2744 printk ("scsi%d : unknown command sxfer=0x%x, scntl3=0x%x\n",
2745 host
->host_no
, (int) sxfer
, (int) scntl3
);
2748 if (sxfer
!= hostdata
->sync
[c
->target
].sxfer_sanity
) {
2749 printk ("scsi%d : sync sanity check failed sxfer=0x%x",
2750 host
->host_no
, sxfer
);
2751 NCR53c7x0_write8 (SXFER_REG
, sxfer
);
2752 NCR53c7x0_write8 (SBCL_REG
,
2753 hostdata
->sync
[c
->target
].sscf_710
);
2756 printk ("scsi%d : unknown command sxfer=0x%x\n",
2757 host
->host_no
, (int) sxfer
);
2760 return SPECIFIC_INT_RESTART
;
2762 #ifdef A_int_debug_datain
2763 case A_int_debug_datain
:
2764 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
|
2765 OPTION_DEBUG_DISCONNECT
|OPTION_DEBUG_SDTR
)) {
2767 if ((hostdata
->chip
/ 100) == 8)
2768 printk ("scsi%d : In do_datain (%s) sxfer=0x%x, scntl3=0x%x\n"
2769 " datapath residual=%d\n",
2770 host
->host_no
, sbcl_to_phase (NCR53c7x0_read8 (SBCL_REG
)),
2771 (int) NCR53c7x0_read8(SXFER_REG
),
2772 (int) NCR53c7x0_read8(SCNTL3_REG_800
),
2773 datapath_residual (host
)) ;
2775 printk ("scsi%d : In do_datain (%s) sxfer=0x%x\n"
2776 " datapath residual=%d\n",
2777 host
->host_no
, sbcl_to_phase (NCR53c7x0_read8 (SBCL_REG
)),
2778 (int) NCR53c7x0_read8(SXFER_REG
),
2779 datapath_residual (host
)) ;
2780 print_insn (host
, dsp
, "", 1);
2781 size
= print_insn (host
, (u32
*) bus_to_virt(dsp
[1]), "", 1);
2782 print_insn (host
, (u32
*) bus_to_virt(dsp
[1]) + size
, "", 1);
2784 return SPECIFIC_INT_RESTART
;
2786 #ifdef A_int_debug_check_dsa
2787 case A_int_debug_check_dsa
:
2788 if (NCR53c7x0_read8 (SCNTL1_REG
) & SCNTL1_CON
) {
2792 if (hostdata
->chip
/ 100 == 8)
2793 sdid
= NCR53c7x0_read8 (SDID_REG_800
) & 15;
2795 tmp
= NCR53c7x0_read8 (SDID_REG_700
);
2797 panic ("SDID_REG_700 = 0");
2805 where
= dsp
- NCR53c7x0_insn_size(NCR53c7x0_read8
2806 (DCMD_REG
)) == hostdata
->script
+
2807 Ent_select_check_dsa
/ sizeof(u32
) ?
2808 "selection" : "reselection";
2809 if (c
&& sdid
!= c
->target
) {
2810 printk ("scsi%d : SDID target %d != DSA target %d at %s\n",
2811 host
->host_no
, sdid
, c
->target
, where
);
2813 dump_events (host
, 20);
2814 return SPECIFIC_INT_PANIC
;
2817 return SPECIFIC_INT_RESTART
;
2820 if ((dsps
& 0xff000000) == 0x03000000) {
2821 printk ("scsi%d : misc debug interrupt 0x%x\n",
2822 host
->host_no
, dsps
);
2823 return SPECIFIC_INT_RESTART
;
2824 } else if ((dsps
& 0xff000000) == 0x05000000) {
2825 if (hostdata
->events
) {
2826 struct NCR53c7x0_event
*event
;
2827 ++hostdata
->event_index
;
2828 if (hostdata
->event_index
>= hostdata
->event_size
)
2829 hostdata
->event_index
= 0;
2830 event
= (struct NCR53c7x0_event
*) hostdata
->events
+
2831 hostdata
->event_index
;
2832 event
->event
= (enum ncr_event
) dsps
;
2833 event
->dsa
= bus_to_virt(NCR53c7x0_read32(DSA_REG
));
2834 if (NCR53c7x0_read8 (SCNTL1_REG
) & SCNTL1_CON
) {
2835 if (hostdata
->chip
/ 100 == 8)
2836 event
->target
= NCR53c7x0_read8(SSID_REG_800
);
2838 unsigned char tmp
, sdid
;
2839 tmp
= NCR53c7x0_read8 (SDID_REG_700
);
2841 panic ("SDID_REG_700 = 0");
2848 event
->target
= sdid
;
2852 event
->target
= 255;
2854 if (event
->event
== EVENT_RESELECT
)
2855 event
->lun
= hostdata
->reselected_identify
& 0xf;
2857 event
->lun
= c
->lun
;
2860 do_gettimeofday(&(event
->time
));
2862 event
->pid
= c
->pid
;
2863 memcpy ((void *) event
->cmnd
, (void *) c
->cmnd
,
2864 sizeof (event
->cmnd
));
2869 return SPECIFIC_INT_RESTART
;
2872 printk ("scsi%d : unknown user interrupt 0x%x\n",
2873 host
->host_no
, (unsigned) dsps
);
2874 return SPECIFIC_INT_PANIC
;
2879 * XXX - the stock NCR assembler won't output the scriptu.h file,
2880 * which undefine's all #define'd CPP symbols from the script.h
2881 * file, which will create problems if you use multiple scripts
2882 * with the same symbol names.
2884 * If you insist on using NCR's assembler, you could generate
2885 * scriptu.h from script.h using something like
2887 * grep #define script.h | \
2888 * sed 's/#define[ ][ ]*\([_a-zA-Z][_a-zA-Z0-9]*\).*$/#undefine \1/' \
2892 #include "53c7xx_u.h"
2894 /* XXX - add alternate script handling code here */
2898 * Function : static void NCR537xx_soft_reset (struct Scsi_Host *host)
2900 * Purpose : perform a soft reset of the NCR53c7xx chip
2902 * Inputs : host - pointer to this host adapter's structure
2904 * Preconditions : NCR53c7x0_init must have been called for this
2910 NCR53c7x0_soft_reset (struct Scsi_Host
*host
) {
2911 NCR53c7x0_local_declare();
2912 unsigned long flags
;
2913 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
2915 NCR53c7x0_local_setup(host
);
2920 /* Disable scsi chip and s/w level 7 ints */
2922 #ifdef CONFIG_MVME16x
2923 if (MACH_IS_MVME16x
)
2925 volatile unsigned long v
;
2927 v
= *(volatile unsigned long *)0xfff4006c;
2929 *(volatile unsigned long *)0xfff4006c = v
;
2930 v
= *(volatile unsigned long *)0xfff4202c;
2932 *(volatile unsigned long *)0xfff4202c = v
;
2935 /* Anything specific for your hardware? */
2938 * Do a soft reset of the chip so that everything is
2939 * reinitialized to the power-on state.
2941 * Basically follow the procedure outlined in the NCR53c700
2942 * data manual under Chapter Six, How to Use, Steps Necessary to
2943 * Start SCRIPTS, with the exception of actually starting the
2944 * script and setting up the synchronous transfer gunk.
2947 /* Should we reset the scsi bus here??????????????????? */
2949 NCR53c7x0_write8(ISTAT_REG_700
, ISTAT_10_SRST
);
2950 NCR53c7x0_write8(ISTAT_REG_700
, 0);
2953 * saved_dcntl is set up in NCR53c7x0_init() before it is overwritten
2954 * here. We should have some better way of working out the CF bit
2958 hostdata
->saved_dcntl
= DCNTL_10_EA
|DCNTL_10_COM
;
2959 if (hostdata
->scsi_clock
> 50000000)
2960 hostdata
->saved_dcntl
|= DCNTL_700_CF_3
;
2962 if (hostdata
->scsi_clock
> 37500000)
2963 hostdata
->saved_dcntl
|= DCNTL_700_CF_2
;
2966 /* Any clocks less than 37.5MHz? */
2969 if (hostdata
->options
& OPTION_DEBUG_TRACE
)
2970 NCR53c7x0_write8(DCNTL_REG
, hostdata
->saved_dcntl
| DCNTL_SSM
);
2972 NCR53c7x0_write8(DCNTL_REG
, hostdata
->saved_dcntl
);
2973 /* Following disables snooping - snooping is not required, as non-
2974 * cached pages are used for shared data, and appropriate use is
2975 * made of cache_push/cache_clear. Indeed, for 68060
2976 * enabling snooping causes disk corruption of ext2fs free block
2977 * bitmaps and the like. If you have a 68060 with snooping hardwared
2978 * on, then you need to enable CONFIG_060_WRITETHROUGH.
2980 NCR53c7x0_write8(CTEST7_REG
, CTEST7_10_TT1
|CTEST7_STD
);
2981 /* Actually burst of eight, according to my 53c710 databook */
2982 NCR53c7x0_write8(hostdata
->dmode
, DMODE_10_BL_8
| DMODE_10_FC2
);
2983 NCR53c7x0_write8(SCID_REG
, 1 << host
->this_id
);
2984 NCR53c7x0_write8(SBCL_REG
, 0);
2985 NCR53c7x0_write8(SCNTL1_REG
, SCNTL1_ESR_700
);
2986 NCR53c7x0_write8(SCNTL0_REG
, ((hostdata
->options
& OPTION_PARITY
) ?
2987 SCNTL0_EPC
: 0) | SCNTL0_EPG_700
| SCNTL0_ARB1
| SCNTL0_ARB2
);
2990 * Enable all interrupts, except parity which we only want when
2991 * the user requests it.
2994 NCR53c7x0_write8(DIEN_REG
, DIEN_700_BF
|
2995 DIEN_ABRT
| DIEN_SSI
| DIEN_SIR
| DIEN_700_OPC
);
2997 NCR53c7x0_write8(SIEN_REG_700
, ((hostdata
->options
& OPTION_PARITY
) ?
2998 SIEN_PAR
: 0) | SIEN_700_STO
| SIEN_RST
| SIEN_UDC
|
2999 SIEN_SGE
| SIEN_MA
);
3001 #ifdef CONFIG_MVME16x
3002 if (MACH_IS_MVME16x
)
3004 volatile unsigned long v
;
3006 /* Enable scsi chip and s/w level 7 ints */
3007 v
= *(volatile unsigned long *)0xfff40080;
3008 v
= (v
& ~(0xf << 28)) | (4 << 28);
3009 *(volatile unsigned long *)0xfff40080 = v
;
3010 v
= *(volatile unsigned long *)0xfff4006c;
3012 *(volatile unsigned long *)0xfff4006c = v
;
3013 v
= *(volatile unsigned long *)0xfff4202c;
3014 v
= (v
& ~0xff) | 0x10 | 4;
3015 *(volatile unsigned long *)0xfff4202c = v
;
3018 /* Anything needed for your hardware? */
3019 restore_flags(flags
);
3024 * Function static struct NCR53c7x0_cmd *allocate_cmd (Scsi_Cmnd *cmd)
3026 * Purpose : Return the first free NCR53c7x0_cmd structure (which are
3027 * reused in a LIFO manner to minimize cache thrashing).
3029 * Side effects : If we haven't yet scheduled allocation of NCR53c7x0_cmd
3030 * structures for this device, do so. Attempt to complete all scheduled
3031 * allocations using get_free_page(), putting NCR53c7x0_cmd structures on
3032 * the free list. Teach programmers not to drink and hack.
3034 * Inputs : cmd - SCSI command
3036 * Returns : NCR53c7x0_cmd structure allocated on behalf of cmd;
3041 my_free_page (void *addr
, int dummy
)
3043 /* XXX This assumes default cache mode to be IOMAP_FULL_CACHING, which
3044 * XXX may be invalid (CONFIG_060_WRITETHROUGH)
3046 kernel_set_cachemode((u32
)addr
, 4096, IOMAP_FULL_CACHING
);
3047 free_page ((u32
)addr
);
3050 static struct NCR53c7x0_cmd
*
3051 allocate_cmd (Scsi_Cmnd
*cmd
) {
3052 struct Scsi_Host
*host
= cmd
->host
;
3053 struct NCR53c7x0_hostdata
*hostdata
=
3054 (struct NCR53c7x0_hostdata
*) host
->hostdata
[0];
3055 u32 real
; /* Real address */
3056 int size
; /* Size of *tmp */
3057 struct NCR53c7x0_cmd
*tmp
;
3058 unsigned long flags
;
3060 if (hostdata
->options
& OPTION_DEBUG_ALLOCATION
)
3061 printk ("scsi%d : num_cmds = %d, can_queue = %d\n"
3062 " target = %d, lun = %d, %s\n",
3063 host
->host_no
, hostdata
->num_cmds
, host
->can_queue
,
3064 cmd
->target
, cmd
->lun
, (hostdata
->cmd_allocated
[cmd
->target
] &
3065 (1 << cmd
->lun
)) ? "already allocated" : "not allocated");
3068 * If we have not yet reserved commands for this I_T_L nexus, and
3069 * the device exists (as indicated by permanent Scsi_Cmnd structures
3070 * being allocated under 1.3.x, or being outside of scan_scsis in
3071 * 1.2.x), do so now.
3073 if (!(hostdata
->cmd_allocated
[cmd
->target
] & (1 << cmd
->lun
)) &&
3074 cmd
->device
&& cmd
->device
->has_cmdblocks
) {
3075 if ((hostdata
->extra_allocate
+ hostdata
->num_cmds
) < host
->can_queue
)
3076 hostdata
->extra_allocate
+= host
->cmd_per_lun
;
3077 hostdata
->cmd_allocated
[cmd
->target
] |= (1 << cmd
->lun
);
3080 for (; hostdata
->extra_allocate
> 0 ; --hostdata
->extra_allocate
,
3081 ++hostdata
->num_cmds
) {
3082 /* historically, kmalloc has returned unaligned addresses; pad so we
3083 have enough room to ROUNDUP */
3084 size
= hostdata
->max_cmd_size
+ sizeof (void *);
3085 #ifdef FORCE_DSA_ALIGNMENT
3087 * 53c710 rev.0 doesn't have an add-with-carry instruction.
3088 * Ensure we allocate enough memory to force alignment.
3092 /* FIXME: for ISA bus '7xx chips, we need to or GFP_DMA in here */
3095 panic ("53c7xx: allocate_cmd size > 4K");
3096 real
= get_free_page(GFP_ATOMIC
);
3099 memset((void *)real
, 0, 4096);
3100 cache_push(virt_to_phys((void *)real
), 4096);
3101 cache_clear(virt_to_phys((void *)real
), 4096);
3102 kernel_set_cachemode(real
, 4096, IOMAP_NOCACHE_SER
);
3103 tmp
= ROUNDUP(real
, void *);
3104 #ifdef FORCE_DSA_ALIGNMENT
3106 if (((u32
)tmp
& 0xff) > CmdPageStart
)
3107 tmp
= (struct NCR53c7x0_cmd
*)((u32
)tmp
+ 255);
3108 tmp
= (struct NCR53c7x0_cmd
*)(((u32
)tmp
& ~0xff) + CmdPageStart
);
3110 printk ("scsi: size = %d, real = 0x%08x, tmp set to 0x%08x\n",
3111 size
, real
, (u32
)tmp
);
3115 tmp
->real
= (void *)real
;
3117 tmp
->free
= ((void (*)(void *, int)) my_free_page
);
3120 tmp
->next
= hostdata
->free
;
3121 hostdata
->free
= tmp
;
3122 restore_flags (flags
);
3126 tmp
= (struct NCR53c7x0_cmd
*) hostdata
->free
;
3128 hostdata
->free
= tmp
->next
;
3130 restore_flags(flags
);
3132 printk ("scsi%d : can't allocate command for target %d lun %d\n",
3133 host
->host_no
, cmd
->target
, cmd
->lun
);
3138 * Function static struct NCR53c7x0_cmd *create_cmd (Scsi_Cmnd *cmd)
3141 * Purpose : allocate a NCR53c7x0_cmd structure, initialize it based on the
3142 * Scsi_Cmnd structure passed in cmd, including dsa and Linux field
3143 * initialization, and dsa code relocation.
3145 * Inputs : cmd - SCSI command
3147 * Returns : NCR53c7x0_cmd structure corresponding to cmd,
3150 static struct NCR53c7x0_cmd
*
3151 create_cmd (Scsi_Cmnd
*cmd
) {
3152 NCR53c7x0_local_declare();
3153 struct Scsi_Host
*host
= cmd
->host
;
3154 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
3156 struct NCR53c7x0_cmd
*tmp
; /* NCR53c7x0_cmd structure for this command */
3157 int datain
, /* Number of instructions per phase */
3159 int data_transfer_instructions
, /* Count of dynamic instructions */
3161 u32
*cmd_datain
, /* Address of datain/dataout code */
3162 *cmd_dataout
; /* Incremented as we assemble */
3164 unsigned char *msgptr
; /* Current byte in select message */
3165 int msglen
; /* Length of whole select message */
3167 unsigned long flags
;
3168 u32 exp_select_indirect
; /* Used in sanity check */
3169 NCR53c7x0_local_setup(cmd
->host
);
3171 if (!(tmp
= allocate_cmd (cmd
)))
3175 * Copy CDB and initialised result fields from Scsi_Cmnd to NCR53c7x0_cmd.
3176 * We do this because NCR53c7x0_cmd may have a special cache mode
3177 * selected to cope with lack of bus snooping, etc.
3180 memcpy(tmp
->cmnd
, cmd
->cmnd
, 12);
3181 tmp
->result
= cmd
->result
;
3184 * Decide whether we need to generate commands for DATA IN,
3185 * DATA OUT, neither, or both based on the SCSI command
3188 switch (cmd
->cmnd
[0]) {
3189 /* These commands do DATA IN */
3196 case READ_BLOCK_LIMITS
:
3198 datain
= 2 * (cmd
->use_sg
? cmd
->use_sg
: 1) + 3;
3201 /* These commands do DATA OUT */
3206 printk("scsi%d : command is ", host
->host_no
);
3207 print_command(cmd
->cmnd
);
3210 printk ("scsi%d : %d scatter/gather segments\n", host
->host_no
,
3214 dataout
= 2 * (cmd
->use_sg
? cmd
->use_sg
: 1) + 3;
3216 hostdata
->options
|= OPTION_DEBUG_INTR
;
3220 * These commands do no data transfer, we should force an
3221 * interrupt if a data phase is attempted on them.
3223 case TEST_UNIT_READY
:
3224 case ALLOW_MEDIUM_REMOVAL
:
3226 datain
= dataout
= 0;
3229 * We don't know about these commands, so generate code to handle
3230 * both DATA IN and DATA OUT phases. More efficient to identify them
3231 * and add them to the above cases.
3234 printk("scsi%d : datain+dataout for command ", host
->host_no
);
3235 print_command(cmd
->cmnd
);
3236 datain
= dataout
= 2 * (cmd
->use_sg
? cmd
->use_sg
: 1) + 3;
3240 * New code : so that active pointers work correctly regardless
3241 * of where the saved data pointer is at, we want to immediately
3242 * enter the dynamic code after selection, and on a non-data
3243 * phase perform a CALL to the non-data phase handler, with
3244 * returns back to this address.
3246 * If a phase mismatch is encountered in the middle of a
3247 * Block MOVE instruction, we want to _leave_ that instruction
3248 * unchanged as the current case is, modify a temporary buffer,
3249 * and point the active pointer (TEMP) at that.
3251 * Furthermore, we want to implement a saved data pointer,
3252 * set by the SAVE_DATA_POINTERs message.
3254 * So, the data transfer segments will change to
3255 * CALL data_transfer, WHEN NOT data phase
3256 * MOVE x, x, WHEN data phase
3258 * JUMP other_transfer
3261 data_transfer_instructions
= datain
+ dataout
;
3264 * When we perform a request sense, we overwrite various things,
3265 * including the data transfer code. Make sure we have enough
3269 if (data_transfer_instructions
< 2)
3270 data_transfer_instructions
= 2;
3274 * The saved data pointer is set up so that a RESTORE POINTERS message
3275 * will start the data transfer over at the begining.
3278 tmp
->saved_data_pointer
= virt_to_bus (hostdata
->script
) +
3279 hostdata
->E_data_transfer
;
3282 * Initialize Linux specific fields.
3288 tmp
->dsa_next_addr
= virt_to_bus(tmp
->dsa
) + hostdata
->dsa_next
-
3289 hostdata
->dsa_start
;
3290 tmp
->dsa_addr
= virt_to_bus(tmp
->dsa
) - hostdata
->dsa_start
;
3293 * Calculate addresses of dynamic code to fill in DSA
3296 tmp
->data_transfer_start
= tmp
->dsa
+ (hostdata
->dsa_end
-
3297 hostdata
->dsa_start
) / sizeof(u32
);
3298 tmp
->data_transfer_end
= tmp
->data_transfer_start
+
3299 2 * data_transfer_instructions
;
3301 cmd_datain
= datain
? tmp
->data_transfer_start
: NULL
;
3302 cmd_dataout
= dataout
? (datain
? cmd_datain
+ 2 * datain
: tmp
->
3303 data_transfer_start
) : NULL
;
3306 * Fill in the NCR53c7x0_cmd structure as follows
3307 * dsa, with fixed up DSA code
3312 /* Copy template code into dsa and perform all necessary fixups */
3313 if (hostdata
->dsa_fixup
)
3314 hostdata
->dsa_fixup(tmp
);
3316 patch_dsa_32(tmp
->dsa
, dsa_next
, 0, 0);
3318 * XXX is this giving 53c710 access to the Scsi_Cmnd in some way?
3319 * Do we need to change it for caching reasons?
3321 patch_dsa_32(tmp
->dsa
, dsa_cmnd
, 0, virt_to_bus(cmd
));
3323 if (hostdata
->options
& OPTION_DEBUG_SYNCHRONOUS
) {
3325 exp_select_indirect
= ((1 << cmd
->target
) << 16) |
3326 (hostdata
->sync
[cmd
->target
].sxfer_sanity
<< 8);
3328 if (hostdata
->sync
[cmd
->target
].select_indirect
!=
3329 exp_select_indirect
) {
3330 printk ("scsi%d : sanity check failed select_indirect=0x%x\n",
3331 host
->host_no
, hostdata
->sync
[cmd
->target
].select_indirect
);
3337 patch_dsa_32(tmp
->dsa
, dsa_select
, 0,
3338 hostdata
->sync
[cmd
->target
].select_indirect
);
3341 * Right now, we'll do the WIDE and SYNCHRONOUS negotiations on
3342 * different commands; although it should be trivial to do them
3343 * both at the same time.
3345 if (hostdata
->initiate_wdtr
& (1 << cmd
->target
)) {
3346 memcpy ((void *) (tmp
->select
+ 1), (void *) wdtr_message
,
3347 sizeof(wdtr_message
));
3348 patch_dsa_32(tmp
->dsa
, dsa_msgout
, 0, 1 + sizeof(wdtr_message
));
3351 hostdata
->initiate_wdtr
&= ~(1 << cmd
->target
);
3352 restore_flags(flags
);
3353 } else if (hostdata
->initiate_sdtr
& (1 << cmd
->target
)) {
3354 memcpy ((void *) (tmp
->select
+ 1), (void *) sdtr_message
,
3355 sizeof(sdtr_message
));
3356 patch_dsa_32(tmp
->dsa
, dsa_msgout
, 0, 1 + sizeof(sdtr_message
));
3357 tmp
->flags
|= CMD_FLAG_SDTR
;
3360 hostdata
->initiate_sdtr
&= ~(1 << cmd
->target
);
3361 restore_flags(flags
);
3365 else if (!(hostdata
->talked_to
& (1 << cmd
->target
)) &&
3366 !(hostdata
->options
& OPTION_NO_ASYNC
)) {
3368 memcpy ((void *) (tmp
->select
+ 1), (void *) async_message
,
3369 sizeof(async_message
));
3370 patch_dsa_32(tmp
->dsa
, dsa_msgout
, 0, 1 + sizeof(async_message
));
3371 tmp
->flags
|= CMD_FLAG_SDTR
;
3375 patch_dsa_32(tmp
->dsa
, dsa_msgout
, 0, 1);
3377 hostdata
->talked_to
|= (1 << cmd
->target
);
3378 tmp
->select
[0] = (hostdata
->options
& OPTION_DISCONNECT
) ?
3379 IDENTIFY (1, cmd
->lun
) : IDENTIFY (0, cmd
->lun
);
3380 patch_dsa_32(tmp
->dsa
, dsa_msgout
, 1, virt_to_bus(tmp
->select
));
3381 patch_dsa_32(tmp
->dsa
, dsa_cmdout
, 0, cmd
->cmd_len
);
3382 patch_dsa_32(tmp
->dsa
, dsa_cmdout
, 1, virt_to_bus(tmp
->cmnd
));
3383 patch_dsa_32(tmp
->dsa
, dsa_dataout
, 0, cmd_dataout
?
3384 virt_to_bus (cmd_dataout
)
3385 : virt_to_bus (hostdata
->script
) + hostdata
->E_other_transfer
);
3386 patch_dsa_32(tmp
->dsa
, dsa_datain
, 0, cmd_datain
?
3387 virt_to_bus (cmd_datain
)
3388 : virt_to_bus (hostdata
->script
) + hostdata
->E_other_transfer
);
3390 * XXX - need to make endian aware, should use separate variables
3391 * for both status and message bytes.
3393 patch_dsa_32(tmp
->dsa
, dsa_msgin
, 0, 1);
3395 * FIXME : these only works for little endian. We probably want to
3396 * provide message and status fields in the NCR53c7x0_cmd
3397 * structure, and assign them to cmd->result when we're done.
3400 patch_dsa_32(tmp
->dsa
, dsa_msgin
, 1, virt_to_bus(&tmp
->result
) + 2);
3401 patch_dsa_32(tmp
->dsa
, dsa_status
, 0, 1);
3402 patch_dsa_32(tmp
->dsa
, dsa_status
, 1, virt_to_bus(&tmp
->result
) + 3);
3404 patch_dsa_32(tmp
->dsa
, dsa_msgin
, 1, virt_to_bus(&tmp
->result
) + 1);
3405 patch_dsa_32(tmp
->dsa
, dsa_status
, 0, 1);
3406 patch_dsa_32(tmp
->dsa
, dsa_status
, 1, virt_to_bus(&tmp
->result
));
3408 patch_dsa_32(tmp
->dsa
, dsa_msgout_other
, 0, 1);
3409 patch_dsa_32(tmp
->dsa
, dsa_msgout_other
, 1,
3410 virt_to_bus(&(hostdata
->NCR53c7xx_msg_nop
)));
3413 * Generate code for zero or more of the DATA IN, DATA OUT phases
3416 * CALL data_transfer, WHEN NOT phase
3417 * MOVE first buffer length, first buffer address, WHEN phase
3419 * MOVE last buffer length, last buffer address, WHEN phase
3420 * JUMP other_transfer
3424 * See if we're getting to data transfer by generating an unconditional
3429 cmd_datain
[0] = 0x98080000;
3430 cmd_datain
[1] = 0x03ffd00d;
3436 * XXX - I'm undecided whether all of this nonsense is faster
3437 * in the long run, or whether I should just go and implement a loop
3438 * on the NCR chip using table indirect mode?
3440 * In any case, this is how it _must_ be done for 53c700/700-66 chips,
3441 * so this stays even when we come up with something better.
3443 * When we're limited to 1 simultaneous command, no overlapping processing,
3444 * we're seeing 630K/sec, with 7% CPU usage on a slow Syquest 45M
3447 * Not bad, not good. We'll see.
3450 tmp
->bounce
.len
= 0; /* Assume aligned buffer */
3452 for (i
= 0; cmd
->use_sg
? (i
< cmd
->use_sg
) : !i
; cmd_datain
+= 4,
3453 cmd_dataout
+= 4, ++i
) {
3454 u32 vbuf
= cmd
->use_sg
?
3455 (u32
)(((struct scatterlist
*)cmd
->buffer
)[i
].address
) :
3456 (u32
)(cmd
->request_buffer
);
3457 u32 bbuf
= virt_to_bus((void *)vbuf
);
3458 u32 count
= cmd
->use_sg
?
3459 ((struct scatterlist
*)cmd
->buffer
)[i
].length
:
3460 cmd
->request_bufflen
;
3463 * If we have buffers which are not aligned with 16 byte cache
3464 * lines, then we just hope nothing accesses the other parts of
3465 * those cache lines while the transfer is in progress. That would
3466 * fill the cache, and subsequent reads of the dma data would pick
3467 * up the wrong thing.
3468 * XXX We need a bounce buffer to handle that correctly.
3471 if (((bbuf
& 15) || (count
& 15)) && (datain
|| dataout
))
3473 /* Bounce buffer needed */
3475 printk ("53c7xx: Non-aligned buffer with use_sg\n");
3476 else if (datain
&& dataout
)
3477 printk ("53c7xx: Non-aligned buffer with datain && dataout\n");
3478 else if (count
> 256)
3479 printk ("53c7xx: Non-aligned transfer > 256 bytes\n");
3484 tmp
->bounce
.len
= count
;
3485 tmp
->bounce
.addr
= vbuf
;
3486 bbuf
= virt_to_bus(tmp
->bounce
.buf
);
3487 tmp
->bounce
.buf
[0] = 0xff;
3488 tmp
->bounce
.buf
[1] = 0xfe;
3489 tmp
->bounce
.buf
[2] = 0xfd;
3490 tmp
->bounce
.buf
[3] = 0xfc;
3494 memcpy ((void *)tmp
->bounce
.buf
, (void *)vbuf
, count
);
3495 bbuf
= virt_to_bus(tmp
->bounce
.buf
);
3501 cache_clear(virt_to_phys((void *)vbuf
), count
);
3502 /* CALL other_in, WHEN NOT DATA_IN */
3503 cmd_datain
[0] = ((DCMD_TYPE_TCI
| DCMD_TCI_OP_CALL
|
3504 DCMD_TCI_IO
) << 24) |
3505 DBC_TCI_WAIT_FOR_VALID
| DBC_TCI_COMPARE_PHASE
;
3506 cmd_datain
[1] = virt_to_bus (hostdata
->script
) +
3507 hostdata
->E_other_in
;
3508 /* MOVE count, buf, WHEN DATA_IN */
3509 cmd_datain
[2] = ((DCMD_TYPE_BMI
| DCMD_BMI_OP_MOVE_I
| DCMD_BMI_IO
)
3511 cmd_datain
[3] = bbuf
;
3513 print_insn (host
, cmd_datain
, "dynamic ", 1);
3514 print_insn (host
, cmd_datain
+ 2, "dynamic ", 1);
3518 cache_push(virt_to_phys((void *)vbuf
), count
);
3519 /* CALL other_out, WHEN NOT DATA_OUT */
3520 cmd_dataout
[0] = ((DCMD_TYPE_TCI
| DCMD_TCI_OP_CALL
) << 24) |
3521 DBC_TCI_WAIT_FOR_VALID
| DBC_TCI_COMPARE_PHASE
;
3522 cmd_dataout
[1] = virt_to_bus(hostdata
->script
) +
3523 hostdata
->E_other_out
;
3524 /* MOVE count, buf, WHEN DATA+OUT */
3525 cmd_dataout
[2] = ((DCMD_TYPE_BMI
| DCMD_BMI_OP_MOVE_I
) << 24)
3527 cmd_dataout
[3] = bbuf
;
3529 print_insn (host
, cmd_dataout
, "dynamic ", 1);
3530 print_insn (host
, cmd_dataout
+ 2, "dynamic ", 1);
3536 * Install JUMP instructions after the data transfer routines to return
3537 * control to the do_other_transfer routines.
3542 cmd_datain
[0] = ((DCMD_TYPE_TCI
| DCMD_TCI_OP_JUMP
) << 24) |
3544 cmd_datain
[1] = virt_to_bus(hostdata
->script
) +
3545 hostdata
->E_other_transfer
;
3547 print_insn (host
, cmd_datain
, "dynamic jump ", 1);
3553 cmd_datain
[0] = 0x98080000;
3554 cmd_datain
[1] = 0x03ffdeed;
3559 cmd_dataout
[0] = ((DCMD_TYPE_TCI
| DCMD_TCI_OP_JUMP
) << 24) |
3561 cmd_dataout
[1] = virt_to_bus(hostdata
->script
) +
3562 hostdata
->E_other_transfer
;
3564 print_insn (host
, cmd_dataout
, "dynamic jump ", 1);
3573 * Function : int NCR53c7xx_queue_command (Scsi_Cmnd *cmd,
3574 * void (*done)(Scsi_Cmnd *))
3576 * Purpose : enqueues a SCSI command
3578 * Inputs : cmd - SCSI command, done - function called on completion, with
3579 * a pointer to the command descriptor.
3584 * cmd is added to the per instance driver issue_queue, with major
3585 * twiddling done to the host specific fields of cmd. If the
3586 * process_issue_queue coroutine isn't running, it is restarted.
3588 * NOTE : we use the host_scribble field of the Scsi_Cmnd structure to
3589 * hold our own data, and pervert the ptr field of the SCp field
3590 * to create a linked list.
3594 NCR53c7xx_queue_command (Scsi_Cmnd
*cmd
, void (* done
)(Scsi_Cmnd
*)) {
3595 struct Scsi_Host
*host
= cmd
->host
;
3596 struct NCR53c7x0_hostdata
*hostdata
=
3597 (struct NCR53c7x0_hostdata
*) host
->hostdata
[0];
3598 unsigned long flags
;
3601 cmd
->scsi_done
= done
;
3602 cmd
->host_scribble
= NULL
;
3603 cmd
->SCp
.ptr
= NULL
;
3604 cmd
->SCp
.buffer
= NULL
;
3607 /* Ignore commands on invalid IDs */
3608 if (!hostdata
->valid_ids
[cmd
->target
]) {
3609 printk("scsi%d : ignoring target %d lun %d\n", host
->host_no
,
3610 cmd
->target
, cmd
->lun
);
3611 cmd
->result
= (DID_BAD_TARGET
<< 16);
3619 if ((hostdata
->options
& (OPTION_DEBUG_INIT_ONLY
|OPTION_DEBUG_PROBE_ONLY
))
3620 || ((hostdata
->options
& OPTION_DEBUG_TARGET_LIMIT
) &&
3621 !(hostdata
->debug_lun_limit
[cmd
->target
] & (1 << cmd
->lun
)))
3625 || cmd
->target
> host
->max_id
3627 || cmd
->target
== host
->this_id
3628 || hostdata
->state
== STATE_DISABLED
) {
3629 printk("scsi%d : disabled or bad target %d lun %d\n", host
->host_no
,
3630 cmd
->target
, cmd
->lun
);
3631 cmd
->result
= (DID_BAD_TARGET
<< 16);
3633 restore_flags (flags
);
3637 if ((hostdata
->options
& OPTION_DEBUG_NCOMMANDS_LIMIT
) &&
3638 (hostdata
->debug_count_limit
== 0)) {
3639 printk("scsi%d : maximum commands exceeded\n", host
->host_no
);
3640 cmd
->result
= (DID_BAD_TARGET
<< 16);
3642 restore_flags (flags
);
3646 if (hostdata
->options
& OPTION_DEBUG_READ_ONLY
) {
3647 switch (cmd
->cmnd
[0]) {
3650 printk("scsi%d : WRITE attempted with NO_WRITE debugging flag set\n",
3652 cmd
->result
= (DID_BAD_TARGET
<< 16);
3654 restore_flags (flags
);
3659 if ((hostdata
->options
& OPTION_DEBUG_TARGET_LIMIT
) &&
3660 hostdata
->debug_count_limit
!= -1)
3661 --hostdata
->debug_count_limit
;
3663 cmd
->result
= 0xffff; /* The NCR will overwrite message
3664 and status with valid data */
3665 cmd
->host_scribble
= (unsigned char *) tmp
= create_cmd (cmd
);
3668 * REQUEST SENSE commands are inserted at the head of the queue
3669 * so that we do not clear the contingent allegiance condition
3670 * they may be looking at.
3673 if (!(hostdata
->issue_queue
) || (cmd
->cmnd
[0] == REQUEST_SENSE
)) {
3674 cmd
->SCp
.ptr
= (unsigned char *) hostdata
->issue_queue
;
3675 hostdata
->issue_queue
= cmd
;
3677 for (tmp
= (Scsi_Cmnd
*) hostdata
->issue_queue
; tmp
->SCp
.ptr
;
3678 tmp
= (Scsi_Cmnd
*) tmp
->SCp
.ptr
);
3679 tmp
->SCp
.ptr
= (unsigned char *) cmd
;
3681 restore_flags (flags
);
3682 run_process_issue_queue();
3687 * Function : void to_schedule_list (struct Scsi_Host *host,
3688 * struct NCR53c7x0_hostdata * hostdata, Scsi_Cmnd *cmd)
3690 * Purpose : takes a SCSI command which was just removed from the
3691 * issue queue, and deals with it by inserting it in the first
3692 * free slot in the schedule list or by terminating it immediately.
3695 * host - SCSI host adapter; hostdata - hostdata structure for
3696 * this adapter; cmd - a pointer to the command; should have
3697 * the host_scribble field initialized to point to a valid
3700 * cmd is added to the per instance schedule list, with minor
3701 * twiddling done to the host specific fields of cmd.
3705 static __inline__
void
3706 to_schedule_list (struct Scsi_Host
*host
, struct NCR53c7x0_hostdata
*hostdata
,
3707 struct NCR53c7x0_cmd
*cmd
) {
3708 NCR53c7x0_local_declare();
3709 Scsi_Cmnd
*tmp
= cmd
->cmd
;
3710 unsigned long flags
;
3711 /* dsa start is negative, so subtraction is used */
3712 volatile u32
*ncrcurrent
;
3715 NCR53c7x0_local_setup(host
);
3717 printk("scsi%d : new dsa is 0x%lx (virt 0x%p)\n", host
->host_no
,
3718 virt_to_bus(hostdata
->dsa
), hostdata
->dsa
);
3725 * Work around race condition : if an interrupt fired and we
3726 * got disabled forget about this command.
3729 if (hostdata
->state
== STATE_DISABLED
) {
3730 printk("scsi%d : driver disabled\n", host
->host_no
);
3731 tmp
->result
= (DID_BAD_TARGET
<< 16);
3732 cmd
->next
= (struct NCR53c7x0_cmd
*) hostdata
->free
;
3733 hostdata
->free
= cmd
;
3734 tmp
->scsi_done(tmp
);
3735 restore_flags (flags
);
3739 for (i
= host
->can_queue
, ncrcurrent
= hostdata
->schedule
;
3740 i
> 0 && ncrcurrent
[0] != hostdata
->NOP_insn
;
3741 --i
, ncrcurrent
+= 2 /* JUMP instructions are two words */);
3744 ++hostdata
->busy
[tmp
->target
][tmp
->lun
];
3745 cmd
->next
= hostdata
->running_list
;
3746 hostdata
->running_list
= cmd
;
3748 /* Restore this instruction to a NOP once the command starts */
3749 cmd
->dsa
[(hostdata
->dsa_jump_dest
- hostdata
->dsa_start
) /
3750 sizeof(u32
)] = (u32
) virt_to_bus ((void *)ncrcurrent
);
3751 /* Replace the current jump operand. */
3753 virt_to_bus ((void *) cmd
->dsa
) + hostdata
->E_dsa_code_begin
-
3754 hostdata
->E_dsa_code_template
;
3755 /* Replace the NOP instruction with a JUMP */
3756 ncrcurrent
[0] = ((DCMD_TYPE_TCI
|DCMD_TCI_OP_JUMP
) << 24) |
3759 printk ("scsi%d: no free slot\n", host
->host_no
);
3761 tmp
->result
= (DID_ERROR
<< 16);
3762 cmd
->next
= (struct NCR53c7x0_cmd
*) hostdata
->free
;
3763 hostdata
->free
= cmd
;
3764 tmp
->scsi_done(tmp
);
3765 restore_flags (flags
);
3770 * If the NCR chip is in an idle state, start it running the scheduler
3771 * immediately. Otherwise, signal the chip to jump to schedule as
3772 * soon as it is idle.
3775 if (hostdata
->idle
) {
3777 hostdata
->state
= STATE_RUNNING
;
3778 NCR53c7x0_write32 (DSP_REG
, virt_to_bus ((void *)hostdata
->schedule
));
3779 if (hostdata
->options
& OPTION_DEBUG_TRACE
)
3780 NCR53c7x0_write8 (DCNTL_REG
, hostdata
->saved_dcntl
|
3781 DCNTL_SSM
| DCNTL_STD
);
3783 NCR53c7x0_write8(hostdata
->istat
, ISTAT_10_SIGP
);
3786 restore_flags(flags
);
3790 * Function : busyp (struct Scsi_Host *host, struct NCR53c7x0_hostdata
3791 * *hostdata, Scsi_Cmnd *cmd)
3793 * Purpose : decide if we can pass the given SCSI command on to the
3794 * device in question or not.
3796 * Returns : non-zero when we're busy, 0 when we aren't.
3799 static __inline__
int
3800 busyp (struct Scsi_Host
*host
, struct NCR53c7x0_hostdata
*hostdata
,
3802 /* FIXME : in the future, this needs to accommodate SCSI-II tagged
3803 queuing, and we may be able to play with fairness here a bit.
3805 return hostdata
->busy
[cmd
->target
][cmd
->lun
];
3809 * Function : process_issue_queue (void)
3811 * Purpose : transfer commands from the issue queue to NCR start queue
3812 * of each NCR53c7/8xx in the system, avoiding kernel stack
3813 * overflows when the scsi_done() function is invoked recursively.
3815 * NOTE : process_issue_queue exits with interrupts *disabled*, so the
3816 * caller must reenable them if it desires.
3818 * NOTE : process_issue_queue should be called from both
3819 * NCR53c7x0_queue_command() and from the interrupt handler
3820 * after command completion in case NCR53c7x0_queue_command()
3821 * isn't invoked again but we've freed up resources that are
3826 process_issue_queue (unsigned long flags
) {
3827 Scsi_Cmnd
*tmp
, *prev
;
3828 struct Scsi_Host
*host
;
3829 struct NCR53c7x0_hostdata
*hostdata
;
3833 * We run (with interrupts disabled) until we're sure that none of
3834 * the host adapters have anything that can be done, at which point
3835 * we set process_issue_queue_running to 0 and exit.
3837 * Interrupts are enabled before doing various other internal
3838 * instructions, after we've decided that we need to run through
3844 cli(); /* Freeze request queues */
3846 for (host
= first_host
; host
&& host
->hostt
== the_template
;
3847 host
= host
->next
) {
3848 hostdata
= (struct NCR53c7x0_hostdata
*) host
->hostdata
[0];
3850 if (hostdata
->issue_queue
) {
3851 if (hostdata
->state
== STATE_DISABLED
) {
3852 tmp
= (Scsi_Cmnd
*) hostdata
->issue_queue
;
3853 hostdata
->issue_queue
= (Scsi_Cmnd
*) tmp
->SCp
.ptr
;
3854 tmp
->result
= (DID_BAD_TARGET
<< 16);
3855 if (tmp
->host_scribble
) {
3856 ((struct NCR53c7x0_cmd
*)tmp
->host_scribble
)->next
=
3859 (struct NCR53c7x0_cmd
*)tmp
->host_scribble
;
3860 tmp
->host_scribble
= NULL
;
3862 tmp
->scsi_done (tmp
);
3865 for (tmp
= (Scsi_Cmnd
*) hostdata
->issue_queue
,
3866 prev
= NULL
; tmp
; prev
= tmp
, tmp
= (Scsi_Cmnd
*)
3868 if (!tmp
->host_scribble
||
3869 !busyp (host
, hostdata
, tmp
)) {
3871 prev
->SCp
.ptr
= tmp
->SCp
.ptr
;
3873 hostdata
->issue_queue
= (Scsi_Cmnd
*)
3875 tmp
->SCp
.ptr
= NULL
;
3876 if (tmp
->host_scribble
) {
3877 if (hostdata
->options
& OPTION_DEBUG_QUEUES
)
3878 printk ("scsi%d : moving command for target %d lun %d to start list\n",
3879 host
->host_no
, tmp
->target
, tmp
->lun
);
3882 to_schedule_list (host
, hostdata
,
3883 (struct NCR53c7x0_cmd
*)
3884 tmp
->host_scribble
);
3886 if (((tmp
->result
& 0xff) == 0xff) ||
3887 ((tmp
->result
& 0xff00) == 0xff00)) {
3888 printk ("scsi%d : danger Will Robinson!\n",
3890 tmp
->result
= DID_ERROR
<< 16;
3893 tmp
->scsi_done(tmp
);
3896 } /* if target/lun is not busy */
3897 } /* if hostdata->issue_queue */
3899 restore_flags (flags
);
3902 process_issue_queue_running
= 0;
3906 * Function : static void intr_scsi (struct Scsi_Host *host,
3907 * struct NCR53c7x0_cmd *cmd)
3909 * Purpose : handle all SCSI interrupts, indicated by the setting
3910 * of the SIP bit in the ISTAT register.
3912 * Inputs : host, cmd - host and NCR command causing the interrupt, cmd
3917 intr_scsi (struct Scsi_Host
*host
, struct NCR53c7x0_cmd
*cmd
) {
3918 NCR53c7x0_local_declare();
3919 struct NCR53c7x0_hostdata
*hostdata
=
3920 (struct NCR53c7x0_hostdata
*) host
->hostdata
[0];
3921 unsigned char sstat0_sist0
, sist1
, /* Registers */
3922 fatal
; /* Did a fatal interrupt
3925 NCR53c7x0_local_setup(host
);
3929 sstat0_sist0
= NCR53c7x0_read8(SSTAT0_REG
);
3932 if (hostdata
->options
& OPTION_DEBUG_INTR
)
3933 printk ("scsi%d : SIST0 0x%0x, SIST1 0x%0x\n", host
->host_no
,
3934 sstat0_sist0
, sist1
);
3936 /* 250ms selection timeout */
3937 if (sstat0_sist0
& SSTAT0_700_STO
) {
3939 if (hostdata
->options
& OPTION_DEBUG_INTR
) {
3940 printk ("scsi%d : Selection Timeout\n", host
->host_no
);
3942 printk("scsi%d : target %d, lun %d, command ",
3943 host
->host_no
, cmd
->cmd
->target
, cmd
->cmd
->lun
);
3944 print_command (cmd
->cmd
->cmnd
);
3945 printk("scsi%d : dsp = 0x%x (virt 0x%p)\n", host
->host_no
,
3946 NCR53c7x0_read32(DSP_REG
),
3947 bus_to_virt(NCR53c7x0_read32(DSP_REG
)));
3949 printk("scsi%d : no command\n", host
->host_no
);
3953 * XXX - question : how do we want to handle the Illegal Instruction
3954 * interrupt, which may occur before or after the Selection Timeout
3960 hostdata
->expecting_sto
= 0;
3962 if (hostdata
->test_running
) {
3963 hostdata
->test_running
= 0;
3964 hostdata
->test_completed
= 3;
3966 abnormal_finished(cmd
, DID_BAD_TARGET
<< 16);
3969 hostdata
->intrs
= 0;
3975 * FIXME : in theory, we can also get a UDC when a STO occurs.
3977 if (sstat0_sist0
& SSTAT0_UDC
) {
3980 printk("scsi%d : target %d lun %d unexpected disconnect\n",
3981 host
->host_no
, cmd
->cmd
->target
, cmd
->cmd
->lun
);
3983 abnormal_finished(cmd
, DID_ERROR
<< 16);
3985 printk("scsi%d : unexpected disconnect (no command)\n",
3988 hostdata
->dsp
= (u32
*) hostdata
->schedule
;
3989 hostdata
->dsp_changed
= 1;
3992 /* SCSI PARITY error */
3993 if (sstat0_sist0
& SSTAT0_PAR
) {
3995 if (cmd
&& cmd
->cmd
) {
3996 printk("scsi%d : target %d lun %d parity error.\n",
3997 host
->host_no
, cmd
->cmd
->target
, cmd
->cmd
->lun
);
3998 abnormal_finished (cmd
, DID_PARITY
<< 16);
4000 printk("scsi%d : parity error\n", host
->host_no
);
4001 /* Should send message out, parity error */
4003 /* XXX - Reduce synchronous transfer rate! */
4004 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_initiator_abort
/
4006 hostdata
->dsp_changed
= 1;
4007 /* SCSI GROSS error */
4010 if (sstat0_sist0
& SSTAT0_SGE
) {
4012 printk("scsi%d : gross error, saved2_dsa = 0x%x\n", host
->host_no
,
4013 (unsigned int)hostdata
->saved2_dsa
);
4017 * A SCSI gross error may occur when we have
4019 * - A synchronous offset which causes the SCSI FIFO to be overwritten.
4021 * - A REQ which causes the maximum synchronous offset programmed in
4022 * the SXFER register to be exceeded.
4024 * - A phase change with an outstanding synchronous offset.
4026 * - Residual data in the synchronous data FIFO, with a transfer
4027 * other than a synchronous receive is started.$#
4031 /* XXX Should deduce synchronous transfer rate! */
4032 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_initiator_abort
/
4034 hostdata
->dsp_changed
= 1;
4035 /* Phase mismatch */
4038 if (sstat0_sist0
& SSTAT0_MA
) {
4040 if (hostdata
->options
& OPTION_DEBUG_INTR
)
4041 printk ("scsi%d : SSTAT0_MA\n", host
->host_no
);
4042 intr_phase_mismatch (host
, cmd
);
4046 if (sstat0_sist0
& SIST0_800_RSL
)
4047 printk ("scsi%d : Oh no Mr. Bill!\n", host
->host_no
);
4051 * If a fatal SCSI interrupt occurs, we must insure that the DMA and
4052 * SCSI FIFOs were flushed.
4056 if (!hostdata
->dstat_valid
) {
4057 hostdata
->dstat
= NCR53c7x0_read8(DSTAT_REG
);
4058 hostdata
->dstat_valid
= 1;
4061 if (!(hostdata
->dstat
& DSTAT_DFE
)) {
4062 printk ("scsi%d : DMA FIFO not empty\n", host
->host_no
);
4064 * Really need to check this code for 710 RGH.
4065 * Havn't seen any problems, but maybe we should FLUSH before
4066 * clearing sometimes.
4068 NCR53c7x0_write8 (CTEST8_REG
, CTEST8_10_CLF
);
4069 while (NCR53c7x0_read8 (CTEST8_REG
) & CTEST8_10_CLF
)
4071 hostdata
->dstat
|= DSTAT_DFE
;
4079 * The following implements a cyclic log of instructions executed, if you turn
4080 * TRACE on. It will also print the log for you. Very useful when debugging
4081 * 53c710 support, possibly not really needed any more.
4085 u32 insn_log_index
= 0;
4089 insn_log
[insn_log_index
++] = i
;
4090 if (insn_log_index
== 4096)
4094 void log_insn (u32
*ip
)
4099 if (((*ip
>> 24) & DCMD_TYPE_MASK
) == DCMD_TYPE_MMI
)
4106 int i
= insn_log_index
;
4108 struct Scsi_Host
*host
= first_host
;
4110 while (cnt
< 4096) {
4111 printk ("%08x (+%6x): ", insn_log
[i
], (insn_log
[i
] - (u32
)&(((struct NCR53c7x0_hostdata
*)host
->hostdata
[0])->script
))/4);
4115 if (((insn_log
[i
] >> 24) & DCMD_TYPE_MASK
) == DCMD_TYPE_MMI
)
4120 printk ("%08x ", insn_log
[i
]);
4132 * Function : static void NCR53c7x0_intfly (struct Scsi_Host *host)
4134 * Purpose : Scan command queue for specified host, looking for completed
4137 * Inputs : Scsi_Host pointer.
4139 * This is called from the interrupt handler, when a simulated INTFLY
4144 NCR53c7x0_intfly (struct Scsi_Host
*host
)
4146 NCR53c7x0_local_declare();
4147 struct NCR53c7x0_hostdata
*hostdata
; /* host->hostdata[0] */
4148 struct NCR53c7x0_cmd
*cmd
, /* command which halted */
4150 unsigned long flags
;
4151 char search_found
= 0; /* Got at least one ? */
4153 hostdata
= (struct NCR53c7x0_hostdata
*) host
->hostdata
[0];
4154 NCR53c7x0_local_setup(host
);
4156 if (hostdata
->options
& OPTION_DEBUG_INTR
)
4157 printk ("scsi%d : INTFLY\n", host
->host_no
);
4160 * Traverse our list of running commands, and look
4161 * for those with valid (non-0xff ff) status and message
4162 * bytes encoded in the result which signify command
4169 for (cmd_prev_ptr
= (struct NCR53c7x0_cmd
**)&(hostdata
->running_list
),
4170 cmd
= (struct NCR53c7x0_cmd
*) hostdata
->running_list
; cmd
;
4171 cmd_prev_ptr
= (struct NCR53c7x0_cmd
**) &(cmd
->next
),
4172 cmd
= (struct NCR53c7x0_cmd
*) cmd
->next
)
4177 printk("scsi%d : very weird.\n", host
->host_no
);
4181 if (!(tmp
= cmd
->cmd
)) {
4182 printk("scsi%d : weird. NCR53c7x0_cmd has no Scsi_Cmnd\n",
4186 /* Copy the result over now; may not be complete,
4187 * but subsequent tests may as well be done on
4190 tmp
->result
= cmd
->result
;
4192 if (((tmp
->result
& 0xff) == 0xff) ||
4193 ((tmp
->result
& 0xff00) == 0xff00))
4198 if (cmd
->bounce
.len
)
4199 memcpy ((void *)cmd
->bounce
.addr
,
4200 (void *)cmd
->bounce
.buf
, cmd
->bounce
.len
);
4202 /* Important - remove from list _before_ done is called */
4204 *cmd_prev_ptr
= (struct NCR53c7x0_cmd
*) cmd
->next
;
4206 --hostdata
->busy
[tmp
->target
][tmp
->lun
];
4207 cmd
->next
= hostdata
->free
;
4208 hostdata
->free
= cmd
;
4210 tmp
->host_scribble
= NULL
;
4212 if (hostdata
->options
& OPTION_DEBUG_INTR
) {
4213 printk ("scsi%d : command complete : pid %lu, id %d,lun %d result 0x%x ",
4214 host
->host_no
, tmp
->pid
, tmp
->target
, tmp
->lun
, tmp
->result
);
4215 print_command (tmp
->cmnd
);
4218 tmp
->scsi_done(tmp
);
4221 restore_flags(flags
);
4223 if (!search_found
) {
4224 printk ("scsi%d : WARNING : INTFLY with no completed commands.\n",
4227 run_process_issue_queue();
4233 * Function : static void NCR53c7x0_intr (int irq, void *dev_id, struct pt_regs * regs)
4235 * Purpose : handle NCR53c7x0 interrupts for all NCR devices sharing
4236 * the same IRQ line.
4238 * Inputs : Since we're using the SA_INTERRUPT interrupt handler
4239 * semantics, irq indicates the interrupt which invoked
4242 * On the 710 we simualte an INTFLY with a script interrupt, and the
4243 * script interrupt handler will call back to this function.
4247 NCR53c7x0_intr (int irq
, void *dev_id
, struct pt_regs
* regs
) {
4248 NCR53c7x0_local_declare();
4249 struct Scsi_Host
*host
; /* Host we are looking at */
4250 unsigned char istat
; /* Values of interrupt regs */
4251 struct NCR53c7x0_hostdata
*hostdata
; /* host->hostdata[0] */
4252 struct NCR53c7x0_cmd
*cmd
; /* command which halted */
4256 char buf
[80]; /* Debugging sprintf buffer */
4257 size_t buflen
; /* Length of same */
4260 host
= (struct Scsi_Host
*)dev_id
;
4261 hostdata
= (struct NCR53c7x0_hostdata
*) host
->hostdata
[0];
4262 NCR53c7x0_local_setup(host
);
4265 * Only read istat once per loop, since reading it again will unstack
4269 while ((istat
= NCR53c7x0_read8(hostdata
->istat
)) & (ISTAT_SIP
|ISTAT_DIP
)) {
4270 hostdata
->dsp_changed
= 0;
4271 hostdata
->dstat_valid
= 0;
4272 hostdata
->state
= STATE_HALTED
;
4274 if (NCR53c7x0_read8 (SSTAT2_REG
) & SSTAT2_FF_MASK
)
4275 printk ("scsi%d : SCSI FIFO not empty\n", host
->host_no
);
4278 * NCR53c700 and NCR53c700-66 change the current SCSI
4279 * process, hostdata->ncrcurrent, in the Linux driver so
4280 * cmd = hostdata->ncrcurrent.
4282 * With other chips, we must look through the commands
4283 * executing and find the command structure which
4284 * corresponds to the DSA register.
4287 if (hostdata
->options
& OPTION_700
) {
4288 cmd
= (struct NCR53c7x0_cmd
*) hostdata
->ncrcurrent
;
4290 dsa
= bus_to_virt(NCR53c7x0_read32(DSA_REG
));
4291 for (cmd
= (struct NCR53c7x0_cmd
*) hostdata
->running_list
;
4292 cmd
&& (dsa
+ (hostdata
->dsa_start
/ sizeof(u32
))) != cmd
->dsa
;
4293 cmd
= (struct NCR53c7x0_cmd
*)(cmd
->next
))
4296 if (hostdata
->options
& OPTION_DEBUG_INTR
) {
4298 printk("scsi%d : interrupt for pid %lu, id %d, lun %d ",
4299 host
->host_no
, cmd
->cmd
->pid
, (int) cmd
->cmd
->target
,
4300 (int) cmd
->cmd
->lun
);
4301 print_command (cmd
->cmd
->cmnd
);
4303 printk("scsi%d : no active command\n", host
->host_no
);
4307 if (istat
& ISTAT_SIP
) {
4308 if (hostdata
->options
& OPTION_DEBUG_INTR
)
4309 printk ("scsi%d : ISTAT_SIP\n", host
->host_no
);
4310 intr_scsi (host
, cmd
);
4313 if (istat
& ISTAT_DIP
) {
4314 if (hostdata
->options
& OPTION_DEBUG_INTR
)
4315 printk ("scsi%d : ISTAT_DIP\n", host
->host_no
);
4316 intr_dma (host
, cmd
);
4319 if (!hostdata
->dstat_valid
) {
4320 hostdata
->dstat
= NCR53c7x0_read8(DSTAT_REG
);
4321 hostdata
->dstat_valid
= 1;
4324 if (!(hostdata
->dstat
& DSTAT_DFE
)) {
4325 printk ("scsi%d : DMA FIFO not empty\n", host
->host_no
);
4326 /* Really need to check this out for 710 RGH */
4327 NCR53c7x0_write8 (CTEST8_REG
, CTEST8_10_CLF
);
4328 while (NCR53c7x0_read8 (CTEST8_REG
) & CTEST8_10_CLF
)
4330 hostdata
->dstat
|= DSTAT_DFE
;
4333 if (!hostdata
->idle
&& hostdata
->state
== STATE_HALTED
) {
4334 if (!hostdata
->dsp_changed
)
4335 hostdata
->dsp
= (u32
*)bus_to_virt(NCR53c7x0_read32(DSP_REG
));
4337 printk("scsi%d : new dsp is 0x%lx (virt 0x%p)\n",
4338 host
->host_no
, virt_to_bus(hostdata
->dsp
), hostdata
->dsp
);
4341 hostdata
->state
= STATE_RUNNING
;
4342 NCR53c7x0_write32 (DSP_REG
, virt_to_bus(hostdata
->dsp
));
4343 if (hostdata
->options
& OPTION_DEBUG_TRACE
) {
4345 log_insn (hostdata
->dsp
);
4347 print_insn (host
, hostdata
->dsp
, "t ", 1);
4349 NCR53c7x0_write8 (DCNTL_REG
,
4350 hostdata
->saved_dcntl
| DCNTL_SSM
| DCNTL_STD
);
4358 * Function : static int abort_connected (struct Scsi_Host *host)
4360 * Purpose : Assuming that the NCR SCSI processor is currently
4361 * halted, break the currently established nexus. Clean
4362 * up of the NCR53c7x0_cmd and Scsi_Cmnd structures should
4363 * be done on receipt of the abort interrupt.
4365 * Inputs : host - SCSI host
4370 abort_connected (struct Scsi_Host
*host
) {
4372 NCR53c7x0_local_declare();
4374 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
4376 /* FIXME : this probably should change for production kernels; at the
4377 least, counter should move to a per-host structure. */
4378 static int counter
= 5;
4380 int sstat
, phase
, offset
;
4382 NCR53c7x0_local_setup(host
);
4385 if (--counter
<= 0) {
4390 printk ("scsi%d : DANGER : abort_connected() called \n",
4396 * New strategy : Rather than using a generic abort routine,
4397 * we'll specifically try to source or sink the appropriate
4398 * amount of data for the phase we're currently in (taking into
4399 * account the current synchronous offset)
4402 sstat
= (NCR53c8x0_read8 (SSTAT2_REG
);
4403 offset
= OFFSET (sstat
& SSTAT2_FF_MASK
) >> SSTAT2_FF_SHIFT
;
4404 phase
= sstat
& SSTAT2_PHASE_MASK
;
4408 * MOVE source_or_sink, WHEN CURRENT PHASE
4409 * < repeat for each outstanding byte >
4410 * JUMP send_abort_message
4413 script
= hostdata
->abort_script
= kmalloc (
4414 8 /* instruction size */ * (
4416 (!offset
? 1 : offset
) /* One transfer per outstanding byte */ +
4417 1 /* send abort message */),
4421 #else /* def NEW_ABORT */
4422 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_initiator_abort
/
4424 #endif /* def NEW_ABORT */
4425 hostdata
->dsp_changed
= 1;
4427 /* XXX - need to flag the command as aborted after the abort_connected
4434 * Function : static int datapath_residual (Scsi_Host *host)
4436 * Purpose : return residual data count of what's in the chip.
4438 * Inputs : host - SCSI host
4442 datapath_residual (struct Scsi_Host
*host
) {
4443 NCR53c7x0_local_declare();
4444 int count
, synchronous
, sstat
;
4447 NCR53c7x0_local_setup(host
);
4448 /* COMPAT : the 700 and 700-66 need to use DFIFO_00_BO_MASK */
4449 count
= ((NCR53c7x0_read8 (DFIFO_REG
) & DFIFO_10_BO_MASK
) -
4450 (NCR53c7x0_read32 (DBC_REG
) & DFIFO_10_BO_MASK
)) & DFIFO_10_BO_MASK
;
4451 synchronous
= NCR53c7x0_read8 (SXFER_REG
) & SXFER_MO_MASK
;
4452 /* COMPAT : DDIR is elsewhere on non-'8xx chips. */
4453 ddir
= NCR53c7x0_read8 (CTEST0_REG_700
) & CTEST0_700_DDIR
;
4458 count
+= (NCR53c7x0_read8 (SSTAT2_REG
) & SSTAT2_FF_MASK
) >> SSTAT2_FF_SHIFT
;
4460 if (NCR53c7x0_read8 (SSTAT1_REG
) & SSTAT1_ILF
)
4464 sstat
= NCR53c7x0_read8 (SSTAT1_REG
);
4465 if (sstat
& SSTAT1_OLF
)
4467 if (synchronous
&& (sstat
& SSTAT1_ORF
))
4474 * Function : static const char * sbcl_to_phase (int sbcl)_
4476 * Purpose : Convert SBCL register to user-parsable phase representation
4478 * Inputs : sbcl - value of sbcl register
4483 sbcl_to_phase (int sbcl
) {
4484 switch (sbcl
& SBCL_PHASE_MASK
) {
4485 case SBCL_PHASE_DATAIN
:
4487 case SBCL_PHASE_DATAOUT
:
4489 case SBCL_PHASE_MSGIN
:
4491 case SBCL_PHASE_MSGOUT
:
4493 case SBCL_PHASE_CMDOUT
:
4495 case SBCL_PHASE_STATIN
:
4503 * Function : static const char * sstat2_to_phase (int sstat)_
4505 * Purpose : Convert SSTAT2 register to user-parsable phase representation
4507 * Inputs : sstat - value of sstat register
4512 sstat2_to_phase (int sstat
) {
4513 switch (sstat
& SSTAT2_PHASE_MASK
) {
4514 case SSTAT2_PHASE_DATAIN
:
4516 case SSTAT2_PHASE_DATAOUT
:
4518 case SSTAT2_PHASE_MSGIN
:
4520 case SSTAT2_PHASE_MSGOUT
:
4522 case SSTAT2_PHASE_CMDOUT
:
4524 case SSTAT2_PHASE_STATIN
:
4532 * Function : static void intr_phase_mismatch (struct Scsi_Host *host,
4533 * struct NCR53c7x0_cmd *cmd)
4535 * Purpose : Handle phase mismatch interrupts
4537 * Inputs : host, cmd - host and NCR command causing the interrupt, cmd
4540 * Side effects : The abort_connected() routine is called or the NCR chip
4541 * is restarted, jumping to the command_complete entry point, or
4542 * patching the address and transfer count of the current instruction
4543 * and calling the msg_in entry point as appropriate.
4547 intr_phase_mismatch (struct Scsi_Host
*host
, struct NCR53c7x0_cmd
*cmd
) {
4548 NCR53c7x0_local_declare();
4549 u32 dbc_dcmd
, *dsp
, *dsp_next
;
4550 unsigned char dcmd
, sbcl
;
4551 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
4554 enum {ACTION_ABORT
, ACTION_ABORT_PRINT
, ACTION_CONTINUE
} action
=
4556 const char *where
= NULL
;
4558 NCR53c7x0_local_setup(host
);
4561 * Corrective action is based on where in the SCSI SCRIPT(tm) the error
4562 * occurred, as well as which SCSI phase we are currently in.
4564 dsp_next
= bus_to_virt(NCR53c7x0_read32(DSP_REG
));
4567 * Fetch the current instruction, and remove the operands for easier
4570 dbc_dcmd
= NCR53c7x0_read32(DBC_REG
);
4571 dcmd
= (dbc_dcmd
& 0xff000000) >> 24;
4573 * Like other processors, the NCR adjusts the instruction pointer before
4574 * instruction decode. Set the DSP address back to what it should
4575 * be for this instruction based on its size (2 or 3 32 bit words).
4577 dsp
= dsp_next
- NCR53c7x0_insn_size(dcmd
);
4581 * Read new SCSI phase from the SBCL lines. Since all of our code uses
4582 * a WHEN conditional instead of an IF conditional, we don't need to
4583 * wait for a new REQ.
4585 sbcl
= NCR53c7x0_read8(SBCL_REG
) & SBCL_PHASE_MASK
;
4588 action
= ACTION_ABORT_PRINT
;
4589 where
= "no current command";
4591 * The way my SCSI SCRIPTS(tm) are architected, recoverable phase
4592 * mismatches should only occur where we're doing a multi-byte
4593 * BMI instruction. Specifically, this means
4595 * - select messages (a SCSI-I target may ignore additional messages
4596 * after the IDENTIFY; any target may reject a SDTR or WDTR)
4598 * - command out (targets may send a message to signal an error
4599 * condition, or go into STATUSIN after they've decided
4600 * they don't like the command.
4602 * - reply_message (targets may reject a multi-byte message in the
4605 * - data transfer routines (command completion with buffer space
4606 * left, disconnect message, or error message)
4608 } else if (((dsp
>= cmd
->data_transfer_start
&&
4609 dsp
< cmd
->data_transfer_end
)) || dsp
== (cmd
->residual
+ 2)) {
4610 if ((dcmd
& (DCMD_TYPE_MASK
|DCMD_BMI_OP_MASK
|DCMD_BMI_INDIRECT
|
4611 DCMD_BMI_MSG
|DCMD_BMI_CD
)) == (DCMD_TYPE_BMI
|
4612 DCMD_BMI_OP_MOVE_I
)) {
4613 residual
= datapath_residual (host
);
4614 if (hostdata
->options
& OPTION_DEBUG_DISCONNECT
)
4615 printk ("scsi%d : handling residual transfer (+ %d bytes from DMA FIFO)\n",
4616 host
->host_no
, residual
);
4619 * The first instruction is a CALL to the alternate handler for
4620 * this data transfer phase, so we can do calls to
4621 * munge_msg_restart as we would if control were passed
4622 * from normal dynamic code.
4624 if (dsp
!= cmd
->residual
+ 2) {
4625 cmd
->residual
[0] = ((DCMD_TYPE_TCI
| DCMD_TCI_OP_CALL
|
4626 ((dcmd
& DCMD_BMI_IO
) ? DCMD_TCI_IO
: 0)) << 24) |
4627 DBC_TCI_WAIT_FOR_VALID
| DBC_TCI_COMPARE_PHASE
;
4628 cmd
->residual
[1] = virt_to_bus(hostdata
->script
)
4629 + ((dcmd
& DCMD_BMI_IO
)
4630 ? hostdata
->E_other_in
: hostdata
->E_other_out
);
4634 * The second instruction is the a data transfer block
4635 * move instruction, reflecting the pointer and count at the
4636 * time of the phase mismatch.
4638 cmd
->residual
[2] = dbc_dcmd
+ residual
;
4639 cmd
->residual
[3] = NCR53c7x0_read32(DNAD_REG
) - residual
;
4642 * The third and final instruction is a jump to the instruction
4643 * which follows the instruction which had to be 'split'
4645 if (dsp
!= cmd
->residual
+ 2) {
4646 cmd
->residual
[4] = ((DCMD_TYPE_TCI
|DCMD_TCI_OP_JUMP
)
4647 << 24) | DBC_TCI_TRUE
;
4648 cmd
->residual
[5] = virt_to_bus(dsp_next
);
4652 * For the sake of simplicity, transfer control to the
4653 * conditional CALL at the start of the residual buffer.
4655 hostdata
->dsp
= cmd
->residual
;
4656 hostdata
->dsp_changed
= 1;
4657 action
= ACTION_CONTINUE
;
4659 where
= "non-BMI dynamic DSA code";
4660 action
= ACTION_ABORT_PRINT
;
4662 } else if (dsp
== (hostdata
->script
+ hostdata
->E_select_msgout
/ 4 + 2)) {
4663 /* RGH 290697: Added +2 above, to compensate for the script
4664 * instruction which disables the selection timer. */
4666 NCR53c7x0_write8 (SOCL_REG
, 0);
4669 * Some devices (SQ555 come to mind) grab the IDENTIFY message
4670 * sent on selection, and decide to go into COMMAND OUT phase
4671 * rather than accepting the rest of the messages or rejecting
4672 * them. Handle these devices gracefully.
4674 case SBCL_PHASE_CMDOUT
:
4675 hostdata
->dsp
= dsp
+ 2 /* two _words_ */;
4676 hostdata
->dsp_changed
= 1;
4677 printk ("scsi%d : target %d ignored SDTR and went into COMMAND OUT\n",
4678 host
->host_no
, cmd
->cmd
->target
);
4679 cmd
->flags
&= ~CMD_FLAG_SDTR
;
4680 action
= ACTION_CONTINUE
;
4682 case SBCL_PHASE_MSGIN
:
4683 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_msg_in
/
4685 hostdata
->dsp_changed
= 1;
4686 action
= ACTION_CONTINUE
;
4689 where
="select message out";
4690 action
= ACTION_ABORT_PRINT
;
4693 * Some SCSI devices will interpret a command as they read the bytes
4694 * off the SCSI bus, and may decide that the command is Bogus before
4695 * they've read the entire command off the bus.
4697 } else if (dsp
== hostdata
->script
+ hostdata
->E_cmdout_cmdout
/ sizeof
4699 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_data_transfer
/
4701 hostdata
->dsp_changed
= 1;
4702 action
= ACTION_CONTINUE
;
4703 /* FIXME : we need to handle message reject, etc. within msg_respond. */
4705 } else if (dsp
== hostdata
->script
+ hostdata
->E_reply_message
) {
4707 /* Any other phase mismatches abort the currently executing command. */
4710 where
= "unknown location";
4711 action
= ACTION_ABORT_PRINT
;
4714 /* Flush DMA FIFO */
4715 if (!hostdata
->dstat_valid
) {
4716 hostdata
->dstat
= NCR53c7x0_read8(DSTAT_REG
);
4717 hostdata
->dstat_valid
= 1;
4719 if (!(hostdata
->dstat
& DSTAT_DFE
)) {
4720 /* Really need to check this out for 710 RGH */
4721 NCR53c7x0_write8 (CTEST8_REG
, CTEST8_10_CLF
);
4722 while (NCR53c7x0_read8 (CTEST8_REG
) & CTEST8_10_CLF
);
4723 hostdata
->dstat
|= DSTAT_DFE
;
4727 case ACTION_ABORT_PRINT
:
4728 printk("scsi%d : %s : unexpected phase %s.\n",
4729 host
->host_no
, where
? where
: "unknown location",
4730 sbcl_to_phase(sbcl
));
4732 /* Fall through to ACTION_ABORT */
4734 abort_connected (host
);
4736 case ACTION_CONTINUE
:
4741 if (hostdata
->dsp_changed
) {
4742 printk("scsi%d: new dsp 0x%p\n", host
->host_no
, hostdata
->dsp
);
4743 print_insn (host
, hostdata
->dsp
, "", 1);
4749 * Function : static void intr_bf (struct Scsi_Host *host,
4750 * struct NCR53c7x0_cmd *cmd)
4752 * Purpose : handle BUS FAULT interrupts
4754 * Inputs : host, cmd - host and NCR command causing the interrupt, cmd
4759 intr_bf (struct Scsi_Host
*host
, struct NCR53c7x0_cmd
*cmd
) {
4760 NCR53c7x0_local_declare();
4762 *next_dsp
, /* Current dsp */
4764 dbc_dcmd
; /* DCMD (high eight bits) + DBC */
4765 char *reason
= NULL
;
4766 /* Default behavior is for a silent error, with a retry until we've
4767 exhausted retries. */
4768 enum {MAYBE
, ALWAYS
, NEVER
} retry
= MAYBE
;
4770 NCR53c7x0_local_setup(host
);
4772 dbc_dcmd
= NCR53c7x0_read32 (DBC_REG
);
4773 next_dsp
= bus_to_virt (NCR53c7x0_read32(DSP_REG
));
4774 dsp
= next_dsp
- NCR53c7x0_insn_size ((dbc_dcmd
>> 24) & 0xff);
4775 /* FIXME - check chip type */
4776 dsa
= bus_to_virt (NCR53c7x0_read32(DSA_REG
));
4779 * Bus faults can be caused by either a Bad Address or
4780 * Target Abort. We should check the Received Target Abort
4781 * bit of the PCI status register and Master Abort Bit.
4783 * - Master Abort bit indicates that no device claimed
4784 * the address with DEVSEL within five clocks
4786 * - Target Abort bit indicates that a target claimed it,
4787 * but changed its mind once it saw the byte enables.
4791 /* 53c710, not PCI system */
4798 if (report
&& reason
)
4800 printk(KERN_ALERT
"scsi%d : BUS FAULT reason = %s\n",
4801 host
->host_no
, reason
? reason
: "unknown");
4810 * TODO : we should attempt to recover from any spurious bus
4811 * faults. After X retries, we should figure that things are
4812 * sufficiently wedged, and call NCR53c7xx_reset.
4814 * This code should only get executed once we've decided that we
4818 if (retry
== NEVER
) {
4819 printk(KERN_ALERT
" mail richard@sleepie.demon.co.uk\n");
4825 * Function : static void intr_dma (struct Scsi_Host *host,
4826 * struct NCR53c7x0_cmd *cmd)
4828 * Purpose : handle all DMA interrupts, indicated by the setting
4829 * of the DIP bit in the ISTAT register.
4831 * Inputs : host, cmd - host and NCR command causing the interrupt, cmd
4836 intr_dma (struct Scsi_Host
*host
, struct NCR53c7x0_cmd
*cmd
) {
4837 NCR53c7x0_local_declare();
4838 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
4840 unsigned char dstat
; /* DSTAT */
4842 *next_dsp
, /* Current dsp */
4844 dbc_dcmd
; /* DCMD (high eight bits) + DBC */
4846 unsigned long flags
;
4847 NCR53c7x0_local_setup(host
);
4849 if (!hostdata
->dstat_valid
) {
4850 hostdata
->dstat
= NCR53c7x0_read8(DSTAT_REG
);
4851 hostdata
->dstat_valid
= 1;
4854 dstat
= hostdata
->dstat
;
4856 if (hostdata
->options
& OPTION_DEBUG_INTR
)
4857 printk("scsi%d : DSTAT=0x%x\n", host
->host_no
, (int) dstat
);
4859 dbc_dcmd
= NCR53c7x0_read32 (DBC_REG
);
4860 next_dsp
= bus_to_virt(NCR53c7x0_read32(DSP_REG
));
4861 dsp
= next_dsp
- NCR53c7x0_insn_size ((dbc_dcmd
>> 24) & 0xff);
4862 /* XXX - check chip type */
4863 dsa
= bus_to_virt(NCR53c7x0_read32(DSA_REG
));
4866 * DSTAT_ABRT is the aborted interrupt. This is set whenever the
4867 * SCSI chip is aborted.
4869 * With NCR53c700 and NCR53c700-66 style chips, we should only
4870 * get this when the chip is currently running the accept
4871 * reselect/select code and we have set the abort bit in the
4876 if (dstat
& DSTAT_ABRT
) {
4878 /* XXX - add code here to deal with normal abort */
4879 if ((hostdata
->options
& OPTION_700
) && (hostdata
->state
==
4884 printk(KERN_ALERT
"scsi%d : unexpected abort interrupt at\n"
4885 " ", host
->host_no
);
4886 print_insn (host
, dsp
, KERN_ALERT
"s ", 1);
4892 * DSTAT_SSI is the single step interrupt. Should be generated
4893 * whenever we have single stepped or are tracing.
4896 if (dstat
& DSTAT_SSI
) {
4897 if (hostdata
->options
& OPTION_DEBUG_TRACE
) {
4898 /* Don't print instr. until we write DSP at end of intr function */
4899 } else if (hostdata
->options
& OPTION_DEBUG_SINGLE
) {
4900 print_insn (host
, dsp
, "s ", 0);
4903 /* XXX - should we do this, or can we get away with writing dsp? */
4905 NCR53c7x0_write8 (DCNTL_REG
, (NCR53c7x0_read8(DCNTL_REG
) &
4906 ~DCNTL_SSM
) | DCNTL_STD
);
4907 restore_flags(flags
);
4909 printk(KERN_ALERT
"scsi%d : unexpected single step interrupt at\n"
4910 " ", host
->host_no
);
4911 print_insn (host
, dsp
, KERN_ALERT
"", 1);
4912 printk(KERN_ALERT
" mail drew@PoohSticks.ORG\n");
4918 * DSTAT_IID / DSTAT_OPC (same bit, same meaning, only the name
4919 * is different) is generated whenever an illegal instruction is
4922 * XXX - we may want to emulate INTFLY here, so we can use
4923 * the same SCSI SCRIPT (tm) for NCR53c710 through NCR53c810
4927 if (dstat
& DSTAT_OPC
) {
4929 * Ascertain if this IID interrupts occurred before or after a STO
4930 * interrupt. Since the interrupt handling code now leaves
4931 * DSP unmodified until _after_ all stacked interrupts have been
4932 * processed, reading the DSP returns the original DSP register.
4933 * This means that if dsp lies between the select code, and
4934 * message out following the selection code (where the IID interrupt
4935 * would have to have occurred by due to the implicit wait for REQ),
4936 * we have an IID interrupt resulting from a STO condition and
4940 if (((dsp
>= (hostdata
->script
+ hostdata
->E_select
/ sizeof(u32
))) &&
4941 (dsp
<= (hostdata
->script
+ hostdata
->E_select_msgout
/
4942 sizeof(u32
) + 8))) || (hostdata
->test_running
== 2)) {
4943 if (hostdata
->options
& OPTION_DEBUG_INTR
)
4944 printk ("scsi%d : ignoring DSTAT_IID for SSTAT_STO\n",
4946 if (hostdata
->expecting_iid
) {
4947 hostdata
->expecting_iid
= 0;
4949 if (hostdata
->test_running
== 2) {
4950 hostdata
->test_running
= 0;
4951 hostdata
->test_completed
= 3;
4953 abnormal_finished (cmd
, DID_BAD_TARGET
<< 16);
4955 hostdata
->expecting_sto
= 1;
4958 * We can't guarantee we'll be able to execute the WAIT DISCONNECT
4959 * instruction within the 3.4us of bus free and arbitration delay
4960 * that a target can RESELECT in and assert REQ after we've dropped
4961 * ACK. If this happens, we'll get an illegal instruction interrupt.
4962 * Doing away with the WAIT DISCONNECT instructions broke everything,
4963 * so instead I'll settle for moving one WAIT DISCONNECT a few
4964 * instructions closer to the CLEAR ACK before it to minimize the
4965 * chances of this happening, and handle it if it occurs anyway.
4967 * Simply continue with what we were doing, and control should
4968 * be transfered to the schedule routine which will ultimately
4969 * pass control onto the reselection or selection (not yet)
4972 } else if (dbc_dcmd
== 0x48000000 && (NCR53c7x0_read8 (SBCL_REG
) &
4974 if (!(hostdata
->options
& OPTION_NO_PRINT_RACE
))
4976 printk("scsi%d: REQ before WAIT DISCONNECT IID\n",
4978 hostdata
->options
|= OPTION_NO_PRINT_RACE
;
4981 printk(KERN_ALERT
"scsi%d : illegal instruction\n", host
->host_no
);
4983 printk(KERN_ALERT
" mail Richard@sleepie.demon.co.uk with ALL\n"
4984 " boot messages and diagnostic output\n");
4990 * DSTAT_BF are bus fault errors. DSTAT_800_BF is valid for 710 also.
4993 if (dstat
& DSTAT_800_BF
) {
4994 intr_bf (host
, cmd
);
4999 * DSTAT_SIR interrupts are generated by the execution of
5000 * the INT instruction. Since the exact values available
5001 * are determined entirely by the SCSI script running,
5002 * and are local to a particular script, a unique handler
5003 * is called for each script.
5006 if (dstat
& DSTAT_SIR
) {
5007 if (hostdata
->options
& OPTION_DEBUG_INTR
)
5008 printk ("scsi%d : DSTAT_SIR\n", host
->host_no
);
5009 switch ((tmp
= hostdata
->dstat_sir_intr (host
, cmd
))) {
5010 case SPECIFIC_INT_NOTHING
:
5011 case SPECIFIC_INT_RESTART
:
5013 case SPECIFIC_INT_ABORT
:
5014 abort_connected(host
);
5016 case SPECIFIC_INT_PANIC
:
5017 printk(KERN_ALERT
"scsi%d : failure at ", host
->host_no
);
5018 print_insn (host
, dsp
, KERN_ALERT
"", 1);
5019 printk(KERN_ALERT
" dstat_sir_intr() returned SPECIFIC_INT_PANIC\n");
5022 case SPECIFIC_INT_BREAK
:
5023 intr_break (host
, cmd
);
5026 printk(KERN_ALERT
"scsi%d : failure at ", host
->host_no
);
5027 print_insn (host
, dsp
, KERN_ALERT
"", 1);
5028 printk(KERN_ALERT
" dstat_sir_intr() returned unknown value %d\n",
5036 * Function : static int print_insn (struct Scsi_Host *host,
5037 * u32 *insn, int kernel)
5039 * Purpose : print numeric representation of the instruction pointed
5040 * to by insn to the debugging or kernel message buffer
5043 * If desired, a user level program can interpret this
5046 * Inputs : host, insn - host, pointer to instruction, prefix -
5047 * string to prepend, kernel - use printk instead of debugging buffer.
5049 * Returns : size, in u32s, of instruction printed.
5053 * FIXME: should change kernel parameter so that it takes an ENUM
5054 * specifying severity - either KERN_ALERT or KERN_PANIC so
5055 * all panic messages are output with the same severity.
5059 print_insn (struct Scsi_Host
*host
, const u32
*insn
,
5060 const char *prefix
, int kernel
) {
5061 char buf
[160], /* Temporary buffer and pointer. ICKY
5062 arbitrary length. */
5066 unsigned char dcmd
; /* dcmd register for *insn */
5070 * Check to see if the instruction pointer is not bogus before
5071 * indirecting through it; avoiding red-zone at start of
5074 * FIXME: icky magic needs to happen here on non-intel boxes which
5075 * don't have kernel memory mapped in like this. Might be reasonable
5079 if (virt_to_phys((void *)insn
) < PAGE_SIZE
||
5080 virt_to_phys((void *)(insn
+ 8)) > virt_to_phys(high_memory
) ||
5081 ((((dcmd
= (insn
[0] >> 24) & 0xff) & DCMD_TYPE_MMI
) == DCMD_TYPE_MMI
) &&
5082 virt_to_phys((void *)(insn
+ 12)) > virt_to_phys(high_memory
))) {
5084 sprintf (buf
, "%s%p: address out of range\n",
5088 * FIXME : (void *) cast in virt_to_bus should be unnecessary, because
5089 * it should take const void * as argument.
5091 #if !defined(CONFIG_MVME16x) && !defined(CONFIG_BVME6000)
5092 sprintf(buf
, "%s0x%lx (virt 0x%p) : 0x%08x 0x%08x (virt 0x%p)",
5093 (prefix
? prefix
: ""), virt_to_bus((void *) insn
), insn
,
5094 insn
[0], insn
[1], bus_to_virt (insn
[1]));
5096 /* Remove virtual addresses to reduce output, as they are the same */
5097 sprintf(buf
, "%s0x%x (+%x) : 0x%08x 0x%08x",
5098 (prefix
? prefix
: ""), (u32
)insn
, ((u32
)insn
-
5099 (u32
)&(((struct NCR53c7x0_hostdata
*)host
->hostdata
[0])->script
))/4,
5102 tmp
= buf
+ strlen(buf
);
5103 if ((dcmd
& DCMD_TYPE_MASK
) == DCMD_TYPE_MMI
) {
5104 #if !defined(CONFIG_MVME16x) && !defined(CONFIG_BVME6000)
5105 sprintf (tmp
, " 0x%08x (virt 0x%p)\n", insn
[2],
5106 bus_to_virt(insn
[2]));
5108 /* Remove virtual addr to reduce output, as it is the same */
5109 sprintf (tmp
, " 0x%08x\n", insn
[2]);
5113 sprintf (tmp
, "\n");
5122 size_t len
= strlen(buf
);
5123 debugger_kernel_write(host
, buf
, len
);
5130 * Function : int NCR53c7xx_abort (Scsi_Cmnd *cmd)
5132 * Purpose : Abort an errant SCSI command, doing all necessary
5133 * cleanup of the issue_queue, running_list, shared Linux/NCR
5134 * dsa issue and reconnect queues.
5136 * Inputs : cmd - command to abort, code - entire result field
5138 * Returns : 0 on success, -1 on failure.
5142 NCR53c7xx_abort (Scsi_Cmnd
*cmd
) {
5143 NCR53c7x0_local_declare();
5144 struct Scsi_Host
*host
= cmd
->host
;
5145 struct NCR53c7x0_hostdata
*hostdata
= host
? (struct NCR53c7x0_hostdata
*)
5146 host
->hostdata
[0] : NULL
;
5147 unsigned long flags
;
5148 struct NCR53c7x0_cmd
*curr
, **prev
;
5149 Scsi_Cmnd
*me
, **last
;
5151 static long cache_pid
= -1;
5156 printk ("Bogus SCSI command pid %ld; no host structure\n",
5158 return SCSI_ABORT_ERROR
;
5159 } else if (!hostdata
) {
5160 printk ("Bogus SCSI host %d; no hostdata\n", host
->host_no
);
5161 return SCSI_ABORT_ERROR
;
5163 NCR53c7x0_local_setup(host
);
5166 * CHECK : I don't think that reading ISTAT will unstack any interrupts,
5167 * since we need to write the INTF bit to clear it, and SCSI/DMA
5168 * interrupts don't clear until we read SSTAT/SIST and DSTAT registers.
5170 * See that this is the case. Appears to be correct on the 710, at least.
5172 * I suspect that several of our failures may be coming from a new fatal
5173 * interrupt (possibly due to a phase mismatch) happening after we've left
5174 * the interrupt handler, but before the PIC has had the interrupt condition
5178 if (NCR53c7x0_read8(hostdata
->istat
) & (ISTAT_DIP
|ISTAT_SIP
)) {
5179 printk ("scsi%d : dropped interrupt for command %ld\n", host
->host_no
,
5181 NCR53c7x0_intr (host
->irq
, NULL
, NULL
);
5182 return SCSI_ABORT_BUSY
;
5188 if (cache_pid
== cmd
->pid
)
5189 panic ("scsi%d : bloody fetus %d\n", host
->host_no
, cmd
->pid
);
5191 cache_pid
= cmd
->pid
;
5196 * The command could be hiding in the issue_queue. This would be very
5197 * nice, as commands can't be moved from the high level driver's issue queue
5198 * into the shared queue until an interrupt routine is serviced, and this
5201 * If this is the case, we don't have to worry about anything - we simply
5202 * pull the command out of the old queue, and call it aborted.
5205 for (me
= (Scsi_Cmnd
*) hostdata
->issue_queue
,
5206 last
= (Scsi_Cmnd
**) &(hostdata
->issue_queue
);
5207 me
&& me
!= cmd
; last
= (Scsi_Cmnd
**)&(me
->SCp
.ptr
),
5208 me
= (Scsi_Cmnd
*)me
->SCp
.ptr
);
5211 *last
= (Scsi_Cmnd
*) me
->SCp
.ptr
;
5212 if (me
->host_scribble
) {
5213 ((struct NCR53c7x0_cmd
*)me
->host_scribble
)->next
= hostdata
->free
;
5214 hostdata
->free
= (struct NCR53c7x0_cmd
*) me
->host_scribble
;
5215 me
->host_scribble
= NULL
;
5217 cmd
->result
= DID_ABORT
<< 16;
5218 cmd
->scsi_done(cmd
);
5219 printk ("scsi%d : found command %ld in Linux issue queue\n",
5220 host
->host_no
, me
->pid
);
5221 restore_flags(flags
);
5222 run_process_issue_queue();
5223 return SCSI_ABORT_SUCCESS
;
5227 * That failing, the command could be in our list of already executing
5228 * commands. If this is the case, drastic measures are called for.
5231 for (curr
= (struct NCR53c7x0_cmd
*) hostdata
->running_list
,
5232 prev
= (struct NCR53c7x0_cmd
**) &(hostdata
->running_list
);
5233 curr
&& curr
->cmd
!= cmd
; prev
= (struct NCR53c7x0_cmd
**)
5234 &(curr
->next
), curr
= (struct NCR53c7x0_cmd
*) curr
->next
);
5237 if ((curr
->result
& 0xff) != 0xff && (curr
->result
& 0xff00) != 0xff00) {
5238 cmd
->result
= curr
->result
;
5240 *prev
= (struct NCR53c7x0_cmd
*) curr
->next
;
5241 curr
->next
= (struct NCR53c7x0_cmd
*) hostdata
->free
;
5242 cmd
->host_scribble
= NULL
;
5243 hostdata
->free
= curr
;
5244 cmd
->scsi_done(cmd
);
5245 printk ("scsi%d : found finished command %ld in running list\n",
5246 host
->host_no
, cmd
->pid
);
5247 restore_flags(flags
);
5248 return SCSI_ABORT_NOT_RUNNING
;
5250 printk ("scsi%d : DANGER : command running, can not abort.\n",
5251 cmd
->host
->host_no
);
5252 restore_flags(flags
);
5253 return SCSI_ABORT_BUSY
;
5258 * And if we couldn't find it in any of our queues, it must have been
5259 * a dropped interrupt.
5262 curr
= (struct NCR53c7x0_cmd
*) cmd
->host_scribble
;
5264 curr
->next
= hostdata
->free
;
5265 hostdata
->free
= curr
;
5266 cmd
->host_scribble
= NULL
;
5269 if (curr
== NULL
|| ((curr
->result
& 0xff00) == 0xff00) ||
5270 ((curr
->result
& 0xff) == 0xff)) {
5271 printk ("scsi%d : did this command ever run?\n", host
->host_no
);
5272 cmd
->result
= DID_ABORT
<< 16;
5274 printk ("scsi%d : probably lost INTFLY, normal completion\n",
5276 cmd
->result
= curr
->result
;
5278 * FIXME : We need to add an additional flag which indicates if a
5279 * command was ever counted as BUSY, so if we end up here we can
5280 * decrement the busy count if and only if it is necessary.
5282 --hostdata
->busy
[cmd
->target
][cmd
->lun
];
5284 restore_flags(flags
);
5285 cmd
->scsi_done(cmd
);
5288 * We need to run process_issue_queue since termination of this command
5289 * may allow another queued command to execute first?
5291 return SCSI_ABORT_NOT_RUNNING
;
5295 * Function : int NCR53c7xx_reset (Scsi_Cmnd *cmd)
5297 * Purpose : perform a hard reset of the SCSI bus and NCR
5300 * Inputs : cmd - command which caused the SCSI RESET
5302 * Returns : 0 on success.
5306 NCR53c7xx_reset (Scsi_Cmnd
*cmd
, unsigned int reset_flags
) {
5307 NCR53c7x0_local_declare();
5308 unsigned long flags
;
5310 struct NCR53c7x0_cmd
* c
;
5313 * When we call scsi_done(), it's going to wake up anything sleeping on the
5314 * resources which were in use by the aborted commands, and we'll start to
5317 * We can't let this happen until after we've re-initialized the driver
5318 * structures, and can't reinitialize those structures until after we've
5319 * dealt with their contents.
5321 * So, we need to find all of the commands which were running, stick
5322 * them on a linked list of completed commands (we'll use the host_scribble
5323 * pointer), do our reinitialization, and then call the done function for
5326 Scsi_Cmnd
*nuke_list
= NULL
;
5327 struct Scsi_Host
*host
= cmd
->host
;
5328 struct NCR53c7x0_hostdata
*hostdata
=
5329 (struct NCR53c7x0_hostdata
*) host
->hostdata
[0];
5331 NCR53c7x0_local_setup(host
);
5336 dump_events (host
, 30);
5337 ncr_scsi_reset (host
);
5338 for (tmp
= nuke_list
= return_outstanding_commands (host
, 1 /* free */,
5339 0 /* issue */ ); tmp
; tmp
= (Scsi_Cmnd
*) tmp
->SCp
.buffer
)
5346 * If we didn't find the command which caused this reset in our running
5347 * list, then we've lost it. See that it terminates normally anyway.
5350 c
= (struct NCR53c7x0_cmd
*) cmd
->host_scribble
;
5352 cmd
->host_scribble
= NULL
;
5353 c
->next
= hostdata
->free
;
5356 printk ("scsi%d: lost command %ld\n", host
->host_no
, cmd
->pid
);
5357 cmd
->SCp
.buffer
= (struct scatterlist
*) nuke_list
;
5361 NCR53c7x0_driver_init (host
);
5362 hostdata
->soft_reset (host
);
5363 if (hostdata
->resets
== 0)
5365 else if (hostdata
->resets
!= -1)
5367 restore_flags(flags
);
5368 for (; nuke_list
; nuke_list
= tmp
) {
5369 tmp
= (Scsi_Cmnd
*) nuke_list
->SCp
.buffer
;
5370 nuke_list
->result
= DID_RESET
<< 16;
5371 nuke_list
->scsi_done (nuke_list
);
5373 restore_flags(flags
);
5374 return SCSI_RESET_SUCCESS
;
5378 * The NCR SDMS bios follows Annex A of the SCSI-CAM draft, and
5379 * therefore shares the scsicam_bios_param function.
5383 * Function : int insn_to_offset (Scsi_Cmnd *cmd, u32 *insn)
5385 * Purpose : convert instructions stored at NCR pointer into data
5388 * Inputs : cmd - SCSI command; insn - pointer to instruction. Either current
5389 * DSP, or saved data pointer.
5391 * Returns : offset on success, -1 on failure.
5396 insn_to_offset (Scsi_Cmnd
*cmd
, u32
*insn
) {
5397 struct NCR53c7x0_hostdata
*hostdata
=
5398 (struct NCR53c7x0_hostdata
*) cmd
->host
->hostdata
[0];
5399 struct NCR53c7x0_cmd
*ncmd
=
5400 (struct NCR53c7x0_cmd
*) cmd
->host_scribble
;
5401 int offset
= 0, buffers
;
5402 struct scatterlist
*segment
;
5407 * With the current code implementation, if the insn is inside dynamically
5408 * generated code, the data pointer will be the instruction preceding
5409 * the next transfer segment.
5412 if (!check_address ((unsigned long) ncmd
, sizeof (struct NCR53c7x0_cmd
)) &&
5413 ((insn
>= ncmd
->data_transfer_start
&&
5414 insn
< ncmd
->data_transfer_end
) ||
5415 (insn
>= ncmd
->residual
&&
5416 insn
< (ncmd
->residual
+
5417 sizeof(ncmd
->residual
))))) {
5418 ptr
= bus_to_virt(insn
[3]);
5420 if ((buffers
= cmd
->use_sg
)) {
5422 segment
= (struct scatterlist
*) cmd
->buffer
;
5423 buffers
&& !((found
= ((ptr
>= segment
->address
) &&
5424 (ptr
< (segment
->address
+ segment
->length
)))));
5425 --buffers
, offset
+= segment
->length
, ++segment
)
5427 printk("scsi%d: comparing 0x%p to 0x%p\n",
5428 cmd
->host
->host_no
, saved
, segment
->address
);
5432 offset
+= ptr
- segment
->address
;
5435 offset
= ptr
- (char *) (cmd
->request_buffer
);
5437 } else if ((insn
>= hostdata
->script
+
5438 hostdata
->E_data_transfer
/ sizeof(u32
)) &&
5439 (insn
<= hostdata
->script
+
5440 hostdata
->E_end_data_transfer
/ sizeof(u32
))) {
5444 return found
? offset
: -1;
5450 * Function : void print_progress (Scsi_Cmnd *cmd)
5452 * Purpose : print the current location of the saved data pointer
5454 * Inputs : cmd - command we are interested in
5459 print_progress (Scsi_Cmnd
*cmd
) {
5460 NCR53c7x0_local_declare();
5461 struct NCR53c7x0_cmd
*ncmd
=
5462 (struct NCR53c7x0_cmd
*) cmd
->host_scribble
;
5466 NCR53c7x0_local_setup (cmd
->host
);
5468 if (check_address ((unsigned long) ncmd
,sizeof (struct NCR53c7x0_cmd
)) == 0)
5470 printk("\nNCR53c7x0_cmd fields:\n");
5471 printk(" bounce.len=0x%x, addr=0x%0x, buf[]=0x%02x %02x %02x %02x\n",
5472 ncmd
->bounce
.len
, ncmd
->bounce
.addr
, ncmd
->bounce
.buf
[0],
5473 ncmd
->bounce
.buf
[1], ncmd
->bounce
.buf
[2], ncmd
->bounce
.buf
[3]);
5474 printk(" result=%04x, cdb[0]=0x%02x\n", ncmd
->result
, ncmd
->cmnd
[0]);
5477 for (i
= 0; i
< 2; ++i
) {
5478 if (check_address ((unsigned long) ncmd
,
5479 sizeof (struct NCR53c7x0_cmd
)) == -1)
5483 ptr
= bus_to_virt(ncmd
->saved_data_pointer
);
5486 ptr
= bus_to_virt (NCR53c7x0_read32 (DSP_REG
) -
5487 NCR53c7x0_insn_size (NCR53c7x0_read8 (DCMD_REG
)) *
5490 offset
= insn_to_offset (cmd
, ptr
);
5493 printk ("scsi%d : %s data pointer at offset %d\n",
5494 cmd
->host
->host_no
, where
, offset
);
5497 printk ("scsi%d : can't determine %s data pointer offset\n",
5498 cmd
->host
->host_no
, where
);
5500 size
= print_insn (cmd
->host
,
5501 bus_to_virt(ncmd
->saved_data_pointer
), "", 1);
5502 print_insn (cmd
->host
,
5503 bus_to_virt(ncmd
->saved_data_pointer
) + size
* sizeof(u32
),
5512 print_dsa (struct Scsi_Host
*host
, u32
*dsa
, const char *prefix
) {
5513 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
5519 if (check_address ((unsigned long) dsa
, hostdata
->dsa_end
-
5520 hostdata
->dsa_start
) == -1) {
5521 printk("scsi%d : bad dsa virt 0x%p\n", host
->host_no
, dsa
);
5524 printk("%sscsi%d : dsa at phys 0x%lx (virt 0x%p)\n"
5525 " + %d : dsa_msgout length = %u, data = 0x%x (virt 0x%p)\n" ,
5526 prefix
? prefix
: "",
5527 host
->host_no
, virt_to_bus (dsa
), dsa
, hostdata
->dsa_msgout
,
5528 dsa
[hostdata
->dsa_msgout
/ sizeof(u32
)],
5529 dsa
[hostdata
->dsa_msgout
/ sizeof(u32
) + 1],
5530 bus_to_virt (dsa
[hostdata
->dsa_msgout
/ sizeof(u32
) + 1]));
5533 * Only print messages if they're sane in length so we don't
5534 * blow the kernel printk buffer on something which won't buy us
5538 if (dsa
[hostdata
->dsa_msgout
/ sizeof(u32
)] <
5539 sizeof (hostdata
->free
->select
))
5540 for (i
= dsa
[hostdata
->dsa_msgout
/ sizeof(u32
)],
5541 ptr
= bus_to_virt (dsa
[hostdata
->dsa_msgout
/ sizeof(u32
) + 1]);
5542 i
> 0 && !check_address ((unsigned long) ptr
, 1);
5543 ptr
+= len
, i
-= len
) {
5545 len
= print_msg (ptr
);
5551 printk(" + %d : select_indirect = 0x%x\n",
5552 hostdata
->dsa_select
, dsa
[hostdata
->dsa_select
/ sizeof(u32
)]);
5553 cmd
= (Scsi_Cmnd
*) bus_to_virt(dsa
[hostdata
->dsa_cmnd
/ sizeof(u32
)]);
5554 printk(" + %d : dsa_cmnd = 0x%x ", hostdata
->dsa_cmnd
,
5555 (u32
) virt_to_bus(cmd
));
5556 /* XXX Maybe we should access cmd->host_scribble->result here. RGH */
5558 printk(" result = 0x%x, target = %d, lun = %d, cmd = ",
5559 cmd
->result
, cmd
->target
, cmd
->lun
);
5560 print_command(cmd
->cmnd
);
5563 printk(" + %d : dsa_next = 0x%x\n", hostdata
->dsa_next
,
5564 dsa
[hostdata
->dsa_next
/ sizeof(u32
)]);
5566 printk("scsi%d target %d : sxfer_sanity = 0x%x, scntl3_sanity = 0x%x\n"
5568 host
->host_no
, cmd
->target
,
5569 hostdata
->sync
[cmd
->target
].sxfer_sanity
,
5570 hostdata
->sync
[cmd
->target
].scntl3_sanity
);
5571 for (i
= 0; i
< (sizeof(hostdata
->sync
[cmd
->target
].script
) / 4); ++i
)
5572 printk ("0x%x ", hostdata
->sync
[cmd
->target
].script
[i
]);
5574 print_progress (cmd
);
5578 * Function : void print_queues (Scsi_Host *host)
5580 * Purpose : print the contents of the NCR issue and reconnect queues
5582 * Inputs : host - SCSI host we are interested in
5587 print_queues (struct Scsi_Host
*host
) {
5588 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
5590 u32
*dsa
, *next_dsa
;
5591 volatile u32
*ncrcurrent
;
5593 Scsi_Cmnd
*cmd
, *next_cmd
;
5594 unsigned long flags
;
5596 printk ("scsi%d : issue queue\n", host
->host_no
);
5598 for (left
= host
->can_queue
, cmd
= (Scsi_Cmnd
*) hostdata
->issue_queue
;
5601 next_cmd
= (Scsi_Cmnd
*) cmd
->SCp
.ptr
;
5604 if (cmd
->host_scribble
) {
5605 if (check_address ((unsigned long) (cmd
->host_scribble
),
5606 sizeof (cmd
->host_scribble
)) == -1)
5607 printk ("scsi%d: scsi pid %ld bad pointer to NCR53c7x0_cmd\n",
5608 host
->host_no
, cmd
->pid
);
5609 /* print_dsa does sanity check on address, no need to check */
5611 print_dsa (host
, ((struct NCR53c7x0_cmd
*) cmd
->host_scribble
)
5614 printk ("scsi%d : scsi pid %ld for target %d lun %d has no NCR53c7x0_cmd\n",
5615 host
->host_no
, cmd
->pid
, cmd
->target
, cmd
->lun
);
5616 restore_flags(flags
);
5620 printk ("scsi%d : loop detected in issue queue\n",
5625 * Traverse the NCR reconnect and start DSA structures, printing out
5626 * each element until we hit the end or detect a loop. Currently,
5627 * the reconnect structure is a linked list; and the start structure
5628 * is an array. Eventually, the reconnect structure will become a
5629 * list as well, since this simplifies the code.
5632 printk ("scsi%d : schedule dsa array :\n", host
->host_no
);
5633 for (left
= host
->can_queue
, ncrcurrent
= hostdata
->schedule
;
5634 left
> 0; ncrcurrent
+= 2, --left
)
5635 if (ncrcurrent
[0] != hostdata
->NOP_insn
)
5636 /* FIXME : convert pointer to dsa_begin to pointer to dsa. */
5637 print_dsa (host
, bus_to_virt (ncrcurrent
[1] -
5638 (hostdata
->E_dsa_code_begin
-
5639 hostdata
->E_dsa_code_template
)), "");
5640 printk ("scsi%d : end schedule dsa array\n", host
->host_no
);
5642 printk ("scsi%d : reconnect_dsa_head :\n", host
->host_no
);
5644 for (left
= host
->can_queue
,
5645 dsa
= bus_to_virt (hostdata
->reconnect_dsa_head
);
5650 if (check_address ((unsigned long) dsa
, sizeof(dsa
)) == -1) {
5651 printk ("scsi%d: bad DSA pointer 0x%p", host
->host_no
,
5657 next_dsa
= bus_to_virt(dsa
[hostdata
->dsa_next
/ sizeof(u32
)]);
5658 print_dsa (host
, dsa
, "");
5660 restore_flags(flags
);
5662 printk ("scsi%d : end reconnect_dsa_head\n", host
->host_no
);
5664 printk("scsi%d: possible loop in ncr reconnect list\n",
5669 print_lots (struct Scsi_Host
*host
) {
5670 NCR53c7x0_local_declare();
5671 struct NCR53c7x0_hostdata
*hostdata
=
5672 (struct NCR53c7x0_hostdata
*) host
->hostdata
[0];
5673 u32
*dsp_next
, *dsp
, *dsa
, dbc_dcmd
;
5674 unsigned char dcmd
, sbcl
;
5676 NCR53c7x0_local_setup(host
);
5678 if ((dsp_next
= bus_to_virt(NCR53c7x0_read32 (DSP_REG
)))) {
5679 dbc_dcmd
= NCR53c7x0_read32(DBC_REG
);
5680 dcmd
= (dbc_dcmd
& 0xff000000) >> 24;
5681 dsp
= dsp_next
- NCR53c7x0_insn_size(dcmd
);
5682 dsa
= bus_to_virt(NCR53c7x0_read32(DSA_REG
));
5683 sbcl
= NCR53c7x0_read8 (SBCL_REG
);
5686 * For the 53c710, the following will report value 0 for SCNTL3
5687 * and STEST0 - we don't have these registers.
5689 printk ("scsi%d : DCMD|DBC=0x%x, DNAD=0x%x (virt 0x%p)\n"
5690 " DSA=0x%lx (virt 0x%p)\n"
5691 " DSPS=0x%x, TEMP=0x%x (virt 0x%p), DMODE=0x%x\n"
5692 " SXFER=0x%x, SCNTL3=0x%x\n"
5693 " %s%s%sphase=%s, %d bytes in SCSI FIFO\n"
5694 " SCRATCH=0x%x, saved2_dsa=0x%0lx\n",
5695 host
->host_no
, dbc_dcmd
, NCR53c7x0_read32(DNAD_REG
),
5696 bus_to_virt(NCR53c7x0_read32(DNAD_REG
)),
5697 virt_to_bus(dsa
), dsa
,
5698 NCR53c7x0_read32(DSPS_REG
), NCR53c7x0_read32(TEMP_REG
),
5699 bus_to_virt (NCR53c7x0_read32(TEMP_REG
)),
5700 (int) NCR53c7x0_read8(hostdata
->dmode
),
5701 (int) NCR53c7x0_read8(SXFER_REG
),
5702 ((hostdata
->chip
/ 100) == 8) ?
5703 (int) NCR53c7x0_read8(SCNTL3_REG_800
) : 0,
5704 (sbcl
& SBCL_BSY
) ? "BSY " : "",
5705 (sbcl
& SBCL_SEL
) ? "SEL " : "",
5706 (sbcl
& SBCL_REQ
) ? "REQ " : "",
5707 sstat2_to_phase(NCR53c7x0_read8 (((hostdata
->chip
/ 100) == 8) ?
5708 SSTAT1_REG
: SSTAT2_REG
)),
5709 (NCR53c7x0_read8 ((hostdata
->chip
/ 100) == 8 ?
5710 SSTAT1_REG
: SSTAT2_REG
) & SSTAT2_FF_MASK
) >> SSTAT2_FF_SHIFT
,
5711 ((hostdata
->chip
/ 100) == 8) ? NCR53c7x0_read8 (STEST0_REG_800
) :
5712 NCR53c7x0_read32(SCRATCHA_REG_800
),
5713 hostdata
->saved2_dsa
);
5714 printk ("scsi%d : DSP 0x%lx (virt 0x%p) ->\n", host
->host_no
,
5715 virt_to_bus(dsp
), dsp
);
5716 for (i
= 6; i
> 0; --i
, dsp
+= size
)
5717 size
= print_insn (host
, dsp
, "", 1);
5718 if (NCR53c7x0_read8 (SCNTL1_REG
) & SCNTL1_CON
) {
5719 if ((hostdata
->chip
/ 100) == 8)
5720 printk ("scsi%d : connected (SDID=0x%x, SSID=0x%x)\n",
5721 host
->host_no
, NCR53c7x0_read8 (SDID_REG_800
),
5722 NCR53c7x0_read8 (SSID_REG_800
));
5724 printk ("scsi%d : connected (SDID=0x%x)\n",
5725 host
->host_no
, NCR53c7x0_read8 (SDID_REG_700
));
5726 print_dsa (host
, dsa
, "");
5730 print_queues (host
);
5736 * Function : static int shutdown (struct Scsi_Host *host)
5738 * Purpose : does a clean (we hope) shutdown of the NCR SCSI
5739 * chip. Use prior to dumping core, unloading the NCR driver,
5741 * Returns : 0 on success
5744 shutdown (struct Scsi_Host
*host
) {
5745 NCR53c7x0_local_declare();
5746 unsigned long flags
;
5747 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
5749 NCR53c7x0_local_setup(host
);
5752 /* Get in a state where we can reset the SCSI bus */
5754 ncr_scsi_reset (host
);
5755 hostdata
->soft_reset(host
);
5758 restore_flags (flags
);
5763 * Function : void ncr_scsi_reset (struct Scsi_Host *host)
5765 * Purpose : reset the SCSI bus.
5769 ncr_scsi_reset (struct Scsi_Host
*host
) {
5770 NCR53c7x0_local_declare();
5771 unsigned long flags
;
5772 NCR53c7x0_local_setup(host
);
5775 NCR53c7x0_write8(SCNTL1_REG
, SCNTL1_RST
);
5776 udelay(25); /* Minimum amount of time to assert RST */
5777 NCR53c7x0_write8(SCNTL1_REG
, 0);
5778 restore_flags (flags
);
5782 * Function : void hard_reset (struct Scsi_Host *host)
5787 hard_reset (struct Scsi_Host
*host
) {
5788 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
5790 unsigned long flags
;
5793 ncr_scsi_reset(host
);
5794 NCR53c7x0_driver_init (host
);
5795 if (hostdata
->soft_reset
)
5796 hostdata
->soft_reset (host
);
5797 restore_flags(flags
);
5802 * Function : Scsi_Cmnd *return_outstanding_commands (struct Scsi_Host *host,
5803 * int free, int issue)
5805 * Purpose : return a linked list (using the SCp.buffer field as next,
5806 * so we don't perturb hostdata. We don't use a field of the
5807 * NCR53c7x0_cmd structure since we may not have allocated one
5808 * for the command causing the reset.) of Scsi_Cmnd structures that
5809 * had propogated below the Linux issue queue level. If free is set,
5810 * free the NCR53c7x0_cmd structures which are associated with
5811 * the Scsi_Cmnd structures, and clean up any internal
5812 * NCR lists that the commands were on. If issue is set,
5813 * also return commands in the issue queue.
5815 * Returns : linked list of commands
5817 * NOTE : the caller should insure that the NCR chip is halted
5818 * if the free flag is set.
5822 return_outstanding_commands (struct Scsi_Host
*host
, int free
, int issue
) {
5823 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
5825 struct NCR53c7x0_cmd
*c
;
5828 Scsi_Cmnd
*list
= NULL
, *tmp
;
5829 for (c
= (struct NCR53c7x0_cmd
*) hostdata
->running_list
; c
;
5830 c
= (struct NCR53c7x0_cmd
*) c
->next
) {
5831 if (c
->cmd
->SCp
.buffer
) {
5832 printk ("scsi%d : loop detected in running list!\n", host
->host_no
);
5835 printk ("Duh? Bad things happening in the NCR driver\n");
5839 c
->cmd
->SCp
.buffer
= (struct scatterlist
*) list
;
5842 c
->next
= hostdata
->free
;
5848 for (i
= 0, ncrcurrent
= (u32
*) hostdata
->schedule
;
5849 i
< host
->can_queue
; ++i
, ncrcurrent
+= 2) {
5850 ncrcurrent
[0] = hostdata
->NOP_insn
;
5851 ncrcurrent
[1] = 0xdeadbeef;
5853 hostdata
->ncrcurrent
= NULL
;
5857 for (tmp
= (Scsi_Cmnd
*) hostdata
->issue_queue
; tmp
; tmp
= tmp
->next
) {
5858 if (tmp
->SCp
.buffer
) {
5859 printk ("scsi%d : loop detected in issue queue!\n",
5863 tmp
->SCp
.buffer
= (struct scatterlist
*) list
;
5867 hostdata
->issue_queue
= NULL
;
5874 * Function : static int disable (struct Scsi_Host *host)
5876 * Purpose : disables the given NCR host, causing all commands
5877 * to return a driver error. Call this so we can unload the
5878 * module during development and try again. Eventually,
5879 * we should be able to find clean workarounds for these
5882 * Inputs : host - hostadapter to twiddle
5884 * Returns : 0 on success.
5888 disable (struct Scsi_Host
*host
) {
5889 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
5891 unsigned long flags
;
5892 Scsi_Cmnd
*nuke_list
, *tmp
;
5895 if (hostdata
->state
!= STATE_HALTED
)
5897 nuke_list
= return_outstanding_commands (host
, 1 /* free */, 1 /* issue */);
5899 hostdata
->state
= STATE_DISABLED
;
5900 restore_flags(flags
);
5901 printk ("scsi%d : nuking commands\n", host
->host_no
);
5902 for (; nuke_list
; nuke_list
= tmp
) {
5903 tmp
= (Scsi_Cmnd
*) nuke_list
->SCp
.buffer
;
5904 nuke_list
->result
= DID_ERROR
<< 16;
5905 nuke_list
->scsi_done(nuke_list
);
5907 printk ("scsi%d : done. \n", host
->host_no
);
5908 printk (KERN_ALERT
"scsi%d : disabled. Unload and reload\n",
5914 * Function : static int ncr_halt (struct Scsi_Host *host)
5916 * Purpose : halts the SCSI SCRIPTS(tm) processor on the NCR chip
5918 * Inputs : host - SCSI chip to halt
5920 * Returns : 0 on success
5924 ncr_halt (struct Scsi_Host
*host
) {
5925 NCR53c7x0_local_declare();
5926 unsigned long flags
;
5927 unsigned char istat
, tmp
;
5928 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
5931 NCR53c7x0_local_setup(host
);
5935 /* Stage 0 : eat all interrupts
5937 Stage 2 : eat all but abort interrupts
5938 Stage 3 : eat all interrupts
5942 NCR53c7x0_write8(hostdata
->istat
, ISTAT_ABRT
);
5945 istat
= NCR53c7x0_read8 (hostdata
->istat
);
5946 if (istat
& ISTAT_SIP
) {
5947 tmp
= NCR53c7x0_read8(SSTAT0_REG
);
5948 } else if (istat
& ISTAT_DIP
) {
5949 tmp
= NCR53c7x0_read8(DSTAT_REG
);
5951 if (tmp
& DSTAT_ABRT
) {
5952 NCR53c7x0_write8(hostdata
->istat
, 0);
5955 printk(KERN_ALERT
"scsi%d : could not halt NCR chip\n",
5961 if (!(istat
& (ISTAT_SIP
|ISTAT_DIP
))) {
5964 else if (stage
== 3)
5968 hostdata
->state
= STATE_HALTED
;
5969 restore_flags(flags
);
5977 * Function: event_name (int event)
5979 * Purpose: map event enum into user-readable strings.
5983 event_name (int event
) {
5985 case EVENT_NONE
: return "none";
5986 case EVENT_ISSUE_QUEUE
: return "to issue queue";
5987 case EVENT_START_QUEUE
: return "to start queue";
5988 case EVENT_SELECT
: return "selected";
5989 case EVENT_DISCONNECT
: return "disconnected";
5990 case EVENT_RESELECT
: return "reselected";
5991 case EVENT_COMPLETE
: return "completed";
5992 case EVENT_IDLE
: return "idle";
5993 case EVENT_SELECT_FAILED
: return "select failed";
5994 case EVENT_BEFORE_SELECT
: return "before select";
5995 case EVENT_RESELECT_FAILED
: return "reselect failed";
5996 default: return "unknown";
6001 * Function : void dump_events (struct Scsi_Host *host, count)
6003 * Purpose : print last count events which have occurred.
6006 dump_events (struct Scsi_Host
*host
, int count
) {
6007 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
6009 struct NCR53c7x0_event event
;
6011 unsigned long flags
;
6012 if (hostdata
->events
) {
6013 if (count
> hostdata
->event_size
)
6014 count
= hostdata
->event_size
;
6015 for (i
= hostdata
->event_index
; count
> 0;
6016 i
= (i
? i
- 1 : hostdata
->event_size
-1), --count
) {
6019 * By copying the event we're currently examining with interrupts
6020 * disabled, we can do multiple printk(), etc. operations and
6021 * still be guaranteed that they're happening on the same
6026 event
= hostdata
->events
[i
];
6028 memcpy ((void *) &event
, (void *) &(hostdata
->events
[i
]),
6032 restore_flags(flags
);
6033 printk ("scsi%d : %s event %d at %ld secs %ld usecs target %d lun %d\n",
6034 host
->host_no
, event_name (event
.event
), count
,
6035 (long) event
.time
.tv_sec
, (long) event
.time
.tv_usec
,
6036 event
.target
, event
.lun
);
6038 printk (" event for dsa 0x%lx (virt 0x%p)\n",
6039 virt_to_bus(event
.dsa
), event
.dsa
);
6040 if (event
.pid
!= -1) {
6041 printk (" event for pid %ld ", event
.pid
);
6042 print_command (event
.cmnd
);
6049 * Function: check_address
6051 * Purpose: Check to see if a possibly corrupt pointer will fault the
6054 * Inputs: addr - address; size - size of area
6056 * Returns: 0 if area is OK, -1 on error.
6058 * NOTES: should be implemented in terms of vverify on kernels
6063 check_address (unsigned long addr
, int size
) {
6064 return (virt_to_phys((void *)addr
) < PAGE_SIZE
|| virt_to_phys((void *)(addr
+ size
)) > virt_to_phys(high_memory
) ? -1 : 0);
6069 NCR53c7x0_release(struct Scsi_Host
*host
) {
6070 struct NCR53c7x0_hostdata
*hostdata
=
6071 (struct NCR53c7x0_hostdata
*) host
->hostdata
[0];
6072 struct NCR53c7x0_cmd
*cmd
, *tmp
;
6074 if (host
->irq
!= IRQ_NONE
)
6077 struct Scsi_Host
*tmp
;
6078 for (irq_count
= 0, tmp
= first_host
; tmp
; tmp
= tmp
->next
)
6079 if (tmp
->hostt
== the_template
&& tmp
->irq
== host
->irq
)
6082 free_irq(host
->irq
, NULL
);
6084 if (host
->dma_channel
!= DMA_NONE
)
6085 free_dma(host
->dma_channel
);
6087 release_region(host
->io_port
, host
->n_io_port
);
6089 for (cmd
= (struct NCR53c7x0_cmd
*) hostdata
->free
; cmd
; cmd
= tmp
,
6090 --hostdata
->num_cmds
) {
6091 tmp
= (struct NCR53c7x0_cmd
*) cmd
->next
;
6093 * If we're going to loop, try to stop it to get a more accurate
6094 * count of the leaked commands.
6098 cmd
->free ((void *) cmd
->real
, cmd
->size
);
6100 if (hostdata
->num_cmds
)
6101 printk ("scsi%d : leaked %d NCR53c7x0_cmd structures\n",
6102 host
->host_no
, hostdata
->num_cmds
);
6103 if (hostdata
->events
)
6104 vfree ((void *)hostdata
->events
);
6106 /* XXX This assumes default cache mode to be IOMAP_FULL_CACHING, which
6107 * XXX may be invalid (CONFIG_060_WRITETHROUGH)
6109 kernel_set_cachemode((u32
)hostdata
, 8192, IOMAP_FULL_CACHING
);
6110 free_pages ((u32
)hostdata
, 1);
6113 #endif /* def MODULE */
6115 static Scsi_Host_Template driver_template
= NCR53c7xx
;
6116 #include "scsi_module.c"