2 * PERM_OPTIONS are driver options which will be enabled for all NCR boards
3 * in the system at driver initialization time.
5 * Don't THINK about touching these in PERM_OPTIONS :
7 * Memory mapped IO does not work under i86 Linux.
10 * Test 1 does bus mastering and interrupt tests, which will help weed
11 * out brain damaged main boards.
13 * These are development kernel changes. Code for them included in this
14 * driver release may or may not work. If you turn them on, you should be
15 * running the latest copy of the development sources from
17 * ftp://tsx-11.mit.edu/pub/linux/ALPHA/scsi/53c7,8xx
19 * and be subscribed to the ncr53c810@colorado.edu mailing list. To
20 * subscribe, send mail to majordomo@colorado.edu with
28 * Don't negotiate for asynchronous transfers on the first command
29 * when OPTION_ALWAYS_SYNCHRONOUS is set. Useful for dain bramaged
30 * devices which do something bad rather than sending a MESSAGE
31 * REJECT back to us like they should if they can't cope.
34 * Enable support for synchronous transfers. Target negotiated
35 * synchronous transfers will be responded to. To initiate
36 * a synchronous transfer request, call
38 * request_synchronous (hostno, target)
42 * OPTION_ALWAYS_SYNCHRONOUS
43 * Negotiate for synchronous transfers with every target after
44 * driver initialization or a SCSI bus reset. This is a bit dangerous,
45 * since there are some dain bramaged SCSI devices which will accept
46 * SDTR messages but keep talking asynchronously.
49 * Enable support for disconnect/reconnect. To change the
50 * default setting on a given host adapter, call
52 * request_disconnect (hostno, allow)
54 * where allow is non-zero to allow, 0 to disallow.
56 * If you really want to run 10MHz FAST SCSI-II transfers, you should
57 * know that the NCR driver currently ignores parity information. Most
58 * systems do 5MHz SCSI fine. I've seen a lot that have problems faster
59 * than 8MHz. To play it safe, we only request 5MHz transfers.
61 * If you'd rather get 10MHz transfers, edit sdtr_message and change
62 * the fourth byte from 50 to 25.
65 #include <linux/config.h>
67 #ifdef CONFIG_SCSI_NCR53C7xx_sync
68 #ifdef CONFIG_SCSI_NCR53C7xx_DISCONNECT
69 #define PERM_OPTIONS (OPTION_IO_MAPPED|OPTION_DEBUG_TEST1|OPTION_DISCONNECT|\
70 OPTION_SYNCHRONOUS|OPTION_ALWAYS_SYNCHRONOUS)
72 #define PERM_OPTIONS (OPTION_IO_MAPPED|OPTION_DEBUG_TEST1|\
73 OPTION_SYNCHRONOUS|OPTION_ALWAYS_SYNCHRONOUS)
76 #ifdef CONFIG_SCSI_NCR53C7xx_DISCONNECT
77 #define PERM_OPTIONS (OPTION_IO_MAPPED|OPTION_DEBUG_TEST1|OPTION_DISCONNECT|\
80 #define PERM_OPTIONS (OPTION_IO_MAPPED|OPTION_DEBUG_TEST1|OPTION_SYNCHRONOUS)
86 * iX Multiuser Multitasking Magazine
90 * Copyright 1993, 1994, 1995 Drew Eckhardt
92 * (Unix and Linux consulting and custom programming)
96 * TolerANT and SCSI SCRIPTS are registered trademarks of NCR Corporation.
98 * For more information, please consult
105 * PCI-SCSI I/O Processor
109 * PCI-SCSI I/O Processor Design In Guide
111 * For literature on Symbios Logic Inc. formerly NCR, SCSI,
112 * and Communication products please call (800) 334-5454 or
115 * PCI BIOS Specification Revision
116 * PCI Local Bus Specification
117 * PCI System Design Guide
119 * PCI Special Interest Group
121 * 5200 N.E. Elam Young Parkway
122 * Hillsboro, Oregon 97124-6497
129 * The cumulative latency needed to propagate a read/write request
130 * through the file system, buffer cache, driver stacks, SCSI host, and
131 * SCSI device is ultimately the limiting factor in throughput once we
132 * have a sufficiently fast host adapter.
134 * So, to maximize performance we want to keep the ratio of latency to data
135 * transfer time to a minimum by
136 * 1. Minimizing the total number of commands sent (typical command latency
137 * including drive and bus mastering host overhead is as high as 4.5ms)
138 * to transfer a given amount of data.
140 * This is accomplished by placing no arbitrary limit on the number
141 * of scatter/gather buffers supported, since we can transfer 1K
142 * per scatter/gather buffer without Eric's cluster patches,
145 * 2. Minimizing the number of fatal interrupts serviced, since
146 * fatal interrupts halt the SCSI I/O processor. Basically,
147 * this means offloading the practical maximum amount of processing
150 * On the NCR53c810/820/720, this is accomplished by using
151 * interrupt-on-the-fly signals when commands complete,
152 * and only handling fatal errors and SDTR / WDTR messages
155 * On the NCR53c710, interrupts are generated as on the NCR53c8x0,
156 * only the lack of an interrupt-on-the-fly facility complicates
157 * things. Also, SCSI ID registers and commands are
158 * bit fielded rather than binary encoded.
160 * On the NCR53c700 and NCR53c700-66, operations that are done via
161 * indirect, table mode on the more advanced chips must be
162 * replaced by calls through a jump table which
163 * acts as a surrogate for the DSA. Unfortunately, this
164 * will mean that we must service an interrupt for each
165 * disconnect/reconnect.
167 * 3. Eliminating latency by pipelining operations at the different levels.
169 * This driver allows a configurable number of commands to be enqueued
170 * for each target/lun combination (experimentally, I have discovered
171 * that two seems to work best) and will ultimately allow for
172 * SCSI-II tagged queuing.
176 * This driver is built around a Linux queue of commands waiting to
177 * be executed, and a shared Linux/NCR array of commands to start. Commands
178 * are transfered to the array by the run_process_issue_queue() function
179 * which is called whenever a command completes.
181 * As commands are completed, the interrupt routine is triggered,
182 * looks for commands in the linked list of completed commands with
183 * valid status, removes these commands from a list of running commands,
184 * calls the done routine, and flags their target/luns as not busy.
186 * Due to limitations in the intelligence of the NCR chips, certain
187 * concessions are made. In many cases, it is easier to dynamically
188 * generate/fix-up code rather than calculate on the NCR at run time.
189 * So, code is generated or fixed up for
191 * - Handling data transfers, using a variable number of MOVE instructions
192 * interspersed with CALL MSG_IN, WHEN MSGIN instructions.
194 * The DATAIN and DATAOUT routines are separate, so that an incorrect
195 * direction can be trapped, and space isn't wasted.
197 * It may turn out that we're better off using some sort
198 * of table indirect instruction in a loop with a variable
199 * sized table on the NCR53c710 and newer chips.
201 * - Checking for reselection (NCR53c710 and better)
203 * - Handling the details of SCSI context switches (NCR53c710 and better),
204 * such as reprogramming appropriate synchronous parameters,
205 * removing the dsa structure from the NCR's queue of outstanding
211 * Accommodate differences between stock 1.2.x and 1.3.x asm-i386/types.h
212 * so lusers can drop in 53c7,8xx.* and get something which compiles
216 #if !defined(LINUX_1_2) && !defined(LINUX_1_3)
217 #include <linux/version.h>
218 #if LINUX_VERSION_CODE > 65536 + 3 * 256
226 #define u32 bogus_u32
227 #define s32 bogus_s32
228 #include <asm/types.h>
231 typedef __signed__
int s32
;
232 typedef unsigned int u32
;
233 #endif /* def LINUX_1_2 */
236 #include <linux/module.h>
241 #include <asm/system.h>
242 #include <linux/delay.h>
243 #include <linux/signal.h>
244 #include <linux/sched.h>
245 #include <linux/errno.h>
246 #include <linux/bios32.h>
247 #include <linux/pci.h>
248 #include <linux/proc_fs.h>
249 #include <linux/string.h>
250 #include <linux/malloc.h>
251 #include <linux/vmalloc.h>
252 #include <linux/mm.h>
253 #include <linux/ioport.h>
254 #include <linux/time.h>
255 #include <linux/blk.h>
256 #include <linux/init.h>
260 #include "53c7,8xx.h"
261 #include "constants.h"
263 #include <linux/stat.h>
264 #include <linux/stddef.h>
267 struct proc_dir_entry proc_scsi_ncr53c7xx
= {
268 PROC_SCSI_NCR53C7xx
, 9, "ncr53c7xx",
269 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2
273 static int check_address (unsigned long addr
, int size
);
274 static void dump_events (struct Scsi_Host
*host
, int count
);
275 static Scsi_Cmnd
* return_outstanding_commands (struct Scsi_Host
*host
,
276 int free
, int issue
);
277 static void hard_reset (struct Scsi_Host
*host
);
278 static void ncr_scsi_reset (struct Scsi_Host
*host
);
279 static void print_lots (struct Scsi_Host
*host
);
280 static void set_synchronous (struct Scsi_Host
*host
, int target
, int sxfer
,
281 int scntl3
, int now_connected
);
282 static int datapath_residual (struct Scsi_Host
*host
);
283 static const char * sbcl_to_phase (int sbcl
);
284 static void print_progress (Scsi_Cmnd
*cmd
);
285 static void print_queues (struct Scsi_Host
*host
);
286 static void process_issue_queue (unsigned long flags
);
287 static int shutdown (struct Scsi_Host
*host
);
288 static void abnormal_finished (struct NCR53c7x0_cmd
*cmd
, int result
);
289 static int disable (struct Scsi_Host
*host
);
290 static int NCR53c8xx_run_tests (struct Scsi_Host
*host
);
291 static int NCR53c8xx_script_len
;
292 static int NCR53c8xx_dsa_len
;
293 static void NCR53c7x0_intr(int irq
, void *dev_id
, struct pt_regs
* regs
);
294 static int ncr_halt (struct Scsi_Host
*host
);
295 static void intr_phase_mismatch (struct Scsi_Host
*host
, struct NCR53c7x0_cmd
297 static void intr_dma (struct Scsi_Host
*host
, struct NCR53c7x0_cmd
*cmd
);
298 static void print_dsa (struct Scsi_Host
*host
, u32
*dsa
,
300 static int print_insn (struct Scsi_Host
*host
, const u32
*insn
,
301 const char *prefix
, int kernel
);
303 static void NCR53c8xx_dsa_fixup (struct NCR53c7x0_cmd
*cmd
);
304 static void NCR53c8x0_init_fixup (struct Scsi_Host
*host
);
305 static int NCR53c8x0_dstat_sir_intr (struct Scsi_Host
*host
, struct
307 static void NCR53c8x0_soft_reset (struct Scsi_Host
*host
);
309 /* INSMOD variables */
310 static long long perm_options
= PERM_OPTIONS
;
311 /* 14 = .5s; 15 is max; decreasing divides by two. */
312 static int selection_timeout
= 14;
313 /* Size of event list (per host adapter) */
314 static int track_events
= 0;
316 static struct Scsi_Host
*first_host
= NULL
; /* Head of list of NCR boards */
317 static Scsi_Host_Template
*the_template
= NULL
;
321 * - There is some sort of conflict when the PPP driver is compiled with
322 * support for 16 channels?
324 * - On systems which predate the 1.3.x initialization order change,
325 * the NCR driver will cause Cannot get free page messages to appear.
326 * These are harmless, but I don't know of an easy way to avoid them.
328 * - With OPTION_DISCONNECT, on two systems under unknown circumstances,
329 * we get a PHASE MISMATCH with DSA set to zero (suggests that we
330 * are occurring somewhere in the reselection code) where
331 * DSP=some value DCMD|DBC=same value.
333 * Closer inspection suggests that we may be trying to execute
334 * some portion of the DSA?
335 * scsi0 : handling residual transfer (+ 0 bytes from DMA FIFO)
336 * scsi0 : handling residual transfer (+ 0 bytes from DMA FIFO)
337 * scsi0 : no current command : unexpected phase MSGIN.
338 * DSP=0x1c46cc, DCMD|DBC=0x1c46ac, DSA=0x0
339 * DSPS=0x0, TEMP=0x1c3e70, DMODE=0x80
341 * 001c46cc : 0x001c46cc 0x00000000
342 * 001c46d4 : 0x001c5ea0 0x000011f8
344 * Changed the print code in the phase_mismatch handler so
345 * that we call print_lots to try to diagnose this.
350 * Possible future direction of architecture for max performance :
352 * We're using a single start array for the NCR chip. This is
353 * sub-optimal, because we cannot add a command which would conflict with
354 * an executing command to this start queue, and therefore must insert the
355 * next command for a given I/T/L combination after the first has completed;
356 * incurring our interrupt latency between SCSI commands.
358 * To allow further pipelining of the NCR and host CPU operation, we want
359 * to set things up so that immediately on termination of a command destined
360 * for a given LUN, we get that LUN busy again.
362 * To do this, we need to add a 32 bit pointer to which is jumped to
363 * on completion of a command. If no new command is available, this
364 * would point to the usual DSA issue queue select routine.
366 * If one were, it would point to a per-NCR53c7x0_cmd select routine
367 * which starts execution immediately, inserting the command at the head
368 * of the start queue if the NCR chip is selected or reselected.
370 * We would change so that we keep a list of outstanding commands
371 * for each unit, rather than a single running_list. We'd insert
372 * a new command into the right running list; if the NCR didn't
373 * have something running for that yet, we'd put it in the
374 * start queue as well. Some magic needs to happen to handle the
375 * race condition between the first command terminating before the
376 * new one is written.
378 * Potential for profiling :
379 * Call do_gettimeofday(struct timeval *tv) to get 800ns resolution.
385 * 1. To support WIDE transfers, not much needs to happen. We
386 * should do CHMOVE instructions instead of MOVEs when
387 * we have scatter/gather segments of uneven length. When
388 * we do this, we need to handle the case where we disconnect
391 * 2. Currently, when Icky things happen we do a FATAL(). Instead,
392 * we want to do an integrity check on the parts of the NCR hostdata
393 * structure which were initialized at boot time; FATAL() if that
394 * fails, and otherwise try to recover. Keep track of how many
395 * times this has happened within a single SCSI command; if it
396 * gets excessive, then FATAL().
398 * 3. Parity checking is currently disabled, and a few things should
399 * happen here now that we support synchronous SCSI transfers :
400 * 1. On soft-reset, we should set the EPC (Enable Parity Checking)
401 * and AAP (Assert SATN/ on parity error) bits in SCNTL0.
403 * 2. We should enable the parity interrupt in the SIEN0 register.
405 * 3. intr_phase_mismatch() needs to believe that message out is
406 * always an "acceptable" phase to have a mismatch in. If
407 * the old phase was MSG_IN, we should send a MESSAGE PARITY
408 * error. If the old phase was something else, we should send
409 * a INITIATOR_DETECTED_ERROR message. Note that this could
410 * cause a RESTORE POINTERS message; so we should handle that
411 * correctly first. Instead, we should probably do an
414 * 4. MPEE bit of CTEST4 should be set so we get interrupted if
415 * we detect an error.
418 * 5. The initial code has been tested on the NCR53c810. I don't
419 * have access to NCR53c700, 700-66 (Forex boards), NCR53c710
420 * (NCR Pentium systems), NCR53c720, NCR53c820, or NCR53c825 boards to
421 * finish development on those platforms.
423 * NCR53c820/825/720 - need to add wide transfer support, including WDTR
424 * negotiation, programming of wide transfer capabilities
425 * on reselection and table indirect selection.
427 * NCR53c710 - need to add fatal interrupt or GEN code for
428 * command completion signaling. Need to modify all
429 * SDID, SCID, etc. registers, and table indirect select code
430 * since these use bit fielded (ie 1<<target) instead of
431 * binary encoded target ids. Need to accommodate
432 * different register mappings, probably scan through
433 * the SCRIPT code and change the non SFBR register operand
434 * of all MOVE instructions.
436 * NCR53c700/700-66 - need to add code to refix addresses on
437 * every nexus change, eliminate all table indirect code,
440 * 6. The NCR53c7x0 series is very popular on other platforms that
441 * could be running Linux - ie, some high performance AMIGA SCSI
444 * So, I should include #ifdef'd code so that it is
445 * compatible with these systems.
447 * Specifically, the little Endian assumptions I made in my
448 * bit fields need to change, and if the NCR doesn't see memory
449 * the right way, we need to provide options to reverse words
450 * when the scripts are relocated.
452 * 7. Use ioremap() to access memory mapped boards.
456 * Allow for simultaneous existence of multiple SCSI scripts so we
457 * can have a single driver binary for all of the family.
459 * - one for NCR53c700 and NCR53c700-66 chips (not yet supported)
460 * - one for rest (only the NCR53c810, 815, 820, and 825 are currently
463 * So that we only need two SCSI scripts, we need to modify things so
464 * that we fixup register accesses in READ/WRITE instructions, and
465 * we'll also have to accommodate the bit vs. binary encoding of IDs
466 * with the 7xx chips.
470 * Use pci_chips_ids to translate in both directions between PCI device ID
475 unsigned short pci_device_id
;
478 * The revision field of the PCI_CLASS_REVISION register is compared
479 * against each of these fields if the field is not -1. If it
480 * is less than min_revision or larger than max_revision, a warning
481 * message is printed.
486 {PCI_DEVICE_ID_NCR_53C810
, 810, 2, 1},
487 {PCI_DEVICE_ID_NCR_53C815
, 815, 3, 2},
488 {PCI_DEVICE_ID_NCR_53C820
, 820, -1, -1},
489 {PCI_DEVICE_ID_NCR_53C825
, 825, -1, -1}
492 #define NPCI_CHIP_IDS (sizeof (pci_chip_ids) / sizeof(pci_chip_ids[0]))
494 #define ROUNDUP(adr,type) \
495 ((void *) (((long) (adr) + sizeof(type) - 1) & ~(sizeof(type) - 1)))
498 * Forced detection and autoprobe code for various hardware. Currently,
499 * entry points for these are not included in init/main.c because if the
500 * PCI BIOS code isn't working right, you're not going to be able to use
501 * the hardware anyways; this way we force users to solve their
502 * problems rather than forcing detection and blaming us when it
506 static struct override
{
507 int chip
; /* 700, 70066, 710, 720, 810, 820 */
508 int board
; /* Any special board level gunk */
512 int base
; /* Memory address - indicates memory mapped regs */
513 int io_port
;/* I/O port address - indicates I/O mapped regs */
514 int irq
; /* IRQ line */
515 int dma
; /* DMA channel - often none */
524 } overrides
[4] = {{0,},};
525 static int commandline_current
= 0;
526 static int no_overrides
= 0;
529 #define OVERRIDE_LIMIT (sizeof(overrides) / sizeof(struct override))
531 #define OVERRIDE_LIMIT commandline_current
535 * Function: issue_to_cmd
537 * Purpose: convert jump instruction in issue array to NCR53c7x0_cmd
540 * Inputs; issue - pointer to start of NOP or JUMP instruction
543 * Returns: pointer to command on success; 0 if opcode is NOP.
546 static inline struct NCR53c7x0_cmd
*
547 issue_to_cmd (struct Scsi_Host
*host
, struct NCR53c7x0_hostdata
*hostdata
,
550 return (issue
[0] != hostdata
->NOP_insn
) ?
552 * If the IF TRUE bit is set, it's a JUMP instruction. The
553 * operand is a bus pointer to the dsa_begin routine for this DSA. The
554 * dsa field of the NCR53c7x0_cmd structure starts with the
555 * DSA code template. By converting to a virtual address,
556 * subtracting the code template size, and offset of the
557 * dsa field, we end up with a pointer to the start of the
558 * structure (alternatively, we could use the
559 * dsa_cmnd field, an anachronism from when we weren't
560 * sure what the relationship between the NCR structures
561 * and host structures were going to be.
563 (struct NCR53c7x0_cmd
*) ((char *) bus_to_virt (le32_to_cpu(issue
[1])) -
564 (hostdata
->E_dsa_code_begin
- hostdata
->E_dsa_code_template
) -
565 offsetof(struct NCR53c7x0_cmd
, dsa
))
566 /* If the IF TRUE bit is not set, it's a NOP */
572 * Function : static internal_setup(int board, int chip, char *str, int *ints)
574 * Purpose : LILO command line initialization of the overrides array,
576 * Inputs : board - currently, unsupported. chip - 700, 70066, 710, 720
577 * 810, 815, 820, 825, although currently only the NCR53c810 is
583 internal_setup(int board
, int chip
, char *str
, int *ints
) {
584 unsigned char pci
; /* Specifies a PCI override, with bus, device,
587 pci
= (str
&& !strcmp (str
, "pci")) ? 1 : 0;
590 * Override syntaxes are as follows :
591 * ncr53c700,ncr53c700-66,ncr53c710,ncr53c720=mem,io,irq,dma
592 * ncr53c810,ncr53c820,ncr53c825=mem,io,irq or pci,bus,device,function
595 if (commandline_current
< OVERRIDE_LIMIT
) {
596 overrides
[commandline_current
].pci
= pci
? 1 : 0;
598 overrides
[commandline_current
].data
.normal
.base
= ints
[1];
599 overrides
[commandline_current
].data
.normal
.io_port
= ints
[2];
600 overrides
[commandline_current
].data
.normal
.irq
= ints
[3];
601 overrides
[commandline_current
].data
.normal
.dma
= (ints
[0] >= 4) ?
603 /* FIXME: options is now a long long */
604 overrides
[commandline_current
].options
= (ints
[0] >= 5) ?
607 overrides
[commandline_current
].data
.pci
.bus
= ints
[1];
608 overrides
[commandline_current
].data
.pci
.device
= ints
[2];
609 overrides
[commandline_current
].data
.pci
.function
= ints
[3];
610 /* FIXME: options is now a long long */
611 overrides
[commandline_current
].options
= (ints
[0] >= 4) ?
614 overrides
[commandline_current
].board
= board
;
615 overrides
[commandline_current
].chip
= chip
;
616 ++commandline_current
;
619 printk ("53c7,7x0.c:internal_setup() : too many overrides\n");
624 * XXX - we might want to implement a single override function
625 * with a chip type field, revamp the command line configuration,
629 #define setup_wrapper(x) \
630 void ncr53c##x##_setup (char *str, int *ints) { \
631 internal_setup (BOARD_GENERIC, x, str, ints); \
644 * FIXME: we should junk these, in favor of synchronous_want and
645 * wide_want in the NCR53c7x0_hostdata structure.
648 /* Template for "preferred" synchronous transfer parameters. */
650 static const unsigned char sdtr_message
[] = {
651 #ifdef CONFIG_SCSI_NCR53C7xx_FAST
652 EXTENDED_MESSAGE
, 3 /* length */, EXTENDED_SDTR
, 25 /* *4ns */, 8 /* off */
654 EXTENDED_MESSAGE
, 3 /* length */, EXTENDED_SDTR
, 50 /* *4ns */, 8 /* off */
658 /* Template to request asynchronous transfers */
660 static const unsigned char async_message
[] = {
661 EXTENDED_MESSAGE
, 3 /* length */, EXTENDED_SDTR
, 0, 0 /* asynchronous */
664 /* Template for "preferred" WIDE transfer parameters */
666 static const unsigned char wdtr_message
[] = {
667 EXTENDED_MESSAGE
, 2 /* length */, EXTENDED_WDTR
, 1 /* 2^1 bytes */
671 * Function : struct Scsi_Host *find_host (int host)
673 * Purpose : KGDB support function which translates a host number
674 * to a host structure.
676 * Inputs : host - number of SCSI host
678 * Returns : NULL on failure, pointer to host structure on success.
682 static struct Scsi_Host
*
683 find_host (int host
) {
685 for (h
= first_host
; h
&& h
->host_no
!= host
; h
= h
->next
);
687 printk (KERN_ALERT
"scsi%d not found\n", host
);
689 } else if (h
->hostt
!= the_template
) {
690 printk (KERN_ALERT
"scsi%d is not a NCR board\n", host
);
697 * Function : request_synchronous (int host, int target)
699 * Purpose : KGDB interface which will allow us to negotiate for
700 * synchronous transfers. This ill be replaced with a more
701 * integrated function; perhaps a new entry in the scsi_host
702 * structure, accessible via an ioctl() or perhaps /proc/scsi.
704 * Inputs : host - number of SCSI host; target - number of target.
706 * Returns : 0 when negotiation has been setup for next SCSI command,
711 request_synchronous (int host
, int target
) {
713 struct NCR53c7x0_hostdata
*hostdata
;
716 printk (KERN_ALERT
"target %d is bogus\n", target
);
719 if (!(h
= find_host (host
)))
721 else if (h
->this_id
== target
) {
722 printk (KERN_ALERT
"target %d is host ID\n", target
);
726 else if (target
> h
->max_id
) {
727 printk (KERN_ALERT
"target %d exceeds maximum of %d\n", target
,
732 hostdata
= (struct NCR53c7x0_hostdata
*)h
->hostdata
;
736 if (hostdata
->initiate_sdtr
& (1 << target
)) {
737 restore_flags(flags
);
738 printk (KERN_ALERT
"target %d already doing SDTR\n", target
);
741 hostdata
->initiate_sdtr
|= (1 << target
);
742 restore_flags(flags
);
747 * Function : request_disconnect (int host, int on_or_off)
749 * Purpose : KGDB support function, tells us to allow or disallow
752 * Inputs : host - number of SCSI host; on_or_off - non-zero to allow,
755 * Returns : 0 on success, * -1 on failure.
759 request_disconnect (int host
, int on_or_off
) {
761 struct NCR53c7x0_hostdata
*hostdata
;
762 if (!(h
= find_host (host
)))
764 hostdata
= (struct NCR53c7x0_hostdata
*) h
->hostdata
;
766 hostdata
->options
|= OPTION_DISCONNECT
;
768 hostdata
->options
&= ~OPTION_DISCONNECT
;
774 * Function : static void NCR53c7x0_driver_init (struct Scsi_Host *host)
776 * Purpose : Initialize internal structures, as required on startup, or
777 * after a SCSI bus reset.
779 * Inputs : host - pointer to this host adapter's structure
783 NCR53c7x0_driver_init (struct Scsi_Host
*host
) {
784 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
788 for (i
= 0; i
< 16; ++i
) {
789 hostdata
->request_sense
[i
] = 0;
790 for (j
= 0; j
< 8; ++j
)
791 hostdata
->busy
[i
][j
] = 0;
792 set_synchronous (host
, i
, /* sxfer */ 0, hostdata
->saved_scntl3
, 0);
794 hostdata
->issue_queue
= NULL
;
795 hostdata
->running_list
= hostdata
->finished_queue
=
796 hostdata
->curr
= NULL
;
797 for (i
= 0, curr
= (u32
*) hostdata
->schedule
;
798 i
< host
->can_queue
; ++i
, curr
+= 2) {
799 curr
[0] = hostdata
->NOP_insn
;
800 curr
[1] = le32_to_cpu(0xdeadbeef);
802 curr
[0] = le32_to_cpu(((DCMD_TYPE_TCI
|DCMD_TCI_OP_JUMP
) << 24) | DBC_TCI_TRUE
);
803 curr
[1] = (u32
) le32_to_cpu(virt_to_bus (hostdata
->script
) +
804 hostdata
->E_wait_reselect
);
805 hostdata
->reconnect_dsa_head
= 0;
806 hostdata
->addr_reconnect_dsa_head
= (u32
)
807 le32_to_cpu(virt_to_bus((void *) &(hostdata
->reconnect_dsa_head
)));
808 hostdata
->expecting_iid
= 0;
809 hostdata
->expecting_sto
= 0;
810 if (hostdata
->options
& OPTION_ALWAYS_SYNCHRONOUS
)
811 hostdata
->initiate_sdtr
= le32_to_cpu(0xffff);
813 hostdata
->initiate_sdtr
= 0;
814 hostdata
->talked_to
= 0;
819 * Function : static int ccf_to_clock (int ccf)
821 * Purpose : Return the largest SCSI clock allowable for a given
822 * clock conversion factor, allowing us to do synchronous periods
823 * when we don't know what the SCSI clock is by taking at least
824 * as long as the device says we can.
828 * Returns : clock on success, -1 on failure.
832 ccf_to_clock (int ccf
) {
834 case 1: return 25000000; /* Divide by 1.0 */
835 case 2: return 37500000; /* Divide by 1.5 */
836 case 3: return 50000000; /* Divide by 2.0 */
837 case 0: /* Divide by 3.0 */
838 case 4: return 66000000;
844 * Function : static int clock_to_ccf (int clock)
846 * Purpose : Return the clock conversion factor for a given SCSI clock.
848 * Inputs : clock - SCSI clock expressed in Hz.
850 * Returns : ccf on success, -1 on failure.
854 clock_to_ccf (int clock
) {
855 if (clock
< 16666666)
857 if (clock
< 25000000)
858 return 1; /* Divide by 1.0 */
859 else if (clock
< 37500000)
860 return 2; /* Divide by 1.5 */
861 else if (clock
< 50000000)
862 return 3; /* Divide by 2.0 */
863 else if (clock
< 66000000)
864 return 4; /* Divide by 3.0 */
870 * Function : static int NCR53c7x0_init (struct Scsi_Host *host)
872 * Purpose : initialize the internal structures for a given SCSI host
874 * Inputs : host - pointer to this host adapter's structure
876 * Preconditions : when this function is called, the chip_type
877 * field of the hostdata structure MUST have been set.
879 * Returns : 0 on success, -1 on failure.
883 NCR53c7x0_init (struct Scsi_Host
*host
) {
884 NCR53c7x0_local_declare();
885 int i
, ccf
, expected_ccf
;
886 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
888 struct Scsi_Host
*search
;
890 * There are some things which we need to know about in order to provide
891 * a semblance of support. Print 'em if they aren't what we expect,
892 * otherwise don't add to the noise.
894 * -1 means we don't know what to expect.
896 int expected_id
= -1;
897 int expected_clock
= -1;
898 int uninitialized
= 0;
900 * FIXME : this is only on Intel boxes. On other platforms, this
903 int expected_mapping
= OPTION_IO_MAPPED
;
905 NCR53c7x0_local_setup(host
);
907 switch (hostdata
->chip
) {
916 hostdata
->dstat_sir_intr
= NCR53c8x0_dstat_sir_intr
;
917 hostdata
->init_save_regs
= NULL
;
918 hostdata
->dsa_fixup
= NCR53c8xx_dsa_fixup
;
919 hostdata
->init_fixup
= NCR53c8x0_init_fixup
;
920 hostdata
->soft_reset
= NCR53c8x0_soft_reset
;
921 hostdata
->run_tests
= NCR53c8xx_run_tests
;
922 /* Is the SCSI clock ever anything else on these chips? */
923 expected_clock
= hostdata
->scsi_clock
= 40000000;
927 printk ("scsi%d : chip type of %d is not supported yet, detaching.\n",
928 host
->host_no
, hostdata
->chip
);
929 scsi_unregister (host
);
933 /* Assign constants accessed by NCR */
934 hostdata
->NCR53c7xx_zero
= 0;
935 hostdata
->NCR53c7xx_msg_reject
= le32_to_cpu(MESSAGE_REJECT
);
936 hostdata
->NCR53c7xx_msg_abort
= le32_to_cpu(ABORT
);
937 hostdata
->NCR53c7xx_msg_nop
= le32_to_cpu(NOP
);
938 hostdata
->NOP_insn
= le32_to_cpu((DCMD_TYPE_TCI
|DCMD_TCI_OP_JUMP
) << 24);
940 if (expected_mapping
== -1 ||
941 (hostdata
->options
& (OPTION_MEMORY_MAPPED
)) !=
942 (expected_mapping
& OPTION_MEMORY_MAPPED
))
943 printk ("scsi%d : using %s mapped access\n", host
->host_no
,
944 (hostdata
->options
& OPTION_MEMORY_MAPPED
) ? "memory" :
947 hostdata
->dmode
= (hostdata
->chip
== 700 || hostdata
->chip
== 70066) ?
948 DMODE_REG_00
: DMODE_REG_10
;
949 hostdata
->istat
= ((hostdata
->chip
/ 100) == 8) ?
950 ISTAT_REG_800
: ISTAT_REG_700
;
952 /* Only the ISTAT register is readable when the NCR is running, so make
957 * XXX - the NCR53c700 uses bitfielded registers for SCID, SDID, etc,
958 * as does the 710 with one bit per SCSI ID. Conversely, the NCR
959 * uses a normal, 3 bit binary representation of these values.
961 * Get the rest of the NCR documentation, and FIND OUT where the change
965 tmp
= hostdata
->this_id_mask
= NCR53c7x0_read8(SCID_REG
);
966 for (host
->this_id
= 0; tmp
!= 1; tmp
>>=1, ++host
->this_id
);
968 host
->this_id
= NCR53c7x0_read8(SCID_REG
) & 15;
969 if (host
->this_id
== 0)
970 host
->this_id
= 7; /* sanitize hostid---0 doesn't make sense */
971 hostdata
->this_id_mask
= 1 << host
->this_id
;
975 * Note : we should never encounter a board setup for ID0. So,
976 * if we see ID0, assume that it was uninitialized and set it
977 * to the industry standard 7.
979 if (!host
->this_id
) {
980 printk("scsi%d : initiator ID was %d, changing to 7\n",
981 host
->host_no
, host
->this_id
);
983 hostdata
->this_id_mask
= 1 << 7;
987 if (expected_id
== -1 || host
->this_id
!= expected_id
)
988 printk("scsi%d : using initiator ID %d\n", host
->host_no
,
992 * Save important registers to allow a soft reset.
995 if ((hostdata
->chip
/ 100) == 8) {
997 * CTEST4 controls burst mode disable.
999 hostdata
->saved_ctest4
= NCR53c7x0_read8(CTEST4_REG_800
) &
1003 * CTEST7 controls cache snooping, burst mode, and support for
1004 * external differential drivers.
1006 hostdata
->saved_ctest7
= NCR53c7x0_read8(CTEST7_REG
) & CTEST7_SAVE
;
1010 * On NCR53c700 series chips, DCNTL controls the SCSI clock divisor,
1011 * on 800 series chips, it allows for a totem-pole IRQ driver.
1014 hostdata
->saved_dcntl
= NCR53c7x0_read8(DCNTL_REG
);
1017 * DCNTL_800_IRQM controls weather we are using an open drain
1018 * driver (reset) or totem pole driver (set). In all cases,
1019 * it's level active. I suppose this is an issue when we're trying to
1020 * wire-or the same PCI INTx line?
1022 if ((hostdata
->chip
/ 100) == 8)
1023 hostdata
->saved_dcntl
&= ~DCNTL_800_IRQM
;
1026 * DMODE controls DMA burst length, and on 700 series chips,
1027 * 286 mode and bus width
1029 hostdata
->saved_dmode
= NCR53c7x0_read8(hostdata
->dmode
);
1032 * Now that burst length and enabled/disabled status is known,
1033 * clue the user in on it.
1036 if ((hostdata
->chip
/ 100) == 8) {
1037 if (hostdata
->saved_ctest4
& CTEST4_800_BDIS
) {
1038 printk ("scsi%d : burst mode disabled\n", host
->host_no
);
1040 switch (hostdata
->saved_dmode
& DMODE_BL_MASK
) {
1041 case DMODE_BL_2
: i
= 2; break;
1042 case DMODE_BL_4
: i
= 4; break;
1043 case DMODE_BL_8
: i
= 8; break;
1044 case DMODE_BL_16
: i
= 16; break;
1047 printk ("scsi%d : burst length %d\n", host
->host_no
, i
);
1052 * On NCR53c810 and NCR53c820 chips, SCNTL3 contails the synchronous
1053 * and normal clock conversion factors.
1055 if (hostdata
->chip
/ 100 == 8) {
1056 expected_ccf
= clock_to_ccf (expected_clock
);
1057 hostdata
->saved_scntl3
= NCR53c7x0_read8(SCNTL3_REG_800
);
1058 ccf
= hostdata
->saved_scntl3
& SCNTL3_800_CCF_MASK
;
1059 if (expected_ccf
!= -1 && ccf
!= expected_ccf
&& !ccf
) {
1060 hostdata
->saved_scntl3
= (hostdata
->saved_scntl3
&
1061 ~SCNTL3_800_CCF_MASK
) | expected_ccf
;
1062 if (!uninitialized
) {
1063 printk ("scsi%d : reset ccf to %d from %d\n",
1064 host
->host_no
, expected_ccf
, ccf
);
1072 * If we don't have a SCSI clock programmed, pick one on the upper
1073 * bound of that allowed by NCR so that our transfers err on the
1074 * slow side, since transfer period must be >= the agreed
1078 if ((!hostdata
->scsi_clock
) && (hostdata
->scsi_clock
= ccf_to_clock (ccf
))
1080 printk ("scsi%d : clock conversion factor %d unknown.\n"
1081 " synchronous transfers disabled\n",
1082 host
->host_no
, ccf
);
1083 hostdata
->options
&= ~OPTION_SYNCHRONOUS
;
1084 hostdata
->scsi_clock
= 0;
1087 if (expected_clock
== -1 || hostdata
->scsi_clock
!= expected_clock
)
1088 printk ("scsi%d : using %dMHz SCSI clock\n", host
->host_no
,
1089 hostdata
->scsi_clock
/ 1000000);
1091 for (i
= 0; i
< 16; ++i
)
1092 hostdata
->cmd_allocated
[i
] = 0;
1094 if (hostdata
->init_save_regs
)
1095 hostdata
->init_save_regs (host
);
1096 if (hostdata
->init_fixup
)
1097 hostdata
->init_fixup (host
);
1099 if (!the_template
) {
1100 the_template
= host
->hostt
;
1105 * Linux SCSI drivers have always been plagued with initialization
1106 * problems - some didn't work with the BIOS disabled since they expected
1107 * initialization from it, some didn't work when the networking code
1108 * was enabled and registers got scrambled, etc.
1110 * To avoid problems like this, in the future, we will do a soft
1111 * reset on the SCSI chip, taking it back to a sane state.
1114 hostdata
->soft_reset (host
);
1117 hostdata
->debug_count_limit
= -1;
1119 hostdata
->debug_count_limit
= 1;
1121 hostdata
->intrs
= -1;
1122 hostdata
->resets
= -1;
1123 memcpy ((void *) hostdata
->synchronous_want
, (void *) sdtr_message
,
1124 sizeof (hostdata
->synchronous_want
));
1126 NCR53c7x0_driver_init (host
);
1129 * Set up an interrupt handler if we aren't already sharing an IRQ
1130 * with another board.
1133 for (search
= first_host
; search
&& !(search
->hostt
== the_template
&&
1134 search
->irq
== host
->irq
&& search
!= host
); search
=search
->next
);
1138 if (request_irq(host
->irq
, NCR53c7x0_intr
, SA_SHIRQ
, "53c7,8xx", NULL
))
1140 if (request_irq(host
->irq
, NCR53c7x0_intr
, SA_INTERRUPT
, "53c7,8xx", NULL
))
1145 printk("scsi%d : IRQ%d not free, detaching\n"
1146 " You have either a configuration problem, or a\n"
1147 " broken BIOS. You may wish to manually assign\n"
1148 " an interrupt to the NCR board rather than using\n"
1149 " an automatic setting.\n",
1150 host
->host_no
, host
->irq
);
1151 scsi_unregister (host
);
1155 printk("scsi%d : using interrupt handler previously installed for scsi%d\n",
1156 host
->host_no
, search
->host_no
);
1160 if ((hostdata
->run_tests
&& hostdata
->run_tests(host
) == -1) ||
1161 (hostdata
->options
& OPTION_DEBUG_TESTS_ONLY
)) {
1162 /* XXX Should disable interrupts, etc. here */
1163 scsi_unregister (host
);
1166 if (host
->io_port
) {
1167 host
->n_io_port
= 128;
1168 request_region (host
->io_port
, host
->n_io_port
, "ncr53c7,8xx");
1172 if (NCR53c7x0_read8 (SBCL_REG
) & SBCL_BSY
) {
1173 printk ("scsi%d : bus wedge, doing SCSI reset\n", host
->host_no
);
1180 * Function : static int normal_init(Scsi_Host_Template *tpnt, int board,
1181 * int chip, u32 base, int io_port, int irq, int dma, int pcivalid,
1182 * unsigned char pci_bus, unsigned char pci_device_fn,
1183 * long long options);
1185 * Purpose : initializes a NCR53c7,8x0 based on base addresses,
1186 * IRQ, and DMA channel.
1188 * Useful where a new NCR chip is backwards compatible with
1189 * a supported chip, but the DEVICE ID has changed so it
1190 * doesn't show up when the autoprobe does a pcibios_find_device.
1192 * Inputs : tpnt - Template for this SCSI adapter, board - board level
1193 * product, chip - 810, 820, or 825, bus - PCI bus, device_fn -
1194 * device and function encoding as used by PCI BIOS calls.
1196 * Returns : 0 on success, -1 on failure.
1200 __initfunc(static int
1201 normal_init (Scsi_Host_Template
*tpnt
, int board
, int chip
,
1202 u32 base
, int io_port
, int irq
, int dma
, int pci_valid
,
1203 unsigned char pci_bus
, unsigned char pci_device_fn
, long long options
)) {
1204 struct Scsi_Host
*instance
;
1205 struct NCR53c7x0_hostdata
*hostdata
;
1207 int script_len
= 0, dsa_len
= 0, size
= 0, max_cmd_size
= 0,
1208 schedule_size
= 0, ok
= 0;
1211 options
|= perm_options
;
1218 schedule_size
= (tpnt
->can_queue
+ 1) * 8 /* JUMP instruction size */;
1219 script_len
= NCR53c8xx_script_len
;
1220 dsa_len
= NCR53c8xx_dsa_len
;
1221 options
|= OPTION_INTFLY
;
1222 sprintf (chip_str
, "NCR53c%d", chip
);
1225 printk("scsi-ncr53c7,8xx : unsupported SCSI chip %d\n", chip
);
1229 printk("scsi-ncr53c7,8xx : %s at memory 0x%x, io 0x%x, irq %d",
1230 chip_str
, (unsigned) base
, io_port
, irq
);
1231 if (dma
== DMA_NONE
)
1234 printk(", dma %d\n", dma
);
1236 if ((chip
/ 100 == 8) && !pci_valid
)
1237 printk ("scsi-ncr53c7,8xx : for better reliability and performance, please use the\n"
1238 " PCI override instead.\n"
1239 " Syntax : ncr53c8{10,15,20,25}=pci,<bus>,<device>,<function>\n"
1240 " <bus> and <device> are usually 0.\n");
1242 if (options
& OPTION_DEBUG_PROBE_ONLY
) {
1243 printk ("scsi-ncr53c7,8xx : probe only enabled, aborting initialization\n");
1247 max_cmd_size
= sizeof(struct NCR53c7x0_cmd
) + dsa_len
+
1248 /* Size of dynamic part of command structure : */
1249 2 * /* Worst case : we don't know if we need DATA IN or DATA out */
1250 ( 2 * /* Current instructions per scatter/gather segment */
1251 tpnt
->sg_tablesize
+
1252 3 /* Current startup / termination required per phase */
1254 8 /* Each instruction is eight bytes */;
1256 /* Allocate fixed part of hostdata, dynamic part to hold appropriate
1257 SCSI SCRIPT(tm) plus a single, maximum-sized NCR53c7x0_cmd structure.
1259 We need a NCR53c7x0_cmd structure for scan_scsis() when we are
1260 not loaded as a module, and when we're loaded as a module, we
1261 can't use a non-dynamically allocated structure because modules
1262 are vmalloc()'d, which can allow structures to cross page
1263 boundaries and breaks our physical/virtual address assumptions
1266 So, we stick it past the end of our hostdata structure.
1269 Regardless of how many simultaneous SCSI commands we allow,
1270 the probe code only executes a _single_ instruction at a time,
1271 so we only need one here, and don't need to allocate NCR53c7x0_cmd
1272 structures for each target until we are no longer in scan_scsis
1273 and kmalloc() has become functional (memory_init() happens
1274 after all device driver initialization).
1277 size
= sizeof(struct NCR53c7x0_hostdata
) + script_len
+
1278 /* Note that alignment will be guaranteed, since we put the command
1279 allocated at probe time after the fixed-up SCSI script, which
1280 consists of 32 bit words, aligned on a 32 bit boundary. But
1281 on a 64bit machine we need 8 byte alignment for hostdata->free, so
1282 we add in another 4 bytes to take care of potential misalignment
1284 (sizeof(void *) - sizeof(u32
)) + max_cmd_size
+ schedule_size
;
1286 instance
= scsi_register (tpnt
, size
);
1290 /* FIXME : if we ever support an ISA NCR53c7xx based board, we
1291 need to check if the chip is running in a 16 bit mode, and if so
1292 unregister it if it is past the 16M (0x1000000) mark */
1294 hostdata
= (struct NCR53c7x0_hostdata
*)
1296 hostdata
->size
= size
;
1297 hostdata
->script_count
= script_len
/ sizeof(u32
);
1298 hostdata
= (struct NCR53c7x0_hostdata
*) instance
->hostdata
;
1299 hostdata
->board
= board
;
1300 hostdata
->chip
= chip
;
1301 if ((hostdata
->pci_valid
= pci_valid
)) {
1302 hostdata
->pci_bus
= pci_bus
;
1303 hostdata
->pci_device_fn
= pci_device_fn
;
1307 * Being memory mapped is more desirable, since
1309 * - Memory accesses may be faster.
1311 * - The destination and source address spaces are the same for
1312 * all instructions, meaning we don't have to twiddle dmode or
1313 * any other registers.
1315 * So, we try for memory mapped, and if we don't get it,
1316 * we go for port mapped, and that failing we tell the user
1321 instance
->base
= (unsigned char *) (unsigned long) base
;
1322 /* Check for forced I/O mapping */
1323 if (!(options
& OPTION_IO_MAPPED
)) {
1324 options
|= OPTION_MEMORY_MAPPED
;
1328 options
&= ~OPTION_MEMORY_MAPPED
;
1332 instance
->io_port
= io_port
;
1333 options
|= OPTION_IO_MAPPED
;
1336 options
&= ~OPTION_IO_MAPPED
;
1340 printk ("scsi%d : not initializing, no I/O or memory mapping known \n",
1342 scsi_unregister (instance
);
1345 instance
->irq
= irq
;
1346 instance
->dma_channel
= dma
;
1348 hostdata
->options
= options
;
1349 hostdata
->dsa_len
= dsa_len
;
1350 hostdata
->max_cmd_size
= max_cmd_size
;
1351 hostdata
->num_cmds
= 1;
1352 /* Initialize single command */
1353 tmp
= (hostdata
->script
+ hostdata
->script_count
);
1354 hostdata
->free
= ROUNDUP(tmp
, void *);
1355 hostdata
->free
->real
= tmp
;
1356 hostdata
->free
->size
= max_cmd_size
;
1357 hostdata
->free
->free
= NULL
;
1358 hostdata
->free
->next
= NULL
;
1359 hostdata
->extra_allocate
= 0;
1361 /* Allocate command start code space */
1362 hostdata
->schedule
= (chip
== 700 || chip
== 70066) ?
1363 NULL
: (u32
*) ((char *)hostdata
->free
+ max_cmd_size
);
1366 * For diagnostic purposes, we don't really care how fast things blaze.
1367 * For profiling, we want to access the 800ns resolution system clock,
1368 * using a 'C' call on the host processor.
1370 * Therefore, there's no need for the NCR chip to directly manipulate
1371 * this data, and we should put it wherever is most convenient for
1375 hostdata
->events
= (struct NCR53c7x0_event
*) (track_events
?
1376 vmalloc (sizeof (struct NCR53c7x0_event
) * track_events
) : NULL
);
1378 hostdata
->events
= NULL
;
1380 if (hostdata
->events
) {
1381 memset ((void *) hostdata
->events
, 0, sizeof(struct NCR53c7x0_event
) *
1383 hostdata
->event_size
= track_events
;
1384 hostdata
->event_index
= 0;
1386 hostdata
->event_size
= 0;
1388 return NCR53c7x0_init(instance
);
1393 * Function : static int ncr_pci_init(Scsi_Host_Template *tpnt, int board,
1394 * int chip, int bus, int device_fn, long long options)
1396 * Purpose : initializes a NCR53c800 family based on the PCI
1397 * bus, device, and function location of it. Allows
1398 * reprogramming of latency timer and determining addresses
1399 * and whether bus mastering, etc. are OK.
1401 * Useful where a new NCR chip is backwards compatible with
1402 * a supported chip, but the DEVICE ID has changed so it
1403 * doesn't show up when the autoprobe does a pcibios_find_device.
1405 * Inputs : tpnt - Template for this SCSI adapter, board - board level
1406 * product, chip - 810, 820, or 825, bus - PCI bus, device_fn -
1407 * device and function encoding as used by PCI BIOS calls.
1409 * Returns : 0 on success, -1 on failure.
1413 __initfunc(static int
1414 ncr_pci_init (Scsi_Host_Template
*tpnt
, int board
, int chip
,
1415 unsigned char bus
, unsigned char device_fn
, long long options
)) {
1416 unsigned short vendor_id
, device_id
, command
;
1423 unsigned char irq
, revision
;
1424 int error
, expected_chip
;
1425 int expected_id
= -1, max_revision
= -1, min_revision
= -1;
1428 printk("scsi-ncr53c7,8xx : at PCI bus %d, device %d, function %d\n",
1429 bus
, (int) (device_fn
& 0xf8) >> 3,
1430 (int) device_fn
& 7);
1432 if (!pcibios_present()) {
1433 printk("scsi-ncr53c7,8xx : not initializing due to lack of PCI BIOS,\n"
1434 " try using memory, port, irq override instead.\n");
1438 if ((error
= pcibios_read_config_word (bus
, device_fn
, PCI_VENDOR_ID
,
1440 (error
= pcibios_read_config_word (bus
, device_fn
, PCI_DEVICE_ID
,
1442 (error
= pcibios_read_config_word (bus
, device_fn
, PCI_COMMAND
,
1444 (error
= pcibios_read_config_dword (bus
, device_fn
,
1445 PCI_BASE_ADDRESS_0
, &io_port
)) ||
1446 (error
= pcibios_read_config_dword (bus
, device_fn
,
1447 PCI_BASE_ADDRESS_1
, &base
)) ||
1448 (error
= pcibios_read_config_byte (bus
, device_fn
, PCI_CLASS_REVISION
,
1450 (error
= pcibios_read_config_byte (bus
, device_fn
, PCI_INTERRUPT_LINE
,
1452 printk ("scsi-ncr53c7,8xx : error %s not initializing due to error reading configuration space\n"
1453 " perhaps you specified an incorrect PCI bus, device, or function.\n"
1454 , pcibios_strerror(error
));
1458 /* If any one ever clones the NCR chips, this will have to change */
1460 if (vendor_id
!= PCI_VENDOR_ID_NCR
) {
1461 printk ("scsi-ncr53c7,8xx : not initializing, 0x%04x is not NCR vendor ID\n",
1467 if ( ! (command
& PCI_COMMAND_MASTER
)) {
1468 printk("SCSI: PCI Master Bit has not been set. Setting...\n");
1469 command
|= PCI_COMMAND_MASTER
|PCI_COMMAND_IO
;
1470 pcibios_write_config_word(bus
, device_fn
, PCI_COMMAND
, command
);
1471 if (io_port
>= 0x10000000) {
1472 /* Mapping on PowerPC can't handle this! */
1473 unsigned long new_io_port
;
1474 new_io_port
= (io_port
& 0x00FFFFFF) | 0x01000000;
1475 printk("SCSI: I/O moved from %08X to %08x\n", io_port
, new_io_port
);
1476 io_port
= new_io_port
;
1477 pcibios_write_config_dword(bus
, device_fn
, PCI_BASE_ADDRESS_0
, io_port
);
1483 * Bit 0 is the address space indicator and must be one for I/O
1484 * space mappings, bit 1 is reserved, discard them after checking
1485 * that they have the correct value of 1.
1488 if (command
& PCI_COMMAND_IO
) {
1489 if ((io_port
& 3) != 1) {
1490 printk ("scsi-ncr53c7,8xx : disabling I/O mapping since base address 0 (0x%x)\n"
1491 " bits 0..1 indicate a non-IO mapping\n",
1492 (unsigned) io_port
);
1495 io_port
&= PCI_BASE_ADDRESS_IO_MASK
;
1500 if (command
& PCI_COMMAND_MEMORY
) {
1501 if ((base
& PCI_BASE_ADDRESS_SPACE
) != PCI_BASE_ADDRESS_SPACE_MEMORY
) {
1502 printk("scsi-ncr53c7,8xx : disabling memory mapping since base address 1\n"
1503 " contains a non-memory mapping\n");
1506 base
&= PCI_BASE_ADDRESS_MEM_MASK
;
1511 if (!io_port
&& !base
) {
1512 printk ("scsi-ncr53c7,8xx : not initializing, both I/O and memory mappings disabled\n");
1516 if (!(command
& PCI_COMMAND_MASTER
)) {
1517 printk ("scsi-ncr53c7,8xx : not initializing, BUS MASTERING was disabled\n");
1521 for (i
= 0; i
< NPCI_CHIP_IDS
; ++i
) {
1522 if (device_id
== pci_chip_ids
[i
].pci_device_id
) {
1523 max_revision
= pci_chip_ids
[i
].max_revision
;
1524 min_revision
= pci_chip_ids
[i
].min_revision
;
1525 expected_chip
= pci_chip_ids
[i
].chip
;
1527 if (chip
== pci_chip_ids
[i
].chip
)
1528 expected_id
= pci_chip_ids
[i
].pci_device_id
;
1531 if (chip
&& device_id
!= expected_id
)
1532 printk ("scsi-ncr53c7,8xx : warning : device id of 0x%04x doesn't\n"
1533 " match expected 0x%04x\n",
1534 (unsigned int) device_id
, (unsigned int) expected_id
);
1536 if (max_revision
!= -1 && revision
> max_revision
)
1537 printk ("scsi-ncr53c7,8xx : warning : revision of %d is greater than %d.\n",
1538 (int) revision
, max_revision
);
1539 else if (min_revision
!= -1 && revision
< min_revision
)
1540 printk ("scsi-ncr53c7,8xx : warning : revision of %d is less than %d.\n",
1541 (int) revision
, min_revision
);
1543 if (io_port
&& check_region (io_port
, 128)) {
1544 printk ("scsi-ncr53c7,8xx : IO region 0x%x to 0x%x is in use\n",
1545 (unsigned) io_port
, (unsigned) io_port
+ 127);
1549 return normal_init (tpnt
, board
, chip
, (int) base
, io_port
,
1550 (int) irq
, DMA_NONE
, 1, bus
, device_fn
, options
);
1555 * Function : int NCR53c7xx_detect(Scsi_Host_Template *tpnt)
1557 * Purpose : detects and initializes NCR53c7,8x0 SCSI chips
1558 * that were autoprobed, overridden on the LILO command line,
1559 * or specified at compile time.
1561 * Inputs : tpnt - template for this SCSI adapter
1563 * Returns : number of host adapters detected
1568 NCR53c7xx_detect(Scsi_Host_Template
*tpnt
)) {
1570 int current_override
;
1571 int count
; /* Number of boards detected */
1572 unsigned char pci_bus
, pci_device_fn
;
1573 static short pci_index
=0; /* Device index to PCI BIOS calls */
1576 tpnt
->proc_dir
= &proc_scsi_ncr53c7xx
;
1579 for (current_override
= count
= 0; current_override
< OVERRIDE_LIMIT
;
1580 ++current_override
) {
1581 if (overrides
[current_override
].pci
?
1582 !ncr_pci_init (tpnt
, overrides
[current_override
].board
,
1583 overrides
[current_override
].chip
,
1584 (unsigned char) overrides
[current_override
].data
.pci
.bus
,
1585 (((overrides
[current_override
].data
.pci
.device
1586 << 3) & 0xf8)|(overrides
[current_override
].data
.pci
.function
&
1587 7)), overrides
[current_override
].options
):
1588 !normal_init (tpnt
, overrides
[current_override
].board
,
1589 overrides
[current_override
].chip
,
1590 overrides
[current_override
].data
.normal
.base
,
1591 overrides
[current_override
].data
.normal
.io_port
,
1592 overrides
[current_override
].data
.normal
.irq
,
1593 overrides
[current_override
].data
.normal
.dma
,
1594 0 /* PCI data invalid */, 0 /* PCI bus place holder */,
1595 0 /* PCI device_function place holder */,
1596 overrides
[current_override
].options
)) {
1601 if (pcibios_present()) {
1602 for (i
= 0; i
< NPCI_CHIP_IDS
; ++i
)
1604 !pcibios_find_device (PCI_VENDOR_ID_NCR
,
1605 pci_chip_ids
[i
].pci_device_id
, pci_index
, &pci_bus
,
1608 if (!ncr_pci_init (tpnt
, BOARD_GENERIC
, pci_chip_ids
[i
].chip
,
1609 pci_bus
, pci_device_fn
, /* no options */ 0))
1615 /* NCR53c810 and NCR53c820 script handling code */
1617 #include "53c8xx_d.h"
1618 #ifdef A_int_debug_sync
1619 #define DEBUG_SYNC_INTR A_int_debug_sync
1621 static int NCR53c8xx_script_len
= sizeof (SCRIPT
);
1622 static int NCR53c8xx_dsa_len
= A_dsa_end
+ Ent_dsa_zero
- Ent_dsa_code_template
;
1625 * Function : static void NCR53c8x0_init_fixup (struct Scsi_Host *host)
1627 * Purpose : copy and fixup the SCSI SCRIPTS(tm) code for this device.
1629 * Inputs : host - pointer to this host adapter's structure
1634 NCR53c8x0_init_fixup (struct Scsi_Host
*host
) {
1635 NCR53c7x0_local_declare();
1636 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
1639 int i
, ncr_to_memory
, memory_to_ncr
;
1642 unsigned long *script_ptr
;
1644 NCR53c7x0_local_setup(host
);
1647 /* XXX - NOTE : this code MUST be made endian aware */
1648 /* Copy code into buffer that was allocated at detection time. */
1649 memcpy ((void *) hostdata
->script
, (void *) SCRIPT
,
1652 for (i
= 0; i
< PATCHES
; ++i
)
1653 hostdata
->script
[LABELPATCHES
[i
]] +=
1654 virt_to_bus(hostdata
->script
);
1655 /* Fixup addresses of constants that used to be EXTERNAL */
1657 patch_abs_32 (hostdata
->script
, 0, NCR53c7xx_msg_abort
,
1658 virt_to_bus(&(hostdata
->NCR53c7xx_msg_abort
)));
1659 patch_abs_32 (hostdata
->script
, 0, NCR53c7xx_msg_reject
,
1660 virt_to_bus(&(hostdata
->NCR53c7xx_msg_reject
)));
1661 patch_abs_32 (hostdata
->script
, 0, NCR53c7xx_zero
,
1662 virt_to_bus(&(hostdata
->NCR53c7xx_zero
)));
1663 patch_abs_32 (hostdata
->script
, 0, NCR53c7xx_sink
,
1664 virt_to_bus(&(hostdata
->NCR53c7xx_sink
)));
1665 patch_abs_32 (hostdata
->script
, 0, NOP_insn
,
1666 virt_to_bus(&(hostdata
->NOP_insn
)));
1667 patch_abs_32 (hostdata
->script
, 0, schedule
,
1668 virt_to_bus((void *) hostdata
->schedule
));
1670 /* Fixup references to external variables: */
1671 for (i
= 0; i
< EXTERNAL_PATCHES_LEN
; ++i
)
1672 hostdata
->script
[EXTERNAL_PATCHES
[i
].offset
] +=
1673 virt_to_bus(EXTERNAL_PATCHES
[i
].address
);
1676 * Fixup absolutes set at boot-time.
1678 * All non-code absolute variables suffixed with "dsa_" and "int_"
1679 * are constants, and need no fixup provided the assembler has done
1680 * it for us (I don't know what the "real" NCR assembler does in
1681 * this case, my assembler does the right magic).
1684 patch_abs_rwri_data (hostdata
->script
, 0, dsa_save_data_pointer
,
1685 Ent_dsa_code_save_data_pointer
- Ent_dsa_zero
);
1686 patch_abs_rwri_data (hostdata
->script
, 0, dsa_restore_pointers
,
1687 Ent_dsa_code_restore_pointers
- Ent_dsa_zero
);
1688 patch_abs_rwri_data (hostdata
->script
, 0, dsa_check_reselect
,
1689 Ent_dsa_code_check_reselect
- Ent_dsa_zero
);
1692 * Just for the hell of it, preserve the settings of
1693 * Burst Length and Enable Read Line bits from the DMODE
1694 * register. Make sure SCRIPTS start automagically.
1697 tmp
= NCR53c7x0_read8(DMODE_REG_10
);
1698 tmp
&= (DMODE_800_ERL
| DMODE_BL_MASK
);
1700 if (!(hostdata
->options
& OPTION_MEMORY_MAPPED
)) {
1701 base
= (u32
) host
->io_port
;
1702 memory_to_ncr
= tmp
|DMODE_800_DIOM
;
1703 ncr_to_memory
= tmp
|DMODE_800_SIOM
;
1705 base
= virt_to_bus(host
->base
);
1706 memory_to_ncr
= ncr_to_memory
= tmp
;
1709 patch_abs_32 (hostdata
->script
, 0, addr_scratch
, base
+ SCRATCHA_REG_800
);
1710 patch_abs_32 (hostdata
->script
, 0, addr_temp
, base
+ TEMP_REG
);
1713 * I needed some variables in the script to be accessible to
1714 * both the NCR chip and the host processor. For these variables,
1715 * I made the arbitrary decision to store them directly in the
1716 * hostdata structure rather than in the RELATIVE area of the
1721 patch_abs_rwri_data (hostdata
->script
, 0, dmode_memory_to_memory
, tmp
);
1722 patch_abs_rwri_data (hostdata
->script
, 0, dmode_memory_to_ncr
, memory_to_ncr
);
1723 patch_abs_rwri_data (hostdata
->script
, 0, dmode_ncr_to_memory
, ncr_to_memory
);
1725 patch_abs_32 (hostdata
->script
, 0, msg_buf
,
1726 virt_to_bus((void *)&(hostdata
->msg_buf
)));
1727 patch_abs_32 (hostdata
->script
, 0, reconnect_dsa_head
,
1728 virt_to_bus((void *)&(hostdata
->reconnect_dsa_head
)));
1729 patch_abs_32 (hostdata
->script
, 0, addr_reconnect_dsa_head
,
1730 virt_to_bus((void *)&(hostdata
->addr_reconnect_dsa_head
)));
1731 patch_abs_32 (hostdata
->script
, 0, reselected_identify
,
1732 virt_to_bus((void *)&(hostdata
->reselected_identify
)));
1733 /* reselected_tag is currently unused */
1735 patch_abs_32 (hostdata
->script
, 0, reselected_tag
,
1736 virt_to_bus((void *)&(hostdata
->reselected_tag
)));
1739 patch_abs_32 (hostdata
->script
, 0, test_dest
,
1740 virt_to_bus((void*)&hostdata
->test_dest
));
1741 patch_abs_32 (hostdata
->script
, 0, test_src
,
1742 virt_to_bus(&hostdata
->test_source
));
1744 patch_abs_rwri_data (hostdata
->script
, 0, dsa_check_reselect
,
1745 (unsigned char)(Ent_dsa_code_check_reselect
- Ent_dsa_zero
));
1747 /* These are for event logging; the ncr_event enum contains the
1748 actual interrupt numbers. */
1749 #ifdef A_int_EVENT_SELECT
1750 patch_abs_32 (hostdata
->script
, 0, int_EVENT_SELECT
, (u32
) EVENT_SELECT
);
1752 #ifdef A_int_EVENT_DISCONNECT
1753 patch_abs_32 (hostdata
->script
, 0, int_EVENT_DISCONNECT
, (u32
) EVENT_DISCONNECT
);
1755 #ifdef A_int_EVENT_RESELECT
1756 patch_abs_32 (hostdata
->script
, 0, int_EVENT_RESELECT
, (u32
) EVENT_RESELECT
);
1758 #ifdef A_int_EVENT_COMPLETE
1759 patch_abs_32 (hostdata
->script
, 0, int_EVENT_COMPLETE
, (u32
) EVENT_COMPLETE
);
1761 #ifdef A_int_EVENT_IDLE
1762 patch_abs_32 (hostdata
->script
, 0, int_EVENT_IDLE
, (u32
) EVENT_IDLE
);
1764 #ifdef A_int_EVENT_SELECT_FAILED
1765 patch_abs_32 (hostdata
->script
, 0, int_EVENT_SELECT_FAILED
,
1766 (u32
) EVENT_SELECT_FAILED
);
1768 #ifdef A_int_EVENT_BEFORE_SELECT
1769 patch_abs_32 (hostdata
->script
, 0, int_EVENT_BEFORE_SELECT
,
1770 (u32
) EVENT_BEFORE_SELECT
);
1772 #ifdef A_int_EVENT_RESELECT_FAILED
1773 patch_abs_32 (hostdata
->script
, 0, int_EVENT_RESELECT_FAILED
,
1774 (u32
) EVENT_RESELECT_FAILED
);
1778 * Make sure the NCR and Linux code agree on the location of
1782 hostdata
->E_accept_message
= Ent_accept_message
;
1783 hostdata
->E_command_complete
= Ent_command_complete
;
1784 hostdata
->E_cmdout_cmdout
= Ent_cmdout_cmdout
;
1785 hostdata
->E_data_transfer
= Ent_data_transfer
;
1786 hostdata
->E_debug_break
= Ent_debug_break
;
1787 hostdata
->E_dsa_code_template
= Ent_dsa_code_template
;
1788 hostdata
->E_dsa_code_template_end
= Ent_dsa_code_template_end
;
1789 hostdata
->E_end_data_transfer
= Ent_end_data_transfer
;
1790 hostdata
->E_initiator_abort
= Ent_initiator_abort
;
1791 hostdata
->E_msg_in
= Ent_msg_in
;
1792 hostdata
->E_other_transfer
= Ent_other_transfer
;
1793 hostdata
->E_other_in
= Ent_other_in
;
1794 hostdata
->E_other_out
= Ent_other_out
;
1795 hostdata
->E_reject_message
= Ent_reject_message
;
1796 hostdata
->E_respond_message
= Ent_respond_message
;
1797 hostdata
->E_select
= Ent_select
;
1798 hostdata
->E_select_msgout
= Ent_select_msgout
;
1799 hostdata
->E_target_abort
= Ent_target_abort
;
1801 hostdata
->E_test_0
= Ent_test_0
;
1803 hostdata
->E_test_1
= Ent_test_1
;
1804 hostdata
->E_test_2
= Ent_test_2
;
1806 hostdata
->E_test_3
= Ent_test_3
;
1808 hostdata
->E_wait_reselect
= Ent_wait_reselect
;
1809 hostdata
->E_dsa_code_begin
= Ent_dsa_code_begin
;
1811 hostdata
->dsa_cmdout
= A_dsa_cmdout
;
1812 hostdata
->dsa_cmnd
= A_dsa_cmnd
;
1813 hostdata
->dsa_datain
= A_dsa_datain
;
1814 hostdata
->dsa_dataout
= A_dsa_dataout
;
1815 hostdata
->dsa_end
= A_dsa_end
;
1816 hostdata
->dsa_msgin
= A_dsa_msgin
;
1817 hostdata
->dsa_msgout
= A_dsa_msgout
;
1818 hostdata
->dsa_msgout_other
= A_dsa_msgout_other
;
1819 hostdata
->dsa_next
= A_dsa_next
;
1820 hostdata
->dsa_select
= A_dsa_select
;
1821 hostdata
->dsa_start
= Ent_dsa_code_template
- Ent_dsa_zero
;
1822 hostdata
->dsa_status
= A_dsa_status
;
1823 hostdata
->dsa_jump_dest
= Ent_dsa_code_fix_jump
- Ent_dsa_zero
+
1824 8 /* destination operand */;
1827 if (A_dsa_fields_start
!= Ent_dsa_code_template_end
-
1829 printk("scsi%d : NCR dsa_fields start is %d not %d\n",
1830 host
->host_no
, A_dsa_fields_start
, Ent_dsa_code_template_end
-
1833 /* The PowerPC is Big Endian - adjust script appropriately */
1834 script_ptr
= hostdata
->script
;
1835 for (i
= 0; i
< sizeof(SCRIPT
); i
+= sizeof(long))
1837 *script_ptr
++ = le32_to_cpu(*script_ptr
);
1841 printk("scsi%d : NCR code relocated to 0x%lx (virt 0x%p)\n", host
->host_no
,
1842 virt_to_bus(hostdata
->script
), hostdata
->script
);
1846 * Function : static int NCR53c8xx_run_tests (struct Scsi_Host *host)
1848 * Purpose : run various verification tests on the NCR chip,
1849 * including interrupt generation, and proper bus mastering
1852 * Inputs : host - a properly initialized Scsi_Host structure
1854 * Preconditions : the NCR chip must be in a halted state.
1856 * Returns : 0 if all tests were successful, -1 on error.
1861 NCR53c8xx_run_tests (struct Scsi_Host
*host
) {
1862 NCR53c7x0_local_declare();
1863 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
1865 unsigned long timeout
;
1868 unsigned long flags
;
1869 NCR53c7x0_local_setup(host
);
1871 /* The NCR chip _must_ be idle to run the test scripts */
1875 if (!hostdata
->idle
) {
1876 printk ("scsi%d : chip not idle, aborting tests\n", host
->host_no
);
1877 restore_flags(flags
);
1882 * Check for functional interrupts, this could work as an
1883 * autoprobe routine.
1886 if ((hostdata
->options
& OPTION_DEBUG_TEST1
) &&
1887 hostdata
->state
!= STATE_DISABLED
) {
1889 hostdata
->test_running
= 1;
1890 hostdata
->test_completed
= -1;
1891 hostdata
->test_dest
= 0;
1892 hostdata
->test_source
= 0xdeadbeef;
1893 start
= virt_to_bus (hostdata
->script
) + hostdata
->E_test_1
;
1894 hostdata
->state
= STATE_RUNNING
;
1895 printk ("scsi%d : test 1", host
->host_no
);
1896 NCR53c7x0_write32 (DSP_REG
, start
);
1897 printk (" started\n");
1901 * This is currently a .5 second timeout, since (in theory) no slow
1902 * board will take that long. In practice, we've seen one
1903 * pentium which occasionally fails with this, but works with
1907 timeout
= jiffies
+ 5 * HZ
/ 10;
1908 while ((hostdata
->test_completed
== -1) && jiffies
< timeout
)
1912 if (hostdata
->test_completed
== -1)
1913 printk ("scsi%d : driver test 1 timed out%s\n",host
->host_no
,
1914 (hostdata
->test_dest
== 0xdeadbeef) ?
1915 " due to lost interrupt.\n"
1916 " Please verify that the correct IRQ is being used for your board,\n"
1917 " and that the motherboard IRQ jumpering matches the PCI setup on\n"
1919 " If you are using a NCR53c810 board in a PCI system, you should\n"
1920 " also verify that the board is jumpered to use PCI INTA, since\n"
1921 " most PCI motherboards lack support for INTB, INTC, and INTD.\n"
1923 else if (hostdata
->test_completed
!= 1)
1924 printk ("scsi%d : test 1 bad interrupt value (%d)\n",
1925 host
->host_no
, hostdata
->test_completed
);
1927 failed
= (hostdata
->test_dest
!= 0xdeadbeef);
1929 if (hostdata
->test_dest
!= 0xdeadbeef) {
1930 printk ("scsi%d : driver test 1 read 0x%x instead of 0xdeadbeef indicating a\n"
1931 " probable cache invalidation problem. Please configure caching\n"
1932 " as write-through or disabled\n",
1933 host
->host_no
, hostdata
->test_dest
);
1937 printk ("scsi%d : DSP = 0x%p (script at 0x%p, start at 0x%x)\n",
1938 host
->host_no
, bus_to_virt(NCR53c7x0_read32(DSP_REG
)),
1939 hostdata
->script
, start
);
1940 printk ("scsi%d : DSPS = 0x%x\n", host
->host_no
,
1941 NCR53c7x0_read32(DSPS_REG
));
1942 restore_flags(flags
);
1945 hostdata
->test_running
= 0;
1948 if ((hostdata
->options
& OPTION_DEBUG_TEST2
) &&
1949 hostdata
->state
!= STATE_DISABLED
) {
1951 unsigned char identify
= IDENTIFY(0, 0);
1952 unsigned char cmd
[6];
1953 unsigned char data
[36];
1954 unsigned char status
= 0xff;
1955 unsigned char msg
= 0xff;
1958 cmd
[1] = cmd
[2] = cmd
[3] = cmd
[5] = 0;
1959 cmd
[4] = sizeof(data
);
1961 /* Need to adjust for endian-ness */
1962 dsa
[2] = le32_to_cpu(1);
1963 dsa
[3] = le32_to_cpu(virt_to_bus(&identify
));
1964 dsa
[4] = le32_to_cpu(6);
1965 dsa
[5] = le32_to_cpu(virt_to_bus(&cmd
));
1966 dsa
[6] = le32_to_cpu(sizeof(data
));
1967 dsa
[7] = le32_to_cpu(virt_to_bus(&data
));
1968 dsa
[8] = le32_to_cpu(1);
1969 dsa
[9] = le32_to_cpu(virt_to_bus(&status
));
1970 dsa
[10] = le32_to_cpu(1);
1971 dsa
[11] = le32_to_cpu(virt_to_bus(&msg
));
1973 for (i
= 0; i
< 3; ++i
) {
1975 if (!hostdata
->idle
) {
1976 printk ("scsi%d : chip not idle, aborting tests\n", host
->host_no
);
1977 restore_flags(flags
);
1982 dsa
[0] = le32_to_cpu((0x33 << 24) | (i
<< 16)) ;
1984 hostdata
->test_running
= 2;
1985 hostdata
->test_completed
= -1;
1986 start
= virt_to_bus(hostdata
->script
) + hostdata
->E_test_2
;
1987 hostdata
->state
= STATE_RUNNING
;
1988 NCR53c7x0_write32 (DSA_REG
, virt_to_bus(dsa
));
1989 NCR53c7x0_write32 (DSP_REG
, start
);
1992 timeout
= jiffies
+ 5 * HZ
; /* arbitrary */
1993 while ((hostdata
->test_completed
== -1) && jiffies
< timeout
)
1995 NCR53c7x0_write32 (DSA_REG
, 0);
1997 if (hostdata
->test_completed
== 2) {
1999 printk ("scsi%d : test 2 INQUIRY to target %d, lun 0 : %s\n",
2000 host
->host_no
, i
, data
+ 8);
2001 printk ("scsi%d : status ", host
->host_no
);
2002 print_status (status
);
2003 printk ("\nscsi%d : message ", host
->host_no
);
2006 } else if (hostdata
->test_completed
== 3) {
2007 printk("scsi%d : test 2 no connection with target %d\n",
2009 if (!hostdata
->idle
) {
2010 printk("scsi%d : not idle\n", host
->host_no
);
2011 restore_flags(flags
);
2014 } else if (hostdata
->test_completed
== -1) {
2015 printk ("scsi%d : test 2 timed out\n", host
->host_no
);
2016 restore_flags(flags
);
2019 hostdata
->test_running
= 0;
2023 restore_flags(flags
);
2028 * Function : static void NCR53c8xx_dsa_fixup (struct NCR53c7x0_cmd *cmd)
2030 * Purpose : copy the NCR53c8xx dsa structure into cmd's dsa buffer,
2031 * performing all necessary relocation.
2033 * Inputs : cmd, a NCR53c7x0_cmd structure with a dsa area large
2034 * enough to hold the NCR53c8xx dsa.
2038 NCR53c8xx_dsa_fixup (struct NCR53c7x0_cmd
*cmd
) {
2039 Scsi_Cmnd
*c
= cmd
->cmd
;
2040 struct Scsi_Host
*host
= c
->host
;
2041 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
2046 unsigned long *dsa_ptr
;
2049 memcpy (cmd
->dsa
, hostdata
->script
+ (hostdata
->E_dsa_code_template
/ 4),
2050 hostdata
->E_dsa_code_template_end
- hostdata
->E_dsa_code_template
);
2052 /* Note: the script has already been 'endianized' */
2054 len
= hostdata
->E_dsa_code_template_end
- hostdata
->E_dsa_code_template
;
2055 for (i
= 0; i
< len
; i
+= sizeof(long))
2057 *dsa_ptr
++ = le32_to_cpu(*dsa_ptr
);
2062 * Note : within the NCR 'C' code, dsa points to the _start_
2063 * of the DSA structure, and _not_ the offset of dsa_zero within
2064 * that structure used to facilitate shorter signed offsets
2065 * for the 8 bit ALU.
2067 * The implications of this are that
2069 * - 32 bit A_dsa_* absolute values require an additional
2070 * dsa_zero added to their value to be correct, since they are
2071 * relative to dsa_zero which is in essentially a separate
2072 * space from the code symbols.
2074 * - All other symbols require no special treatment.
2077 patch_abs_tci_data (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
2078 dsa_temp_lun
, c
->lun
);
2079 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
2080 dsa_temp_addr_next
, virt_to_bus(&cmd
->dsa_next_addr
));
2081 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
2082 dsa_temp_next
, virt_to_bus(cmd
->dsa
) + Ent_dsa_zero
-
2083 Ent_dsa_code_template
+ A_dsa_next
);
2084 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
2085 dsa_temp_sync
, virt_to_bus((void *)hostdata
->sync
[c
->target
].script
));
2086 patch_abs_tci_data (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
2087 dsa_temp_target
, c
->target
);
2088 /* XXX - new pointer stuff */
2089 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
2090 dsa_temp_addr_saved_pointer
, virt_to_bus(&cmd
->saved_data_pointer
));
2091 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
2092 dsa_temp_addr_saved_residual
, virt_to_bus(&cmd
->saved_residual
));
2093 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
2094 dsa_temp_addr_residual
, virt_to_bus(&cmd
->residual
));
2096 /* XXX - new start stuff */
2097 patch_abs_32 (cmd
->dsa
, Ent_dsa_code_template
/ sizeof(u32
),
2098 dsa_temp_addr_dsa_value
, virt_to_bus(&cmd
->dsa_addr
));
2101 len
= hostdata
->E_dsa_code_template_end
- hostdata
->E_dsa_code_template
;
2102 for (i
= 0; i
< len
; i
+= sizeof(long))
2104 *dsa_ptr
++ = le32_to_cpu(*dsa_ptr
);
2111 * Function : run_process_issue_queue (void)
2113 * Purpose : insure that the coroutine is running and will process our
2114 * request. process_issue_queue_running is checked/set here (in an
2115 * inline function) rather than in process_issue_queue itself to reduce
2116 * the chances of stack overflow.
2120 static volatile int process_issue_queue_running
= 0;
2122 static __inline__
void
2123 run_process_issue_queue(void) {
2124 unsigned long flags
;
2127 if (!process_issue_queue_running
) {
2128 process_issue_queue_running
= 1;
2129 process_issue_queue(flags
);
2131 * process_issue_queue_running is cleared in process_issue_queue
2132 * once it can't do more work, and process_issue_queue exits with
2133 * interrupts disabled.
2136 restore_flags (flags
);
2140 * Function : static void abnormal_finished (struct NCR53c7x0_cmd *cmd, int
2143 * Purpose : mark SCSI command as finished, OR'ing the host portion
2144 * of the result word into the result field of the corresponding
2145 * Scsi_Cmnd structure, and removing it from the internal queues.
2147 * Inputs : cmd - command, result - entire result field
2149 * Preconditions : the NCR chip should be in a halted state when
2150 * abnormal_finished is run, since it modifies structures which
2151 * the NCR expects to have exclusive access to.
2155 abnormal_finished (struct NCR53c7x0_cmd
*cmd
, int result
) {
2156 Scsi_Cmnd
*c
= cmd
->cmd
;
2157 struct Scsi_Host
*host
= c
->host
;
2158 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
2160 unsigned long flags
;
2162 volatile struct NCR53c7x0_cmd
* linux_search
;
2163 volatile struct NCR53c7x0_cmd
* volatile *linux_prev
;
2164 volatile u32
*ncr_prev
, *curr
, ncr_search
;
2167 printk ("scsi%d: abnormal finished\n", host
->host_no
);
2174 * Traverse the NCR issue array until we find a match or run out
2175 * of instructions. Instructions in the NCR issue array are
2176 * either JUMP or NOP instructions, which are 2 words in length.
2180 for (found
= 0, left
= host
->can_queue
, curr
= hostdata
->schedule
;
2181 left
> 0; --left
, curr
+= 2)
2183 if (issue_to_cmd (host
, hostdata
, (u32
*) curr
) == cmd
)
2185 curr
[0] = hostdata
->NOP_insn
;
2186 curr
[1] = le32_to_cpu(0xdeadbeef);
2193 * Traverse the NCR reconnect list of DSA structures until we find
2194 * a pointer to this dsa or have found too many command structures.
2195 * We let prev point at the next field of the previous element or
2196 * head of the list, so we don't do anything different for removing
2200 for (left
= host
->can_queue
,
2201 ncr_search
= le32_to_cpu(hostdata
->reconnect_dsa_head
),
2202 ncr_prev
= &hostdata
->reconnect_dsa_head
;
2203 left
>= 0 && ncr_search
&&
2204 ((char*)bus_to_virt(ncr_search
) + hostdata
->dsa_start
)
2205 != (char *) cmd
->dsa
;
2206 ncr_prev
= (u32
*) ((char*)bus_to_virt(ncr_search
) +
2207 hostdata
->dsa_next
), ncr_search
= le32_to_cpu(*ncr_prev
), --left
);
2210 printk("scsi%d: loop detected in ncr reconnect list\n",
2212 else if (ncr_search
)
2214 printk("scsi%d: scsi %ld in ncr issue array and reconnect lists\n",
2215 host
->host_no
, c
->pid
);
2217 volatile u32
* next
= (u32
*)
2218 ((char *)bus_to_virt(ncr_search
) + hostdata
->dsa_next
);
2220 /* If we're at the tail end of the issue queue, update that pointer too. */
2225 * Traverse the host running list until we find this command or discover
2226 * we have too many elements, pointing linux_prev at the next field of the
2227 * linux_previous element or head of the list, search at this element.
2230 for (left
= host
->can_queue
, linux_search
= hostdata
->running_list
,
2231 linux_prev
= &hostdata
->running_list
;
2232 left
>= 0 && linux_search
&& linux_search
!= cmd
;
2233 linux_prev
= &(linux_search
->next
),
2234 linux_search
= linux_search
->next
, --left
);
2237 printk ("scsi%d: loop detected in host running list for scsi pid %ld\n",
2238 host
->host_no
, c
->pid
);
2239 else if (linux_search
) {
2240 *linux_prev
= linux_search
->next
;
2241 --hostdata
->busy
[c
->target
][c
->lun
];
2244 /* Return the NCR command structure to the free list */
2245 cmd
->next
= hostdata
->free
;
2246 hostdata
->free
= cmd
;
2247 c
->host_scribble
= NULL
;
2253 restore_flags(flags
);
2254 run_process_issue_queue();
2258 * Function : static void intr_break (struct Scsi_Host *host,
2259 * struct NCR53c7x0_cmd *cmd)
2261 * Purpose : Handler for breakpoint interrupts from a SCSI script
2263 * Inputs : host - pointer to this host adapter's structure,
2264 * cmd - pointer to the command (if any) dsa was pointing
2270 intr_break (struct Scsi_Host
*host
, struct
2271 NCR53c7x0_cmd
*cmd
) {
2272 NCR53c7x0_local_declare();
2273 struct NCR53c7x0_break
*bp
;
2275 Scsi_Cmnd
*c
= cmd
? cmd
->cmd
: NULL
;
2278 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
2280 unsigned long flags
;
2281 NCR53c7x0_local_setup(host
);
2284 * Find the break point corresponding to this address, and
2285 * dump the appropriate debugging information to standard
2290 dsp
= (u32
*) bus_to_virt(NCR53c7x0_read32(DSP_REG
));
2291 for (bp
= hostdata
->breakpoints
; bp
&& bp
->address
!= dsp
;
2294 panic("scsi%d : break point interrupt from %p with no breakpoint!",
2295 host
->host_no
, dsp
);
2298 * Configure the NCR chip for manual start mode, so that we can
2299 * point the DSP register at the instruction that follows the
2300 * INT int_debug_break instruction.
2303 NCR53c7x0_write8 (hostdata
->dmode
,
2304 NCR53c7x0_read8(hostdata
->dmode
)|DMODE_MAN
);
2307 * And update the DSP register, using the size of the old
2308 * instruction in bytes.
2311 restore_flags(flags
);
2314 * Function : static void print_synchronous (const char *prefix,
2315 * const unsigned char *msg)
2317 * Purpose : print a pretty, user and machine parsable representation
2318 * of a SDTR message, including the "real" parameters, data
2319 * clock so we can tell transfer rate at a glance.
2321 * Inputs ; prefix - text to prepend, msg - SDTR message (5 bytes)
2325 print_synchronous (const char *prefix
, const unsigned char *msg
) {
2327 int Hz
= 1000000000 / (msg
[3] * 4);
2328 int integer
= Hz
/ 1000000;
2329 int fraction
= (Hz
- (integer
* 1000000)) / 10000;
2330 printk ("%speriod %dns offset %d %d.%02dMHz %s SCSI%s\n",
2331 prefix
, (int) msg
[3] * 4, (int) msg
[4], integer
, fraction
,
2332 (((msg
[3] * 4) < 200) ? "FAST" : "synchronous"),
2333 (((msg
[3] * 4) < 200) ? "-II" : ""));
2335 printk ("%sasynchronous SCSI\n", prefix
);
2339 * Function : static void set_synchronous (struct Scsi_Host *host,
2340 * int target, int sxfer, int scntl3, int now_connected)
2342 * Purpose : reprogram transfers between the selected SCSI initiator and
2343 * target with the given register values; in the indirect
2344 * select operand, reselection script, and chip registers.
2346 * Inputs : host - NCR53c7,8xx SCSI host, target - number SCSI target id,
2347 * sxfer and scntl3 - NCR registers. now_connected - if non-zero,
2348 * we should reprogram the registers now too.
2352 set_synchronous (struct Scsi_Host
*host
, int target
, int sxfer
, int scntl3
,
2353 int now_connected
) {
2354 NCR53c7x0_local_declare();
2355 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
2358 NCR53c7x0_local_setup(host
);
2360 /* These are eight bit registers */
2364 hostdata
->sync
[target
].sxfer_sanity
= sxfer
;
2365 hostdata
->sync
[target
].scntl3_sanity
= scntl3
;
2368 * HARD CODED : synchronous script is EIGHT words long. This
2369 * must agree with 53c7.8xx.h
2372 if ((hostdata
->chip
!= 700) && (hostdata
->chip
!= 70066)) {
2373 hostdata
->sync
[target
].select_indirect
= (scntl3
<< 24) |
2374 (target
<< 16) | (sxfer
<< 8);
2376 script
= (u32
*) hostdata
->sync
[target
].script
;
2378 /* XXX - add NCR53c7x0 code to reprogram SCF bits if we want to */
2379 if ((hostdata
->chip
/ 100) == 8) {
2380 script
[0] = ((DCMD_TYPE_RWRI
| DCMD_RWRI_OPC_MODIFY
|
2381 DCMD_RWRI_OP_MOVE
) << 24) |
2382 (SCNTL3_REG_800
<< 16) | (scntl3
<< 8);
2387 script
[0] = ((DCMD_TYPE_RWRI
| DCMD_RWRI_OPC_MODIFY
|
2388 DCMD_RWRI_OP_MOVE
) << 24) |
2389 (SXFER_REG
<< 16) | (sxfer
<< 8);
2393 #ifdef DEBUG_SYNC_INTR
2394 if (hostdata
->options
& OPTION_DEBUG_DISCONNECT
) {
2395 script
[0] = ((DCMD_TYPE_TCI
|DCMD_TCI_OP_INT
) << 24) | DBC_TCI_TRUE
;
2396 script
[1] = DEBUG_SYNC_INTR
;
2401 script
[0] = ((DCMD_TYPE_TCI
|DCMD_TCI_OP_RETURN
) << 24) | DBC_TCI_TRUE
;
2406 if (hostdata
->options
& OPTION_DEBUG_SYNCHRONOUS
)
2407 printk ("scsi%d : target %d sync parameters are sxfer=0x%x, scntl3=0x%x\n",
2408 host
->host_no
, target
, sxfer
, scntl3
);
2410 if (now_connected
) {
2411 if ((hostdata
->chip
/ 100) == 8)
2412 NCR53c7x0_write8(SCNTL3_REG_800
, scntl3
);
2413 NCR53c7x0_write8(SXFER_REG
, sxfer
);
2419 * Function : static int asynchronous (struct Scsi_Host *host, int target)
2421 * Purpose : reprogram between the selected SCSI Host adapter and target
2422 * (assumed to be currently connected) for asynchronous transfers.
2424 * Inputs : host - SCSI host structure, target - numeric target ID.
2426 * Preconditions : the NCR chip should be in one of the halted states
2430 asynchronous (struct Scsi_Host
*host
, int target
) {
2431 NCR53c7x0_local_declare();
2432 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
2434 NCR53c7x0_local_setup(host
);
2435 set_synchronous (host
, target
, /* no offset */ 0, hostdata
->saved_scntl3
,
2437 printk ("scsi%d : setting target %d to asynchronous SCSI\n",
2438 host
->host_no
, target
);
2442 * XXX - do we want to go out of our way (ie, add extra code to selection
2443 * in the NCR53c710/NCR53c720 script) to reprogram the synchronous
2444 * conversion bits, or can we be content in just setting the
2448 /* Table for NCR53c8xx synchronous values */
2449 static const struct {
2450 int div
; /* Total clock divisor * 10 */
2451 unsigned char scf
; /* */
2452 unsigned char tp
; /* 4 + tp = xferp divisor */
2454 /* div scf tp div scf tp div scf tp */
2455 { 40, 1, 0}, { 50, 1, 1}, { 60, 1, 2},
2456 { 70, 1, 3}, { 75, 2, 1}, { 80, 1, 4},
2457 { 90, 1, 5}, { 100, 1, 6}, { 105, 2, 3},
2458 { 110, 1, 7}, { 120, 2, 4}, { 135, 2, 5},
2459 { 140, 3, 3}, { 150, 2, 6}, { 160, 3, 4},
2460 { 165, 2, 7}, { 180, 3, 5}, { 200, 3, 6},
2461 { 210, 4, 3}, { 220, 3, 7}, { 240, 4, 4},
2462 { 270, 4, 5}, { 300, 4, 6}, { 330, 4, 7}
2466 * Function : static void synchronous (struct Scsi_Host *host, int target,
2469 * Purpose : reprogram transfers between the selected SCSI initiator and
2470 * target for synchronous SCSI transfers such that the synchronous
2471 * offset is less than that requested and period at least as long
2472 * as that requested. Also modify *msg such that it contains
2473 * an appropriate response.
2475 * Inputs : host - NCR53c7,8xx SCSI host, target - number SCSI target id,
2476 * msg - synchronous transfer request.
2481 synchronous (struct Scsi_Host
*host
, int target
, char *msg
) {
2482 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
2484 int desire
, divisor
, i
, limit
;
2485 unsigned char scntl3
, sxfer
;
2486 /* The diagnostic message fits on one line, even with max. width integers */
2489 /* Desired transfer clock in Hz */
2490 desire
= 1000000000L / (msg
[3] * 4);
2491 /* Scale the available SCSI clock by 10 so we get tenths */
2492 divisor
= (hostdata
->scsi_clock
* 10) / desire
;
2494 /* NCR chips can handle at most an offset of 8 */
2498 if (hostdata
->options
& OPTION_DEBUG_SDTR
)
2499 printk("scsi%d : optimal synchronous divisor of %d.%01d\n",
2500 host
->host_no
, divisor
/ 10, divisor
% 10);
2502 limit
= (sizeof(syncs
) / sizeof(syncs
[0]) -1);
2503 for (i
= 0; (i
< limit
) && (divisor
> syncs
[i
].div
); ++i
);
2505 if (hostdata
->options
& OPTION_DEBUG_SDTR
)
2506 printk("scsi%d : selected synchronous divisor of %d.%01d\n",
2507 host
->host_no
, syncs
[i
].div
/ 10, syncs
[i
].div
% 10);
2509 msg
[3] = ((1000000000L / hostdata
->scsi_clock
) * syncs
[i
].div
/ 10 / 4);
2511 if (hostdata
->options
& OPTION_DEBUG_SDTR
)
2512 printk("scsi%d : selected synchronous period of %dns\n", host
->host_no
,
2515 scntl3
= (hostdata
->chip
/ 100 == 8) ? ((hostdata
->saved_scntl3
&
2516 ~SCNTL3_800_SCF_MASK
) | (syncs
[i
].scf
<< SCNTL3_800_SCF_SHIFT
)) : 0;
2517 sxfer
= (msg
[4] << SXFER_MO_SHIFT
) | ((syncs
[i
].tp
) << SXFER_TP_SHIFT
);
2518 if (hostdata
->options
& OPTION_DEBUG_SDTR
)
2519 printk ("scsi%d : sxfer=0x%x scntl3=0x%x\n",
2520 host
->host_no
, (int) sxfer
, (int) scntl3
);
2521 set_synchronous (host
, target
, sxfer
, scntl3
, 1);
2522 sprintf (buf
, "scsi%d : setting target %d to ", host
->host_no
, target
);
2523 print_synchronous (buf
, msg
);
2527 * Function : static int NCR53c8x0_dstat_sir_intr (struct Scsi_Host *host,
2528 * struct NCR53c7x0_cmd *cmd)
2530 * Purpose : Handler for INT generated instructions for the
2531 * NCR53c810/820 SCSI SCRIPT
2533 * Inputs : host - pointer to this host adapter's structure,
2534 * cmd - pointer to the command (if any) dsa was pointing
2540 NCR53c8x0_dstat_sir_intr (struct Scsi_Host
*host
, struct
2541 NCR53c7x0_cmd
*cmd
) {
2542 NCR53c7x0_local_declare();
2544 Scsi_Cmnd
*c
= cmd
? cmd
->cmd
: NULL
;
2545 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
2547 u32 dsps
,*dsp
; /* Argument of the INT instruction */
2548 NCR53c7x0_local_setup(host
);
2549 dsps
= NCR53c7x0_read32(DSPS_REG
);
2550 dsp
= (u32
*) bus_to_virt(NCR53c7x0_read32(DSP_REG
));
2552 if (hostdata
->options
& OPTION_DEBUG_INTR
)
2553 printk ("scsi%d : DSPS = 0x%x\n", host
->host_no
, dsps
);
2558 switch (hostdata
->msg_buf
[0]) {
2560 * Unless we've initiated synchronous negotiation, I don't
2561 * think that this should happen.
2563 case MESSAGE_REJECT
:
2564 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_accept_message
/
2566 hostdata
->dsp_changed
= 1;
2567 if (cmd
&& (cmd
->flags
& CMD_FLAG_SDTR
)) {
2568 printk ("scsi%d : target %d rejected SDTR\n", host
->host_no
,
2570 cmd
->flags
&= ~CMD_FLAG_SDTR
;
2571 asynchronous (host
, c
->target
);
2575 case INITIATE_RECOVERY
:
2576 printk ("scsi%d : extended contingent allegiance not supported yet, rejecting\n",
2578 /* Fall through to default */
2579 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_reject_message
/
2581 hostdata
->dsp_changed
= 1;
2584 printk ("scsi%d : unsupported message, rejecting\n",
2586 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_reject_message
/
2588 hostdata
->dsp_changed
= 1;
2591 printk ("scsi%d : received message", host
->host_no
);
2593 printk (" from target %d lun %d ", c
->target
, c
->lun
);
2594 print_msg ((unsigned char *) hostdata
->msg_buf
);
2598 return SPECIFIC_INT_NOTHING
;
2601 case A_int_msg_sdtr
:
2603 * At this point, hostdata->msg_buf contains
2604 * 0 EXTENDED MESSAGE
2613 sprintf (buf
, "scsi%d : target %d %s ", host
->host_no
, c
->target
,
2614 (cmd
->flags
& CMD_FLAG_SDTR
) ? "accepting" : "requesting");
2615 print_synchronous (buf
, (unsigned char *) hostdata
->msg_buf
);
2618 * Initiator initiated, won't happen unless synchronous
2619 * transfers are enabled. If we get a SDTR message in
2620 * response to our SDTR, we should program our parameters
2622 * offset <= requested offset
2623 * period >= requested period
2625 if (cmd
->flags
& CMD_FLAG_SDTR
) {
2626 cmd
->flags
&= ~CMD_FLAG_SDTR
;
2627 if (hostdata
->msg_buf
[4])
2628 synchronous (host
, c
->target
, (unsigned char *)
2631 asynchronous (host
, c
->target
);
2632 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_accept_message
/
2634 hostdata
->dsp_changed
= 1;
2635 return SPECIFIC_INT_NOTHING
;
2637 if (hostdata
->options
& OPTION_SYNCHRONOUS
) {
2638 cmd
->flags
|= CMD_FLAG_DID_SDTR
;
2639 synchronous (host
, c
->target
, (unsigned char *)
2642 hostdata
->msg_buf
[4] = 0; /* 0 offset = async */
2643 asynchronous (host
, c
->target
);
2645 patch_dsa_32 (cmd
->dsa
, dsa_msgout_other
, 0, le32_to_cpu(5));
2646 patch_dsa_32 (cmd
->dsa
, dsa_msgout_other
, 1, (u32
)
2647 le32_to_cpu(virt_to_bus ((void *)&hostdata
->msg_buf
)));
2648 hostdata
->dsp
= hostdata
->script
+
2649 hostdata
->E_respond_message
/ sizeof(u32
);
2650 hostdata
->dsp_changed
= 1;
2652 return SPECIFIC_INT_NOTHING
;
2654 /* Fall through to abort if we couldn't find a cmd, and
2655 therefore a dsa structure to twiddle */
2656 case A_int_msg_wdtr
:
2657 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_reject_message
/
2659 hostdata
->dsp_changed
= 1;
2660 return SPECIFIC_INT_NOTHING
;
2661 case A_int_err_unexpected_phase
:
2662 if (hostdata
->options
& OPTION_DEBUG_INTR
)
2663 printk ("scsi%d : unexpected phase\n", host
->host_no
);
2664 return SPECIFIC_INT_ABORT
;
2665 case A_int_err_selected
:
2666 printk ("scsi%d : selected by target %d\n", host
->host_no
,
2667 (int) NCR53c7x0_read8(SDID_REG_800
) &7);
2668 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_target_abort
/
2670 hostdata
->dsp_changed
= 1;
2671 return SPECIFIC_INT_NOTHING
;
2672 case A_int_err_unexpected_reselect
:
2673 printk ("scsi%d : unexpected reselect by target %d lun %d\n",
2674 host
->host_no
, (int) NCR53c7x0_read8(SDID_REG_800
) & 7,
2675 hostdata
->reselected_identify
& 7);
2676 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_initiator_abort
/
2678 hostdata
->dsp_changed
= 1;
2679 return SPECIFIC_INT_NOTHING
;
2681 * Since contingent allegiance conditions are cleared by the next
2682 * command issued to a target, we must issue a REQUEST SENSE
2683 * command after receiving a CHECK CONDITION status, before
2684 * another command is issued.
2686 * Since this NCR53c7x0_cmd will be freed after use, we don't
2687 * care if we step on the various fields, so modify a few things.
2689 case A_int_err_check_condition
:
2691 if (hostdata
->options
& OPTION_DEBUG_INTR
)
2693 printk ("scsi%d : CHECK CONDITION\n", host
->host_no
);
2695 printk("scsi%d : CHECK CONDITION with no SCSI command\n",
2697 return SPECIFIC_INT_PANIC
;
2701 * FIXME : this uses the normal one-byte selection message.
2702 * We may want to renegotiate for synchronous & WIDE transfers
2703 * since these could be the crux of our problem.
2705 hostdata->NOP_insn* FIXME : once SCSI-II tagged queuing is implemented, we'll
2706 * have to set this up so that the rest of the DSA
2707 * agrees with this being an untagged queue'd command.
2710 patch_dsa_32 (cmd
->dsa
, dsa_msgout
, 0, le32_to_cpu(1));
2713 * Modify the table indirect for COMMAND OUT phase, since
2714 * Request Sense is a six byte command.
2717 patch_dsa_32 (cmd
->dsa
, dsa_cmdout
, 0, le32_to_cpu(6));
2719 c
->cmnd
[0] = REQUEST_SENSE
;
2720 c
->cmnd
[1] &= 0xe0; /* Zero all but LUN */
2723 c
->cmnd
[4] = sizeof(c
->sense_buffer
);
2727 * Disable dataout phase, and program datain to transfer to the
2728 * sense buffer, and add a jump to other_transfer after the
2729 * command so overflow/underrun conditions are detected.
2732 patch_dsa_32 (cmd
->dsa
, dsa_dataout
, 0,
2733 le32_to_cpu(virt_to_bus(hostdata
->script
) + hostdata
->E_other_transfer
));
2734 patch_dsa_32 (cmd
->dsa
, dsa_datain
, 0,
2735 le32_to_cpu(virt_to_bus(cmd
->data_transfer_start
)));
2736 cmd
->data_transfer_start
[0] = le32_to_cpu((((DCMD_TYPE_BMI
| DCMD_BMI_OP_MOVE_I
|
2737 DCMD_BMI_IO
)) << 24) | sizeof(c
->sense_buffer
));
2738 cmd
->data_transfer_start
[1] = (u32
) le32_to_cpu(virt_to_bus(c
->sense_buffer
));
2740 cmd
->data_transfer_start
[2] = le32_to_cpu(((DCMD_TYPE_TCI
| DCMD_TCI_OP_JUMP
)
2741 << 24) | DBC_TCI_TRUE
);
2742 cmd
->data_transfer_start
[3] = (u32
) le32_to_cpu(virt_to_bus(hostdata
->script
) +
2743 hostdata
->E_other_transfer
);
2746 * Currently, this command is flagged as completed, ie
2747 * it has valid status and message data. Reflag it as
2748 * incomplete. Q - need to do something so that original
2749 * status, etc are used.
2752 cmd
->cmd
->result
= le32_to_cpu(0xffff);
2755 * Restart command as a REQUEST SENSE.
2757 hostdata
->dsp
= (u32
*) hostdata
->script
+ hostdata
->E_select
/
2759 hostdata
->dsp_changed
= 1;
2760 return SPECIFIC_INT_NOTHING
;
2761 case A_int_debug_break
:
2762 return SPECIFIC_INT_BREAK
;
2763 case A_int_norm_aborted
:
2764 hostdata
->dsp
= (u32
*) hostdata
->schedule
;
2765 hostdata
->dsp_changed
= 1;
2767 abnormal_finished (cmd
, DID_ERROR
<< 16);
2768 return SPECIFIC_INT_NOTHING
;
2772 hostdata
->test_completed
= (dsps
- A_int_test_1
) / 0x00010000 + 1;
2773 if (hostdata
->options
& OPTION_DEBUG_INTR
)
2774 printk("scsi%d : test%d complete\n", host
->host_no
,
2775 hostdata
->test_completed
);
2776 return SPECIFIC_INT_NOTHING
;
2777 #ifdef A_int_debug_reselected_ok
2778 case A_int_debug_reselected_ok
:
2779 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
|
2780 OPTION_DEBUG_DISCONNECT
)) {
2782 * Note - this dsa is not based on location relative to
2783 * the command structure, but to location relative to the
2787 dsa
= (u32
*) bus_to_virt (NCR53c7x0_read32(DSA_REG
));
2789 printk("scsi%d : reselected_ok (DSA = 0x%x (virt 0x%p)\n",
2790 host
->host_no
, NCR53c7x0_read32(DSA_REG
), dsa
);
2791 printk("scsi%d : resume address is 0x%x (virt 0x%p)\n",
2792 host
->host_no
, cmd
->saved_data_pointer
,
2793 bus_to_virt(le32_to_cpu(cmd
->saved_data_pointer
)));
2794 print_insn (host
, hostdata
->script
+ Ent_reselected_ok
/
2795 sizeof(u32
), "", 1);
2796 printk ("scsi%d : sxfer=0x%x, scntl3=0x%x\n",
2797 host
->host_no
, NCR53c7x0_read8(SXFER_REG
),
2798 NCR53c7x0_read8(SCNTL3_REG_800
));
2800 print_insn (host
, (u32
*)
2801 hostdata
->sync
[c
->target
].script
, "", 1);
2802 print_insn (host
, (u32
*)
2803 hostdata
->sync
[c
->target
].script
+ 2, "", 1);
2806 return SPECIFIC_INT_RESTART
;
2808 #ifdef A_int_debug_reselect_check
2809 case A_int_debug_reselect_check
:
2810 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
)) {
2816 * Note - this dsa is not based on location relative to
2817 * the command structure, but to location relative to the
2820 dsa
= bus_to_virt (NCR53c7x0_read32(DSA_REG
));
2821 printk("scsi%d : reselected_check_next (DSA = 0x%lx (virt 0x%p))\n",
2822 host
->host_no
, virt_to_bus(dsa
), dsa
);
2824 printk("scsi%d : resume address is 0x%x (virt 0x%p)\n",
2825 host
->host_no
, cmd
->saved_data_pointer
,
2826 bus_to_virt (le32_to_cpu(cmd
->saved_data_pointer
)));
2828 printk("scsi%d : template code :\n", host
->host_no
);
2829 for (code
= dsa
+ (Ent_dsa_code_check_reselect
- Ent_dsa_zero
)
2830 / sizeof(u32
); code
< (dsa
+ Ent_dsa_zero
/ sizeof(u32
));
2831 code
+= print_insn (host
, code
, "", 1));
2834 print_insn (host
, hostdata
->script
+ Ent_reselected_ok
/
2835 sizeof(u32
), "", 1);
2837 return SPECIFIC_INT_RESTART
;
2839 #ifdef A_int_debug_dsa_schedule
2840 case A_int_debug_dsa_schedule
:
2841 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
)) {
2844 * Note - this dsa is not based on location relative to
2845 * the command structure, but to location relative to the
2848 dsa
= (u32
*) bus_to_virt (NCR53c7x0_read32(DSA_REG
));
2849 printk("scsi%d : dsa_schedule (old DSA = 0x%lx (virt 0x%p))\n",
2850 host
->host_no
, virt_to_bus(dsa
), dsa
);
2852 printk("scsi%d : resume address is 0x%x (virt 0x%p)\n"
2853 " (temp was 0x%x (virt 0x%p))\n",
2854 host
->host_no
, cmd
->saved_data_pointer
,
2855 bus_to_virt (le32_to_cpu(cmd
->saved_data_pointer
)),
2856 NCR53c7x0_read32 (TEMP_REG
),
2857 bus_to_virt (NCR53c7x0_read32(TEMP_REG
)));
2859 return SPECIFIC_INT_RESTART
;
2861 #ifdef A_int_debug_scheduled
2862 case A_int_debug_scheduled
:
2863 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
)) {
2864 printk("scsi%d : new I/O 0x%x (virt 0x%p) scheduled\n",
2865 host
->host_no
, NCR53c7x0_read32(DSA_REG
),
2866 bus_to_virt(NCR53c7x0_read32(DSA_REG
)));
2868 return SPECIFIC_INT_RESTART
;
2870 #ifdef A_int_debug_idle
2871 case A_int_debug_idle
:
2872 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
)) {
2873 printk("scsi%d : idle\n", host
->host_no
);
2875 return SPECIFIC_INT_RESTART
;
2877 #ifdef A_int_debug_cmd
2878 case A_int_debug_cmd
:
2879 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
)) {
2880 printk("scsi%d : command sent\n");
2882 return SPECIFIC_INT_RESTART
;
2884 #ifdef A_int_debug_dsa_loaded
2885 case A_int_debug_dsa_loaded
:
2886 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
)) {
2887 printk("scsi%d : DSA loaded with 0x%x (virt 0x%p)\n", host
->host_no
,
2888 NCR53c7x0_read32(DSA_REG
),
2889 bus_to_virt(NCR53c7x0_read32(DSA_REG
)));
2891 return SPECIFIC_INT_RESTART
;
2893 #ifdef A_int_debug_reselected
2894 case A_int_debug_reselected
:
2895 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
|
2896 OPTION_DEBUG_DISCONNECT
)) {
2897 printk("scsi%d : reselected by target %d lun %d\n",
2898 host
->host_no
, (int) NCR53c7x0_read8(SDID_REG_800
) & ~0x80,
2899 (int) hostdata
->reselected_identify
& 7);
2902 return SPECIFIC_INT_RESTART
;
2904 #ifdef A_int_debug_disconnect_msg
2905 case A_int_debug_disconnect_msg
:
2906 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
)) {
2908 printk("scsi%d : target %d lun %d disconnecting\n",
2909 host
->host_no
, c
->target
, c
->lun
);
2911 printk("scsi%d : unknown target disconnecting\n",
2914 return SPECIFIC_INT_RESTART
;
2916 #ifdef A_int_debug_disconnected
2917 case A_int_debug_disconnected
:
2918 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
|
2919 OPTION_DEBUG_DISCONNECT
)) {
2920 printk ("scsi%d : disconnected, new queues are\n",
2924 printk ("scsi%d : sxfer=0x%x, scntl3=0x%x\n",
2925 host
->host_no
, NCR53c7x0_read8(SXFER_REG
),
2926 NCR53c7x0_read8(SCNTL3_REG_800
));
2929 print_insn (host
, (u32
*)
2930 hostdata
->sync
[c
->target
].script
, "", 1);
2931 print_insn (host
, (u32
*)
2932 hostdata
->sync
[c
->target
].script
+ 2, "", 1);
2935 return SPECIFIC_INT_RESTART
;
2937 #ifdef A_int_debug_panic
2938 case A_int_debug_panic
:
2939 printk("scsi%d : int_debug_panic received\n", host
->host_no
);
2941 return SPECIFIC_INT_PANIC
;
2943 #ifdef A_int_debug_saved
2944 case A_int_debug_saved
:
2945 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
|
2946 OPTION_DEBUG_DISCONNECT
)) {
2947 printk ("scsi%d : saved data pointer 0x%x (virt 0x%p)\n",
2948 host
->host_no
, cmd
->saved_data_pointer
,
2949 bus_to_virt (le32_to_cpu(cmd
->saved_data_pointer
)));
2952 return SPECIFIC_INT_RESTART
;
2954 #ifdef A_int_debug_restored
2955 case A_int_debug_restored
:
2956 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
|
2957 OPTION_DEBUG_DISCONNECT
)) {
2960 printk ("scsi%d : restored data pointer 0x%x (virt 0x%p)\n",
2961 host
->host_no
, cmd
->saved_data_pointer
, bus_to_virt (
2962 le32_to_cpu(cmd
->saved_data_pointer
)));
2963 size
= print_insn (host
, (u32
*)
2964 bus_to_virt(le32_to_cpu(cmd
->saved_data_pointer
)), "", 1);
2965 size
= print_insn (host
, (u32
*)
2966 bus_to_virt(le32_to_cpu(cmd
->saved_data_pointer
)) + size
, "", 1);
2970 printk ("scsi%d : datapath residual %d\n",
2971 host
->host_no
, datapath_residual (host
)) ;
2974 return SPECIFIC_INT_RESTART
;
2976 #ifdef A_int_debug_sync
2977 case A_int_debug_sync
:
2978 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
|
2979 OPTION_DEBUG_DISCONNECT
|OPTION_DEBUG_SDTR
)) {
2980 unsigned char sxfer
= NCR53c7x0_read8 (SXFER_REG
),
2981 scntl3
= NCR53c7x0_read8 (SCNTL3_REG_800
);
2983 if (sxfer
!= hostdata
->sync
[c
->target
].sxfer_sanity
||
2984 scntl3
!= hostdata
->sync
[c
->target
].scntl3_sanity
) {
2985 printk ("scsi%d : sync sanity check failed sxfer=0x%x, scntl3=0x%x",
2986 host
->host_no
, sxfer
, scntl3
);
2987 NCR53c7x0_write8 (SXFER_REG
, sxfer
);
2988 NCR53c7x0_write8 (SCNTL3_REG_800
, scntl3
);
2991 printk ("scsi%d : unknown command sxfer=0x%x, scntl3=0x%x\n",
2992 host
->host_no
, (int) sxfer
, (int) scntl3
);
2994 return SPECIFIC_INT_RESTART
;
2996 #ifdef A_int_debug_datain
2997 case A_int_debug_datain
:
2998 if (hostdata
->options
& (OPTION_DEBUG_SCRIPT
|OPTION_DEBUG_INTR
|
2999 OPTION_DEBUG_DISCONNECT
|OPTION_DEBUG_SDTR
)) {
3001 printk ("scsi%d : In do_datain (%s) sxfer=0x%x, scntl3=0x%x\n"
3002 " datapath residual=%d\n",
3003 host
->host_no
, sbcl_to_phase (NCR53c7x0_read8 (SBCL_REG
)),
3004 (int) NCR53c7x0_read8(SXFER_REG
),
3005 (int) NCR53c7x0_read8(SCNTL3_REG_800
),
3006 datapath_residual (host
)) ;
3007 print_insn (host
, dsp
, "", 1);
3008 size
= print_insn (host
, (u32
*) bus_to_virt(le32_to_cpu(dsp
[1])), "", 1);
3009 print_insn (host
, (u32
*) bus_to_virt(le32_to_cpu(dsp
[1])) + size
, "", 1);
3011 return SPECIFIC_INT_RESTART
;
3014 * FIXME : for 7xx support, we need to read SDID_REG_700 and handle
3015 * the comparison as bitfielded, not binary.
3017 #ifdef A_int_debug_check_dsa
3018 case A_int_debug_check_dsa
:
3019 if (NCR53c7x0_read8 (SCNTL1_REG
) & SCNTL1_CON
) {
3020 int sdid
= NCR53c7x0_read8 (SDID_REG_800
) & 15;
3021 char *where
= dsp
- NCR53c7x0_insn_size(NCR53c7x0_read8
3022 (DCMD_REG
)) == hostdata
->script
+
3023 Ent_select_check_dsa
/ sizeof(u32
) ?
3024 "selection" : "reselection";
3025 if (c
&& sdid
!= c
->target
) {
3026 printk ("scsi%d : SDID target %d != DSA target %d at %s\n",
3027 host
->host_no
, sdid
, c
->target
, where
);
3029 dump_events (host
, 20);
3030 return SPECIFIC_INT_PANIC
;
3033 return SPECIFIC_INT_RESTART
;
3036 if ((dsps
& 0xff000000) == 0x03000000) {
3037 printk ("scsi%d : misc debug interrupt 0x%x\n",
3038 host
->host_no
, dsps
);
3039 return SPECIFIC_INT_RESTART
;
3040 } else if ((dsps
& 0xff000000) == 0x05000000) {
3041 if (hostdata
->events
) {
3042 struct NCR53c7x0_event
*event
;
3043 ++hostdata
->event_index
;
3044 if (hostdata
->event_index
>= hostdata
->event_size
)
3045 hostdata
->event_index
= 0;
3046 event
= (struct NCR53c7x0_event
*) hostdata
->events
+
3047 hostdata
->event_index
;
3048 event
->event
= (enum ncr_event
) dsps
;
3049 event
->dsa
= bus_to_virt(NCR53c7x0_read32(DSA_REG
));
3050 /* FIXME : this needs to change for the '7xx family */
3051 if (NCR53c7x0_read8 (SCNTL1_REG
) & SCNTL1_CON
)
3052 event
->target
= NCR53c7x0_read8(SSID_REG_800
);
3054 event
->target
= 255;
3056 if (event
->event
== EVENT_RESELECT
)
3057 event
->lun
= hostdata
->reselected_identify
& 0xf;
3059 event
->lun
= c
->lun
;
3062 do_gettimeofday(&(event
->time
));
3064 event
->pid
= c
->pid
;
3065 memcpy ((void *) event
->cmnd
, (void *) c
->cmnd
,
3066 sizeof (event
->cmnd
));
3071 return SPECIFIC_INT_RESTART
;
3074 printk ("scsi%d : unknown user interrupt 0x%x\n",
3075 host
->host_no
, (unsigned) dsps
);
3076 return SPECIFIC_INT_PANIC
;
3081 * XXX - the stock NCR assembler won't output the scriptu.h file,
3082 * which undefine's all #define'd CPP symbols from the script.h
3083 * file, which will create problems if you use multiple scripts
3084 * with the same symbol names.
3086 * If you insist on using NCR's assembler, you could generate
3087 * scriptu.h from script.h using something like
3089 * grep #define script.h | \
3090 * sed 's/#define[ ][ ]*\([_a-zA-Z][_a-zA-Z0-9]*\).*$/#undefine \1/' \
3094 #include "53c8xx_u.h"
3096 /* XXX - add alternate script handling code here */
3101 * Debugging without a debugger is no fun. So, I've provided
3102 * a debugging interface in the NCR53c7x0 driver. To avoid
3103 * kernel cruft, there's just enough here to act as an interface
3104 * to a user level debugger (aka, GDB).
3107 * The following restrictions apply to debugger commands :
3108 * 1. The command must be terminated by a newline.
3109 * 2. Command length must be less than 80 bytes including the
3111 * 3. The entire command must be written with one system call.
3114 static const char debugger_help
=
3115 "bc <addr> - clear breakpoint\n"
3116 "bl - list breakpoints\n"
3117 "bs <addr> - set breakpoint\n"
3120 "? - this message\n"
3122 "mp <addr> <size> - print memory\n"
3123 "ms <addr> <size> <value> - store memory\n"
3124 "rp <num> <size> - print register\n"
3125 "rs <num> <size> <value> - store register\n"
3127 "tb - begin trace \n"
3131 * Whenever we change a break point, we should probably
3132 * set the NCR up so that it is in a single step mode.
3135 static int debugger_fn_bc (struct Scsi_Host
*host
, struct debugger_token
*token
,
3137 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
3139 struct NCR53c7x0_break
*bp
, **prev
;
3140 unsigned long flags
;
3143 for (bp
= (struct NCR53c7x0_break
*) instance
->breakpoints
,
3144 prev
= (struct NCR53c7x0_break
**) &instance
->breakpoints
;
3145 bp
; prev
= (struct NCR53c7x0_break
**) &(bp
->next
),
3146 bp
= (struct NCR53c7x0_break
*) bp
->next
);
3149 restore_flags(flags
);
3154 * XXX - we need to insure that the processor is halted
3155 * here in order to prevent a race condition.
3158 memcpy ((void *) bp
->addr
, (void *) bp
->old
, sizeof(bp
->old
));
3162 restore_flags(flags
);
3168 debugger_fn_bl (struct Scsi_Host
*host
, struct debugger_token
*token
,
3170 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
3172 struct NCR53c7x0_break
*bp
;
3175 unsigned long flags
;
3177 * XXX - we need to insure that the processor is halted
3178 * here in order to prevent a race condition. So, if the
3179 * processor isn't halted, print an error message and continue.
3182 sprintf (buf
, "scsi%d : bp : warning : processor not halted\b",
3184 debugger_kernel_write (host
, buf
, strlen(buf
));
3188 for (bp
= (struct NCR53c7x0_break
*) host
->breakpoints
;
3189 bp
; bp
= (struct NCR53c7x0_break
*) bp
->next
); {
3190 sprintf (buf
, "scsi%d : bp : success : at %08x, replaces %08x %08x",
3191 bp
->addr
, bp
->old
[0], bp
->old
[1]);
3193 if ((bp
->old
[0] & (DCMD_TYPE_MASK
<< 24)) ==
3194 (DCMD_TYPE_MMI
<< 24)) {
3195 sprintf(buf
+ len
, "%08x\n", * (u32
*) bp
->addr
);
3197 sprintf(buf
+ len
, "\n");
3200 debugger_kernel_write (host
, buf
, len
);
3202 restore_flags(flags
);
3207 debugger_fn_bs (struct Scsi_Host
*host
, struct debugger_token
*token
,
3209 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
3211 struct NCR53c7x0_break
*bp
;
3214 unsigned long flags
;
3218 if (hostdata
->state
!= STATE_HALTED
) {
3219 sprintf (buf
, "scsi%d : bs : failure : NCR not halted\n", host
->host_no
);
3220 debugger_kernel_write (host
, buf
, strlen(buf
));
3221 restore_flags(flags
);
3225 if (!(bp
= kmalloc (sizeof (struct NCR53c7x0_break
)))) {
3226 printk ("scsi%d : kmalloc(%d) of breakpoint structure failed, try again\n",
3227 host
->host_no
, sizeof(struct NCR53c7x0_break
));
3228 restore_flags(flags
);
3232 bp
->address
= (u32
*) args
[0];
3233 memcpy ((void *) bp
->old_instruction
, (void *) bp
->address
, 8);
3234 bp
->old_size
= (((bp
->old_instruction
[0] >> 24) & DCMD_TYPE_MASK
) ==
3235 DCMD_TYPE_MMI
? 3 : 2;
3236 bp
->next
= hostdata
->breakpoints
;
3237 hostdata
->breakpoints
= bp
->next
;
3238 memcpy ((void *) bp
->address
, (void *) hostdata
->E_debug_break
, 8);
3240 restore_flags(flags
);
3244 #define TOKEN(name,nargs) {#name, nargs, debugger_fn_##name}
3245 static const struct debugger_token
{
3248 int (*fn
)(struct debugger_token
*token
, u32 args
[]);
3249 } debugger_tokens
[] = {
3250 TOKEN(bc
,1), TOKEN(bl
,0), TOKEN(bs
,1), TOKEN(g
,0), TOKEN(halt
,0),
3251 {DT_help
, "?", 0} , TOKEN(h
,0), TOKEN(i
,0), TOKEN(mp
,2),
3252 TOKEN(ms
,3), TOKEN(rp
,2), TOKEN(rs
,2), TOKEN(s
,0), TOKEN(tb
,0), TOKEN(te
,0)
3255 #define NDT sizeof(debugger_tokens / sizeof(struct debugger_token))
3257 static struct Scsi_Host
* inode_to_host (struct inode
*inode
) {
3259 struct Scsi_Host
*tmp
;
3260 for (dev
= MINOR(inode
->rdev
), host
= first_host
;
3261 (host
->hostt
== the_template
); --dev
, host
= host
->next
)
3262 if (!dev
) return host
;
3268 debugger_user_write (struct inode
*inode
,struct file
*filp
,
3269 char *buf
,int count
) {
3270 struct Scsi_Host
*host
; /* This SCSI host */
3271 struct NCR53c7x0_hostadata
*hostdata
;
3272 char input_buf
[80], /* Kernel space copy of buf */
3273 *ptr
; /* Pointer to argument list */
3274 u32 args
[3]; /* Arguments */
3275 int i
, j
, error
, len
;
3277 if (!(host
= inode_to_host(inode
)))
3280 hostdata
= (struct NCR53c7x0_hostdata
*) host
->hostdata
;
3282 if (error
= verify_area(VERIFY_READ
,buf
,count
))
3288 memcpy_from_fs(input_buf
, buf
, count
);
3290 if (input_buf
[count
- 1] != '\n')
3293 input_buf
[count
- 1]=0;
3295 for (i
= 0; i
< NDT
; ++i
) {
3296 len
= strlen (debugger_tokens
[i
].name
);
3297 if (!strncmp(input_buf
, debugger_tokens
[i
].name
, len
))
3304 for (ptr
= input_buf
+ len
, j
= 0; j
< debugger_tokens
[i
].nargs
&& *ptr
;) {
3305 if (*ptr
== ' ' || *ptr
== '\t') {
3307 } else if (isdigit(*ptr
)) {
3308 args
[j
++] = simple_strtoul (ptr
, &ptr
, 0);
3314 if (j
!= debugger_tokens
[i
].nargs
)
3321 debugger_user_read (struct inode
*inode
,struct file
*filp
,
3322 char *buf
,int count
) {
3323 struct Scsi_Host
*instance
;
3328 debugger_kernel_write (struct Scsi_Host
*host
, char *buf
, size_t
3330 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
3333 unsigned long flags
;
3337 left
= (hostdata
->debug_buf
+ hostdata
->debug_size
- 1) -
3338 hostdata
->debug_write
;
3339 copy
= (buflen
<= left
) ? buflen
: left
;
3340 memcpy (hostdata
->debug_write
, buf
, copy
);
3343 hostdata
->debug_count
+= copy
;
3344 if ((hostdata
->debug_write
+= copy
) ==
3345 (hostdata
->debug_buf
+ hostdata
->debug_size
))
3346 hosdata
->debug_write
= hostdata
->debug_buf
;
3348 restore_flags(flags
);
3351 #endif /* def NCRDEBUG */
3354 * Function : static void NCR538xx_soft_reset (struct Scsi_Host *host)
3356 * Purpose : perform a soft reset of the NCR53c8xx chip
3358 * Inputs : host - pointer to this host adapter's structure
3360 * Preconditions : NCR53c7x0_init must have been called for this
3366 NCR53c8x0_soft_reset (struct Scsi_Host
*host
) {
3367 NCR53c7x0_local_declare();
3368 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
3370 NCR53c7x0_local_setup(host
);
3374 * Do a soft reset of the chip so that everything is
3375 * reinitialized to the power-on state.
3377 * Basically follow the procedure outlined in the NCR53c700
3378 * data manual under Chapter Six, How to Use, Steps Necessary to
3379 * Start SCRIPTS, with the exception of actually starting the
3380 * script and setting up the synchronous transfer gunk.
3383 NCR53c7x0_write8(ISTAT_REG_800
, ISTAT_10_SRST
);
3384 NCR53c7x0_write8(ISTAT_REG_800
, 0);
3385 NCR53c7x0_write8(hostdata
->dmode
, hostdata
->saved_dmode
& ~DMODE_MAN
);
3389 * Respond to reselection by targets and use our _initiator_ SCSI ID
3390 * for arbitration. If notyet, also respond to SCSI selection.
3392 * XXX - Note : we must reprogram this when reselecting as
3397 NCR53c7x0_write8(SCID_REG
, (host
->this_id
& 7)|SCID_800_RRE
|SCID_800_SRE
);
3399 NCR53c7x0_write8(SCID_REG
, (host
->this_id
& 7)|SCID_800_RRE
);
3401 NCR53c7x0_write8(RESPID_REG_800
, hostdata
->this_id_mask
);
3404 * Use a maximum (1.6) second handshake to handshake timeout,
3405 * and SCSI recommended .5s selection timeout.
3409 * The new gcc won't recognize preprocessing directives
3410 * within macro args.
3413 NCR53c7x0_write8(STIME0_REG_800
,
3414 ((selection_timeout
<< STIME0_800_SEL_SHIFT
) & STIME0_800_SEL_MASK
)
3415 | ((15 << STIME0_800_HTH_SHIFT
) & STIME0_800_HTH_MASK
));
3417 /* Disable HTH interrupt */
3418 NCR53c7x0_write8(STIME0_REG_800
,
3419 ((selection_timeout
<< STIME0_800_SEL_SHIFT
) & STIME0_800_SEL_MASK
));
3424 * Enable active negation for happy synchronous transfers.
3427 NCR53c7x0_write8(STEST3_REG_800
, STEST3_800_TE
);
3430 * Enable all interrupts, except parity which we only want when
3431 * the user requests it.
3434 NCR53c7x0_write8(DIEN_REG
, DIEN_800_MDPE
| DIEN_800_BF
|
3435 DIEN_ABRT
| DIEN_SSI
| DIEN_SIR
| DIEN_800_IID
);
3438 NCR53c7x0_write8(SIEN0_REG_800
, ((hostdata
->options
& OPTION_PARITY
) ?
3439 SIEN_PAR
: 0) | SIEN_RST
| SIEN_UDC
| SIEN_SGE
| SIEN_MA
);
3440 NCR53c7x0_write8(SIEN1_REG_800
, SIEN1_800_STO
| SIEN1_800_HTH
);
3443 * Use saved clock frequency divisor and scripts loaded in 16 bit
3444 * mode flags from the saved dcntl.
3447 NCR53c7x0_write8(DCNTL_REG
, hostdata
->saved_dcntl
);
3448 NCR53c7x0_write8(CTEST4_REG_800
, hostdata
->saved_ctest4
);
3450 /* Enable active negation */
3451 NCR53c7x0_write8(STEST3_REG_800
, STEST3_800_TE
);
3455 * Function static struct NCR53c7x0_cmd *allocate_cmd (Scsi_Cmnd *cmd)
3457 * Purpose : Return the first free NCR53c7x0_cmd structure (which are
3458 * reused in a LIFO manner to minimize cache thrashing).
3460 * Side effects : If we haven't yet scheduled allocation of NCR53c7x0_cmd
3461 * structures for this device, do so. Attempt to complete all scheduled
3462 * allocations using kmalloc(), putting NCR53c7x0_cmd structures on
3463 * the free list. Teach programmers not to drink and hack.
3465 * Inputs : cmd - SCSI command
3467 * Returns : NCR53c7x0_cmd structure allocated on behalf of cmd;
3471 static struct NCR53c7x0_cmd
*
3472 allocate_cmd (Scsi_Cmnd
*cmd
) {
3473 struct Scsi_Host
*host
= cmd
->host
;
3474 struct NCR53c7x0_hostdata
*hostdata
=
3475 (struct NCR53c7x0_hostdata
*) host
->hostdata
;
3476 void *real
; /* Real address */
3477 int size
; /* Size of *tmp */
3478 struct NCR53c7x0_cmd
*tmp
;
3479 unsigned long flags
;
3481 if (hostdata
->options
& OPTION_DEBUG_ALLOCATION
)
3482 printk ("scsi%d : num_cmds = %d, can_queue = %d\n"
3483 " target = %d, lun = %d, %s\n",
3484 host
->host_no
, hostdata
->num_cmds
, host
->can_queue
,
3485 cmd
->target
, cmd
->lun
, (hostdata
->cmd_allocated
[cmd
->target
] &
3486 (1 << cmd
->lun
)) ? "already allocated" : "not allocated");
3489 * If we have not yet reserved commands for this I_T_L nexus, and
3490 * the device exists (as indicated by permanent Scsi_Cmnd structures
3491 * being allocated under 1.3.x, or being outside of scan_scsis in
3492 * 1.2.x), do so now.
3494 if (!(hostdata
->cmd_allocated
[cmd
->target
] & (1 << cmd
->lun
)) &&
3498 cmd
->device
&& cmd
->device
->has_cmdblocks
3501 if ((hostdata
->extra_allocate
+ hostdata
->num_cmds
) < host
->can_queue
)
3502 hostdata
->extra_allocate
+= host
->cmd_per_lun
;
3503 hostdata
->cmd_allocated
[cmd
->target
] |= (1 << cmd
->lun
);
3506 for (; hostdata
->extra_allocate
> 0 ; --hostdata
->extra_allocate
,
3507 ++hostdata
->num_cmds
) {
3508 /* historically, kmalloc has returned unaligned addresses; pad so we
3509 have enough room to ROUNDUP */
3510 size
= hostdata
->max_cmd_size
+ sizeof (void *);
3511 /* FIXME: for ISA bus '7xx chips, we need to or GFP_DMA in here */
3512 real
= kmalloc (size
, GFP_ATOMIC
);
3514 if (hostdata
->options
& OPTION_DEBUG_ALLOCATION
)
3515 printk ("scsi%d : kmalloc(%d) failed\n",
3516 host
->host_no
, size
);
3519 tmp
= ROUNDUP(real
, void *);
3523 tmp
->free
= ((void (*)(void *, int)) kfree_s
);
3525 tmp
->free
= ((void (*)(void *, int)) kfree
);
3529 tmp
->next
= hostdata
->free
;
3530 hostdata
->free
= tmp
;
3531 restore_flags (flags
);
3535 tmp
= (struct NCR53c7x0_cmd
*) hostdata
->free
;
3537 hostdata
->free
= tmp
->next
;
3539 restore_flags(flags
);
3541 printk ("scsi%d : can't allocate command for target %d lun %d\n",
3542 host
->host_no
, cmd
->target
, cmd
->lun
);
3547 * Function static struct NCR53c7x0_cmd *create_cmd (Scsi_Cmnd *cmd)
3550 * Purpose : allocate a NCR53c7x0_cmd structure, initialize it based on the
3551 * Scsi_Cmnd structure passed in cmd, including dsa and Linux field
3552 * initialization, and dsa code relocation.
3554 * Inputs : cmd - SCSI command
3556 * Returns : NCR53c7x0_cmd structure corresponding to cmd,
3560 static struct NCR53c7x0_cmd
*
3561 create_cmd (Scsi_Cmnd
*cmd
) {
3562 NCR53c7x0_local_declare();
3563 struct Scsi_Host
*host
= cmd
->host
;
3564 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
3566 struct NCR53c7x0_cmd
*tmp
; /* NCR53c7x0_cmd structure for this command */
3567 int datain
, /* Number of instructions per phase */
3569 int data_transfer_instructions
, /* Count of dynamic instructions */
3571 u32
*cmd_datain
, /* Address of datain/dataout code */
3572 *cmd_dataout
; /* Incremented as we assemble */
3574 unsigned char *msgptr
; /* Current byte in select message */
3575 int msglen
; /* Length of whole select message */
3577 unsigned long flags
;
3578 NCR53c7x0_local_setup(cmd
->host
);
3580 if (!(tmp
= allocate_cmd (cmd
)))
3585 * Decide whether we need to generate commands for DATA IN,
3586 * DATA OUT, neither, or both based on the SCSI command
3589 switch (cmd
->cmnd
[0]) {
3590 /* These commands do DATA IN */
3597 datain
= 2 * (cmd
->use_sg
? cmd
->use_sg
: 1) + 3;
3600 /* These commands do DATA OUT */
3605 printk("scsi%d : command is ", host
->host_no
);
3606 print_command(cmd
->cmnd
);
3609 printk ("scsi%d : %d scatter/gather segments\n", host
->host_no
,
3613 dataout
= 2 * (cmd
->use_sg
? cmd
->use_sg
: 1) + 3;
3615 hostdata
->options
|= OPTION_DEBUG_INTR
;
3619 * These commands do no data transfer, we should force an
3620 * interrupt if a data phase is attempted on them.
3622 case START_STOP
: /* also SCAN, which may do DATA OUT */
3623 case TEST_UNIT_READY
:
3624 datain
= dataout
= 0;
3627 * We don't know about these commands, so generate code to handle
3628 * both DATA IN and DATA OUT phases.
3631 datain
= dataout
= 2 * (cmd
->use_sg
? cmd
->use_sg
: 1) + 3;
3635 * New code : so that active pointers work correctly regardless
3636 * of where the saved data pointer is at, we want to immediately
3637 * enter the dynamic code after selection, and on a non-data
3638 * phase perform a CALL to the non-data phase handler, with
3639 * returns back to this address.
3641 * If a phase mismatch is encountered in the middle of a
3642 * Block MOVE instruction, we want to _leave_ that instruction
3643 * unchanged as the current case is, modify a temporary buffer,
3644 * and point the active pointer (TEMP) at that.
3646 * Furthermore, we want to implement a saved data pointer,
3647 * set by the SAVE_DATA_POINTERs message.
3649 * So, the data transfer segments will change to
3650 * CALL data_transfer, WHEN NOT data phase
3651 * MOVE x, x, WHEN data phase
3653 * JUMP other_transfer
3656 data_transfer_instructions
= datain
+ dataout
;
3659 * When we perform a request sense, we overwrite various things,
3660 * including the data transfer code. Make sure we have enough
3664 if (data_transfer_instructions
< 2)
3665 data_transfer_instructions
= 2;
3669 * The saved data pointer is set up so that a RESTORE POINTERS message
3670 * will start the data transfer over at the beginning.
3673 tmp
->saved_data_pointer
= le32_to_cpu(virt_to_bus (hostdata
->script
) +
3674 hostdata
->E_data_transfer
);
3677 * Initialize Linux specific fields.
3683 tmp
->dsa_next_addr
= le32_to_cpu(virt_to_bus(tmp
->dsa
) + hostdata
->dsa_next
-
3684 hostdata
->dsa_start
);
3685 tmp
->dsa_addr
= le32_to_cpu(virt_to_bus(tmp
->dsa
) - hostdata
->dsa_start
);
3688 * Calculate addresses of dynamic code to fill in DSA
3691 tmp
->data_transfer_start
= tmp
->dsa
+ (hostdata
->dsa_end
-
3692 hostdata
->dsa_start
) / sizeof(u32
);
3693 tmp
->data_transfer_end
= tmp
->data_transfer_start
+
3694 2 * data_transfer_instructions
;
3696 cmd_datain
= datain
? tmp
->data_transfer_start
: NULL
;
3697 cmd_dataout
= dataout
? (datain
? cmd_datain
+ 2 * datain
: tmp
->
3698 data_transfer_start
) : NULL
;
3701 * Fill in the NCR53c7x0_cmd structure as follows
3702 * dsa, with fixed up DSA code
3707 /* Copy template code into dsa and perform all necessary fixups */
3708 if (hostdata
->dsa_fixup
)
3709 hostdata
->dsa_fixup(tmp
);
3711 patch_dsa_32(tmp
->dsa
, dsa_next
, 0, le32_to_cpu(0));
3712 patch_dsa_32(tmp
->dsa
, dsa_cmnd
, 0, le32_to_cpu(virt_to_bus(cmd
)));
3714 if (hostdata
->options
& OPTION_DEBUG_SYNCHRONOUS
)
3715 if (hostdata
->sync
[cmd
->target
].select_indirect
!=
3716 ((hostdata
->sync
[cmd
->target
].scntl3_sanity
<< 24) |
3717 (cmd
->target
<< 16) |
3718 (hostdata
->sync
[cmd
->target
].sxfer_sanity
<< 8))) {
3719 printk ("scsi%d : sanity check failed select_indirect=0x%x\n",
3720 host
->host_no
, hostdata
->sync
[cmd
->target
].select_indirect
);
3725 patch_dsa_32(tmp
->dsa
, dsa_select
, 0, le32_to_cpu(hostdata
->sync
[cmd
->target
].
3728 * Right now, we'll do the WIDE and SYNCHRONOUS negotiations on
3729 * different commands; although it should be trivial to do them
3730 * both at the same time.
3732 if (hostdata
->initiate_wdtr
& (1 << cmd
->target
)) {
3733 memcpy ((void *) (tmp
->select
+ 1), (void *) wdtr_message
,
3734 sizeof(wdtr_message
));
3735 patch_dsa_32(tmp
->dsa
, dsa_msgout
, 0, le32_to_cpu(1 + sizeof(wdtr_message
)));
3738 hostdata
->initiate_wdtr
&= ~(1 << cmd
->target
);
3739 restore_flags(flags
);
3740 } else if (hostdata
->initiate_sdtr
& (1 << cmd
->target
)) {
3741 memcpy ((void *) (tmp
->select
+ 1), (void *) sdtr_message
,
3742 sizeof(sdtr_message
));
3743 patch_dsa_32(tmp
->dsa
, dsa_msgout
, 0, le32_to_cpu(1 + sizeof(sdtr_message
)));
3744 tmp
->flags
|= CMD_FLAG_SDTR
;
3747 hostdata
->initiate_sdtr
&= ~(1 << cmd
->target
);
3748 restore_flags(flags
);
3752 else if (!(hostdata
->talked_to
& (1 << cmd
->target
)) &&
3753 !(hostdata
->options
& OPTION_NO_ASYNC
)) {
3754 memcpy ((void *) (tmp
->select
+ 1), (void *) async_message
,
3755 sizeof(async_message
));
3756 patch_dsa_32(tmp
->dsa
, dsa_msgout
, 0, le32_to_cpu(1 + sizeof(async_message
)));
3757 tmp
->flags
|= CMD_FLAG_SDTR
;
3761 patch_dsa_32(tmp
->dsa
, dsa_msgout
, 0, le32_to_cpu(1));
3762 hostdata
->talked_to
|= (1 << cmd
->target
);
3763 tmp
->select
[0] = (hostdata
->options
& OPTION_DISCONNECT
) ?
3764 IDENTIFY (1, cmd
->lun
) : IDENTIFY (0, cmd
->lun
);
3765 patch_dsa_32(tmp
->dsa
, dsa_msgout
, 1, le32_to_cpu(virt_to_bus(tmp
->select
)));
3766 patch_dsa_32(tmp
->dsa
, dsa_cmdout
, 0, le32_to_cpu(cmd
->cmd_len
));
3767 patch_dsa_32(tmp
->dsa
, dsa_cmdout
, 1, le32_to_cpu(virt_to_bus(cmd
->cmnd
)));
3768 patch_dsa_32(tmp
->dsa
, dsa_dataout
, 0, le32_to_cpu(cmd_dataout
?
3769 virt_to_bus (cmd_dataout
)
3770 : virt_to_bus (hostdata
->script
) + hostdata
->E_other_transfer
));
3771 patch_dsa_32(tmp
->dsa
, dsa_datain
, 0, le32_to_cpu(cmd_datain
?
3772 virt_to_bus (cmd_datain
)
3773 : virt_to_bus (hostdata
->script
) + hostdata
->E_other_transfer
));
3775 * XXX - need to make endian aware, should use separate variables
3776 * for both status and message bytes.
3778 patch_dsa_32(tmp
->dsa
, dsa_msgin
, 0, le32_to_cpu(1));
3780 * FIXME : these only works for little endian. We probably want to
3781 * provide message and status fields in the NCR53c7x0_cmd
3782 * structure, and assign them to cmd->result when we're done.
3784 patch_dsa_32(tmp
->dsa
, dsa_msgin
, 1, le32_to_cpu(virt_to_bus(&cmd
->result
) + 1));
3785 patch_dsa_32(tmp
->dsa
, dsa_status
, 0, le32_to_cpu(1));
3786 patch_dsa_32(tmp
->dsa
, dsa_status
, 1, le32_to_cpu(virt_to_bus(&cmd
->result
)));
3787 patch_dsa_32(tmp
->dsa
, dsa_msgout_other
, 0, le32_to_cpu(1));
3788 patch_dsa_32(tmp
->dsa
, dsa_msgout_other
, 1,
3789 le32_to_cpu(virt_to_bus(&(hostdata
->NCR53c7xx_msg_nop
))));
3792 * Generate code for zero or more of the DATA IN, DATA OUT phases
3795 * CALL data_transfer, WHEN NOT phase
3796 * MOVE first buffer length, first buffer address, WHEN phase
3798 * MOVE last buffer length, last buffer address, WHEN phase
3799 * JUMP other_transfer
3803 * See if we're getting to data transfer by generating an unconditional
3808 cmd_datain
[0] = 0x98080000;
3809 cmd_datain
[1] = 0x03ffd00d;
3815 * XXX - I'm undecided whether all of this nonsense is faster
3816 * in the long run, or whether I should just go and implement a loop
3817 * on the NCR chip using table indirect mode?
3819 * In any case, this is how it _must_ be done for 53c700/700-66 chips,
3820 * so this stays even when we come up with something better.
3822 * When we're limited to 1 simultaneous command, no overlapping processing,
3823 * we're seeing 630K/sec, with 7% CPU usage on a slow Syquest 45M
3826 * Not bad, not good. We'll see.
3829 for (i
= 0; cmd
->use_sg
? (i
< cmd
->use_sg
) : !i
; cmd_datain
+= 4,
3830 cmd_dataout
+= 4, ++i
) {
3831 u32 buf
= cmd
->use_sg
?
3832 virt_to_bus(((struct scatterlist
*)cmd
->buffer
)[i
].address
) :
3833 virt_to_bus(cmd
->request_buffer
);
3834 u32 count
= cmd
->use_sg
?
3835 ((struct scatterlist
*)cmd
->buffer
)[i
].length
:
3836 cmd
->request_bufflen
;
3839 /* CALL other_in, WHEN NOT DATA_IN */
3840 cmd_datain
[0] = le32_to_cpu(((DCMD_TYPE_TCI
| DCMD_TCI_OP_CALL
|
3841 DCMD_TCI_IO
) << 24) |
3842 DBC_TCI_WAIT_FOR_VALID
| DBC_TCI_COMPARE_PHASE
);
3843 cmd_datain
[1] = le32_to_cpu(virt_to_bus (hostdata
->script
) +
3844 hostdata
->E_other_in
);
3845 /* MOVE count, buf, WHEN DATA_IN */
3846 cmd_datain
[2] = le32_to_cpu(((DCMD_TYPE_BMI
| DCMD_BMI_OP_MOVE_I
| DCMD_BMI_IO
)
3848 cmd_datain
[3] = le32_to_cpu(buf
);
3850 print_insn (host
, cmd_datain
, "dynamic ", 1);
3851 print_insn (host
, cmd_datain
+ 2, "dynamic ", 1);
3855 /* CALL other_out, WHEN NOT DATA_OUT */
3856 cmd_dataout
[0] = le32_to_cpu(((DCMD_TYPE_TCI
| DCMD_TCI_OP_CALL
) << 24) |
3857 DBC_TCI_WAIT_FOR_VALID
| DBC_TCI_COMPARE_PHASE
);
3858 cmd_dataout
[1] = le32_to_cpu(virt_to_bus(hostdata
->script
) +
3859 hostdata
->E_other_out
);
3860 /* MOVE count, buf, WHEN DATA+OUT */
3861 cmd_dataout
[2] = le32_to_cpu(((DCMD_TYPE_BMI
| DCMD_BMI_OP_MOVE_I
) << 24)
3863 cmd_dataout
[3] = le32_to_cpu(buf
);
3865 print_insn (host
, cmd_dataout
, "dynamic ", 1);
3866 print_insn (host
, cmd_dataout
+ 2, "dynamic ", 1);
3872 * Install JUMP instructions after the data transfer routines to return
3873 * control to the do_other_transfer routines.
3878 cmd_datain
[0] = le32_to_cpu(((DCMD_TYPE_TCI
| DCMD_TCI_OP_JUMP
) << 24) |
3880 cmd_datain
[1] = le32_to_cpu(virt_to_bus(hostdata
->script
) +
3881 hostdata
->E_other_transfer
);
3883 print_insn (host
, cmd_datain
, "dynamic jump ", 1);
3889 cmd_datain
[0] = 0x98080000;
3890 cmd_datain
[1] = 0x03ffdeed;
3895 cmd_dataout
[0] = le32_to_cpu(((DCMD_TYPE_TCI
| DCMD_TCI_OP_JUMP
) << 24) |
3897 cmd_dataout
[1] = le32_to_cpu(virt_to_bus(hostdata
->script
) +
3898 hostdata
->E_other_transfer
);
3900 print_insn (host
, cmd_dataout
, "dynamic jump ", 1);
3908 * Function : int NCR53c7xx_queue_command (Scsi_Cmnd *cmd,
3909 * void (*done)(Scsi_Cmnd *))
3911 * Purpose : enqueues a SCSI command
3913 * Inputs : cmd - SCSI command, done - function called on completion, with
3914 * a pointer to the command descriptor.
3919 * cmd is added to the per instance driver issue_queue, with major
3920 * twiddling done to the host specific fields of cmd. If the
3921 * process_issue_queue coroutine isn't running, it is restarted.
3923 * NOTE : we use the host_scribble field of the Scsi_Cmnd structure to
3924 * hold our own data, and pervert the ptr field of the SCp field
3925 * to create a linked list.
3929 NCR53c7xx_queue_command (Scsi_Cmnd
*cmd
, void (* done
)(Scsi_Cmnd
*)) {
3930 struct Scsi_Host
*host
= cmd
->host
;
3931 struct NCR53c7x0_hostdata
*hostdata
=
3932 (struct NCR53c7x0_hostdata
*) host
->hostdata
;
3933 unsigned long flags
;
3936 cmd
->scsi_done
= done
;
3937 cmd
->host_scribble
= NULL
;
3938 cmd
->SCp
.ptr
= NULL
;
3939 cmd
->SCp
.buffer
= NULL
;
3943 if ((hostdata
->options
& (OPTION_DEBUG_INIT_ONLY
|OPTION_DEBUG_PROBE_ONLY
))
3944 || ((hostdata
->options
& OPTION_DEBUG_TARGET_LIMIT
) &&
3945 !(hostdata
->debug_lun_limit
[cmd
->target
] & (1 << cmd
->lun
)))
3949 || cmd
->target
> host
->max_id
3951 || cmd
->target
== host
->this_id
3952 || hostdata
->state
== STATE_DISABLED
) {
3953 printk("scsi%d : disabled or bad target %d lun %d\n", host
->host_no
,
3954 cmd
->target
, cmd
->lun
);
3955 cmd
->result
= DID_BAD_TARGET
<< 16;
3956 } else if ((hostdata
->options
& OPTION_DEBUG_NCOMMANDS_LIMIT
) &&
3957 (hostdata
->debug_count_limit
== 0)) {
3958 printk("scsi%d : maximum commands exceeded\n", host
->host_no
);
3959 cmd
->result
= DID_BAD_TARGET
<< 16;
3960 } else if (hostdata
->options
& OPTION_DEBUG_READ_ONLY
) {
3961 switch (cmd
->cmnd
[0]) {
3964 printk("scsi%d : WRITE attempted with NO_WRITE debugging flag set\n",
3966 cmd
->result
= DID_BAD_TARGET
<< 16;
3969 if ((hostdata
->options
& OPTION_DEBUG_TARGET_LIMIT
) &&
3970 hostdata
->debug_count_limit
!= -1)
3971 --hostdata
->debug_count_limit
;
3972 restore_flags (flags
);
3973 cmd
->result
= le32_to_cpu(0xffff); /* The NCR will overwrite message
3974 and status with valid data */
3975 cmd
->host_scribble
= (unsigned char *) tmp
= create_cmd (cmd
);
3979 * REQUEST SENSE commands are inserted at the head of the queue
3980 * so that we do not clear the contingent allegiance condition
3981 * they may be looking at.
3984 if (!(hostdata
->issue_queue
) || (cmd
->cmnd
[0] == REQUEST_SENSE
)) {
3985 cmd
->SCp
.ptr
= (unsigned char *) hostdata
->issue_queue
;
3986 hostdata
->issue_queue
= cmd
;
3988 for (tmp
= (Scsi_Cmnd
*) hostdata
->issue_queue
; tmp
->SCp
.ptr
;
3989 tmp
= (Scsi_Cmnd
*) tmp
->SCp
.ptr
);
3990 tmp
->SCp
.ptr
= (unsigned char *) cmd
;
3992 restore_flags (flags
);
3993 run_process_issue_queue();
3998 * Function : void to_schedule_list (struct Scsi_Host *host,
3999 * struct NCR53c7x0_hostdata * hostdata, Scsi_Cmnd *cmd)
4001 * Purpose : takes a SCSI command which was just removed from the
4002 * issue queue, and deals with it by inserting it in the first
4003 * free slot in the schedule list or by terminating it immediately.
4006 * host - SCSI host adapter; hostdata - hostdata structure for
4007 * this adapter; cmd - a pointer to the command; should have
4008 * the host_scribble field initialized to point to a valid
4011 * cmd is added to the per instance schedule list, with minor
4012 * twiddling done to the host specific fields of cmd.
4016 static __inline__
void
4017 to_schedule_list (struct Scsi_Host
*host
, struct NCR53c7x0_hostdata
*hostdata
,
4018 struct NCR53c7x0_cmd
*cmd
) {
4019 NCR53c7x0_local_declare();
4020 Scsi_Cmnd
*tmp
= cmd
->cmd
;
4021 unsigned long flags
;
4022 /* dsa start is negative, so subtraction is used */
4026 NCR53c7x0_local_setup(host
);
4028 printk("scsi%d : new dsa is 0x%lx (virt 0x%p)\n", host
->host_no
,
4029 virt_to_bus(dsa
), dsa
);
4036 * Work around race condition : if an interrupt fired and we
4037 * got disabled forget about this command.
4040 if (hostdata
->state
== STATE_DISABLED
) {
4041 printk("scsi%d : driver disabled\n", host
->host_no
);
4042 tmp
->result
= DID_BAD_TARGET
<< 16;
4043 cmd
->next
= (struct NCR53c7x0_cmd
*) hostdata
->free
;
4044 hostdata
->free
= cmd
;
4045 tmp
->scsi_done(tmp
);
4046 restore_flags (flags
);
4050 for (i
= host
->can_queue
, curr
= hostdata
->schedule
;
4051 i
> 0 && curr
[0] != hostdata
->NOP_insn
;
4052 --i
, curr
+= 2 /* JUMP instructions are two words */);
4055 ++hostdata
->busy
[tmp
->target
][tmp
->lun
];
4056 cmd
->next
= hostdata
->running_list
;
4057 hostdata
->running_list
= cmd
;
4059 /* Restore this instruction to a NOP once the command starts */
4060 cmd
->dsa
[(hostdata
->dsa_jump_dest
- hostdata
->dsa_start
) /
4061 sizeof(u32
)] = (u32
) le32_to_cpu(virt_to_bus ((void *)curr
));
4062 /* Replace the current jump operand. */
4064 le32_to_cpu(virt_to_bus ((void *) cmd
->dsa
) + hostdata
->E_dsa_code_begin
-
4065 hostdata
->E_dsa_code_template
);
4066 /* Replace the NOP instruction with a JUMP */
4067 curr
[0] = le32_to_cpu(((DCMD_TYPE_TCI
|DCMD_TCI_OP_JUMP
) << 24) |
4070 printk ("scsi%d: no free slot\n", host
->host_no
);
4072 tmp
->result
= DID_ERROR
<< 16;
4073 cmd
->next
= (struct NCR53c7x0_cmd
*) hostdata
->free
;
4074 hostdata
->free
= cmd
;
4075 tmp
->scsi_done(tmp
);
4076 restore_flags (flags
);
4081 * If the NCR chip is in an idle state, start it running the scheduler
4082 * immediately. Otherwise, signal the chip to jump to schedule as
4083 * soon as it is idle.
4085 if (hostdata
->idle
) {
4087 hostdata
->state
= STATE_RUNNING
;
4088 NCR53c7x0_write32 (DSP_REG
, virt_to_bus ((void *)hostdata
->schedule
));
4090 NCR53c7x0_write8(hostdata
->istat
, ISTAT_10_SIGP
);
4093 restore_flags(flags
);
4097 * Function : busyp (struct Scsi_Host *host, struct NCR53c7x0_hostdata
4098 * *hostdata, Scsi_Cmnd *cmd)
4100 * Purpose : decide if we can pass the given SCSI command on to the
4101 * device in question or not.
4103 * Returns : non-zero when we're busy, 0 when we aren't.
4106 static __inline__
int
4107 busyp (struct Scsi_Host
*host
, struct NCR53c7x0_hostdata
*hostdata
,
4109 /* FIXME : in the future, this needs to accommodate SCSI-II tagged
4110 queuing, and we may be able to play with fairness here a bit.
4112 return hostdata
->busy
[cmd
->target
][cmd
->lun
];
4116 * Function : process_issue_queue (void)
4118 * Purpose : transfer commands from the issue queue to NCR start queue
4119 * of each NCR53c7/8xx in the system, avoiding kernel stack
4120 * overflows when the scsi_done() function is invoked recursively.
4122 * NOTE : process_issue_queue exits with interrupts *disabled*, so the
4123 * caller must reenable them if it desires.
4125 * NOTE : process_issue_queue should be called from both
4126 * NCR53c7x0_queue_command() and from the interrupt handler
4127 * after command completion in case NCR53c7x0_queue_command()
4128 * isn't invoked again but we've freed up resources that are
4133 process_issue_queue (unsigned long flags
) {
4134 Scsi_Cmnd
*tmp
, *prev
;
4135 struct Scsi_Host
*host
;
4136 struct NCR53c7x0_hostdata
*hostdata
;
4140 * We run (with interrupts disabled) until we're sure that none of
4141 * the host adapters have anything that can be done, at which point
4142 * we set process_issue_queue_running to 0 and exit.
4144 * Interrupts are enabled before doing various other internal
4145 * instructions, after we've decided that we need to run through
4151 cli(); /* Freeze request queues */
4153 for (host
= first_host
; host
&& host
->hostt
== the_template
;
4154 host
= host
->next
) {
4155 hostdata
= (struct NCR53c7x0_hostdata
*) host
->hostdata
;
4157 if (hostdata
->issue_queue
) {
4158 if (hostdata
->state
== STATE_DISABLED
) {
4159 tmp
= (Scsi_Cmnd
*) hostdata
->issue_queue
;
4160 hostdata
->issue_queue
= (Scsi_Cmnd
*) tmp
->SCp
.ptr
;
4161 tmp
->result
= DID_BAD_TARGET
<< 16;
4162 if (tmp
->host_scribble
) {
4163 ((struct NCR53c7x0_cmd
*)tmp
->host_scribble
)->next
=
4166 (struct NCR53c7x0_cmd
*)tmp
->host_scribble
;
4167 tmp
->host_scribble
= NULL
;
4169 tmp
->scsi_done (tmp
);
4172 for (tmp
= (Scsi_Cmnd
*) hostdata
->issue_queue
,
4173 prev
= NULL
; tmp
; prev
= tmp
, tmp
= (Scsi_Cmnd
*)
4175 if (!tmp
->host_scribble
||
4176 !busyp (host
, hostdata
, tmp
)) {
4178 prev
->SCp
.ptr
= tmp
->SCp
.ptr
;
4180 hostdata
->issue_queue
= (Scsi_Cmnd
*)
4182 tmp
->SCp
.ptr
= NULL
;
4183 if (tmp
->host_scribble
) {
4184 if (hostdata
->options
& OPTION_DEBUG_QUEUES
)
4185 printk ("scsi%d : moving command for target %d lun %d to start list\n",
4186 host
->host_no
, tmp
->target
, tmp
->lun
);
4189 to_schedule_list (host
, hostdata
,
4190 (struct NCR53c7x0_cmd
*)
4191 tmp
->host_scribble
);
4193 tmp
->result
= le32_to_cpu(tmp
->result
);
4194 if (((tmp
->result
& 0xff) == 0xff) ||
4195 ((tmp
->result
& 0xff00) == 0xff00)) {
4196 printk ("scsi%d : danger Will Robinson!\n",
4198 tmp
->result
= DID_ERROR
<< 16;
4201 tmp
->scsi_done(tmp
);
4204 } /* if target/lun is not busy */
4205 } /* if hostdata->issue_queue */
4207 restore_flags (flags
);
4210 process_issue_queue_running
= 0;
4214 * Function : static void intr_scsi (struct Scsi_Host *host,
4215 * struct NCR53c7x0_cmd *cmd)
4217 * Purpose : handle all SCSI interrupts, indicated by the setting
4218 * of the SIP bit in the ISTAT register.
4220 * Inputs : host, cmd - host and NCR command causing the interrupt, cmd
4225 intr_scsi (struct Scsi_Host
*host
, struct NCR53c7x0_cmd
*cmd
) {
4226 NCR53c7x0_local_declare();
4227 struct NCR53c7x0_hostdata
*hostdata
=
4228 (struct NCR53c7x0_hostdata
*) host
->hostdata
;
4229 unsigned char sstat0_sist0
, sist1
, /* Registers */
4230 fatal
; /* Did a fatal interrupt
4234 NCR53c7x0_local_setup(host
);
4238 is_8xx_chip
= ((unsigned) (hostdata
->chip
- 800)) < 100;
4240 sstat0_sist0
= NCR53c7x0_read8(SIST0_REG_800
);
4242 sist1
= NCR53c7x0_read8(SIST1_REG_800
);
4244 sstat0_sist0
= NCR53c7x0_read8(SSTAT0_REG
);
4248 if (hostdata
->options
& OPTION_DEBUG_INTR
)
4249 printk ("scsi%d : SIST0 0x%0x, SIST1 0x%0x\n", host
->host_no
,
4250 sstat0_sist0
, sist1
);
4252 /* 250ms selection timeout */
4253 if ((is_8xx_chip
&& (sist1
& SIST1_800_STO
)) ||
4254 (!is_8xx_chip
&& (sstat0_sist0
& SSTAT0_700_STO
))) {
4256 if (hostdata
->options
& OPTION_DEBUG_INTR
) {
4257 printk ("scsi%d : Selection Timeout\n", host
->host_no
);
4259 printk("scsi%d : target %d, lun %d, command ",
4260 host
->host_no
, cmd
->cmd
->target
, cmd
->cmd
->lun
);
4261 print_command (cmd
->cmd
->cmnd
);
4262 printk("scsi%d : dsp = 0x%x (virt 0x%p)\n", host
->host_no
,
4263 NCR53c7x0_read32(DSP_REG
),
4264 bus_to_virt(NCR53c7x0_read32(DSP_REG
)));
4266 printk("scsi%d : no command\n", host
->host_no
);
4270 * XXX - question : how do we want to handle the Illegal Instruction
4271 * interrupt, which may occur before or after the Selection Timeout
4277 hostdata
->expecting_sto
= 0;
4279 if (hostdata
->test_running
) {
4280 hostdata
->test_running
= 0;
4281 hostdata
->test_completed
= 3;
4283 abnormal_finished(cmd
, DID_BAD_TARGET
<< 16);
4286 hostdata
->intrs
= 0;
4292 * FIXME : in theory, we can also get a UDC when a STO occurs.
4294 if (sstat0_sist0
& SSTAT0_UDC
) {
4297 printk("scsi%d : target %d lun %d unexpected disconnect\n",
4298 host
->host_no
, cmd
->cmd
->target
, cmd
->cmd
->lun
);
4300 abnormal_finished(cmd
, DID_ERROR
<< 16);
4302 printk("scsi%d : unexpected disconnect (no command)\n",
4305 hostdata
->dsp
= (u32
*) hostdata
->schedule
;
4306 hostdata
->dsp_changed
= 1;
4309 /* SCSI PARITY error */
4310 if (sstat0_sist0
& SSTAT0_PAR
) {
4312 if (cmd
&& cmd
->cmd
) {
4313 printk("scsi%d : target %d lun %d parity error.\n",
4314 host
->host_no
, cmd
->cmd
->target
, cmd
->cmd
->lun
);
4315 abnormal_finished (cmd
, DID_PARITY
<< 16);
4317 printk("scsi%d : parity error\n", host
->host_no
);
4318 /* Should send message out, parity error */
4320 /* XXX - Reduce synchronous transfer rate! */
4321 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_initiator_abort
/
4323 hostdata
->dsp_changed
= 1;
4324 /* SCSI GROSS error */
4327 if (sstat0_sist0
& SSTAT0_SGE
) {
4329 printk("scsi%d : gross error\n", host
->host_no
);
4330 /* Reset SCSI offset */
4331 if ((hostdata
->chip
/ 100) == 8) {
4332 NCR53c7x0_write8 (STEST2_REG_800
, STEST2_800_ROF
);
4336 * A SCSI gross error may occur when we have
4338 * - A synchronous offset which causes the SCSI FIFO to be overwritten.
4340 * - A REQ which causes the maximum synchronous offset programmed in
4341 * the SXFER register to be exceeded.
4343 * - A phase change with an outstanding synchronous offset.
4345 * - Residual data in the synchronous data FIFO, with a transfer
4346 * other than a synchronous receive is started.$#
4350 /* XXX Should deduce synchronous transfer rate! */
4351 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_initiator_abort
/
4353 hostdata
->dsp_changed
= 1;
4354 /* Phase mismatch */
4357 if (sstat0_sist0
& SSTAT0_MA
) {
4359 if (hostdata
->options
& OPTION_DEBUG_INTR
)
4360 printk ("scsi%d : SSTAT0_MA\n", host
->host_no
);
4361 intr_phase_mismatch (host
, cmd
);
4365 if (sstat0_sist0
& SIST0_800_RSL
)
4366 printk ("scsi%d : Oh no Mr. Bill!\n", host
->host_no
);
4370 * If a fatal SCSI interrupt occurs, we must insure that the DMA and
4371 * SCSI FIFOs were flushed.
4375 if (!hostdata
->dstat_valid
) {
4376 hostdata
->dstat
= NCR53c7x0_read8(DSTAT_REG
);
4377 hostdata
->dstat_valid
= 1;
4380 /* XXX - code check for 700/800 chips */
4381 if (!(hostdata
->dstat
& DSTAT_DFE
)) {
4382 printk ("scsi%d : DMA FIFO not empty\n", host
->host_no
);
4383 if (NCR53c7x0_read8 (CTEST2_REG_800
) & CTEST2_800_DDIR
) {
4384 printk ("scsi%d: Flushing DMA FIFO\n",
4386 NCR53c7x0_write8 (CTEST3_REG_800
, CTEST3_800_FLF
);
4387 while (!((hostdata
->dstat
= NCR53c7x0_read8(DSTAT_REG
)) &
4390 NCR53c7x0_write8 (CTEST3_REG_800
, CTEST3_800_CLF
);
4391 while (NCR53c7x0_read8 (CTEST3_REG_800
) & CTEST3_800_CLF
);
4393 hostdata
->dstat
|= DSTAT_DFE
;
4399 * Function : static void NCR53c7x0_intr (int irq, void *dev_id, struct pt_regs * regs)
4401 * Purpose : handle NCR53c7x0 interrupts for all NCR devices sharing
4402 * the same IRQ line.
4404 * Inputs : Since we're using the SA_INTERRUPT interrupt handler
4405 * semantics, irq indicates the interrupt which invoked
4410 NCR53c7x0_intr (int irq
, void *dev_id
, struct pt_regs
* regs
) {
4411 NCR53c7x0_local_declare();
4412 struct Scsi_Host
*host
; /* Host we are looking at */
4413 unsigned char istat
; /* Values of interrupt regs */
4414 struct NCR53c7x0_hostdata
*hostdata
; /* host->hostdata */
4415 struct NCR53c7x0_cmd
*cmd
, /* command which halted */
4418 int done
= 1; /* Indicates when handler
4420 int interrupted
= 0; /* This HA generated
4422 int have_intfly
; /* Don't print warning
4423 messages when we stack
4425 unsigned long flags
;
4428 char buf
[80]; /* Debugging sprintf buffer */
4429 size_t buflen
; /* Length of same */
4433 for (host
= first_host
; host
; host
= host
->next
)
4434 if (host
->hostt
== the_template
&& host
->irq
== irq
) {
4435 NCR53c7x0_local_setup(host
);
4437 hostdata
= (struct NCR53c7x0_hostdata
*) host
->hostdata
;
4438 hostdata
->dsp_changed
= 0;
4445 hostdata
->dstat_valid
= 0;
4448 * Only read istat once, since reading it again will unstack
4451 istat
= NCR53c7x0_read8(hostdata
->istat
);
4454 * INTFLY interrupts are used by the NCR53c720, NCR53c810,
4455 * and NCR53c820 to signify completion of a command. Since
4456 * the SCSI processor continues running, we can't just look
4457 * at the contents of the DSA register and continue running.
4459 /* XXX - this is too big, offends my sense of aesthetics, and should
4460 move to intr_intfly() */
4461 is_8xx_chip
= ((unsigned) (hostdata
->chip
- 800)) < 100;
4462 if ((hostdata
->options
& OPTION_INTFLY
) &&
4463 (is_8xx_chip
&& (istat
& ISTAT_800_INTF
))) {
4464 char search_found
= 0; /* Got at least one ? */
4469 * Clear the INTF bit by writing a one.
4470 * This reset operation is self-clearing.
4472 NCR53c7x0_write8(hostdata
->istat
, istat
|ISTAT_800_INTF
);
4474 if (hostdata
->options
& OPTION_DEBUG_INTR
)
4475 printk ("scsi%d : INTFLY\n", host
->host_no
);
4478 * Traverse our list of running commands, and look
4479 * for those with valid (non-0xff ff) status and message
4480 * bytes encoded in the result which signify command
4488 for (cmd_prev_ptr
= (struct NCR53c7x0_cmd
**)
4489 &(hostdata
->running_list
), cmd
=
4490 (struct NCR53c7x0_cmd
*) hostdata
->running_list
; cmd
;
4491 cmd_prev_ptr
= (struct NCR53c7x0_cmd
**) &(cmd
->next
),
4492 cmd
= (struct NCR53c7x0_cmd
*) cmd
->next
) {
4496 printk("scsi%d : very weird.\n", host
->host_no
);
4500 if (!(tmp
= cmd
->cmd
)) {
4501 printk("scsi%d : weird. NCR53c7x0_cmd has no Scsi_Cmnd\n",
4506 printk ("scsi%d : looking at result of 0x%x\n",
4507 host
->host_no
, cmd
->cmd
->result
);
4511 if (tmp
->result
== le32_to_cpu(0xffff))
4513 tmp
->result
= le32_to_cpu(tmp
->result
);
4515 if (((tmp
->result
& 0xff) == 0xff) ||
4516 ((tmp
->result
& 0xff00) == 0xff00))
4522 /* Important - remove from list _before_ done is called */
4524 *cmd_prev_ptr
= (struct NCR53c7x0_cmd
*) cmd
->next
;
4526 --hostdata
->busy
[tmp
->target
][tmp
->lun
];
4527 cmd
->next
= hostdata
->free
;
4528 hostdata
->free
= cmd
;
4530 tmp
->host_scribble
= NULL
;
4532 if (hostdata
->options
& OPTION_DEBUG_INTR
) {
4533 printk ("scsi%d : command complete : pid %lu, id %d,lun %d result 0x%x ",
4534 host
->host_no
, tmp
->pid
, tmp
->target
, tmp
->lun
, tmp
->result
);
4535 print_command (tmp
->cmnd
);
4539 hostdata
->options
&= ~OPTION_DEBUG_INTR
;
4541 tmp
->scsi_done(tmp
);
4545 restore_flags(flags
);
4548 * I think that we're stacking INTFLY interrupts; taking care of
4549 * all the finished commands on the first one, and then getting
4550 * worried when we see the next one. The magic with have_intfly
4551 * should tell if this is the case..
4554 if (!search_found
&& !have_intfly
) {
4555 printk ("scsi%d : WARNING : INTFLY with no completed commands.\n",
4557 } else if (!have_intfly
) {
4559 run_process_issue_queue();
4563 if (istat
& (ISTAT_SIP
|ISTAT_DIP
)) {
4566 hostdata
->state
= STATE_HALTED
;
4568 if (NCR53c7x0_read8 ((hostdata
->chip
/ 100) == 8 ?
4569 SSTAT1_REG
: SSTAT2_REG
) & SSTAT2_FF_MASK
)
4570 printk ("scsi%d : SCSI FIFO not empty\n",
4574 * NCR53c700 and NCR53c700-66 change the current SCSI
4575 * process, hostdata->curr, in the Linux driver so
4576 * cmd = hostdata->curr.
4578 * With other chips, we must look through the commands
4579 * executing and find the command structure which
4580 * corresponds to the DSA register.
4583 if (hostdata
->options
& OPTION_700
) {
4584 cmd
= (struct NCR53c7x0_cmd
*) hostdata
->curr
;
4586 dsa
= bus_to_virt(NCR53c7x0_read32(DSA_REG
));
4587 for (cmd
= (struct NCR53c7x0_cmd
*)
4588 hostdata
->running_list
; cmd
&&
4589 (dsa
+ (hostdata
->dsa_start
/ sizeof(u32
))) !=
4591 cmd
= (struct NCR53c7x0_cmd
*)(cmd
->next
));
4593 if (hostdata
->options
& OPTION_DEBUG_INTR
) {
4595 printk("scsi%d : interrupt for pid %lu, id %d, lun %d ",
4596 host
->host_no
, cmd
->cmd
->pid
, (int) cmd
->cmd
->target
,
4597 (int) cmd
->cmd
->lun
);
4598 print_command (cmd
->cmd
->cmnd
);
4600 printk("scsi%d : no active command\n", host
->host_no
);
4603 if (istat
& ISTAT_SIP
) {
4604 if (hostdata
->options
& OPTION_DEBUG_INTR
)
4605 printk ("scsi%d : ISTAT_SIP\n", host
->host_no
);
4606 intr_scsi (host
, cmd
);
4609 if (istat
& ISTAT_DIP
) {
4610 if (hostdata
->options
& OPTION_DEBUG_INTR
)
4611 printk ("scsi%d : ISTAT_DIP\n", host
->host_no
);
4612 intr_dma (host
, cmd
);
4615 if (!hostdata
->dstat_valid
) {
4616 hostdata
->dstat
= NCR53c7x0_read8(DSTAT_REG
);
4617 hostdata
->dstat_valid
= 1;
4620 /* XXX - code check for 700/800 chips */
4621 if (!(hostdata
->dstat
& DSTAT_DFE
)) {
4622 printk ("scsi%d : DMA FIFO not empty\n", host
->host_no
);
4623 if (NCR53c7x0_read8 (CTEST2_REG_800
) & CTEST2_800_DDIR
) {
4624 printk ("scsi%d: Flushing DMA FIFO\n",
4626 NCR53c7x0_write8 (CTEST3_REG_800
, CTEST3_800_FLF
);
4627 while (!((hostdata
->dstat
= NCR53c7x0_read8(DSTAT_REG
)) &
4631 NCR53c7x0_write8 (CTEST3_REG_800
, CTEST3_800_CLF
);
4632 while (NCR53c7x0_read8 (CTEST3_REG_800
) & CTEST3_800_CLF
);
4634 hostdata
->dstat
|= DSTAT_DFE
;
4637 } while (interrupted
);
4641 if (hostdata
->intrs
!= -1)
4644 if (hostdata
->intrs
> 40) {
4645 printk("scsi%d : too many interrupts, halting", host
->host_no
);
4650 if (!hostdata
->idle
&& hostdata
->state
== STATE_HALTED
) {
4651 if (!hostdata
->dsp_changed
) {
4652 hostdata
->dsp
= (u32
*)
4653 bus_to_virt(NCR53c7x0_read32(DSP_REG
));
4657 printk("scsi%d : new dsp is 0x%lx (virt 0x%p)\n",
4658 host
->host_no
, virt_to_bus(hostdata
->dsp
), hostdata
->dsp
);
4661 hostdata
->state
= STATE_RUNNING
;
4662 NCR53c7x0_write32 (DSP_REG
, virt_to_bus(hostdata
->dsp
));
4670 * Function : static int abort_connected (struct Scsi_Host *host)
4672 * Purpose : Assuming that the NCR SCSI processor is currently
4673 * halted, break the currently established nexus. Clean
4674 * up of the NCR53c7x0_cmd and Scsi_Cmnd structures should
4675 * be done on receipt of the abort interrupt.
4677 * Inputs : host - SCSI host
4682 abort_connected (struct Scsi_Host
*host
) {
4684 NCR53c7x0_local_declare();
4686 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
4688 /* FIXME : this probably should change for production kernels; at the
4689 least, counter should move to a per-host structure. */
4690 static int counter
= 5;
4692 int sstat
, phase
, offset
;
4694 NCR53c7x0_local_setup(host
);
4697 if (--counter
<= 0) {
4702 printk ("scsi%d : DANGER : abort_connected() called \n",
4708 * New strategy : Rather than using a generic abort routine,
4709 * we'll specifically try to source or sink the appropriate
4710 * amount of data for the phase we're currently in (taking into
4711 * account the current synchronous offset)
4714 sstat
= (NCR53c8x0_read8 ((chip
/ 100) == 8 ? SSTAT1_REG
: SSTAT2_REG
);
4715 offset
= OFFSET (sstat
& SSTAT2_FF_MASK
) >> SSTAT2_FF_SHIFT
;
4716 phase
= sstat
& SSTAT2_PHASE_MASK
;
4720 * MOVE source_or_sink, WHEN CURRENT PHASE
4721 * < repeat for each outstanding byte >
4722 * JUMP send_abort_message
4725 script
= hostdata
->abort_script
= kmalloc (
4726 8 /* instruction size */ * (
4728 (!offset
? 1 : offset
) /* One transfer per outstanding byte */ +
4729 1 /* send abort message */),
4733 #else /* def NEW_ABORT */
4734 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_initiator_abort
/
4736 #endif /* def NEW_ABORT */
4737 hostdata
->dsp_changed
= 1;
4739 /* XXX - need to flag the command as aborted after the abort_connected
4746 * Function : static int datapath_residual (Scsi_Host *host)
4748 * Purpose : return residual data count of what's in the chip.
4750 * Inputs : host - SCSI host
4754 datapath_residual (struct Scsi_Host
*host
) {
4755 NCR53c7x0_local_declare();
4756 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
4758 int count
, synchronous
, sstat
;
4759 NCR53c7x0_local_setup(host
);
4760 /* COMPAT : the 700 and 700-66 need to use DFIFO_00_BO_MASK */
4761 count
= ((NCR53c7x0_read8 (DFIFO_REG
) & DFIFO_10_BO_MASK
) -
4762 (NCR53c7x0_read32 (DBC_REG
) & DFIFO_10_BO_MASK
)) & DFIFO_10_BO_MASK
;
4763 synchronous
= NCR53c7x0_read8 (SXFER_REG
) & SXFER_MO_MASK
;
4764 /* COMPAT : DDIR is elsewhere on non-'8xx chips. */
4765 if (NCR53c7x0_read8 (CTEST2_REG_800
) & CTEST2_800_DDIR
) {
4768 count
+= (NCR53c7x0_read8 ((hostdata
->chip
/ 100) == 8 ?
4769 SSTAT1_REG
: SSTAT2_REG
) & SSTAT2_FF_MASK
) >> SSTAT2_FF_SHIFT
;
4771 if (NCR53c7x0_read8 ((hostdata
->chip
/ 100) == 8 ?
4772 SSTAT0_REG
: SSTAT1_REG
) & SSTAT1_ILF
)
4776 sstat
= ((hostdata
->chip
/ 100) == 8) ? NCR53c7x0_read8 (SSTAT0_REG
) :
4777 NCR53c7x0_read8 (SSTAT1_REG
);
4778 if (sstat
& SSTAT1_OLF
)
4780 if (synchronous
&& (sstat
& SSTAT1_ORF
))
4787 * Function : static const char * sbcl_to_phase (int sbcl)_
4789 * Purpose : Convert SBCL register to user-parsable phase representation
4791 * Inputs : sbcl - value of sbcl register
4796 sbcl_to_phase (int sbcl
) {
4797 switch (sbcl
& SBCL_PHASE_MASK
) {
4798 case SBCL_PHASE_DATAIN
:
4800 case SBCL_PHASE_DATAOUT
:
4802 case SBCL_PHASE_MSGIN
:
4804 case SBCL_PHASE_MSGOUT
:
4806 case SBCL_PHASE_CMDOUT
:
4808 case SBCL_PHASE_STATIN
:
4816 * Function : static const char * sstat2_to_phase (int sstat)_
4818 * Purpose : Convert SSTAT2 register to user-parsable phase representation
4820 * Inputs : sstat - value of sstat register
4825 sstat2_to_phase (int sstat
) {
4826 switch (sstat
& SSTAT2_PHASE_MASK
) {
4827 case SSTAT2_PHASE_DATAIN
:
4829 case SSTAT2_PHASE_DATAOUT
:
4831 case SSTAT2_PHASE_MSGIN
:
4833 case SSTAT2_PHASE_MSGOUT
:
4835 case SSTAT2_PHASE_CMDOUT
:
4837 case SSTAT2_PHASE_STATIN
:
4845 * Function : static void intr_phase_mismatch (struct Scsi_Host *host,
4846 * struct NCR53c7x0_cmd *cmd)
4848 * Purpose : Handle phase mismatch interrupts
4850 * Inputs : host, cmd - host and NCR command causing the interrupt, cmd
4853 * Side effects : The abort_connected() routine is called or the NCR chip
4854 * is restarted, jumping to the command_complete entry point, or
4855 * patching the address and transfer count of the current instruction
4856 * and calling the msg_in entry point as appropriate.
4860 intr_phase_mismatch (struct Scsi_Host
*host
, struct NCR53c7x0_cmd
*cmd
) {
4861 NCR53c7x0_local_declare();
4862 u32 dbc_dcmd
, *dsp
, *dsp_next
;
4863 unsigned char dcmd
, sbcl
;
4864 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
4867 enum {ACTION_ABORT
, ACTION_ABORT_PRINT
, ACTION_CONTINUE
} action
=
4869 const char *where
= NULL
;
4870 NCR53c7x0_local_setup(host
);
4873 * Corrective action is based on where in the SCSI SCRIPT(tm) the error
4874 * occurred, as well as which SCSI phase we are currently in.
4876 dsp_next
= bus_to_virt(NCR53c7x0_read32(DSP_REG
));
4879 * Fetch the current instruction, and remove the operands for easier
4882 dbc_dcmd
= NCR53c7x0_read32(DBC_REG
);
4883 dcmd
= (dbc_dcmd
& 0xff000000) >> 24;
4885 * Like other processors, the NCR adjusts the instruction pointer before
4886 * instruction decode. Set the DSP address back to what it should
4887 * be for this instruction based on its size (2 or 3 32 bit words).
4889 dsp
= dsp_next
- NCR53c7x0_insn_size(dcmd
);
4893 * Read new SCSI phase from the SBCL lines. Since all of our code uses
4894 * a WHEN conditional instead of an IF conditional, we don't need to
4895 * wait for a new REQ.
4897 sbcl
= NCR53c7x0_read8(SBCL_REG
) & SBCL_PHASE_MASK
;
4900 action
= ACTION_ABORT_PRINT
;
4901 where
= "no current command";
4903 * The way my SCSI SCRIPTS(tm) are architected, recoverable phase
4904 * mismatches should only occur where we're doing a multi-byte
4905 * BMI instruction. Specifically, this means
4907 * - select messages (a SCSI-I target may ignore additional messages
4908 * after the IDENTIFY; any target may reject a SDTR or WDTR)
4910 * - command out (targets may send a message to signal an error
4911 * condition, or go into STATUSIN after they've decided
4912 * they don't like the command.
4914 * - reply_message (targets may reject a multi-byte message in the
4917 * - data transfer routines (command completion with buffer space
4918 * left, disconnect message, or error message)
4920 } else if (((dsp
>= cmd
->data_transfer_start
&&
4921 dsp
< cmd
->data_transfer_end
)) || dsp
== (cmd
->residual
+ 2)) {
4922 if ((dcmd
& (DCMD_TYPE_MASK
|DCMD_BMI_OP_MASK
|DCMD_BMI_INDIRECT
|
4923 DCMD_BMI_MSG
|DCMD_BMI_CD
)) == (DCMD_TYPE_BMI
|
4924 DCMD_BMI_OP_MOVE_I
)) {
4925 residual
= datapath_residual (host
);
4926 if (hostdata
->options
& OPTION_DEBUG_DISCONNECT
)
4927 printk ("scsi%d : handling residual transfer (+ %d bytes from DMA FIFO)\n",
4928 host
->host_no
, residual
);
4931 * The first instruction is a CALL to the alternate handler for
4932 * this data transfer phase, so we can do calls to
4933 * munge_msg_restart as we would if control were passed
4934 * from normal dynamic code.
4936 if (dsp
!= cmd
->residual
+ 2) {
4937 cmd
->residual
[0] = le32_to_cpu(((DCMD_TYPE_TCI
| DCMD_TCI_OP_CALL
|
4938 ((dcmd
& DCMD_BMI_IO
) ? DCMD_TCI_IO
: 0)) << 24) |
4939 DBC_TCI_WAIT_FOR_VALID
| DBC_TCI_COMPARE_PHASE
);
4940 cmd
->residual
[1] = le32_to_cpu(virt_to_bus(hostdata
->script
)
4941 + ((dcmd
& DCMD_BMI_IO
)
4942 ? hostdata
->E_other_in
: hostdata
->E_other_out
));
4946 * The second instruction is the a data transfer block
4947 * move instruction, reflecting the pointer and count at the
4948 * time of the phase mismatch.
4950 cmd
->residual
[2] = le32_to_cpu(dbc_dcmd
+ residual
);
4951 cmd
->residual
[3] = le32_to_cpu(NCR53c7x0_read32(DNAD_REG
) - residual
);
4954 * The third and final instruction is a jump to the instruction
4955 * which follows the instruction which had to be 'split'
4957 if (dsp
!= cmd
->residual
+ 2) {
4958 cmd
->residual
[4] = le32_to_cpu(((DCMD_TYPE_TCI
|DCMD_TCI_OP_JUMP
)
4959 << 24) | DBC_TCI_TRUE
);
4960 cmd
->residual
[5] = le32_to_cpu(virt_to_bus(dsp_next
));
4964 * For the sake of simplicity, transfer control to the
4965 * conditional CALL at the start of the residual buffer.
4967 hostdata
->dsp
= cmd
->residual
;
4968 hostdata
->dsp_changed
= 1;
4969 action
= ACTION_CONTINUE
;
4971 where
= "non-BMI dynamic DSA code";
4972 action
= ACTION_ABORT_PRINT
;
4974 } else if (dsp
== (hostdata
->script
+ hostdata
->E_select_msgout
/ 4)) {
4976 NCR53c7x0_write8 (SOCL_REG
, 0);
4979 * Some devices (SQ555 come to mind) grab the IDENTIFY message
4980 * sent on selection, and decide to go into COMMAND OUT phase
4981 * rather than accepting the rest of the messages or rejecting
4982 * them. Handle these devices gracefully.
4984 case SBCL_PHASE_CMDOUT
:
4985 hostdata
->dsp
= dsp
+ 2 /* two _words_ */;
4986 hostdata
->dsp_changed
= 1;
4987 printk ("scsi%d : target %d ignored SDTR and went into COMMAND OUT\n",
4988 host
->host_no
, cmd
->cmd
->target
);
4989 cmd
->flags
&= ~CMD_FLAG_SDTR
;
4990 action
= ACTION_CONTINUE
;
4992 case SBCL_PHASE_MSGIN
:
4993 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_msg_in
/
4995 hostdata
->dsp_changed
= 1;
4996 action
= ACTION_CONTINUE
;
4999 where
="select message out";
5000 action
= ACTION_ABORT_PRINT
;
5003 * Some SCSI devices will interpret a command as they read the bytes
5004 * off the SCSI bus, and may decide that the command is Bogus before
5005 * they've read the entire command off the bus.
5007 } else if (dsp
== hostdata
->script
+ hostdata
->E_cmdout_cmdout
/ sizeof
5009 hostdata
->dsp
= hostdata
->script
+ hostdata
->E_data_transfer
/
5011 hostdata
->dsp_changed
= 1;
5012 action
= ACTION_CONTINUE
;
5013 /* FIXME : we need to handle message reject, etc. within msg_respond. */
5015 } else if (dsp
== hostdata
->script
+ hostdata
->E_reply_message
) {
5017 /* Any other phase mismatches abort the currently executing command. */
5020 where
= "unknown location";
5021 action
= ACTION_ABORT_PRINT
;
5024 /* Flush DMA FIFO */
5025 if (!hostdata
->dstat_valid
) {
5026 hostdata
->dstat
= NCR53c7x0_read8(DSTAT_REG
);
5027 hostdata
->dstat_valid
= 1;
5029 if (!(hostdata
->dstat
& DSTAT_DFE
)) {
5030 if (NCR53c7x0_read8 (CTEST2_REG_800
) & CTEST2_800_DDIR
) {
5031 printk ("scsi%d: Flushing DMA FIFO\n",
5033 NCR53c7x0_write8 (CTEST3_REG_800
, CTEST3_800_FLF
);
5034 /* FIXME : what about stacked DMA interrupts? */
5035 while (!((hostdata
->dstat
= NCR53c7x0_read8(DSTAT_REG
)) &
5038 NCR53c7x0_write8 (CTEST3_REG_800
, CTEST3_800_CLF
);
5039 while (NCR53c7x0_read8 (CTEST3_REG_800
) & CTEST3_800_CLF
);
5041 hostdata
->dstat
|= DSTAT_DFE
;
5045 case ACTION_ABORT_PRINT
:
5046 printk("scsi%d : %s : unexpected phase %s.\n",
5047 host
->host_no
, where
? where
: "unknown location",
5048 sbcl_to_phase(sbcl
));
5050 /* Fall through to ACTION_ABORT */
5052 abort_connected (host
);
5054 case ACTION_CONTINUE
:
5059 if (hostdata
->dsp_changed
) {
5060 printk("scsi%d: new dsp 0x%p\n", host
->host_no
, hostdata
->dsp
);
5061 print_insn (host
, hostdata
->dsp
, "", 1);
5068 * Function : static void intr_bf (struct Scsi_Host *host,
5069 * struct NCR53c7x0_cmd *cmd)
5071 * Purpose : handle BUS FAULT interrupts
5073 * Inputs : host, cmd - host and NCR command causing the interrupt, cmd
5078 intr_bf (struct Scsi_Host
*host
, struct NCR53c7x0_cmd
*cmd
) {
5079 NCR53c7x0_local_declare();
5080 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
5083 *next_dsp
, /* Current dsp */
5085 dbc_dcmd
; /* DCMD (high eight bits) + DBC */
5086 unsigned short pci_status
;
5088 unsigned long flags
;
5089 char *reason
= NULL
;
5090 /* Default behavior is for a silent error, with a retry until we've
5091 exhausted retries. */
5092 enum {MAYBE
, ALWAYS
, NEVER
} retry
= MAYBE
;
5094 NCR53c7x0_local_setup(host
);
5096 dbc_dcmd
= NCR53c7x0_read32 (DBC_REG
);
5097 next_dsp
= bus_to_virt (NCR53c7x0_read32(DSP_REG
));
5098 dsp
= next_dsp
- NCR53c7x0_insn_size ((dbc_dcmd
>> 24) & 0xff);
5099 /* FIXME - check chip type */
5100 dsa
= bus_to_virt (NCR53c7x0_read32(DSA_REG
));
5103 * Bus faults can be caused by either a Bad Address or
5104 * Target Abort. We should check the Received Target Abort
5105 * bit of the PCI status register and Master Abort Bit.
5107 * - Master Abort bit indicates that no device claimed
5108 * the address with DEVSEL within five clocks
5110 * - Target Abort bit indicates that a target claimed it,
5111 * but changed its mind once it saw the byte enables.
5115 if ((hostdata
->chip
/ 100) == 8) {
5118 tmp
= pcibios_read_config_word (hostdata
->pci_bus
,
5119 hostdata
->pci_device_fn
, PCI_STATUS
, &pci_status
);
5120 restore_flags (flags
);
5121 if (tmp
== PCIBIOS_SUCCESSFUL
) {
5122 if (pci_status
& PCI_STATUS_REC_TARGET_ABORT
) {
5123 reason
= "PCI target abort";
5124 pci_status
&= ~PCI_STATUS_REC_TARGET_ABORT
;
5125 } else if (pci_status
& PCI_STATUS_REC_MASTER_ABORT
) {
5126 reason
= "No device asserted PCI DEVSEL within five bus clocks";
5127 pci_status
&= ~PCI_STATUS_REC_MASTER_ABORT
;
5128 } else if (pci_status
& PCI_STATUS_PARITY
) {
5130 pci_status
&= ~PCI_STATUS_PARITY
;
5133 printk ("scsi%d : couldn't read status register : %s\n",
5134 host
->host_no
, pcibios_strerror (tmp
));
5142 if (report
&& reason
) {
5143 printk(KERN_ALERT
"scsi%d : BUS FAULT reason = %s\n",
5144 host
->host_no
, reason
? reason
: "unknown");
5153 * TODO : we should attempt to recover from any spurious bus
5154 * faults. After X retries, we should figure that things are
5155 * sufficiently wedged, and call NCR53c7xx_reset.
5157 * This code should only get executed once we've decided that we
5161 if (retry
== NEVER
) {
5162 printk(KERN_ALERT
" mail drew@PoohSticks.ORG\n");
5168 * Function : static void intr_dma (struct Scsi_Host *host,
5169 * struct NCR53c7x0_cmd *cmd)
5171 * Purpose : handle all DMA interrupts, indicated by the setting
5172 * of the DIP bit in the ISTAT register.
5174 * Inputs : host, cmd - host and NCR command causing the interrupt, cmd
5179 intr_dma (struct Scsi_Host
*host
, struct NCR53c7x0_cmd
*cmd
) {
5180 NCR53c7x0_local_declare();
5181 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
5183 unsigned char dstat
; /* DSTAT */
5185 *next_dsp
, /* Current dsp */
5187 dbc_dcmd
; /* DCMD (high eight bits) + DBC */
5189 unsigned long flags
;
5190 NCR53c7x0_local_setup(host
);
5192 if (!hostdata
->dstat_valid
) {
5193 hostdata
->dstat
= NCR53c7x0_read8(DSTAT_REG
);
5194 hostdata
->dstat_valid
= 1;
5197 dstat
= hostdata
->dstat
;
5199 if (hostdata
->options
& OPTION_DEBUG_INTR
)
5200 printk("scsi%d : DSTAT=0x%x\n", host
->host_no
, (int) dstat
);
5202 dbc_dcmd
= NCR53c7x0_read32 (DBC_REG
);
5203 next_dsp
= bus_to_virt(NCR53c7x0_read32(DSP_REG
));
5204 dsp
= next_dsp
- NCR53c7x0_insn_size ((dbc_dcmd
>> 24) & 0xff);
5205 /* XXX - check chip type */
5206 dsa
= bus_to_virt(NCR53c7x0_read32(DSA_REG
));
5209 * DSTAT_ABRT is the aborted interrupt. This is set whenever the
5210 * SCSI chip is aborted.
5212 * With NCR53c700 and NCR53c700-66 style chips, we should only
5213 * get this when the chip is currently running the accept
5214 * reselect/select code and we have set the abort bit in the
5219 if (dstat
& DSTAT_ABRT
) {
5221 /* XXX - add code here to deal with normal abort */
5222 if ((hostdata
->options
& OPTION_700
) && (hostdata
->state
==
5227 printk(KERN_ALERT
"scsi%d : unexpected abort interrupt at\n"
5228 " ", host
->host_no
);
5229 print_insn (host
, dsp
, KERN_ALERT
"s ", 1);
5235 * DSTAT_SSI is the single step interrupt. Should be generated
5236 * whenever we have single stepped or are tracing.
5239 if (dstat
& DSTAT_SSI
) {
5240 if (hostdata
->options
& OPTION_DEBUG_TRACE
) {
5241 } else if (hostdata
->options
& OPTION_DEBUG_SINGLE
) {
5242 print_insn (host
, dsp
, "s ", 0);
5245 /* XXX - should we do this, or can we get away with writing dsp? */
5247 NCR53c7x0_write8 (DCNTL_REG
, (NCR53c7x0_read8(DCNTL_REG
) &
5248 ~DCNTL_SSM
) | DCNTL_STD
);
5249 restore_flags(flags
);
5251 printk(KERN_ALERT
"scsi%d : unexpected single step interrupt at\n"
5252 " ", host
->host_no
);
5253 print_insn (host
, dsp
, KERN_ALERT
"", 1);
5254 printk(KERN_ALERT
" mail drew@PoohSticks.ORG\n");
5260 * DSTAT_IID / DSTAT_OPC (same bit, same meaning, only the name
5261 * is different) is generated whenever an illegal instruction is
5264 * XXX - we may want to emulate INTFLY here, so we can use
5265 * the same SCSI SCRIPT (tm) for NCR53c710 through NCR53c810
5269 if (dstat
& DSTAT_OPC
) {
5271 * Ascertain if this IID interrupts occurred before or after a STO
5272 * interrupt. Since the interrupt handling code now leaves
5273 * DSP unmodified until _after_ all stacked interrupts have been
5274 * processed, reading the DSP returns the original DSP register.
5275 * This means that if dsp lies between the select code, and
5276 * message out following the selection code (where the IID interrupt
5277 * would have to have occurred by due to the implicit wait for REQ),
5278 * we have an IID interrupt resulting from a STO condition and
5282 if (((dsp
>= (hostdata
->script
+ hostdata
->E_select
/ sizeof(u32
))) &&
5283 (dsp
<= (hostdata
->script
+ hostdata
->E_select_msgout
/
5284 sizeof(u32
) + 8))) || (hostdata
->test_running
== 2)) {
5285 if (hostdata
->options
& OPTION_DEBUG_INTR
)
5286 printk ("scsi%d : ignoring DSTAT_IID for SSTAT_STO\n",
5288 if (hostdata
->expecting_iid
) {
5289 hostdata
->expecting_iid
= 0;
5291 if (hostdata
->test_running
== 2) {
5292 hostdata
->test_running
= 0;
5293 hostdata
->test_completed
= 3;
5295 abnormal_finished (cmd
, DID_BAD_TARGET
<< 16);
5297 hostdata
->expecting_sto
= 1;
5300 * We can't guarantee we'll be able to execute the WAIT DISCONNECT
5301 * instruction within the 3.4us of bus free and arbitration delay
5302 * that a target can RESELECT in and assert REQ after we've dropped
5303 * ACK. If this happens, we'll get an illegal instruction interrupt.
5304 * Doing away with the WAIT DISCONNECT instructions broke everything,
5305 * so instead I'll settle for moving one WAIT DISCONNECT a few
5306 * instructions closer to the CLEAR ACK before it to minimize the
5307 * chances of this happening, and handle it if it occurs anyway.
5309 * Simply continue with what we were doing, and control should
5310 * be transfered to the schedule routine which will ultimately
5311 * pass control onto the reselection or selection (not yet)
5314 } else if (dbc_dcmd
== 0x48000000 && (NCR53c7x0_read8 (SBCL_REG
) &
5316 if (!(hostdata
->options
& OPTION_NO_PRINT_RACE
))
5318 printk("scsi%d: REQ before WAIT DISCONNECT IID\n",
5320 hostdata
->options
|= OPTION_NO_PRINT_RACE
;
5323 printk(KERN_ALERT
"scsi%d : illegal instruction\n", host
->host_no
);
5325 printk(KERN_ALERT
" mail drew@PoohSticks.ORG with ALL\n"
5326 " boot messages and diagnostic output\n");
5332 * DSTAT_BF are bus fault errors
5335 if (dstat
& DSTAT_800_BF
) {
5336 intr_bf (host
, cmd
);
5341 * DSTAT_SIR interrupts are generated by the execution of
5342 * the INT instruction. Since the exact values available
5343 * are determined entirely by the SCSI script running,
5344 * and are local to a particular script, a unique handler
5345 * is called for each script.
5348 if (dstat
& DSTAT_SIR
) {
5349 if (hostdata
->options
& OPTION_DEBUG_INTR
)
5350 printk ("scsi%d : DSTAT_SIR\n", host
->host_no
);
5351 switch ((tmp
= hostdata
->dstat_sir_intr (host
, cmd
))) {
5352 case SPECIFIC_INT_NOTHING
:
5353 case SPECIFIC_INT_RESTART
:
5355 case SPECIFIC_INT_ABORT
:
5356 abort_connected(host
);
5358 case SPECIFIC_INT_PANIC
:
5359 printk(KERN_ALERT
"scsi%d : failure at ", host
->host_no
);
5360 print_insn (host
, dsp
, KERN_ALERT
"", 1);
5361 printk(KERN_ALERT
" dstat_sir_intr() returned SPECIFIC_INT_PANIC\n");
5364 case SPECIFIC_INT_BREAK
:
5365 intr_break (host
, cmd
);
5368 printk(KERN_ALERT
"scsi%d : failure at ", host
->host_no
);
5369 print_insn (host
, dsp
, KERN_ALERT
"", 1);
5370 printk(KERN_ALERT
" dstat_sir_intr() returned unknown value %d\n",
5376 if ((hostdata
->chip
/ 100) == 8 && (dstat
& DSTAT_800_MDPE
)) {
5377 printk(KERN_ALERT
"scsi%d : Master Data Parity Error\n",
5384 * Function : static int print_insn (struct Scsi_Host *host,
5385 * u32 *insn, int kernel)
5387 * Purpose : print numeric representation of the instruction pointed
5388 * to by insn to the debugging or kernel message buffer
5391 * If desired, a user level program can interpret this
5394 * Inputs : host, insn - host, pointer to instruction, prefix -
5395 * string to prepend, kernel - use printk instead of debugging buffer.
5397 * Returns : size, in u32s, of instruction printed.
5401 * FIXME: should change kernel parameter so that it takes an ENUM
5402 * specifying severity - either KERN_ALERT or KERN_PANIC so
5403 * all panic messages are output with the same severity.
5407 print_insn (struct Scsi_Host
*host
, const u32
*insn
,
5408 const char *prefix
, int kernel
) {
5409 char buf
[160], /* Temporary buffer and pointer. ICKY
5410 arbitrary length. */
5414 unsigned char dcmd
; /* dcmd register for *insn */
5418 * Check to see if the instruction pointer is not bogus before
5419 * indirecting through it; avoiding red-zone at start of
5422 * FIXME: icky magic needs to happen here on non-intel boxes which
5423 * don't have kernel memory mapped in like this. Might be reasonable
5427 if (MAP_NR(insn
) < 1 || MAP_NR(insn
+ 8) > MAP_NR(high_memory
) ||
5428 ((((dcmd
= (insn
[0] >> 24) & 0xff) & DCMD_TYPE_MMI
) == DCMD_TYPE_MMI
) &&
5429 MAP_NR(insn
+ 12) > MAP_NR(high_memory
))) {
5431 sprintf (buf
, "%s%p: address out of range\n",
5435 * FIXME : (void *) cast in virt_to_bus should be unnecessary, because
5436 * it should take const void * as argument.
5438 sprintf(buf
, "%s0x%lx (virt 0x%p) : 0x%08x 0x%08x (virt 0x%p)",
5439 (prefix
? prefix
: ""), virt_to_bus((void *) insn
), insn
,
5440 insn
[0], insn
[1], bus_to_virt (le32_to_cpu(insn
[1])));
5441 tmp
= buf
+ strlen(buf
);
5442 if ((dcmd
& DCMD_TYPE_MASK
) == DCMD_TYPE_MMI
) {
5443 sprintf (tmp
, " 0x%08x (virt 0x%p)\n", insn
[2],
5444 bus_to_virt(le32_to_cpu(insn
[2])));
5447 sprintf (tmp
, "\n");
5456 size_t len
= strlen(buf
);
5457 debugger_kernel_write(host
, buf
, len
);
5464 * Function : static const char *ncr_state (int state)
5466 * Purpose : convert state (probably from hostdata->state) to a string
5470 * Returns : char * representation of state, "unknown" on error.
5475 ncr_state (int state
) {
5477 case STATE_HALTED
: return "halted";
5478 case STATE_WAITING
: return "waiting";
5479 case STATE_RUNNING
: return "running";
5480 case STATE_ABORTING
: return "aborting";
5481 case STATE_DISABLED
: return "disabled";
5482 default: return "unknown";
5488 * Function : int NCR53c7xx_abort (Scsi_Cmnd *cmd)
5490 * Purpose : Abort an errant SCSI command, doing all necessary
5491 * cleanup of the issue_queue, running_list, shared Linux/NCR
5492 * dsa issue and reconnect queues.
5494 * Inputs : cmd - command to abort, code - entire result field
5496 * Returns : 0 on success, -1 on failure.
5500 NCR53c7xx_abort (Scsi_Cmnd
*cmd
) {
5501 NCR53c7x0_local_declare();
5502 struct Scsi_Host
*host
= cmd
->host
;
5503 struct NCR53c7x0_hostdata
*hostdata
= host
? (struct NCR53c7x0_hostdata
*)
5504 host
->hostdata
: NULL
;
5505 unsigned long flags
;
5506 unsigned long result
;
5507 struct NCR53c7x0_cmd
*curr
, **prev
;
5508 Scsi_Cmnd
*me
, **last
;
5510 static long cache_pid
= -1;
5515 printk ("Bogus SCSI command pid %ld; no host structure\n",
5517 return SCSI_ABORT_ERROR
;
5518 } else if (!hostdata
) {
5519 printk ("Bogus SCSI host %d; no hostdata\n", host
->host_no
);
5520 return SCSI_ABORT_ERROR
;
5522 NCR53c7x0_local_setup(host
);
5525 * CHECK : I don't think that reading ISTAT will unstack any interrupts,
5526 * since we need to write the INTF bit to clear it, and SCSI/DMA
5527 * interrupts don't clear until we read SSTAT/SIST and DSTAT registers.
5529 * See that this is the case.
5531 * I suspect that several of our failures may be coming from a new fatal
5532 * interrupt (possibly due to a phase mismatch) happening after we've left
5533 * the interrupt handler, but before the PIC has had the interrupt condition
5537 if (NCR53c7x0_read8(hostdata
->istat
) &
5538 (ISTAT_DIP
|ISTAT_SIP
|
5539 (hostdata
->chip
/ 100 == 8 ? ISTAT_800_INTF
: 0))) {
5540 printk ("scsi%d : dropped interrupt for command %ld\n", host
->host_no
,
5542 NCR53c7x0_intr (host
->irq
, NULL
, NULL
);
5543 return SCSI_ABORT_BUSY
;
5549 if (cache_pid
== cmd
->pid
)
5550 panic ("scsi%d : bloody fetus %d\n", host
->host_no
, cmd
->pid
);
5552 cache_pid
= cmd
->pid
;
5557 * The command could be hiding in the issue_queue. This would be very
5558 * nice, as commands can't be moved from the high level driver's issue queue
5559 * into the shared queue until an interrupt routine is serviced, and this
5562 * If this is the case, we don't have to worry about anything - we simply
5563 * pull the command out of the old queue, and call it aborted.
5566 for (me
= (Scsi_Cmnd
*) hostdata
->issue_queue
,
5567 last
= (Scsi_Cmnd
**) &(hostdata
->issue_queue
);
5568 me
&& me
!= cmd
; last
= (Scsi_Cmnd
**)&(me
->SCp
.ptr
),
5569 me
= (Scsi_Cmnd
*)me
->SCp
.ptr
);
5572 *last
= (Scsi_Cmnd
*) me
->SCp
.ptr
;
5573 if (me
->host_scribble
) {
5574 ((struct NCR53c7x0_cmd
*)me
->host_scribble
)->next
= hostdata
->free
;
5575 hostdata
->free
= (struct NCR53c7x0_cmd
*) me
->host_scribble
;
5576 me
->host_scribble
= NULL
;
5578 cmd
->result
= DID_ABORT
<< 16;
5579 cmd
->scsi_done(cmd
);
5580 printk ("scsi%d : found command %ld in Linux issue queue\n",
5581 host
->host_no
, me
->pid
);
5582 restore_flags(flags
);
5583 run_process_issue_queue();
5584 return SCSI_ABORT_SUCCESS
;
5588 * That failing, the command could be in our list of already executing
5589 * commands. If this is the case, drastic measures are called for.
5592 for (curr
= (struct NCR53c7x0_cmd
*) hostdata
->running_list
,
5593 prev
= (struct NCR53c7x0_cmd
**) &(hostdata
->running_list
);
5594 curr
&& curr
->cmd
!= cmd
; prev
= (struct NCR53c7x0_cmd
**)
5595 &(curr
->next
), curr
= (struct NCR53c7x0_cmd
*) curr
->next
);
5598 result
= le32_to_cpu(cmd
->result
);
5599 if ((result
& 0xff) != 0xff && (result
& 0xff00) != 0xff00) {
5601 *prev
= (struct NCR53c7x0_cmd
*) curr
->next
;
5602 curr
->next
= (struct NCR53c7x0_cmd
*) hostdata
->free
;
5603 cmd
->host_scribble
= NULL
;
5604 hostdata
->free
= curr
;
5605 cmd
->scsi_done(cmd
);
5606 printk ("scsi%d : found finished command %ld in running list\n",
5607 host
->host_no
, cmd
->pid
);
5608 restore_flags(flags
);
5609 return SCSI_ABORT_NOT_RUNNING
;
5611 printk ("scsi%d : DANGER : command running, can not abort.\n",
5612 cmd
->host
->host_no
);
5613 restore_flags(flags
);
5614 return SCSI_ABORT_BUSY
;
5619 * And if we couldn't find it in any of our queues, it must have been
5620 * a dropped interrupt.
5623 curr
= (struct NCR53c7x0_cmd
*) cmd
->host_scribble
;
5625 curr
->next
= hostdata
->free
;
5626 hostdata
->free
= curr
;
5627 cmd
->host_scribble
= NULL
;
5630 result
= le32_to_cpu(cmd
->result
);
5631 if (((result
& 0xff00) == 0xff00) ||
5632 ((result
& 0xff) == 0xff)) {
5633 printk ("scsi%d : did this command ever run?\n", host
->host_no
);
5634 cmd
->result
= DID_ABORT
<< 16;
5636 printk ("scsi%d : probably lost INTFLY, normal completion\n",
5639 * FIXME : We need to add an additional flag which indicates if a
5640 * command was ever counted as BUSY, so if we end up here we can
5641 * decrement the busy count if and only if it is necessary.
5643 --hostdata
->busy
[cmd
->target
][cmd
->lun
];
5645 restore_flags(flags
);
5646 cmd
->scsi_done(cmd
);
5649 * We need to run process_issue_queue since termination of this command
5650 * may allow another queued command to execute first?
5652 return SCSI_ABORT_NOT_RUNNING
;
5656 * Function : int NCR53c7xx_reset (Scsi_Cmnd *cmd)
5658 * Purpose : perform a hard reset of the SCSI bus and NCR
5661 * Inputs : cmd - command which caused the SCSI RESET
5663 * Returns : 0 on success.
5667 NCR53c7xx_reset (Scsi_Cmnd
*cmd
, unsigned int reset_flags
) {
5668 NCR53c7x0_local_declare();
5669 unsigned long flags
;
5671 struct NCR53c7x0_cmd
* c
;
5674 * When we call scsi_done(), it's going to wake up anything sleeping on the
5675 * resources which were in use by the aborted commands, and we'll start to
5678 * We can't let this happen until after we've re-initialized the driver
5679 * structures, and can't reinitialize those structures until after we've
5680 * dealt with their contents.
5682 * So, we need to find all of the commands which were running, stick
5683 * them on a linked list of completed commands (we'll use the host_scribble
5684 * pointer), do our reinitialization, and then call the done function for
5687 Scsi_Cmnd
*nuke_list
= NULL
;
5688 struct Scsi_Host
*host
= cmd
->host
;
5689 struct NCR53c7x0_hostdata
*hostdata
=
5690 (struct NCR53c7x0_hostdata
*) host
->hostdata
;
5692 NCR53c7x0_local_setup(host
);
5697 dump_events (host
, 30);
5698 ncr_scsi_reset (host
);
5699 for (tmp
= nuke_list
= return_outstanding_commands (host
, 1 /* free */,
5700 0 /* issue */ ); tmp
; tmp
= (Scsi_Cmnd
*) tmp
->SCp
.buffer
)
5707 * If we didn't find the command which caused this reset in our running
5708 * list, then we've lost it. See that it terminates normally anyway.
5711 c
= (struct NCR53c7x0_cmd
*) cmd
->host_scribble
;
5713 cmd
->host_scribble
= NULL
;
5714 c
->next
= hostdata
->free
;
5717 printk ("scsi%d: lost command %ld\n", host
->host_no
, cmd
->pid
);
5718 cmd
->SCp
.buffer
= (struct scatterlist
*) nuke_list
;
5722 NCR53c7x0_driver_init (host
);
5723 hostdata
->soft_reset (host
);
5724 if (hostdata
->resets
== 0)
5726 else if (hostdata
->resets
!= -1)
5729 for (; nuke_list
; nuke_list
= tmp
) {
5730 tmp
= (Scsi_Cmnd
*) nuke_list
->SCp
.buffer
;
5731 nuke_list
->result
= DID_RESET
<< 16;
5732 nuke_list
->scsi_done (nuke_list
);
5734 restore_flags(flags
);
5735 return SCSI_RESET_SUCCESS
;
5739 * The NCR SDMS bios follows Annex A of the SCSI-CAM draft, and
5740 * therefore shares the scsicam_bios_param function.
5744 * Function : int insn_to_offset (Scsi_Cmnd *cmd, u32 *insn)
5746 * Purpose : convert instructions stored at NCR pointer into data
5749 * Inputs : cmd - SCSI command; insn - pointer to instruction. Either current
5750 * DSP, or saved data pointer.
5752 * Returns : offset on success, -1 on failure.
5757 insn_to_offset (Scsi_Cmnd
*cmd
, u32
*insn
) {
5758 struct NCR53c7x0_hostdata
*hostdata
=
5759 (struct NCR53c7x0_hostdata
*) cmd
->host
->hostdata
;
5760 struct NCR53c7x0_cmd
*ncmd
=
5761 (struct NCR53c7x0_cmd
*) cmd
->host_scribble
;
5762 int offset
= 0, buffers
;
5763 struct scatterlist
*segment
;
5768 * With the current code implementation, if the insn is inside dynamically
5769 * generated code, the data pointer will be the instruction preceding
5770 * the next transfer segment.
5773 if (!check_address ((unsigned long) ncmd
, sizeof (struct NCR53c7x0_cmd
)) &&
5774 ((insn
>= ncmd
->data_transfer_start
&&
5775 insn
< ncmd
->data_transfer_end
) ||
5776 (insn
>= ncmd
->residual
&&
5777 insn
< (ncmd
->residual
+
5778 sizeof(ncmd
->residual
))))) {
5779 ptr
= bus_to_virt(le32_to_cpu(insn
[3]));
5781 if ((buffers
= cmd
->use_sg
)) {
5783 segment
= (struct scatterlist
*) cmd
->buffer
;
5784 buffers
&& !((found
= ((ptr
>= segment
->address
) &&
5785 (ptr
< (segment
->address
+ segment
->length
)))));
5786 --buffers
, offset
+= segment
->length
, ++segment
)
5788 printk("scsi%d: comparing 0x%p to 0x%p\n",
5789 cmd
->host
->host_no
, saved
, segment
->address
);
5793 offset
+= ptr
- segment
->address
;
5796 offset
= ptr
- (char *) (cmd
->request_buffer
);
5798 } else if ((insn
>= hostdata
->script
+
5799 hostdata
->E_data_transfer
/ sizeof(u32
)) &&
5800 (insn
<= hostdata
->script
+
5801 hostdata
->E_end_data_transfer
/ sizeof(u32
))) {
5805 return found
? offset
: -1;
5811 * Function : void print_progress (Scsi_Cmnd *cmd)
5813 * Purpose : print the current location of the saved data pointer
5815 * Inputs : cmd - command we are interested in
5820 print_progress (Scsi_Cmnd
*cmd
) {
5821 NCR53c7x0_local_declare();
5822 struct NCR53c7x0_cmd
*ncmd
=
5823 (struct NCR53c7x0_cmd
*) cmd
->host_scribble
;
5827 NCR53c7x0_local_setup (cmd
->host
);
5828 for (i
= 0; i
< 2; ++i
) {
5829 if (check_address ((unsigned long) ncmd
,
5830 sizeof (struct NCR53c7x0_cmd
)) == -1)
5834 ptr
= bus_to_virt(le32_to_cpu(ncmd
->saved_data_pointer
));
5837 ptr
= bus_to_virt (NCR53c7x0_read32 (DSP_REG
) -
5838 NCR53c7x0_insn_size (NCR53c7x0_read8 (DCMD_REG
)) *
5841 offset
= insn_to_offset (cmd
, ptr
);
5844 printk ("scsi%d : %s data pointer at offset %d\n",
5845 cmd
->host
->host_no
, where
, offset
);
5848 printk ("scsi%d : can't determine %s data pointer offset\n",
5849 cmd
->host
->host_no
, where
);
5851 size
= print_insn (cmd
->host
,
5852 bus_to_virt(le32_to_cpu(ncmd
->saved_data_pointer
)), "", 1);
5853 print_insn (cmd
->host
,
5854 bus_to_virt(le32_to_cpu(ncmd
->saved_data_pointer
)) + size
* sizeof(u32
),
5863 print_dsa (struct Scsi_Host
*host
, u32
*dsa
, const char *prefix
) {
5864 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
5870 if (check_address ((unsigned long) dsa
, hostdata
->dsa_end
-
5871 hostdata
->dsa_start
) == -1) {
5872 printk("scsi%d : bad dsa virt 0x%p\n", host
->host_no
, dsa
);
5875 printk("%sscsi%d : dsa at phys 0x%lx (virt 0x%p)\n"
5876 " + %d : dsa_msgout length = %u, data = 0x%x (virt 0x%p)\n" ,
5877 prefix
? prefix
: "",
5878 host
->host_no
, virt_to_bus (dsa
), dsa
, hostdata
->dsa_msgout
,
5879 le32_to_cpu(dsa
[hostdata
->dsa_msgout
/ sizeof(u32
)]),
5880 le32_to_cpu(dsa
[hostdata
->dsa_msgout
/ sizeof(u32
) + 1]),
5881 bus_to_virt (le32_to_cpu(dsa
[hostdata
->dsa_msgout
/ sizeof(u32
) + 1])));
5884 * Only print messages if they're sane in length so we don't
5885 * blow the kernel printk buffer on something which won't buy us
5889 if (le32_to_cpu(dsa
[hostdata
->dsa_msgout
/ sizeof(u32
)]) <
5890 sizeof (hostdata
->free
->select
))
5891 for (i
= le32_to_cpu(dsa
[hostdata
->dsa_msgout
/ sizeof(u32
)]),
5892 ptr
= bus_to_virt (le32_to_cpu(dsa
[hostdata
->dsa_msgout
/ sizeof(u32
) + 1]));
5893 i
> 0 && !check_address ((unsigned long) ptr
, 1);
5894 ptr
+= len
, i
-= len
) {
5896 len
= print_msg (ptr
);
5902 printk(" + %d : select_indirect = 0x%x\n",
5903 hostdata
->dsa_select
, le32_to_cpu(dsa
[hostdata
->dsa_select
/ sizeof(u32
)]));
5904 cmd
= (Scsi_Cmnd
*) bus_to_virt(le32_to_cpu(dsa
[hostdata
->dsa_cmnd
/ sizeof(u32
)]));
5905 printk(" + %d : dsa_cmnd = 0x%x ", hostdata
->dsa_cmnd
,
5906 (u32
) virt_to_bus(cmd
));
5908 printk(" result = 0x%x, target = %d, lun = %d, cmd = ",
5909 cmd
->result
, cmd
->target
, cmd
->lun
);
5910 print_command(cmd
->cmnd
);
5913 printk(" + %d : dsa_next = 0x%x\n", hostdata
->dsa_next
,
5914 le32_to_cpu(dsa
[hostdata
->dsa_next
/ sizeof(u32
)]));
5916 printk("scsi%d target %d : sxfer_sanity = 0x%x, scntl3_sanity = 0x%x\n"
5918 host
->host_no
, cmd
->target
,
5919 hostdata
->sync
[cmd
->target
].sxfer_sanity
,
5920 hostdata
->sync
[cmd
->target
].scntl3_sanity
);
5921 for (i
= 0; i
< (sizeof(hostdata
->sync
[cmd
->target
].script
) / 4); ++i
)
5922 printk ("0x%x ", hostdata
->sync
[cmd
->target
].script
[i
]);
5924 print_progress (cmd
);
5928 * Function : void print_queues (Scsi_Host *host)
5930 * Purpose : print the contents of the NCR issue and reconnect queues
5932 * Inputs : host - SCSI host we are interested in
5937 print_queues (struct Scsi_Host
*host
) {
5938 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
5940 u32
*dsa
, *next_dsa
;
5943 Scsi_Cmnd
*cmd
, *next_cmd
;
5944 unsigned long flags
;
5946 printk ("scsi%d : issue queue\n", host
->host_no
);
5948 for (left
= host
->can_queue
, cmd
= (Scsi_Cmnd
*) hostdata
->issue_queue
;
5951 next_cmd
= (Scsi_Cmnd
*) cmd
->SCp
.ptr
;
5954 if (cmd
->host_scribble
) {
5955 if (check_address ((unsigned long) (cmd
->host_scribble
),
5956 sizeof (cmd
->host_scribble
)) == -1)
5957 printk ("scsi%d: scsi pid %ld bad pointer to NCR53c7x0_cmd\n",
5958 host
->host_no
, cmd
->pid
);
5959 /* print_dsa does sanity check on address, no need to check */
5961 print_dsa (host
, bus_to_virt(le32_to_cpu(((struct NCR53c7x0_cmd
*) cmd
->host_scribble
)-> dsa
)), "");
5963 printk ("scsi%d : scsi pid %ld for target %d lun %d has no NCR53c7x0_cmd\n",
5964 host
->host_no
, cmd
->pid
, cmd
->target
, cmd
->lun
);
5965 restore_flags(flags
);
5969 printk ("scsi%d : loop detected in issue queue\n",
5974 * Traverse the NCR reconnect and start DSA structures, printing out
5975 * each element until we hit the end or detect a loop. Currently,
5976 * the reconnect structure is a linked list; and the start structure
5977 * is an array. Eventually, the reconnect structure will become a
5978 * list as well, since this simplifies the code.
5981 printk ("scsi%d : schedule dsa array :\n", host
->host_no
);
5982 for (left
= host
->can_queue
, curr
= hostdata
->schedule
;
5983 left
> 0; curr
+= 2, --left
)
5984 if (curr
[0] != hostdata
->NOP_insn
)
5985 /* FIXME : convert pointer to dsa_begin to pointer to dsa. */
5986 print_dsa (host
, bus_to_virt (le32_to_cpu(curr
[1]) -
5987 (hostdata
->E_dsa_code_begin
-
5988 hostdata
->E_dsa_code_template
)), "");
5989 printk ("scsi%d : end schedule dsa array\n", host
->host_no
);
5991 printk ("scsi%d : reconnect_dsa_head :\n", host
->host_no
);
5993 for (left
= host
->can_queue
,
5994 dsa
= bus_to_virt (le32_to_cpu(hostdata
->reconnect_dsa_head
));
5999 if (check_address ((unsigned long) dsa
, sizeof(dsa
)) == -1) {
6000 printk ("scsi%d: bad DSA pointer 0x%p", host
->host_no
,
6006 next_dsa
= bus_to_virt(le32_to_cpu(dsa
[hostdata
->dsa_next
/ sizeof(u32
)]));
6007 print_dsa (host
, dsa
, "");
6009 restore_flags(flags
);
6011 printk ("scsi%d : end reconnect_dsa_head\n", host
->host_no
);
6013 printk("scsi%d: possible loop in ncr reconnect list\n",
6018 print_lots (struct Scsi_Host
*host
) {
6019 NCR53c7x0_local_declare();
6020 struct NCR53c7x0_hostdata
*hostdata
=
6021 (struct NCR53c7x0_hostdata
*) host
->hostdata
;
6022 u32
*dsp_next
, *dsp
, *dsa
, dbc_dcmd
;
6023 unsigned char dcmd
, sbcl
;
6025 NCR53c7x0_local_setup(host
);
6027 if ((dsp_next
= bus_to_virt(NCR53c7x0_read32 (DSP_REG
)))) {
6028 dbc_dcmd
= NCR53c7x0_read32(DBC_REG
);
6029 dcmd
= (dbc_dcmd
& 0xff000000) >> 24;
6030 dsp
= dsp_next
- NCR53c7x0_insn_size(dcmd
);
6031 dsa
= bus_to_virt(NCR53c7x0_read32(DSA_REG
));
6032 sbcl
= NCR53c7x0_read8 (SBCL_REG
);
6035 printk ("scsi%d : DCMD|DBC=0x%x, DNAD=0x%x (virt 0x%p)\n"
6036 " DSA=0x%lx (virt 0x%p)\n"
6037 " DSPS=0x%x, TEMP=0x%x (virt 0x%p), DMODE=0x%x\n"
6038 " SXFER=0x%x, SCNTL3=0x%x\n"
6039 " %s%s%sphase=%s, %d bytes in SCSI FIFO\n"
6041 host
->host_no
, dbc_dcmd
, NCR53c7x0_read32(DNAD_REG
),
6042 bus_to_virt(NCR53c7x0_read32(DNAD_REG
)),
6043 virt_to_bus(dsa
), dsa
,
6044 NCR53c7x0_read32(DSPS_REG
), NCR53c7x0_read32(TEMP_REG
),
6045 bus_to_virt (NCR53c7x0_read32(TEMP_REG
)),
6046 (int) NCR53c7x0_read8(hostdata
->dmode
),
6047 (int) NCR53c7x0_read8(SXFER_REG
),
6048 (int) NCR53c7x0_read8(SCNTL3_REG_800
),
6049 (sbcl
& SBCL_BSY
) ? "BSY " : "",
6050 (sbcl
& SBCL_SEL
) ? "SEL " : "",
6051 (sbcl
& SBCL_REQ
) ? "REQ " : "",
6052 sstat2_to_phase(NCR53c7x0_read8 (((hostdata
->chip
/ 100) == 8) ?
6053 SSTAT1_REG
: SSTAT2_REG
)),
6054 (NCR53c7x0_read8 ((hostdata
->chip
/ 100) == 8 ?
6055 SSTAT1_REG
: SSTAT2_REG
) & SSTAT2_FF_MASK
) >> SSTAT2_FF_SHIFT
,
6056 NCR53c7x0_read8 (STEST0_REG_800
));
6057 printk ("scsi%d : DSP 0x%lx (virt 0x%p) ->\n", host
->host_no
,
6058 virt_to_bus(dsp
), dsp
);
6059 for (i
= 6; i
> 0; --i
, dsp
+= size
)
6060 size
= print_insn (host
, dsp
, "", 1);
6061 if (NCR53c7x0_read8 (SCNTL1_REG
) & SCNTL1_CON
) {
6062 printk ("scsi%d : connected (SDID=0x%x, SSID=0x%x)\n",
6063 host
->host_no
, NCR53c7x0_read8 (SDID_REG_800
),
6064 NCR53c7x0_read8 (SSID_REG_800
));
6065 print_dsa (host
, dsa
, "");
6069 print_queues (host
);
6075 * Function : static int shutdown (struct Scsi_Host *host)
6077 * Purpose : does a clean (we hope) shutdown of the NCR SCSI
6078 * chip. Use prior to dumping core, unloading the NCR driver,
6080 * Returns : 0 on success
6083 shutdown (struct Scsi_Host
*host
) {
6084 NCR53c7x0_local_declare();
6085 unsigned long flags
;
6086 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
6088 NCR53c7x0_local_setup(host
);
6091 /* Get in a state where we can reset the SCSI bus */
6093 ncr_scsi_reset (host
);
6094 hostdata
->soft_reset(host
);
6097 restore_flags (flags
);
6102 * Function : void ncr_scsi_reset (struct Scsi_Host *host)
6104 * Purpose : reset the SCSI bus.
6108 ncr_scsi_reset (struct Scsi_Host
*host
) {
6109 NCR53c7x0_local_declare();
6110 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
6112 unsigned long flags
;
6114 NCR53c7x0_local_setup(host
);
6117 if ((hostdata
->chip
/ 100) == 8) {
6118 sien
= NCR53c7x0_read8(SIEN0_REG_800
);
6119 NCR53c7x0_write8(SIEN0_REG_800
, sien
& ~SIEN_RST
);
6121 NCR53c7x0_write8(SCNTL1_REG
, SCNTL1_RST
);
6122 udelay(25); /* Minimum amount of time to assert RST */
6123 NCR53c7x0_write8(SCNTL1_REG
, 0);
6124 if ((hostdata
->chip
/ 100) == 8) {
6125 NCR53c7x0_write8(SIEN0_REG_800
, sien
);
6127 restore_flags (flags
);
6131 * Function : void hard_reset (struct Scsi_Host *host)
6136 hard_reset (struct Scsi_Host
*host
) {
6137 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
6139 unsigned long flags
;
6142 ncr_scsi_reset(host
);
6143 NCR53c7x0_driver_init (host
);
6144 if (hostdata
->soft_reset
)
6145 hostdata
->soft_reset (host
);
6146 restore_flags(flags
);
6151 * Function : Scsi_Cmnd *return_outstanding_commands (struct Scsi_Host *host,
6152 * int free, int issue)
6154 * Purpose : return a linked list (using the SCp.buffer field as next,
6155 * so we don't perturb hostdata. We don't use a field of the
6156 * NCR53c7x0_cmd structure since we may not have allocated one
6157 * for the command causing the reset.) of Scsi_Cmnd structures that
6158 * had propagated below the Linux issue queue level. If free is set,
6159 * free the NCR53c7x0_cmd structures which are associated with
6160 * the Scsi_Cmnd structures, and clean up any internal
6161 * NCR lists that the commands were on. If issue is set,
6162 * also return commands in the issue queue.
6164 * Returns : linked list of commands
6166 * NOTE : the caller should insure that the NCR chip is halted
6167 * if the free flag is set.
6171 return_outstanding_commands (struct Scsi_Host
*host
, int free
, int issue
) {
6172 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
6174 struct NCR53c7x0_cmd
*c
;
6177 Scsi_Cmnd
*list
= NULL
, *tmp
;
6178 for (c
= (struct NCR53c7x0_cmd
*) hostdata
->running_list
; c
;
6179 c
= (struct NCR53c7x0_cmd
*) c
->next
) {
6180 if (c
->cmd
->SCp
.buffer
) {
6181 printk ("scsi%d : loop detected in running list!\n", host
->host_no
);
6184 printk ("The sti() implicit in a printk() prevents hangs\n");
6188 c
->cmd
->SCp
.buffer
= (struct scatterlist
*) list
;
6191 c
->next
= hostdata
->free
;
6197 for (i
= 0, curr
= (u32
*) hostdata
->schedule
;
6198 i
< host
->can_queue
; ++i
, curr
+= 2) {
6199 curr
[0] = hostdata
->NOP_insn
;
6200 curr
[1] = le32_to_cpu(0xdeadbeef);
6202 hostdata
->curr
= NULL
;
6206 for (tmp
= (Scsi_Cmnd
*) hostdata
->issue_queue
; tmp
; tmp
= tmp
->next
) {
6207 if (tmp
->SCp
.buffer
) {
6208 printk ("scsi%d : loop detected in issue queue!\n",
6212 tmp
->SCp
.buffer
= (struct scatterlist
*) list
;
6216 hostdata
->issue_queue
= NULL
;
6223 * Function : static int disable (struct Scsi_Host *host)
6225 * Purpose : disables the given NCR host, causing all commands
6226 * to return a driver error. Call this so we can unload the
6227 * module during development and try again. Eventually,
6228 * we should be able to find clean workarounds for these
6231 * Inputs : host - hostadapter to twiddle
6233 * Returns : 0 on success.
6237 disable (struct Scsi_Host
*host
) {
6238 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
6240 unsigned long flags
;
6241 Scsi_Cmnd
*nuke_list
, *tmp
;
6244 if (hostdata
->state
!= STATE_HALTED
)
6246 nuke_list
= return_outstanding_commands (host
, 1 /* free */, 1 /* issue */);
6248 hostdata
->state
= STATE_DISABLED
;
6249 restore_flags(flags
);
6250 printk ("scsi%d : nuking commands\n", host
->host_no
);
6251 for (; nuke_list
; nuke_list
= tmp
) {
6252 tmp
= (Scsi_Cmnd
*) nuke_list
->SCp
.buffer
;
6253 nuke_list
->result
= DID_ERROR
<< 16;
6254 nuke_list
->scsi_done(nuke_list
);
6256 printk ("scsi%d : done. \n", host
->host_no
);
6257 printk (KERN_ALERT
"scsi%d : disabled. Unload and reload\n",
6263 * Function : static int ncr_halt (struct Scsi_Host *host)
6265 * Purpose : halts the SCSI SCRIPTS(tm) processor on the NCR chip
6267 * Inputs : host - SCSI chip to halt
6269 * Returns : 0 on success
6273 ncr_halt (struct Scsi_Host
*host
) {
6274 NCR53c7x0_local_declare();
6275 unsigned long flags
;
6276 unsigned char istat
, tmp
;
6277 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
6280 NCR53c7x0_local_setup(host
);
6284 /* Stage 0 : eat all interrupts
6286 Stage 2 : eat all but abort interrupts
6287 Stage 3 : eat all interrupts
6291 NCR53c7x0_write8(hostdata
->istat
, ISTAT_ABRT
);
6294 istat
= NCR53c7x0_read8 (hostdata
->istat
);
6295 if (istat
& ISTAT_SIP
) {
6296 if ((hostdata
->chip
/ 100) == 8) {
6297 tmp
= NCR53c7x0_read8(SIST0_REG_800
);
6299 tmp
= NCR53c7x0_read8(SIST1_REG_800
);
6301 tmp
= NCR53c7x0_read8(SSTAT0_REG
);
6303 } else if (istat
& ISTAT_DIP
) {
6304 tmp
= NCR53c7x0_read8(DSTAT_REG
);
6306 if (tmp
& DSTAT_ABRT
) {
6307 NCR53c7x0_write8(hostdata
->istat
, 0);
6310 printk(KERN_ALERT
"scsi%d : could not halt NCR chip\n",
6316 if (!(istat
& (ISTAT_SIP
|ISTAT_DIP
)))
6319 else if (stage
== 3)
6322 hostdata
->state
= STATE_HALTED
;
6323 restore_flags(flags
);
6331 * Function: event_name (int event)
6333 * Purpose: map event enum into user-readable strings.
6337 event_name (int event
) {
6339 case EVENT_NONE
: return "none";
6340 case EVENT_ISSUE_QUEUE
: return "to issue queue";
6341 case EVENT_START_QUEUE
: return "to start queue";
6342 case EVENT_SELECT
: return "selected";
6343 case EVENT_DISCONNECT
: return "disconnected";
6344 case EVENT_RESELECT
: return "reselected";
6345 case EVENT_COMPLETE
: return "completed";
6346 case EVENT_IDLE
: return "idle";
6347 case EVENT_SELECT_FAILED
: return "select failed";
6348 case EVENT_BEFORE_SELECT
: return "before select";
6349 case EVENT_RESELECT_FAILED
: return "reselect failed";
6350 default: return "unknown";
6355 * Function : void dump_events (struct Scsi_Host *host, count)
6357 * Purpose : print last count events which have occurred.
6360 dump_events (struct Scsi_Host
*host
, int count
) {
6361 struct NCR53c7x0_hostdata
*hostdata
= (struct NCR53c7x0_hostdata
*)
6363 struct NCR53c7x0_event event
;
6365 unsigned long flags
;
6366 if (hostdata
->events
) {
6367 if (count
> hostdata
->event_size
)
6368 count
= hostdata
->event_size
;
6369 for (i
= hostdata
->event_index
; count
> 0;
6370 i
= (i
? i
- 1 : hostdata
->event_size
-1), --count
) {
6373 * By copying the event we're currently examining with interrupts
6374 * disabled, we can do multiple printk(), etc. operations and
6375 * still be guaranteed that they're happening on the same
6380 event
= hostdata
->events
[i
];
6382 memcpy ((void *) &event
, (void *) &(hostdata
->events
[i
]),
6386 restore_flags(flags
);
6387 printk ("scsi%d : %s event %d at %ld secs %ld usecs target %d lun %d\n",
6388 host
->host_no
, event_name (event
.event
), count
,
6389 (long) event
.time
.tv_sec
, (long) event
.time
.tv_usec
,
6390 event
.target
, event
.lun
);
6392 printk (" event for dsa 0x%lx (virt 0x%p)\n",
6393 virt_to_bus(event
.dsa
), event
.dsa
);
6394 if (event
.pid
!= -1) {
6395 printk (" event for pid %ld ", event
.pid
);
6396 print_command (event
.cmnd
);
6403 * Function: check_address
6405 * Purpose: Check to see if a possibly corrupt pointer will fault the
6408 * Inputs: addr - address; size - size of area
6410 * Returns: 0 if area is OK, -1 on error.
6412 * NOTES: should be implemented in terms of vverify on kernels
6417 check_address (unsigned long addr
, int size
) {
6418 return (MAP_NR(addr
) < 1 || MAP_NR(addr
+ size
) > MAP_NR(high_memory
) ?
6424 NCR53c7x0_release(struct Scsi_Host
*host
) {
6425 struct NCR53c7x0_hostdata
*hostdata
=
6426 (struct NCR53c7x0_hostdata
*) host
->hostdata
;
6427 struct NCR53c7x0_cmd
*cmd
, *tmp
;
6429 if (host
->irq
!= IRQ_NONE
)
6432 struct Scsi_Host
*tmp
;
6433 for (irq_count
= 0, tmp
= first_host
; tmp
; tmp
= tmp
->next
)
6434 if (tmp
->hostt
== the_template
&& tmp
->irq
== host
->irq
)
6437 free_irq(host
->irq
, NULL
);
6439 if (host
->dma_channel
!= DMA_NONE
)
6440 free_dma(host
->dma_channel
);
6442 release_region(host
->io_port
, host
->n_io_port
);
6444 for (cmd
= (struct NCR53c7x0_cmd
*) hostdata
->free
; cmd
; cmd
= tmp
,
6445 --hostdata
->num_cmds
) {
6446 tmp
= (struct NCR53c7x0_cmd
*) cmd
->next
;
6448 * If we're going to loop, try to stop it to get a more accurate
6449 * count of the leaked commands.
6453 cmd
->free ((void *) cmd
->real
, cmd
->size
);
6455 if (hostdata
->num_cmds
)
6456 printk ("scsi%d : leaked %d NCR53c7x0_cmd structures\n",
6457 host
->host_no
, hostdata
->num_cmds
);
6458 if (hostdata
->events
)
6459 vfree ((void *)hostdata
->events
);
6462 Scsi_Host_Template driver_template
= NCR53c7xx
;
6463 #include "scsi_module.c"
6464 #endif /* def MODULE */