1 /******************************************************************************
2 ** Device driver for the PCI-SCSI NCR538XX controller family.
4 ** Copyright (C) 1994 Wolfgang Stanglmeier
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 **-----------------------------------------------------------------------------
22 ** This driver has been ported to Linux from the FreeBSD NCR53C8XX driver
23 ** and is currently maintained by
25 ** Gerard Roudier <groudier@free.fr>
27 ** Being given that this driver originates from the FreeBSD version, and
28 ** in order to keep synergy on both, any suggested enhancements and corrections
29 ** received on Linux are automatically a potential candidate for the FreeBSD
32 ** The original driver has been written for 386bsd and FreeBSD by
33 ** Wolfgang Stanglmeier <wolf@cologne.de>
34 ** Stefan Esser <se@mi.Uni-Koeln.de>
36 ** And has been ported to NetBSD by
37 ** Charles M. Hannum <mycroft@gnu.ai.mit.edu>
39 **-----------------------------------------------------------------------------
43 ** December 10 1995 by Gerard Roudier:
44 ** Initial port to Linux.
46 ** June 23 1996 by Gerard Roudier:
47 ** Support for 64 bits architectures (Alpha).
49 ** November 30 1996 by Gerard Roudier:
50 ** Support for Fast-20 scsi.
51 ** Support for large DMA fifo and 128 dwords bursting.
53 ** February 27 1997 by Gerard Roudier:
54 ** Support for Fast-40 scsi.
55 ** Support for on-Board RAM.
57 ** May 3 1997 by Gerard Roudier:
58 ** Full support for scsi scripts instructions pre-fetching.
60 ** May 19 1997 by Richard Waltham <dormouse@farsrobt.demon.co.uk>:
61 ** Support for NvRAM detection and reading.
63 ** August 18 1997 by Cort <cort@cs.nmt.edu>:
64 ** Support for Power/PC (Big Endian).
66 ** June 20 1998 by Gerard Roudier
67 ** Support for up to 64 tags per lun.
68 ** O(1) everywhere (C and SCRIPTS) for normal cases.
69 ** Low PCI traffic for command handling when on-chip RAM is present.
70 ** Aggressive SCSI SCRIPTS optimizations.
72 *******************************************************************************
76 ** Supported SCSI-II features:
77 ** Synchronous negotiation
78 ** Wide negotiation (depends on the NCR Chip)
79 ** Enable disconnection
80 ** Tagged command queuing
84 ** Supported NCR/SYMBIOS chips:
85 ** 53C720 (Wide, Fast SCSI-2, intfly problems)
86 ** 53C810 (8 bits, Fast SCSI-2, no rom BIOS)
87 ** 53C815 (8 bits, Fast SCSI-2, on board rom BIOS)
88 ** 53C820 (Wide, Fast SCSI-2, no rom BIOS)
89 ** 53C825 (Wide, Fast SCSI-2, on board rom BIOS)
90 ** 53C860 (8 bits, Fast 20, no rom BIOS)
91 ** 53C875 (Wide, Fast 20, on board rom BIOS)
92 ** 53C895 (Wide, Fast 40, on board rom BIOS)
93 ** 53C895A (Wide, Fast 40, on board rom BIOS)
94 ** 53C896 (Wide, Fast 40, on board rom BIOS)
95 ** 53C897 (Wide, Fast 40, on board rom BIOS)
96 ** 53C1510D (Wide, Fast 40, on board rom BIOS)
99 ** Memory mapped IO (linux-1.3.X and above only)
101 ** Shared IRQ (since linux-1.3.72)
105 ** Name and version of the driver
107 #define SCSI_NCR_DRIVER_NAME "ncr53c8xx-3.4.3b-20010512"
109 #define SCSI_NCR_DEBUG_FLAGS (0)
111 /*==========================================================
115 **==========================================================
118 #include <linux/version.h>
120 #include <linux/module.h>
123 #include <asm/system.h>
124 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,17)
125 #include <linux/spinlock.h>
126 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
127 #include <asm/spinlock.h>
129 #include <linux/delay.h>
130 #include <linux/signal.h>
131 #include <linux/sched.h>
132 #include <linux/errno.h>
133 #include <linux/pci.h>
134 #include <linux/dma-mapping.h>
135 #include <linux/interrupt.h>
136 #include <linux/string.h>
137 #include <linux/mm.h>
138 #include <linux/ioport.h>
139 #include <linux/time.h>
140 #include <linux/timer.h>
141 #include <linux/stat.h>
143 #include <linux/blk.h>
145 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,35)
146 #include <linux/init.h>
156 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,1,92)
157 #include <linux/bios32.h>
163 #include <linux/types.h>
166 ** Define BITS_PER_LONG for earlier linux versions.
168 #ifndef BITS_PER_LONG
169 #if (~0UL) == 0xffffffffUL
170 #define BITS_PER_LONG 32
172 #define BITS_PER_LONG 64
176 #include "ncr53c8xx.h"
179 ** Donnot compile integrity checking code for Linux-2.3.0
180 ** and above since SCSI data structures are not ready yet.
182 /* #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */
184 #define SCSI_NCR_INTEGRITY_CHECKING
187 #define NAME53C "ncr53c"
188 #define NAME53C8XX "ncr53c8xx"
189 #define DRIVER_SMP_LOCK ncr53c8xx_lock
191 #include "sym53c8xx_comm.h"
193 int ncr53c8xx_slave_configure(Scsi_Device
*device
);
194 int ncr53c8xx_bus_reset(Scsi_Cmnd
*cmd
);
195 int ncr53c8xx_queue_command (Scsi_Cmnd
*cmd
, void (* done
)(Scsi_Cmnd
*));
196 const char *ncr53c8xx_info (struct Scsi_Host
*host
);
199 /*==========================================================
201 ** The CCB done queue uses an array of CCB virtual
202 ** addresses. Empty entries are flagged using the bogus
203 ** virtual address 0xffffffff.
205 ** Since PCI ensures that only aligned DWORDs are accessed
206 ** atomically, 64 bit little-endian architecture requires
207 ** to test the high order DWORD of the entry to determine
208 ** if it is empty or valid.
210 ** BTW, I will make things differently as soon as I will
211 ** have a better idea, but this is simple and should work.
213 **==========================================================
216 #define SCSI_NCR_CCB_DONE_SUPPORT
217 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
220 #define CCB_DONE_EMPTY 0xffffffffUL
222 /* All 32 bit architectures */
223 #if BITS_PER_LONG == 32
224 #define CCB_DONE_VALID(cp) (((u_long) cp) != CCB_DONE_EMPTY)
226 /* All > 32 bit (64 bit) architectures regardless endian-ness */
228 #define CCB_DONE_VALID(cp) \
229 ((((u_long) cp) & 0xffffffff00000000ul) && \
230 (((u_long) cp) & 0xfffffffful) != CCB_DONE_EMPTY)
233 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
235 /*==========================================================
237 ** Configuration and Debugging
239 **==========================================================
243 ** SCSI address of this device.
244 ** The boot routines should have set it.
248 #ifndef SCSI_NCR_MYADDR
249 #define SCSI_NCR_MYADDR (7)
253 ** The maximum number of tags per logic unit.
254 ** Used only for disk devices that support tags.
257 #ifndef SCSI_NCR_MAX_TAGS
258 #define SCSI_NCR_MAX_TAGS (8)
262 ** TAGS are actually limited to 64 tags/lun.
263 ** We need to deal with power of 2, for alignment constraints.
265 #if SCSI_NCR_MAX_TAGS > 64
266 #define MAX_TAGS (64)
268 #define MAX_TAGS SCSI_NCR_MAX_TAGS
274 ** Choose appropriate type for tag bitmap.
277 typedef u_int64 tagmap_t
;
279 typedef u_int32 tagmap_t
;
283 ** Number of targets supported by the driver.
284 ** n permits target numbers 0..n-1.
285 ** Default is 16, meaning targets #0..#15.
289 #ifdef SCSI_NCR_MAX_TARGET
290 #define MAX_TARGET (SCSI_NCR_MAX_TARGET)
292 #define MAX_TARGET (16)
296 ** Number of logic units supported by the driver.
297 ** n enables logic unit numbers 0..n-1.
298 ** The common SCSI devices require only
299 ** one lun, so take 1 as the default.
302 #ifdef SCSI_NCR_MAX_LUN
303 #define MAX_LUN SCSI_NCR_MAX_LUN
309 ** Asynchronous pre-scaler (ns). Shall be 40
312 #ifndef SCSI_NCR_MIN_ASYNC
313 #define SCSI_NCR_MIN_ASYNC (40)
317 ** The maximum number of jobs scheduled for starting.
318 ** There should be one slot per target, and one slot
319 ** for each tag of each target in use.
320 ** The calculation below is actually quite silly ...
323 #ifdef SCSI_NCR_CAN_QUEUE
324 #define MAX_START (SCSI_NCR_CAN_QUEUE + 4)
326 #define MAX_START (MAX_TARGET + 7 * MAX_TAGS)
330 ** We limit the max number of pending IO to 250.
331 ** since we donnot want to allocate more than 1
332 ** PAGE for 'scripth'.
336 #define MAX_START 250
340 ** The maximum number of segments a transfer is split into.
341 ** We support up to 127 segments for both read and write.
342 ** The data scripts are broken into 2 sub-scripts.
343 ** 80 (MAX_SCATTERL) segments are moved from a sub-script
344 ** in on-chip RAM. This makes data transfers shorter than
345 ** 80k (assuming 1k fs) as fast as possible.
348 #define MAX_SCATTER (SCSI_NCR_MAX_SCATTER)
350 #if (MAX_SCATTER > 80)
351 #define MAX_SCATTERL 80
352 #define MAX_SCATTERH (MAX_SCATTER - MAX_SCATTERL)
354 #define MAX_SCATTERL (MAX_SCATTER-1)
355 #define MAX_SCATTERH 1
362 #define NCR_SNOOP_TIMEOUT (1000000)
365 ** Head of list of NCR boards
367 ** For kernel version < 1.3.70, host is retrieved by its irq level.
368 ** For later kernels, the internal host control block address
369 ** (struct ncb) is used as device id parameter of the irq stuff.
372 static struct Scsi_Host
*first_host
= NULL
;
373 static Scsi_Host_Template
*the_template
= NULL
;
379 #define ScsiResult(host_code, scsi_code) (((host_code) << 16) + ((scsi_code) & 0x7f))
381 static void ncr53c8xx_timeout(unsigned long np
);
382 static int ncr53c8xx_proc_info(struct Scsi_Host
*host
, char *buffer
, char **start
, off_t offset
,
383 int length
, int func
);
385 #define initverbose (driver_setup.verbose)
386 #define bootverbose (np->verbose)
388 #ifdef SCSI_NCR_NVRAM_SUPPORT
389 static u_char Tekram_sync
[16] __initdata
=
390 {25,31,37,43, 50,62,75,125, 12,15,18,21, 6,7,9,10};
391 #endif /* SCSI_NCR_NVRAM_SUPPORT */
393 /*==========================================================
395 ** Command control block states.
397 **==========================================================
402 #define HS_NEGOTIATE (2) /* sync/wide data transfer*/
403 #define HS_DISCONNECT (3) /* Disconnected by target */
405 #define HS_DONEMASK (0x80)
406 #define HS_COMPLETE (4|HS_DONEMASK)
407 #define HS_SEL_TIMEOUT (5|HS_DONEMASK) /* Selection timeout */
408 #define HS_RESET (6|HS_DONEMASK) /* SCSI reset */
409 #define HS_ABORTED (7|HS_DONEMASK) /* Transfer aborted */
410 #define HS_TIMEOUT (8|HS_DONEMASK) /* Software timeout */
411 #define HS_FAIL (9|HS_DONEMASK) /* SCSI or PCI bus errors */
412 #define HS_UNEXPECTED (10|HS_DONEMASK)/* Unexpected disconnect */
415 ** Invalid host status values used by the SCRIPTS processor
416 ** when the nexus is not fully identified.
417 ** Shall never appear in a CCB.
420 #define HS_INVALMASK (0x40)
421 #define HS_SELECTING (0|HS_INVALMASK)
422 #define HS_IN_RESELECT (1|HS_INVALMASK)
423 #define HS_STARTING (2|HS_INVALMASK)
426 ** Flags set by the SCRIPT processor for commands
427 ** that have been skipped.
429 #define HS_SKIPMASK (0x20)
431 /*==========================================================
433 ** Software Interrupt Codes
435 **==========================================================
438 #define SIR_BAD_STATUS (1)
439 #define SIR_XXXXXXXXXX (2)
440 #define SIR_NEGO_SYNC (3)
441 #define SIR_NEGO_WIDE (4)
442 #define SIR_NEGO_FAILED (5)
443 #define SIR_NEGO_PROTO (6)
444 #define SIR_REJECT_RECEIVED (7)
445 #define SIR_REJECT_SENT (8)
446 #define SIR_IGN_RESIDUE (9)
447 #define SIR_MISSING_SAVE (10)
448 #define SIR_RESEL_NO_MSG_IN (11)
449 #define SIR_RESEL_NO_IDENTIFY (12)
450 #define SIR_RESEL_BAD_LUN (13)
451 #define SIR_RESEL_BAD_TARGET (14)
452 #define SIR_RESEL_BAD_I_T_L (15)
453 #define SIR_RESEL_BAD_I_T_L_Q (16)
454 #define SIR_DONE_OVERFLOW (17)
455 #define SIR_INTFLY (18)
458 /*==========================================================
460 ** Extended error codes.
461 ** xerr_status field of struct ccb.
463 **==========================================================
467 #define XE_EXTRA_DATA (1) /* unexpected data phase */
468 #define XE_BAD_PHASE (2) /* illegal phase (4/5) */
470 /*==========================================================
472 ** Negotiation status.
473 ** nego_status field of struct ccb.
475 **==========================================================
478 #define NS_NOCHANGE (0)
483 /*==========================================================
485 ** "Special features" of targets.
486 ** quirks field of struct tcb.
487 ** actualquirks field of struct ccb.
489 **==========================================================
492 #define QUIRK_AUTOSAVE (0x01)
493 #define QUIRK_NOMSG (0x02)
494 #define QUIRK_NOSYNC (0x10)
495 #define QUIRK_NOWIDE16 (0x20)
497 /*==========================================================
499 ** Capability bits in Inquire response byte 7.
501 **==========================================================
504 #define INQ7_QUEUE (0x02)
505 #define INQ7_SYNC (0x10)
506 #define INQ7_WIDE16 (0x20)
508 /*==========================================================
512 **==========================================================
515 #define CCB_MAGIC (0xf2691ad2)
517 /*==========================================================
519 ** Declaration of structs.
521 **==========================================================
530 typedef struct ncb
* ncb_p
;
531 typedef struct tcb
* tcb_p
;
532 typedef struct lcb
* lcb_p
;
533 typedef struct ccb
* ccb_p
;
547 #define UC_SETSYNC 10
548 #define UC_SETTAGS 11
549 #define UC_SETDEBUG 12
550 #define UC_SETORDER 13
551 #define UC_SETWIDE 14
552 #define UC_SETFLAG 15
553 #define UC_SETVERBOSE 17
555 #define UF_TRACE (0x01)
556 #define UF_NODISC (0x02)
557 #define UF_NOSCAN (0x04)
559 /*========================================================================
561 ** Declaration of structs: target control block
563 **========================================================================
566 /*----------------------------------------------------------------
567 ** During reselection the ncr jumps to this point with SFBR
568 ** set to the encoded target number with bit 7 set.
569 ** if it's not this target, jump to the next.
571 ** JUMP IF (SFBR != #target#), @(next tcb)
572 **----------------------------------------------------------------
574 struct link jump_tcb
;
576 /*----------------------------------------------------------------
577 ** Load the actual values for the sxfer and the scntl3
578 ** register (sync/wide mode).
580 ** SCR_COPY (1), @(sval field of this tcb), @(sxfer register)
581 ** SCR_COPY (1), @(wval field of this tcb), @(scntl3 register)
582 **----------------------------------------------------------------
586 /*----------------------------------------------------------------
587 ** Get the IDENTIFY message and load the LUN to SFBR.
590 **----------------------------------------------------------------
592 struct link call_lun
;
594 /*----------------------------------------------------------------
595 ** Now look for the right lun.
598 ** SCR_JUMP ^ IFTRUE(MASK(i, 3)), @(first lcb mod. i)
600 ** Recent chips will prefetch the 4 JUMPS using only 1 burst.
601 ** It is kind of hashcoding.
602 **----------------------------------------------------------------
604 struct link jump_lcb
[4]; /* JUMPs for reselection */
605 lcb_p lp
[MAX_LUN
]; /* The lcb's of this tcb */
606 u_char inq_done
; /* Target capabilities received */
607 u_char inq_byte7
; /* Contains these capabilities */
609 /*----------------------------------------------------------------
610 ** Pointer to the ccb used for negotiation.
611 ** Prevent from starting a negotiation for all queued commands
612 ** when tagged command queuing is enabled.
613 **----------------------------------------------------------------
617 /*----------------------------------------------------------------
619 **----------------------------------------------------------------
624 /*----------------------------------------------------------------
625 ** negotiation of wide and synch transfer and device quirks.
626 **----------------------------------------------------------------
628 #ifdef SCSI_NCR_BIG_ENDIAN
629 /*0*/ u_short period
;
631 /*3*/ u_char minsync
;
633 /*1*/ u_char widedone
;
635 /*3*/ u_char maxoffs
;
637 /*0*/ u_char minsync
;
639 /*2*/ u_short period
;
640 /*0*/ u_char maxoffs
;
642 /*2*/ u_char widedone
;
646 #ifdef SCSI_NCR_INTEGRITY_CHECKING
649 u_char ic_maximums_set
;
653 /*----------------------------------------------------------------
654 ** User settable limits and options.
655 ** These limits are read from the NVRAM if present.
656 **----------------------------------------------------------------
664 /*========================================================================
666 ** Declaration of structs: lun control block
668 **========================================================================
671 /*----------------------------------------------------------------
672 ** During reselection the ncr jumps to this point
673 ** with SFBR set to the "Identify" message.
674 ** if it's not this lun, jump to the next.
676 ** JUMP IF (SFBR != #lun#), @(next lcb of this target)
678 ** It is this lun. Load TEMP with the nexus jumps table
679 ** address and jump to RESEL_TAG (or RESEL_NOTAG).
681 ** SCR_COPY (4), p_jump_ccb, TEMP,
682 ** SCR_JUMP, <RESEL_TAG>
683 **----------------------------------------------------------------
685 struct link jump_lcb
;
686 ncrcmd load_jump_ccb
[3];
687 struct link jump_tag
;
688 ncrcmd p_jump_ccb
; /* Jump table bus address */
690 /*----------------------------------------------------------------
691 ** Jump table used by the script processor to directly jump
692 ** to the CCB corresponding to the reselected nexus.
693 ** Address is allocated on 256 bytes boundary in order to
694 ** allow 8 bit calculation of the tag jump entry for up to
696 **----------------------------------------------------------------
698 u_int32 jump_ccb_0
; /* Default table if no tags */
699 u_int32
*jump_ccb
; /* Virtual address */
701 /*----------------------------------------------------------------
702 ** CCB queue management.
703 **----------------------------------------------------------------
705 XPT_QUEHEAD free_ccbq
; /* Queue of available CCBs */
706 XPT_QUEHEAD busy_ccbq
; /* Queue of busy CCBs */
707 XPT_QUEHEAD wait_ccbq
; /* Queue of waiting for IO CCBs */
708 XPT_QUEHEAD skip_ccbq
; /* Queue of skipped CCBs */
709 u_char actccbs
; /* Number of allocated CCBs */
710 u_char busyccbs
; /* CCBs busy for this lun */
711 u_char queuedccbs
; /* CCBs queued to the controller*/
712 u_char queuedepth
; /* Queue depth for this lun */
713 u_char scdev_depth
; /* SCSI device queue depth */
714 u_char maxnxs
; /* Max possible nexuses */
716 /*----------------------------------------------------------------
717 ** Control of tagged command queuing.
718 ** Tags allocation is performed using a circular buffer.
719 ** This avoids using a loop for tag allocation.
720 **----------------------------------------------------------------
722 u_char ia_tag
; /* Allocation index */
723 u_char if_tag
; /* Freeing index */
724 u_char cb_tags
[MAX_TAGS
]; /* Circular tags buffer */
725 u_char usetags
; /* Command queuing is active */
726 u_char maxtags
; /* Max nr of tags asked by user */
727 u_char numtags
; /* Current number of tags */
728 u_char inq_byte7
; /* Store unit CmdQ capabitility */
730 /*----------------------------------------------------------------
731 ** QUEUE FULL control and ORDERED tag control.
732 **----------------------------------------------------------------
734 /*----------------------------------------------------------------
735 ** QUEUE FULL and ORDERED tag control.
736 **----------------------------------------------------------------
738 u_short num_good
; /* Nr of GOOD since QUEUE FULL */
739 tagmap_t tags_umap
; /* Used tags bitmap */
740 tagmap_t tags_smap
; /* Tags in use at 'tag_stime' */
741 u_long tags_stime
; /* Last time we set smap=umap */
742 ccb_p held_ccb
; /* CCB held for QUEUE FULL */
745 /*========================================================================
747 ** Declaration of structs: the launch script.
749 **========================================================================
751 ** It is part of the CCB and is called by the scripts processor to
752 ** start or restart the data structure (nexus).
753 ** This 6 DWORDs mini script makes use of prefetching.
755 **------------------------------------------------------------------------
758 /*----------------------------------------------------------------
759 ** SCR_COPY(4), @(p_phys), @(dsa register)
760 ** SCR_JUMP, @(scheduler_point)
761 **----------------------------------------------------------------
763 ncrcmd setup_dsa
[3]; /* Copy 'phys' address to dsa */
764 struct link schedule
; /* Jump to scheduler point */
765 ncrcmd p_phys
; /* 'phys' header bus address */
768 /*========================================================================
770 ** Declaration of structs: global HEADER.
772 **========================================================================
774 ** This substructure is copied from the ccb to a global address after
775 ** selection (or reselection) and copied back before disconnect.
777 ** These fields are accessible to the script processor.
779 **------------------------------------------------------------------------
783 /*----------------------------------------------------------------
784 ** Saved data pointer.
785 ** Points to the position in the script responsible for the
786 ** actual transfer transfer of data.
787 ** It's written after reception of a SAVE_DATA_POINTER message.
788 ** The goalpointer points after the last transfer command.
789 **----------------------------------------------------------------
795 /*----------------------------------------------------------------
796 ** Alternate data pointer.
797 ** They are copied back to savep/lastp/goalp by the SCRIPTS
798 ** when the direction is unknown and the device claims data out.
799 **----------------------------------------------------------------
804 /*----------------------------------------------------------------
805 ** The virtual address of the ccb containing this header.
806 **----------------------------------------------------------------
810 /*----------------------------------------------------------------
812 **----------------------------------------------------------------
814 u_char scr_st
[4]; /* script status */
815 u_char status
[4]; /* host status. must be the */
816 /* last DWORD of the header. */
820 ** The status bytes are used by the host and the script processor.
822 ** The byte corresponding to the host_status must be stored in the
823 ** last DWORD of the CCB header since it is used for command
824 ** completion (ncr_wakeup()). Doing so, we are sure that the header
825 ** has been entirely copied back to the CCB when the host_status is
826 ** seen complete by the CPU.
828 ** The last four bytes (status[4]) are copied to the scratchb register
829 ** (declared as scr0..scr3 in ncr_reg.h) just after the select/reselect,
830 ** and copied back just after disconnecting.
831 ** Inside the script the XX_REG are used.
833 ** The first four bytes (scr_st[4]) are used inside the script by
835 ** Because source and destination must have the same alignment
836 ** in a DWORD, the fields HAVE to be at the choosen offsets.
837 ** xerr_st 0 (0x34) scratcha
838 ** sync_st 1 (0x05) sxfer
839 ** wide_st 3 (0x03) scntl3
843 ** Last four bytes (script)
847 #define HS_PRT nc_scr1
849 #define SS_PRT nc_scr2
853 ** Last four bytes (host)
855 #ifdef SCSI_NCR_BIG_ENDIAN
856 #define actualquirks phys.header.status[3]
857 #define host_status phys.header.status[2]
858 #define scsi_status phys.header.status[1]
859 #define parity_status phys.header.status[0]
861 #define actualquirks phys.header.status[0]
862 #define host_status phys.header.status[1]
863 #define scsi_status phys.header.status[2]
864 #define parity_status phys.header.status[3]
868 ** First four bytes (script)
870 #define xerr_st header.scr_st[0]
871 #define sync_st header.scr_st[1]
872 #define nego_st header.scr_st[2]
873 #define wide_st header.scr_st[3]
876 ** First four bytes (host)
878 #define xerr_status phys.xerr_st
879 #define nego_status phys.nego_st
882 #define sync_status phys.sync_st
883 #define wide_status phys.wide_st
886 /*==========================================================
888 ** Declaration of structs: Data structure block
890 **==========================================================
892 ** During execution of a ccb by the script processor,
893 ** the DSA (data structure address) register points
894 ** to this substructure of the ccb.
895 ** This substructure contains the header with
896 ** the script-processor-changable data and
897 ** data blocks for the indirect move commands.
899 **----------------------------------------------------------
911 ** Table data for Script
914 struct scr_tblsel select
;
915 struct scr_tblmove smsg
;
916 struct scr_tblmove cmd
;
917 struct scr_tblmove sense
;
918 struct scr_tblmove data
[MAX_SCATTER
];
922 /*========================================================================
924 ** Declaration of structs: Command control block.
926 **========================================================================
929 /*----------------------------------------------------------------
930 ** This is the data structure which is pointed by the DSA
931 ** register when it is executed by the script processor.
932 ** It must be the first entry because it contains the header
933 ** as first entry that must be cache line aligned.
934 **----------------------------------------------------------------
938 /*----------------------------------------------------------------
939 ** Mini-script used at CCB execution start-up.
940 ** Load the DSA with the data structure address (phys) and
941 ** jump to SELECT. Jump to CANCEL if CCB is to be canceled.
942 **----------------------------------------------------------------
946 /*----------------------------------------------------------------
947 ** Mini-script used at CCB relection to restart the nexus.
948 ** Load the DSA with the data structure address (phys) and
949 ** jump to RESEL_DSA. Jump to ABORT if CCB is to be aborted.
950 **----------------------------------------------------------------
952 struct launch restart
;
954 /*----------------------------------------------------------------
955 ** If a data transfer phase is terminated too early
956 ** (after reception of a message (i.e. DISCONNECT)),
957 ** we have to prepare a mini script to transfer
958 ** the rest of the data.
959 **----------------------------------------------------------------
963 /*----------------------------------------------------------------
964 ** The general SCSI driver provides a
965 ** pointer to a control block.
966 **----------------------------------------------------------------
968 Scsi_Cmnd
*cmd
; /* SCSI command */
969 u_char cdb_buf
[16]; /* Copy of CDB */
970 u_char sense_buf
[64];
971 int data_len
; /* Total data length */
973 /*----------------------------------------------------------------
975 ** We prepare a message to be sent after selection.
976 ** We may use a second one if the command is rescheduled
977 ** due to GETCC or QFULL.
978 ** Contents are IDENTIFY and SIMPLE_TAG.
979 ** While negotiating sync or wide transfer,
980 ** a SDTR or WDTR message is appended.
981 **----------------------------------------------------------------
983 u_char scsi_smsg
[8];
984 u_char scsi_smsg2
[8];
986 /*----------------------------------------------------------------
988 **----------------------------------------------------------------
990 u_long p_ccb
; /* BUS address of this CCB */
991 u_char sensecmd
[6]; /* Sense command */
992 u_char tag
; /* Tag for this transfer */
993 /* 255 means no tag */
998 ccb_p link_ccb
; /* Host adapter CCB chain */
999 XPT_QUEHEAD link_ccbq
; /* Link to unit CCB queue */
1000 u_int32 startp
; /* Initial data pointer */
1001 u_long magic
; /* Free / busy CCB flag */
1004 #define CCB_PHYS(cp,lbl) (cp->p_ccb + offsetof(struct ccb, lbl))
1007 /*========================================================================
1009 ** Declaration of structs: NCR device descriptor
1011 **========================================================================
1014 /*----------------------------------------------------------------
1015 ** The global header.
1016 ** It is accessible to both the host and the script processor.
1017 ** Must be cache line size aligned (32 for x86) in order to
1018 ** allow cache line bursting when it is copied to/from CCB.
1019 **----------------------------------------------------------------
1023 /*----------------------------------------------------------------
1024 ** CCBs management queues.
1025 **----------------------------------------------------------------
1027 Scsi_Cmnd
*waiting_list
; /* Commands waiting for a CCB */
1028 /* when lcb is not allocated. */
1029 Scsi_Cmnd
*done_list
; /* Commands waiting for done() */
1030 /* callback to be invoked. */
1031 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
1032 spinlock_t smp_lock
; /* Lock for SMP threading */
1035 /*----------------------------------------------------------------
1036 ** Chip and controller indentification.
1037 **----------------------------------------------------------------
1039 int unit
; /* Unit number */
1040 char chip_name
[8]; /* Chip name */
1041 char inst_name
[16]; /* ncb instance name */
1043 /*----------------------------------------------------------------
1044 ** Initial value of some IO register bits.
1045 ** These values are assumed to have been set by BIOS, and may
1046 ** be used for probing adapter implementation differences.
1047 **----------------------------------------------------------------
1049 u_char sv_scntl0
, sv_scntl3
, sv_dmode
, sv_dcntl
, sv_ctest0
, sv_ctest3
,
1050 sv_ctest4
, sv_ctest5
, sv_gpcntl
, sv_stest2
, sv_stest4
;
1052 /*----------------------------------------------------------------
1053 ** Actual initial value of IO register bits used by the
1054 ** driver. They are loaded at initialisation according to
1055 ** features that are to be enabled.
1056 **----------------------------------------------------------------
1058 u_char rv_scntl0
, rv_scntl3
, rv_dmode
, rv_dcntl
, rv_ctest0
, rv_ctest3
,
1059 rv_ctest4
, rv_ctest5
, rv_stest2
;
1061 /*----------------------------------------------------------------
1062 ** Targets management.
1063 ** During reselection the ncr jumps to jump_tcb.
1064 ** The SFBR register is loaded with the encoded target id.
1066 ** SCR_JUMP ^ IFTRUE(MASK(i, 3)), @(next tcb mod. i)
1068 ** Recent chips will prefetch the 4 JUMPS using only 1 burst.
1069 ** It is kind of hashcoding.
1070 **----------------------------------------------------------------
1072 struct link jump_tcb
[4]; /* JUMPs for reselection */
1073 struct tcb target
[MAX_TARGET
]; /* Target data */
1075 /*----------------------------------------------------------------
1076 ** Virtual and physical bus addresses of the chip.
1077 **----------------------------------------------------------------
1079 vm_offset_t vaddr
; /* Virtual and bus address of */
1080 vm_offset_t paddr
; /* chip's IO registers. */
1081 vm_offset_t paddr2
; /* On-chip RAM bus address. */
1082 volatile /* Pointer to volatile for */
1083 struct ncr_reg
*reg
; /* memory mapped IO. */
1085 /*----------------------------------------------------------------
1086 ** SCRIPTS virtual and physical bus addresses.
1087 ** 'script' is loaded in the on-chip RAM if present.
1088 ** 'scripth' stays in main memory.
1089 **----------------------------------------------------------------
1091 struct script
*script0
; /* Copies of script and scripth */
1092 struct scripth
*scripth0
; /* relocated for this ncb. */
1093 struct scripth
*scripth
; /* Actual scripth virt. address */
1094 u_long p_script
; /* Actual script and scripth */
1095 u_long p_scripth
; /* bus addresses. */
1097 /*----------------------------------------------------------------
1098 ** General controller parameters and configuration.
1099 **----------------------------------------------------------------
1102 u_short device_id
; /* PCI device id */
1103 u_char revision_id
; /* PCI device revision id */
1104 u_char bus
; /* PCI BUS number */
1105 u_char device_fn
; /* PCI BUS device and function */
1106 u_long base_io
; /* IO space base address */
1107 u_int irq
; /* IRQ level */
1108 u_int features
; /* Chip features map */
1109 u_char myaddr
; /* SCSI id of the adapter */
1110 u_char maxburst
; /* log base 2 of dwords burst */
1111 u_char maxwide
; /* Maximum transfer width */
1112 u_char minsync
; /* Minimum sync period factor */
1113 u_char maxsync
; /* Maximum sync period factor */
1114 u_char maxoffs
; /* Max scsi offset */
1115 u_char multiplier
; /* Clock multiplier (1,2,4) */
1116 u_char clock_divn
; /* Number of clock divisors */
1117 u_long clock_khz
; /* SCSI clock frequency in KHz */
1119 /*----------------------------------------------------------------
1120 ** Start queue management.
1121 ** It is filled up by the host processor and accessed by the
1122 ** SCRIPTS processor in order to start SCSI commands.
1123 **----------------------------------------------------------------
1125 u_short squeueput
; /* Next free slot of the queue */
1126 u_short actccbs
; /* Number of allocated CCBs */
1127 u_short queuedccbs
; /* Number of CCBs in start queue*/
1128 u_short queuedepth
; /* Start queue depth */
1130 /*----------------------------------------------------------------
1132 **----------------------------------------------------------------
1134 struct timer_list timer
; /* Timer handler link header */
1136 u_long settle_time
; /* Resetting the SCSI BUS */
1138 /*----------------------------------------------------------------
1139 ** Debugging and profiling.
1140 **----------------------------------------------------------------
1142 struct ncr_reg regdump
; /* Register dump */
1143 u_long regtime
; /* Time it has been done */
1145 /*----------------------------------------------------------------
1146 ** Miscellaneous buffers accessed by the scripts-processor.
1147 ** They shall be DWORD aligned, because they may be read or
1148 ** written with a SCR_COPY script command.
1149 **----------------------------------------------------------------
1151 u_char msgout
[8]; /* Buffer for MESSAGE OUT */
1152 u_char msgin
[8]; /* Buffer for MESSAGE IN */
1153 u_int32 lastmsg
; /* Last SCSI message sent */
1154 u_char scratch
; /* Scratch for SCSI receive */
1156 /*----------------------------------------------------------------
1157 ** Miscellaneous configuration and status parameters.
1158 **----------------------------------------------------------------
1160 u_char disc
; /* Diconnection allowed */
1161 u_char scsi_mode
; /* Current SCSI BUS mode */
1162 u_char order
; /* Tag order to use */
1163 u_char verbose
; /* Verbosity for this controller*/
1164 int ncr_cache
; /* Used for cache test at init. */
1165 u_long p_ncb
; /* BUS address of this NCB */
1167 /*----------------------------------------------------------------
1168 ** Command completion handling.
1169 **----------------------------------------------------------------
1171 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
1172 struct ccb
*(ccb_done
[MAX_DONE
]);
1175 /*----------------------------------------------------------------
1176 ** Fields that should be removed or changed.
1177 **----------------------------------------------------------------
1179 struct ccb
*ccb
; /* Global CCB */
1180 struct usrcmd user
; /* Command from user */
1181 volatile u_char release_stage
; /* Synchronisation stage on release */
1183 #ifdef SCSI_NCR_INTEGRITY_CHECKING
1184 /*----------------------------------------------------------------
1185 ** Fields that are used for integrity check
1186 **----------------------------------------------------------------
1188 unsigned char check_integrity
; /* Enable midlayer integ.check on
1190 unsigned char check_integ_par
; /* Set if par or Init. Det. error
1191 * used only during integ check */
1195 #define NCB_SCRIPT_PHYS(np,lbl) (np->p_script + offsetof (struct script, lbl))
1196 #define NCB_SCRIPTH_PHYS(np,lbl) (np->p_scripth + offsetof (struct scripth,lbl))
1198 /*==========================================================
1201 ** Script for NCR-Processor.
1203 ** Use ncr_script_fill() to create the variable parts.
1204 ** Use ncr_script_copy_and_bind() to make a copy and
1205 ** bind to physical addresses.
1208 **==========================================================
1210 ** We have to know the offsets of all labels before
1211 ** we reach them (for forward jumps).
1212 ** Therefore we declare a struct here.
1213 ** If you make changes inside the script,
1214 ** DONT FORGET TO CHANGE THE LENGTHS HERE!
1216 **----------------------------------------------------------
1220 ** For HP Zalon/53c720 systems, the Zalon interface
1221 ** between CPU and 53c720 does prefetches, which causes
1222 ** problems with self modifying scripts. The problem
1223 ** is overcome by calling a dummy subroutine after each
1224 ** modification, to force a refetch of the script on
1225 ** return from the subroutine.
1228 #ifdef CONFIG_NCR53C8XX_PREFETCH
1229 #define PREFETCH_FLUSH_CNT 2
1230 #define PREFETCH_FLUSH SCR_CALL, PADDRH (wait_dma),
1232 #define PREFETCH_FLUSH_CNT 0
1233 #define PREFETCH_FLUSH
1237 ** Script fragments which are loaded into the on-chip RAM
1238 ** of 825A, 875 and 895 chips.
1242 ncrcmd startpos
[ 1];
1244 ncrcmd select2
[ 9 + PREFETCH_FLUSH_CNT
];
1245 ncrcmd loadpos
[ 4];
1246 ncrcmd send_ident
[ 9];
1247 ncrcmd prepare
[ 6];
1248 ncrcmd prepare2
[ 7];
1249 ncrcmd command
[ 6];
1250 ncrcmd dispatch
[ 32];
1252 ncrcmd no_data
[ 17];
1255 ncrcmd msg_in2
[ 16];
1256 ncrcmd msg_bad
[ 4];
1258 ncrcmd cleanup
[ 6];
1259 ncrcmd complete
[ 9];
1260 ncrcmd cleanup_ok
[ 8 + PREFETCH_FLUSH_CNT
];
1261 ncrcmd cleanup0
[ 1];
1262 #ifndef SCSI_NCR_CCB_DONE_SUPPORT
1263 ncrcmd signal
[ 12];
1266 ncrcmd done_pos
[ 1];
1267 ncrcmd done_plug
[ 2];
1268 ncrcmd done_end
[ 7];
1270 ncrcmd save_dp
[ 7];
1271 ncrcmd restore_dp
[ 5];
1272 ncrcmd disconnect
[ 17];
1273 ncrcmd msg_out
[ 9];
1274 ncrcmd msg_out_done
[ 7];
1276 ncrcmd reselect
[ 8];
1277 ncrcmd reselected
[ 8];
1278 ncrcmd resel_dsa
[ 6 + PREFETCH_FLUSH_CNT
];
1279 ncrcmd loadpos1
[ 4];
1280 ncrcmd resel_lun
[ 6];
1281 ncrcmd resel_tag
[ 6];
1282 ncrcmd jump_to_nexus
[ 4 + PREFETCH_FLUSH_CNT
];
1283 ncrcmd nexus_indirect
[ 4];
1284 ncrcmd resel_notag
[ 4];
1285 ncrcmd data_in
[MAX_SCATTERL
* 4];
1286 ncrcmd data_in2
[ 4];
1287 ncrcmd data_out
[MAX_SCATTERL
* 4];
1288 ncrcmd data_out2
[ 4];
1292 ** Script fragments which stay in main memory for all chips.
1295 ncrcmd tryloop
[MAX_START
*2];
1296 ncrcmd tryloop2
[ 2];
1297 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
1298 ncrcmd done_queue
[MAX_DONE
*5];
1299 ncrcmd done_queue2
[ 2];
1301 ncrcmd select_no_atn
[ 8];
1303 ncrcmd skip
[ 9 + PREFETCH_FLUSH_CNT
];
1305 ncrcmd par_err_data_in
[ 6];
1306 ncrcmd par_err_other
[ 4];
1307 ncrcmd msg_reject
[ 8];
1308 ncrcmd msg_ign_residue
[ 24];
1309 ncrcmd msg_extended
[ 10];
1310 ncrcmd msg_ext_2
[ 10];
1311 ncrcmd msg_wdtr
[ 14];
1312 ncrcmd send_wdtr
[ 7];
1313 ncrcmd msg_ext_3
[ 10];
1314 ncrcmd msg_sdtr
[ 14];
1315 ncrcmd send_sdtr
[ 7];
1316 ncrcmd nego_bad_phase
[ 4];
1317 ncrcmd msg_out_abort
[ 10];
1318 ncrcmd hdata_in
[MAX_SCATTERH
* 4];
1319 ncrcmd hdata_in2
[ 2];
1320 ncrcmd hdata_out
[MAX_SCATTERH
* 4];
1321 ncrcmd hdata_out2
[ 2];
1323 ncrcmd aborttag
[ 4];
1325 ncrcmd abort_resel
[ 20];
1326 ncrcmd resend_ident
[ 4];
1327 ncrcmd clratn_go_on
[ 3];
1328 ncrcmd nxtdsp_go_on
[ 1];
1329 ncrcmd sdata_in
[ 8];
1330 ncrcmd data_io
[ 18];
1331 ncrcmd bad_identify
[ 12];
1332 ncrcmd bad_i_t_l
[ 4];
1333 ncrcmd bad_i_t_l_q
[ 4];
1334 ncrcmd bad_target
[ 8];
1335 ncrcmd bad_status
[ 8];
1336 ncrcmd start_ram
[ 4 + PREFETCH_FLUSH_CNT
];
1337 ncrcmd start_ram0
[ 4];
1338 ncrcmd sto_restart
[ 5];
1339 ncrcmd wait_dma
[ 2];
1340 ncrcmd snooptest
[ 9];
1341 ncrcmd snoopend
[ 2];
1344 /*==========================================================
1347 ** Function headers.
1350 **==========================================================
1353 static void ncr_alloc_ccb (ncb_p np
, u_char tn
, u_char ln
);
1354 static void ncr_complete (ncb_p np
, ccb_p cp
);
1355 static void ncr_exception (ncb_p np
);
1356 static void ncr_free_ccb (ncb_p np
, ccb_p cp
);
1357 static void ncr_init_ccb (ncb_p np
, ccb_p cp
);
1358 static void ncr_init_tcb (ncb_p np
, u_char tn
);
1359 static lcb_p
ncr_alloc_lcb (ncb_p np
, u_char tn
, u_char ln
);
1360 static lcb_p
ncr_setup_lcb (ncb_p np
, u_char tn
, u_char ln
,
1362 static void ncr_getclock (ncb_p np
, int mult
);
1363 static void ncr_selectclock (ncb_p np
, u_char scntl3
);
1364 static ccb_p
ncr_get_ccb (ncb_p np
, u_char tn
, u_char ln
);
1365 static void ncr_chip_reset (ncb_p np
, int delay
);
1366 static void ncr_init (ncb_p np
, int reset
, char * msg
, u_long code
);
1367 static int ncr_int_sbmc (ncb_p np
);
1368 static int ncr_int_par (ncb_p np
);
1369 static void ncr_int_ma (ncb_p np
);
1370 static void ncr_int_sir (ncb_p np
);
1371 static void ncr_int_sto (ncb_p np
);
1372 static u_long
ncr_lookup (char* id
);
1373 static void ncr_negotiate (struct ncb
* np
, struct tcb
* tp
);
1374 static int ncr_prepare_nego(ncb_p np
, ccb_p cp
, u_char
*msgptr
);
1375 #ifdef SCSI_NCR_INTEGRITY_CHECKING
1376 static int ncr_ic_nego(ncb_p np
, ccb_p cp
, Scsi_Cmnd
*cmd
, u_char
*msgptr
);
1379 static void ncr_script_copy_and_bind
1380 (ncb_p np
, ncrcmd
*src
, ncrcmd
*dst
, int len
);
1381 static void ncr_script_fill (struct script
* scr
, struct scripth
* scripth
);
1382 static int ncr_scatter (ncb_p np
, ccb_p cp
, Scsi_Cmnd
*cmd
);
1383 static void ncr_getsync (ncb_p np
, u_char sfac
, u_char
*fakp
, u_char
*scntl3p
);
1384 static void ncr_setsync (ncb_p np
, ccb_p cp
, u_char scntl3
, u_char sxfer
);
1385 static void ncr_setup_tags (ncb_p np
, u_char tn
, u_char ln
);
1386 static void ncr_setwide (ncb_p np
, ccb_p cp
, u_char wide
, u_char ack
);
1387 static int ncr_show_msg (u_char
* msg
);
1388 static void ncr_print_msg (ccb_p cp
, char *label
, u_char
*msg
);
1389 static int ncr_snooptest (ncb_p np
);
1390 static void ncr_timeout (ncb_p np
);
1391 static void ncr_wakeup (ncb_p np
, u_long code
);
1392 static void ncr_wakeup_done (ncb_p np
);
1393 static void ncr_start_next_ccb (ncb_p np
, lcb_p lp
, int maxn
);
1394 static void ncr_put_start_queue(ncb_p np
, ccb_p cp
);
1395 static void ncr_start_reset (ncb_p np
);
1396 static int ncr_reset_scsi_bus (ncb_p np
, int enab_int
, int settle_delay
);
1398 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
1399 static void ncr_usercmd (ncb_p np
);
1402 static void insert_into_waiting_list(ncb_p np
, Scsi_Cmnd
*cmd
);
1403 static Scsi_Cmnd
*retrieve_from_waiting_list(int to_remove
, ncb_p np
, Scsi_Cmnd
*cmd
);
1404 static void process_waiting_list(ncb_p np
, int sts
);
1406 #define remove_from_waiting_list(np, cmd) \
1407 retrieve_from_waiting_list(1, (np), (cmd))
1408 #define requeue_waiting_list(np) process_waiting_list((np), DID_OK)
1409 #define reset_waiting_list(np) process_waiting_list((np), DID_RESET)
1411 static inline char *ncr_name (ncb_p np
)
1413 return np
->inst_name
;
1417 /*==========================================================
1420 ** Scripts for NCR-Processor.
1422 ** Use ncr_script_bind for binding to physical addresses.
1425 **==========================================================
1427 ** NADDR generates a reference to a field of the controller data.
1428 ** PADDR generates a reference to another part of the script.
1429 ** RADDR generates a reference to a script processor register.
1430 ** FADDR generates a reference to a script processor register
1433 **----------------------------------------------------------
1436 #define RELOC_SOFTC 0x40000000
1437 #define RELOC_LABEL 0x50000000
1438 #define RELOC_REGISTER 0x60000000
1440 #define RELOC_KVAR 0x70000000
1442 #define RELOC_LABELH 0x80000000
1443 #define RELOC_MASK 0xf0000000
1445 #define NADDR(label) (RELOC_SOFTC | offsetof(struct ncb, label))
1446 #define PADDR(label) (RELOC_LABEL | offsetof(struct script, label))
1447 #define PADDRH(label) (RELOC_LABELH | offsetof(struct scripth, label))
1448 #define RADDR(label) (RELOC_REGISTER | REG(label))
1449 #define FADDR(label,ofs)(RELOC_REGISTER | ((REG(label))+(ofs)))
1451 #define KVAR(which) (RELOC_KVAR | (which))
1455 #define SCRIPT_KVAR_JIFFIES (0)
1456 #define SCRIPT_KVAR_FIRST SCRIPT_KVAR_JIFFIES
1457 #define SCRIPT_KVAR_LAST SCRIPT_KVAR_JIFFIES
1459 * Kernel variables referenced in the scripts.
1460 * THESE MUST ALL BE ALIGNED TO A 4-BYTE BOUNDARY.
1462 static void *script_kvars
[] __initdata
=
1463 { (void *)&jiffies
};
1466 static struct script script0 __initdata
= {
1467 /*--------------------------< START >-----------------------*/ {
1469 ** This NOP will be patched with LED ON
1470 ** SCR_REG_REG (gpreg, SCR_AND, 0xfe)
1477 SCR_FROM_REG (ctest2
),
1480 ** Then jump to a certain point in tryloop.
1481 ** Due to the lack of indirect addressing the code
1482 ** is self modifying here.
1485 }/*-------------------------< STARTPOS >--------------------*/,{
1488 }/*-------------------------< SELECT >----------------------*/,{
1490 ** DSA contains the address of a scheduled
1493 ** SCRATCHA contains the address of the script,
1494 ** which starts the next entry.
1496 ** Set Initiator mode.
1498 ** (Target mode is left as an exercise for the reader)
1503 SCR_LOAD_REG (HS_REG
, HS_SELECTING
),
1507 ** And try to select this target.
1509 SCR_SEL_TBL_ATN
^ offsetof (struct dsb
, select
),
1512 }/*-------------------------< SELECT2 >----------------------*/,{
1514 ** Now there are 4 possibilities:
1516 ** (1) The ncr loses arbitration.
1517 ** This is ok, because it will try again,
1518 ** when the bus becomes idle.
1519 ** (But beware of the timeout function!)
1521 ** (2) The ncr is reselected.
1522 ** Then the script processor takes the jump
1523 ** to the RESELECT label.
1525 ** (3) The ncr wins arbitration.
1526 ** Then it will execute SCRIPTS instruction until
1527 ** the next instruction that checks SCSI phase.
1528 ** Then will stop and wait for selection to be
1529 ** complete or selection time-out to occur.
1530 ** As a result the SCRIPTS instructions until
1531 ** LOADPOS + 2 should be executed in parallel with
1532 ** the SCSI core performing selection.
1536 ** The M_REJECT problem seems to be due to a selection
1538 ** Wait immediately for the selection to complete.
1539 ** (2.5x behaves so)
1541 SCR_JUMPR
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
1545 ** Next time use the next slot.
1551 ** The ncr doesn't have an indirect load
1552 ** or store command. So we have to
1553 ** copy part of the control block to a
1554 ** fixed place, where we can access it.
1556 ** We patch the address part of a
1557 ** COPY command with the DSA-register.
1563 ** Flush script prefetch if required
1567 ** then we do the actual copy.
1569 SCR_COPY (sizeof (struct head
)),
1571 ** continued after the next label ...
1573 }/*-------------------------< LOADPOS >---------------------*/,{
1577 ** Wait for the next phase or the selection
1578 ** to complete or time-out.
1580 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
1583 }/*-------------------------< SEND_IDENT >----------------------*/,{
1585 ** Selection complete.
1586 ** Send the IDENTIFY and SIMPLE_TAG messages
1587 ** (and the M_X_SYNC_REQ message)
1589 SCR_MOVE_TBL
^ SCR_MSG_OUT
,
1590 offsetof (struct dsb
, smsg
),
1591 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_OUT
)),
1592 PADDRH (resend_ident
),
1593 SCR_LOAD_REG (scratcha
, 0x80),
1598 }/*-------------------------< PREPARE >----------------------*/,{
1600 ** load the savep (saved pointer) into
1601 ** the TEMP register (actual pointer)
1604 NADDR (header
.savep
),
1607 ** Initialize the status registers
1610 NADDR (header
.status
),
1612 }/*-------------------------< PREPARE2 >---------------------*/,{
1614 ** Initialize the msgout buffer with a NOOP message.
1616 SCR_LOAD_REG (scratcha
, M_NOOP
),
1627 ** Anticipate the COMMAND phase.
1628 ** This is the normal case for initial selection.
1630 SCR_JUMP
^ IFFALSE (WHEN (SCR_COMMAND
)),
1633 }/*-------------------------< COMMAND >--------------------*/,{
1635 ** ... and send the command
1637 SCR_MOVE_TBL
^ SCR_COMMAND
,
1638 offsetof (struct dsb
, cmd
),
1640 ** If status is still HS_NEGOTIATE, negotiation failed.
1641 ** We check this here, since we want to do that
1644 SCR_FROM_REG (HS_REG
),
1646 SCR_INT
^ IFTRUE (DATA (HS_NEGOTIATE
)),
1649 }/*-----------------------< DISPATCH >----------------------*/,{
1651 ** MSG_IN is the only phase that shall be
1652 ** entered at least once for each (re)selection.
1653 ** So we test it first.
1655 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_IN
)),
1658 SCR_RETURN
^ IFTRUE (IF (SCR_DATA_OUT
)),
1661 ** DEL 397 - 53C875 Rev 3 - Part Number 609-0392410 - ITEM 4.
1662 ** Possible data corruption during Memory Write and Invalidate.
1663 ** This work-around resets the addressing logic prior to the
1664 ** start of the first MOVE of a DATA IN phase.
1665 ** (See Documentation/scsi/ncr53c8xx.txt for more information)
1667 SCR_JUMPR
^ IFFALSE (IF (SCR_DATA_IN
)),
1674 SCR_JUMP
^ IFTRUE (IF (SCR_STATUS
)),
1676 SCR_JUMP
^ IFTRUE (IF (SCR_COMMAND
)),
1678 SCR_JUMP
^ IFTRUE (IF (SCR_MSG_OUT
)),
1681 ** Discard one illegal phase byte, if required.
1683 SCR_LOAD_REG (scratcha
, XE_BAD_PHASE
),
1688 SCR_JUMPR
^ IFFALSE (IF (SCR_ILG_OUT
)),
1690 SCR_MOVE_ABS (1) ^ SCR_ILG_OUT
,
1692 SCR_JUMPR
^ IFFALSE (IF (SCR_ILG_IN
)),
1694 SCR_MOVE_ABS (1) ^ SCR_ILG_IN
,
1699 }/*-------------------------< CLRACK >----------------------*/,{
1701 ** Terminate possible pending message phase.
1708 }/*-------------------------< NO_DATA >--------------------*/,{
1710 ** The target wants to tranfer too much data
1711 ** or in the wrong direction.
1712 ** Remember that in extended error.
1714 SCR_LOAD_REG (scratcha
, XE_EXTRA_DATA
),
1720 ** Discard one data byte, if required.
1722 SCR_JUMPR
^ IFFALSE (WHEN (SCR_DATA_OUT
)),
1724 SCR_MOVE_ABS (1) ^ SCR_DATA_OUT
,
1726 SCR_JUMPR
^ IFFALSE (IF (SCR_DATA_IN
)),
1728 SCR_MOVE_ABS (1) ^ SCR_DATA_IN
,
1731 ** .. and repeat as required.
1738 }/*-------------------------< STATUS >--------------------*/,{
1742 SCR_MOVE_ABS (1) ^ SCR_STATUS
,
1745 ** save status to scsi_status.
1746 ** mark as complete.
1748 SCR_TO_REG (SS_REG
),
1750 SCR_LOAD_REG (HS_REG
, HS_COMPLETE
),
1754 }/*-------------------------< MSG_IN >--------------------*/,{
1756 ** Get the first byte of the message
1757 ** and save it to SCRATCHA.
1759 ** The script processor doesn't negate the
1760 ** ACK signal after this transfer.
1762 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
1764 }/*-------------------------< MSG_IN2 >--------------------*/,{
1766 ** Handle this message.
1768 SCR_JUMP
^ IFTRUE (DATA (M_COMPLETE
)),
1770 SCR_JUMP
^ IFTRUE (DATA (M_DISCONNECT
)),
1772 SCR_JUMP
^ IFTRUE (DATA (M_SAVE_DP
)),
1774 SCR_JUMP
^ IFTRUE (DATA (M_RESTORE_DP
)),
1776 SCR_JUMP
^ IFTRUE (DATA (M_EXTENDED
)),
1777 PADDRH (msg_extended
),
1778 SCR_JUMP
^ IFTRUE (DATA (M_NOOP
)),
1780 SCR_JUMP
^ IFTRUE (DATA (M_REJECT
)),
1781 PADDRH (msg_reject
),
1782 SCR_JUMP
^ IFTRUE (DATA (M_IGN_RESIDUE
)),
1783 PADDRH (msg_ign_residue
),
1785 ** Rest of the messages left as
1788 ** Unimplemented messages:
1789 ** fall through to MSG_BAD.
1791 }/*-------------------------< MSG_BAD >------------------*/,{
1793 ** unimplemented message - reject it.
1797 SCR_LOAD_REG (scratcha
, M_REJECT
),
1799 }/*-------------------------< SETMSG >----------------------*/,{
1807 }/*-------------------------< CLEANUP >-------------------*/,{
1809 ** dsa: Pointer to ccb
1810 ** or xxxxxxFF (no ccb)
1812 ** HS_REG: Host-Status (<>0!)
1816 SCR_JUMP
^ IFTRUE (DATA (0xff)),
1820 ** complete the cleanup.
1825 }/*-------------------------< COMPLETE >-----------------*/,{
1827 ** Complete message.
1829 ** Copy TEMP register to LASTP in header.
1833 NADDR (header
.lastp
),
1835 ** When we terminate the cycle by clearing ACK,
1836 ** the target may disconnect immediately.
1838 ** We don't want to be told of an
1839 ** "unexpected disconnect",
1840 ** so we disable this feature.
1842 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
1845 ** Terminate cycle ...
1847 SCR_CLR (SCR_ACK
|SCR_ATN
),
1850 ** ... and wait for the disconnect.
1854 }/*-------------------------< CLEANUP_OK >----------------*/,{
1856 ** Save host status to header.
1860 NADDR (header
.status
),
1862 ** and copy back the header to the ccb.
1868 ** Flush script prefetch if required
1871 SCR_COPY (sizeof (struct head
)),
1873 }/*-------------------------< CLEANUP0 >--------------------*/,{
1875 }/*-------------------------< SIGNAL >----------------------*/,{
1877 ** if job not completed ...
1879 SCR_FROM_REG (HS_REG
),
1882 ** ... start the next command.
1884 SCR_JUMP
^ IFTRUE (MASK (0, (HS_DONEMASK
|HS_SKIPMASK
))),
1887 ** If command resulted in not GOOD status,
1888 ** call the C code if needed.
1890 SCR_FROM_REG (SS_REG
),
1892 SCR_CALL
^ IFFALSE (DATA (S_GOOD
)),
1893 PADDRH (bad_status
),
1895 #ifndef SCSI_NCR_CCB_DONE_SUPPORT
1898 ** ... signal completion to the host
1900 #ifdef SIMULATED_INTFLY
1908 ** Auf zu neuen Schandtaten!
1913 #else /* defined SCSI_NCR_CCB_DONE_SUPPORT */
1916 ** ... signal completion to the host
1919 }/*------------------------< DONE_POS >---------------------*/,{
1920 PADDRH (done_queue
),
1921 }/*------------------------< DONE_PLUG >--------------------*/,{
1924 }/*------------------------< DONE_END >---------------------*/,{
1925 #ifdef SIMULATED_INTFLY
1938 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
1940 }/*-------------------------< SAVE_DP >------------------*/,{
1943 ** Copy TEMP register to SAVEP in header.
1947 NADDR (header
.savep
),
1952 }/*-------------------------< RESTORE_DP >---------------*/,{
1954 ** RESTORE_DP message:
1955 ** Copy SAVEP in header to TEMP register.
1958 NADDR (header
.savep
),
1963 }/*-------------------------< DISCONNECT >---------------*/,{
1965 ** DISCONNECTing ...
1967 ** disable the "unexpected disconnect" feature,
1968 ** and remove the ACK signal.
1970 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
1972 SCR_CLR (SCR_ACK
|SCR_ATN
),
1975 ** Wait for the disconnect.
1980 ** Status is: DISCONNECTED.
1982 SCR_LOAD_REG (HS_REG
, HS_DISCONNECT
),
1985 ** If QUIRK_AUTOSAVE is set,
1986 ** do an "save pointer" operation.
1988 SCR_FROM_REG (QU_REG
),
1990 SCR_JUMP
^ IFFALSE (MASK (QUIRK_AUTOSAVE
, QUIRK_AUTOSAVE
)),
1993 ** like SAVE_DP message:
1994 ** Copy TEMP register to SAVEP in header.
1998 NADDR (header
.savep
),
2002 }/*-------------------------< MSG_OUT >-------------------*/,{
2004 ** The target requests a message.
2006 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT
,
2012 ** If it was no ABORT message ...
2014 SCR_JUMP
^ IFTRUE (DATA (M_ABORT
)),
2015 PADDRH (msg_out_abort
),
2017 ** ... wait for the next phase
2018 ** if it's a message out, send it again, ...
2020 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_OUT
)),
2022 }/*-------------------------< MSG_OUT_DONE >--------------*/,{
2024 ** ... else clear the message ...
2026 SCR_LOAD_REG (scratcha
, M_NOOP
),
2032 ** ... and process the next phase
2036 }/*-------------------------< IDLE >------------------------*/,{
2039 ** Wait for reselect.
2040 ** This NOP will be patched with LED OFF
2041 ** SCR_REG_REG (gpreg, SCR_OR, 0x01)
2045 }/*-------------------------< RESELECT >--------------------*/,{
2047 ** make the DSA invalid.
2049 SCR_LOAD_REG (dsa
, 0xff),
2053 SCR_LOAD_REG (HS_REG
, HS_IN_RESELECT
),
2056 ** Sleep waiting for a reselection.
2057 ** If SIGP is set, special treatment.
2059 ** Zu allem bereit ..
2063 }/*-------------------------< RESELECTED >------------------*/,{
2065 ** This NOP will be patched with LED ON
2066 ** SCR_REG_REG (gpreg, SCR_AND, 0xfe)
2071 ** ... zu nichts zu gebrauchen ?
2073 ** load the target id into the SFBR
2074 ** and jump to the control block.
2076 ** Look at the declarations of
2081 ** to understand what's going on.
2083 SCR_REG_SFBR (ssid
, SCR_AND
, 0x8F),
2090 }/*-------------------------< RESEL_DSA >-------------------*/,{
2092 ** Ack the IDENTIFY or TAG previously received.
2097 ** The ncr doesn't have an indirect load
2098 ** or store command. So we have to
2099 ** copy part of the control block to a
2100 ** fixed place, where we can access it.
2102 ** We patch the address part of a
2103 ** COPY command with the DSA-register.
2109 ** Flush script prefetch if required
2113 ** then we do the actual copy.
2115 SCR_COPY (sizeof (struct head
)),
2117 ** continued after the next label ...
2120 }/*-------------------------< LOADPOS1 >-------------------*/,{
2124 ** The DSA contains the data structure address.
2129 }/*-------------------------< RESEL_LUN >-------------------*/,{
2131 ** come back to this point
2132 ** to get an IDENTIFY message
2133 ** Wait for a msg_in phase.
2135 SCR_INT
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2136 SIR_RESEL_NO_MSG_IN
,
2139 ** Read the data directly from the BUS DATA lines.
2140 ** This helps to support very old SCSI devices that
2141 ** may reselect without sending an IDENTIFY.
2143 SCR_FROM_REG (sbdl
),
2146 ** It should be an Identify message.
2150 }/*-------------------------< RESEL_TAG >-------------------*/,{
2152 ** Read IDENTIFY + SIMPLE + TAG using a single MOVE.
2153 ** Agressive optimization, is'nt it?
2154 ** No need to test the SIMPLE TAG message, since the
2155 ** driver only supports conformant devices for tags. ;-)
2157 SCR_MOVE_ABS (3) ^ SCR_MSG_IN
,
2160 ** Read the TAG from the SIDL.
2161 ** Still an aggressive optimization. ;-)
2162 ** Compute the CCB indirect jump address which
2163 ** is (#TAG*2 & 0xfc) due to tag numbering using
2164 ** 1,3,5..MAXTAGS*2+1 actual values.
2166 SCR_REG_SFBR (sidl
, SCR_SHL
, 0),
2168 SCR_SFBR_REG (temp
, SCR_AND
, 0xfc),
2170 }/*-------------------------< JUMP_TO_NEXUS >-------------------*/,{
2173 PADDR (nexus_indirect
),
2175 ** Flush script prefetch if required
2179 }/*-------------------------< NEXUS_INDIRECT >-------------------*/,{
2184 }/*-------------------------< RESEL_NOTAG >-------------------*/,{
2187 ** Read an throw away the IDENTIFY.
2189 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2192 PADDR (jump_to_nexus
),
2193 }/*-------------------------< DATA_IN >--------------------*/,{
2195 ** Because the size depends on the
2196 ** #define MAX_SCATTERL parameter,
2197 ** it is filled in at runtime.
2199 ** ##===========< i=0; i<MAX_SCATTERL >=========
2200 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN)),
2201 ** || PADDR (dispatch),
2202 ** || SCR_MOVE_TBL ^ SCR_DATA_IN,
2203 ** || offsetof (struct dsb, data[ i]),
2204 ** ##==========================================
2206 **---------------------------------------------------------
2209 }/*-------------------------< DATA_IN2 >-------------------*/,{
2214 }/*-------------------------< DATA_OUT >--------------------*/,{
2216 ** Because the size depends on the
2217 ** #define MAX_SCATTERL parameter,
2218 ** it is filled in at runtime.
2220 ** ##===========< i=0; i<MAX_SCATTERL >=========
2221 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT)),
2222 ** || PADDR (dispatch),
2223 ** || SCR_MOVE_TBL ^ SCR_DATA_OUT,
2224 ** || offsetof (struct dsb, data[ i]),
2225 ** ##==========================================
2227 **---------------------------------------------------------
2230 }/*-------------------------< DATA_OUT2 >-------------------*/,{
2235 }/*--------------------------------------------------------*/
2238 static struct scripth scripth0 __initdata
= {
2239 /*-------------------------< TRYLOOP >---------------------*/{
2241 ** Start the next entry.
2242 ** Called addresses point to the launch script in the CCB.
2243 ** They are patched by the main processor.
2245 ** Because the size depends on the
2246 ** #define MAX_START parameter, it is filled
2249 **-----------------------------------------------------------
2251 ** ##===========< I=0; i<MAX_START >===========
2254 ** ##==========================================
2256 **-----------------------------------------------------------
2259 }/*------------------------< TRYLOOP2 >---------------------*/,{
2263 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
2265 }/*------------------------< DONE_QUEUE >-------------------*/,{
2267 ** Copy the CCB address to the next done entry.
2268 ** Because the size depends on the
2269 ** #define MAX_DONE parameter, it is filled
2272 **-----------------------------------------------------------
2274 ** ##===========< I=0; i<MAX_DONE >===========
2275 ** || SCR_COPY (sizeof(ccb_p)),
2276 ** || NADDR (header.cp),
2277 ** || NADDR (ccb_done[i]),
2279 ** || PADDR (done_end),
2280 ** ##==========================================
2282 **-----------------------------------------------------------
2285 }/*------------------------< DONE_QUEUE2 >------------------*/,{
2287 PADDRH (done_queue
),
2289 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
2290 }/*------------------------< SELECT_NO_ATN >-----------------*/,{
2292 ** Set Initiator mode.
2293 ** And try to select this target without ATN.
2298 SCR_LOAD_REG (HS_REG
, HS_SELECTING
),
2300 SCR_SEL_TBL
^ offsetof (struct dsb
, select
),
2305 }/*-------------------------< CANCEL >------------------------*/,{
2307 SCR_LOAD_REG (scratcha
, HS_ABORTED
),
2311 }/*-------------------------< SKIP >------------------------*/,{
2312 SCR_LOAD_REG (scratcha
, 0),
2315 ** This entry has been canceled.
2316 ** Next time use the next slot.
2322 ** The ncr doesn't have an indirect load
2323 ** or store command. So we have to
2324 ** copy part of the control block to a
2325 ** fixed place, where we can access it.
2327 ** We patch the address part of a
2328 ** COPY command with the DSA-register.
2334 ** Flush script prefetch if required
2338 ** then we do the actual copy.
2340 SCR_COPY (sizeof (struct head
)),
2342 ** continued after the next label ...
2344 }/*-------------------------< SKIP2 >---------------------*/,{
2348 ** Initialize the status registers
2351 NADDR (header
.status
),
2354 ** Force host status.
2356 SCR_FROM_REG (scratcha
),
2358 SCR_JUMPR
^ IFFALSE (MASK (0, HS_DONEMASK
)),
2360 SCR_REG_REG (HS_REG
, SCR_OR
, HS_SKIPMASK
),
2364 SCR_TO_REG (HS_REG
),
2366 SCR_LOAD_REG (SS_REG
, S_GOOD
),
2371 },/*-------------------------< PAR_ERR_DATA_IN >---------------*/{
2373 ** Ignore all data in byte, until next phase
2375 SCR_JUMP
^ IFFALSE (WHEN (SCR_DATA_IN
)),
2376 PADDRH (par_err_other
),
2377 SCR_MOVE_ABS (1) ^ SCR_DATA_IN
,
2381 },/*-------------------------< PAR_ERR_OTHER >------------------*/{
2385 SCR_REG_REG (PS_REG
, SCR_ADD
, 0x01),
2388 ** jump to dispatcher.
2392 }/*-------------------------< MSG_REJECT >---------------*/,{
2394 ** If a negotiation was in progress,
2395 ** negotiation failed.
2396 ** Otherwise, let the C code print
2399 SCR_FROM_REG (HS_REG
),
2401 SCR_INT
^ IFFALSE (DATA (HS_NEGOTIATE
)),
2402 SIR_REJECT_RECEIVED
,
2403 SCR_INT
^ IFTRUE (DATA (HS_NEGOTIATE
)),
2408 }/*-------------------------< MSG_IGN_RESIDUE >----------*/,{
2414 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2417 ** get residue size.
2419 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2422 ** Size is 0 .. ignore message.
2424 SCR_JUMP
^ IFTRUE (DATA (0)),
2427 ** Size is not 1 .. have to interrupt.
2429 SCR_JUMPR
^ IFFALSE (DATA (1)),
2432 ** Check for residue byte in swide register
2434 SCR_FROM_REG (scntl2
),
2436 SCR_JUMPR
^ IFFALSE (MASK (WSR
, WSR
)),
2439 ** There IS data in the swide register.
2442 SCR_REG_REG (scntl2
, SCR_OR
, WSR
),
2447 ** Load again the size to the sfbr register.
2449 SCR_FROM_REG (scratcha
),
2456 }/*-------------------------< MSG_EXTENDED >-------------*/,{
2462 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2467 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2471 SCR_JUMP
^ IFTRUE (DATA (3)),
2473 SCR_JUMP
^ IFFALSE (DATA (2)),
2475 }/*-------------------------< MSG_EXT_2 >----------------*/,{
2478 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2481 ** get extended message code.
2483 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2485 SCR_JUMP
^ IFTRUE (DATA (M_X_WIDE_REQ
)),
2488 ** unknown extended message
2492 }/*-------------------------< MSG_WDTR >-----------------*/,{
2495 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2498 ** get data bus width
2500 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2503 ** let the host do the real work.
2508 ** let the target fetch our answer.
2514 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
2515 PADDRH (nego_bad_phase
),
2517 }/*-------------------------< SEND_WDTR >----------------*/,{
2519 ** Send the M_X_WIDE_REQ
2521 SCR_MOVE_ABS (4) ^ SCR_MSG_OUT
,
2527 PADDR (msg_out_done
),
2529 }/*-------------------------< MSG_EXT_3 >----------------*/,{
2532 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2535 ** get extended message code.
2537 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2539 SCR_JUMP
^ IFTRUE (DATA (M_X_SYNC_REQ
)),
2542 ** unknown extended message
2547 }/*-------------------------< MSG_SDTR >-----------------*/,{
2550 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2553 ** get period and offset
2555 SCR_MOVE_ABS (2) ^ SCR_MSG_IN
,
2558 ** let the host do the real work.
2563 ** let the target fetch our answer.
2569 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
2570 PADDRH (nego_bad_phase
),
2572 }/*-------------------------< SEND_SDTR >-------------*/,{
2574 ** Send the M_X_SYNC_REQ
2576 SCR_MOVE_ABS (5) ^ SCR_MSG_OUT
,
2582 PADDR (msg_out_done
),
2584 }/*-------------------------< NEGO_BAD_PHASE >------------*/,{
2590 }/*-------------------------< MSG_OUT_ABORT >-------------*/,{
2592 ** After ABORT message,
2594 ** expect an immediate disconnect, ...
2596 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
2598 SCR_CLR (SCR_ACK
|SCR_ATN
),
2603 ** ... and set the status to "ABORTED"
2605 SCR_LOAD_REG (HS_REG
, HS_ABORTED
),
2610 }/*-------------------------< HDATA_IN >-------------------*/,{
2612 ** Because the size depends on the
2613 ** #define MAX_SCATTERH parameter,
2614 ** it is filled in at runtime.
2616 ** ##==< i=MAX_SCATTERL; i<MAX_SCATTERL+MAX_SCATTERH >==
2617 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN)),
2618 ** || PADDR (dispatch),
2619 ** || SCR_MOVE_TBL ^ SCR_DATA_IN,
2620 ** || offsetof (struct dsb, data[ i]),
2621 ** ##===================================================
2623 **---------------------------------------------------------
2626 }/*-------------------------< HDATA_IN2 >------------------*/,{
2630 }/*-------------------------< HDATA_OUT >-------------------*/,{
2632 ** Because the size depends on the
2633 ** #define MAX_SCATTERH parameter,
2634 ** it is filled in at runtime.
2636 ** ##==< i=MAX_SCATTERL; i<MAX_SCATTERL+MAX_SCATTERH >==
2637 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT)),
2638 ** || PADDR (dispatch),
2639 ** || SCR_MOVE_TBL ^ SCR_DATA_OUT,
2640 ** || offsetof (struct dsb, data[ i]),
2641 ** ##===================================================
2643 **---------------------------------------------------------
2646 }/*-------------------------< HDATA_OUT2 >------------------*/,{
2650 }/*-------------------------< RESET >----------------------*/,{
2652 ** Send a M_RESET message if bad IDENTIFY
2653 ** received on reselection.
2655 SCR_LOAD_REG (scratcha
, M_ABORT_TAG
),
2658 PADDRH (abort_resel
),
2659 }/*-------------------------< ABORTTAG >-------------------*/,{
2661 ** Abort a wrong tag received on reselection.
2663 SCR_LOAD_REG (scratcha
, M_ABORT_TAG
),
2666 PADDRH (abort_resel
),
2667 }/*-------------------------< ABORT >----------------------*/,{
2669 ** Abort a reselection when no active CCB.
2671 SCR_LOAD_REG (scratcha
, M_ABORT
),
2673 }/*-------------------------< ABORT_RESEL >----------------*/,{
2683 ** we expect an immediate disconnect
2685 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
2687 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT
,
2692 SCR_CLR (SCR_ACK
|SCR_ATN
),
2698 }/*-------------------------< RESEND_IDENT >-------------------*/,{
2700 ** The target stays in MSG OUT phase after having acked
2701 ** Identify [+ Tag [+ Extended message ]]. Targets shall
2702 ** behave this way on parity error.
2703 ** We must send it again all the messages.
2705 SCR_SET (SCR_ATN
), /* Shall be asserted 2 deskew delays before the */
2706 0, /* 1rst ACK = 90 ns. Hope the NCR is'nt too fast */
2709 }/*-------------------------< CLRATN_GO_ON >-------------------*/,{
2713 }/*-------------------------< NXTDSP_GO_ON >-------------------*/,{
2715 }/*-------------------------< SDATA_IN >-------------------*/,{
2716 SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_IN
)),
2718 SCR_MOVE_TBL
^ SCR_DATA_IN
,
2719 offsetof (struct dsb
, sense
),
2724 }/*-------------------------< DATA_IO >--------------------*/,{
2726 ** We jump here if the data direction was unknown at the
2727 ** time we had to queue the command to the scripts processor.
2728 ** Pointers had been set as follow in this situation:
2729 ** savep --> DATA_IO
2730 ** lastp --> start pointer when DATA_IN
2731 ** goalp --> goal pointer when DATA_IN
2732 ** wlastp --> start pointer when DATA_OUT
2733 ** wgoalp --> goal pointer when DATA_OUT
2734 ** This script sets savep/lastp/goalp according to the
2735 ** direction chosen by the target.
2737 SCR_JUMPR
^ IFTRUE (WHEN (SCR_DATA_OUT
)),
2740 ** Direction is DATA IN.
2741 ** Warning: we jump here, even when phase is DATA OUT.
2744 NADDR (header
.lastp
),
2745 NADDR (header
.savep
),
2748 ** Jump to the SCRIPTS according to actual direction.
2751 NADDR (header
.savep
),
2756 ** Direction is DATA OUT.
2759 NADDR (header
.wlastp
),
2760 NADDR (header
.lastp
),
2762 NADDR (header
.wgoalp
),
2763 NADDR (header
.goalp
),
2766 }/*-------------------------< BAD_IDENTIFY >---------------*/,{
2768 ** If message phase but not an IDENTIFY,
2769 ** get some help from the C code.
2770 ** Old SCSI device may behave so.
2772 SCR_JUMPR
^ IFTRUE (MASK (0x80, 0x80)),
2775 SIR_RESEL_NO_IDENTIFY
,
2779 ** Message is an IDENTIFY, but lun is unknown.
2780 ** Read the message, since we got it directly
2781 ** from the SCSI BUS data lines.
2782 ** Signal problem to C code for logging the event.
2783 ** Send a M_ABORT to clear all pending tasks.
2787 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2791 }/*-------------------------< BAD_I_T_L >------------------*/,{
2793 ** We donnot have a task for that I_T_L.
2794 ** Signal problem to C code for logging the event.
2795 ** Send a M_ABORT message.
2798 SIR_RESEL_BAD_I_T_L
,
2801 }/*-------------------------< BAD_I_T_L_Q >----------------*/,{
2803 ** We donnot have a task that matches the tag.
2804 ** Signal problem to C code for logging the event.
2805 ** Send a M_ABORTTAG message.
2808 SIR_RESEL_BAD_I_T_L_Q
,
2811 }/*-------------------------< BAD_TARGET >-----------------*/,{
2813 ** We donnot know the target that reselected us.
2814 ** Grab the first message if any (IDENTIFY).
2815 ** Signal problem to C code for logging the event.
2819 SIR_RESEL_BAD_TARGET
,
2820 SCR_JUMPR
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2822 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2826 }/*-------------------------< BAD_STATUS >-----------------*/,{
2828 ** If command resulted in either QUEUE FULL,
2829 ** CHECK CONDITION or COMMAND TERMINATED,
2832 SCR_INT
^ IFTRUE (DATA (S_QUEUE_FULL
)),
2834 SCR_INT
^ IFTRUE (DATA (S_CHECK_COND
)),
2836 SCR_INT
^ IFTRUE (DATA (S_TERMINATED
)),
2840 }/*-------------------------< START_RAM >-------------------*/,{
2842 ** Load the script into on-chip RAM,
2843 ** and jump to start point.
2847 PADDRH (start_ram0
),
2849 ** Flush script prefetch if required
2852 SCR_COPY (sizeof (struct script
)),
2853 }/*-------------------------< START_RAM0 >--------------------*/,{
2858 }/*-------------------------< STO_RESTART >-------------------*/,{
2861 ** Repair start queue (e.g. next time use the next slot)
2862 ** and jump to start point.
2869 }/*-------------------------< WAIT_DMA >-------------------*/,{
2871 ** For HP Zalon/53c720 systems, the Zalon interface
2872 ** between CPU and 53c720 does prefetches, which causes
2873 ** problems with self modifying scripts. The problem
2874 ** is overcome by calling a dummy subroutine after each
2875 ** modification, to force a refetch of the script on
2876 ** return from the subroutine.
2880 }/*-------------------------< SNOOPTEST >-------------------*/,{
2882 ** Read the variable.
2888 ** Write the variable.
2894 ** Read back the variable.
2899 }/*-------------------------< SNOOPEND >-------------------*/,{
2905 }/*--------------------------------------------------------*/
2908 /*==========================================================
2911 ** Fill in #define dependent parts of the script
2914 **==========================================================
2917 void __init
ncr_script_fill (struct script
* scr
, struct scripth
* scrh
)
2923 for (i
=0; i
<MAX_START
; i
++) {
2928 assert ((u_long
)p
== (u_long
)&scrh
->tryloop
+ sizeof (scrh
->tryloop
));
2930 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
2932 p
= scrh
->done_queue
;
2933 for (i
= 0; i
<MAX_DONE
; i
++) {
2934 *p
++ =SCR_COPY (sizeof(ccb_p
));
2935 *p
++ =NADDR (header
.cp
);
2936 *p
++ =NADDR (ccb_done
[i
]);
2938 *p
++ =PADDR (done_end
);
2941 assert ((u_long
)p
==(u_long
)&scrh
->done_queue
+sizeof(scrh
->done_queue
));
2943 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
2946 for (i
=0; i
<MAX_SCATTERH
; i
++) {
2947 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_IN
));
2948 *p
++ =PADDR (dispatch
);
2949 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_IN
;
2950 *p
++ =offsetof (struct dsb
, data
[i
]);
2952 assert ((u_long
)p
== (u_long
)&scrh
->hdata_in
+ sizeof (scrh
->hdata_in
));
2955 for (i
=MAX_SCATTERH
; i
<MAX_SCATTERH
+MAX_SCATTERL
; i
++) {
2956 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_IN
));
2957 *p
++ =PADDR (dispatch
);
2958 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_IN
;
2959 *p
++ =offsetof (struct dsb
, data
[i
]);
2961 assert ((u_long
)p
== (u_long
)&scr
->data_in
+ sizeof (scr
->data_in
));
2963 p
= scrh
->hdata_out
;
2964 for (i
=0; i
<MAX_SCATTERH
; i
++) {
2965 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_OUT
));
2966 *p
++ =PADDR (dispatch
);
2967 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_OUT
;
2968 *p
++ =offsetof (struct dsb
, data
[i
]);
2970 assert ((u_long
)p
==(u_long
)&scrh
->hdata_out
+ sizeof (scrh
->hdata_out
));
2973 for (i
=MAX_SCATTERH
; i
<MAX_SCATTERH
+MAX_SCATTERL
; i
++) {
2974 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_OUT
));
2975 *p
++ =PADDR (dispatch
);
2976 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_OUT
;
2977 *p
++ =offsetof (struct dsb
, data
[i
]);
2980 assert ((u_long
)p
== (u_long
)&scr
->data_out
+ sizeof (scr
->data_out
));
2983 /*==========================================================
2986 ** Copy and rebind a script.
2989 **==========================================================
2993 ncr_script_copy_and_bind (ncb_p np
, ncrcmd
*src
, ncrcmd
*dst
, int len
)
2995 ncrcmd opcode
, new, old
, tmp1
, tmp2
;
2996 ncrcmd
*start
, *end
;
3006 *dst
++ = cpu_to_scr(opcode
);
3009 ** If we forget to change the length
3010 ** in struct script, a field will be
3011 ** padded with 0. This is an illegal
3016 printk (KERN_ERR
"%s: ERROR0 IN SCRIPT at %d.\n",
3017 ncr_name(np
), (int) (src
-start
-1));
3021 if (DEBUG_FLAGS
& DEBUG_SCRIPT
)
3022 printk (KERN_DEBUG
"%p: <%x>\n",
3023 (src
-1), (unsigned)opcode
);
3026 ** We don't have to decode ALL commands
3028 switch (opcode
>> 28) {
3032 ** COPY has TWO arguments.
3037 if ((tmp1
& RELOC_MASK
) == RELOC_KVAR
)
3042 if ((tmp2
& RELOC_MASK
) == RELOC_KVAR
)
3045 if ((tmp1
^ tmp2
) & 3) {
3046 printk (KERN_ERR
"%s: ERROR1 IN SCRIPT at %d.\n",
3047 ncr_name(np
), (int) (src
-start
-1));
3051 ** If PREFETCH feature not enabled, remove
3052 ** the NO FLUSH bit if present.
3054 if ((opcode
& SCR_NO_FLUSH
) && !(np
->features
& FE_PFEN
)) {
3055 dst
[-1] = cpu_to_scr(opcode
& ~SCR_NO_FLUSH
);
3062 ** MOVE (absolute address)
3070 ** don't relocate if relative :-)
3072 if (opcode
& 0x00800000)
3094 switch (old
& RELOC_MASK
) {
3095 case RELOC_REGISTER
:
3096 new = (old
& ~RELOC_MASK
) + np
->paddr
;
3099 new = (old
& ~RELOC_MASK
) + np
->p_script
;
3102 new = (old
& ~RELOC_MASK
) + np
->p_scripth
;
3105 new = (old
& ~RELOC_MASK
) + np
->p_ncb
;
3109 if (((old
& ~RELOC_MASK
) <
3110 SCRIPT_KVAR_FIRST
) ||
3111 ((old
& ~RELOC_MASK
) >
3113 panic("ncr KVAR out of range");
3114 new = vtophys(script_kvars
[old
&
3119 /* Don't relocate a 0 address. */
3126 panic("ncr_script_copy_and_bind: weird relocation %x\n", old
);
3130 *dst
++ = cpu_to_scr(new);
3133 *dst
++ = cpu_to_scr(*src
++);
3138 /*==========================================================
3141 ** Auto configuration: attach and init a host adapter.
3144 **==========================================================
3148 ** Linux host data structure
3150 ** The script area is allocated in the host data structure
3151 ** because kmalloc() returns NULL during scsi initialisations
3160 ** Print something which allows to retrieve the controller type, unit,
3161 ** target, lun concerned by a kernel message.
3164 static void PRINT_TARGET(ncb_p np
, int target
)
3166 printk(KERN_INFO
"%s-<%d,*>: ", ncr_name(np
), target
);
3169 static void PRINT_LUN(ncb_p np
, int target
, int lun
)
3171 printk(KERN_INFO
"%s-<%d,%d>: ", ncr_name(np
), target
, lun
);
3174 static void PRINT_ADDR(Scsi_Cmnd
*cmd
)
3176 struct host_data
*host_data
= (struct host_data
*) cmd
->device
->host
->hostdata
;
3177 PRINT_LUN(host_data
->ncb
, cmd
->device
->id
, cmd
->device
->lun
);
3180 /*==========================================================
3182 ** NCR chip clock divisor table.
3183 ** Divisors are multiplied by 10,000,000 in order to make
3184 ** calculations more simple.
3186 **==========================================================
3190 static u_long div_10M
[] =
3191 {2*_5M
, 3*_5M
, 4*_5M
, 6*_5M
, 8*_5M
, 12*_5M
, 16*_5M
};
3194 /*===============================================================
3196 ** Prepare io register values used by ncr_init() according
3197 ** to selected and supported features.
3199 ** NCR chips allow burst lengths of 2, 4, 8, 16, 32, 64, 128
3200 ** transfers. 32,64,128 are only supported by 875 and 895 chips.
3201 ** We use log base 2 (burst length) as internal code, with
3202 ** value 0 meaning "burst disabled".
3204 **===============================================================
3208 * Burst length from burst code.
3210 #define burst_length(bc) (!(bc))? 0 : 1 << (bc)
3213 * Burst code from io register bits. Burst enable is ctest0 for c720,
3214 * ctest4 for others.
3216 #define burst_code(dmode, ctest0, ctest4, ctest5) \
3217 (np->device_id == PSEUDO_720_ID) ? \
3218 (ctest0) & 0x80? 0 : (((dmode) & 0xc0) >> 6) + 1 : \
3219 (ctest4) & 0x80? 0 : (((dmode) & 0xc0) >> 6) + ((ctest5) & 0x04) + 1
3222 * Set initial io register bits from burst code.
3224 static inline void ncr_init_burst(ncb_p np
, u_char bc
)
3226 u_char
*be
= (np
->device_id
== PSEUDO_720_ID
) ?
3227 &np
->rv_ctest0
: &np
->rv_ctest4
;
3229 np
->rv_dmode
&= ~(0x3 << 6);
3230 np
->rv_ctest5
&= ~0x4;
3237 np
->rv_dmode
|= ((bc
& 0x3) << 6);
3238 np
->rv_ctest5
|= (bc
& 0x4);
3242 #ifdef SCSI_NCR_NVRAM_SUPPORT
3245 ** Get target set-up from Symbios format NVRAM.
3249 ncr_Symbios_setup_target(ncb_p np
, int target
, Symbios_nvram
*nvram
)
3251 tcb_p tp
= &np
->target
[target
];
3252 Symbios_target
*tn
= &nvram
->target
[target
];
3254 tp
->usrsync
= tn
->sync_period
? (tn
->sync_period
+ 3) / 4 : 255;
3255 tp
->usrwide
= tn
->bus_width
== 0x10 ? 1 : 0;
3257 (tn
->flags
& SYMBIOS_QUEUE_TAGS_ENABLED
)? MAX_TAGS
: 0;
3259 if (!(tn
->flags
& SYMBIOS_DISCONNECT_ENABLE
))
3260 tp
->usrflag
|= UF_NODISC
;
3261 if (!(tn
->flags
& SYMBIOS_SCAN_AT_BOOT_TIME
))
3262 tp
->usrflag
|= UF_NOSCAN
;
3266 ** Get target set-up from Tekram format NVRAM.
3270 ncr_Tekram_setup_target(ncb_p np
, int target
, Tekram_nvram
*nvram
)
3272 tcb_p tp
= &np
->target
[target
];
3273 struct Tekram_target
*tn
= &nvram
->target
[target
];
3276 if (tn
->flags
& TEKRAM_SYNC_NEGO
) {
3277 i
= tn
->sync_index
& 0xf;
3278 tp
->usrsync
= Tekram_sync
[i
];
3281 tp
->usrwide
= (tn
->flags
& TEKRAM_WIDE_NEGO
) ? 1 : 0;
3283 if (tn
->flags
& TEKRAM_TAGGED_COMMANDS
) {
3284 tp
->usrtags
= 2 << nvram
->max_tags_index
;
3287 if (!(tn
->flags
& TEKRAM_DISCONNECT_ENABLE
))
3288 tp
->usrflag
= UF_NODISC
;
3290 /* If any device does not support parity, we will not use this option */
3291 if (!(tn
->flags
& TEKRAM_PARITY_CHECK
))
3292 np
->rv_scntl0
&= ~0x0a; /* SCSI parity checking disabled */
3294 #endif /* SCSI_NCR_NVRAM_SUPPORT */
3296 static int __init
ncr_prepare_setting(ncb_p np
, ncr_nvram
*nvram
)
3303 ** Save assumed BIOS setting
3306 np
->sv_scntl0
= INB(nc_scntl0
) & 0x0a;
3307 np
->sv_scntl3
= INB(nc_scntl3
) & 0x07;
3308 np
->sv_dmode
= INB(nc_dmode
) & 0xce;
3309 np
->sv_dcntl
= INB(nc_dcntl
) & 0xa8;
3310 np
->sv_ctest0
= INB(nc_ctest0
) & 0x84;
3311 np
->sv_ctest3
= INB(nc_ctest3
) & 0x01;
3312 np
->sv_ctest4
= INB(nc_ctest4
) & 0x80;
3313 np
->sv_ctest5
= INB(nc_ctest5
) & 0x24;
3314 np
->sv_gpcntl
= INB(nc_gpcntl
);
3315 np
->sv_stest2
= INB(nc_stest2
) & 0x20;
3316 np
->sv_stest4
= INB(nc_stest4
);
3322 np
->maxwide
= (np
->features
& FE_WIDE
)? 1 : 0;
3325 * Guess the frequency of the chip's clock.
3327 if (np
->features
& (FE_ULTRA3
| FE_ULTRA2
))
3328 np
->clock_khz
= 160000;
3329 else if (np
->features
& FE_ULTRA
)
3330 np
->clock_khz
= 80000;
3332 np
->clock_khz
= 40000;
3335 * Get the clock multiplier factor.
3337 if (np
->features
& FE_QUAD
)
3339 else if (np
->features
& FE_DBLR
)
3345 * Measure SCSI clock frequency for chips
3346 * it may vary from assumed one.
3348 if (np
->features
& FE_VARCLK
)
3349 ncr_getclock(np
, np
->multiplier
);
3352 * Divisor to be used for async (timer pre-scaler).
3354 i
= np
->clock_divn
- 1;
3356 if (10ul * SCSI_NCR_MIN_ASYNC
* np
->clock_khz
> div_10M
[i
]) {
3361 np
->rv_scntl3
= i
+1;
3364 * Minimum synchronous period factor supported by the chip.
3365 * Btw, 'period' is in tenths of nanoseconds.
3368 period
= (4 * div_10M
[0] + np
->clock_khz
- 1) / np
->clock_khz
;
3369 if (period
<= 250) np
->minsync
= 10;
3370 else if (period
<= 303) np
->minsync
= 11;
3371 else if (period
<= 500) np
->minsync
= 12;
3372 else np
->minsync
= (period
+ 40 - 1) / 40;
3375 * Check against chip SCSI standard support (SCSI-2,ULTRA,ULTRA2).
3378 if (np
->minsync
< 25 && !(np
->features
& (FE_ULTRA
|FE_ULTRA2
)))
3380 else if (np
->minsync
< 12 && !(np
->features
& FE_ULTRA2
))
3384 * Maximum synchronous period factor supported by the chip.
3387 period
= (11 * div_10M
[np
->clock_divn
- 1]) / (4 * np
->clock_khz
);
3388 np
->maxsync
= period
> 2540 ? 254 : period
/ 10;
3391 ** Prepare initial value of other IO registers
3393 #if defined SCSI_NCR_TRUST_BIOS_SETTING
3394 np
->rv_scntl0
= np
->sv_scntl0
;
3395 np
->rv_dmode
= np
->sv_dmode
;
3396 np
->rv_dcntl
= np
->sv_dcntl
;
3397 np
->rv_ctest0
= np
->sv_ctest0
;
3398 np
->rv_ctest3
= np
->sv_ctest3
;
3399 np
->rv_ctest4
= np
->sv_ctest4
;
3400 np
->rv_ctest5
= np
->sv_ctest5
;
3401 burst_max
= burst_code(np
->sv_dmode
, np
->sv_ctest0
, np
->sv_ctest4
, np
->sv_ctest5
);
3405 ** Select burst length (dwords)
3407 burst_max
= driver_setup
.burst_max
;
3408 if (burst_max
== 255)
3409 burst_max
= burst_code(np
->sv_dmode
, np
->sv_ctest0
, np
->sv_ctest4
, np
->sv_ctest5
);
3412 if (burst_max
> np
->maxburst
)
3413 burst_max
= np
->maxburst
;
3416 ** Select all supported special features
3418 if (np
->features
& FE_ERL
)
3419 np
->rv_dmode
|= ERL
; /* Enable Read Line */
3420 if (np
->features
& FE_BOF
)
3421 np
->rv_dmode
|= BOF
; /* Burst Opcode Fetch */
3422 if (np
->features
& FE_ERMP
)
3423 np
->rv_dmode
|= ERMP
; /* Enable Read Multiple */
3424 if (np
->features
& FE_PFEN
)
3425 np
->rv_dcntl
|= PFEN
; /* Prefetch Enable */
3426 if (np
->features
& FE_CLSE
)
3427 np
->rv_dcntl
|= CLSE
; /* Cache Line Size Enable */
3428 if (np
->features
& FE_WRIE
)
3429 np
->rv_ctest3
|= WRIE
; /* Write and Invalidate */
3430 if (np
->features
& FE_DFS
)
3431 np
->rv_ctest5
|= DFS
; /* Dma Fifo Size */
3432 if (np
->features
& FE_MUX
)
3433 np
->rv_ctest4
|= MUX
; /* Host bus multiplex mode */
3434 if (np
->features
& FE_EA
)
3435 np
->rv_dcntl
|= EA
; /* Enable ACK */
3436 if (np
->features
& FE_EHP
)
3437 np
->rv_ctest0
|= EHP
; /* Even host parity */
3440 ** Select some other
3442 if (driver_setup
.master_parity
)
3443 np
->rv_ctest4
|= MPEE
; /* Master parity checking */
3444 if (driver_setup
.scsi_parity
)
3445 np
->rv_scntl0
|= 0x0a; /* full arb., ena parity, par->ATN */
3447 #ifdef SCSI_NCR_NVRAM_SUPPORT
3449 ** Get parity checking, host ID and verbose mode from NVRAM
3452 switch(nvram
->type
) {
3453 case SCSI_NCR_TEKRAM_NVRAM
:
3454 np
->myaddr
= nvram
->data
.Tekram
.host_id
& 0x0f;
3456 case SCSI_NCR_SYMBIOS_NVRAM
:
3457 if (!(nvram
->data
.Symbios
.flags
& SYMBIOS_PARITY_ENABLE
))
3458 np
->rv_scntl0
&= ~0x0a;
3459 np
->myaddr
= nvram
->data
.Symbios
.host_id
& 0x0f;
3460 if (nvram
->data
.Symbios
.flags
& SYMBIOS_VERBOSE_MSGS
)
3467 ** Get SCSI addr of host adapter (set by bios?).
3469 if (np
->myaddr
== 255) {
3470 np
->myaddr
= INB(nc_scid
) & 0x07;
3472 np
->myaddr
= SCSI_NCR_MYADDR
;
3475 #endif /* SCSI_NCR_TRUST_BIOS_SETTING */
3478 * Prepare initial io register bits for burst length
3480 ncr_init_burst(np
, burst_max
);
3483 ** Set SCSI BUS mode.
3485 ** - ULTRA2 chips (895/895A/896) report the current
3486 ** BUS mode through the STEST4 IO register.
3487 ** - For previous generation chips (825/825A/875),
3488 ** user has to tell us how to check against HVD,
3489 ** since a 100% safe algorithm is not possible.
3491 np
->scsi_mode
= SMODE_SE
;
3492 if (np
->features
& FE_ULTRA2
)
3493 np
->scsi_mode
= (np
->sv_stest4
& SMODE
);
3494 else if (np
->features
& FE_DIFF
) {
3495 switch(driver_setup
.diff_support
) {
3496 case 4: /* Trust previous settings if present, then GPIO3 */
3497 if (np
->sv_scntl3
) {
3498 if (np
->sv_stest2
& 0x20)
3499 np
->scsi_mode
= SMODE_HVD
;
3502 case 3: /* SYMBIOS controllers report HVD through GPIO3 */
3503 if (nvram
&& nvram
->type
!= SCSI_NCR_SYMBIOS_NVRAM
)
3505 if (INB(nc_gpreg
) & 0x08)
3507 case 2: /* Set HVD unconditionally */
3508 np
->scsi_mode
= SMODE_HVD
;
3509 case 1: /* Trust previous settings for HVD */
3510 if (np
->sv_stest2
& 0x20)
3511 np
->scsi_mode
= SMODE_HVD
;
3513 default:/* Don't care about HVD */
3517 if (np
->scsi_mode
== SMODE_HVD
)
3518 np
->rv_stest2
|= 0x20;
3521 ** Set LED support from SCRIPTS.
3522 ** Ignore this feature for boards known to use a
3523 ** specific GPIO wiring and for the 895A or 896
3524 ** that drive the LED directly.
3525 ** Also probe initial setting of GPIO0 as output.
3527 if ((driver_setup
.led_pin
||
3528 (nvram
&& nvram
->type
== SCSI_NCR_SYMBIOS_NVRAM
)) &&
3529 !(np
->features
& FE_LEDC
) && !(np
->sv_gpcntl
& 0x01))
3530 np
->features
|= FE_LED0
;
3535 switch(driver_setup
.irqm
& 3) {
3537 np
->rv_dcntl
|= IRQM
;
3540 np
->rv_dcntl
|= (np
->sv_dcntl
& IRQM
);
3547 ** Configure targets according to driver setup.
3548 ** If NVRAM present get targets setup from NVRAM.
3549 ** Allow to override sync, wide and NOSCAN from
3550 ** boot command line.
3552 for (i
= 0 ; i
< MAX_TARGET
; i
++) {
3553 tcb_p tp
= &np
->target
[i
];
3556 #ifdef SCSI_NCR_NVRAM_SUPPORT
3558 switch(nvram
->type
) {
3559 case SCSI_NCR_TEKRAM_NVRAM
:
3560 ncr_Tekram_setup_target(np
, i
, &nvram
->data
.Tekram
);
3562 case SCSI_NCR_SYMBIOS_NVRAM
:
3563 ncr_Symbios_setup_target(np
, i
, &nvram
->data
.Symbios
);
3566 if (driver_setup
.use_nvram
& 0x2)
3567 tp
->usrsync
= driver_setup
.default_sync
;
3568 if (driver_setup
.use_nvram
& 0x4)
3569 tp
->usrwide
= driver_setup
.max_wide
;
3570 if (driver_setup
.use_nvram
& 0x8)
3571 tp
->usrflag
&= ~UF_NOSCAN
;
3577 tp
->usrsync
= driver_setup
.default_sync
;
3578 tp
->usrwide
= driver_setup
.max_wide
;
3579 tp
->usrtags
= MAX_TAGS
;
3580 if (!driver_setup
.disconnection
)
3581 np
->target
[i
].usrflag
= UF_NODISC
;
3586 ** Announce all that stuff to user.
3589 i
= nvram
? nvram
->type
: 0;
3590 printk(KERN_INFO
"%s: %sID %d, Fast-%d%s%s\n", ncr_name(np
),
3591 i
== SCSI_NCR_SYMBIOS_NVRAM
? "Symbios format NVRAM, " :
3592 (i
== SCSI_NCR_TEKRAM_NVRAM
? "Tekram format NVRAM, " : ""),
3594 np
->minsync
< 12 ? 40 : (np
->minsync
< 25 ? 20 : 10),
3595 (np
->rv_scntl0
& 0xa) ? ", Parity Checking" : ", NO Parity",
3596 (np
->rv_stest2
& 0x20) ? ", Differential" : "");
3598 if (bootverbose
> 1) {
3599 printk (KERN_INFO
"%s: initial SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
3600 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
3601 ncr_name(np
), np
->sv_scntl3
, np
->sv_dmode
, np
->sv_dcntl
,
3602 np
->sv_ctest3
, np
->sv_ctest4
, np
->sv_ctest5
);
3604 printk (KERN_INFO
"%s: final SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
3605 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
3606 ncr_name(np
), np
->rv_scntl3
, np
->rv_dmode
, np
->rv_dcntl
,
3607 np
->rv_ctest3
, np
->rv_ctest4
, np
->rv_ctest5
);
3610 if (bootverbose
&& np
->paddr2
)
3611 printk (KERN_INFO
"%s: on-chip RAM at 0x%lx\n",
3612 ncr_name(np
), np
->paddr2
);
3618 ** Host attach and initialisations.
3620 ** Allocate host data and ncb structure.
3621 ** Request IO region and remap MMIO region.
3622 ** Do chip initialization.
3623 ** If all is OK, install interrupt handling and
3624 ** start the timer daemon.
3627 struct Scsi_Host
* __init
3628 ncr_attach (Scsi_Host_Template
*tpnt
, int unit
, ncr_device
*device
)
3630 struct host_data
*host_data
;
3632 struct Scsi_Host
*instance
= 0;
3634 ncr_nvram
*nvram
= device
->nvram
;
3637 #ifdef SCSI_NCR_PROC_INFO_SUPPORT
3638 tpnt
->proc_info
= ncr53c8xx_proc_info
,
3640 tpnt
->info
= ncr53c8xx_info
;
3641 tpnt
->queuecommand
= ncr53c8xx_queue_command
;
3642 tpnt
->slave_configure
= ncr53c8xx_slave_configure
;
3643 tpnt
->eh_bus_reset_handler
= ncr53c8xx_bus_reset
;
3644 tpnt
->can_queue
= SCSI_NCR_CAN_QUEUE
;
3646 tpnt
->sg_tablesize
= SCSI_NCR_SG_TABLESIZE
;
3647 tpnt
->cmd_per_lun
= SCSI_NCR_CMD_PER_LUN
;
3648 tpnt
->use_clustering
= DISABLE_CLUSTERING
;
3650 if(device
->differential
)
3651 driver_setup
.diff_support
= device
->differential
;
3653 printk(KERN_INFO
"ncr53c%s-%d: rev 0x%x on pci bus %d device %d function %d "
3659 device
->chip
.name
, unit
, device
->chip
.revision_id
,
3660 device
->slot
.bus
, (device
->slot
.device_fn
& 0xf8) >> 3,
3661 device
->slot
.device_fn
& 7,
3663 __irq_itoa(device
->slot
.irq
));
3669 ** Allocate host_data structure
3671 if (!(instance
= scsi_host_alloc(tpnt
, sizeof(*host_data
))))
3673 host_data
= (struct host_data
*) instance
->hostdata
;
3676 ** Allocate the host control block.
3678 np
= __m_calloc_dma(device
->dev
, sizeof(struct ncb
), "NCB");
3681 NCR_INIT_LOCK_NCB(np
);
3682 np
->dev
= device
->dev
;
3683 np
->p_ncb
= vtobus(np
);
3684 host_data
->ncb
= np
;
3687 ** Allocate the default CCB.
3689 np
->ccb
= (ccb_p
) m_calloc_dma(sizeof(struct ccb
), "CCB");
3694 ** Store input informations in the host data structure.
3696 strlcpy(np
->chip_name
, device
->chip
.name
, sizeof(np
->chip_name
));
3698 np
->verbose
= driver_setup
.verbose
;
3699 sprintf(np
->inst_name
, "ncr53c%s-%d", np
->chip_name
, np
->unit
);
3700 np
->device_id
= device
->chip
.device_id
;
3701 np
->revision_id
= device
->chip
.revision_id
;
3702 np
->bus
= device
->slot
.bus
;
3703 np
->device_fn
= device
->slot
.device_fn
;
3704 np
->features
= device
->chip
.features
;
3705 np
->clock_divn
= device
->chip
.nr_divisor
;
3706 np
->maxoffs
= device
->chip
.offset_max
;
3707 np
->maxburst
= device
->chip
.burst_max
;
3708 np
->myaddr
= device
->host_id
;
3711 ** Allocate SCRIPTS areas.
3713 np
->script0
= (struct script
*)
3714 m_calloc_dma(sizeof(struct script
), "SCRIPT");
3717 np
->scripth0
= (struct scripth
*)
3718 m_calloc_dma(sizeof(struct scripth
), "SCRIPTH");
3723 ** Initialize timer structure
3726 init_timer(&np
->timer
);
3727 np
->timer
.data
= (unsigned long) np
;
3728 np
->timer
.function
= ncr53c8xx_timeout
;
3731 ** Try to map the controller chip to
3732 ** virtual and physical memory.
3735 np
->paddr
= device
->slot
.base
;
3736 np
->paddr2
= (np
->features
& FE_RAM
)? device
->slot
.base_2
: 0;
3738 #ifndef SCSI_NCR_IOMAPPED
3739 if(device
->slot
.base_v
)
3740 np
->vaddr
= device
->slot
.base_v
;
3742 np
->vaddr
= remap_pci_mem(device
->slot
.base_c
, (u_long
) 128);
3746 "%s: can't map memory mapped IO region\n",ncr_name(np
));
3750 if (bootverbose
> 1)
3752 "%s: using memory mapped IO at virtual address 0x%lx\n", ncr_name(np
), (u_long
) np
->vaddr
);
3755 ** Make the controller's registers available.
3756 ** Now the INB INW INL OUTB OUTW OUTL macros
3757 ** can be used safely.
3760 np
->reg
= (struct ncr_reg
*) np
->vaddr
;
3765 ** Try to map the controller chip into iospace.
3768 np
->base_io
= device
->slot
.io_port
;
3769 #endif /* !defined SCSI_NCR_IOMAPPED */
3771 #ifdef SCSI_NCR_NVRAM_SUPPORT
3773 switch(nvram
->type
) {
3774 case SCSI_NCR_SYMBIOS_NVRAM
:
3775 #ifdef SCSI_NCR_DEBUG_NVRAM
3776 ncr_display_Symbios_nvram(&nvram
->data
.Symbios
);
3779 case SCSI_NCR_TEKRAM_NVRAM
:
3780 #ifdef SCSI_NCR_DEBUG_NVRAM
3781 ncr_display_Tekram_nvram(&nvram
->data
.Tekram
);
3786 #ifdef SCSI_NCR_DEBUG_NVRAM
3787 printk(KERN_DEBUG
"%s: NVRAM: None or invalid data.\n", ncr_name(np
));
3794 ** Do chip dependent initialization.
3796 (void)ncr_prepare_setting(np
, nvram
);
3798 if (np
->paddr2
&& sizeof(struct script
) > 4096) {
3800 printk(KERN_WARNING
"%s: script too large, NOT using on chip RAM.\n",
3805 ** Fill Linux host instance structure
3807 instance
->max_channel
= 0;
3808 instance
->this_id
= np
->myaddr
;
3809 instance
->max_id
= np
->maxwide
? 16 : 8;
3810 instance
->max_lun
= SCSI_NCR_MAX_LUN
;
3811 #ifndef SCSI_NCR_IOMAPPED
3812 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,29)
3813 instance
->base
= (unsigned long) np
->reg
;
3815 instance
->base
= (char *) np
->reg
;
3818 instance
->irq
= device
->slot
.irq
;
3819 instance
->unique_id
= device
->slot
.io_port
;
3820 instance
->io_port
= device
->slot
.io_port
;
3821 instance
->n_io_port
= 128;
3822 instance
->dma_channel
= 0;
3823 instance
->cmd_per_lun
= MAX_TAGS
;
3824 instance
->can_queue
= (MAX_START
-4);
3825 scsi_set_device(instance
, device
->dev
);
3827 #ifdef SCSI_NCR_INTEGRITY_CHECKING
3828 np
->check_integrity
= 0;
3829 instance
->check_integrity
= 0;
3831 #ifdef SCSI_NCR_ENABLE_INTEGRITY_CHECK
3832 if ( !(driver_setup
.bus_check
& 0x04) ) {
3833 np
->check_integrity
= 1;
3834 instance
->check_integrity
= 1;
3839 ** Patch script to physical addresses
3841 ncr_script_fill (&script0
, &scripth0
);
3843 np
->scripth
= np
->scripth0
;
3844 np
->p_scripth
= vtobus(np
->scripth
);
3846 np
->p_script
= (np
->paddr2
) ? np
->paddr2
: vtobus(np
->script0
);
3848 ncr_script_copy_and_bind (np
, (ncrcmd
*) &script0
, (ncrcmd
*) np
->script0
, sizeof(struct script
));
3849 ncr_script_copy_and_bind (np
, (ncrcmd
*) &scripth0
, (ncrcmd
*) np
->scripth0
, sizeof(struct scripth
));
3850 np
->ccb
->p_ccb
= vtobus (np
->ccb
);
3853 ** Patch the script for LED support.
3856 if (np
->features
& FE_LED0
) {
3857 np
->script0
->idle
[0] =
3858 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_OR
, 0x01));
3859 np
->script0
->reselected
[0] =
3860 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_AND
, 0xfe));
3861 np
->script0
->start
[0] =
3862 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_AND
, 0xfe));
3866 ** Look for the target control block of this nexus.
3868 ** JUMP ^ IFTRUE (MASK (i, 3)), @(next_lcb)
3870 for (i
= 0 ; i
< 4 ; i
++) {
3871 np
->jump_tcb
[i
].l_cmd
=
3872 cpu_to_scr((SCR_JUMP
^ IFTRUE (MASK (i
, 3))));
3873 np
->jump_tcb
[i
].l_paddr
=
3874 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_target
));
3880 ncr_chip_reset(np
, 100);
3883 ** Now check the cache handling of the pci chipset.
3886 if (ncr_snooptest (np
)) {
3887 printk (KERN_ERR
"CACHE INCORRECTLY CONFIGURED.\n");
3892 ** Install the interrupt handler.
3895 np
->irq
= device
->slot
.irq
;
3898 ** Initialize the fixed part of the default ccb.
3900 ncr_init_ccb(np
, np
->ccb
);
3903 ** After SCSI devices have been opened, we cannot
3904 ** reset the bus safely, so we do it here.
3905 ** Interrupt handler does the real work.
3906 ** Process the reset exception,
3907 ** if interrupts are not enabled yet.
3908 ** Then enable disconnects.
3910 NCR_LOCK_NCB(np
, flags
);
3911 if (ncr_reset_scsi_bus(np
, 0, driver_setup
.settle_delay
) != 0) {
3912 printk(KERN_ERR
"%s: FATAL ERROR: CHECK SCSI BUS - CABLES, TERMINATION, DEVICE POWER etc.!\n", ncr_name(np
));
3914 NCR_UNLOCK_NCB(np
, flags
);
3922 ** The middle-level SCSI driver does not
3923 ** wait for devices to settle.
3924 ** Wait synchronously if more than 2 seconds.
3926 if (driver_setup
.settle_delay
> 2) {
3927 printk(KERN_INFO
"%s: waiting %d seconds for scsi devices to settle...\n",
3928 ncr_name(np
), driver_setup
.settle_delay
);
3929 MDELAY (1000 * driver_setup
.settle_delay
);
3933 ** Now let the generic SCSI driver
3934 ** look for the SCSI devices on the bus ..
3938 ** start the timeout daemon
3944 ** use SIMPLE TAG messages by default
3946 #ifdef SCSI_NCR_ALWAYS_SIMPLE_TAG
3947 np
->order
= M_SIMPLE_TAG
;
3953 if (!the_template
) {
3954 the_template
= instance
->hostt
;
3955 first_host
= instance
;
3958 NCR_UNLOCK_NCB(np
, flags
);
3963 if (!instance
) return NULL
;
3964 printk(KERN_INFO
"%s: detaching...\n", ncr_name(np
));
3968 m_free_dma(np
->scripth0
, sizeof(struct scripth
), "SCRIPTH");
3970 m_free_dma(np
->script0
, sizeof(struct script
), "SCRIPT");
3972 m_free_dma(np
->ccb
, sizeof(struct ccb
), "CCB");
3973 m_free_dma(np
, sizeof(struct ncb
), "NCB");
3976 scsi_host_put(instance
);
3982 /*==========================================================
3985 ** Done SCSI commands list management.
3987 ** We donnot enter the scsi_done() callback immediately
3988 ** after a command has been seen as completed but we
3989 ** insert it into a list which is flushed outside any kind
3990 ** of driver critical section.
3991 ** This allows to do minimal stuff under interrupt and
3992 ** inside critical sections and to also avoid locking up
3993 ** on recursive calls to driver entry points under SMP.
3994 ** In fact, the only kernel point which is entered by the
3995 ** driver with a driver lock set is kmalloc(GFP_ATOMIC)
3996 ** that shall not reenter the driver under any circumstances,
3999 **==========================================================
4001 static inline void ncr_queue_done_cmd(ncb_p np
, Scsi_Cmnd
*cmd
)
4003 unmap_scsi_data(np
, cmd
);
4004 cmd
->host_scribble
= (char *) np
->done_list
;
4005 np
->done_list
= cmd
;
4008 static inline void ncr_flush_done_cmds(Scsi_Cmnd
*lcmd
)
4014 lcmd
= (Scsi_Cmnd
*) cmd
->host_scribble
;
4015 cmd
->scsi_done(cmd
);
4019 /*==========================================================
4022 ** Prepare the next negotiation message for integrity check,
4025 ** Fill in the part of message buffer that contains the
4026 ** negotiation and the nego_status field of the CCB.
4027 ** Returns the size of the message in bytes.
4030 **==========================================================
4033 #ifdef SCSI_NCR_INTEGRITY_CHECKING
4034 static int ncr_ic_nego(ncb_p np
, ccb_p cp
, Scsi_Cmnd
*cmd
, u_char
*msgptr
)
4036 tcb_p tp
= &np
->target
[cp
->target
];
4043 if (!tp
->ic_maximums_set
) {
4044 tp
->ic_maximums_set
= 1;
4046 /* check target and host adapter capabilities */
4047 if ( (tp
->inq_byte7
& INQ7_WIDE16
) &&
4048 np
->maxwide
&& tp
->usrwide
)
4049 tp
->ic_max_width
= 1;
4051 tp
->ic_max_width
= 0;
4053 if ((tp
->inq_byte7
& INQ7_SYNC
) && tp
->maxoffs
) {
4054 tp
->ic_min_sync
= (tp
->minsync
< np
->minsync
) ?
4055 np
->minsync
: tp
->minsync
;
4058 tp
->ic_min_sync
= 255;
4064 if (DEBUG_FLAGS
& DEBUG_IC
) {
4065 printk("%s: cmd->ic_nego %d, 1st byte 0x%2X\n",
4066 ncr_name(np
), cmd
->ic_nego
, cmd
->cmnd
[0]);
4069 /* First command from integrity check routine will request
4070 * a PPR message. Disable.
4072 if ((cmd
->ic_nego
& NS_PPR
) == NS_PPR
)
4073 cmd
->ic_nego
&= ~NS_PPR
;
4074 /* Previous command recorded a parity or an initiator
4075 * detected error condition. Force bus to narrow for this
4076 * target. Clear flag. Negotation on request sense.
4077 * Note: kernel forces 2 bus resets :o( but clears itself out.
4078 * Minor bug? in scsi_obsolete.c (ugly)
4080 if (np
->check_integ_par
) {
4081 printk("%s: Parity Error. Target set to narrow.\n",
4083 tp
->ic_max_width
= 0;
4084 tp
->widedone
= tp
->period
= 0;
4087 /* In case of a bus reset, ncr_negotiate will reset
4088 * the flags tp->widedone and tp->period to 0, forcing
4089 * a new negotiation.
4092 if (tp
->widedone
== 0) {
4093 cmd
->ic_nego
= NS_WIDE
;
4097 else if (tp
->period
== 0) {
4098 cmd
->ic_nego
= NS_SYNC
;
4103 switch (cmd
->ic_nego
) {
4106 ** negotiate wide transfers ?
4107 ** Do NOT negotiate if device only supports
4110 if (tp
->ic_max_width
| np
->check_integ_par
) {
4113 msgptr
[msglen
++] = M_EXTENDED
;
4114 msgptr
[msglen
++] = 2;
4115 msgptr
[msglen
++] = M_X_WIDE_REQ
;
4116 msgptr
[msglen
++] = cmd
->ic_nego_width
& tp
->ic_max_width
;
4119 cmd
->ic_nego_width
&= tp
->ic_max_width
;
4125 ** negotiate synchronous transfers?
4126 ** Target must support sync transfers.
4128 ** If period becomes longer than max, reset to async
4131 if (tp
->inq_byte7
& INQ7_SYNC
) {
4135 msgptr
[msglen
++] = M_EXTENDED
;
4136 msgptr
[msglen
++] = 3;
4137 msgptr
[msglen
++] = M_X_SYNC_REQ
;
4139 switch (cmd
->ic_nego_sync
) {
4140 case 2: /* increase the period */
4142 if (tp
->ic_min_sync
<= 0x0A)
4143 tp
->ic_min_sync
= 0x0C;
4144 else if (tp
->ic_min_sync
<= 0x0C)
4145 tp
->ic_min_sync
= 0x19;
4146 else if (tp
->ic_min_sync
<= 0x19)
4147 tp
->ic_min_sync
*= 2;
4149 tp
->ic_min_sync
= 255;
4150 cmd
->ic_nego_sync
= 0;
4154 msgptr
[msglen
++] = tp
->maxoffs
?tp
->ic_min_sync
:0;
4155 msgptr
[msglen
++] = tp
->maxoffs
;
4158 case 1: /* nego. to maximum */
4159 msgptr
[msglen
++] = tp
->maxoffs
?tp
->ic_min_sync
:0;
4160 msgptr
[msglen
++] = tp
->maxoffs
;
4163 case 0: /* nego to async */
4165 msgptr
[msglen
++] = 0;
4166 msgptr
[msglen
++] = 0;
4171 cmd
->ic_nego_sync
= 0;
4180 cp
->nego_status
= nego
;
4181 np
->check_integ_par
= 0;
4185 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
4186 ncr_print_msg(cp
, nego
== NS_WIDE
?
4187 "wide/narrow msgout": "sync/async msgout", msgptr
);
4193 #endif /* SCSI_NCR_INTEGRITY_CHECKING */
4195 /*==========================================================
4198 ** Prepare the next negotiation message if needed.
4200 ** Fill in the part of message buffer that contains the
4201 ** negotiation and the nego_status field of the CCB.
4202 ** Returns the size of the message in bytes.
4205 **==========================================================
4209 static int ncr_prepare_nego(ncb_p np
, ccb_p cp
, u_char
*msgptr
)
4211 tcb_p tp
= &np
->target
[cp
->target
];
4218 ** negotiate wide transfers ?
4221 if (!tp
->widedone
) {
4222 if (tp
->inq_byte7
& INQ7_WIDE16
) {
4224 #ifdef SCSI_NCR_INTEGRITY_CHECKING
4226 tp
->usrwide
&= tp
->ic_max_width
;
4234 ** negotiate synchronous transfers?
4237 if (!nego
&& !tp
->period
) {
4238 if (tp
->inq_byte7
& INQ7_SYNC
) {
4240 #ifdef SCSI_NCR_INTEGRITY_CHECKING
4241 if ((tp
->ic_done
) &&
4242 (tp
->minsync
< tp
->ic_min_sync
))
4243 tp
->minsync
= tp
->ic_min_sync
;
4247 PRINT_TARGET(np
, cp
->target
);
4248 printk ("target did not report SYNC.\n");
4255 msgptr
[msglen
++] = M_EXTENDED
;
4256 msgptr
[msglen
++] = 3;
4257 msgptr
[msglen
++] = M_X_SYNC_REQ
;
4258 msgptr
[msglen
++] = tp
->maxoffs
? tp
->minsync
: 0;
4259 msgptr
[msglen
++] = tp
->maxoffs
;
4262 msgptr
[msglen
++] = M_EXTENDED
;
4263 msgptr
[msglen
++] = 2;
4264 msgptr
[msglen
++] = M_X_WIDE_REQ
;
4265 msgptr
[msglen
++] = tp
->usrwide
;
4269 cp
->nego_status
= nego
;
4273 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
4274 ncr_print_msg(cp
, nego
== NS_WIDE
?
4275 "wide msgout":"sync_msgout", msgptr
);
4284 /*==========================================================
4287 ** Start execution of a SCSI command.
4288 ** This is called from the generic SCSI driver.
4291 **==========================================================
4293 static int ncr_queue_command (ncb_p np
, Scsi_Cmnd
*cmd
)
4295 /* Scsi_Device *device = cmd->device; */
4296 tcb_p tp
= &np
->target
[cmd
->device
->id
];
4297 lcb_p lp
= tp
->lp
[cmd
->device
->lun
];
4301 u_char idmsg
, *msgptr
;
4304 u_int32 lastp
, goalp
;
4306 /*---------------------------------------------
4308 ** Some shortcuts ...
4310 **---------------------------------------------
4312 if ((cmd
->device
->id
== np
->myaddr
) ||
4313 (cmd
->device
->id
>= MAX_TARGET
) ||
4314 (cmd
->device
->lun
>= MAX_LUN
)) {
4315 return(DID_BAD_TARGET
);
4318 /*---------------------------------------------
4320 ** Complete the 1st TEST UNIT READY command
4321 ** with error condition if the device is
4322 ** flagged NOSCAN, in order to speed up
4325 **---------------------------------------------
4327 if ((cmd
->cmnd
[0] == 0 || cmd
->cmnd
[0] == 0x12) &&
4328 (tp
->usrflag
& UF_NOSCAN
)) {
4329 tp
->usrflag
&= ~UF_NOSCAN
;
4330 return DID_BAD_TARGET
;
4333 if (DEBUG_FLAGS
& DEBUG_TINY
) {
4335 printk ("CMD=%x ", cmd
->cmnd
[0]);
4338 /*---------------------------------------------------
4340 ** Assign a ccb / bind cmd.
4341 ** If resetting, shorten settle_time if necessary
4342 ** in order to avoid spurious timeouts.
4343 ** If resetting or no free ccb,
4344 ** insert cmd into the waiting list.
4346 **----------------------------------------------------
4348 if (np
->settle_time
&& cmd
->timeout_per_command
>= HZ
) {
4349 u_long tlimit
= ktime_get(cmd
->timeout_per_command
- HZ
);
4350 if (ktime_dif(np
->settle_time
, tlimit
) > 0)
4351 np
->settle_time
= tlimit
;
4354 if (np
->settle_time
|| !(cp
=ncr_get_ccb (np
, cmd
->device
->id
, cmd
->device
->lun
))) {
4355 insert_into_waiting_list(np
, cmd
);
4360 /*---------------------------------------------------
4362 ** Enable tagged queue if asked by scsi ioctl
4364 **----------------------------------------------------
4366 #if 0 /* This stuff was only useful for linux-1.2.13 */
4367 if (lp
&& !lp
->numtags
&& cmd
->device
&& cmd
->device
->tagged_queue
) {
4368 lp
->numtags
= tp
->usrtags
;
4369 ncr_setup_tags (np
, cmd
->device
->id
, cmd
->device
->lun
);
4373 /*----------------------------------------------------
4375 ** Build the identify / tag / sdtr message
4377 **----------------------------------------------------
4380 idmsg
= M_IDENTIFY
| cmd
->device
->lun
;
4382 if (cp
->tag
!= NO_TAG
||
4383 (cp
!= np
->ccb
&& np
->disc
&& !(tp
->usrflag
& UF_NODISC
)))
4386 msgptr
= cp
->scsi_smsg
;
4388 msgptr
[msglen
++] = idmsg
;
4390 if (cp
->tag
!= NO_TAG
) {
4391 char order
= np
->order
;
4394 ** Force ordered tag if necessary to avoid timeouts
4395 ** and to preserve interactivity.
4397 if (lp
&& ktime_exp(lp
->tags_stime
)) {
4398 if (lp
->tags_smap
) {
4399 order
= M_ORDERED_TAG
;
4400 if ((DEBUG_FLAGS
& DEBUG_TAGS
)||bootverbose
>2){
4402 printk("ordered tag forced.\n");
4405 lp
->tags_stime
= ktime_get(3*HZ
);
4406 lp
->tags_smap
= lp
->tags_umap
;
4411 ** Ordered write ops, unordered read ops.
4413 switch (cmd
->cmnd
[0]) {
4414 case 0x08: /* READ_SMALL (6) */
4415 case 0x28: /* READ_BIG (10) */
4416 case 0xa8: /* READ_HUGE (12) */
4417 order
= M_SIMPLE_TAG
;
4420 order
= M_ORDERED_TAG
;
4423 msgptr
[msglen
++] = order
;
4425 ** Actual tags are numbered 1,3,5,..2*MAXTAGS+1,
4426 ** since we may have to deal with devices that have
4427 ** problems with #TAG 0 or too great #TAG numbers.
4429 msgptr
[msglen
++] = (cp
->tag
<< 1) + 1;
4432 /*----------------------------------------------------
4434 ** Build the data descriptors
4436 **----------------------------------------------------
4439 direction
= scsi_data_direction(cmd
);
4440 if (direction
!= SCSI_DATA_NONE
) {
4441 segments
= ncr_scatter (np
, cp
, cp
->cmd
);
4443 ncr_free_ccb(np
, cp
);
4452 /*---------------------------------------------------
4454 ** negotiation required?
4456 ** (nego_status is filled by ncr_prepare_nego())
4458 **---------------------------------------------------
4461 cp
->nego_status
= 0;
4463 #ifdef SCSI_NCR_INTEGRITY_CHECKING
4464 if ((np
->check_integrity
&& tp
->ic_done
) || !np
->check_integrity
) {
4465 if ((!tp
->widedone
|| !tp
->period
) && !tp
->nego_cp
&& lp
) {
4466 msglen
+= ncr_prepare_nego (np
, cp
, msgptr
+ msglen
);
4469 else if (np
->check_integrity
&& (cmd
->ic_in_progress
)) {
4470 msglen
+= ncr_ic_nego (np
, cp
, cmd
, msgptr
+ msglen
);
4472 else if (np
->check_integrity
&& cmd
->ic_complete
) {
4474 * Midlayer signal to the driver that all of the scsi commands
4475 * for the integrity check have completed. Save the negotiated
4476 * parameters (extracted from sval and wval).
4481 idiv
= (tp
->wval
>>4) & 0x07;
4482 if ((tp
->sval
&0x1f) && idiv
)
4483 tp
->period
= (((tp
->sval
>>5)+4)
4484 *div_10M
[idiv
-1])/np
->clock_khz
;
4486 tp
->period
= 0xffff;
4489 * tp->period contains 10 times the transfer period,
4490 * which itself is 4 * the requested negotiation rate.
4492 if (tp
->period
<= 250) tp
->ic_min_sync
= 10;
4493 else if (tp
->period
<= 303) tp
->ic_min_sync
= 11;
4494 else if (tp
->period
<= 500) tp
->ic_min_sync
= 12;
4496 tp
->ic_min_sync
= (tp
->period
+ 40 - 1) / 40;
4500 * Negotiation for this target it complete.
4502 tp
->ic_max_width
= (tp
->wval
& EWS
) ? 1: 0;
4506 printk("%s: Integrity Check Complete: \n", ncr_name(np
));
4508 printk("%s: %s %s SCSI", ncr_name(np
),
4509 (tp
->sval
&0x1f)?"SYNC":"ASYNC",
4510 tp
->ic_max_width
?"WIDE":"NARROW");
4512 if (tp
->sval
&0x1f) {
4513 u_long mbs
= 10000 * (tp
->ic_max_width
+ 1);
4515 printk(" %d.%d MB/s",
4516 (int) (mbs
/ tp
->period
), (int) (mbs
% tp
->period
));
4518 printk(" (%d ns, %d offset)\n",
4519 tp
->period
/10, tp
->sval
&0x1f);
4522 printk(" %d MB/s. \n ", (tp
->ic_max_width
+1)*5);
4525 if ((!tp
->widedone
|| !tp
->period
) && !tp
->nego_cp
&& lp
) {
4526 msglen
+= ncr_prepare_nego (np
, cp
, msgptr
+ msglen
);
4528 #endif /* SCSI_NCR_INTEGRITY_CHECKING */
4530 /*----------------------------------------------------
4532 ** Determine xfer direction.
4534 **----------------------------------------------------
4537 direction
= SCSI_DATA_NONE
;
4540 ** If data direction is UNKNOWN, speculate DATA_READ
4541 ** but prepare alternate pointers for WRITE in case
4542 ** of our speculation will be just wrong.
4543 ** SCRIPTS will swap values if needed.
4546 case SCSI_DATA_UNKNOWN
:
4547 case SCSI_DATA_WRITE
:
4548 goalp
= NCB_SCRIPT_PHYS (np
, data_out2
) + 8;
4549 if (segments
<= MAX_SCATTERL
)
4550 lastp
= goalp
- 8 - (segments
* 16);
4552 lastp
= NCB_SCRIPTH_PHYS (np
, hdata_out2
);
4553 lastp
-= (segments
- MAX_SCATTERL
) * 16;
4555 if (direction
!= SCSI_DATA_UNKNOWN
)
4557 cp
->phys
.header
.wgoalp
= cpu_to_scr(goalp
);
4558 cp
->phys
.header
.wlastp
= cpu_to_scr(lastp
);
4560 case SCSI_DATA_READ
:
4561 goalp
= NCB_SCRIPT_PHYS (np
, data_in2
) + 8;
4562 if (segments
<= MAX_SCATTERL
)
4563 lastp
= goalp
- 8 - (segments
* 16);
4565 lastp
= NCB_SCRIPTH_PHYS (np
, hdata_in2
);
4566 lastp
-= (segments
- MAX_SCATTERL
) * 16;
4570 case SCSI_DATA_NONE
:
4571 lastp
= goalp
= NCB_SCRIPT_PHYS (np
, no_data
);
4576 ** Set all pointers values needed by SCRIPTS.
4577 ** If direction is unknown, start at data_io.
4579 cp
->phys
.header
.lastp
= cpu_to_scr(lastp
);
4580 cp
->phys
.header
.goalp
= cpu_to_scr(goalp
);
4582 if (direction
== SCSI_DATA_UNKNOWN
)
4583 cp
->phys
.header
.savep
=
4584 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, data_io
));
4586 cp
->phys
.header
.savep
= cpu_to_scr(lastp
);
4589 ** Save the initial data pointer in order to be able
4590 ** to redo the command.
4592 cp
->startp
= cp
->phys
.header
.savep
;
4594 /*----------------------------------------------------
4598 **----------------------------------------------------
4601 ** physical -> virtual backlink
4602 ** Generic SCSI command
4608 cp
->start
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, select
));
4609 cp
->restart
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, resel_dsa
));
4613 cp
->phys
.select
.sel_id
= cmd
->device
->id
;
4614 cp
->phys
.select
.sel_scntl3
= tp
->wval
;
4615 cp
->phys
.select
.sel_sxfer
= tp
->sval
;
4619 cp
->phys
.smsg
.addr
= cpu_to_scr(CCB_PHYS (cp
, scsi_smsg
));
4620 cp
->phys
.smsg
.size
= cpu_to_scr(msglen
);
4625 memcpy(cp
->cdb_buf
, cmd
->cmnd
, MIN(cmd
->cmd_len
, sizeof(cp
->cdb_buf
)));
4626 cp
->phys
.cmd
.addr
= cpu_to_scr(CCB_PHYS (cp
, cdb_buf
[0]));
4627 cp
->phys
.cmd
.size
= cpu_to_scr(cmd
->cmd_len
);
4632 cp
->actualquirks
= tp
->quirks
;
4633 cp
->host_status
= cp
->nego_status
? HS_NEGOTIATE
: HS_BUSY
;
4634 cp
->scsi_status
= S_ILLEGAL
;
4635 cp
->parity_status
= 0;
4637 cp
->xerr_status
= XE_OK
;
4639 cp
->sync_status
= tp
->sval
;
4640 cp
->wide_status
= tp
->wval
;
4643 /*----------------------------------------------------
4645 ** Critical region: start this job.
4647 **----------------------------------------------------
4651 ** activate this job.
4653 cp
->magic
= CCB_MAGIC
;
4656 ** insert next CCBs into start queue.
4657 ** 2 max at a time is enough to flush the CCB wait queue.
4661 ncr_start_next_ccb(np
, lp
, 2);
4663 ncr_put_start_queue(np
, cp
);
4666 ** Command is successfully queued.
4673 /*==========================================================
4676 ** Insert a CCB into the start queue and wake up the
4677 ** SCRIPTS processor.
4680 **==========================================================
4683 static void ncr_start_next_ccb(ncb_p np
, lcb_p lp
, int maxn
)
4691 while (maxn
-- && lp
->queuedccbs
< lp
->queuedepth
) {
4692 qp
= xpt_remque_head(&lp
->wait_ccbq
);
4696 cp
= xpt_que_entry(qp
, struct ccb
, link_ccbq
);
4697 xpt_insque_tail(qp
, &lp
->busy_ccbq
);
4698 lp
->jump_ccb
[cp
->tag
== NO_TAG
? 0 : cp
->tag
] =
4699 cpu_to_scr(CCB_PHYS (cp
, restart
));
4700 ncr_put_start_queue(np
, cp
);
4704 static void ncr_put_start_queue(ncb_p np
, ccb_p cp
)
4709 ** insert into start queue.
4711 if (!np
->squeueput
) np
->squeueput
= 1;
4712 qidx
= np
->squeueput
+ 2;
4713 if (qidx
>= MAX_START
+ MAX_START
) qidx
= 1;
4715 np
->scripth
->tryloop
[qidx
] = cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
4717 np
->scripth
->tryloop
[np
->squeueput
] = cpu_to_scr(CCB_PHYS (cp
, start
));
4719 np
->squeueput
= qidx
;
4723 if (DEBUG_FLAGS
& DEBUG_QUEUE
)
4724 printk ("%s: queuepos=%d.\n", ncr_name (np
), np
->squeueput
);
4727 ** Script processor may be waiting for reselect.
4731 OUTB (nc_istat
, SIGP
);
4735 /*==========================================================
4738 ** Start reset process.
4739 ** If reset in progress do nothing.
4740 ** The interrupt handler will reinitialize the chip.
4741 ** The timeout handler will wait for settle_time before
4742 ** clearing it and so resuming command processing.
4745 **==========================================================
4747 static void ncr_start_reset(ncb_p np
)
4749 if (!np
->settle_time
) {
4750 (void) ncr_reset_scsi_bus(np
, 1, driver_setup
.settle_delay
);
4754 static int ncr_reset_scsi_bus(ncb_p np
, int enab_int
, int settle_delay
)
4759 np
->settle_time
= ktime_get(settle_delay
* HZ
);
4761 if (bootverbose
> 1)
4762 printk("%s: resetting, "
4763 "command processing suspended for %d seconds\n",
4764 ncr_name(np
), settle_delay
);
4766 ncr_chip_reset(np
, 100);
4767 UDELAY (2000); /* The 895 needs time for the bus mode to settle */
4769 OUTW (nc_sien
, RST
);
4771 ** Enable Tolerant, reset IRQD if present and
4772 ** properly set IRQ mode, prior to resetting the bus.
4774 OUTB (nc_stest3
, TE
);
4775 if (np
->device_id
!= PSEUDO_720_ID
)
4776 OUTB (nc_dcntl
, (np
->rv_dcntl
& IRQM
));
4777 OUTB (nc_scntl1
, CRST
);
4780 if (!driver_setup
.bus_check
)
4783 ** Check for no terminators or SCSI bus shorts to ground.
4784 ** Read SCSI data bus, data parity bits and control signals.
4785 ** We are expecting RESET to be TRUE and other signals to be
4789 term
= INB(nc_sstat0
);
4790 term
= ((term
& 2) << 7) + ((term
& 1) << 17); /* rst sdp0 */
4791 term
|= ((INB(nc_sstat2
) & 0x01) << 26) | /* sdp1 */
4792 ((INW(nc_sbdl
) & 0xff) << 9) | /* d7-0 */
4793 ((INW(nc_sbdl
) & 0xff00) << 10) | /* d15-8 */
4794 INB(nc_sbcl
); /* req ack bsy sel atn msg cd io */
4796 if (!(np
->features
& FE_WIDE
))
4799 if (term
!= (2<<7)) {
4800 printk("%s: suspicious SCSI data while resetting the BUS.\n",
4802 printk("%s: %sdp0,d7-0,rst,req,ack,bsy,sel,atn,msg,c/d,i/o = "
4803 "0x%lx, expecting 0x%lx\n",
4805 (np
->features
& FE_WIDE
) ? "dp1,d15-8," : "",
4806 (u_long
)term
, (u_long
)(2<<7));
4807 if (driver_setup
.bus_check
== 1)
4811 OUTB (nc_scntl1
, 0);
4815 /*==========================================================
4818 ** Reset the SCSI BUS.
4819 ** This is called from the generic SCSI driver.
4822 **==========================================================
4824 static int ncr_reset_bus (ncb_p np
, Scsi_Cmnd
*cmd
, int sync_reset
)
4826 /* Scsi_Device *device = cmd->device; */
4831 * Return immediately if reset is in progress.
4833 if (np
->settle_time
) {
4837 * Start the reset process.
4838 * The script processor is then assumed to be stopped.
4839 * Commands will now be queued in the waiting list until a settle
4840 * delay of 2 seconds will be completed.
4842 ncr_start_reset(np
);
4844 * First, look in the wakeup list
4846 for (found
=0, cp
=np
->ccb
; cp
; cp
=cp
->link_ccb
) {
4848 ** look for the ccb of this command.
4850 if (cp
->host_status
== HS_IDLE
) continue;
4851 if (cp
->cmd
== cmd
) {
4857 * Then, look in the waiting list
4859 if (!found
&& retrieve_from_waiting_list(0, np
, cmd
))
4862 * Wake-up all awaiting commands with DID_RESET.
4864 reset_waiting_list(np
);
4866 * Wake-up all pending commands with HS_RESET -> DID_RESET.
4868 ncr_wakeup(np
, HS_RESET
);
4870 * If the involved command was not in a driver queue, and the
4871 * scsi driver told us reset is synchronous, and the command is not
4872 * currently in the waiting list, complete it with DID_RESET status,
4873 * in order to keep it alive.
4875 if (!found
&& sync_reset
&& !retrieve_from_waiting_list(0, np
, cmd
)) {
4876 cmd
->result
= ScsiResult(DID_RESET
, 0);
4877 ncr_queue_done_cmd(np
, cmd
);
4883 /*==========================================================
4886 ** Abort an SCSI command.
4887 ** This is called from the generic SCSI driver.
4890 **==========================================================
4892 static int ncr_abort_command (ncb_p np
, Scsi_Cmnd
*cmd
)
4894 /* Scsi_Device *device = cmd->device; */
4900 * First, look for the scsi command in the waiting list
4902 if (remove_from_waiting_list(np
, cmd
)) {
4903 cmd
->result
= ScsiResult(DID_ABORT
, 0);
4904 ncr_queue_done_cmd(np
, cmd
);
4905 return SCSI_ABORT_SUCCESS
;
4909 * Then, look in the wakeup list
4911 for (found
=0, cp
=np
->ccb
; cp
; cp
=cp
->link_ccb
) {
4913 ** look for the ccb of this command.
4915 if (cp
->host_status
== HS_IDLE
) continue;
4916 if (cp
->cmd
== cmd
) {
4923 return SCSI_ABORT_NOT_RUNNING
;
4926 if (np
->settle_time
) {
4927 return SCSI_ABORT_SNOOZE
;
4931 ** If the CCB is active, patch schedule jumps for the
4932 ** script to abort the command.
4935 switch(cp
->host_status
) {
4938 printk ("%s: abort ccb=%p (cancel)\n", ncr_name (np
), cp
);
4939 cp
->start
.schedule
.l_paddr
=
4940 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, cancel
));
4941 retv
= SCSI_ABORT_PENDING
;
4944 cp
->restart
.schedule
.l_paddr
=
4945 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, abort
));
4946 retv
= SCSI_ABORT_PENDING
;
4949 retv
= SCSI_ABORT_NOT_RUNNING
;
4955 ** If there are no requests, the script
4956 ** processor will sleep on SEL_WAIT_RESEL.
4957 ** Let's wake it up, since it may have to work.
4959 OUTB (nc_istat
, SIGP
);
4964 /*==========================================================
4966 ** Linux release module stuff.
4968 ** Called before unloading the module
4970 ** We have to free resources and halt the NCR chip
4972 **==========================================================
4975 static int ncr_detach(ncb_p np
)
4984 /* Local copy so we don't access np after freeing it! */
4985 strlcpy(inst_name
, ncr_name(np
), sizeof(inst_name
));
4987 printk("%s: releasing host resources\n", ncr_name(np
));
4990 ** Stop the ncr_timeout process
4991 ** Set release_stage to 1 and wait that ncr_timeout() set it to 2.
4994 #ifdef DEBUG_NCR53C8XX
4995 printk("%s: stopping the timer\n", ncr_name(np
));
4997 np
->release_stage
= 1;
4998 for (i
= 50 ; i
&& np
->release_stage
!= 2 ; i
--) MDELAY (100);
4999 if (np
->release_stage
!= 2)
5000 printk("%s: the timer seems to be already stopped\n", ncr_name(np
));
5001 else np
->release_stage
= 2;
5004 ** Disable chip interrupts
5007 #ifdef DEBUG_NCR53C8XX
5008 printk("%s: disabling chip interrupts\n", ncr_name(np
));
5015 ** Restore bios setting for automatic clock detection.
5018 printk("%s: resetting chip\n", ncr_name(np
));
5019 ncr_chip_reset(np
, 100);
5021 OUTB(nc_dmode
, np
->sv_dmode
);
5022 OUTB(nc_dcntl
, np
->sv_dcntl
);
5023 OUTB(nc_ctest0
, np
->sv_ctest0
);
5024 OUTB(nc_ctest3
, np
->sv_ctest3
);
5025 OUTB(nc_ctest4
, np
->sv_ctest4
);
5026 OUTB(nc_ctest5
, np
->sv_ctest5
);
5027 OUTB(nc_gpcntl
, np
->sv_gpcntl
);
5028 OUTB(nc_stest2
, np
->sv_stest2
);
5030 ncr_selectclock(np
, np
->sv_scntl3
);
5033 ** Free allocated ccb(s)
5036 while ((cp
=np
->ccb
->link_ccb
) != NULL
) {
5037 np
->ccb
->link_ccb
= cp
->link_ccb
;
5038 if (cp
->host_status
) {
5039 printk("%s: shall free an active ccb (host_status=%d)\n",
5040 ncr_name(np
), cp
->host_status
);
5042 #ifdef DEBUG_NCR53C8XX
5043 printk("%s: freeing ccb (%lx)\n", ncr_name(np
), (u_long
) cp
);
5045 m_free_dma(cp
, sizeof(*cp
), "CCB");
5049 ** Free allocated tp(s)
5052 for (target
= 0; target
< MAX_TARGET
; target
++) {
5053 tp
=&np
->target
[target
];
5054 for (lun
= 0 ; lun
< MAX_LUN
; lun
++) {
5057 #ifdef DEBUG_NCR53C8XX
5058 printk("%s: freeing lp (%lx)\n", ncr_name(np
), (u_long
) lp
);
5060 if (lp
->jump_ccb
!= &lp
->jump_ccb_0
)
5061 m_free_dma(lp
->jump_ccb
,256,"JUMP_CCB");
5062 m_free_dma(lp
, sizeof(*lp
), "LCB");
5068 m_free_dma(np
->scripth0
, sizeof(struct scripth
), "SCRIPTH");
5070 m_free_dma(np
->script0
, sizeof(struct script
), "SCRIPT");
5072 m_free_dma(np
->ccb
, sizeof(struct ccb
), "CCB");
5073 m_free_dma(np
, sizeof(struct ncb
), "NCB");
5075 printk("%s: host resources successfully released\n", inst_name
);
5080 /*==========================================================
5083 ** Complete execution of a SCSI command.
5084 ** Signal completion to the generic SCSI driver.
5087 **==========================================================
5090 void ncr_complete (ncb_p np
, ccb_p cp
)
5100 if (!cp
|| cp
->magic
!= CCB_MAGIC
|| !cp
->cmd
)
5104 ** Print minimal debug information.
5107 if (DEBUG_FLAGS
& DEBUG_TINY
)
5108 printk ("CCB=%lx STAT=%x/%x\n", (unsigned long)cp
,
5109 cp
->host_status
,cp
->scsi_status
);
5112 ** Get command, target and lun pointers.
5117 tp
= &np
->target
[cmd
->device
->id
];
5118 lp
= tp
->lp
[cmd
->device
->lun
];
5121 ** We donnot queue more than 1 ccb per target
5122 ** with negotiation at any time. If this ccb was
5123 ** used for negotiation, clear this info in the tcb.
5126 if (cp
== tp
->nego_cp
)
5130 ** If auto-sense performed, change scsi status.
5132 if (cp
->auto_sense
) {
5133 cp
->scsi_status
= cp
->auto_sense
;
5137 ** If we were recovering from queue full or performing
5138 ** auto-sense, requeue skipped CCBs to the wait queue.
5141 if (lp
&& lp
->held_ccb
) {
5142 if (cp
== lp
->held_ccb
) {
5143 xpt_que_splice(&lp
->skip_ccbq
, &lp
->wait_ccbq
);
5144 xpt_que_init(&lp
->skip_ccbq
);
5150 ** Check for parity errors.
5153 if (cp
->parity_status
> 1) {
5155 printk ("%d parity error(s).\n",cp
->parity_status
);
5159 ** Check for extended errors.
5162 if (cp
->xerr_status
!= XE_OK
) {
5164 switch (cp
->xerr_status
) {
5166 printk ("extraneous data discarded.\n");
5169 printk ("illegal scsi phase (4/5).\n");
5172 printk ("extended error %d.\n", cp
->xerr_status
);
5175 if (cp
->host_status
==HS_COMPLETE
)
5176 cp
->host_status
= HS_FAIL
;
5180 ** Print out any error for debugging purpose.
5182 if (DEBUG_FLAGS
& (DEBUG_RESULT
|DEBUG_TINY
)) {
5183 if (cp
->host_status
!=HS_COMPLETE
|| cp
->scsi_status
!=S_GOOD
) {
5185 printk ("ERROR: cmd=%x host_status=%x scsi_status=%x\n",
5186 cmd
->cmnd
[0], cp
->host_status
, cp
->scsi_status
);
5191 ** Check the status.
5193 if ( (cp
->host_status
== HS_COMPLETE
)
5194 && (cp
->scsi_status
== S_GOOD
||
5195 cp
->scsi_status
== S_COND_MET
)) {
5197 ** All went well (GOOD status).
5198 ** CONDITION MET status is returned on
5199 ** `Pre-Fetch' or `Search data' success.
5201 cmd
->result
= ScsiResult(DID_OK
, cp
->scsi_status
);
5205 ** Could dig out the correct value for resid,
5206 ** but it would be quite complicated.
5208 /* if (cp->phys.header.lastp != cp->phys.header.goalp) */
5211 ** Allocate the lcb if not yet.
5214 ncr_alloc_lcb (np
, cmd
->device
->id
, cmd
->device
->lun
);
5217 ** On standard INQUIRY response (EVPD and CmDt
5218 ** not set), setup logical unit according to
5219 ** announced capabilities (we need the 1rst 7 bytes).
5221 if (cmd
->cmnd
[0] == 0x12 && !(cmd
->cmnd
[1] & 0x3) &&
5222 cmd
->cmnd
[4] >= 7 && !cmd
->use_sg
) {
5223 sync_scsi_data(np
, cmd
); /* SYNC the data */
5224 ncr_setup_lcb (np
, cmd
->device
->id
, cmd
->device
->lun
,
5225 (char *) cmd
->request_buffer
);
5228 tp
->bytes
+= cp
->data_len
;
5232 ** If tags was reduced due to queue full,
5233 ** increase tags if 1000 good status received.
5235 if (lp
&& lp
->usetags
&& lp
->numtags
< lp
->maxtags
) {
5237 if (lp
->num_good
>= 1000) {
5240 ncr_setup_tags (np
, cmd
->device
->id
, cmd
->device
->lun
);
5243 } else if ((cp
->host_status
== HS_COMPLETE
)
5244 && (cp
->scsi_status
== S_CHECK_COND
)) {
5246 ** Check condition code
5248 cmd
->result
= ScsiResult(DID_OK
, S_CHECK_COND
);
5251 ** Copy back sense data to caller's buffer.
5253 memcpy(cmd
->sense_buffer
, cp
->sense_buf
,
5254 MIN(sizeof(cmd
->sense_buffer
), sizeof(cp
->sense_buf
)));
5256 if (DEBUG_FLAGS
& (DEBUG_RESULT
|DEBUG_TINY
)) {
5257 u_char
* p
= (u_char
*) & cmd
->sense_buffer
;
5260 printk ("sense data:");
5261 for (i
=0; i
<14; i
++) printk (" %x", *p
++);
5264 } else if ((cp
->host_status
== HS_COMPLETE
)
5265 && (cp
->scsi_status
== S_CONFLICT
)) {
5267 ** Reservation Conflict condition code
5269 cmd
->result
= ScsiResult(DID_OK
, S_CONFLICT
);
5271 } else if ((cp
->host_status
== HS_COMPLETE
)
5272 && (cp
->scsi_status
== S_BUSY
||
5273 cp
->scsi_status
== S_QUEUE_FULL
)) {
5278 cmd
->result
= ScsiResult(DID_OK
, cp
->scsi_status
);
5280 } else if ((cp
->host_status
== HS_SEL_TIMEOUT
)
5281 || (cp
->host_status
== HS_TIMEOUT
)) {
5286 cmd
->result
= ScsiResult(DID_TIME_OUT
, cp
->scsi_status
);
5288 } else if (cp
->host_status
== HS_RESET
) {
5293 cmd
->result
= ScsiResult(DID_RESET
, cp
->scsi_status
);
5295 } else if (cp
->host_status
== HS_ABORTED
) {
5300 cmd
->result
= ScsiResult(DID_ABORT
, cp
->scsi_status
);
5305 ** Other protocol messes
5308 printk ("COMMAND FAILED (%x %x) @%p.\n",
5309 cp
->host_status
, cp
->scsi_status
, cp
);
5311 cmd
->result
= ScsiResult(DID_ERROR
, cp
->scsi_status
);
5318 if (tp
->usrflag
& UF_TRACE
) {
5323 p
= (u_char
*) &cmd
->cmnd
[0];
5324 for (i
=0; i
<cmd
->cmd_len
; i
++) printk (" %x", *p
++);
5326 if (cp
->host_status
==HS_COMPLETE
) {
5327 switch (cp
->scsi_status
) {
5333 p
= (u_char
*) &cmd
->sense_buffer
;
5334 for (i
=0; i
<14; i
++)
5335 printk (" %x", *p
++);
5338 printk (" STAT: %x\n", cp
->scsi_status
);
5341 } else printk (" HOSTERROR: %x", cp
->host_status
);
5348 ncr_free_ccb (np
, cp
);
5351 ** requeue awaiting scsi commands for this lun.
5353 if (lp
&& lp
->queuedccbs
< lp
->queuedepth
&&
5354 !xpt_que_empty(&lp
->wait_ccbq
))
5355 ncr_start_next_ccb(np
, lp
, 2);
5358 ** requeue awaiting scsi commands for this controller.
5360 if (np
->waiting_list
)
5361 requeue_waiting_list(np
);
5364 ** signal completion to generic driver.
5366 ncr_queue_done_cmd(np
, cmd
);
5369 /*==========================================================
5372 ** Signal all (or one) control block done.
5375 **==========================================================
5379 ** This CCB has been skipped by the NCR.
5380 ** Queue it in the correponding unit queue.
5382 static void ncr_ccb_skipped(ncb_p np
, ccb_p cp
)
5384 tcb_p tp
= &np
->target
[cp
->target
];
5385 lcb_p lp
= tp
->lp
[cp
->lun
];
5387 if (lp
&& cp
!= np
->ccb
) {
5388 cp
->host_status
&= ~HS_SKIPMASK
;
5389 cp
->start
.schedule
.l_paddr
=
5390 cpu_to_scr(NCB_SCRIPT_PHYS (np
, select
));
5391 xpt_remque(&cp
->link_ccbq
);
5392 xpt_insque_tail(&cp
->link_ccbq
, &lp
->skip_ccbq
);
5404 ** The NCR has completed CCBs.
5405 ** Look at the DONE QUEUE if enabled, otherwise scan all CCBs
5407 void ncr_wakeup_done (ncb_p np
)
5410 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
5413 i
= np
->ccb_done_ic
;
5419 cp
= np
->ccb_done
[j
];
5420 if (!CCB_DONE_VALID(cp
))
5423 np
->ccb_done
[j
] = (ccb_p
) CCB_DONE_EMPTY
;
5424 np
->scripth
->done_queue
[5*j
+ 4] =
5425 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_plug
));
5427 np
->scripth
->done_queue
[5*i
+ 4] =
5428 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_end
));
5430 if (cp
->host_status
& HS_DONEMASK
)
5431 ncr_complete (np
, cp
);
5432 else if (cp
->host_status
& HS_SKIPMASK
)
5433 ncr_ccb_skipped (np
, cp
);
5437 np
->ccb_done_ic
= i
;
5441 if (cp
->host_status
& HS_DONEMASK
)
5442 ncr_complete (np
, cp
);
5443 else if (cp
->host_status
& HS_SKIPMASK
)
5444 ncr_ccb_skipped (np
, cp
);
5451 ** Complete all active CCBs.
5453 void ncr_wakeup (ncb_p np
, u_long code
)
5458 if (cp
->host_status
!= HS_IDLE
) {
5459 cp
->host_status
= code
;
5460 ncr_complete (np
, cp
);
5470 /* Some initialisation must be done immediately following reset, for 53c720,
5471 * at least. EA (dcntl bit 5) isn't set here as it is set once only in
5472 * the _detect function.
5474 static void ncr_chip_reset(ncb_p np
, int delay
)
5476 OUTB (nc_istat
, SRST
);
5478 OUTB (nc_istat
, 0 );
5480 if (np
->features
& FE_EHP
)
5481 OUTB (nc_ctest0
, EHP
);
5482 if (np
->features
& FE_MUX
)
5483 OUTB (nc_ctest4
, MUX
);
5487 /*==========================================================
5493 **==========================================================
5496 void ncr_init (ncb_p np
, int reset
, char * msg
, u_long code
)
5501 ** Reset chip if asked, otherwise just clear fifos.
5505 OUTB (nc_istat
, SRST
);
5509 OUTB (nc_stest3
, TE
|CSF
);
5510 OUTONB (nc_ctest3
, CLF
);
5517 if (msg
) printk (KERN_INFO
"%s: restart (%s).\n", ncr_name (np
), msg
);
5520 ** Clear Start Queue
5522 np
->queuedepth
= MAX_START
- 1; /* 1 entry needed as end marker */
5523 for (i
= 1; i
< MAX_START
+ MAX_START
; i
+= 2)
5524 np
->scripth0
->tryloop
[i
] =
5525 cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
5528 ** Start at first entry.
5531 np
->script0
->startpos
[0] = cpu_to_scr(NCB_SCRIPTH_PHYS (np
, tryloop
));
5533 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
5537 for (i
= 0; i
< MAX_DONE
; i
++) {
5538 np
->ccb_done
[i
] = (ccb_p
) CCB_DONE_EMPTY
;
5539 np
->scripth0
->done_queue
[5*i
+ 4] =
5540 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_end
));
5545 ** Start at first entry.
5547 np
->script0
->done_pos
[0] = cpu_to_scr(NCB_SCRIPTH_PHYS (np
,done_queue
));
5548 np
->ccb_done_ic
= MAX_DONE
-1;
5549 np
->scripth0
->done_queue
[5*(MAX_DONE
-1) + 4] =
5550 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_plug
));
5553 ** Wakeup all pending jobs.
5555 ncr_wakeup (np
, code
);
5562 ** Remove reset; big delay because the 895 needs time for the
5563 ** bus mode to settle
5565 ncr_chip_reset(np
, 2000);
5567 OUTB (nc_scntl0
, np
->rv_scntl0
| 0xc0);
5568 /* full arb., ena parity, par->ATN */
5569 OUTB (nc_scntl1
, 0x00); /* odd parity, and remove CRST!! */
5571 ncr_selectclock(np
, np
->rv_scntl3
); /* Select SCSI clock */
5573 OUTB (nc_scid
, RRE
|np
->myaddr
); /* Adapter SCSI address */
5574 OUTW (nc_respid
, 1ul<<np
->myaddr
); /* Id to respond to */
5575 OUTB (nc_istat
, SIGP
); /* Signal Process */
5576 OUTB (nc_dmode
, np
->rv_dmode
); /* Burst length, dma mode */
5577 OUTB (nc_ctest5
, np
->rv_ctest5
); /* Large fifo + large burst */
5579 OUTB (nc_dcntl
, NOCOM
|np
->rv_dcntl
); /* Protect SFBR */
5580 OUTB (nc_ctest0
, np
->rv_ctest0
); /* 720: CDIS and EHP */
5581 OUTB (nc_ctest3
, np
->rv_ctest3
); /* Write and invalidate */
5582 OUTB (nc_ctest4
, np
->rv_ctest4
); /* Master parity checking */
5584 OUTB (nc_stest2
, EXT
|np
->rv_stest2
); /* Extended Sreq/Sack filtering */
5585 OUTB (nc_stest3
, TE
); /* TolerANT enable */
5586 OUTB (nc_stime0
, 0x0c ); /* HTH disabled STO 0.25 sec */
5589 ** Disable disconnects.
5595 ** Enable GPIO0 pin for writing if LED support.
5598 if (np
->features
& FE_LED0
) {
5599 OUTOFFB (nc_gpcntl
, 0x01);
5606 OUTW (nc_sien
, STO
|HTH
|MA
|SGE
|UDC
|RST
|PAR
);
5607 OUTB (nc_dien
, MDPE
|BF
|ABRT
|SSI
|SIR
|IID
);
5610 ** For 895/6 enable SBMC interrupt and save current SCSI bus mode.
5612 if (np
->features
& FE_ULTRA2
) {
5613 OUTONW (nc_sien
, SBMC
);
5614 np
->scsi_mode
= INB (nc_stest4
) & SMODE
;
5618 ** DEL 441 - 53C876 Rev 5 - Part Number 609-0392787/2788 - ITEM 2.
5619 ** Disable overlapped arbitration.
5620 ** All 896 chips are also affected by this errata.
5622 if (np
->device_id
== PCI_DEVICE_ID_NCR_53C875
)
5623 OUTB (nc_ctest0
, (1<<5));
5624 else if (np
->device_id
== PCI_DEVICE_ID_NCR_53C896
)
5625 OUTB (nc_ccntl0
, DPR
);
5628 ** Fill in target structure.
5629 ** Reinitialize usrsync.
5630 ** Reinitialize usrwide.
5631 ** Prepare sync negotiation according to actual SCSI bus mode.
5634 for (i
=0;i
<MAX_TARGET
;i
++) {
5635 tcb_p tp
= &np
->target
[i
];
5638 tp
->wval
= np
->rv_scntl3
;
5640 if (tp
->usrsync
!= 255) {
5641 if (tp
->usrsync
<= np
->maxsync
) {
5642 if (tp
->usrsync
< np
->minsync
) {
5643 tp
->usrsync
= np
->minsync
;
5650 if (tp
->usrwide
> np
->maxwide
)
5651 tp
->usrwide
= np
->maxwide
;
5653 ncr_negotiate (np
, tp
);
5657 ** Start script processor.
5661 printk ("%s: Downloading SCSI SCRIPTS.\n",
5663 OUTL (nc_scratcha
, vtobus(np
->script0
));
5664 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, start_ram
));
5667 OUTL_DSP (NCB_SCRIPT_PHYS (np
, start
));
5670 /*==========================================================
5672 ** Prepare the negotiation values for wide and
5673 ** synchronous transfers.
5675 **==========================================================
5678 static void ncr_negotiate (struct ncb
* np
, struct tcb
* tp
)
5681 ** minsync unit is 4ns !
5684 u_long minsync
= tp
->usrsync
;
5687 ** SCSI bus mode limit
5690 if (np
->scsi_mode
&& np
->scsi_mode
== SMODE_SE
) {
5691 if (minsync
< 12) minsync
= 12;
5698 if (minsync
< np
->minsync
)
5699 minsync
= np
->minsync
;
5705 if (minsync
> np
->maxsync
)
5708 tp
->minsync
= minsync
;
5709 tp
->maxoffs
= (minsync
<255 ? np
->maxoffs
: 0);
5712 ** period=0: has to negotiate sync transfer
5718 ** widedone=0: has to negotiate wide transfer
5723 /*==========================================================
5725 ** Get clock factor and sync divisor for a given
5726 ** synchronous factor period.
5727 ** Returns the clock factor (in sxfer) and scntl3
5728 ** synchronous divisor field.
5730 **==========================================================
5733 static void ncr_getsync(ncb_p np
, u_char sfac
, u_char
*fakp
, u_char
*scntl3p
)
5735 u_long clk
= np
->clock_khz
; /* SCSI clock frequency in kHz */
5736 int div
= np
->clock_divn
; /* Number of divisors supported */
5737 u_long fak
; /* Sync factor in sxfer */
5738 u_long per
; /* Period in tenths of ns */
5739 u_long kpc
; /* (per * clk) */
5742 ** Compute the synchronous period in tenths of nano-seconds
5744 if (sfac
<= 10) per
= 250;
5745 else if (sfac
== 11) per
= 303;
5746 else if (sfac
== 12) per
= 500;
5747 else per
= 40 * sfac
;
5750 ** Look for the greatest clock divisor that allows an
5751 ** input speed faster than the period.
5755 if (kpc
>= (div_10M
[div
] << 2)) break;
5758 ** Calculate the lowest clock factor that allows an output
5759 ** speed not faster than the period.
5761 fak
= (kpc
- 1) / div_10M
[div
] + 1;
5763 #if 0 /* This optimization does not seem very useful */
5765 per
= (fak
* div_10M
[div
]) / clk
;
5768 ** Why not to try the immediate lower divisor and to choose
5769 ** the one that allows the fastest output speed ?
5770 ** We don't want input speed too much greater than output speed.
5772 if (div
>= 1 && fak
< 8) {
5774 fak2
= (kpc
- 1) / div_10M
[div
-1] + 1;
5775 per2
= (fak2
* div_10M
[div
-1]) / clk
;
5776 if (per2
< per
&& fak2
<= 8) {
5784 if (fak
< 4) fak
= 4; /* Should never happen, too bad ... */
5787 ** Compute and return sync parameters for the ncr
5790 *scntl3p
= ((div
+1) << 4) + (sfac
< 25 ? 0x80 : 0);
5794 /*==========================================================
5796 ** Set actual values, sync status and patch all ccbs of
5797 ** a target according to new sync/wide agreement.
5799 **==========================================================
5802 static void ncr_set_sync_wide_status (ncb_p np
, u_char target
)
5805 tcb_p tp
= &np
->target
[target
];
5808 ** set actual value and sync_status
5810 OUTB (nc_sxfer
, tp
->sval
);
5811 np
->sync_st
= tp
->sval
;
5812 OUTB (nc_scntl3
, tp
->wval
);
5813 np
->wide_st
= tp
->wval
;
5816 ** patch ALL ccbs of this target.
5818 for (cp
= np
->ccb
; cp
; cp
= cp
->link_ccb
) {
5819 if (!cp
->cmd
) continue;
5820 if (cp
->cmd
->device
->id
!= target
) continue;
5822 cp
->sync_status
= tp
->sval
;
5823 cp
->wide_status
= tp
->wval
;
5825 cp
->phys
.select
.sel_scntl3
= tp
->wval
;
5826 cp
->phys
.select
.sel_sxfer
= tp
->sval
;
5830 /*==========================================================
5832 ** Switch sync mode for current job and it's target
5834 **==========================================================
5837 static void ncr_setsync (ncb_p np
, ccb_p cp
, u_char scntl3
, u_char sxfer
)
5841 u_char target
= INB (nc_sdid
) & 0x0f;
5844 assert (cp
&& cp
->cmd
);
5850 assert (target
== (cmd
->device
->id
& 0xf));
5852 tp
= &np
->target
[target
];
5854 if (!scntl3
|| !(sxfer
& 0x1f))
5855 scntl3
= np
->rv_scntl3
;
5856 scntl3
= (scntl3
& 0xf0) | (tp
->wval
& EWS
) | (np
->rv_scntl3
& 0x07);
5859 ** Deduce the value of controller sync period from scntl3.
5860 ** period is in tenths of nano-seconds.
5863 idiv
= ((scntl3
>> 4) & 0x7);
5864 if ((sxfer
& 0x1f) && idiv
)
5865 tp
->period
= (((sxfer
>>5)+4)*div_10M
[idiv
-1])/np
->clock_khz
;
5867 tp
->period
= 0xffff;
5870 ** Stop there if sync parameters are unchanged
5872 if (tp
->sval
== sxfer
&& tp
->wval
== scntl3
) return;
5877 ** Bells and whistles ;-)
5879 PRINT_TARGET(np
, target
);
5880 if (sxfer
& 0x01f) {
5881 unsigned f10
= 100000 << (tp
->widedone
? tp
->widedone
-1 : 0);
5882 unsigned mb10
= (f10
+ tp
->period
/2) / tp
->period
;
5886 ** Disable extended Sreq/Sack filtering
5888 if (tp
->period
<= 2000) OUTOFFB (nc_stest2
, EXT
);
5891 ** Bells and whistles ;-)
5893 if (tp
->period
< 500) scsi
= "FAST-40";
5894 else if (tp
->period
< 1000) scsi
= "FAST-20";
5895 else if (tp
->period
< 2000) scsi
= "FAST-10";
5896 else scsi
= "FAST-5";
5898 printk ("%s %sSCSI %d.%d MB/s (%d ns, offset %d)\n", scsi
,
5899 tp
->widedone
> 1 ? "WIDE " : "",
5900 mb10
/ 10, mb10
% 10, tp
->period
/ 10, sxfer
& 0x1f);
5902 printk ("%sasynchronous.\n", tp
->widedone
> 1 ? "wide " : "");
5905 ** set actual value and sync_status
5906 ** patch ALL ccbs of this target.
5908 ncr_set_sync_wide_status(np
, target
);
5911 /*==========================================================
5913 ** Switch wide mode for current job and it's target
5914 ** SCSI specs say: a SCSI device that accepts a WDTR
5915 ** message shall reset the synchronous agreement to
5916 ** asynchronous mode.
5918 **==========================================================
5921 static void ncr_setwide (ncb_p np
, ccb_p cp
, u_char wide
, u_char ack
)
5924 u_short target
= INB (nc_sdid
) & 0x0f;
5929 assert (cp
&& cp
->cmd
);
5935 assert (target
== (cmd
->device
->id
& 0xf));
5937 tp
= &np
->target
[target
];
5938 tp
->widedone
= wide
+1;
5939 scntl3
= (tp
->wval
& (~EWS
)) | (wide
? EWS
: 0);
5941 sxfer
= ack
? 0 : tp
->sval
;
5944 ** Stop there if sync/wide parameters are unchanged
5946 if (tp
->sval
== sxfer
&& tp
->wval
== scntl3
) return;
5951 ** Bells and whistles ;-)
5953 if (bootverbose
>= 2) {
5954 PRINT_TARGET(np
, target
);
5956 printk ("WIDE SCSI (16 bit) enabled.\n");
5958 printk ("WIDE SCSI disabled.\n");
5962 ** set actual value and sync_status
5963 ** patch ALL ccbs of this target.
5965 ncr_set_sync_wide_status(np
, target
);
5968 /*==========================================================
5970 ** Switch tagged mode for a target.
5972 **==========================================================
5975 static void ncr_setup_tags (ncb_p np
, u_char tn
, u_char ln
)
5977 tcb_p tp
= &np
->target
[tn
];
5978 lcb_p lp
= tp
->lp
[ln
];
5979 u_char reqtags
, maxdepth
;
5988 ** If SCSI device queue depth is not yet set, leave here.
5990 if (!lp
->scdev_depth
)
5994 ** Donnot allow more tags than the SCSI driver can queue
5996 ** Donnot allow more tags than we can handle.
5998 maxdepth
= lp
->scdev_depth
;
5999 if (maxdepth
> lp
->maxnxs
) maxdepth
= lp
->maxnxs
;
6000 if (lp
->maxtags
> maxdepth
) lp
->maxtags
= maxdepth
;
6001 if (lp
->numtags
> maxdepth
) lp
->numtags
= maxdepth
;
6004 ** only devices conformant to ANSI Version >= 2
6005 ** only devices capable of tagged commands
6006 ** only if enabled by user ..
6008 if ((lp
->inq_byte7
& INQ7_QUEUE
) && lp
->numtags
> 1) {
6009 reqtags
= lp
->numtags
;
6015 ** Update max number of tags
6017 lp
->numtags
= reqtags
;
6018 if (lp
->numtags
> lp
->maxtags
)
6019 lp
->maxtags
= lp
->numtags
;
6022 ** If we want to switch tag mode, we must wait
6023 ** for no CCB to be active.
6025 if (reqtags
> 1 && lp
->usetags
) { /* Stay in tagged mode */
6026 if (lp
->queuedepth
== reqtags
) /* Already announced */
6028 lp
->queuedepth
= reqtags
;
6030 else if (reqtags
<= 1 && !lp
->usetags
) { /* Stay in untagged mode */
6031 lp
->queuedepth
= reqtags
;
6034 else { /* Want to switch tag mode */
6035 if (lp
->busyccbs
) /* If not yet safe, return */
6037 lp
->queuedepth
= reqtags
;
6038 lp
->usetags
= reqtags
> 1 ? 1 : 0;
6042 ** Patch the lun mini-script, according to tag mode.
6044 lp
->jump_tag
.l_paddr
= lp
->usetags
?
6045 cpu_to_scr(NCB_SCRIPT_PHYS(np
, resel_tag
)) :
6046 cpu_to_scr(NCB_SCRIPT_PHYS(np
, resel_notag
));
6049 ** Announce change to user.
6052 PRINT_LUN(np
, tn
, ln
);
6054 printk("tagged command queue depth set to %d\n", reqtags
);
6057 printk("tagged command queueing disabled\n");
6062 /*----------------------------------------------------
6064 ** handle user commands
6066 **----------------------------------------------------
6069 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
6071 static void ncr_usercmd (ncb_p np
)
6076 switch (np
->user
.cmd
) {
6081 for (t
=0; t
<MAX_TARGET
; t
++) {
6082 if (!((np
->user
.target
>>t
)&1)) continue;
6083 tp
= &np
->target
[t
];
6084 tp
->usrsync
= np
->user
.data
;
6085 ncr_negotiate (np
, tp
);
6090 for (t
=0; t
<MAX_TARGET
; t
++) {
6092 if (!((np
->user
.target
>>t
)&1)) continue;
6093 np
->target
[t
].usrtags
= np
->user
.data
;
6094 for (ln
= 0; ln
< MAX_LUN
; ln
++) {
6095 lcb_p lp
= np
->target
[t
].lp
[ln
];
6098 lp
->maxtags
= lp
->numtags
= np
->user
.data
;
6099 ncr_setup_tags (np
, t
, ln
);
6105 #ifdef SCSI_NCR_DEBUG_INFO_SUPPORT
6106 ncr_debug
= np
->user
.data
;
6111 np
->order
= np
->user
.data
;
6115 np
->verbose
= np
->user
.data
;
6119 for (t
=0; t
<MAX_TARGET
; t
++) {
6121 if (!((np
->user
.target
>>t
)&1)) continue;
6122 tp
= &np
->target
[t
];
6123 size
= np
->user
.data
;
6124 if (size
> np
->maxwide
) size
=np
->maxwide
;
6126 ncr_negotiate (np
, tp
);
6131 for (t
=0; t
<MAX_TARGET
; t
++) {
6132 if (!((np
->user
.target
>>t
)&1)) continue;
6133 tp
= &np
->target
[t
];
6134 tp
->usrflag
= np
->user
.data
;
6142 /*==========================================================
6145 ** ncr timeout handler.
6148 **==========================================================
6150 ** Misused to keep the driver running when
6151 ** interrupts are not configured correctly.
6153 **----------------------------------------------------------
6156 static void ncr_timeout (ncb_p np
)
6158 u_long thistime
= ktime_get(0);
6161 ** If release process in progress, let's go
6162 ** Set the release stage from 1 to 2 to synchronize
6163 ** with the release process.
6166 if (np
->release_stage
) {
6167 if (np
->release_stage
== 1) np
->release_stage
= 2;
6171 np
->timer
.expires
= ktime_get(SCSI_NCR_TIMER_INTERVAL
);
6172 add_timer(&np
->timer
);
6175 ** If we are resetting the ncr, wait for settle_time before
6176 ** clearing it. Then command processing will be resumed.
6178 if (np
->settle_time
) {
6179 if (np
->settle_time
<= thistime
) {
6180 if (bootverbose
> 1)
6181 printk("%s: command processing resumed\n", ncr_name(np
));
6182 np
->settle_time
= 0;
6184 requeue_waiting_list(np
);
6190 ** Since the generic scsi driver only allows us 0.5 second
6191 ** to perform abort of a command, we must look at ccbs about
6192 ** every 0.25 second.
6194 if (np
->lasttime
+ 4*HZ
< thistime
) {
6196 ** block ncr interrupts
6198 np
->lasttime
= thistime
;
6201 #ifdef SCSI_NCR_BROKEN_INTR
6202 if (INB(nc_istat
) & (INTF
|SIP
|DIP
)) {
6205 ** Process pending interrupts.
6207 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("{");
6209 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("}");
6211 #endif /* SCSI_NCR_BROKEN_INTR */
6214 /*==========================================================
6216 ** log message for real hard errors
6218 ** "ncr0 targ 0?: ERROR (ds:si) (so-si-sd) (sxfer/scntl3) @ name (dsp:dbc)."
6219 ** " reg: r0 r1 r2 r3 r4 r5 r6 ..... rf."
6221 ** exception register:
6226 ** so: control lines as driver by NCR.
6227 ** si: control lines as seen by NCR.
6228 ** sd: scsi data lines as seen by NCR.
6231 ** sxfer: (see the manual)
6232 ** scntl3: (see the manual)
6234 ** current script command:
6235 ** dsp: script address (relative to start of script).
6236 ** dbc: first word of script command.
6238 ** First 16 register of the chip:
6241 **==========================================================
6244 static void ncr_log_hard_error(ncb_p np
, u_short sist
, u_char dstat
)
6250 u_char
*script_base
;
6255 if (dsp
> np
->p_script
&& dsp
<= np
->p_script
+ sizeof(struct script
)) {
6256 script_ofs
= dsp
- np
->p_script
;
6257 script_size
= sizeof(struct script
);
6258 script_base
= (u_char
*) np
->script0
;
6259 script_name
= "script";
6261 else if (np
->p_scripth
< dsp
&&
6262 dsp
<= np
->p_scripth
+ sizeof(struct scripth
)) {
6263 script_ofs
= dsp
- np
->p_scripth
;
6264 script_size
= sizeof(struct scripth
);
6265 script_base
= (u_char
*) np
->scripth0
;
6266 script_name
= "scripth";
6271 script_name
= "mem";
6274 printk ("%s:%d: ERROR (%x:%x) (%x-%x-%x) (%x/%x) @ (%s %x:%08x).\n",
6275 ncr_name (np
), (unsigned)INB (nc_sdid
)&0x0f, dstat
, sist
,
6276 (unsigned)INB (nc_socl
), (unsigned)INB (nc_sbcl
), (unsigned)INB (nc_sbdl
),
6277 (unsigned)INB (nc_sxfer
),(unsigned)INB (nc_scntl3
), script_name
, script_ofs
,
6278 (unsigned)INL (nc_dbc
));
6280 if (((script_ofs
& 3) == 0) &&
6281 (unsigned)script_ofs
< script_size
) {
6282 printk ("%s: script cmd = %08x\n", ncr_name(np
),
6283 scr_to_cpu((int) *(ncrcmd
*)(script_base
+ script_ofs
)));
6286 printk ("%s: regdump:", ncr_name(np
));
6288 printk (" %02x", (unsigned)INB_OFF(i
));
6292 /*============================================================
6294 ** ncr chip exception handler.
6296 **============================================================
6298 ** In normal cases, interrupt conditions occur one at a
6299 ** time. The ncr is able to stack in some extra registers
6300 ** other interrupts that will occurs after the first one.
6301 ** But severall interrupts may occur at the same time.
6303 ** We probably should only try to deal with the normal
6304 ** case, but it seems that multiple interrupts occur in
6305 ** some cases that are not abnormal at all.
6307 ** The most frequent interrupt condition is Phase Mismatch.
6308 ** We should want to service this interrupt quickly.
6309 ** A SCSI parity error may be delivered at the same time.
6310 ** The SIR interrupt is not very frequent in this driver,
6311 ** since the INTFLY is likely used for command completion
6313 ** The Selection Timeout interrupt may be triggered with
6315 ** The SBMC interrupt (SCSI Bus Mode Change) may probably
6316 ** occur at any time.
6318 ** This handler try to deal as cleverly as possible with all
6321 **============================================================
6324 void ncr_exception (ncb_p np
)
6326 u_char istat
, dstat
;
6331 ** interrupt on the fly ?
6332 ** Since the global header may be copied back to a CCB
6333 ** using a posted PCI memory write, the last operation on
6334 ** the istat register is a READ in order to flush posted
6335 ** PCI write commands.
6337 istat
= INB (nc_istat
);
6339 OUTB (nc_istat
, (istat
& SIGP
) | INTF
);
6340 istat
= INB (nc_istat
);
6341 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("F ");
6342 ncr_wakeup_done (np
);
6345 if (!(istat
& (SIP
|DIP
)))
6349 OUTB (nc_istat
, CABRT
);
6352 ** Steinbach's Guideline for Systems Programming:
6353 ** Never test for an error condition you don't know how to handle.
6356 sist
= (istat
& SIP
) ? INW (nc_sist
) : 0;
6357 dstat
= (istat
& DIP
) ? INB (nc_dstat
) : 0;
6359 if (DEBUG_FLAGS
& DEBUG_TINY
)
6360 printk ("<%d|%x:%x|%x:%x>",
6363 (unsigned)INL(nc_dsp
),
6364 (unsigned)INL(nc_dbc
));
6366 /*========================================================
6367 ** First, interrupts we want to service cleanly.
6369 ** Phase mismatch is the most frequent interrupt, and
6370 ** so we have to service it as quickly and as cleanly
6372 ** Programmed interrupts are rarely used in this driver,
6373 ** but we must handle them cleanly anyway.
6374 ** We try to deal with PAR and SBMC combined with
6375 ** some other interrupt(s).
6376 **=========================================================
6379 if (!(sist
& (STO
|GEN
|HTH
|SGE
|UDC
|RST
)) &&
6380 !(dstat
& (MDPE
|BF
|ABRT
|IID
))) {
6381 if ((sist
& SBMC
) && ncr_int_sbmc (np
))
6383 if ((sist
& PAR
) && ncr_int_par (np
))
6394 ** DEL 397 - 53C875 Rev 3 - Part Number 609-0392410 - ITEM 2.
6396 if (!(sist
& (SBMC
|PAR
)) && !(dstat
& SSI
)) {
6397 printk( "%s: unknown interrupt(s) ignored, "
6398 "ISTAT=%x DSTAT=%x SIST=%x\n",
6399 ncr_name(np
), istat
, dstat
, sist
);
6406 /*========================================================
6407 ** Now, interrupts that need some fixing up.
6408 ** Order and multiple interrupts is so less important.
6410 ** If SRST has been asserted, we just reset the chip.
6412 ** Selection is intirely handled by the chip. If the
6413 ** chip says STO, we trust it. Seems some other
6414 ** interrupts may occur at the same time (UDC, IID), so
6415 ** we ignore them. In any case we do enough fix-up
6416 ** in the service routine.
6417 ** We just exclude some fatal dma errors.
6418 **=========================================================
6422 ncr_init (np
, 1, bootverbose
? "scsi reset" : NULL
, HS_RESET
);
6427 !(dstat
& (MDPE
|BF
|ABRT
))) {
6429 ** DEL 397 - 53C875 Rev 3 - Part Number 609-0392410 - ITEM 1.
6431 OUTONB (nc_ctest3
, CLF
);
6437 /*=========================================================
6438 ** Now, interrupts we are not able to recover cleanly.
6439 ** (At least for the moment).
6441 ** Do the register dump.
6442 ** Log message for real hard errors.
6444 ** For MDPE, BF, ABORT, IID, SGE and HTH we reset the
6445 ** BUS and the chip.
6446 ** We are more soft for UDC.
6447 **=========================================================
6450 if (ktime_exp(np
->regtime
)) {
6451 np
->regtime
= ktime_get(10*HZ
);
6452 for (i
= 0; i
<sizeof(np
->regdump
); i
++)
6453 ((char*)&np
->regdump
)[i
] = INB_OFF(i
);
6454 np
->regdump
.nc_dstat
= dstat
;
6455 np
->regdump
.nc_sist
= sist
;
6458 ncr_log_hard_error(np
, sist
, dstat
);
6460 printk ("%s: have to clear fifos.\n", ncr_name (np
));
6461 OUTB (nc_stest3
, TE
|CSF
);
6462 OUTONB (nc_ctest3
, CLF
);
6464 if ((sist
& (SGE
)) ||
6465 (dstat
& (MDPE
|BF
|ABRT
|IID
))) {
6466 ncr_start_reset(np
);
6471 printk ("%s: handshake timeout\n", ncr_name(np
));
6472 ncr_start_reset(np
);
6477 printk ("%s: unexpected disconnect\n", ncr_name(np
));
6478 OUTB (HS_PRT
, HS_UNEXPECTED
);
6479 OUTL_DSP (NCB_SCRIPT_PHYS (np
, cleanup
));
6483 /*=========================================================
6484 ** We just miss the cause of the interrupt. :(
6485 ** Print a message. The timeout will do the real work.
6486 **=========================================================
6488 printk ("%s: unknown interrupt\n", ncr_name(np
));
6491 /*==========================================================
6493 ** ncr chip exception handler for selection timeout
6495 **==========================================================
6497 ** There seems to be a bug in the 53c810.
6498 ** Although a STO-Interrupt is pending,
6499 ** it continues executing script commands.
6500 ** But it will fail and interrupt (IID) on
6501 ** the next instruction where it's looking
6502 ** for a valid phase.
6504 **----------------------------------------------------------
6507 void ncr_int_sto (ncb_p np
)
6511 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("T");
6514 ** look for ccb and set the status.
6519 while (cp
&& (CCB_PHYS (cp
, phys
) != dsa
))
6523 cp
-> host_status
= HS_SEL_TIMEOUT
;
6524 ncr_complete (np
, cp
);
6528 ** repair start queue and jump to start point.
6531 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, sto_restart
));
6535 /*==========================================================
6537 ** ncr chip exception handler for SCSI bus mode change
6539 **==========================================================
6541 ** spi2-r12 11.2.3 says a transceiver mode change must
6542 ** generate a reset event and a device that detects a reset
6543 ** event shall initiate a hard reset. It says also that a
6544 ** device that detects a mode change shall set data transfer
6545 ** mode to eight bit asynchronous, etc...
6546 ** So, just resetting should be enough.
6549 **----------------------------------------------------------
6552 static int ncr_int_sbmc (ncb_p np
)
6554 u_char scsi_mode
= INB (nc_stest4
) & SMODE
;
6556 if (scsi_mode
!= np
->scsi_mode
) {
6557 printk("%s: SCSI bus mode change from %x to %x.\n",
6558 ncr_name(np
), np
->scsi_mode
, scsi_mode
);
6560 np
->scsi_mode
= scsi_mode
;
6564 ** Suspend command processing for 1 second and
6565 ** reinitialize all except the chip.
6567 np
->settle_time
= ktime_get(1*HZ
);
6568 ncr_init (np
, 0, bootverbose
? "scsi mode change" : NULL
, HS_RESET
);
6574 /*==========================================================
6576 ** ncr chip exception handler for SCSI parity error.
6578 **==========================================================
6581 **----------------------------------------------------------
6584 static int ncr_int_par (ncb_p np
)
6586 u_char hsts
= INB (HS_PRT
);
6587 u_int32 dbc
= INL (nc_dbc
);
6588 u_char sstat1
= INB (nc_sstat1
);
6593 printk("%s: SCSI parity error detected: SCR1=%d DBC=%x SSTAT1=%x\n",
6594 ncr_name(np
), hsts
, dbc
, sstat1
);
6597 * Ignore the interrupt if the NCR is not connected
6598 * to the SCSI bus, since the right work should have
6599 * been done on unexpected disconnection handling.
6601 if (!(INB (nc_scntl1
) & ISCON
))
6605 * If the nexus is not clearly identified, reset the bus.
6606 * We will try to do better later.
6608 if (hsts
& HS_INVALMASK
)
6612 * If the SCSI parity error occurs in MSG IN phase, prepare a
6613 * MSG PARITY message. Otherwise, prepare a INITIATOR DETECTED
6614 * ERROR message and let the device decide to retry the command
6615 * or to terminate with check condition. If we were in MSG IN
6616 * phase waiting for the response of a negotiation, we will
6617 * get SIR_NEGO_FAILED at dispatch.
6619 if (!(dbc
& 0xc0000000))
6620 phase
= (dbc
>> 24) & 7;
6626 #ifdef SCSI_NCR_INTEGRITY_CHECKING
6628 ** Save error message. For integrity check use only.
6630 if (np
->check_integrity
)
6631 np
->check_integ_par
= msg
;
6635 * If the NCR stopped on a MOVE ^ DATA_IN, we jump to a
6636 * script that will ignore all data in bytes until phase
6637 * change, since we are not sure the chip will wait the phase
6638 * change prior to delivering the interrupt.
6641 jmp
= NCB_SCRIPTH_PHYS (np
, par_err_data_in
);
6643 jmp
= NCB_SCRIPTH_PHYS (np
, par_err_other
);
6645 OUTONB (nc_ctest3
, CLF
); /* clear dma fifo */
6646 OUTB (nc_stest3
, TE
|CSF
); /* clear scsi fifo */
6648 np
->msgout
[0] = msg
;
6653 ncr_start_reset(np
);
6657 /*==========================================================
6660 ** ncr chip exception handler for phase errors.
6663 **==========================================================
6665 ** We have to construct a new transfer descriptor,
6666 ** to transfer the rest of the current block.
6668 **----------------------------------------------------------
6671 static void ncr_int_ma (ncb_p np
)
6688 sbcl
= INB (nc_sbcl
);
6691 rest
= dbc
& 0xffffff;
6694 ** Take into account dma fifo and various buffers and latches,
6695 ** only if the interrupted phase is an OUTPUT phase.
6698 if ((cmd
& 1) == 0) {
6699 u_char ctest5
, ss0
, ss2
;
6702 ctest5
= (np
->rv_ctest5
& DFS
) ? INB (nc_ctest5
) : 0;
6704 delta
=(((ctest5
<< 8) | (INB (nc_dfifo
) & 0xff)) - rest
) & 0x3ff;
6706 delta
=(INB (nc_dfifo
) - rest
) & 0x7f;
6709 ** The data in the dma fifo has not been transferred to
6710 ** the target -> add the amount to the rest
6711 ** and clear the data.
6712 ** Check the sstat2 register in case of wide transfer.
6716 ss0
= INB (nc_sstat0
);
6717 if (ss0
& OLF
) rest
++;
6718 if (ss0
& ORF
) rest
++;
6719 if (INB(nc_scntl3
) & EWS
) {
6720 ss2
= INB (nc_sstat2
);
6721 if (ss2
& OLF1
) rest
++;
6722 if (ss2
& ORF1
) rest
++;
6725 if (DEBUG_FLAGS
& (DEBUG_TINY
|DEBUG_PHASE
))
6726 printk ("P%x%x RL=%d D=%d SS0=%x ", cmd
&7, sbcl
&7,
6727 (unsigned) rest
, (unsigned) delta
, ss0
);
6730 if (DEBUG_FLAGS
& (DEBUG_TINY
|DEBUG_PHASE
))
6731 printk ("P%x%x RL=%d ", cmd
&7, sbcl
&7, rest
);
6737 OUTONB (nc_ctest3
, CLF
); /* clear dma fifo */
6738 OUTB (nc_stest3
, TE
|CSF
); /* clear scsi fifo */
6741 ** locate matching cp.
6742 ** if the interrupted phase is DATA IN or DATA OUT,
6743 ** trust the global header.
6748 if (CCB_PHYS(cp
, phys
) != dsa
)
6752 while (cp
&& (CCB_PHYS (cp
, phys
) != dsa
))
6757 ** try to find the interrupted script command,
6758 ** and the address at which to continue.
6762 if (dsp
> np
->p_script
&&
6763 dsp
<= np
->p_script
+ sizeof(struct script
)) {
6764 vdsp
= (u_int32
*)((char*)np
->script0
+ (dsp
-np
->p_script
-8));
6767 else if (dsp
> np
->p_scripth
&&
6768 dsp
<= np
->p_scripth
+ sizeof(struct scripth
)) {
6769 vdsp
= (u_int32
*)((char*)np
->scripth0
+ (dsp
-np
->p_scripth
-8));
6773 if (dsp
== CCB_PHYS (cp
, patch
[2])) {
6774 vdsp
= &cp
->patch
[0];
6775 nxtdsp
= scr_to_cpu(vdsp
[3]);
6777 else if (dsp
== CCB_PHYS (cp
, patch
[6])) {
6778 vdsp
= &cp
->patch
[4];
6779 nxtdsp
= scr_to_cpu(vdsp
[3]);
6784 ** log the information
6787 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
6788 printk ("\nCP=%p CP2=%p DSP=%x NXT=%x VDSP=%p CMD=%x ",
6791 (unsigned)nxtdsp
, vdsp
, cmd
);
6795 ** cp=0 means that the DSA does not point to a valid control
6796 ** block. This should not happen since we donnot use multi-byte
6797 ** move while we are being reselected ot after command complete.
6798 ** We are not able to recover from such a phase error.
6801 printk ("%s: SCSI phase error fixup: "
6802 "CCB already dequeued (0x%08lx)\n",
6803 ncr_name (np
), (u_long
) np
->header
.cp
);
6808 ** get old startaddress and old length.
6811 oadr
= scr_to_cpu(vdsp
[1]);
6813 if (cmd
& 0x10) { /* Table indirect */
6814 tblp
= (u_int32
*) ((char*) &cp
->phys
+ oadr
);
6815 olen
= scr_to_cpu(tblp
[0]);
6816 oadr
= scr_to_cpu(tblp
[1]);
6818 tblp
= (u_int32
*) 0;
6819 olen
= scr_to_cpu(vdsp
[0]) & 0xffffff;
6822 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
6823 printk ("OCMD=%x\nTBLP=%p OLEN=%x OADR=%x\n",
6824 (unsigned) (scr_to_cpu(vdsp
[0]) >> 24),
6831 ** check cmd against assumed interrupted script command.
6834 if (cmd
!= (scr_to_cpu(vdsp
[0]) >> 24)) {
6835 PRINT_ADDR(cp
->cmd
);
6836 printk ("internal error: cmd=%02x != %02x=(vdsp[0] >> 24)\n",
6837 (unsigned)cmd
, (unsigned)scr_to_cpu(vdsp
[0]) >> 24);
6843 ** cp != np->header.cp means that the header of the CCB
6844 ** currently being processed has not yet been copied to
6845 ** the global header area. That may happen if the device did
6846 ** not accept all our messages after having been selected.
6848 if (cp
!= np
->header
.cp
) {
6849 printk ("%s: SCSI phase error fixup: "
6850 "CCB address mismatch (0x%08lx != 0x%08lx)\n",
6851 ncr_name (np
), (u_long
) cp
, (u_long
) np
->header
.cp
);
6855 ** if old phase not dataphase, leave here.
6859 PRINT_ADDR(cp
->cmd
);
6860 printk ("phase change %x-%x %d@%08x resid=%d.\n",
6861 cmd
&7, sbcl
&7, (unsigned)olen
,
6862 (unsigned)oadr
, (unsigned)rest
);
6863 goto unexpected_phase
;
6867 ** choose the correct patch area.
6868 ** if savep points to one, choose the other.
6872 newtmp
= CCB_PHYS (cp
, patch
);
6873 if (newtmp
== scr_to_cpu(cp
->phys
.header
.savep
)) {
6874 newcmd
= &cp
->patch
[4];
6875 newtmp
= CCB_PHYS (cp
, patch
[4]);
6879 ** fillin the commands
6882 newcmd
[0] = cpu_to_scr(((cmd
& 0x0f) << 24) | rest
);
6883 newcmd
[1] = cpu_to_scr(oadr
+ olen
- rest
);
6884 newcmd
[2] = cpu_to_scr(SCR_JUMP
);
6885 newcmd
[3] = cpu_to_scr(nxtdsp
);
6887 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
6888 PRINT_ADDR(cp
->cmd
);
6889 printk ("newcmd[%d] %x %x %x %x.\n",
6890 (int) (newcmd
- cp
->patch
),
6891 (unsigned)scr_to_cpu(newcmd
[0]),
6892 (unsigned)scr_to_cpu(newcmd
[1]),
6893 (unsigned)scr_to_cpu(newcmd
[2]),
6894 (unsigned)scr_to_cpu(newcmd
[3]));
6897 ** fake the return address (to the patch).
6898 ** and restart script processor at dispatcher.
6900 OUTL (nc_temp
, newtmp
);
6901 OUTL_DSP (NCB_SCRIPT_PHYS (np
, dispatch
));
6905 ** Unexpected phase changes that occurs when the current phase
6906 ** is not a DATA IN or DATA OUT phase are due to error conditions.
6907 ** Such event may only happen when the SCRIPTS is using a
6908 ** multibyte SCSI MOVE.
6910 ** Phase change Some possible cause
6912 ** COMMAND --> MSG IN SCSI parity error detected by target.
6913 ** COMMAND --> STATUS Bad command or refused by target.
6914 ** MSG OUT --> MSG IN Message rejected by target.
6915 ** MSG OUT --> COMMAND Bogus target that discards extended
6916 ** negotiation messages.
6918 ** The code below does not care of the new phase and so
6919 ** trusts the target. Why to annoy it ?
6920 ** If the interrupted phase is COMMAND phase, we restart at
6922 ** If a target does not get all the messages after selection,
6923 ** the code assumes blindly that the target discards extended
6924 ** messages and clears the negotiation status.
6925 ** If the target does not want all our response to negotiation,
6926 ** we force a SIR_NEGO_PROTO interrupt (it is a hack that avoids
6927 ** bloat for such a should_not_happen situation).
6928 ** In all other situation, we reset the BUS.
6929 ** Are these assumptions reasonnable ? (Wait and see ...)
6936 case 2: /* COMMAND phase */
6937 nxtdsp
= NCB_SCRIPT_PHYS (np
, dispatch
);
6940 case 3: /* STATUS phase */
6941 nxtdsp
= NCB_SCRIPT_PHYS (np
, dispatch
);
6944 case 6: /* MSG OUT phase */
6945 np
->scripth
->nxtdsp_go_on
[0] = cpu_to_scr(dsp
+ 8);
6946 if (dsp
== NCB_SCRIPT_PHYS (np
, send_ident
)) {
6947 cp
->host_status
= HS_BUSY
;
6948 nxtdsp
= NCB_SCRIPTH_PHYS (np
, clratn_go_on
);
6950 else if (dsp
== NCB_SCRIPTH_PHYS (np
, send_wdtr
) ||
6951 dsp
== NCB_SCRIPTH_PHYS (np
, send_sdtr
)) {
6952 nxtdsp
= NCB_SCRIPTH_PHYS (np
, nego_bad_phase
);
6956 case 7: /* MSG IN phase */
6957 nxtdsp
= NCB_SCRIPT_PHYS (np
, clrack
);
6968 ncr_start_reset(np
);
6972 static void ncr_sir_to_redo(ncb_p np
, int num
, ccb_p cp
)
6974 Scsi_Cmnd
*cmd
= cp
->cmd
;
6975 tcb_p tp
= &np
->target
[cmd
->device
->id
];
6976 lcb_p lp
= tp
->lp
[cmd
->device
->lun
];
6982 u_char s_status
= INB (SS_PRT
);
6985 ** Let the SCRIPTS processor skip all not yet started CCBs,
6986 ** and count disconnected CCBs. Since the busy queue is in
6987 ** the same order as the chip start queue, disconnected CCBs
6988 ** are before cp and busy ones after.
6991 qp
= lp
->busy_ccbq
.blink
;
6992 while (qp
!= &lp
->busy_ccbq
) {
6993 cp2
= xpt_que_entry(qp
, struct ccb
, link_ccbq
);
6998 cp2
->start
.schedule
.l_paddr
=
6999 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, skip
));
7001 lp
->held_ccb
= cp
; /* Requeue when this one completes */
7002 disc_cnt
= lp
->queuedccbs
- busy_cnt
;
7006 default: /* Just for safety, should never happen */
7009 ** Decrease number of tags to the number of
7010 ** disconnected commands.
7014 if (bootverbose
>= 1) {
7016 printk ("QUEUE FULL! %d busy, %d disconnected CCBs\n",
7017 busy_cnt
, disc_cnt
);
7019 if (disc_cnt
< lp
->numtags
) {
7020 lp
->numtags
= disc_cnt
> 2 ? disc_cnt
: 2;
7022 ncr_setup_tags (np
, cmd
->device
->id
, cmd
->device
->lun
);
7025 ** Requeue the command to the start queue.
7026 ** If any disconnected commands,
7028 ** Jump to reselect.
7030 cp
->phys
.header
.savep
= cp
->startp
;
7031 cp
->host_status
= HS_BUSY
;
7032 cp
->scsi_status
= S_ILLEGAL
;
7034 ncr_put_start_queue(np
, cp
);
7036 INB (nc_ctest2
); /* Clear SIGP */
7037 OUTL_DSP (NCB_SCRIPT_PHYS (np
, reselect
));
7042 ** If we were requesting sense, give up.
7048 ** Device returned CHECK CONDITION status.
7049 ** Prepare all needed data strutures for getting
7054 cp
->scsi_smsg2
[0] = M_IDENTIFY
| cmd
->device
->lun
;
7055 cp
->phys
.smsg
.addr
= cpu_to_scr(CCB_PHYS (cp
, scsi_smsg2
));
7056 cp
->phys
.smsg
.size
= cpu_to_scr(1);
7061 cp
->phys
.cmd
.addr
= cpu_to_scr(CCB_PHYS (cp
, sensecmd
));
7062 cp
->phys
.cmd
.size
= cpu_to_scr(6);
7065 ** patch requested size into sense command
7067 cp
->sensecmd
[0] = 0x03;
7068 cp
->sensecmd
[1] = cmd
->device
->lun
<< 5;
7069 cp
->sensecmd
[4] = sizeof(cp
->sense_buf
);
7074 bzero(cp
->sense_buf
, sizeof(cp
->sense_buf
));
7075 cp
->phys
.sense
.addr
= cpu_to_scr(CCB_PHYS(cp
,sense_buf
[0]));
7076 cp
->phys
.sense
.size
= cpu_to_scr(sizeof(cp
->sense_buf
));
7079 ** requeue the command.
7081 startp
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, sdata_in
));
7083 cp
->phys
.header
.savep
= startp
;
7084 cp
->phys
.header
.goalp
= startp
+ 24;
7085 cp
->phys
.header
.lastp
= startp
;
7086 cp
->phys
.header
.wgoalp
= startp
+ 24;
7087 cp
->phys
.header
.wlastp
= startp
;
7089 cp
->host_status
= HS_BUSY
;
7090 cp
->scsi_status
= S_ILLEGAL
;
7091 cp
->auto_sense
= s_status
;
7093 cp
->start
.schedule
.l_paddr
=
7094 cpu_to_scr(NCB_SCRIPT_PHYS (np
, select
));
7097 ** Select without ATN for quirky devices.
7099 if (tp
->quirks
& QUIRK_NOMSG
)
7100 cp
->start
.schedule
.l_paddr
=
7101 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, select_no_atn
));
7103 ncr_put_start_queue(np
, cp
);
7105 OUTL_DSP (NCB_SCRIPT_PHYS (np
, start
));
7115 /*==========================================================
7118 ** ncr chip exception handler for programmed interrupts.
7121 **==========================================================
7124 static int ncr_show_msg (u_char
* msg
)
7128 if (*msg
==M_EXTENDED
) {
7130 if (i
-1>msg
[1]) break;
7131 printk ("-%x",msg
[i
]);
7134 } else if ((*msg
& 0xf0) == 0x20) {
7135 printk ("-%x",msg
[1]);
7141 static void ncr_print_msg ( ccb_p cp
, char *label
, u_char
*msg
)
7144 PRINT_ADDR(cp
->cmd
);
7146 printk("%s: ", label
);
7148 (void) ncr_show_msg (msg
);
7152 void ncr_int_sir (ncb_p np
)
7155 u_char chg
, ofs
, per
, fak
, wide
;
7156 u_char num
= INB (nc_dsps
);
7158 u_long dsa
= INL (nc_dsa
);
7159 u_char target
= INB (nc_sdid
) & 0x0f;
7160 tcb_p tp
= &np
->target
[target
];
7162 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("I#%d", num
);
7167 ** This is used for HP Zalon/53c720 where INTFLY
7168 ** operation is currently broken.
7170 ncr_wakeup_done(np
);
7171 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
7172 OUTL(nc_dsp
, NCB_SCRIPT_PHYS (np
, done_end
) + 8);
7174 OUTL(nc_dsp
, NCB_SCRIPT_PHYS (np
, start
));
7177 case SIR_RESEL_NO_MSG_IN
:
7178 case SIR_RESEL_NO_IDENTIFY
:
7180 ** If devices reselecting without sending an IDENTIFY
7181 ** message still exist, this should help.
7182 ** We just assume lun=0, 1 CCB, no tag.
7185 OUTL_DSP (scr_to_cpu(tp
->lp
[0]->jump_ccb
[0]));
7188 case SIR_RESEL_BAD_TARGET
: /* Will send a TARGET RESET message */
7189 case SIR_RESEL_BAD_LUN
: /* Will send a TARGET RESET message */
7190 case SIR_RESEL_BAD_I_T_L_Q
: /* Will send an ABORT TAG message */
7191 case SIR_RESEL_BAD_I_T_L
: /* Will send an ABORT message */
7192 printk ("%s:%d: SIR %d, "
7193 "incorrect nexus identification on reselection\n",
7194 ncr_name (np
), target
, num
);
7196 case SIR_DONE_OVERFLOW
:
7197 printk ("%s:%d: SIR %d, "
7198 "CCB done queue overflow\n",
7199 ncr_name (np
), target
, num
);
7201 case SIR_BAD_STATUS
:
7203 if (!cp
|| CCB_PHYS (cp
, phys
) != dsa
)
7205 ncr_sir_to_redo(np
, num
, cp
);
7212 while (cp
&& (CCB_PHYS (cp
, phys
) != dsa
))
7215 assert (cp
&& cp
== np
->header
.cp
);
7217 if (!cp
|| cp
!= np
->header
.cp
)
7222 /*-----------------------------------------------------------------------------
7224 ** Was Sie schon immer ueber transfermode negotiation wissen wollten ...
7226 ** We try to negotiate sync and wide transfer only after
7227 ** a successful inquire command. We look at byte 7 of the
7228 ** inquire data to determine the capabilities of the target.
7230 ** When we try to negotiate, we append the negotiation message
7231 ** to the identify and (maybe) simple tag message.
7232 ** The host status field is set to HS_NEGOTIATE to mark this
7235 ** If the target doesn't answer this message immidiately
7236 ** (as required by the standard), the SIR_NEGO_FAIL interrupt
7237 ** will be raised eventually.
7238 ** The handler removes the HS_NEGOTIATE status, and sets the
7239 ** negotiated value to the default (async / nowide).
7241 ** If we receive a matching answer immediately, we check it
7242 ** for validity, and set the values.
7244 ** If we receive a Reject message immediately, we assume the
7245 ** negotiation has failed, and fall back to standard values.
7247 ** If we receive a negotiation message while not in HS_NEGOTIATE
7248 ** state, it's a target initiated negotiation. We prepare a
7249 ** (hopefully) valid answer, set our parameters, and send back
7250 ** this answer to the target.
7252 ** If the target doesn't fetch the answer (no message out phase),
7253 ** we assume the negotiation has failed, and fall back to default
7256 ** When we set the values, we adjust them in all ccbs belonging
7257 ** to this target, in the controller's register, and in the "phys"
7258 ** field of the controller's struct ncb.
7260 ** Possible cases: hs sir msg_in value send goto
7261 ** We try to negotiate:
7262 ** -> target doesn't msgin NEG FAIL noop defa. - dispatch
7263 ** -> target rejected our msg NEG FAIL reject defa. - dispatch
7264 ** -> target answered (ok) NEG SYNC sdtr set - clrack
7265 ** -> target answered (!ok) NEG SYNC sdtr defa. REJ--->msg_bad
7266 ** -> target answered (ok) NEG WIDE wdtr set - clrack
7267 ** -> target answered (!ok) NEG WIDE wdtr defa. REJ--->msg_bad
7268 ** -> any other msgin NEG FAIL noop defa. - dispatch
7270 ** Target tries to negotiate:
7271 ** -> incoming message --- SYNC sdtr set SDTR -
7272 ** -> incoming message --- WIDE wdtr set WDTR -
7273 ** We sent our answer:
7274 ** -> target doesn't msgout --- PROTO ? defa. - dispatch
7276 **-----------------------------------------------------------------------------
7279 case SIR_NEGO_FAILED
:
7280 /*-------------------------------------------------------
7282 ** Negotiation failed.
7283 ** Target doesn't send an answer message,
7284 ** or target rejected our message.
7286 ** Remove negotiation request.
7288 **-------------------------------------------------------
7290 OUTB (HS_PRT
, HS_BUSY
);
7294 case SIR_NEGO_PROTO
:
7295 /*-------------------------------------------------------
7297 ** Negotiation failed.
7298 ** Target doesn't fetch the answer message.
7300 **-------------------------------------------------------
7303 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
7304 PRINT_ADDR(cp
->cmd
);
7305 printk ("negotiation failed sir=%x status=%x.\n",
7306 num
, cp
->nego_status
);
7310 ** any error in negotiation:
7311 ** fall back to default mode.
7313 switch (cp
->nego_status
) {
7316 ncr_setsync (np
, cp
, 0, 0xe0);
7320 ncr_setwide (np
, cp
, 0, 0);
7324 np
->msgin
[0] = M_NOOP
;
7325 np
->msgout
[0] = M_NOOP
;
7326 cp
->nego_status
= 0;
7331 ** Synchronous request message received.
7334 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
7335 PRINT_ADDR(cp
->cmd
);
7336 printk ("sync msgin: ");
7337 (void) ncr_show_msg (np
->msgin
);
7342 ** get requested values.
7348 if (ofs
==0) per
=255;
7351 ** if target sends SDTR message,
7352 ** it CAN transfer synch.
7356 tp
->inq_byte7
|= INQ7_SYNC
;
7359 ** check values against driver limits.
7362 if (per
< np
->minsync
)
7363 {chg
= 1; per
= np
->minsync
;}
7364 if (per
< tp
->minsync
)
7365 {chg
= 1; per
= tp
->minsync
;}
7366 if (ofs
> tp
->maxoffs
)
7367 {chg
= 1; ofs
= tp
->maxoffs
;}
7370 ** Check against controller limits.
7375 ncr_getsync(np
, per
, &fak
, &scntl3
);
7388 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
7389 PRINT_ADDR(cp
->cmd
);
7390 printk ("sync: per=%d scntl3=0x%x ofs=%d fak=%d chg=%d.\n",
7391 per
, scntl3
, ofs
, fak
, chg
);
7394 if (INB (HS_PRT
) == HS_NEGOTIATE
) {
7395 OUTB (HS_PRT
, HS_BUSY
);
7396 switch (cp
->nego_status
) {
7400 ** This was an answer message
7404 ** Answer wasn't acceptable.
7406 ncr_setsync (np
, cp
, 0, 0xe0);
7407 OUTL_DSP (NCB_SCRIPT_PHYS (np
, msg_bad
));
7412 ncr_setsync (np
, cp
, scntl3
, (fak
<<5)|ofs
);
7413 OUTL_DSP (NCB_SCRIPT_PHYS (np
, clrack
));
7418 ncr_setwide (np
, cp
, 0, 0);
7424 ** It was a request. Set value and
7425 ** prepare an answer message
7428 ncr_setsync (np
, cp
, scntl3
, (fak
<<5)|ofs
);
7430 np
->msgout
[0] = M_EXTENDED
;
7432 np
->msgout
[2] = M_X_SYNC_REQ
;
7433 np
->msgout
[3] = per
;
7434 np
->msgout
[4] = ofs
;
7436 cp
->nego_status
= NS_SYNC
;
7438 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
7439 PRINT_ADDR(cp
->cmd
);
7440 printk ("sync msgout: ");
7441 (void) ncr_show_msg (np
->msgout
);
7446 OUTL_DSP (NCB_SCRIPT_PHYS (np
, msg_bad
));
7449 np
->msgin
[0] = M_NOOP
;
7455 ** Wide request message received.
7457 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
7458 PRINT_ADDR(cp
->cmd
);
7459 printk ("wide msgin: ");
7460 (void) ncr_show_msg (np
->msgin
);
7465 ** get requested values.
7469 wide
= np
->msgin
[3];
7472 ** if target sends WDTR message,
7473 ** it CAN transfer wide.
7477 tp
->inq_byte7
|= INQ7_WIDE16
;
7480 ** check values against driver limits.
7483 if (wide
> tp
->usrwide
)
7484 {chg
= 1; wide
= tp
->usrwide
;}
7486 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
7487 PRINT_ADDR(cp
->cmd
);
7488 printk ("wide: wide=%d chg=%d.\n", wide
, chg
);
7491 if (INB (HS_PRT
) == HS_NEGOTIATE
) {
7492 OUTB (HS_PRT
, HS_BUSY
);
7493 switch (cp
->nego_status
) {
7497 ** This was an answer message
7501 ** Answer wasn't acceptable.
7503 ncr_setwide (np
, cp
, 0, 1);
7504 OUTL_DSP (NCB_SCRIPT_PHYS (np
, msg_bad
));
7509 ncr_setwide (np
, cp
, wide
, 1);
7510 OUTL_DSP (NCB_SCRIPT_PHYS (np
, clrack
));
7515 ncr_setsync (np
, cp
, 0, 0xe0);
7521 ** It was a request, set value and
7522 ** prepare an answer message
7525 ncr_setwide (np
, cp
, wide
, 1);
7527 np
->msgout
[0] = M_EXTENDED
;
7529 np
->msgout
[2] = M_X_WIDE_REQ
;
7530 np
->msgout
[3] = wide
;
7532 np
->msgin
[0] = M_NOOP
;
7534 cp
->nego_status
= NS_WIDE
;
7536 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
7537 PRINT_ADDR(cp
->cmd
);
7538 printk ("wide msgout: ");
7539 (void) ncr_show_msg (np
->msgin
);
7544 /*--------------------------------------------------------------------
7546 ** Processing of special messages
7548 **--------------------------------------------------------------------
7551 case SIR_REJECT_RECEIVED
:
7552 /*-----------------------------------------------
7554 ** We received a M_REJECT message.
7556 **-----------------------------------------------
7559 PRINT_ADDR(cp
->cmd
);
7560 printk ("M_REJECT received (%x:%x).\n",
7561 (unsigned)scr_to_cpu(np
->lastmsg
), np
->msgout
[0]);
7564 case SIR_REJECT_SENT
:
7565 /*-----------------------------------------------
7567 ** We received an unknown message
7569 **-----------------------------------------------
7572 PRINT_ADDR(cp
->cmd
);
7573 printk ("M_REJECT sent for ");
7574 (void) ncr_show_msg (np
->msgin
);
7578 /*--------------------------------------------------------------------
7580 ** Processing of special messages
7582 **--------------------------------------------------------------------
7585 case SIR_IGN_RESIDUE
:
7586 /*-----------------------------------------------
7588 ** We received an IGNORE RESIDUE message,
7589 ** which couldn't be handled by the script.
7591 **-----------------------------------------------
7594 PRINT_ADDR(cp
->cmd
);
7595 printk ("M_IGN_RESIDUE received, but not yet implemented.\n");
7598 case SIR_MISSING_SAVE
:
7599 /*-----------------------------------------------
7601 ** We received an DISCONNECT message,
7602 ** but the datapointer wasn't saved before.
7604 **-----------------------------------------------
7607 PRINT_ADDR(cp
->cmd
);
7608 printk ("M_DISCONNECT received, but datapointer not saved: "
7609 "data=%x save=%x goal=%x.\n",
7610 (unsigned) INL (nc_temp
),
7611 (unsigned) scr_to_cpu(np
->header
.savep
),
7612 (unsigned) scr_to_cpu(np
->header
.goalp
));
7621 /*==========================================================
7624 ** Acquire a control block
7627 **==========================================================
7630 static ccb_p
ncr_get_ccb (ncb_p np
, u_char tn
, u_char ln
)
7632 tcb_p tp
= &np
->target
[tn
];
7633 lcb_p lp
= tp
->lp
[ln
];
7634 u_char tag
= NO_TAG
;
7635 ccb_p cp
= (ccb_p
) 0;
7638 ** Lun structure available ?
7643 ** Keep from using more tags than we can handle.
7645 if (lp
->usetags
&& lp
->busyccbs
>= lp
->maxnxs
)
7649 ** Allocate a new CCB if needed.
7651 if (xpt_que_empty(&lp
->free_ccbq
))
7652 ncr_alloc_ccb(np
, tn
, ln
);
7655 ** Tune tag mode if asked by user.
7657 if (lp
->queuedepth
!= lp
->numtags
) {
7658 ncr_setup_tags(np
, tn
, ln
);
7662 ** Look for free CCB
7664 qp
= xpt_remque_head(&lp
->free_ccbq
);
7666 cp
= xpt_que_entry(qp
, struct ccb
, link_ccbq
);
7668 PRINT_LUN(np
, tn
, ln
);
7669 printk ("ccb free list corrupted (@%p)\n", cp
);
7673 xpt_insque_tail(qp
, &lp
->wait_ccbq
);
7679 ** If a CCB is available,
7680 ** Get a tag for this nexus if required.
7684 tag
= lp
->cb_tags
[lp
->ia_tag
];
7686 else if (lp
->actccbs
> 0)
7691 ** if nothing available, take the default.
7697 ** Wait until available.
7701 if (flags
& SCSI_NOSLEEP
) break;
7702 if (tsleep ((caddr_t
)cp
, PRIBIO
|PCATCH
, "ncr", 0))
7713 ** Move to next available tag if tag used.
7716 if (tag
!= NO_TAG
) {
7718 if (lp
->ia_tag
== MAX_TAGS
)
7720 lp
->tags_umap
|= (((tagmap_t
) 1) << tag
);
7725 ** Remember all informations needed to free this CCB.
7731 if (DEBUG_FLAGS
& DEBUG_TAGS
) {
7732 PRINT_LUN(np
, tn
, ln
);
7733 printk ("ccb @%p using tag %d.\n", cp
, tag
);
7739 /*==========================================================
7742 ** Release one control block
7745 **==========================================================
7748 static void ncr_free_ccb (ncb_p np
, ccb_p cp
)
7750 tcb_p tp
= &np
->target
[cp
->target
];
7751 lcb_p lp
= tp
->lp
[cp
->lun
];
7753 if (DEBUG_FLAGS
& DEBUG_TAGS
) {
7754 PRINT_LUN(np
, cp
->target
, cp
->lun
);
7755 printk ("ccb @%p freeing tag %d.\n", cp
, cp
->tag
);
7759 ** If lun control block available,
7760 ** decrement active commands and increment credit,
7761 ** free the tag if any and remove the JUMP for reselect.
7764 if (cp
->tag
!= NO_TAG
) {
7765 lp
->cb_tags
[lp
->if_tag
++] = cp
->tag
;
7766 if (lp
->if_tag
== MAX_TAGS
)
7768 lp
->tags_umap
&= ~(((tagmap_t
) 1) << cp
->tag
);
7769 lp
->tags_smap
&= lp
->tags_umap
;
7770 lp
->jump_ccb
[cp
->tag
] =
7771 cpu_to_scr(NCB_SCRIPTH_PHYS(np
, bad_i_t_l_q
));
7774 cpu_to_scr(NCB_SCRIPTH_PHYS(np
, bad_i_t_l
));
7779 ** Make this CCB available.
7783 if (cp
!= np
->ccb
) {
7784 xpt_remque(&cp
->link_ccbq
);
7785 xpt_insque_head(&cp
->link_ccbq
, &lp
->free_ccbq
);
7792 cp
-> host_status
= HS_IDLE
;
7801 wakeup ((caddr_t
) cp
);
7806 #define ncr_reg_bus_addr(r) (np->paddr + offsetof (struct ncr_reg, r))
7808 /*------------------------------------------------------------------------
7809 ** Initialize the fixed part of a CCB structure.
7810 **------------------------------------------------------------------------
7811 **------------------------------------------------------------------------
7813 static void ncr_init_ccb(ncb_p np
, ccb_p cp
)
7815 ncrcmd copy_4
= np
->features
& FE_PFEN
? SCR_COPY(4) : SCR_COPY_F(4);
7818 ** Remember virtual and bus address of this ccb.
7820 cp
->p_ccb
= vtobus(cp
);
7821 cp
->phys
.header
.cp
= cp
;
7824 ** This allows xpt_remque to work for the default ccb.
7826 xpt_que_init(&cp
->link_ccbq
);
7829 ** Initialyze the start and restart launch script.
7831 ** COPY(4) @(...p_phys), @(dsa)
7832 ** JUMP @(sched_point)
7834 cp
->start
.setup_dsa
[0] = cpu_to_scr(copy_4
);
7835 cp
->start
.setup_dsa
[1] = cpu_to_scr(CCB_PHYS(cp
, start
.p_phys
));
7836 cp
->start
.setup_dsa
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_dsa
));
7837 cp
->start
.schedule
.l_cmd
= cpu_to_scr(SCR_JUMP
);
7838 cp
->start
.p_phys
= cpu_to_scr(CCB_PHYS(cp
, phys
));
7840 bcopy(&cp
->start
, &cp
->restart
, sizeof(cp
->restart
));
7842 cp
->start
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
7843 cp
->restart
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, abort
));
7847 /*------------------------------------------------------------------------
7848 ** Allocate a CCB and initialize its fixed part.
7849 **------------------------------------------------------------------------
7850 **------------------------------------------------------------------------
7852 static void ncr_alloc_ccb(ncb_p np
, u_char tn
, u_char ln
)
7854 tcb_p tp
= &np
->target
[tn
];
7855 lcb_p lp
= tp
->lp
[ln
];
7859 ** Allocate memory for this CCB.
7861 cp
= m_calloc_dma(sizeof(struct ccb
), "CCB");
7866 ** Count it and initialyze it.
7870 bzero (cp
, sizeof (*cp
));
7871 ncr_init_ccb(np
, cp
);
7874 ** Chain into wakeup list and free ccb queue and take it
7875 ** into account for tagged commands.
7877 cp
->link_ccb
= np
->ccb
->link_ccb
;
7878 np
->ccb
->link_ccb
= cp
;
7880 xpt_insque_head(&cp
->link_ccbq
, &lp
->free_ccbq
);
7881 ncr_setup_tags (np
, tn
, ln
);
7884 /*==========================================================
7887 ** Allocation of resources for Targets/Luns/Tags.
7890 **==========================================================
7894 /*------------------------------------------------------------------------
7895 ** Target control block initialisation.
7896 **------------------------------------------------------------------------
7897 ** This data structure is fully initialized after a SCSI command
7898 ** has been successfully completed for this target.
7899 ** It contains a SCRIPT that is called on target reselection.
7900 **------------------------------------------------------------------------
7902 static void ncr_init_tcb (ncb_p np
, u_char tn
)
7904 tcb_p tp
= &np
->target
[tn
];
7905 ncrcmd copy_1
= np
->features
& FE_PFEN
? SCR_COPY(1) : SCR_COPY_F(1);
7910 ** Jump to next tcb if SFBR does not match this target.
7911 ** JUMP IF (SFBR != #target#), @(next tcb)
7913 tp
->jump_tcb
.l_cmd
=
7914 cpu_to_scr((SCR_JUMP
^ IFFALSE (DATA (0x80 + tn
))));
7915 tp
->jump_tcb
.l_paddr
= np
->jump_tcb
[th
].l_paddr
;
7918 ** Load the synchronous transfer register.
7919 ** COPY @(tp->sval), @(sxfer)
7921 tp
->getscr
[0] = cpu_to_scr(copy_1
);
7922 tp
->getscr
[1] = cpu_to_scr(vtobus (&tp
->sval
));
7923 #ifdef SCSI_NCR_BIG_ENDIAN
7924 tp
->getscr
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_sxfer
) ^ 3);
7926 tp
->getscr
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_sxfer
));
7930 ** Load the timing register.
7931 ** COPY @(tp->wval), @(scntl3)
7933 tp
->getscr
[3] = cpu_to_scr(copy_1
);
7934 tp
->getscr
[4] = cpu_to_scr(vtobus (&tp
->wval
));
7935 #ifdef SCSI_NCR_BIG_ENDIAN
7936 tp
->getscr
[5] = cpu_to_scr(ncr_reg_bus_addr(nc_scntl3
) ^ 3);
7938 tp
->getscr
[5] = cpu_to_scr(ncr_reg_bus_addr(nc_scntl3
));
7942 ** Get the IDENTIFY message and the lun.
7943 ** CALL @script(resel_lun)
7945 tp
->call_lun
.l_cmd
= cpu_to_scr(SCR_CALL
);
7946 tp
->call_lun
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, resel_lun
));
7949 ** Look for the lun control block of this nexus.
7951 ** JUMP ^ IFTRUE (MASK (i, 3)), @(next_lcb)
7953 for (i
= 0 ; i
< 4 ; i
++) {
7954 tp
->jump_lcb
[i
].l_cmd
=
7955 cpu_to_scr((SCR_JUMP
^ IFTRUE (MASK (i
, 3))));
7956 tp
->jump_lcb
[i
].l_paddr
=
7957 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_identify
));
7961 ** Link this target control block to the JUMP chain.
7963 np
->jump_tcb
[th
].l_paddr
= cpu_to_scr(vtobus (&tp
->jump_tcb
));
7966 ** These assert's should be moved at driver initialisations.
7968 #ifdef SCSI_NCR_BIG_ENDIAN
7969 assert (( (offsetof(struct ncr_reg
, nc_sxfer
) ^
7970 offsetof(struct tcb
, sval
)) &3) == 3);
7971 assert (( (offsetof(struct ncr_reg
, nc_scntl3
) ^
7972 offsetof(struct tcb
, wval
)) &3) == 3);
7974 assert (( (offsetof(struct ncr_reg
, nc_sxfer
) ^
7975 offsetof(struct tcb
, sval
)) &3) == 0);
7976 assert (( (offsetof(struct ncr_reg
, nc_scntl3
) ^
7977 offsetof(struct tcb
, wval
)) &3) == 0);
7982 /*------------------------------------------------------------------------
7983 ** Lun control block allocation and initialization.
7984 **------------------------------------------------------------------------
7985 ** This data structure is allocated and initialized after a SCSI
7986 ** command has been successfully completed for this target/lun.
7987 **------------------------------------------------------------------------
7989 static lcb_p
ncr_alloc_lcb (ncb_p np
, u_char tn
, u_char ln
)
7991 tcb_p tp
= &np
->target
[tn
];
7992 lcb_p lp
= tp
->lp
[ln
];
7993 ncrcmd copy_4
= np
->features
& FE_PFEN
? SCR_COPY(4) : SCR_COPY_F(4);
7997 ** Already done, return.
8003 ** Allocate the lcb.
8005 lp
= m_calloc_dma(sizeof(struct lcb
), "LCB");
8008 bzero(lp
, sizeof(*lp
));
8012 ** Initialize the target control block if not yet.
8014 if (!tp
->jump_tcb
.l_cmd
)
8015 ncr_init_tcb(np
, tn
);
8018 ** Initialize the CCB queue headers.
8020 xpt_que_init(&lp
->free_ccbq
);
8021 xpt_que_init(&lp
->busy_ccbq
);
8022 xpt_que_init(&lp
->wait_ccbq
);
8023 xpt_que_init(&lp
->skip_ccbq
);
8026 ** Set max CCBs to 1 and use the default 1 entry
8027 ** jump table by default.
8030 lp
->jump_ccb
= &lp
->jump_ccb_0
;
8031 lp
->p_jump_ccb
= cpu_to_scr(vtobus(lp
->jump_ccb
));
8034 ** Initilialyze the reselect script:
8036 ** Jump to next lcb if SFBR does not match this lun.
8037 ** Load TEMP with the CCB direct jump table bus address.
8038 ** Get the SIMPLE TAG message and the tag.
8040 ** JUMP IF (SFBR != #lun#), @(next lcb)
8041 ** COPY @(lp->p_jump_ccb), @(temp)
8042 ** JUMP @script(resel_notag)
8044 lp
->jump_lcb
.l_cmd
=
8045 cpu_to_scr((SCR_JUMP
^ IFFALSE (MASK (0x80+ln
, 0xff))));
8046 lp
->jump_lcb
.l_paddr
= tp
->jump_lcb
[lh
].l_paddr
;
8048 lp
->load_jump_ccb
[0] = cpu_to_scr(copy_4
);
8049 lp
->load_jump_ccb
[1] = cpu_to_scr(vtobus (&lp
->p_jump_ccb
));
8050 lp
->load_jump_ccb
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_temp
));
8052 lp
->jump_tag
.l_cmd
= cpu_to_scr(SCR_JUMP
);
8053 lp
->jump_tag
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, resel_notag
));
8056 ** Link this lun control block to the JUMP chain.
8058 tp
->jump_lcb
[lh
].l_paddr
= cpu_to_scr(vtobus (&lp
->jump_lcb
));
8061 ** Initialize command queuing control.
8071 /*------------------------------------------------------------------------
8072 ** Lun control block setup on INQUIRY data received.
8073 **------------------------------------------------------------------------
8074 ** We only support WIDE, SYNC for targets and CMDQ for logical units.
8075 ** This setup is done on each INQUIRY since we are expecting user
8076 ** will play with CHANGE DEFINITION commands. :-)
8077 **------------------------------------------------------------------------
8079 static lcb_p
ncr_setup_lcb (ncb_p np
, u_char tn
, u_char ln
, u_char
*inq_data
)
8081 tcb_p tp
= &np
->target
[tn
];
8082 lcb_p lp
= tp
->lp
[ln
];
8086 ** If no lcb, try to allocate it.
8088 if (!lp
&& !(lp
= ncr_alloc_lcb(np
, tn
, ln
)))
8092 ** Get device quirks from a speciality table.
8094 tp
->quirks
= ncr_lookup (inq_data
);
8095 if (tp
->quirks
&& bootverbose
) {
8096 PRINT_LUN(np
, tn
, ln
);
8097 printk ("quirks=%x.\n", tp
->quirks
);
8101 ** Evaluate trustable target/unit capabilities.
8102 ** We only believe device version >= SCSI-2 that
8103 ** use appropriate response data format (2).
8104 ** But it seems that some CCS devices also
8105 ** support SYNC and I donnot want to frustrate
8109 if ((inq_data
[2] & 0x7) >= 2 && (inq_data
[3] & 0xf) == 2)
8110 inq_byte7
= inq_data
[7];
8111 else if ((inq_data
[2] & 0x7) == 1 && (inq_data
[3] & 0xf) == 1)
8112 inq_byte7
= INQ7_SYNC
;
8115 ** Throw away announced LUN capabilities if we are told
8116 ** that there is no real device supported by the logical unit.
8118 if ((inq_data
[0] & 0xe0) > 0x20 || (inq_data
[0] & 0x1f) == 0x1f)
8119 inq_byte7
&= (INQ7_SYNC
| INQ7_WIDE16
);
8122 ** If user is wanting SYNC, force this feature.
8124 if (driver_setup
.force_sync_nego
)
8125 inq_byte7
|= INQ7_SYNC
;
8128 ** Prepare negotiation if SIP capabilities have changed.
8131 if ((inq_byte7
^ tp
->inq_byte7
) & (INQ7_SYNC
| INQ7_WIDE16
)) {
8132 tp
->inq_byte7
= inq_byte7
;
8133 ncr_negotiate(np
, tp
);
8137 ** If unit supports tagged commands, allocate the
8138 ** CCB JUMP table if not yet.
8140 if ((inq_byte7
& INQ7_QUEUE
) && lp
->jump_ccb
== &lp
->jump_ccb_0
) {
8142 lp
->jump_ccb
= m_calloc_dma(256, "JUMP_CCB");
8143 if (!lp
->jump_ccb
) {
8144 lp
->jump_ccb
= &lp
->jump_ccb_0
;
8147 lp
->p_jump_ccb
= cpu_to_scr(vtobus(lp
->jump_ccb
));
8148 for (i
= 0 ; i
< 64 ; i
++)
8150 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_i_t_l_q
));
8151 for (i
= 0 ; i
< MAX_TAGS
; i
++)
8153 lp
->maxnxs
= MAX_TAGS
;
8154 lp
->tags_stime
= ktime_get(3*HZ
);
8158 ** Adjust tagged queueing status if needed.
8160 if ((inq_byte7
^ lp
->inq_byte7
) & INQ7_QUEUE
) {
8161 lp
->inq_byte7
= inq_byte7
;
8162 lp
->numtags
= lp
->maxtags
;
8163 ncr_setup_tags (np
, tn
, ln
);
8170 /*==========================================================
8173 ** Build Scatter Gather Block
8176 **==========================================================
8178 ** The transfer area may be scattered among
8179 ** several non adjacent physical pages.
8181 ** We may use MAX_SCATTER blocks.
8183 **----------------------------------------------------------
8187 ** We try to reduce the number of interrupts caused
8188 ** by unexpected phase changes due to disconnects.
8189 ** A typical harddisk may disconnect before ANY block.
8190 ** If we wanted to avoid unexpected phase changes at all
8191 ** we had to use a break point every 512 bytes.
8192 ** Of course the number of scatter/gather blocks is
8194 ** Under Linux, the scatter/gatter blocks are provided by
8195 ** the generic driver. We just have to copy addresses and
8196 ** sizes to the data segment array.
8199 static int ncr_scatter(ncb_p np
, ccb_p cp
, Scsi_Cmnd
*cmd
)
8201 struct scr_tblmove
*data
;
8203 int use_sg
= (int) cmd
->use_sg
;
8205 data
= cp
->phys
.data
;
8209 if (cmd
->request_bufflen
) {
8210 u_long baddr
= map_scsi_single_data(np
, cmd
);
8212 data
= &data
[MAX_SCATTER
- 1];
8213 data
[0].addr
= cpu_to_scr(baddr
);
8214 data
[0].size
= cpu_to_scr(cmd
->request_bufflen
);
8215 cp
->data_len
= cmd
->request_bufflen
;
8219 else if (use_sg
<= MAX_SCATTER
) {
8220 struct scatterlist
*scatter
= (struct scatterlist
*)cmd
->buffer
;
8222 use_sg
= map_scsi_sg_data(np
, cmd
);
8223 data
= &data
[MAX_SCATTER
- use_sg
];
8225 while (segment
< use_sg
) {
8226 u_long baddr
= scsi_sg_dma_address(&scatter
[segment
]);
8227 unsigned int len
= scsi_sg_dma_len(&scatter
[segment
]);
8229 data
[segment
].addr
= cpu_to_scr(baddr
);
8230 data
[segment
].size
= cpu_to_scr(len
);
8231 cp
->data_len
+= len
;
8242 /*==========================================================
8245 ** Test the pci bus snoop logic :-(
8247 ** Has to be called with interrupts disabled.
8250 **==========================================================
8253 #ifndef SCSI_NCR_IOMAPPED
8254 static int __init
ncr_regtest (struct ncb
* np
)
8256 register volatile u_int32 data
;
8258 ** ncr registers may NOT be cached.
8259 ** write 0xffffffff to a read only register area,
8260 ** and try to read it back.
8263 OUTL_OFF(offsetof(struct ncr_reg
, nc_dstat
), data
);
8264 data
= INL_OFF(offsetof(struct ncr_reg
, nc_dstat
));
8266 if (data
== 0xffffffff) {
8268 if ((data
& 0xe2f0fffd) != 0x02000080) {
8270 printk ("CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
8278 static int __init
ncr_snooptest (struct ncb
* np
)
8280 u_int32 ncr_rd
, ncr_wr
, ncr_bk
, host_rd
, host_wr
, pc
;
8282 #ifndef SCSI_NCR_IOMAPPED
8284 err
|= ncr_regtest (np
);
8285 if (err
) return (err
);
8291 pc
= NCB_SCRIPTH_PHYS (np
, snooptest
);
8295 ** Set memory and register.
8297 np
->ncr_cache
= cpu_to_scr(host_wr
);
8298 OUTL (nc_temp
, ncr_wr
);
8300 ** Start script (exchange values)
8304 ** Wait 'til done (with timeout)
8306 for (i
=0; i
<NCR_SNOOP_TIMEOUT
; i
++)
8307 if (INB(nc_istat
) & (INTF
|SIP
|DIP
))
8310 ** Save termination position.
8314 ** Read memory and register.
8316 host_rd
= scr_to_cpu(np
->ncr_cache
);
8317 ncr_rd
= INL (nc_scratcha
);
8318 ncr_bk
= INL (nc_temp
);
8322 ncr_chip_reset(np
, 100);
8324 ** check for timeout
8326 if (i
>=NCR_SNOOP_TIMEOUT
) {
8327 printk ("CACHE TEST FAILED: timeout.\n");
8331 ** Check termination position.
8333 if (pc
!= NCB_SCRIPTH_PHYS (np
, snoopend
)+8) {
8334 printk ("CACHE TEST FAILED: script execution failed.\n");
8335 printk ("start=%08lx, pc=%08lx, end=%08lx\n",
8336 (u_long
) NCB_SCRIPTH_PHYS (np
, snooptest
), (u_long
) pc
,
8337 (u_long
) NCB_SCRIPTH_PHYS (np
, snoopend
) +8);
8343 if (host_wr
!= ncr_rd
) {
8344 printk ("CACHE TEST FAILED: host wrote %d, ncr read %d.\n",
8345 (int) host_wr
, (int) ncr_rd
);
8348 if (host_rd
!= ncr_wr
) {
8349 printk ("CACHE TEST FAILED: ncr wrote %d, host read %d.\n",
8350 (int) ncr_wr
, (int) host_rd
);
8353 if (ncr_bk
!= ncr_wr
) {
8354 printk ("CACHE TEST FAILED: ncr wrote %d, read back %d.\n",
8355 (int) ncr_wr
, (int) ncr_bk
);
8361 /*==========================================================
8366 ** @GENSCSI@ should be integrated to scsiconf.c
8369 **==========================================================
8372 struct table_entry
{
8373 char * manufacturer
;
8379 static struct table_entry device_tab
[] =
8382 {"", "", "", QUIRK_NOMSG
},
8384 {"SONY", "SDT-5000", "3.17", QUIRK_NOMSG
},
8385 {"WangDAT", "Model 2600", "01.7", QUIRK_NOMSG
},
8386 {"WangDAT", "Model 3200", "02.2", QUIRK_NOMSG
},
8387 {"WangDAT", "Model 1300", "02.4", QUIRK_NOMSG
},
8388 {"", "", "", 0} /* catch all: must be last entry. */
8391 static u_long
ncr_lookup(char * id
)
8393 struct table_entry
* p
= device_tab
;
8399 r
= p
->manufacturer
;
8400 while ((c
=*r
++)) if (c
!=*d
++) break;
8405 while ((c
=*r
++)) if (c
!=*d
++) break;
8410 while ((c
=*r
++)) if (c
!=*d
++) break;
8417 /*==========================================================
8419 ** Determine the ncr's clock frequency.
8420 ** This is essential for the negotiation
8421 ** of the synchronous transfer rate.
8423 **==========================================================
8425 ** Note: we have to return the correct value.
8426 ** THERE IS NO SAVE DEFAULT VALUE.
8428 ** Most NCR/SYMBIOS boards are delivered with a 40 Mhz clock.
8429 ** 53C860 and 53C875 rev. 1 support fast20 transfers but
8430 ** do not have a clock doubler and so are provided with a
8431 ** 80 MHz clock. All other fast20 boards incorporate a doubler
8432 ** and so should be delivered with a 40 MHz clock.
8433 ** The future fast40 chips (895/895) use a 40 Mhz base clock
8434 ** and provide a clock quadrupler (160 Mhz). The code below
8435 ** tries to deal as cleverly as possible with all this stuff.
8437 **----------------------------------------------------------
8441 * Select NCR SCSI clock frequency
8443 static void ncr_selectclock(ncb_p np
, u_char scntl3
)
8445 if (np
->multiplier
< 2) {
8446 OUTB(nc_scntl3
, scntl3
);
8450 if (bootverbose
>= 2)
8451 printk ("%s: enabling clock multiplier\n", ncr_name(np
));
8453 OUTB(nc_stest1
, DBLEN
); /* Enable clock multiplier */
8454 if (np
->multiplier
> 2) { /* Poll bit 5 of stest4 for quadrupler */
8456 while (!(INB(nc_stest4
) & LCKFRQ
) && --i
> 0)
8459 printk("%s: the chip cannot lock the frequency\n", ncr_name(np
));
8460 } else /* Wait 20 micro-seconds for doubler */
8462 OUTB(nc_stest3
, HSC
); /* Halt the scsi clock */
8463 OUTB(nc_scntl3
, scntl3
);
8464 OUTB(nc_stest1
, (DBLEN
|DBLSEL
));/* Select clock multiplier */
8465 OUTB(nc_stest3
, 0x00); /* Restart scsi clock */
8470 * calculate NCR SCSI clock frequency (in KHz)
8472 static unsigned __init
ncrgetfreq (ncb_p np
, int gen
)
8478 * Measure GEN timer delay in order
8479 * to calculate SCSI clock frequency
8481 * This code will never execute too
8482 * many loop iterations (if DELAY is
8483 * reasonably correct). It could get
8484 * too low a delay (too high a freq.)
8485 * if the CPU is slow executing the
8486 * loop for some reason (an NMI, for
8487 * example). For this reason we will
8488 * if multiple measurements are to be
8489 * performed trust the higher delay
8490 * (lower frequency returned).
8492 OUTB (nc_stest1
, 0); /* make sure clock doubler is OFF */
8493 OUTW (nc_sien
, 0); /* mask all scsi interrupts */
8494 (void) INW (nc_sist
); /* clear pending scsi interrupt */
8495 OUTB (nc_dien
, 0); /* mask all dma interrupts */
8496 (void) INW (nc_sist
); /* another one, just to be sure :) */
8497 OUTB (nc_scntl3
, 4); /* set pre-scaler to divide by 3 */
8498 OUTB (nc_stime1
, 0); /* disable general purpose timer */
8499 OUTB (nc_stime1
, gen
); /* set to nominal delay of 1<<gen * 125us */
8500 while (!(INW(nc_sist
) & GEN
) && ms
++ < 100000) {
8501 for (count
= 0; count
< 10; count
++)
8502 UDELAY (100); /* count ms */
8504 OUTB (nc_stime1
, 0); /* disable general purpose timer */
8506 * set prescaler to divide by whatever 0 means
8507 * 0 ought to choose divide by 2, but appears
8508 * to set divide by 3.5 mode in my 53c810 ...
8510 OUTB (nc_scntl3
, 0);
8512 if (bootverbose
>= 2)
8513 printk ("%s: Delay (GEN=%d): %u msec\n", ncr_name(np
), gen
, ms
);
8515 * adjust for prescaler, and convert into KHz
8517 return ms
? ((1 << gen
) * 4340) / ms
: 0;
8521 * Get/probe NCR SCSI clock frequency
8523 static void __init
ncr_getclock (ncb_p np
, int mult
)
8525 unsigned char scntl3
= INB(nc_scntl3
);
8526 unsigned char stest1
= INB(nc_stest1
);
8533 ** True with 875 or 895 with clock multiplier selected
8535 if (mult
> 1 && (stest1
& (DBLEN
+DBLSEL
)) == DBLEN
+DBLSEL
) {
8536 if (bootverbose
>= 2)
8537 printk ("%s: clock multiplier found\n", ncr_name(np
));
8538 np
->multiplier
= mult
;
8542 ** If multiplier not found or scntl3 not 7,5,3,
8543 ** reset chip and get frequency from general purpose timer.
8544 ** Otherwise trust scntl3 BIOS setting.
8546 if (np
->multiplier
!= mult
|| (scntl3
& 7) < 3 || !(scntl3
& 1)) {
8549 ncr_chip_reset(np
, 5);
8551 (void) ncrgetfreq (np
, 11); /* throw away first result */
8552 f1
= ncrgetfreq (np
, 11);
8553 f2
= ncrgetfreq (np
, 11);
8556 printk ("%s: NCR clock is %uKHz, %uKHz\n", ncr_name(np
), f1
, f2
);
8558 if (f1
> f2
) f1
= f2
; /* trust lower result */
8560 if (f1
< 45000) f1
= 40000;
8561 else if (f1
< 55000) f1
= 50000;
8564 if (f1
< 80000 && mult
> 1) {
8565 if (bootverbose
>= 2)
8566 printk ("%s: clock multiplier assumed\n", ncr_name(np
));
8567 np
->multiplier
= mult
;
8570 if ((scntl3
& 7) == 3) f1
= 40000;
8571 else if ((scntl3
& 7) == 5) f1
= 80000;
8574 f1
/= np
->multiplier
;
8578 ** Compute controller synchronous parameters.
8580 f1
*= np
->multiplier
;
8584 /*===================== LINUX ENTRY POINTS SECTION ==========================*/
8587 ** Linux select queue depths function
8590 int ncr53c8xx_slave_configure(Scsi_Device
*device
)
8592 struct Scsi_Host
*host
= device
->host
;
8596 int numtags
, depth_to_use
;
8598 np
= ((struct host_data
*) host
->hostdata
)->ncb
;
8599 tp
= &np
->target
[device
->id
];
8600 lp
= tp
->lp
[device
->lun
];
8603 ** Select queue depth from driver setup.
8604 ** Donnot use more than configured by user.
8606 ** Donnot use more than our maximum.
8608 numtags
= device_queue_depth(np
->unit
, device
->id
, device
->lun
);
8609 if (numtags
> tp
->usrtags
)
8610 numtags
= tp
->usrtags
;
8611 if (!device
->tagged_supported
)
8613 depth_to_use
= numtags
;
8614 if (depth_to_use
< 2)
8616 if (depth_to_use
> MAX_TAGS
)
8617 depth_to_use
= MAX_TAGS
;
8619 scsi_adjust_queue_depth(device
,
8620 (device
->tagged_supported
?
8621 MSG_SIMPLE_TAG
: 0),
8625 ** Since the queue depth is not tunable under Linux,
8626 ** we need to know this value in order not to
8627 ** announce stupid things to user.
8630 lp
->numtags
= lp
->maxtags
= numtags
;
8631 lp
->scdev_depth
= depth_to_use
;
8633 ncr_setup_tags (np
, device
->id
, device
->lun
);
8635 #ifdef DEBUG_NCR53C8XX
8636 printk("ncr53c8xx_select_queue_depth: host=%d, id=%d, lun=%d, depth=%d\n",
8637 np
->unit
, device
->id
, device
->lun
, depth_to_use
);
8644 ** Linux entry point of queuecommand() function
8647 int ncr53c8xx_queue_command (Scsi_Cmnd
*cmd
, void (* done
)(Scsi_Cmnd
*))
8649 ncb_p np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
8650 unsigned long flags
;
8653 #ifdef DEBUG_NCR53C8XX
8654 printk("ncr53c8xx_queue_command\n");
8657 cmd
->scsi_done
= done
;
8658 cmd
->host_scribble
= NULL
;
8659 #ifdef SCSI_NCR_DYNAMIC_DMA_MAPPING
8660 cmd
->__data_mapped
= 0;
8661 cmd
->__data_mapping
= 0;
8664 NCR_LOCK_NCB(np
, flags
);
8666 if ((sts
= ncr_queue_command(np
, cmd
)) != DID_OK
) {
8667 cmd
->result
= ScsiResult(sts
, 0);
8668 #ifdef DEBUG_NCR53C8XX
8669 printk("ncr53c8xx : command not queued - result=%d\n", sts
);
8672 #ifdef DEBUG_NCR53C8XX
8674 printk("ncr53c8xx : command successfully queued\n");
8677 NCR_UNLOCK_NCB(np
, flags
);
8679 if (sts
!= DID_OK
) {
8680 unmap_scsi_data(np
, cmd
);
8688 ** Linux entry point of the interrupt handler.
8689 ** Since linux versions > 1.3.70, we trust the kernel for
8690 ** passing the internal host descriptor as 'dev_id'.
8691 ** Otherwise, we scan the host list and call the interrupt
8692 ** routine for each host that uses this IRQ.
8695 irqreturn_t
ncr53c8xx_intr(int irq
, void *dev_id
, struct pt_regs
* regs
)
8697 unsigned long flags
;
8698 struct Scsi_Host
*shost
= (struct Scsi_Host
*)dev_id
;
8699 struct host_data
*host_data
= (struct host_data
*)shost
->hostdata
;
8700 ncb_p np
= host_data
->ncb
;
8701 Scsi_Cmnd
*done_list
;
8703 #ifdef DEBUG_NCR53C8XX
8704 printk("ncr53c8xx : interrupt received\n");
8707 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("[");
8709 NCR_LOCK_NCB(np
, flags
);
8711 done_list
= np
->done_list
;
8713 NCR_UNLOCK_NCB(np
, flags
);
8715 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("]\n");
8718 NCR_LOCK_SCSI_DONE(done_list
->device
->host
, flags
);
8719 ncr_flush_done_cmds(done_list
);
8720 NCR_UNLOCK_SCSI_DONE(done_list
->device
->host
, flags
);
8726 ** Linux entry point of the timer handler
8729 static void ncr53c8xx_timeout(unsigned long npref
)
8731 ncb_p np
= (ncb_p
) npref
;
8732 unsigned long flags
;
8733 Scsi_Cmnd
*done_list
;
8735 NCR_LOCK_NCB(np
, flags
);
8736 ncr_timeout((ncb_p
) np
);
8737 done_list
= np
->done_list
;
8739 NCR_UNLOCK_NCB(np
, flags
);
8742 NCR_LOCK_SCSI_DONE(done_list
->device
->host
, flags
);
8743 ncr_flush_done_cmds(done_list
);
8744 NCR_UNLOCK_SCSI_DONE(done_list
->device
->host
, flags
);
8749 ** Linux entry point of reset() function
8752 int ncr53c8xx_bus_reset(Scsi_Cmnd
*cmd
)
8754 ncb_p np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
8756 unsigned long flags
;
8757 Scsi_Cmnd
*done_list
;
8759 NCR_LOCK_NCB(np
, flags
);
8762 * If the mid-level driver told us reset is synchronous, it seems
8763 * that we must call the done() callback for the involved command,
8764 * even if this command was not queued to the low-level driver,
8765 * before returning SUCCESS.
8768 sts
= ncr_reset_bus(np
, cmd
, 1);
8770 done_list
= np
->done_list
;
8772 NCR_UNLOCK_NCB(np
, flags
);
8774 ncr_flush_done_cmds(done_list
);
8780 ** Linux entry point of abort() function
8783 int ncr53c8xx_abort(Scsi_Cmnd
*cmd
)
8785 ncb_p np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
8787 unsigned long flags
;
8788 Scsi_Cmnd
*done_list
;
8790 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
8791 printk("ncr53c8xx_abort: pid=%lu serial_number=%ld serial_number_at_timeout=%ld\n",
8792 cmd
->pid
, cmd
->serial_number
, cmd
->serial_number_at_timeout
);
8794 printk("ncr53c8xx_abort: command pid %lu\n", cmd
->pid
);
8797 NCR_LOCK_NCB(np
, flags
);
8799 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
8801 * We have to just ignore abort requests in some situations.
8803 if (cmd
->serial_number
!= cmd
->serial_number_at_timeout
) {
8804 sts
= SCSI_ABORT_NOT_RUNNING
;
8809 sts
= ncr_abort_command(np
, cmd
);
8811 done_list
= np
->done_list
;
8813 NCR_UNLOCK_NCB(np
, flags
);
8815 ncr_flush_done_cmds(done_list
);
8821 int ncr53c8xx_release(struct Scsi_Host
*host
)
8823 #ifdef DEBUG_NCR53C8XX
8824 printk("ncr53c8xx : release\n");
8826 ncr_detach(((struct host_data
*) host
->hostdata
)->ncb
);
8833 ** Scsi command waiting list management.
8835 ** It may happen that we cannot insert a scsi command into the start queue,
8836 ** in the following circumstances.
8837 ** Too few preallocated ccb(s),
8838 ** maxtags < cmd_per_lun of the Linux host control block,
8840 ** Such scsi commands are inserted into a waiting list.
8841 ** When a scsi command complete, we try to requeue the commands of the
8845 #define next_wcmd host_scribble
8847 static void insert_into_waiting_list(ncb_p np
, Scsi_Cmnd
*cmd
)
8851 #ifdef DEBUG_WAITING_LIST
8852 printk("%s: cmd %lx inserted into waiting list\n", ncr_name(np
), (u_long
) cmd
);
8855 if (!(wcmd
= np
->waiting_list
)) np
->waiting_list
= cmd
;
8857 while ((wcmd
->next_wcmd
) != 0)
8858 wcmd
= (Scsi_Cmnd
*) wcmd
->next_wcmd
;
8859 wcmd
->next_wcmd
= (char *) cmd
;
8863 static Scsi_Cmnd
*retrieve_from_waiting_list(int to_remove
, ncb_p np
, Scsi_Cmnd
*cmd
)
8865 Scsi_Cmnd
**pcmd
= &np
->waiting_list
;
8870 *pcmd
= (Scsi_Cmnd
*) cmd
->next_wcmd
;
8873 #ifdef DEBUG_WAITING_LIST
8874 printk("%s: cmd %lx retrieved from waiting list\n", ncr_name(np
), (u_long
) cmd
);
8878 pcmd
= (Scsi_Cmnd
**) &(*pcmd
)->next_wcmd
;
8883 static void process_waiting_list(ncb_p np
, int sts
)
8885 Scsi_Cmnd
*waiting_list
, *wcmd
;
8887 waiting_list
= np
->waiting_list
;
8888 np
->waiting_list
= 0;
8890 #ifdef DEBUG_WAITING_LIST
8891 if (waiting_list
) printk("%s: waiting_list=%lx processing sts=%d\n", ncr_name(np
), (u_long
) waiting_list
, sts
);
8893 while ((wcmd
= waiting_list
) != 0) {
8894 waiting_list
= (Scsi_Cmnd
*) wcmd
->next_wcmd
;
8895 wcmd
->next_wcmd
= 0;
8896 if (sts
== DID_OK
) {
8897 #ifdef DEBUG_WAITING_LIST
8898 printk("%s: cmd %lx trying to requeue\n", ncr_name(np
), (u_long
) wcmd
);
8900 sts
= ncr_queue_command(np
, wcmd
);
8902 if (sts
!= DID_OK
) {
8903 #ifdef DEBUG_WAITING_LIST
8904 printk("%s: cmd %lx done forced sts=%d\n", ncr_name(np
), (u_long
) wcmd
, sts
);
8906 wcmd
->result
= ScsiResult(sts
, 0);
8907 ncr_queue_done_cmd(np
, wcmd
);
8914 #ifdef SCSI_NCR_PROC_INFO_SUPPORT
8916 /*=========================================================================
8917 ** Proc file system stuff
8919 ** A read operation returns profile information.
8920 ** A write operation is a control command.
8921 ** The string is parsed in the driver code and the command is passed
8922 ** to the ncr_usercmd() function.
8923 **=========================================================================
8926 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
8928 #define is_digit(c) ((c) >= '0' && (c) <= '9')
8929 #define digit_to_bin(c) ((c) - '0')
8930 #define is_space(c) ((c) == ' ' || (c) == '\t')
8932 static int skip_spaces(char *ptr
, int len
)
8936 for (cnt
= len
; cnt
> 0 && (c
= *ptr
++) && is_space(c
); cnt
--);
8941 static int get_int_arg(char *ptr
, int len
, u_long
*pv
)
8946 for (v
= 0, cnt
= len
; cnt
> 0 && (c
= *ptr
++) && is_digit(c
); cnt
--) {
8947 v
= (v
* 10) + digit_to_bin(c
);
8956 static int is_keyword(char *ptr
, int len
, char *verb
)
8958 int verb_len
= strlen(verb
);
8960 if (len
>= strlen(verb
) && !memcmp(verb
, ptr
, verb_len
))
8967 #define SKIP_SPACES(min_spaces) \
8968 if ((arg_len = skip_spaces(ptr, len)) < (min_spaces)) \
8970 ptr += arg_len; len -= arg_len;
8972 #define GET_INT_ARG(v) \
8973 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
8975 ptr += arg_len; len -= arg_len;
8979 ** Parse a control command
8982 static int ncr_user_command(ncb_p np
, char *buffer
, int length
)
8986 struct usrcmd
*uc
= &np
->user
;
8990 bzero(uc
, sizeof(*uc
));
8992 if (len
> 0 && ptr
[len
-1] == '\n')
8995 if ((arg_len
= is_keyword(ptr
, len
, "setsync")) != 0)
8996 uc
->cmd
= UC_SETSYNC
;
8997 else if ((arg_len
= is_keyword(ptr
, len
, "settags")) != 0)
8998 uc
->cmd
= UC_SETTAGS
;
8999 else if ((arg_len
= is_keyword(ptr
, len
, "setorder")) != 0)
9000 uc
->cmd
= UC_SETORDER
;
9001 else if ((arg_len
= is_keyword(ptr
, len
, "setverbose")) != 0)
9002 uc
->cmd
= UC_SETVERBOSE
;
9003 else if ((arg_len
= is_keyword(ptr
, len
, "setwide")) != 0)
9004 uc
->cmd
= UC_SETWIDE
;
9005 else if ((arg_len
= is_keyword(ptr
, len
, "setdebug")) != 0)
9006 uc
->cmd
= UC_SETDEBUG
;
9007 else if ((arg_len
= is_keyword(ptr
, len
, "setflag")) != 0)
9008 uc
->cmd
= UC_SETFLAG
;
9012 #ifdef DEBUG_PROC_INFO
9013 printk("ncr_user_command: arg_len=%d, cmd=%ld\n", arg_len
, uc
->cmd
);
9018 ptr
+= arg_len
; len
-= arg_len
;
9026 if ((arg_len
= is_keyword(ptr
, len
, "all")) != 0) {
9027 ptr
+= arg_len
; len
-= arg_len
;
9030 GET_INT_ARG(target
);
9031 uc
->target
= (1<<target
);
9032 #ifdef DEBUG_PROC_INFO
9033 printk("ncr_user_command: target=%ld\n", target
);
9045 GET_INT_ARG(uc
->data
);
9046 #ifdef DEBUG_PROC_INFO
9047 printk("ncr_user_command: data=%ld\n", uc
->data
);
9052 if ((arg_len
= is_keyword(ptr
, len
, "simple")))
9053 uc
->data
= M_SIMPLE_TAG
;
9054 else if ((arg_len
= is_keyword(ptr
, len
, "ordered")))
9055 uc
->data
= M_ORDERED_TAG
;
9056 else if ((arg_len
= is_keyword(ptr
, len
, "default")))
9064 if ((arg_len
= is_keyword(ptr
, len
, "alloc")))
9065 uc
->data
|= DEBUG_ALLOC
;
9066 else if ((arg_len
= is_keyword(ptr
, len
, "phase")))
9067 uc
->data
|= DEBUG_PHASE
;
9068 else if ((arg_len
= is_keyword(ptr
, len
, "queue")))
9069 uc
->data
|= DEBUG_QUEUE
;
9070 else if ((arg_len
= is_keyword(ptr
, len
, "result")))
9071 uc
->data
|= DEBUG_RESULT
;
9072 else if ((arg_len
= is_keyword(ptr
, len
, "scatter")))
9073 uc
->data
|= DEBUG_SCATTER
;
9074 else if ((arg_len
= is_keyword(ptr
, len
, "script")))
9075 uc
->data
|= DEBUG_SCRIPT
;
9076 else if ((arg_len
= is_keyword(ptr
, len
, "tiny")))
9077 uc
->data
|= DEBUG_TINY
;
9078 else if ((arg_len
= is_keyword(ptr
, len
, "timing")))
9079 uc
->data
|= DEBUG_TIMING
;
9080 else if ((arg_len
= is_keyword(ptr
, len
, "nego")))
9081 uc
->data
|= DEBUG_NEGO
;
9082 else if ((arg_len
= is_keyword(ptr
, len
, "tags")))
9083 uc
->data
|= DEBUG_TAGS
;
9086 ptr
+= arg_len
; len
-= arg_len
;
9088 #ifdef DEBUG_PROC_INFO
9089 printk("ncr_user_command: data=%ld\n", uc
->data
);
9095 if ((arg_len
= is_keyword(ptr
, len
, "trace")))
9096 uc
->data
|= UF_TRACE
;
9097 else if ((arg_len
= is_keyword(ptr
, len
, "no_disc")))
9098 uc
->data
|= UF_NODISC
;
9101 ptr
+= arg_len
; len
-= arg_len
;
9111 unsigned long flags
;
9113 NCR_LOCK_NCB(np
, flags
);
9115 NCR_UNLOCK_NCB(np
, flags
);
9120 #endif /* SCSI_NCR_USER_COMMAND_SUPPORT */
9123 #ifdef SCSI_NCR_USER_INFO_SUPPORT
9125 ** Copy formatted information into the input buffer.
9128 static int ncr_host_info(ncb_p np
, char *ptr
, off_t offset
, int len
)
9130 struct info_str info
;
9134 info
.offset
= offset
;
9137 copy_info(&info
, " Chip NCR53C%s, device id 0x%x, "
9138 "revision id 0x%x\n",
9139 np
->chip_name
, np
->device_id
, np
->revision_id
);
9140 copy_info(&info
, " On PCI bus %d, device %d, function %d, "
9146 np
->bus
, (np
->device_fn
& 0xf8) >> 3, np
->device_fn
& 7,
9148 __irq_itoa(np
->irq
));
9152 copy_info(&info
, " Synchronous period factor %d, "
9153 "max commands per lun %d\n",
9154 (int) np
->minsync
, MAX_TAGS
);
9156 if (driver_setup
.debug
|| driver_setup
.verbose
> 1) {
9157 copy_info(&info
, " Debug flags 0x%x, verbosity level %d\n",
9158 driver_setup
.debug
, driver_setup
.verbose
);
9161 return info
.pos
> info
.offset
? info
.pos
- info
.offset
: 0;
9164 #endif /* SCSI_NCR_USER_INFO_SUPPORT */
9167 ** Entry point of the scsi proc fs of the driver.
9168 ** - func = 0 means read (returns profile data)
9169 ** - func = 1 means write (parse user control command)
9172 static int ncr53c8xx_proc_info(struct Scsi_Host
*host
, char *buffer
, char **start
, off_t offset
,
9173 int length
, int func
)
9175 struct host_data
*host_data
;
9179 #ifdef DEBUG_PROC_INFO
9180 printk("ncr53c8xx_proc_info: hostno=%d, func=%d\n", host
->host_no
, func
);
9183 host_data
= (struct host_data
*) host
->hostdata
;
9184 ncb
= host_data
->ncb
;
9187 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
9188 retv
= ncr_user_command(ncb
, buffer
, length
);
9196 #ifdef SCSI_NCR_USER_INFO_SUPPORT
9197 retv
= ncr_host_info(ncb
, buffer
, offset
, length
);
9206 /*=========================================================================
9207 ** End of proc file system stuff
9208 **=========================================================================
9213 /*==========================================================
9215 ** /proc directory entry.
9217 **==========================================================
9219 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,27)
9220 static struct proc_dir_entry proc_scsi_ncr53c8xx
= {
9221 PROC_SCSI_NCR53C8XX
, 9, NAME53C8XX
,
9222 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2
9226 /*==========================================================
9228 ** Boot command line.
9230 **==========================================================
9233 char *ncr53c8xx
= 0; /* command line passed by insmod */
9234 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,30)
9235 MODULE_PARM(ncr53c8xx
, "s");
9239 int __init
ncr53c8xx_setup(char *str
)
9241 return sym53c8xx__setup(str
);
9244 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,13)
9246 __setup("ncr53c8xx=", ncr53c8xx_setup
);
9250 /*===================================================================
9252 ** SYM53C8XX supported device list
9254 **===================================================================
9257 static u_short ncr_chip_ids
[] __initdata
= {
9259 PCI_DEVICE_ID_NCR_53C810
,
9260 PCI_DEVICE_ID_NCR_53C815
,
9261 PCI_DEVICE_ID_NCR_53C820
,
9262 PCI_DEVICE_ID_NCR_53C825
,
9263 PCI_DEVICE_ID_NCR_53C860
,
9264 PCI_DEVICE_ID_NCR_53C875
,
9265 PCI_DEVICE_ID_NCR_53C875J
,
9266 PCI_DEVICE_ID_NCR_53C885
,
9267 PCI_DEVICE_ID_NCR_53C895
,
9268 PCI_DEVICE_ID_NCR_53C896
,
9269 PCI_DEVICE_ID_NCR_53C895A
,
9270 PCI_DEVICE_ID_NCR_53C1510D
9274 /*==========================================================
9276 ** Chip detection entry point.
9278 **==========================================================
9280 int __init
ncr53c8xx_detect(Scsi_Host_Template
*tpnt
)
9282 #if defined(SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT) && defined(MODULE)
9284 ncr53c8xx_setup(ncr53c8xx
);
9287 return sym53c8xx__detect(tpnt
, ncr_chip_ids
,
9288 sizeof(ncr_chip_ids
)/sizeof(ncr_chip_ids
[0]));
9291 /*==========================================================
9293 ** Entry point for info() function
9295 **==========================================================
9297 const char *ncr53c8xx_info (struct Scsi_Host
*host
)
9299 return SCSI_NCR_DRIVER_NAME
;