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)
88 ** Memory mapped IO (linux-1.3.X and above only)
90 ** Shared IRQ (since linux-1.3.72)
93 /* Name and version of the driver */
94 #define SCSI_NCR_DRIVER_NAME "ncr53c8xx-3.4.3f"
96 #define SCSI_NCR_DEBUG_FLAGS (0)
98 /*==========================================================
102 **==========================================================
105 #include <linux/blkdev.h>
106 #include <linux/delay.h>
107 #include <linux/dma-mapping.h>
108 #include <linux/errno.h>
109 #include <linux/init.h>
110 #include <linux/interrupt.h>
111 #include <linux/ioport.h>
112 #include <linux/mm.h>
113 #include <linux/module.h>
114 #include <linux/sched.h>
115 #include <linux/signal.h>
116 #include <linux/spinlock.h>
117 #include <linux/stat.h>
118 #include <linux/string.h>
119 #include <linux/time.h>
120 #include <linux/timer.h>
121 #include <linux/types.h>
125 #include <asm/system.h>
128 #include <scsi/scsi_host.h>
130 #include "ncr53c8xx.h"
133 ** Donnot compile integrity checking code for Linux-2.3.0
134 ** and above since SCSI data structures are not ready yet.
136 /* #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */
138 #define SCSI_NCR_INTEGRITY_CHECKING
141 #define NAME53C "ncr53c"
142 #define NAME53C8XX "ncr53c8xx"
143 #define DRIVER_SMP_LOCK ncr53c8xx_lock
145 #include "sym53c8xx_comm.h"
148 /*==========================================================
150 ** The CCB done queue uses an array of CCB virtual
151 ** addresses. Empty entries are flagged using the bogus
152 ** virtual address 0xffffffff.
154 ** Since PCI ensures that only aligned DWORDs are accessed
155 ** atomically, 64 bit little-endian architecture requires
156 ** to test the high order DWORD of the entry to determine
157 ** if it is empty or valid.
159 ** BTW, I will make things differently as soon as I will
160 ** have a better idea, but this is simple and should work.
162 **==========================================================
165 #define SCSI_NCR_CCB_DONE_SUPPORT
166 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
169 #define CCB_DONE_EMPTY 0xffffffffUL
171 /* All 32 bit architectures */
172 #if BITS_PER_LONG == 32
173 #define CCB_DONE_VALID(cp) (((u_long) cp) != CCB_DONE_EMPTY)
175 /* All > 32 bit (64 bit) architectures regardless endian-ness */
177 #define CCB_DONE_VALID(cp) \
178 ((((u_long) cp) & 0xffffffff00000000ul) && \
179 (((u_long) cp) & 0xfffffffful) != CCB_DONE_EMPTY)
182 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
184 /*==========================================================
186 ** Configuration and Debugging
188 **==========================================================
192 ** SCSI address of this device.
193 ** The boot routines should have set it.
197 #ifndef SCSI_NCR_MYADDR
198 #define SCSI_NCR_MYADDR (7)
202 ** The maximum number of tags per logic unit.
203 ** Used only for disk devices that support tags.
206 #ifndef SCSI_NCR_MAX_TAGS
207 #define SCSI_NCR_MAX_TAGS (8)
211 ** TAGS are actually limited to 64 tags/lun.
212 ** We need to deal with power of 2, for alignment constraints.
214 #if SCSI_NCR_MAX_TAGS > 64
215 #define MAX_TAGS (64)
217 #define MAX_TAGS SCSI_NCR_MAX_TAGS
223 ** Choose appropriate type for tag bitmap.
226 typedef u64 tagmap_t
;
228 typedef u32 tagmap_t
;
232 ** Number of targets supported by the driver.
233 ** n permits target numbers 0..n-1.
234 ** Default is 16, meaning targets #0..#15.
238 #ifdef SCSI_NCR_MAX_TARGET
239 #define MAX_TARGET (SCSI_NCR_MAX_TARGET)
241 #define MAX_TARGET (16)
245 ** Number of logic units supported by the driver.
246 ** n enables logic unit numbers 0..n-1.
247 ** The common SCSI devices require only
248 ** one lun, so take 1 as the default.
251 #ifdef SCSI_NCR_MAX_LUN
252 #define MAX_LUN SCSI_NCR_MAX_LUN
258 ** Asynchronous pre-scaler (ns). Shall be 40
261 #ifndef SCSI_NCR_MIN_ASYNC
262 #define SCSI_NCR_MIN_ASYNC (40)
266 ** The maximum number of jobs scheduled for starting.
267 ** There should be one slot per target, and one slot
268 ** for each tag of each target in use.
269 ** The calculation below is actually quite silly ...
272 #ifdef SCSI_NCR_CAN_QUEUE
273 #define MAX_START (SCSI_NCR_CAN_QUEUE + 4)
275 #define MAX_START (MAX_TARGET + 7 * MAX_TAGS)
279 ** We limit the max number of pending IO to 250.
280 ** since we donnot want to allocate more than 1
281 ** PAGE for 'scripth'.
285 #define MAX_START 250
289 ** The maximum number of segments a transfer is split into.
290 ** We support up to 127 segments for both read and write.
291 ** The data scripts are broken into 2 sub-scripts.
292 ** 80 (MAX_SCATTERL) segments are moved from a sub-script
293 ** in on-chip RAM. This makes data transfers shorter than
294 ** 80k (assuming 1k fs) as fast as possible.
297 #define MAX_SCATTER (SCSI_NCR_MAX_SCATTER)
299 #if (MAX_SCATTER > 80)
300 #define MAX_SCATTERL 80
301 #define MAX_SCATTERH (MAX_SCATTER - MAX_SCATTERL)
303 #define MAX_SCATTERL (MAX_SCATTER-1)
304 #define MAX_SCATTERH 1
311 #define NCR_SNOOP_TIMEOUT (1000000)
317 #define ScsiResult(host_code, scsi_code) (((host_code) << 16) + ((scsi_code) & 0x7f))
319 static void ncr53c8xx_timeout(unsigned long np
);
320 static int ncr53c8xx_proc_info(struct Scsi_Host
*host
, char *buffer
, char **start
, off_t offset
,
321 int length
, int func
);
323 #define initverbose (driver_setup.verbose)
324 #define bootverbose (np->verbose)
326 /*==========================================================
328 ** Command control block states.
330 **==========================================================
335 #define HS_NEGOTIATE (2) /* sync/wide data transfer*/
336 #define HS_DISCONNECT (3) /* Disconnected by target */
338 #define HS_DONEMASK (0x80)
339 #define HS_COMPLETE (4|HS_DONEMASK)
340 #define HS_SEL_TIMEOUT (5|HS_DONEMASK) /* Selection timeout */
341 #define HS_RESET (6|HS_DONEMASK) /* SCSI reset */
342 #define HS_ABORTED (7|HS_DONEMASK) /* Transfer aborted */
343 #define HS_TIMEOUT (8|HS_DONEMASK) /* Software timeout */
344 #define HS_FAIL (9|HS_DONEMASK) /* SCSI or PCI bus errors */
345 #define HS_UNEXPECTED (10|HS_DONEMASK)/* Unexpected disconnect */
348 ** Invalid host status values used by the SCRIPTS processor
349 ** when the nexus is not fully identified.
350 ** Shall never appear in a CCB.
353 #define HS_INVALMASK (0x40)
354 #define HS_SELECTING (0|HS_INVALMASK)
355 #define HS_IN_RESELECT (1|HS_INVALMASK)
356 #define HS_STARTING (2|HS_INVALMASK)
359 ** Flags set by the SCRIPT processor for commands
360 ** that have been skipped.
362 #define HS_SKIPMASK (0x20)
364 /*==========================================================
366 ** Software Interrupt Codes
368 **==========================================================
371 #define SIR_BAD_STATUS (1)
372 #define SIR_XXXXXXXXXX (2)
373 #define SIR_NEGO_SYNC (3)
374 #define SIR_NEGO_WIDE (4)
375 #define SIR_NEGO_FAILED (5)
376 #define SIR_NEGO_PROTO (6)
377 #define SIR_REJECT_RECEIVED (7)
378 #define SIR_REJECT_SENT (8)
379 #define SIR_IGN_RESIDUE (9)
380 #define SIR_MISSING_SAVE (10)
381 #define SIR_RESEL_NO_MSG_IN (11)
382 #define SIR_RESEL_NO_IDENTIFY (12)
383 #define SIR_RESEL_BAD_LUN (13)
384 #define SIR_RESEL_BAD_TARGET (14)
385 #define SIR_RESEL_BAD_I_T_L (15)
386 #define SIR_RESEL_BAD_I_T_L_Q (16)
387 #define SIR_DONE_OVERFLOW (17)
388 #define SIR_INTFLY (18)
391 /*==========================================================
393 ** Extended error codes.
394 ** xerr_status field of struct ccb.
396 **==========================================================
400 #define XE_EXTRA_DATA (1) /* unexpected data phase */
401 #define XE_BAD_PHASE (2) /* illegal phase (4/5) */
403 /*==========================================================
405 ** Negotiation status.
406 ** nego_status field of struct ccb.
408 **==========================================================
411 #define NS_NOCHANGE (0)
416 /*==========================================================
418 ** "Special features" of targets.
419 ** quirks field of struct tcb.
420 ** actualquirks field of struct ccb.
422 **==========================================================
425 #define QUIRK_AUTOSAVE (0x01)
426 #define QUIRK_NOMSG (0x02)
427 #define QUIRK_NOSYNC (0x10)
428 #define QUIRK_NOWIDE16 (0x20)
430 /*==========================================================
432 ** Capability bits in Inquire response byte 7.
434 **==========================================================
437 #define INQ7_QUEUE (0x02)
438 #define INQ7_SYNC (0x10)
439 #define INQ7_WIDE16 (0x20)
441 /*==========================================================
445 **==========================================================
448 #define CCB_MAGIC (0xf2691ad2)
450 /*==========================================================
452 ** Declaration of structs.
454 **==========================================================
475 #define UC_SETSYNC 10
476 #define UC_SETTAGS 11
477 #define UC_SETDEBUG 12
478 #define UC_SETORDER 13
479 #define UC_SETWIDE 14
480 #define UC_SETFLAG 15
481 #define UC_SETVERBOSE 17
483 #define UF_TRACE (0x01)
484 #define UF_NODISC (0x02)
485 #define UF_NOSCAN (0x04)
487 /*========================================================================
489 ** Declaration of structs: target control block
491 **========================================================================
494 /*----------------------------------------------------------------
495 ** During reselection the ncr jumps to this point with SFBR
496 ** set to the encoded target number with bit 7 set.
497 ** if it's not this target, jump to the next.
499 ** JUMP IF (SFBR != #target#), @(next tcb)
500 **----------------------------------------------------------------
502 struct link jump_tcb
;
504 /*----------------------------------------------------------------
505 ** Load the actual values for the sxfer and the scntl3
506 ** register (sync/wide mode).
508 ** SCR_COPY (1), @(sval field of this tcb), @(sxfer register)
509 ** SCR_COPY (1), @(wval field of this tcb), @(scntl3 register)
510 **----------------------------------------------------------------
514 /*----------------------------------------------------------------
515 ** Get the IDENTIFY message and load the LUN to SFBR.
518 **----------------------------------------------------------------
520 struct link call_lun
;
522 /*----------------------------------------------------------------
523 ** Now look for the right lun.
526 ** SCR_JUMP ^ IFTRUE(MASK(i, 3)), @(first lcb mod. i)
528 ** Recent chips will prefetch the 4 JUMPS using only 1 burst.
529 ** It is kind of hashcoding.
530 **----------------------------------------------------------------
532 struct link jump_lcb
[4]; /* JUMPs for reselection */
533 struct lcb
* lp
[MAX_LUN
]; /* The lcb's of this tcb */
534 u_char inq_done
; /* Target capabilities received */
535 u_char inq_byte7
; /* Contains these capabilities */
537 /*----------------------------------------------------------------
538 ** Pointer to the ccb used for negotiation.
539 ** Prevent from starting a negotiation for all queued commands
540 ** when tagged command queuing is enabled.
541 **----------------------------------------------------------------
543 struct ccb
* nego_cp
;
545 /*----------------------------------------------------------------
547 **----------------------------------------------------------------
552 /*----------------------------------------------------------------
553 ** negotiation of wide and synch transfer and device quirks.
554 **----------------------------------------------------------------
556 #ifdef SCSI_NCR_BIG_ENDIAN
559 /*3*/ u_char minsync
;
561 /*1*/ u_char widedone
;
563 /*3*/ u_char maxoffs
;
565 /*0*/ u_char minsync
;
568 /*0*/ u_char maxoffs
;
570 /*2*/ u_char widedone
;
574 #ifdef SCSI_NCR_INTEGRITY_CHECKING
577 u_char ic_maximums_set
;
581 /* User settable limits and options. */
588 /*========================================================================
590 ** Declaration of structs: lun control block
592 **========================================================================
595 /*----------------------------------------------------------------
596 ** During reselection the ncr jumps to this point
597 ** with SFBR set to the "Identify" message.
598 ** if it's not this lun, jump to the next.
600 ** JUMP IF (SFBR != #lun#), @(next lcb of this target)
602 ** It is this lun. Load TEMP with the nexus jumps table
603 ** address and jump to RESEL_TAG (or RESEL_NOTAG).
605 ** SCR_COPY (4), p_jump_ccb, TEMP,
606 ** SCR_JUMP, <RESEL_TAG>
607 **----------------------------------------------------------------
609 struct link jump_lcb
;
610 ncrcmd load_jump_ccb
[3];
611 struct link jump_tag
;
612 ncrcmd p_jump_ccb
; /* Jump table bus address */
614 /*----------------------------------------------------------------
615 ** Jump table used by the script processor to directly jump
616 ** to the CCB corresponding to the reselected nexus.
617 ** Address is allocated on 256 bytes boundary in order to
618 ** allow 8 bit calculation of the tag jump entry for up to
620 **----------------------------------------------------------------
622 u32 jump_ccb_0
; /* Default table if no tags */
623 u32
*jump_ccb
; /* Virtual address */
625 /*----------------------------------------------------------------
626 ** CCB queue management.
627 **----------------------------------------------------------------
629 XPT_QUEHEAD free_ccbq
; /* Queue of available CCBs */
630 XPT_QUEHEAD busy_ccbq
; /* Queue of busy CCBs */
631 XPT_QUEHEAD wait_ccbq
; /* Queue of waiting for IO CCBs */
632 XPT_QUEHEAD skip_ccbq
; /* Queue of skipped CCBs */
633 u_char actccbs
; /* Number of allocated CCBs */
634 u_char busyccbs
; /* CCBs busy for this lun */
635 u_char queuedccbs
; /* CCBs queued to the controller*/
636 u_char queuedepth
; /* Queue depth for this lun */
637 u_char scdev_depth
; /* SCSI device queue depth */
638 u_char maxnxs
; /* Max possible nexuses */
640 /*----------------------------------------------------------------
641 ** Control of tagged command queuing.
642 ** Tags allocation is performed using a circular buffer.
643 ** This avoids using a loop for tag allocation.
644 **----------------------------------------------------------------
646 u_char ia_tag
; /* Allocation index */
647 u_char if_tag
; /* Freeing index */
648 u_char cb_tags
[MAX_TAGS
]; /* Circular tags buffer */
649 u_char usetags
; /* Command queuing is active */
650 u_char maxtags
; /* Max nr of tags asked by user */
651 u_char numtags
; /* Current number of tags */
652 u_char inq_byte7
; /* Store unit CmdQ capabitility */
654 /*----------------------------------------------------------------
655 ** QUEUE FULL control and ORDERED tag control.
656 **----------------------------------------------------------------
658 /*----------------------------------------------------------------
659 ** QUEUE FULL and ORDERED tag control.
660 **----------------------------------------------------------------
662 u16 num_good
; /* Nr of GOOD since QUEUE FULL */
663 tagmap_t tags_umap
; /* Used tags bitmap */
664 tagmap_t tags_smap
; /* Tags in use at 'tag_stime' */
665 u_long tags_stime
; /* Last time we set smap=umap */
666 struct ccb
* held_ccb
; /* CCB held for QUEUE FULL */
669 /*========================================================================
671 ** Declaration of structs: the launch script.
673 **========================================================================
675 ** It is part of the CCB and is called by the scripts processor to
676 ** start or restart the data structure (nexus).
677 ** This 6 DWORDs mini script makes use of prefetching.
679 **------------------------------------------------------------------------
682 /*----------------------------------------------------------------
683 ** SCR_COPY(4), @(p_phys), @(dsa register)
684 ** SCR_JUMP, @(scheduler_point)
685 **----------------------------------------------------------------
687 ncrcmd setup_dsa
[3]; /* Copy 'phys' address to dsa */
688 struct link schedule
; /* Jump to scheduler point */
689 ncrcmd p_phys
; /* 'phys' header bus address */
692 /*========================================================================
694 ** Declaration of structs: global HEADER.
696 **========================================================================
698 ** This substructure is copied from the ccb to a global address after
699 ** selection (or reselection) and copied back before disconnect.
701 ** These fields are accessible to the script processor.
703 **------------------------------------------------------------------------
707 /*----------------------------------------------------------------
708 ** Saved data pointer.
709 ** Points to the position in the script responsible for the
710 ** actual transfer transfer of data.
711 ** It's written after reception of a SAVE_DATA_POINTER message.
712 ** The goalpointer points after the last transfer command.
713 **----------------------------------------------------------------
719 /*----------------------------------------------------------------
720 ** Alternate data pointer.
721 ** They are copied back to savep/lastp/goalp by the SCRIPTS
722 ** when the direction is unknown and the device claims data out.
723 **----------------------------------------------------------------
728 /*----------------------------------------------------------------
729 ** The virtual address of the ccb containing this header.
730 **----------------------------------------------------------------
734 /*----------------------------------------------------------------
736 **----------------------------------------------------------------
738 u_char scr_st
[4]; /* script status */
739 u_char status
[4]; /* host status. must be the */
740 /* last DWORD of the header. */
744 ** The status bytes are used by the host and the script processor.
746 ** The byte corresponding to the host_status must be stored in the
747 ** last DWORD of the CCB header since it is used for command
748 ** completion (ncr_wakeup()). Doing so, we are sure that the header
749 ** has been entirely copied back to the CCB when the host_status is
750 ** seen complete by the CPU.
752 ** The last four bytes (status[4]) are copied to the scratchb register
753 ** (declared as scr0..scr3 in ncr_reg.h) just after the select/reselect,
754 ** and copied back just after disconnecting.
755 ** Inside the script the XX_REG are used.
757 ** The first four bytes (scr_st[4]) are used inside the script by
759 ** Because source and destination must have the same alignment
760 ** in a DWORD, the fields HAVE to be at the choosen offsets.
761 ** xerr_st 0 (0x34) scratcha
762 ** sync_st 1 (0x05) sxfer
763 ** wide_st 3 (0x03) scntl3
767 ** Last four bytes (script)
771 #define HS_PRT nc_scr1
773 #define SS_PRT nc_scr2
777 ** Last four bytes (host)
779 #ifdef SCSI_NCR_BIG_ENDIAN
780 #define actualquirks phys.header.status[3]
781 #define host_status phys.header.status[2]
782 #define scsi_status phys.header.status[1]
783 #define parity_status phys.header.status[0]
785 #define actualquirks phys.header.status[0]
786 #define host_status phys.header.status[1]
787 #define scsi_status phys.header.status[2]
788 #define parity_status phys.header.status[3]
792 ** First four bytes (script)
794 #define xerr_st header.scr_st[0]
795 #define sync_st header.scr_st[1]
796 #define nego_st header.scr_st[2]
797 #define wide_st header.scr_st[3]
800 ** First four bytes (host)
802 #define xerr_status phys.xerr_st
803 #define nego_status phys.nego_st
806 #define sync_status phys.sync_st
807 #define wide_status phys.wide_st
810 /*==========================================================
812 ** Declaration of structs: Data structure block
814 **==========================================================
816 ** During execution of a ccb by the script processor,
817 ** the DSA (data structure address) register points
818 ** to this substructure of the ccb.
819 ** This substructure contains the header with
820 ** the script-processor-changable data and
821 ** data blocks for the indirect move commands.
823 **----------------------------------------------------------
835 ** Table data for Script
838 struct scr_tblsel select
;
839 struct scr_tblmove smsg
;
840 struct scr_tblmove cmd
;
841 struct scr_tblmove sense
;
842 struct scr_tblmove data
[MAX_SCATTER
];
846 /*========================================================================
848 ** Declaration of structs: Command control block.
850 **========================================================================
853 /*----------------------------------------------------------------
854 ** This is the data structure which is pointed by the DSA
855 ** register when it is executed by the script processor.
856 ** It must be the first entry because it contains the header
857 ** as first entry that must be cache line aligned.
858 **----------------------------------------------------------------
862 /*----------------------------------------------------------------
863 ** Mini-script used at CCB execution start-up.
864 ** Load the DSA with the data structure address (phys) and
865 ** jump to SELECT. Jump to CANCEL if CCB is to be canceled.
866 **----------------------------------------------------------------
870 /*----------------------------------------------------------------
871 ** Mini-script used at CCB relection to restart the nexus.
872 ** Load the DSA with the data structure address (phys) and
873 ** jump to RESEL_DSA. Jump to ABORT if CCB is to be aborted.
874 **----------------------------------------------------------------
876 struct launch restart
;
878 /*----------------------------------------------------------------
879 ** If a data transfer phase is terminated too early
880 ** (after reception of a message (i.e. DISCONNECT)),
881 ** we have to prepare a mini script to transfer
882 ** the rest of the data.
883 **----------------------------------------------------------------
887 /*----------------------------------------------------------------
888 ** The general SCSI driver provides a
889 ** pointer to a control block.
890 **----------------------------------------------------------------
892 struct scsi_cmnd
*cmd
; /* SCSI command */
893 u_char cdb_buf
[16]; /* Copy of CDB */
894 u_char sense_buf
[64];
895 int data_len
; /* Total data length */
897 /*----------------------------------------------------------------
899 ** We prepare a message to be sent after selection.
900 ** We may use a second one if the command is rescheduled
901 ** due to GETCC or QFULL.
902 ** Contents are IDENTIFY and SIMPLE_TAG.
903 ** While negotiating sync or wide transfer,
904 ** a SDTR or WDTR message is appended.
905 **----------------------------------------------------------------
907 u_char scsi_smsg
[8];
908 u_char scsi_smsg2
[8];
910 /*----------------------------------------------------------------
912 **----------------------------------------------------------------
914 u_long p_ccb
; /* BUS address of this CCB */
915 u_char sensecmd
[6]; /* Sense command */
916 u_char tag
; /* Tag for this transfer */
917 /* 255 means no tag */
922 struct ccb
* link_ccb
; /* Host adapter CCB chain */
923 XPT_QUEHEAD link_ccbq
; /* Link to unit CCB queue */
924 u32 startp
; /* Initial data pointer */
925 u_long magic
; /* Free / busy CCB flag */
928 #define CCB_PHYS(cp,lbl) (cp->p_ccb + offsetof(struct ccb, lbl))
931 /*========================================================================
933 ** Declaration of structs: NCR device descriptor
935 **========================================================================
938 /*----------------------------------------------------------------
939 ** The global header.
940 ** It is accessible to both the host and the script processor.
941 ** Must be cache line size aligned (32 for x86) in order to
942 ** allow cache line bursting when it is copied to/from CCB.
943 **----------------------------------------------------------------
947 /*----------------------------------------------------------------
948 ** CCBs management queues.
949 **----------------------------------------------------------------
951 struct scsi_cmnd
*waiting_list
; /* Commands waiting for a CCB */
952 /* when lcb is not allocated. */
953 struct scsi_cmnd
*done_list
; /* Commands waiting for done() */
954 /* callback to be invoked. */
955 spinlock_t smp_lock
; /* Lock for SMP threading */
957 /*----------------------------------------------------------------
958 ** Chip and controller indentification.
959 **----------------------------------------------------------------
961 int unit
; /* Unit number */
962 char inst_name
[16]; /* ncb instance name */
964 /*----------------------------------------------------------------
965 ** Initial value of some IO register bits.
966 ** These values are assumed to have been set by BIOS, and may
967 ** be used for probing adapter implementation differences.
968 **----------------------------------------------------------------
970 u_char sv_scntl0
, sv_scntl3
, sv_dmode
, sv_dcntl
, sv_ctest0
, sv_ctest3
,
971 sv_ctest4
, sv_ctest5
, sv_gpcntl
, sv_stest2
, sv_stest4
;
973 /*----------------------------------------------------------------
974 ** Actual initial value of IO register bits used by the
975 ** driver. They are loaded at initialisation according to
976 ** features that are to be enabled.
977 **----------------------------------------------------------------
979 u_char rv_scntl0
, rv_scntl3
, rv_dmode
, rv_dcntl
, rv_ctest0
, rv_ctest3
,
980 rv_ctest4
, rv_ctest5
, rv_stest2
;
982 /*----------------------------------------------------------------
983 ** Targets management.
984 ** During reselection the ncr jumps to jump_tcb.
985 ** The SFBR register is loaded with the encoded target id.
987 ** SCR_JUMP ^ IFTRUE(MASK(i, 3)), @(next tcb mod. i)
989 ** Recent chips will prefetch the 4 JUMPS using only 1 burst.
990 ** It is kind of hashcoding.
991 **----------------------------------------------------------------
993 struct link jump_tcb
[4]; /* JUMPs for reselection */
994 struct tcb target
[MAX_TARGET
]; /* Target data */
996 /*----------------------------------------------------------------
997 ** Virtual and physical bus addresses of the chip.
998 **----------------------------------------------------------------
1000 vm_offset_t vaddr
; /* Virtual and bus address of */
1001 vm_offset_t paddr
; /* chip's IO registers. */
1002 vm_offset_t paddr2
; /* On-chip RAM bus address. */
1003 volatile /* Pointer to volatile for */
1004 struct ncr_reg
*reg
; /* memory mapped IO. */
1006 /*----------------------------------------------------------------
1007 ** SCRIPTS virtual and physical bus addresses.
1008 ** 'script' is loaded in the on-chip RAM if present.
1009 ** 'scripth' stays in main memory.
1010 **----------------------------------------------------------------
1012 struct script
*script0
; /* Copies of script and scripth */
1013 struct scripth
*scripth0
; /* relocated for this ncb. */
1014 struct scripth
*scripth
; /* Actual scripth virt. address */
1015 u_long p_script
; /* Actual script and scripth */
1016 u_long p_scripth
; /* bus addresses. */
1018 /*----------------------------------------------------------------
1019 ** General controller parameters and configuration.
1020 **----------------------------------------------------------------
1023 u_char revision_id
; /* PCI device revision id */
1024 u32 irq
; /* IRQ level */
1025 u32 features
; /* Chip features map */
1026 u_char myaddr
; /* SCSI id of the adapter */
1027 u_char maxburst
; /* log base 2 of dwords burst */
1028 u_char maxwide
; /* Maximum transfer width */
1029 u_char minsync
; /* Minimum sync period factor */
1030 u_char maxsync
; /* Maximum sync period factor */
1031 u_char maxoffs
; /* Max scsi offset */
1032 u_char multiplier
; /* Clock multiplier (1,2,4) */
1033 u_char clock_divn
; /* Number of clock divisors */
1034 u_long clock_khz
; /* SCSI clock frequency in KHz */
1036 /*----------------------------------------------------------------
1037 ** Start queue management.
1038 ** It is filled up by the host processor and accessed by the
1039 ** SCRIPTS processor in order to start SCSI commands.
1040 **----------------------------------------------------------------
1042 u16 squeueput
; /* Next free slot of the queue */
1043 u16 actccbs
; /* Number of allocated CCBs */
1044 u16 queuedccbs
; /* Number of CCBs in start queue*/
1045 u16 queuedepth
; /* Start queue depth */
1047 /*----------------------------------------------------------------
1049 **----------------------------------------------------------------
1051 struct timer_list timer
; /* Timer handler link header */
1053 u_long settle_time
; /* Resetting the SCSI BUS */
1055 /*----------------------------------------------------------------
1056 ** Debugging and profiling.
1057 **----------------------------------------------------------------
1059 struct ncr_reg regdump
; /* Register dump */
1060 u_long regtime
; /* Time it has been done */
1062 /*----------------------------------------------------------------
1063 ** Miscellaneous buffers accessed by the scripts-processor.
1064 ** They shall be DWORD aligned, because they may be read or
1065 ** written with a SCR_COPY script command.
1066 **----------------------------------------------------------------
1068 u_char msgout
[8]; /* Buffer for MESSAGE OUT */
1069 u_char msgin
[8]; /* Buffer for MESSAGE IN */
1070 u32 lastmsg
; /* Last SCSI message sent */
1071 u_char scratch
; /* Scratch for SCSI receive */
1073 /*----------------------------------------------------------------
1074 ** Miscellaneous configuration and status parameters.
1075 **----------------------------------------------------------------
1077 u_char disc
; /* Diconnection allowed */
1078 u_char scsi_mode
; /* Current SCSI BUS mode */
1079 u_char order
; /* Tag order to use */
1080 u_char verbose
; /* Verbosity for this controller*/
1081 int ncr_cache
; /* Used for cache test at init. */
1082 u_long p_ncb
; /* BUS address of this NCB */
1084 /*----------------------------------------------------------------
1085 ** Command completion handling.
1086 **----------------------------------------------------------------
1088 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
1089 struct ccb
*(ccb_done
[MAX_DONE
]);
1092 /*----------------------------------------------------------------
1093 ** Fields that should be removed or changed.
1094 **----------------------------------------------------------------
1096 struct ccb
*ccb
; /* Global CCB */
1097 struct usrcmd user
; /* Command from user */
1098 volatile u_char release_stage
; /* Synchronisation stage on release */
1100 #ifdef SCSI_NCR_INTEGRITY_CHECKING
1101 /*----------------------------------------------------------------
1102 ** Fields that are used for integrity check
1103 **----------------------------------------------------------------
1105 unsigned char check_integrity
; /* Enable midlayer integ.check on
1107 unsigned char check_integ_par
; /* Set if par or Init. Det. error
1108 * used only during integ check */
1112 #define NCB_SCRIPT_PHYS(np,lbl) (np->p_script + offsetof (struct script, lbl))
1113 #define NCB_SCRIPTH_PHYS(np,lbl) (np->p_scripth + offsetof (struct scripth,lbl))
1115 /*==========================================================
1118 ** Script for NCR-Processor.
1120 ** Use ncr_script_fill() to create the variable parts.
1121 ** Use ncr_script_copy_and_bind() to make a copy and
1122 ** bind to physical addresses.
1125 **==========================================================
1127 ** We have to know the offsets of all labels before
1128 ** we reach them (for forward jumps).
1129 ** Therefore we declare a struct here.
1130 ** If you make changes inside the script,
1131 ** DONT FORGET TO CHANGE THE LENGTHS HERE!
1133 **----------------------------------------------------------
1137 ** For HP Zalon/53c720 systems, the Zalon interface
1138 ** between CPU and 53c720 does prefetches, which causes
1139 ** problems with self modifying scripts. The problem
1140 ** is overcome by calling a dummy subroutine after each
1141 ** modification, to force a refetch of the script on
1142 ** return from the subroutine.
1145 #ifdef CONFIG_NCR53C8XX_PREFETCH
1146 #define PREFETCH_FLUSH_CNT 2
1147 #define PREFETCH_FLUSH SCR_CALL, PADDRH (wait_dma),
1149 #define PREFETCH_FLUSH_CNT 0
1150 #define PREFETCH_FLUSH
1154 ** Script fragments which are loaded into the on-chip RAM
1155 ** of 825A, 875 and 895 chips.
1159 ncrcmd startpos
[ 1];
1161 ncrcmd select2
[ 9 + PREFETCH_FLUSH_CNT
];
1162 ncrcmd loadpos
[ 4];
1163 ncrcmd send_ident
[ 9];
1164 ncrcmd prepare
[ 6];
1165 ncrcmd prepare2
[ 7];
1166 ncrcmd command
[ 6];
1167 ncrcmd dispatch
[ 32];
1169 ncrcmd no_data
[ 17];
1172 ncrcmd msg_in2
[ 16];
1173 ncrcmd msg_bad
[ 4];
1175 ncrcmd cleanup
[ 6];
1176 ncrcmd complete
[ 9];
1177 ncrcmd cleanup_ok
[ 8 + PREFETCH_FLUSH_CNT
];
1178 ncrcmd cleanup0
[ 1];
1179 #ifndef SCSI_NCR_CCB_DONE_SUPPORT
1180 ncrcmd signal
[ 12];
1183 ncrcmd done_pos
[ 1];
1184 ncrcmd done_plug
[ 2];
1185 ncrcmd done_end
[ 7];
1187 ncrcmd save_dp
[ 7];
1188 ncrcmd restore_dp
[ 5];
1189 ncrcmd disconnect
[ 17];
1190 ncrcmd msg_out
[ 9];
1191 ncrcmd msg_out_done
[ 7];
1193 ncrcmd reselect
[ 8];
1194 ncrcmd reselected
[ 8];
1195 ncrcmd resel_dsa
[ 6 + PREFETCH_FLUSH_CNT
];
1196 ncrcmd loadpos1
[ 4];
1197 ncrcmd resel_lun
[ 6];
1198 ncrcmd resel_tag
[ 6];
1199 ncrcmd jump_to_nexus
[ 4 + PREFETCH_FLUSH_CNT
];
1200 ncrcmd nexus_indirect
[ 4];
1201 ncrcmd resel_notag
[ 4];
1202 ncrcmd data_in
[MAX_SCATTERL
* 4];
1203 ncrcmd data_in2
[ 4];
1204 ncrcmd data_out
[MAX_SCATTERL
* 4];
1205 ncrcmd data_out2
[ 4];
1209 ** Script fragments which stay in main memory for all chips.
1212 ncrcmd tryloop
[MAX_START
*2];
1213 ncrcmd tryloop2
[ 2];
1214 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
1215 ncrcmd done_queue
[MAX_DONE
*5];
1216 ncrcmd done_queue2
[ 2];
1218 ncrcmd select_no_atn
[ 8];
1220 ncrcmd skip
[ 9 + PREFETCH_FLUSH_CNT
];
1222 ncrcmd par_err_data_in
[ 6];
1223 ncrcmd par_err_other
[ 4];
1224 ncrcmd msg_reject
[ 8];
1225 ncrcmd msg_ign_residue
[ 24];
1226 ncrcmd msg_extended
[ 10];
1227 ncrcmd msg_ext_2
[ 10];
1228 ncrcmd msg_wdtr
[ 14];
1229 ncrcmd send_wdtr
[ 7];
1230 ncrcmd msg_ext_3
[ 10];
1231 ncrcmd msg_sdtr
[ 14];
1232 ncrcmd send_sdtr
[ 7];
1233 ncrcmd nego_bad_phase
[ 4];
1234 ncrcmd msg_out_abort
[ 10];
1235 ncrcmd hdata_in
[MAX_SCATTERH
* 4];
1236 ncrcmd hdata_in2
[ 2];
1237 ncrcmd hdata_out
[MAX_SCATTERH
* 4];
1238 ncrcmd hdata_out2
[ 2];
1240 ncrcmd aborttag
[ 4];
1242 ncrcmd abort_resel
[ 20];
1243 ncrcmd resend_ident
[ 4];
1244 ncrcmd clratn_go_on
[ 3];
1245 ncrcmd nxtdsp_go_on
[ 1];
1246 ncrcmd sdata_in
[ 8];
1247 ncrcmd data_io
[ 18];
1248 ncrcmd bad_identify
[ 12];
1249 ncrcmd bad_i_t_l
[ 4];
1250 ncrcmd bad_i_t_l_q
[ 4];
1251 ncrcmd bad_target
[ 8];
1252 ncrcmd bad_status
[ 8];
1253 ncrcmd start_ram
[ 4 + PREFETCH_FLUSH_CNT
];
1254 ncrcmd start_ram0
[ 4];
1255 ncrcmd sto_restart
[ 5];
1256 ncrcmd wait_dma
[ 2];
1257 ncrcmd snooptest
[ 9];
1258 ncrcmd snoopend
[ 2];
1261 /*==========================================================
1264 ** Function headers.
1267 **==========================================================
1270 static void ncr_alloc_ccb (struct ncb
*np
, u_char tn
, u_char ln
);
1271 static void ncr_complete (struct ncb
*np
, struct ccb
*cp
);
1272 static void ncr_exception (struct ncb
*np
);
1273 static void ncr_free_ccb (struct ncb
*np
, struct ccb
*cp
);
1274 static void ncr_init_ccb (struct ncb
*np
, struct ccb
*cp
);
1275 static void ncr_init_tcb (struct ncb
*np
, u_char tn
);
1276 static struct lcb
* ncr_alloc_lcb (struct ncb
*np
, u_char tn
, u_char ln
);
1277 static struct lcb
* ncr_setup_lcb (struct ncb
*np
, u_char tn
, u_char ln
,
1279 static void ncr_getclock (struct ncb
*np
, int mult
);
1280 static void ncr_selectclock (struct ncb
*np
, u_char scntl3
);
1281 static struct ccb
*ncr_get_ccb (struct ncb
*np
, u_char tn
, u_char ln
);
1282 static void ncr_chip_reset (struct ncb
*np
, int delay
);
1283 static void ncr_init (struct ncb
*np
, int reset
, char * msg
, u_long code
);
1284 static int ncr_int_sbmc (struct ncb
*np
);
1285 static int ncr_int_par (struct ncb
*np
);
1286 static void ncr_int_ma (struct ncb
*np
);
1287 static void ncr_int_sir (struct ncb
*np
);
1288 static void ncr_int_sto (struct ncb
*np
);
1289 static u_long
ncr_lookup (char* id
);
1290 static void ncr_negotiate (struct ncb
* np
, struct tcb
* tp
);
1291 static int ncr_prepare_nego(struct ncb
*np
, struct ccb
*cp
, u_char
*msgptr
);
1292 #ifdef SCSI_NCR_INTEGRITY_CHECKING
1293 static int ncr_ic_nego(struct ncb
*np
, struct ccb
*cp
, struct scsi_cmnd
*cmd
, u_char
*msgptr
);
1296 static void ncr_script_copy_and_bind
1297 (struct ncb
*np
, ncrcmd
*src
, ncrcmd
*dst
, int len
);
1298 static void ncr_script_fill (struct script
* scr
, struct scripth
* scripth
);
1299 static int ncr_scatter (struct ncb
*np
, struct ccb
*cp
, struct scsi_cmnd
*cmd
);
1300 static void ncr_getsync (struct ncb
*np
, u_char sfac
, u_char
*fakp
, u_char
*scntl3p
);
1301 static void ncr_setsync (struct ncb
*np
, struct ccb
*cp
, u_char scntl3
, u_char sxfer
);
1302 static void ncr_setup_tags (struct ncb
*np
, u_char tn
, u_char ln
);
1303 static void ncr_setwide (struct ncb
*np
, struct ccb
*cp
, u_char wide
, u_char ack
);
1304 static int ncr_show_msg (u_char
* msg
);
1305 static void ncr_print_msg (struct ccb
*cp
, char *label
, u_char
*msg
);
1306 static int ncr_snooptest (struct ncb
*np
);
1307 static void ncr_timeout (struct ncb
*np
);
1308 static void ncr_wakeup (struct ncb
*np
, u_long code
);
1309 static void ncr_wakeup_done (struct ncb
*np
);
1310 static void ncr_start_next_ccb (struct ncb
*np
, struct lcb
* lp
, int maxn
);
1311 static void ncr_put_start_queue(struct ncb
*np
, struct ccb
*cp
);
1313 static void insert_into_waiting_list(struct ncb
*np
, struct scsi_cmnd
*cmd
);
1314 static struct scsi_cmnd
*retrieve_from_waiting_list(int to_remove
, struct ncb
*np
, struct scsi_cmnd
*cmd
);
1315 static void process_waiting_list(struct ncb
*np
, int sts
);
1317 #define remove_from_waiting_list(np, cmd) \
1318 retrieve_from_waiting_list(1, (np), (cmd))
1319 #define requeue_waiting_list(np) process_waiting_list((np), DID_OK)
1320 #define reset_waiting_list(np) process_waiting_list((np), DID_RESET)
1322 static inline char *ncr_name (struct ncb
*np
)
1324 return np
->inst_name
;
1328 /*==========================================================
1331 ** Scripts for NCR-Processor.
1333 ** Use ncr_script_bind for binding to physical addresses.
1336 **==========================================================
1338 ** NADDR generates a reference to a field of the controller data.
1339 ** PADDR generates a reference to another part of the script.
1340 ** RADDR generates a reference to a script processor register.
1341 ** FADDR generates a reference to a script processor register
1344 **----------------------------------------------------------
1347 #define RELOC_SOFTC 0x40000000
1348 #define RELOC_LABEL 0x50000000
1349 #define RELOC_REGISTER 0x60000000
1351 #define RELOC_KVAR 0x70000000
1353 #define RELOC_LABELH 0x80000000
1354 #define RELOC_MASK 0xf0000000
1356 #define NADDR(label) (RELOC_SOFTC | offsetof(struct ncb, label))
1357 #define PADDR(label) (RELOC_LABEL | offsetof(struct script, label))
1358 #define PADDRH(label) (RELOC_LABELH | offsetof(struct scripth, label))
1359 #define RADDR(label) (RELOC_REGISTER | REG(label))
1360 #define FADDR(label,ofs)(RELOC_REGISTER | ((REG(label))+(ofs)))
1362 #define KVAR(which) (RELOC_KVAR | (which))
1366 #define SCRIPT_KVAR_JIFFIES (0)
1367 #define SCRIPT_KVAR_FIRST SCRIPT_KVAR_JIFFIES
1368 #define SCRIPT_KVAR_LAST SCRIPT_KVAR_JIFFIES
1370 * Kernel variables referenced in the scripts.
1371 * THESE MUST ALL BE ALIGNED TO A 4-BYTE BOUNDARY.
1373 static void *script_kvars
[] __initdata
=
1374 { (void *)&jiffies
};
1377 static struct script script0 __initdata
= {
1378 /*--------------------------< START >-----------------------*/ {
1380 ** This NOP will be patched with LED ON
1381 ** SCR_REG_REG (gpreg, SCR_AND, 0xfe)
1388 SCR_FROM_REG (ctest2
),
1391 ** Then jump to a certain point in tryloop.
1392 ** Due to the lack of indirect addressing the code
1393 ** is self modifying here.
1396 }/*-------------------------< STARTPOS >--------------------*/,{
1399 }/*-------------------------< SELECT >----------------------*/,{
1401 ** DSA contains the address of a scheduled
1404 ** SCRATCHA contains the address of the script,
1405 ** which starts the next entry.
1407 ** Set Initiator mode.
1409 ** (Target mode is left as an exercise for the reader)
1414 SCR_LOAD_REG (HS_REG
, HS_SELECTING
),
1418 ** And try to select this target.
1420 SCR_SEL_TBL_ATN
^ offsetof (struct dsb
, select
),
1423 }/*-------------------------< SELECT2 >----------------------*/,{
1425 ** Now there are 4 possibilities:
1427 ** (1) The ncr loses arbitration.
1428 ** This is ok, because it will try again,
1429 ** when the bus becomes idle.
1430 ** (But beware of the timeout function!)
1432 ** (2) The ncr is reselected.
1433 ** Then the script processor takes the jump
1434 ** to the RESELECT label.
1436 ** (3) The ncr wins arbitration.
1437 ** Then it will execute SCRIPTS instruction until
1438 ** the next instruction that checks SCSI phase.
1439 ** Then will stop and wait for selection to be
1440 ** complete or selection time-out to occur.
1441 ** As a result the SCRIPTS instructions until
1442 ** LOADPOS + 2 should be executed in parallel with
1443 ** the SCSI core performing selection.
1447 ** The M_REJECT problem seems to be due to a selection
1449 ** Wait immediately for the selection to complete.
1450 ** (2.5x behaves so)
1452 SCR_JUMPR
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
1456 ** Next time use the next slot.
1462 ** The ncr doesn't have an indirect load
1463 ** or store command. So we have to
1464 ** copy part of the control block to a
1465 ** fixed place, where we can access it.
1467 ** We patch the address part of a
1468 ** COPY command with the DSA-register.
1474 ** Flush script prefetch if required
1478 ** then we do the actual copy.
1480 SCR_COPY (sizeof (struct head
)),
1482 ** continued after the next label ...
1484 }/*-------------------------< LOADPOS >---------------------*/,{
1488 ** Wait for the next phase or the selection
1489 ** to complete or time-out.
1491 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
1494 }/*-------------------------< SEND_IDENT >----------------------*/,{
1496 ** Selection complete.
1497 ** Send the IDENTIFY and SIMPLE_TAG messages
1498 ** (and the M_X_SYNC_REQ message)
1500 SCR_MOVE_TBL
^ SCR_MSG_OUT
,
1501 offsetof (struct dsb
, smsg
),
1502 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_OUT
)),
1503 PADDRH (resend_ident
),
1504 SCR_LOAD_REG (scratcha
, 0x80),
1509 }/*-------------------------< PREPARE >----------------------*/,{
1511 ** load the savep (saved pointer) into
1512 ** the TEMP register (actual pointer)
1515 NADDR (header
.savep
),
1518 ** Initialize the status registers
1521 NADDR (header
.status
),
1523 }/*-------------------------< PREPARE2 >---------------------*/,{
1525 ** Initialize the msgout buffer with a NOOP message.
1527 SCR_LOAD_REG (scratcha
, M_NOOP
),
1538 ** Anticipate the COMMAND phase.
1539 ** This is the normal case for initial selection.
1541 SCR_JUMP
^ IFFALSE (WHEN (SCR_COMMAND
)),
1544 }/*-------------------------< COMMAND >--------------------*/,{
1546 ** ... and send the command
1548 SCR_MOVE_TBL
^ SCR_COMMAND
,
1549 offsetof (struct dsb
, cmd
),
1551 ** If status is still HS_NEGOTIATE, negotiation failed.
1552 ** We check this here, since we want to do that
1555 SCR_FROM_REG (HS_REG
),
1557 SCR_INT
^ IFTRUE (DATA (HS_NEGOTIATE
)),
1560 }/*-----------------------< DISPATCH >----------------------*/,{
1562 ** MSG_IN is the only phase that shall be
1563 ** entered at least once for each (re)selection.
1564 ** So we test it first.
1566 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_IN
)),
1569 SCR_RETURN
^ IFTRUE (IF (SCR_DATA_OUT
)),
1572 ** DEL 397 - 53C875 Rev 3 - Part Number 609-0392410 - ITEM 4.
1573 ** Possible data corruption during Memory Write and Invalidate.
1574 ** This work-around resets the addressing logic prior to the
1575 ** start of the first MOVE of a DATA IN phase.
1576 ** (See Documentation/scsi/ncr53c8xx.txt for more information)
1578 SCR_JUMPR
^ IFFALSE (IF (SCR_DATA_IN
)),
1585 SCR_JUMP
^ IFTRUE (IF (SCR_STATUS
)),
1587 SCR_JUMP
^ IFTRUE (IF (SCR_COMMAND
)),
1589 SCR_JUMP
^ IFTRUE (IF (SCR_MSG_OUT
)),
1592 ** Discard one illegal phase byte, if required.
1594 SCR_LOAD_REG (scratcha
, XE_BAD_PHASE
),
1599 SCR_JUMPR
^ IFFALSE (IF (SCR_ILG_OUT
)),
1601 SCR_MOVE_ABS (1) ^ SCR_ILG_OUT
,
1603 SCR_JUMPR
^ IFFALSE (IF (SCR_ILG_IN
)),
1605 SCR_MOVE_ABS (1) ^ SCR_ILG_IN
,
1610 }/*-------------------------< CLRACK >----------------------*/,{
1612 ** Terminate possible pending message phase.
1619 }/*-------------------------< NO_DATA >--------------------*/,{
1621 ** The target wants to tranfer too much data
1622 ** or in the wrong direction.
1623 ** Remember that in extended error.
1625 SCR_LOAD_REG (scratcha
, XE_EXTRA_DATA
),
1631 ** Discard one data byte, if required.
1633 SCR_JUMPR
^ IFFALSE (WHEN (SCR_DATA_OUT
)),
1635 SCR_MOVE_ABS (1) ^ SCR_DATA_OUT
,
1637 SCR_JUMPR
^ IFFALSE (IF (SCR_DATA_IN
)),
1639 SCR_MOVE_ABS (1) ^ SCR_DATA_IN
,
1642 ** .. and repeat as required.
1649 }/*-------------------------< STATUS >--------------------*/,{
1653 SCR_MOVE_ABS (1) ^ SCR_STATUS
,
1656 ** save status to scsi_status.
1657 ** mark as complete.
1659 SCR_TO_REG (SS_REG
),
1661 SCR_LOAD_REG (HS_REG
, HS_COMPLETE
),
1665 }/*-------------------------< MSG_IN >--------------------*/,{
1667 ** Get the first byte of the message
1668 ** and save it to SCRATCHA.
1670 ** The script processor doesn't negate the
1671 ** ACK signal after this transfer.
1673 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
1675 }/*-------------------------< MSG_IN2 >--------------------*/,{
1677 ** Handle this message.
1679 SCR_JUMP
^ IFTRUE (DATA (M_COMPLETE
)),
1681 SCR_JUMP
^ IFTRUE (DATA (M_DISCONNECT
)),
1683 SCR_JUMP
^ IFTRUE (DATA (M_SAVE_DP
)),
1685 SCR_JUMP
^ IFTRUE (DATA (M_RESTORE_DP
)),
1687 SCR_JUMP
^ IFTRUE (DATA (M_EXTENDED
)),
1688 PADDRH (msg_extended
),
1689 SCR_JUMP
^ IFTRUE (DATA (M_NOOP
)),
1691 SCR_JUMP
^ IFTRUE (DATA (M_REJECT
)),
1692 PADDRH (msg_reject
),
1693 SCR_JUMP
^ IFTRUE (DATA (M_IGN_RESIDUE
)),
1694 PADDRH (msg_ign_residue
),
1696 ** Rest of the messages left as
1699 ** Unimplemented messages:
1700 ** fall through to MSG_BAD.
1702 }/*-------------------------< MSG_BAD >------------------*/,{
1704 ** unimplemented message - reject it.
1708 SCR_LOAD_REG (scratcha
, M_REJECT
),
1710 }/*-------------------------< SETMSG >----------------------*/,{
1718 }/*-------------------------< CLEANUP >-------------------*/,{
1720 ** dsa: Pointer to ccb
1721 ** or xxxxxxFF (no ccb)
1723 ** HS_REG: Host-Status (<>0!)
1727 SCR_JUMP
^ IFTRUE (DATA (0xff)),
1731 ** complete the cleanup.
1736 }/*-------------------------< COMPLETE >-----------------*/,{
1738 ** Complete message.
1740 ** Copy TEMP register to LASTP in header.
1744 NADDR (header
.lastp
),
1746 ** When we terminate the cycle by clearing ACK,
1747 ** the target may disconnect immediately.
1749 ** We don't want to be told of an
1750 ** "unexpected disconnect",
1751 ** so we disable this feature.
1753 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
1756 ** Terminate cycle ...
1758 SCR_CLR (SCR_ACK
|SCR_ATN
),
1761 ** ... and wait for the disconnect.
1765 }/*-------------------------< CLEANUP_OK >----------------*/,{
1767 ** Save host status to header.
1771 NADDR (header
.status
),
1773 ** and copy back the header to the ccb.
1779 ** Flush script prefetch if required
1782 SCR_COPY (sizeof (struct head
)),
1784 }/*-------------------------< CLEANUP0 >--------------------*/,{
1786 }/*-------------------------< SIGNAL >----------------------*/,{
1788 ** if job not completed ...
1790 SCR_FROM_REG (HS_REG
),
1793 ** ... start the next command.
1795 SCR_JUMP
^ IFTRUE (MASK (0, (HS_DONEMASK
|HS_SKIPMASK
))),
1798 ** If command resulted in not GOOD status,
1799 ** call the C code if needed.
1801 SCR_FROM_REG (SS_REG
),
1803 SCR_CALL
^ IFFALSE (DATA (S_GOOD
)),
1804 PADDRH (bad_status
),
1806 #ifndef SCSI_NCR_CCB_DONE_SUPPORT
1809 ** ... signal completion to the host
1814 ** Auf zu neuen Schandtaten!
1819 #else /* defined SCSI_NCR_CCB_DONE_SUPPORT */
1822 ** ... signal completion to the host
1825 }/*------------------------< DONE_POS >---------------------*/,{
1826 PADDRH (done_queue
),
1827 }/*------------------------< DONE_PLUG >--------------------*/,{
1830 }/*------------------------< DONE_END >---------------------*/,{
1839 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
1841 }/*-------------------------< SAVE_DP >------------------*/,{
1844 ** Copy TEMP register to SAVEP in header.
1848 NADDR (header
.savep
),
1853 }/*-------------------------< RESTORE_DP >---------------*/,{
1855 ** RESTORE_DP message:
1856 ** Copy SAVEP in header to TEMP register.
1859 NADDR (header
.savep
),
1864 }/*-------------------------< DISCONNECT >---------------*/,{
1866 ** DISCONNECTing ...
1868 ** disable the "unexpected disconnect" feature,
1869 ** and remove the ACK signal.
1871 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
1873 SCR_CLR (SCR_ACK
|SCR_ATN
),
1876 ** Wait for the disconnect.
1881 ** Status is: DISCONNECTED.
1883 SCR_LOAD_REG (HS_REG
, HS_DISCONNECT
),
1886 ** If QUIRK_AUTOSAVE is set,
1887 ** do an "save pointer" operation.
1889 SCR_FROM_REG (QU_REG
),
1891 SCR_JUMP
^ IFFALSE (MASK (QUIRK_AUTOSAVE
, QUIRK_AUTOSAVE
)),
1894 ** like SAVE_DP message:
1895 ** Copy TEMP register to SAVEP in header.
1899 NADDR (header
.savep
),
1903 }/*-------------------------< MSG_OUT >-------------------*/,{
1905 ** The target requests a message.
1907 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT
,
1913 ** If it was no ABORT message ...
1915 SCR_JUMP
^ IFTRUE (DATA (M_ABORT
)),
1916 PADDRH (msg_out_abort
),
1918 ** ... wait for the next phase
1919 ** if it's a message out, send it again, ...
1921 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_OUT
)),
1923 }/*-------------------------< MSG_OUT_DONE >--------------*/,{
1925 ** ... else clear the message ...
1927 SCR_LOAD_REG (scratcha
, M_NOOP
),
1933 ** ... and process the next phase
1937 }/*-------------------------< IDLE >------------------------*/,{
1940 ** Wait for reselect.
1941 ** This NOP will be patched with LED OFF
1942 ** SCR_REG_REG (gpreg, SCR_OR, 0x01)
1946 }/*-------------------------< RESELECT >--------------------*/,{
1948 ** make the DSA invalid.
1950 SCR_LOAD_REG (dsa
, 0xff),
1954 SCR_LOAD_REG (HS_REG
, HS_IN_RESELECT
),
1957 ** Sleep waiting for a reselection.
1958 ** If SIGP is set, special treatment.
1960 ** Zu allem bereit ..
1964 }/*-------------------------< RESELECTED >------------------*/,{
1966 ** This NOP will be patched with LED ON
1967 ** SCR_REG_REG (gpreg, SCR_AND, 0xfe)
1972 ** ... zu nichts zu gebrauchen ?
1974 ** load the target id into the SFBR
1975 ** and jump to the control block.
1977 ** Look at the declarations of
1982 ** to understand what's going on.
1984 SCR_REG_SFBR (ssid
, SCR_AND
, 0x8F),
1991 }/*-------------------------< RESEL_DSA >-------------------*/,{
1993 ** Ack the IDENTIFY or TAG previously received.
1998 ** The ncr doesn't have an indirect load
1999 ** or store command. So we have to
2000 ** copy part of the control block to a
2001 ** fixed place, where we can access it.
2003 ** We patch the address part of a
2004 ** COPY command with the DSA-register.
2010 ** Flush script prefetch if required
2014 ** then we do the actual copy.
2016 SCR_COPY (sizeof (struct head
)),
2018 ** continued after the next label ...
2021 }/*-------------------------< LOADPOS1 >-------------------*/,{
2025 ** The DSA contains the data structure address.
2030 }/*-------------------------< RESEL_LUN >-------------------*/,{
2032 ** come back to this point
2033 ** to get an IDENTIFY message
2034 ** Wait for a msg_in phase.
2036 SCR_INT
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2037 SIR_RESEL_NO_MSG_IN
,
2040 ** Read the data directly from the BUS DATA lines.
2041 ** This helps to support very old SCSI devices that
2042 ** may reselect without sending an IDENTIFY.
2044 SCR_FROM_REG (sbdl
),
2047 ** It should be an Identify message.
2051 }/*-------------------------< RESEL_TAG >-------------------*/,{
2053 ** Read IDENTIFY + SIMPLE + TAG using a single MOVE.
2054 ** Agressive optimization, is'nt it?
2055 ** No need to test the SIMPLE TAG message, since the
2056 ** driver only supports conformant devices for tags. ;-)
2058 SCR_MOVE_ABS (3) ^ SCR_MSG_IN
,
2061 ** Read the TAG from the SIDL.
2062 ** Still an aggressive optimization. ;-)
2063 ** Compute the CCB indirect jump address which
2064 ** is (#TAG*2 & 0xfc) due to tag numbering using
2065 ** 1,3,5..MAXTAGS*2+1 actual values.
2067 SCR_REG_SFBR (sidl
, SCR_SHL
, 0),
2069 SCR_SFBR_REG (temp
, SCR_AND
, 0xfc),
2071 }/*-------------------------< JUMP_TO_NEXUS >-------------------*/,{
2074 PADDR (nexus_indirect
),
2076 ** Flush script prefetch if required
2080 }/*-------------------------< NEXUS_INDIRECT >-------------------*/,{
2085 }/*-------------------------< RESEL_NOTAG >-------------------*/,{
2088 ** Read an throw away the IDENTIFY.
2090 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2093 PADDR (jump_to_nexus
),
2094 }/*-------------------------< DATA_IN >--------------------*/,{
2096 ** Because the size depends on the
2097 ** #define MAX_SCATTERL parameter,
2098 ** it is filled in at runtime.
2100 ** ##===========< i=0; i<MAX_SCATTERL >=========
2101 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN)),
2102 ** || PADDR (dispatch),
2103 ** || SCR_MOVE_TBL ^ SCR_DATA_IN,
2104 ** || offsetof (struct dsb, data[ i]),
2105 ** ##==========================================
2107 **---------------------------------------------------------
2110 }/*-------------------------< DATA_IN2 >-------------------*/,{
2115 }/*-------------------------< DATA_OUT >--------------------*/,{
2117 ** Because the size depends on the
2118 ** #define MAX_SCATTERL parameter,
2119 ** it is filled in at runtime.
2121 ** ##===========< i=0; i<MAX_SCATTERL >=========
2122 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT)),
2123 ** || PADDR (dispatch),
2124 ** || SCR_MOVE_TBL ^ SCR_DATA_OUT,
2125 ** || offsetof (struct dsb, data[ i]),
2126 ** ##==========================================
2128 **---------------------------------------------------------
2131 }/*-------------------------< DATA_OUT2 >-------------------*/,{
2136 }/*--------------------------------------------------------*/
2139 static struct scripth scripth0 __initdata
= {
2140 /*-------------------------< TRYLOOP >---------------------*/{
2142 ** Start the next entry.
2143 ** Called addresses point to the launch script in the CCB.
2144 ** They are patched by the main processor.
2146 ** Because the size depends on the
2147 ** #define MAX_START parameter, it is filled
2150 **-----------------------------------------------------------
2152 ** ##===========< I=0; i<MAX_START >===========
2155 ** ##==========================================
2157 **-----------------------------------------------------------
2160 }/*------------------------< TRYLOOP2 >---------------------*/,{
2164 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
2166 }/*------------------------< DONE_QUEUE >-------------------*/,{
2168 ** Copy the CCB address to the next done entry.
2169 ** Because the size depends on the
2170 ** #define MAX_DONE parameter, it is filled
2173 **-----------------------------------------------------------
2175 ** ##===========< I=0; i<MAX_DONE >===========
2176 ** || SCR_COPY (sizeof(struct ccb *),
2177 ** || NADDR (header.cp),
2178 ** || NADDR (ccb_done[i]),
2180 ** || PADDR (done_end),
2181 ** ##==========================================
2183 **-----------------------------------------------------------
2186 }/*------------------------< DONE_QUEUE2 >------------------*/,{
2188 PADDRH (done_queue
),
2190 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
2191 }/*------------------------< SELECT_NO_ATN >-----------------*/,{
2193 ** Set Initiator mode.
2194 ** And try to select this target without ATN.
2199 SCR_LOAD_REG (HS_REG
, HS_SELECTING
),
2201 SCR_SEL_TBL
^ offsetof (struct dsb
, select
),
2206 }/*-------------------------< CANCEL >------------------------*/,{
2208 SCR_LOAD_REG (scratcha
, HS_ABORTED
),
2212 }/*-------------------------< SKIP >------------------------*/,{
2213 SCR_LOAD_REG (scratcha
, 0),
2216 ** This entry has been canceled.
2217 ** Next time use the next slot.
2223 ** The ncr doesn't have an indirect load
2224 ** or store command. So we have to
2225 ** copy part of the control block to a
2226 ** fixed place, where we can access it.
2228 ** We patch the address part of a
2229 ** COPY command with the DSA-register.
2235 ** Flush script prefetch if required
2239 ** then we do the actual copy.
2241 SCR_COPY (sizeof (struct head
)),
2243 ** continued after the next label ...
2245 }/*-------------------------< SKIP2 >---------------------*/,{
2249 ** Initialize the status registers
2252 NADDR (header
.status
),
2255 ** Force host status.
2257 SCR_FROM_REG (scratcha
),
2259 SCR_JUMPR
^ IFFALSE (MASK (0, HS_DONEMASK
)),
2261 SCR_REG_REG (HS_REG
, SCR_OR
, HS_SKIPMASK
),
2265 SCR_TO_REG (HS_REG
),
2267 SCR_LOAD_REG (SS_REG
, S_GOOD
),
2272 },/*-------------------------< PAR_ERR_DATA_IN >---------------*/{
2274 ** Ignore all data in byte, until next phase
2276 SCR_JUMP
^ IFFALSE (WHEN (SCR_DATA_IN
)),
2277 PADDRH (par_err_other
),
2278 SCR_MOVE_ABS (1) ^ SCR_DATA_IN
,
2282 },/*-------------------------< PAR_ERR_OTHER >------------------*/{
2286 SCR_REG_REG (PS_REG
, SCR_ADD
, 0x01),
2289 ** jump to dispatcher.
2293 }/*-------------------------< MSG_REJECT >---------------*/,{
2295 ** If a negotiation was in progress,
2296 ** negotiation failed.
2297 ** Otherwise, let the C code print
2300 SCR_FROM_REG (HS_REG
),
2302 SCR_INT
^ IFFALSE (DATA (HS_NEGOTIATE
)),
2303 SIR_REJECT_RECEIVED
,
2304 SCR_INT
^ IFTRUE (DATA (HS_NEGOTIATE
)),
2309 }/*-------------------------< MSG_IGN_RESIDUE >----------*/,{
2315 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2318 ** get residue size.
2320 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2323 ** Size is 0 .. ignore message.
2325 SCR_JUMP
^ IFTRUE (DATA (0)),
2328 ** Size is not 1 .. have to interrupt.
2330 SCR_JUMPR
^ IFFALSE (DATA (1)),
2333 ** Check for residue byte in swide register
2335 SCR_FROM_REG (scntl2
),
2337 SCR_JUMPR
^ IFFALSE (MASK (WSR
, WSR
)),
2340 ** There IS data in the swide register.
2343 SCR_REG_REG (scntl2
, SCR_OR
, WSR
),
2348 ** Load again the size to the sfbr register.
2350 SCR_FROM_REG (scratcha
),
2357 }/*-------------------------< MSG_EXTENDED >-------------*/,{
2363 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2368 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2372 SCR_JUMP
^ IFTRUE (DATA (3)),
2374 SCR_JUMP
^ IFFALSE (DATA (2)),
2376 }/*-------------------------< MSG_EXT_2 >----------------*/,{
2379 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2382 ** get extended message code.
2384 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2386 SCR_JUMP
^ IFTRUE (DATA (M_X_WIDE_REQ
)),
2389 ** unknown extended message
2393 }/*-------------------------< MSG_WDTR >-----------------*/,{
2396 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2399 ** get data bus width
2401 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2404 ** let the host do the real work.
2409 ** let the target fetch our answer.
2415 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
2416 PADDRH (nego_bad_phase
),
2418 }/*-------------------------< SEND_WDTR >----------------*/,{
2420 ** Send the M_X_WIDE_REQ
2422 SCR_MOVE_ABS (4) ^ SCR_MSG_OUT
,
2428 PADDR (msg_out_done
),
2430 }/*-------------------------< MSG_EXT_3 >----------------*/,{
2433 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2436 ** get extended message code.
2438 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2440 SCR_JUMP
^ IFTRUE (DATA (M_X_SYNC_REQ
)),
2443 ** unknown extended message
2448 }/*-------------------------< MSG_SDTR >-----------------*/,{
2451 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2454 ** get period and offset
2456 SCR_MOVE_ABS (2) ^ SCR_MSG_IN
,
2459 ** let the host do the real work.
2464 ** let the target fetch our answer.
2470 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
2471 PADDRH (nego_bad_phase
),
2473 }/*-------------------------< SEND_SDTR >-------------*/,{
2475 ** Send the M_X_SYNC_REQ
2477 SCR_MOVE_ABS (5) ^ SCR_MSG_OUT
,
2483 PADDR (msg_out_done
),
2485 }/*-------------------------< NEGO_BAD_PHASE >------------*/,{
2491 }/*-------------------------< MSG_OUT_ABORT >-------------*/,{
2493 ** After ABORT message,
2495 ** expect an immediate disconnect, ...
2497 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
2499 SCR_CLR (SCR_ACK
|SCR_ATN
),
2504 ** ... and set the status to "ABORTED"
2506 SCR_LOAD_REG (HS_REG
, HS_ABORTED
),
2511 }/*-------------------------< HDATA_IN >-------------------*/,{
2513 ** Because the size depends on the
2514 ** #define MAX_SCATTERH parameter,
2515 ** it is filled in at runtime.
2517 ** ##==< i=MAX_SCATTERL; i<MAX_SCATTERL+MAX_SCATTERH >==
2518 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN)),
2519 ** || PADDR (dispatch),
2520 ** || SCR_MOVE_TBL ^ SCR_DATA_IN,
2521 ** || offsetof (struct dsb, data[ i]),
2522 ** ##===================================================
2524 **---------------------------------------------------------
2527 }/*-------------------------< HDATA_IN2 >------------------*/,{
2531 }/*-------------------------< HDATA_OUT >-------------------*/,{
2533 ** Because the size depends on the
2534 ** #define MAX_SCATTERH parameter,
2535 ** it is filled in at runtime.
2537 ** ##==< i=MAX_SCATTERL; i<MAX_SCATTERL+MAX_SCATTERH >==
2538 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT)),
2539 ** || PADDR (dispatch),
2540 ** || SCR_MOVE_TBL ^ SCR_DATA_OUT,
2541 ** || offsetof (struct dsb, data[ i]),
2542 ** ##===================================================
2544 **---------------------------------------------------------
2547 }/*-------------------------< HDATA_OUT2 >------------------*/,{
2551 }/*-------------------------< RESET >----------------------*/,{
2553 ** Send a M_RESET message if bad IDENTIFY
2554 ** received on reselection.
2556 SCR_LOAD_REG (scratcha
, M_ABORT_TAG
),
2559 PADDRH (abort_resel
),
2560 }/*-------------------------< ABORTTAG >-------------------*/,{
2562 ** Abort a wrong tag received on reselection.
2564 SCR_LOAD_REG (scratcha
, M_ABORT_TAG
),
2567 PADDRH (abort_resel
),
2568 }/*-------------------------< ABORT >----------------------*/,{
2570 ** Abort a reselection when no active CCB.
2572 SCR_LOAD_REG (scratcha
, M_ABORT
),
2574 }/*-------------------------< ABORT_RESEL >----------------*/,{
2584 ** we expect an immediate disconnect
2586 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
2588 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT
,
2593 SCR_CLR (SCR_ACK
|SCR_ATN
),
2599 }/*-------------------------< RESEND_IDENT >-------------------*/,{
2601 ** The target stays in MSG OUT phase after having acked
2602 ** Identify [+ Tag [+ Extended message ]]. Targets shall
2603 ** behave this way on parity error.
2604 ** We must send it again all the messages.
2606 SCR_SET (SCR_ATN
), /* Shall be asserted 2 deskew delays before the */
2607 0, /* 1rst ACK = 90 ns. Hope the NCR is'nt too fast */
2610 }/*-------------------------< CLRATN_GO_ON >-------------------*/,{
2614 }/*-------------------------< NXTDSP_GO_ON >-------------------*/,{
2616 }/*-------------------------< SDATA_IN >-------------------*/,{
2617 SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_IN
)),
2619 SCR_MOVE_TBL
^ SCR_DATA_IN
,
2620 offsetof (struct dsb
, sense
),
2625 }/*-------------------------< DATA_IO >--------------------*/,{
2627 ** We jump here if the data direction was unknown at the
2628 ** time we had to queue the command to the scripts processor.
2629 ** Pointers had been set as follow in this situation:
2630 ** savep --> DATA_IO
2631 ** lastp --> start pointer when DATA_IN
2632 ** goalp --> goal pointer when DATA_IN
2633 ** wlastp --> start pointer when DATA_OUT
2634 ** wgoalp --> goal pointer when DATA_OUT
2635 ** This script sets savep/lastp/goalp according to the
2636 ** direction chosen by the target.
2638 SCR_JUMPR
^ IFTRUE (WHEN (SCR_DATA_OUT
)),
2641 ** Direction is DATA IN.
2642 ** Warning: we jump here, even when phase is DATA OUT.
2645 NADDR (header
.lastp
),
2646 NADDR (header
.savep
),
2649 ** Jump to the SCRIPTS according to actual direction.
2652 NADDR (header
.savep
),
2657 ** Direction is DATA OUT.
2660 NADDR (header
.wlastp
),
2661 NADDR (header
.lastp
),
2663 NADDR (header
.wgoalp
),
2664 NADDR (header
.goalp
),
2667 }/*-------------------------< BAD_IDENTIFY >---------------*/,{
2669 ** If message phase but not an IDENTIFY,
2670 ** get some help from the C code.
2671 ** Old SCSI device may behave so.
2673 SCR_JUMPR
^ IFTRUE (MASK (0x80, 0x80)),
2676 SIR_RESEL_NO_IDENTIFY
,
2680 ** Message is an IDENTIFY, but lun is unknown.
2681 ** Read the message, since we got it directly
2682 ** from the SCSI BUS data lines.
2683 ** Signal problem to C code for logging the event.
2684 ** Send a M_ABORT to clear all pending tasks.
2688 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2692 }/*-------------------------< BAD_I_T_L >------------------*/,{
2694 ** We donnot have a task for that I_T_L.
2695 ** Signal problem to C code for logging the event.
2696 ** Send a M_ABORT message.
2699 SIR_RESEL_BAD_I_T_L
,
2702 }/*-------------------------< BAD_I_T_L_Q >----------------*/,{
2704 ** We donnot have a task that matches the tag.
2705 ** Signal problem to C code for logging the event.
2706 ** Send a M_ABORTTAG message.
2709 SIR_RESEL_BAD_I_T_L_Q
,
2712 }/*-------------------------< BAD_TARGET >-----------------*/,{
2714 ** We donnot know the target that reselected us.
2715 ** Grab the first message if any (IDENTIFY).
2716 ** Signal problem to C code for logging the event.
2720 SIR_RESEL_BAD_TARGET
,
2721 SCR_JUMPR
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2723 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2727 }/*-------------------------< BAD_STATUS >-----------------*/,{
2729 ** If command resulted in either QUEUE FULL,
2730 ** CHECK CONDITION or COMMAND TERMINATED,
2733 SCR_INT
^ IFTRUE (DATA (S_QUEUE_FULL
)),
2735 SCR_INT
^ IFTRUE (DATA (S_CHECK_COND
)),
2737 SCR_INT
^ IFTRUE (DATA (S_TERMINATED
)),
2741 }/*-------------------------< START_RAM >-------------------*/,{
2743 ** Load the script into on-chip RAM,
2744 ** and jump to start point.
2748 PADDRH (start_ram0
),
2750 ** Flush script prefetch if required
2753 SCR_COPY (sizeof (struct script
)),
2754 }/*-------------------------< START_RAM0 >--------------------*/,{
2759 }/*-------------------------< STO_RESTART >-------------------*/,{
2762 ** Repair start queue (e.g. next time use the next slot)
2763 ** and jump to start point.
2770 }/*-------------------------< WAIT_DMA >-------------------*/,{
2772 ** For HP Zalon/53c720 systems, the Zalon interface
2773 ** between CPU and 53c720 does prefetches, which causes
2774 ** problems with self modifying scripts. The problem
2775 ** is overcome by calling a dummy subroutine after each
2776 ** modification, to force a refetch of the script on
2777 ** return from the subroutine.
2781 }/*-------------------------< SNOOPTEST >-------------------*/,{
2783 ** Read the variable.
2789 ** Write the variable.
2795 ** Read back the variable.
2800 }/*-------------------------< SNOOPEND >-------------------*/,{
2806 }/*--------------------------------------------------------*/
2809 /*==========================================================
2812 ** Fill in #define dependent parts of the script
2815 **==========================================================
2818 void __init
ncr_script_fill (struct script
* scr
, struct scripth
* scrh
)
2824 for (i
=0; i
<MAX_START
; i
++) {
2829 assert ((u_long
)p
== (u_long
)&scrh
->tryloop
+ sizeof (scrh
->tryloop
));
2831 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
2833 p
= scrh
->done_queue
;
2834 for (i
= 0; i
<MAX_DONE
; i
++) {
2835 *p
++ =SCR_COPY (sizeof(struct ccb
*));
2836 *p
++ =NADDR (header
.cp
);
2837 *p
++ =NADDR (ccb_done
[i
]);
2839 *p
++ =PADDR (done_end
);
2842 assert ((u_long
)p
==(u_long
)&scrh
->done_queue
+sizeof(scrh
->done_queue
));
2844 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
2847 for (i
=0; i
<MAX_SCATTERH
; i
++) {
2848 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_IN
));
2849 *p
++ =PADDR (dispatch
);
2850 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_IN
;
2851 *p
++ =offsetof (struct dsb
, data
[i
]);
2853 assert ((u_long
)p
== (u_long
)&scrh
->hdata_in
+ sizeof (scrh
->hdata_in
));
2856 for (i
=MAX_SCATTERH
; i
<MAX_SCATTERH
+MAX_SCATTERL
; i
++) {
2857 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_IN
));
2858 *p
++ =PADDR (dispatch
);
2859 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_IN
;
2860 *p
++ =offsetof (struct dsb
, data
[i
]);
2862 assert ((u_long
)p
== (u_long
)&scr
->data_in
+ sizeof (scr
->data_in
));
2864 p
= scrh
->hdata_out
;
2865 for (i
=0; i
<MAX_SCATTERH
; i
++) {
2866 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_OUT
));
2867 *p
++ =PADDR (dispatch
);
2868 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_OUT
;
2869 *p
++ =offsetof (struct dsb
, data
[i
]);
2871 assert ((u_long
)p
==(u_long
)&scrh
->hdata_out
+ sizeof (scrh
->hdata_out
));
2874 for (i
=MAX_SCATTERH
; i
<MAX_SCATTERH
+MAX_SCATTERL
; i
++) {
2875 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_OUT
));
2876 *p
++ =PADDR (dispatch
);
2877 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_OUT
;
2878 *p
++ =offsetof (struct dsb
, data
[i
]);
2881 assert ((u_long
)p
== (u_long
)&scr
->data_out
+ sizeof (scr
->data_out
));
2884 /*==========================================================
2887 ** Copy and rebind a script.
2890 **==========================================================
2894 ncr_script_copy_and_bind (struct ncb
*np
, ncrcmd
*src
, ncrcmd
*dst
, int len
)
2896 ncrcmd opcode
, new, old
, tmp1
, tmp2
;
2897 ncrcmd
*start
, *end
;
2907 *dst
++ = cpu_to_scr(opcode
);
2910 ** If we forget to change the length
2911 ** in struct script, a field will be
2912 ** padded with 0. This is an illegal
2917 printk (KERN_ERR
"%s: ERROR0 IN SCRIPT at %d.\n",
2918 ncr_name(np
), (int) (src
-start
-1));
2922 if (DEBUG_FLAGS
& DEBUG_SCRIPT
)
2923 printk (KERN_DEBUG
"%p: <%x>\n",
2924 (src
-1), (unsigned)opcode
);
2927 ** We don't have to decode ALL commands
2929 switch (opcode
>> 28) {
2933 ** COPY has TWO arguments.
2938 if ((tmp1
& RELOC_MASK
) == RELOC_KVAR
)
2943 if ((tmp2
& RELOC_MASK
) == RELOC_KVAR
)
2946 if ((tmp1
^ tmp2
) & 3) {
2947 printk (KERN_ERR
"%s: ERROR1 IN SCRIPT at %d.\n",
2948 ncr_name(np
), (int) (src
-start
-1));
2952 ** If PREFETCH feature not enabled, remove
2953 ** the NO FLUSH bit if present.
2955 if ((opcode
& SCR_NO_FLUSH
) && !(np
->features
& FE_PFEN
)) {
2956 dst
[-1] = cpu_to_scr(opcode
& ~SCR_NO_FLUSH
);
2963 ** MOVE (absolute address)
2971 ** don't relocate if relative :-)
2973 if (opcode
& 0x00800000)
2995 switch (old
& RELOC_MASK
) {
2996 case RELOC_REGISTER
:
2997 new = (old
& ~RELOC_MASK
) + np
->paddr
;
3000 new = (old
& ~RELOC_MASK
) + np
->p_script
;
3003 new = (old
& ~RELOC_MASK
) + np
->p_scripth
;
3006 new = (old
& ~RELOC_MASK
) + np
->p_ncb
;
3010 if (((old
& ~RELOC_MASK
) <
3011 SCRIPT_KVAR_FIRST
) ||
3012 ((old
& ~RELOC_MASK
) >
3014 panic("ncr KVAR out of range");
3015 new = vtophys(script_kvars
[old
&
3020 /* Don't relocate a 0 address. */
3027 panic("ncr_script_copy_and_bind: weird relocation %x\n", old
);
3031 *dst
++ = cpu_to_scr(new);
3034 *dst
++ = cpu_to_scr(*src
++);
3039 /*==========================================================
3042 ** Auto configuration: attach and init a host adapter.
3045 **==========================================================
3049 ** Linux host data structure
3051 ** The script area is allocated in the host data structure
3052 ** because kmalloc() returns NULL during scsi initialisations
3061 ** Print something which allows to retrieve the controller type, unit,
3062 ** target, lun concerned by a kernel message.
3065 static void PRINT_TARGET(struct ncb
*np
, int target
)
3067 printk(KERN_INFO
"%s-<%d,*>: ", ncr_name(np
), target
);
3070 static void PRINT_LUN(struct ncb
*np
, int target
, int lun
)
3072 printk(KERN_INFO
"%s-<%d,%d>: ", ncr_name(np
), target
, lun
);
3075 static void PRINT_ADDR(struct scsi_cmnd
*cmd
)
3077 struct host_data
*host_data
= (struct host_data
*) cmd
->device
->host
->hostdata
;
3078 PRINT_LUN(host_data
->ncb
, cmd
->device
->id
, cmd
->device
->lun
);
3081 /*==========================================================
3083 ** NCR chip clock divisor table.
3084 ** Divisors are multiplied by 10,000,000 in order to make
3085 ** calculations more simple.
3087 **==========================================================
3091 static u_long div_10M
[] =
3092 {2*_5M
, 3*_5M
, 4*_5M
, 6*_5M
, 8*_5M
, 12*_5M
, 16*_5M
};
3095 /*===============================================================
3097 ** Prepare io register values used by ncr_init() according
3098 ** to selected and supported features.
3100 ** NCR chips allow burst lengths of 2, 4, 8, 16, 32, 64, 128
3101 ** transfers. 32,64,128 are only supported by 875 and 895 chips.
3102 ** We use log base 2 (burst length) as internal code, with
3103 ** value 0 meaning "burst disabled".
3105 **===============================================================
3109 * Burst length from burst code.
3111 #define burst_length(bc) (!(bc))? 0 : 1 << (bc)
3114 * Burst code from io register bits. Burst enable is ctest0 for c720
3116 #define burst_code(dmode, ctest0) \
3117 (ctest0) & 0x80 ? 0 : (((dmode) & 0xc0) >> 6) + 1
3120 * Set initial io register bits from burst code.
3122 static inline void ncr_init_burst(struct ncb
*np
, u_char bc
)
3124 u_char
*be
= &np
->rv_ctest0
;
3126 np
->rv_dmode
&= ~(0x3 << 6);
3127 np
->rv_ctest5
&= ~0x4;
3133 np
->rv_dmode
|= ((bc
& 0x3) << 6);
3134 np
->rv_ctest5
|= (bc
& 0x4);
3138 static void __init
ncr_prepare_setting(struct ncb
*np
)
3145 ** Save assumed BIOS setting
3148 np
->sv_scntl0
= INB(nc_scntl0
) & 0x0a;
3149 np
->sv_scntl3
= INB(nc_scntl3
) & 0x07;
3150 np
->sv_dmode
= INB(nc_dmode
) & 0xce;
3151 np
->sv_dcntl
= INB(nc_dcntl
) & 0xa8;
3152 np
->sv_ctest0
= INB(nc_ctest0
) & 0x84;
3153 np
->sv_ctest3
= INB(nc_ctest3
) & 0x01;
3154 np
->sv_ctest4
= INB(nc_ctest4
) & 0x80;
3155 np
->sv_ctest5
= INB(nc_ctest5
) & 0x24;
3156 np
->sv_gpcntl
= INB(nc_gpcntl
);
3157 np
->sv_stest2
= INB(nc_stest2
) & 0x20;
3158 np
->sv_stest4
= INB(nc_stest4
);
3164 np
->maxwide
= (np
->features
& FE_WIDE
)? 1 : 0;
3167 * Guess the frequency of the chip's clock.
3169 if (np
->features
& FE_ULTRA
)
3170 np
->clock_khz
= 80000;
3172 np
->clock_khz
= 40000;
3175 * Get the clock multiplier factor.
3177 if (np
->features
& FE_QUAD
)
3179 else if (np
->features
& FE_DBLR
)
3185 * Measure SCSI clock frequency for chips
3186 * it may vary from assumed one.
3188 if (np
->features
& FE_VARCLK
)
3189 ncr_getclock(np
, np
->multiplier
);
3192 * Divisor to be used for async (timer pre-scaler).
3194 i
= np
->clock_divn
- 1;
3196 if (10ul * SCSI_NCR_MIN_ASYNC
* np
->clock_khz
> div_10M
[i
]) {
3201 np
->rv_scntl3
= i
+1;
3204 * Minimum synchronous period factor supported by the chip.
3205 * Btw, 'period' is in tenths of nanoseconds.
3208 period
= (4 * div_10M
[0] + np
->clock_khz
- 1) / np
->clock_khz
;
3209 if (period
<= 250) np
->minsync
= 10;
3210 else if (period
<= 303) np
->minsync
= 11;
3211 else if (period
<= 500) np
->minsync
= 12;
3212 else np
->minsync
= (period
+ 40 - 1) / 40;
3215 * Check against chip SCSI standard support (SCSI-2,ULTRA,ULTRA2).
3218 if (np
->minsync
< 25 && !(np
->features
& FE_ULTRA
))
3222 * Maximum synchronous period factor supported by the chip.
3225 period
= (11 * div_10M
[np
->clock_divn
- 1]) / (4 * np
->clock_khz
);
3226 np
->maxsync
= period
> 2540 ? 254 : period
/ 10;
3229 ** Prepare initial value of other IO registers
3231 #if defined SCSI_NCR_TRUST_BIOS_SETTING
3232 np
->rv_scntl0
= np
->sv_scntl0
;
3233 np
->rv_dmode
= np
->sv_dmode
;
3234 np
->rv_dcntl
= np
->sv_dcntl
;
3235 np
->rv_ctest0
= np
->sv_ctest0
;
3236 np
->rv_ctest3
= np
->sv_ctest3
;
3237 np
->rv_ctest4
= np
->sv_ctest4
;
3238 np
->rv_ctest5
= np
->sv_ctest5
;
3239 burst_max
= burst_code(np
->sv_dmode
, np
->sv_ctest0
);
3243 ** Select burst length (dwords)
3245 burst_max
= driver_setup
.burst_max
;
3246 if (burst_max
== 255)
3247 burst_max
= burst_code(np
->sv_dmode
, np
->sv_ctest0
);
3250 if (burst_max
> np
->maxburst
)
3251 burst_max
= np
->maxburst
;
3254 ** Select all supported special features
3256 if (np
->features
& FE_ERL
)
3257 np
->rv_dmode
|= ERL
; /* Enable Read Line */
3258 if (np
->features
& FE_BOF
)
3259 np
->rv_dmode
|= BOF
; /* Burst Opcode Fetch */
3260 if (np
->features
& FE_ERMP
)
3261 np
->rv_dmode
|= ERMP
; /* Enable Read Multiple */
3262 if (np
->features
& FE_PFEN
)
3263 np
->rv_dcntl
|= PFEN
; /* Prefetch Enable */
3264 if (np
->features
& FE_CLSE
)
3265 np
->rv_dcntl
|= CLSE
; /* Cache Line Size Enable */
3266 if (np
->features
& FE_WRIE
)
3267 np
->rv_ctest3
|= WRIE
; /* Write and Invalidate */
3268 if (np
->features
& FE_DFS
)
3269 np
->rv_ctest5
|= DFS
; /* Dma Fifo Size */
3270 if (np
->features
& FE_MUX
)
3271 np
->rv_ctest4
|= MUX
; /* Host bus multiplex mode */
3272 if (np
->features
& FE_EA
)
3273 np
->rv_dcntl
|= EA
; /* Enable ACK */
3274 if (np
->features
& FE_EHP
)
3275 np
->rv_ctest0
|= EHP
; /* Even host parity */
3278 ** Select some other
3280 if (driver_setup
.master_parity
)
3281 np
->rv_ctest4
|= MPEE
; /* Master parity checking */
3282 if (driver_setup
.scsi_parity
)
3283 np
->rv_scntl0
|= 0x0a; /* full arb., ena parity, par->ATN */
3286 ** Get SCSI addr of host adapter (set by bios?).
3288 if (np
->myaddr
== 255) {
3289 np
->myaddr
= INB(nc_scid
) & 0x07;
3291 np
->myaddr
= SCSI_NCR_MYADDR
;
3294 #endif /* SCSI_NCR_TRUST_BIOS_SETTING */
3297 * Prepare initial io register bits for burst length
3299 ncr_init_burst(np
, burst_max
);
3302 ** Set SCSI BUS mode.
3304 ** - ULTRA2 chips (895/895A/896) report the current
3305 ** BUS mode through the STEST4 IO register.
3306 ** - For previous generation chips (825/825A/875),
3307 ** user has to tell us how to check against HVD,
3308 ** since a 100% safe algorithm is not possible.
3310 np
->scsi_mode
= SMODE_SE
;
3311 if (np
->features
& FE_DIFF
) {
3312 switch(driver_setup
.diff_support
) {
3313 case 4: /* Trust previous settings if present, then GPIO3 */
3314 if (np
->sv_scntl3
) {
3315 if (np
->sv_stest2
& 0x20)
3316 np
->scsi_mode
= SMODE_HVD
;
3319 case 3: /* SYMBIOS controllers report HVD through GPIO3 */
3320 if (INB(nc_gpreg
) & 0x08)
3322 case 2: /* Set HVD unconditionally */
3323 np
->scsi_mode
= SMODE_HVD
;
3324 case 1: /* Trust previous settings for HVD */
3325 if (np
->sv_stest2
& 0x20)
3326 np
->scsi_mode
= SMODE_HVD
;
3328 default:/* Don't care about HVD */
3332 if (np
->scsi_mode
== SMODE_HVD
)
3333 np
->rv_stest2
|= 0x20;
3336 ** Set LED support from SCRIPTS.
3337 ** Ignore this feature for boards known to use a
3338 ** specific GPIO wiring and for the 895A or 896
3339 ** that drive the LED directly.
3340 ** Also probe initial setting of GPIO0 as output.
3342 if ((driver_setup
.led_pin
) &&
3343 !(np
->features
& FE_LEDC
) && !(np
->sv_gpcntl
& 0x01))
3344 np
->features
|= FE_LED0
;
3349 switch(driver_setup
.irqm
& 3) {
3351 np
->rv_dcntl
|= IRQM
;
3354 np
->rv_dcntl
|= (np
->sv_dcntl
& IRQM
);
3361 ** Configure targets according to driver setup.
3362 ** Allow to override sync, wide and NOSCAN from
3363 ** boot command line.
3365 for (i
= 0 ; i
< MAX_TARGET
; i
++) {
3366 struct tcb
*tp
= &np
->target
[i
];
3368 tp
->usrsync
= driver_setup
.default_sync
;
3369 tp
->usrwide
= driver_setup
.max_wide
;
3370 tp
->usrtags
= MAX_TAGS
;
3371 if (!driver_setup
.disconnection
)
3372 np
->target
[i
].usrflag
= UF_NODISC
;
3376 ** Announce all that stuff to user.
3379 printk(KERN_INFO
"%s: ID %d, Fast-%d%s%s\n", ncr_name(np
),
3381 np
->minsync
< 12 ? 40 : (np
->minsync
< 25 ? 20 : 10),
3382 (np
->rv_scntl0
& 0xa) ? ", Parity Checking" : ", NO Parity",
3383 (np
->rv_stest2
& 0x20) ? ", Differential" : "");
3385 if (bootverbose
> 1) {
3386 printk (KERN_INFO
"%s: initial SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
3387 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
3388 ncr_name(np
), np
->sv_scntl3
, np
->sv_dmode
, np
->sv_dcntl
,
3389 np
->sv_ctest3
, np
->sv_ctest4
, np
->sv_ctest5
);
3391 printk (KERN_INFO
"%s: final SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
3392 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
3393 ncr_name(np
), np
->rv_scntl3
, np
->rv_dmode
, np
->rv_dcntl
,
3394 np
->rv_ctest3
, np
->rv_ctest4
, np
->rv_ctest5
);
3397 if (bootverbose
&& np
->paddr2
)
3398 printk (KERN_INFO
"%s: on-chip RAM at 0x%lx\n",
3399 ncr_name(np
), np
->paddr2
);
3402 /*==========================================================
3405 ** Done SCSI commands list management.
3407 ** We donnot enter the scsi_done() callback immediately
3408 ** after a command has been seen as completed but we
3409 ** insert it into a list which is flushed outside any kind
3410 ** of driver critical section.
3411 ** This allows to do minimal stuff under interrupt and
3412 ** inside critical sections and to also avoid locking up
3413 ** on recursive calls to driver entry points under SMP.
3414 ** In fact, the only kernel point which is entered by the
3415 ** driver with a driver lock set is kmalloc(GFP_ATOMIC)
3416 ** that shall not reenter the driver under any circumstances,
3419 **==========================================================
3421 static inline void ncr_queue_done_cmd(struct ncb
*np
, struct scsi_cmnd
*cmd
)
3423 unmap_scsi_data(np
, cmd
);
3424 cmd
->host_scribble
= (char *) np
->done_list
;
3425 np
->done_list
= cmd
;
3428 static inline void ncr_flush_done_cmds(struct scsi_cmnd
*lcmd
)
3430 struct scsi_cmnd
*cmd
;
3434 lcmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
3435 cmd
->scsi_done(cmd
);
3439 /*==========================================================
3442 ** Prepare the next negotiation message for integrity check,
3445 ** Fill in the part of message buffer that contains the
3446 ** negotiation and the nego_status field of the CCB.
3447 ** Returns the size of the message in bytes.
3450 **==========================================================
3453 #ifdef SCSI_NCR_INTEGRITY_CHECKING
3454 static int ncr_ic_nego(struct ncb
*np
, struct ccb
*cp
, struct scsi_cmnd
*cmd
, u_char
*msgptr
)
3456 struct tcb
*tp
= &np
->target
[cp
->target
];
3463 if (!tp
->ic_maximums_set
) {
3464 tp
->ic_maximums_set
= 1;
3466 /* check target and host adapter capabilities */
3467 if ( (tp
->inq_byte7
& INQ7_WIDE16
) &&
3468 np
->maxwide
&& tp
->usrwide
)
3469 tp
->ic_max_width
= 1;
3471 tp
->ic_max_width
= 0;
3473 if ((tp
->inq_byte7
& INQ7_SYNC
) && tp
->maxoffs
) {
3474 tp
->ic_min_sync
= (tp
->minsync
< np
->minsync
) ?
3475 np
->minsync
: tp
->minsync
;
3478 tp
->ic_min_sync
= 255;
3484 if (DEBUG_FLAGS
& DEBUG_IC
) {
3485 printk("%s: cmd->ic_nego %d, 1st byte 0x%2X\n",
3486 ncr_name(np
), cmd
->ic_nego
, cmd
->cmnd
[0]);
3489 /* First command from integrity check routine will request
3490 * a PPR message. Disable.
3492 if ((cmd
->ic_nego
& NS_PPR
) == NS_PPR
)
3493 cmd
->ic_nego
&= ~NS_PPR
;
3494 /* Previous command recorded a parity or an initiator
3495 * detected error condition. Force bus to narrow for this
3496 * target. Clear flag. Negotation on request sense.
3497 * Note: kernel forces 2 bus resets :o( but clears itself out.
3498 * Minor bug? in scsi_obsolete.c (ugly)
3500 if (np
->check_integ_par
) {
3501 printk("%s: Parity Error. Target set to narrow.\n",
3503 tp
->ic_max_width
= 0;
3504 tp
->widedone
= tp
->period
= 0;
3507 /* In case of a bus reset, ncr_negotiate will reset
3508 * the flags tp->widedone and tp->period to 0, forcing
3509 * a new negotiation.
3512 if (tp
->widedone
== 0) {
3513 cmd
->ic_nego
= NS_WIDE
;
3517 else if (tp
->period
== 0) {
3518 cmd
->ic_nego
= NS_SYNC
;
3523 switch (cmd
->ic_nego
) {
3526 ** negotiate wide transfers ?
3527 ** Do NOT negotiate if device only supports
3530 if (tp
->ic_max_width
| np
->check_integ_par
) {
3533 msgptr
[msglen
++] = M_EXTENDED
;
3534 msgptr
[msglen
++] = 2;
3535 msgptr
[msglen
++] = M_X_WIDE_REQ
;
3536 msgptr
[msglen
++] = cmd
->ic_nego_width
& tp
->ic_max_width
;
3539 cmd
->ic_nego_width
&= tp
->ic_max_width
;
3545 ** negotiate synchronous transfers?
3546 ** Target must support sync transfers.
3548 ** If period becomes longer than max, reset to async
3551 if (tp
->inq_byte7
& INQ7_SYNC
) {
3555 msgptr
[msglen
++] = M_EXTENDED
;
3556 msgptr
[msglen
++] = 3;
3557 msgptr
[msglen
++] = M_X_SYNC_REQ
;
3559 switch (cmd
->ic_nego_sync
) {
3560 case 2: /* increase the period */
3562 if (tp
->ic_min_sync
<= 0x0A)
3563 tp
->ic_min_sync
= 0x0C;
3564 else if (tp
->ic_min_sync
<= 0x0C)
3565 tp
->ic_min_sync
= 0x19;
3566 else if (tp
->ic_min_sync
<= 0x19)
3567 tp
->ic_min_sync
*= 2;
3569 tp
->ic_min_sync
= 255;
3570 cmd
->ic_nego_sync
= 0;
3574 msgptr
[msglen
++] = tp
->maxoffs
?tp
->ic_min_sync
:0;
3575 msgptr
[msglen
++] = tp
->maxoffs
;
3578 case 1: /* nego. to maximum */
3579 msgptr
[msglen
++] = tp
->maxoffs
?tp
->ic_min_sync
:0;
3580 msgptr
[msglen
++] = tp
->maxoffs
;
3583 case 0: /* nego to async */
3585 msgptr
[msglen
++] = 0;
3586 msgptr
[msglen
++] = 0;
3591 cmd
->ic_nego_sync
= 0;
3600 cp
->nego_status
= nego
;
3601 np
->check_integ_par
= 0;
3605 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
3606 ncr_print_msg(cp
, nego
== NS_WIDE
?
3607 "wide/narrow msgout": "sync/async msgout", msgptr
);
3613 #endif /* SCSI_NCR_INTEGRITY_CHECKING */
3615 /*==========================================================
3618 ** Prepare the next negotiation message if needed.
3620 ** Fill in the part of message buffer that contains the
3621 ** negotiation and the nego_status field of the CCB.
3622 ** Returns the size of the message in bytes.
3625 **==========================================================
3629 static int ncr_prepare_nego(struct ncb
*np
, struct ccb
*cp
, u_char
*msgptr
)
3631 struct tcb
*tp
= &np
->target
[cp
->target
];
3638 ** negotiate wide transfers ?
3641 if (!tp
->widedone
) {
3642 if (tp
->inq_byte7
& INQ7_WIDE16
) {
3644 #ifdef SCSI_NCR_INTEGRITY_CHECKING
3646 tp
->usrwide
&= tp
->ic_max_width
;
3654 ** negotiate synchronous transfers?
3657 if (!nego
&& !tp
->period
) {
3658 if (tp
->inq_byte7
& INQ7_SYNC
) {
3660 #ifdef SCSI_NCR_INTEGRITY_CHECKING
3661 if ((tp
->ic_done
) &&
3662 (tp
->minsync
< tp
->ic_min_sync
))
3663 tp
->minsync
= tp
->ic_min_sync
;
3667 PRINT_TARGET(np
, cp
->target
);
3668 printk ("target did not report SYNC.\n");
3675 msgptr
[msglen
++] = M_EXTENDED
;
3676 msgptr
[msglen
++] = 3;
3677 msgptr
[msglen
++] = M_X_SYNC_REQ
;
3678 msgptr
[msglen
++] = tp
->maxoffs
? tp
->minsync
: 0;
3679 msgptr
[msglen
++] = tp
->maxoffs
;
3682 msgptr
[msglen
++] = M_EXTENDED
;
3683 msgptr
[msglen
++] = 2;
3684 msgptr
[msglen
++] = M_X_WIDE_REQ
;
3685 msgptr
[msglen
++] = tp
->usrwide
;
3689 cp
->nego_status
= nego
;
3693 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
3694 ncr_print_msg(cp
, nego
== NS_WIDE
?
3695 "wide msgout":"sync_msgout", msgptr
);
3704 /*==========================================================
3707 ** Start execution of a SCSI command.
3708 ** This is called from the generic SCSI driver.
3711 **==========================================================
3713 static int ncr_queue_command (struct ncb
*np
, struct scsi_cmnd
*cmd
)
3715 /* struct scsi_device *device = cmd->device; */
3716 struct tcb
*tp
= &np
->target
[cmd
->device
->id
];
3717 struct lcb
*lp
= tp
->lp
[cmd
->device
->lun
];
3721 u_char idmsg
, *msgptr
;
3726 /*---------------------------------------------
3728 ** Some shortcuts ...
3730 **---------------------------------------------
3732 if ((cmd
->device
->id
== np
->myaddr
) ||
3733 (cmd
->device
->id
>= MAX_TARGET
) ||
3734 (cmd
->device
->lun
>= MAX_LUN
)) {
3735 return(DID_BAD_TARGET
);
3738 /*---------------------------------------------
3740 ** Complete the 1st TEST UNIT READY command
3741 ** with error condition if the device is
3742 ** flagged NOSCAN, in order to speed up
3745 **---------------------------------------------
3747 if ((cmd
->cmnd
[0] == 0 || cmd
->cmnd
[0] == 0x12) &&
3748 (tp
->usrflag
& UF_NOSCAN
)) {
3749 tp
->usrflag
&= ~UF_NOSCAN
;
3750 return DID_BAD_TARGET
;
3753 if (DEBUG_FLAGS
& DEBUG_TINY
) {
3755 printk ("CMD=%x ", cmd
->cmnd
[0]);
3758 /*---------------------------------------------------
3760 ** Assign a ccb / bind cmd.
3761 ** If resetting, shorten settle_time if necessary
3762 ** in order to avoid spurious timeouts.
3763 ** If resetting or no free ccb,
3764 ** insert cmd into the waiting list.
3766 **----------------------------------------------------
3768 if (np
->settle_time
&& cmd
->timeout_per_command
>= HZ
) {
3769 u_long tlimit
= ktime_get(cmd
->timeout_per_command
- HZ
);
3770 if (ktime_dif(np
->settle_time
, tlimit
) > 0)
3771 np
->settle_time
= tlimit
;
3774 if (np
->settle_time
|| !(cp
=ncr_get_ccb (np
, cmd
->device
->id
, cmd
->device
->lun
))) {
3775 insert_into_waiting_list(np
, cmd
);
3780 /*----------------------------------------------------
3782 ** Build the identify / tag / sdtr message
3784 **----------------------------------------------------
3787 idmsg
= M_IDENTIFY
| cmd
->device
->lun
;
3789 if (cp
->tag
!= NO_TAG
||
3790 (cp
!= np
->ccb
&& np
->disc
&& !(tp
->usrflag
& UF_NODISC
)))
3793 msgptr
= cp
->scsi_smsg
;
3795 msgptr
[msglen
++] = idmsg
;
3797 if (cp
->tag
!= NO_TAG
) {
3798 char order
= np
->order
;
3801 ** Force ordered tag if necessary to avoid timeouts
3802 ** and to preserve interactivity.
3804 if (lp
&& ktime_exp(lp
->tags_stime
)) {
3805 if (lp
->tags_smap
) {
3806 order
= M_ORDERED_TAG
;
3807 if ((DEBUG_FLAGS
& DEBUG_TAGS
)||bootverbose
>2){
3809 printk("ordered tag forced.\n");
3812 lp
->tags_stime
= ktime_get(3*HZ
);
3813 lp
->tags_smap
= lp
->tags_umap
;
3818 ** Ordered write ops, unordered read ops.
3820 switch (cmd
->cmnd
[0]) {
3821 case 0x08: /* READ_SMALL (6) */
3822 case 0x28: /* READ_BIG (10) */
3823 case 0xa8: /* READ_HUGE (12) */
3824 order
= M_SIMPLE_TAG
;
3827 order
= M_ORDERED_TAG
;
3830 msgptr
[msglen
++] = order
;
3832 ** Actual tags are numbered 1,3,5,..2*MAXTAGS+1,
3833 ** since we may have to deal with devices that have
3834 ** problems with #TAG 0 or too great #TAG numbers.
3836 msgptr
[msglen
++] = (cp
->tag
<< 1) + 1;
3839 /*----------------------------------------------------
3841 ** Build the data descriptors
3843 **----------------------------------------------------
3846 direction
= scsi_data_direction(cmd
);
3847 if (direction
!= SCSI_DATA_NONE
) {
3848 segments
= ncr_scatter(np
, cp
, cp
->cmd
);
3850 ncr_free_ccb(np
, cp
);
3859 /*---------------------------------------------------
3861 ** negotiation required?
3863 ** (nego_status is filled by ncr_prepare_nego())
3865 **---------------------------------------------------
3868 cp
->nego_status
= 0;
3870 #ifdef SCSI_NCR_INTEGRITY_CHECKING
3871 if ((np
->check_integrity
&& tp
->ic_done
) || !np
->check_integrity
) {
3872 if ((!tp
->widedone
|| !tp
->period
) && !tp
->nego_cp
&& lp
) {
3873 msglen
+= ncr_prepare_nego (np
, cp
, msgptr
+ msglen
);
3876 else if (np
->check_integrity
&& (cmd
->ic_in_progress
)) {
3877 msglen
+= ncr_ic_nego (np
, cp
, cmd
, msgptr
+ msglen
);
3879 else if (np
->check_integrity
&& cmd
->ic_complete
) {
3881 * Midlayer signal to the driver that all of the scsi commands
3882 * for the integrity check have completed. Save the negotiated
3883 * parameters (extracted from sval and wval).
3888 idiv
= (tp
->wval
>>4) & 0x07;
3889 if ((tp
->sval
&0x1f) && idiv
)
3890 tp
->period
= (((tp
->sval
>>5)+4)
3891 *div_10M
[idiv
-1])/np
->clock_khz
;
3893 tp
->period
= 0xffff;
3896 * tp->period contains 10 times the transfer period,
3897 * which itself is 4 * the requested negotiation rate.
3899 if (tp
->period
<= 250) tp
->ic_min_sync
= 10;
3900 else if (tp
->period
<= 303) tp
->ic_min_sync
= 11;
3901 else if (tp
->period
<= 500) tp
->ic_min_sync
= 12;
3903 tp
->ic_min_sync
= (tp
->period
+ 40 - 1) / 40;
3907 * Negotiation for this target it complete.
3909 tp
->ic_max_width
= (tp
->wval
& EWS
) ? 1: 0;
3913 printk("%s: Integrity Check Complete: \n", ncr_name(np
));
3915 printk("%s: %s %s SCSI", ncr_name(np
),
3916 (tp
->sval
&0x1f)?"SYNC":"ASYNC",
3917 tp
->ic_max_width
?"WIDE":"NARROW");
3919 if (tp
->sval
&0x1f) {
3920 u_long mbs
= 10000 * (tp
->ic_max_width
+ 1);
3922 printk(" %d.%d MB/s", (int) (mbs
/ tp
->period
),
3923 (int) (mbs
% tp
->period
));
3925 printk(" (%d ns, %d offset)\n",
3926 tp
->period
/10, tp
->sval
&0x1f);
3928 printk(" %d MB/s. \n ", (tp
->ic_max_width
+1)*5);
3932 if ((!tp
->widedone
|| !tp
->period
) && !tp
->nego_cp
&& lp
) {
3933 msglen
+= ncr_prepare_nego (np
, cp
, msgptr
+ msglen
);
3935 #endif /* SCSI_NCR_INTEGRITY_CHECKING */
3937 /*----------------------------------------------------
3939 ** Determine xfer direction.
3941 **----------------------------------------------------
3944 direction
= SCSI_DATA_NONE
;
3947 ** If data direction is UNKNOWN, speculate DATA_READ
3948 ** but prepare alternate pointers for WRITE in case
3949 ** of our speculation will be just wrong.
3950 ** SCRIPTS will swap values if needed.
3953 case SCSI_DATA_UNKNOWN
:
3954 case SCSI_DATA_WRITE
:
3955 goalp
= NCB_SCRIPT_PHYS (np
, data_out2
) + 8;
3956 if (segments
<= MAX_SCATTERL
)
3957 lastp
= goalp
- 8 - (segments
* 16);
3959 lastp
= NCB_SCRIPTH_PHYS (np
, hdata_out2
);
3960 lastp
-= (segments
- MAX_SCATTERL
) * 16;
3962 if (direction
!= SCSI_DATA_UNKNOWN
)
3964 cp
->phys
.header
.wgoalp
= cpu_to_scr(goalp
);
3965 cp
->phys
.header
.wlastp
= cpu_to_scr(lastp
);
3967 case SCSI_DATA_READ
:
3968 goalp
= NCB_SCRIPT_PHYS (np
, data_in2
) + 8;
3969 if (segments
<= MAX_SCATTERL
)
3970 lastp
= goalp
- 8 - (segments
* 16);
3972 lastp
= NCB_SCRIPTH_PHYS (np
, hdata_in2
);
3973 lastp
-= (segments
- MAX_SCATTERL
) * 16;
3977 case SCSI_DATA_NONE
:
3978 lastp
= goalp
= NCB_SCRIPT_PHYS (np
, no_data
);
3983 ** Set all pointers values needed by SCRIPTS.
3984 ** If direction is unknown, start at data_io.
3986 cp
->phys
.header
.lastp
= cpu_to_scr(lastp
);
3987 cp
->phys
.header
.goalp
= cpu_to_scr(goalp
);
3989 if (direction
== SCSI_DATA_UNKNOWN
)
3990 cp
->phys
.header
.savep
=
3991 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, data_io
));
3993 cp
->phys
.header
.savep
= cpu_to_scr(lastp
);
3996 ** Save the initial data pointer in order to be able
3997 ** to redo the command.
3999 cp
->startp
= cp
->phys
.header
.savep
;
4001 /*----------------------------------------------------
4005 **----------------------------------------------------
4008 ** physical -> virtual backlink
4009 ** Generic SCSI command
4015 cp
->start
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, select
));
4016 cp
->restart
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, resel_dsa
));
4020 cp
->phys
.select
.sel_id
= cmd
->device
->id
;
4021 cp
->phys
.select
.sel_scntl3
= tp
->wval
;
4022 cp
->phys
.select
.sel_sxfer
= tp
->sval
;
4026 cp
->phys
.smsg
.addr
= cpu_to_scr(CCB_PHYS (cp
, scsi_smsg
));
4027 cp
->phys
.smsg
.size
= cpu_to_scr(msglen
);
4032 memcpy(cp
->cdb_buf
, cmd
->cmnd
, min_t(int, cmd
->cmd_len
, sizeof(cp
->cdb_buf
)));
4033 cp
->phys
.cmd
.addr
= cpu_to_scr(CCB_PHYS (cp
, cdb_buf
[0]));
4034 cp
->phys
.cmd
.size
= cpu_to_scr(cmd
->cmd_len
);
4039 cp
->actualquirks
= tp
->quirks
;
4040 cp
->host_status
= cp
->nego_status
? HS_NEGOTIATE
: HS_BUSY
;
4041 cp
->scsi_status
= S_ILLEGAL
;
4042 cp
->parity_status
= 0;
4044 cp
->xerr_status
= XE_OK
;
4046 cp
->sync_status
= tp
->sval
;
4047 cp
->wide_status
= tp
->wval
;
4050 /*----------------------------------------------------
4052 ** Critical region: start this job.
4054 **----------------------------------------------------
4058 ** activate this job.
4060 cp
->magic
= CCB_MAGIC
;
4063 ** insert next CCBs into start queue.
4064 ** 2 max at a time is enough to flush the CCB wait queue.
4068 ncr_start_next_ccb(np
, lp
, 2);
4070 ncr_put_start_queue(np
, cp
);
4073 ** Command is successfully queued.
4080 /*==========================================================
4083 ** Insert a CCB into the start queue and wake up the
4084 ** SCRIPTS processor.
4087 **==========================================================
4090 static void ncr_start_next_ccb(struct ncb
*np
, struct lcb
*lp
, int maxn
)
4098 while (maxn
-- && lp
->queuedccbs
< lp
->queuedepth
) {
4099 qp
= xpt_remque_head(&lp
->wait_ccbq
);
4103 cp
= xpt_que_entry(qp
, struct ccb
, link_ccbq
);
4104 xpt_insque_tail(qp
, &lp
->busy_ccbq
);
4105 lp
->jump_ccb
[cp
->tag
== NO_TAG
? 0 : cp
->tag
] =
4106 cpu_to_scr(CCB_PHYS (cp
, restart
));
4107 ncr_put_start_queue(np
, cp
);
4111 static void ncr_put_start_queue(struct ncb
*np
, struct ccb
*cp
)
4116 ** insert into start queue.
4118 if (!np
->squeueput
) np
->squeueput
= 1;
4119 qidx
= np
->squeueput
+ 2;
4120 if (qidx
>= MAX_START
+ MAX_START
) qidx
= 1;
4122 np
->scripth
->tryloop
[qidx
] = cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
4124 np
->scripth
->tryloop
[np
->squeueput
] = cpu_to_scr(CCB_PHYS (cp
, start
));
4126 np
->squeueput
= qidx
;
4130 if (DEBUG_FLAGS
& DEBUG_QUEUE
)
4131 printk ("%s: queuepos=%d.\n", ncr_name (np
), np
->squeueput
);
4134 ** Script processor may be waiting for reselect.
4138 OUTB (nc_istat
, SIGP
);
4142 static int ncr_reset_scsi_bus(struct ncb
*np
, int enab_int
, int settle_delay
)
4147 np
->settle_time
= ktime_get(settle_delay
* HZ
);
4149 if (bootverbose
> 1)
4150 printk("%s: resetting, "
4151 "command processing suspended for %d seconds\n",
4152 ncr_name(np
), settle_delay
);
4154 ncr_chip_reset(np
, 100);
4155 UDELAY (2000); /* The 895 needs time for the bus mode to settle */
4157 OUTW (nc_sien
, RST
);
4159 ** Enable Tolerant, reset IRQD if present and
4160 ** properly set IRQ mode, prior to resetting the bus.
4162 OUTB (nc_stest3
, TE
);
4163 OUTB (nc_scntl1
, CRST
);
4166 if (!driver_setup
.bus_check
)
4169 ** Check for no terminators or SCSI bus shorts to ground.
4170 ** Read SCSI data bus, data parity bits and control signals.
4171 ** We are expecting RESET to be TRUE and other signals to be
4175 term
= INB(nc_sstat0
);
4176 term
= ((term
& 2) << 7) + ((term
& 1) << 17); /* rst sdp0 */
4177 term
|= ((INB(nc_sstat2
) & 0x01) << 26) | /* sdp1 */
4178 ((INW(nc_sbdl
) & 0xff) << 9) | /* d7-0 */
4179 ((INW(nc_sbdl
) & 0xff00) << 10) | /* d15-8 */
4180 INB(nc_sbcl
); /* req ack bsy sel atn msg cd io */
4182 if (!(np
->features
& FE_WIDE
))
4185 if (term
!= (2<<7)) {
4186 printk("%s: suspicious SCSI data while resetting the BUS.\n",
4188 printk("%s: %sdp0,d7-0,rst,req,ack,bsy,sel,atn,msg,c/d,i/o = "
4189 "0x%lx, expecting 0x%lx\n",
4191 (np
->features
& FE_WIDE
) ? "dp1,d15-8," : "",
4192 (u_long
)term
, (u_long
)(2<<7));
4193 if (driver_setup
.bus_check
== 1)
4197 OUTB (nc_scntl1
, 0);
4202 * Start reset process.
4203 * If reset in progress do nothing.
4204 * The interrupt handler will reinitialize the chip.
4205 * The timeout handler will wait for settle_time before
4206 * clearing it and so resuming command processing.
4208 static void ncr_start_reset(struct ncb
*np
)
4210 if (!np
->settle_time
) {
4211 ncr_reset_scsi_bus(np
, 1, driver_setup
.settle_delay
);
4215 /*==========================================================
4218 ** Reset the SCSI BUS.
4219 ** This is called from the generic SCSI driver.
4222 **==========================================================
4224 static int ncr_reset_bus (struct ncb
*np
, struct scsi_cmnd
*cmd
, int sync_reset
)
4226 /* struct scsi_device *device = cmd->device; */
4231 * Return immediately if reset is in progress.
4233 if (np
->settle_time
) {
4237 * Start the reset process.
4238 * The script processor is then assumed to be stopped.
4239 * Commands will now be queued in the waiting list until a settle
4240 * delay of 2 seconds will be completed.
4242 ncr_start_reset(np
);
4244 * First, look in the wakeup list
4246 for (found
=0, cp
=np
->ccb
; cp
; cp
=cp
->link_ccb
) {
4248 ** look for the ccb of this command.
4250 if (cp
->host_status
== HS_IDLE
) continue;
4251 if (cp
->cmd
== cmd
) {
4257 * Then, look in the waiting list
4259 if (!found
&& retrieve_from_waiting_list(0, np
, cmd
))
4262 * Wake-up all awaiting commands with DID_RESET.
4264 reset_waiting_list(np
);
4266 * Wake-up all pending commands with HS_RESET -> DID_RESET.
4268 ncr_wakeup(np
, HS_RESET
);
4270 * If the involved command was not in a driver queue, and the
4271 * scsi driver told us reset is synchronous, and the command is not
4272 * currently in the waiting list, complete it with DID_RESET status,
4273 * in order to keep it alive.
4275 if (!found
&& sync_reset
&& !retrieve_from_waiting_list(0, np
, cmd
)) {
4276 cmd
->result
= ScsiResult(DID_RESET
, 0);
4277 ncr_queue_done_cmd(np
, cmd
);
4283 /*==========================================================
4286 ** Abort an SCSI command.
4287 ** This is called from the generic SCSI driver.
4290 **==========================================================
4292 static int ncr_abort_command (struct ncb
*np
, struct scsi_cmnd
*cmd
)
4294 /* struct scsi_device *device = cmd->device; */
4300 * First, look for the scsi command in the waiting list
4302 if (remove_from_waiting_list(np
, cmd
)) {
4303 cmd
->result
= ScsiResult(DID_ABORT
, 0);
4304 ncr_queue_done_cmd(np
, cmd
);
4305 return SCSI_ABORT_SUCCESS
;
4309 * Then, look in the wakeup list
4311 for (found
=0, cp
=np
->ccb
; cp
; cp
=cp
->link_ccb
) {
4313 ** look for the ccb of this command.
4315 if (cp
->host_status
== HS_IDLE
) continue;
4316 if (cp
->cmd
== cmd
) {
4323 return SCSI_ABORT_NOT_RUNNING
;
4326 if (np
->settle_time
) {
4327 return SCSI_ABORT_SNOOZE
;
4331 ** If the CCB is active, patch schedule jumps for the
4332 ** script to abort the command.
4335 switch(cp
->host_status
) {
4338 printk ("%s: abort ccb=%p (cancel)\n", ncr_name (np
), cp
);
4339 cp
->start
.schedule
.l_paddr
=
4340 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, cancel
));
4341 retv
= SCSI_ABORT_PENDING
;
4344 cp
->restart
.schedule
.l_paddr
=
4345 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, abort
));
4346 retv
= SCSI_ABORT_PENDING
;
4349 retv
= SCSI_ABORT_NOT_RUNNING
;
4355 ** If there are no requests, the script
4356 ** processor will sleep on SEL_WAIT_RESEL.
4357 ** Let's wake it up, since it may have to work.
4359 OUTB (nc_istat
, SIGP
);
4364 /*==========================================================
4366 ** Linux release module stuff.
4368 ** Called before unloading the module
4370 ** We have to free resources and halt the NCR chip
4372 **==========================================================
4375 static void ncr_detach(struct ncb
*np
)
4384 /* Local copy so we don't access np after freeing it! */
4385 strlcpy(inst_name
, ncr_name(np
), sizeof(inst_name
));
4387 printk("%s: releasing host resources\n", ncr_name(np
));
4390 ** Stop the ncr_timeout process
4391 ** Set release_stage to 1 and wait that ncr_timeout() set it to 2.
4394 #ifdef DEBUG_NCR53C8XX
4395 printk("%s: stopping the timer\n", ncr_name(np
));
4397 np
->release_stage
= 1;
4398 for (i
= 50 ; i
&& np
->release_stage
!= 2 ; i
--) MDELAY (100);
4399 if (np
->release_stage
!= 2)
4400 printk("%s: the timer seems to be already stopped\n", ncr_name(np
));
4401 else np
->release_stage
= 2;
4404 ** Disable chip interrupts
4407 #ifdef DEBUG_NCR53C8XX
4408 printk("%s: disabling chip interrupts\n", ncr_name(np
));
4415 ** Restore bios setting for automatic clock detection.
4418 printk("%s: resetting chip\n", ncr_name(np
));
4419 ncr_chip_reset(np
, 100);
4421 OUTB(nc_dmode
, np
->sv_dmode
);
4422 OUTB(nc_dcntl
, np
->sv_dcntl
);
4423 OUTB(nc_ctest0
, np
->sv_ctest0
);
4424 OUTB(nc_ctest3
, np
->sv_ctest3
);
4425 OUTB(nc_ctest4
, np
->sv_ctest4
);
4426 OUTB(nc_ctest5
, np
->sv_ctest5
);
4427 OUTB(nc_gpcntl
, np
->sv_gpcntl
);
4428 OUTB(nc_stest2
, np
->sv_stest2
);
4430 ncr_selectclock(np
, np
->sv_scntl3
);
4433 ** Free allocated ccb(s)
4436 while ((cp
=np
->ccb
->link_ccb
) != NULL
) {
4437 np
->ccb
->link_ccb
= cp
->link_ccb
;
4438 if (cp
->host_status
) {
4439 printk("%s: shall free an active ccb (host_status=%d)\n",
4440 ncr_name(np
), cp
->host_status
);
4442 #ifdef DEBUG_NCR53C8XX
4443 printk("%s: freeing ccb (%lx)\n", ncr_name(np
), (u_long
) cp
);
4445 m_free_dma(cp
, sizeof(*cp
), "CCB");
4448 /* Free allocated tp(s) */
4450 for (target
= 0; target
< MAX_TARGET
; target
++) {
4451 tp
=&np
->target
[target
];
4452 for (lun
= 0 ; lun
< MAX_LUN
; lun
++) {
4455 #ifdef DEBUG_NCR53C8XX
4456 printk("%s: freeing lp (%lx)\n", ncr_name(np
), (u_long
) lp
);
4458 if (lp
->jump_ccb
!= &lp
->jump_ccb_0
)
4459 m_free_dma(lp
->jump_ccb
,256,"JUMP_CCB");
4460 m_free_dma(lp
, sizeof(*lp
), "LCB");
4466 m_free_dma(np
->scripth0
, sizeof(struct scripth
), "SCRIPTH");
4468 m_free_dma(np
->script0
, sizeof(struct script
), "SCRIPT");
4470 m_free_dma(np
->ccb
, sizeof(struct ccb
), "CCB");
4471 m_free_dma(np
, sizeof(struct ncb
), "NCB");
4473 printk("%s: host resources successfully released\n", inst_name
);
4476 /*==========================================================
4479 ** Complete execution of a SCSI command.
4480 ** Signal completion to the generic SCSI driver.
4483 **==========================================================
4486 void ncr_complete (struct ncb
*np
, struct ccb
*cp
)
4488 struct scsi_cmnd
*cmd
;
4496 if (!cp
|| cp
->magic
!= CCB_MAGIC
|| !cp
->cmd
)
4500 ** Print minimal debug information.
4503 if (DEBUG_FLAGS
& DEBUG_TINY
)
4504 printk ("CCB=%lx STAT=%x/%x\n", (unsigned long)cp
,
4505 cp
->host_status
,cp
->scsi_status
);
4508 ** Get command, target and lun pointers.
4513 tp
= &np
->target
[cmd
->device
->id
];
4514 lp
= tp
->lp
[cmd
->device
->lun
];
4517 ** We donnot queue more than 1 ccb per target
4518 ** with negotiation at any time. If this ccb was
4519 ** used for negotiation, clear this info in the tcb.
4522 if (cp
== tp
->nego_cp
)
4526 ** If auto-sense performed, change scsi status.
4528 if (cp
->auto_sense
) {
4529 cp
->scsi_status
= cp
->auto_sense
;
4533 ** If we were recovering from queue full or performing
4534 ** auto-sense, requeue skipped CCBs to the wait queue.
4537 if (lp
&& lp
->held_ccb
) {
4538 if (cp
== lp
->held_ccb
) {
4539 xpt_que_splice(&lp
->skip_ccbq
, &lp
->wait_ccbq
);
4540 xpt_que_init(&lp
->skip_ccbq
);
4541 lp
->held_ccb
= NULL
;
4546 ** Check for parity errors.
4549 if (cp
->parity_status
> 1) {
4551 printk ("%d parity error(s).\n",cp
->parity_status
);
4555 ** Check for extended errors.
4558 if (cp
->xerr_status
!= XE_OK
) {
4560 switch (cp
->xerr_status
) {
4562 printk ("extraneous data discarded.\n");
4565 printk ("invalid scsi phase (4/5).\n");
4568 printk ("extended error %d.\n", cp
->xerr_status
);
4571 if (cp
->host_status
==HS_COMPLETE
)
4572 cp
->host_status
= HS_FAIL
;
4576 ** Print out any error for debugging purpose.
4578 if (DEBUG_FLAGS
& (DEBUG_RESULT
|DEBUG_TINY
)) {
4579 if (cp
->host_status
!=HS_COMPLETE
|| cp
->scsi_status
!=S_GOOD
) {
4581 printk ("ERROR: cmd=%x host_status=%x scsi_status=%x\n",
4582 cmd
->cmnd
[0], cp
->host_status
, cp
->scsi_status
);
4587 ** Check the status.
4589 if ( (cp
->host_status
== HS_COMPLETE
)
4590 && (cp
->scsi_status
== S_GOOD
||
4591 cp
->scsi_status
== S_COND_MET
)) {
4593 * All went well (GOOD status).
4594 * CONDITION MET status is returned on
4595 * `Pre-Fetch' or `Search data' success.
4597 cmd
->result
= ScsiResult(DID_OK
, cp
->scsi_status
);
4601 ** Could dig out the correct value for resid,
4602 ** but it would be quite complicated.
4604 /* if (cp->phys.header.lastp != cp->phys.header.goalp) */
4607 ** Allocate the lcb if not yet.
4610 ncr_alloc_lcb (np
, cmd
->device
->id
, cmd
->device
->lun
);
4613 ** On standard INQUIRY response (EVPD and CmDt
4614 ** not set), setup logical unit according to
4615 ** announced capabilities (we need the 1rst 7 bytes).
4617 if (cmd
->cmnd
[0] == 0x12 && !(cmd
->cmnd
[1] & 0x3) &&
4618 cmd
->cmnd
[4] >= 7 && !cmd
->use_sg
) {
4619 sync_scsi_data_for_cpu(np
, cmd
); /* SYNC the data */
4620 ncr_setup_lcb (np
, cmd
->device
->id
, cmd
->device
->lun
,
4621 (char *) cmd
->request_buffer
);
4622 sync_scsi_data_for_device(np
, cmd
); /* SYNC the data */
4625 tp
->bytes
+= cp
->data_len
;
4629 ** If tags was reduced due to queue full,
4630 ** increase tags if 1000 good status received.
4632 if (lp
&& lp
->usetags
&& lp
->numtags
< lp
->maxtags
) {
4634 if (lp
->num_good
>= 1000) {
4637 ncr_setup_tags (np
, cmd
->device
->id
, cmd
->device
->lun
);
4640 } else if ((cp
->host_status
== HS_COMPLETE
)
4641 && (cp
->scsi_status
== S_CHECK_COND
)) {
4643 ** Check condition code
4645 cmd
->result
= ScsiResult(DID_OK
, S_CHECK_COND
);
4648 ** Copy back sense data to caller's buffer.
4650 memcpy(cmd
->sense_buffer
, cp
->sense_buf
,
4651 min(sizeof(cmd
->sense_buffer
), sizeof(cp
->sense_buf
)));
4653 if (DEBUG_FLAGS
& (DEBUG_RESULT
|DEBUG_TINY
)) {
4654 u_char
* p
= (u_char
*) & cmd
->sense_buffer
;
4657 printk ("sense data:");
4658 for (i
=0; i
<14; i
++) printk (" %x", *p
++);
4661 } else if ((cp
->host_status
== HS_COMPLETE
)
4662 && (cp
->scsi_status
== S_CONFLICT
)) {
4664 ** Reservation Conflict condition code
4666 cmd
->result
= ScsiResult(DID_OK
, S_CONFLICT
);
4668 } else if ((cp
->host_status
== HS_COMPLETE
)
4669 && (cp
->scsi_status
== S_BUSY
||
4670 cp
->scsi_status
== S_QUEUE_FULL
)) {
4675 cmd
->result
= ScsiResult(DID_OK
, cp
->scsi_status
);
4677 } else if ((cp
->host_status
== HS_SEL_TIMEOUT
)
4678 || (cp
->host_status
== HS_TIMEOUT
)) {
4683 cmd
->result
= ScsiResult(DID_TIME_OUT
, cp
->scsi_status
);
4685 } else if (cp
->host_status
== HS_RESET
) {
4690 cmd
->result
= ScsiResult(DID_RESET
, cp
->scsi_status
);
4692 } else if (cp
->host_status
== HS_ABORTED
) {
4697 cmd
->result
= ScsiResult(DID_ABORT
, cp
->scsi_status
);
4702 ** Other protocol messes
4705 printk ("COMMAND FAILED (%x %x) @%p.\n",
4706 cp
->host_status
, cp
->scsi_status
, cp
);
4708 cmd
->result
= ScsiResult(DID_ERROR
, cp
->scsi_status
);
4715 if (tp
->usrflag
& UF_TRACE
) {
4720 p
= (u_char
*) &cmd
->cmnd
[0];
4721 for (i
=0; i
<cmd
->cmd_len
; i
++) printk (" %x", *p
++);
4723 if (cp
->host_status
==HS_COMPLETE
) {
4724 switch (cp
->scsi_status
) {
4730 p
= (u_char
*) &cmd
->sense_buffer
;
4731 for (i
=0; i
<14; i
++)
4732 printk (" %x", *p
++);
4735 printk (" STAT: %x\n", cp
->scsi_status
);
4738 } else printk (" HOSTERROR: %x", cp
->host_status
);
4745 ncr_free_ccb (np
, cp
);
4748 ** requeue awaiting scsi commands for this lun.
4750 if (lp
&& lp
->queuedccbs
< lp
->queuedepth
&&
4751 !xpt_que_empty(&lp
->wait_ccbq
))
4752 ncr_start_next_ccb(np
, lp
, 2);
4755 ** requeue awaiting scsi commands for this controller.
4757 if (np
->waiting_list
)
4758 requeue_waiting_list(np
);
4761 ** signal completion to generic driver.
4763 ncr_queue_done_cmd(np
, cmd
);
4766 /*==========================================================
4769 ** Signal all (or one) control block done.
4772 **==========================================================
4776 ** This CCB has been skipped by the NCR.
4777 ** Queue it in the correponding unit queue.
4779 static void ncr_ccb_skipped(struct ncb
*np
, struct ccb
*cp
)
4781 struct tcb
*tp
= &np
->target
[cp
->target
];
4782 struct lcb
*lp
= tp
->lp
[cp
->lun
];
4784 if (lp
&& cp
!= np
->ccb
) {
4785 cp
->host_status
&= ~HS_SKIPMASK
;
4786 cp
->start
.schedule
.l_paddr
=
4787 cpu_to_scr(NCB_SCRIPT_PHYS (np
, select
));
4788 xpt_remque(&cp
->link_ccbq
);
4789 xpt_insque_tail(&cp
->link_ccbq
, &lp
->skip_ccbq
);
4801 ** The NCR has completed CCBs.
4802 ** Look at the DONE QUEUE if enabled, otherwise scan all CCBs
4804 void ncr_wakeup_done (struct ncb
*np
)
4807 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
4810 i
= np
->ccb_done_ic
;
4816 cp
= np
->ccb_done
[j
];
4817 if (!CCB_DONE_VALID(cp
))
4820 np
->ccb_done
[j
] = (struct ccb
*)CCB_DONE_EMPTY
;
4821 np
->scripth
->done_queue
[5*j
+ 4] =
4822 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_plug
));
4824 np
->scripth
->done_queue
[5*i
+ 4] =
4825 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_end
));
4827 if (cp
->host_status
& HS_DONEMASK
)
4828 ncr_complete (np
, cp
);
4829 else if (cp
->host_status
& HS_SKIPMASK
)
4830 ncr_ccb_skipped (np
, cp
);
4834 np
->ccb_done_ic
= i
;
4838 if (cp
->host_status
& HS_DONEMASK
)
4839 ncr_complete (np
, cp
);
4840 else if (cp
->host_status
& HS_SKIPMASK
)
4841 ncr_ccb_skipped (np
, cp
);
4848 ** Complete all active CCBs.
4850 void ncr_wakeup (struct ncb
*np
, u_long code
)
4852 struct ccb
*cp
= np
->ccb
;
4855 if (cp
->host_status
!= HS_IDLE
) {
4856 cp
->host_status
= code
;
4857 ncr_complete (np
, cp
);
4867 /* Some initialisation must be done immediately following reset, for 53c720,
4868 * at least. EA (dcntl bit 5) isn't set here as it is set once only in
4869 * the _detect function.
4871 static void ncr_chip_reset(struct ncb
*np
, int delay
)
4873 OUTB (nc_istat
, SRST
);
4875 OUTB (nc_istat
, 0 );
4877 if (np
->features
& FE_EHP
)
4878 OUTB (nc_ctest0
, EHP
);
4879 if (np
->features
& FE_MUX
)
4880 OUTB (nc_ctest4
, MUX
);
4884 /*==========================================================
4890 **==========================================================
4893 void ncr_init (struct ncb
*np
, int reset
, char * msg
, u_long code
)
4898 ** Reset chip if asked, otherwise just clear fifos.
4902 OUTB (nc_istat
, SRST
);
4906 OUTB (nc_stest3
, TE
|CSF
);
4907 OUTONB (nc_ctest3
, CLF
);
4914 if (msg
) printk (KERN_INFO
"%s: restart (%s).\n", ncr_name (np
), msg
);
4917 ** Clear Start Queue
4919 np
->queuedepth
= MAX_START
- 1; /* 1 entry needed as end marker */
4920 for (i
= 1; i
< MAX_START
+ MAX_START
; i
+= 2)
4921 np
->scripth0
->tryloop
[i
] =
4922 cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
4925 ** Start at first entry.
4928 np
->script0
->startpos
[0] = cpu_to_scr(NCB_SCRIPTH_PHYS (np
, tryloop
));
4930 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
4934 for (i
= 0; i
< MAX_DONE
; i
++) {
4935 np
->ccb_done
[i
] = (struct ccb
*)CCB_DONE_EMPTY
;
4936 np
->scripth0
->done_queue
[5*i
+ 4] =
4937 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_end
));
4942 ** Start at first entry.
4944 np
->script0
->done_pos
[0] = cpu_to_scr(NCB_SCRIPTH_PHYS (np
,done_queue
));
4945 np
->ccb_done_ic
= MAX_DONE
-1;
4946 np
->scripth0
->done_queue
[5*(MAX_DONE
-1) + 4] =
4947 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_plug
));
4950 ** Wakeup all pending jobs.
4952 ncr_wakeup (np
, code
);
4959 ** Remove reset; big delay because the 895 needs time for the
4960 ** bus mode to settle
4962 ncr_chip_reset(np
, 2000);
4964 OUTB (nc_scntl0
, np
->rv_scntl0
| 0xc0);
4965 /* full arb., ena parity, par->ATN */
4966 OUTB (nc_scntl1
, 0x00); /* odd parity, and remove CRST!! */
4968 ncr_selectclock(np
, np
->rv_scntl3
); /* Select SCSI clock */
4970 OUTB (nc_scid
, RRE
|np
->myaddr
); /* Adapter SCSI address */
4971 OUTW (nc_respid
, 1ul<<np
->myaddr
); /* Id to respond to */
4972 OUTB (nc_istat
, SIGP
); /* Signal Process */
4973 OUTB (nc_dmode
, np
->rv_dmode
); /* Burst length, dma mode */
4974 OUTB (nc_ctest5
, np
->rv_ctest5
); /* Large fifo + large burst */
4976 OUTB (nc_dcntl
, NOCOM
|np
->rv_dcntl
); /* Protect SFBR */
4977 OUTB (nc_ctest0
, np
->rv_ctest0
); /* 720: CDIS and EHP */
4978 OUTB (nc_ctest3
, np
->rv_ctest3
); /* Write and invalidate */
4979 OUTB (nc_ctest4
, np
->rv_ctest4
); /* Master parity checking */
4981 OUTB (nc_stest2
, EXT
|np
->rv_stest2
); /* Extended Sreq/Sack filtering */
4982 OUTB (nc_stest3
, TE
); /* TolerANT enable */
4983 OUTB (nc_stime0
, 0x0c ); /* HTH disabled STO 0.25 sec */
4986 ** Disable disconnects.
4992 ** Enable GPIO0 pin for writing if LED support.
4995 if (np
->features
& FE_LED0
) {
4996 OUTOFFB (nc_gpcntl
, 0x01);
5003 OUTW (nc_sien
, STO
|HTH
|MA
|SGE
|UDC
|RST
|PAR
);
5004 OUTB (nc_dien
, MDPE
|BF
|ABRT
|SSI
|SIR
|IID
);
5007 ** Fill in target structure.
5008 ** Reinitialize usrsync.
5009 ** Reinitialize usrwide.
5010 ** Prepare sync negotiation according to actual SCSI bus mode.
5013 for (i
=0;i
<MAX_TARGET
;i
++) {
5014 struct tcb
*tp
= &np
->target
[i
];
5017 tp
->wval
= np
->rv_scntl3
;
5019 if (tp
->usrsync
!= 255) {
5020 if (tp
->usrsync
<= np
->maxsync
) {
5021 if (tp
->usrsync
< np
->minsync
) {
5022 tp
->usrsync
= np
->minsync
;
5029 if (tp
->usrwide
> np
->maxwide
)
5030 tp
->usrwide
= np
->maxwide
;
5032 ncr_negotiate (np
, tp
);
5036 ** Start script processor.
5040 printk ("%s: Downloading SCSI SCRIPTS.\n",
5042 OUTL (nc_scratcha
, vtobus(np
->script0
));
5043 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, start_ram
));
5046 OUTL_DSP (NCB_SCRIPT_PHYS (np
, start
));
5049 /*==========================================================
5051 ** Prepare the negotiation values for wide and
5052 ** synchronous transfers.
5054 **==========================================================
5057 static void ncr_negotiate (struct ncb
* np
, struct tcb
* tp
)
5060 ** minsync unit is 4ns !
5063 u_long minsync
= tp
->usrsync
;
5066 ** SCSI bus mode limit
5069 if (np
->scsi_mode
&& np
->scsi_mode
== SMODE_SE
) {
5070 if (minsync
< 12) minsync
= 12;
5077 if (minsync
< np
->minsync
)
5078 minsync
= np
->minsync
;
5084 if (minsync
> np
->maxsync
)
5087 tp
->minsync
= minsync
;
5088 tp
->maxoffs
= (minsync
<255 ? np
->maxoffs
: 0);
5091 ** period=0: has to negotiate sync transfer
5097 ** widedone=0: has to negotiate wide transfer
5102 /*==========================================================
5104 ** Get clock factor and sync divisor for a given
5105 ** synchronous factor period.
5106 ** Returns the clock factor (in sxfer) and scntl3
5107 ** synchronous divisor field.
5109 **==========================================================
5112 static void ncr_getsync(struct ncb
*np
, u_char sfac
, u_char
*fakp
, u_char
*scntl3p
)
5114 u_long clk
= np
->clock_khz
; /* SCSI clock frequency in kHz */
5115 int div
= np
->clock_divn
; /* Number of divisors supported */
5116 u_long fak
; /* Sync factor in sxfer */
5117 u_long per
; /* Period in tenths of ns */
5118 u_long kpc
; /* (per * clk) */
5121 ** Compute the synchronous period in tenths of nano-seconds
5123 if (sfac
<= 10) per
= 250;
5124 else if (sfac
== 11) per
= 303;
5125 else if (sfac
== 12) per
= 500;
5126 else per
= 40 * sfac
;
5129 ** Look for the greatest clock divisor that allows an
5130 ** input speed faster than the period.
5134 if (kpc
>= (div_10M
[div
] << 2)) break;
5137 ** Calculate the lowest clock factor that allows an output
5138 ** speed not faster than the period.
5140 fak
= (kpc
- 1) / div_10M
[div
] + 1;
5142 #if 0 /* This optimization does not seem very useful */
5144 per
= (fak
* div_10M
[div
]) / clk
;
5147 ** Why not to try the immediate lower divisor and to choose
5148 ** the one that allows the fastest output speed ?
5149 ** We don't want input speed too much greater than output speed.
5151 if (div
>= 1 && fak
< 8) {
5153 fak2
= (kpc
- 1) / div_10M
[div
-1] + 1;
5154 per2
= (fak2
* div_10M
[div
-1]) / clk
;
5155 if (per2
< per
&& fak2
<= 8) {
5163 if (fak
< 4) fak
= 4; /* Should never happen, too bad ... */
5166 ** Compute and return sync parameters for the ncr
5169 *scntl3p
= ((div
+1) << 4) + (sfac
< 25 ? 0x80 : 0);
5173 /*==========================================================
5175 ** Set actual values, sync status and patch all ccbs of
5176 ** a target according to new sync/wide agreement.
5178 **==========================================================
5181 static void ncr_set_sync_wide_status (struct ncb
*np
, u_char target
)
5184 struct tcb
*tp
= &np
->target
[target
];
5187 ** set actual value and sync_status
5189 OUTB (nc_sxfer
, tp
->sval
);
5190 np
->sync_st
= tp
->sval
;
5191 OUTB (nc_scntl3
, tp
->wval
);
5192 np
->wide_st
= tp
->wval
;
5195 ** patch ALL ccbs of this target.
5197 for (cp
= np
->ccb
; cp
; cp
= cp
->link_ccb
) {
5198 if (!cp
->cmd
) continue;
5199 if (cp
->cmd
->device
->id
!= target
) continue;
5201 cp
->sync_status
= tp
->sval
;
5202 cp
->wide_status
= tp
->wval
;
5204 cp
->phys
.select
.sel_scntl3
= tp
->wval
;
5205 cp
->phys
.select
.sel_sxfer
= tp
->sval
;
5209 /*==========================================================
5211 ** Switch sync mode for current job and it's target
5213 **==========================================================
5216 static void ncr_setsync (struct ncb
*np
, struct ccb
*cp
, u_char scntl3
, u_char sxfer
)
5218 struct scsi_cmnd
*cmd
;
5220 u_char target
= INB (nc_sdid
) & 0x0f;
5223 assert (cp
&& cp
->cmd
);
5229 assert (target
== (cmd
->device
->id
& 0xf));
5231 tp
= &np
->target
[target
];
5233 if (!scntl3
|| !(sxfer
& 0x1f))
5234 scntl3
= np
->rv_scntl3
;
5235 scntl3
= (scntl3
& 0xf0) | (tp
->wval
& EWS
) | (np
->rv_scntl3
& 0x07);
5238 ** Deduce the value of controller sync period from scntl3.
5239 ** period is in tenths of nano-seconds.
5242 idiv
= ((scntl3
>> 4) & 0x7);
5243 if ((sxfer
& 0x1f) && idiv
)
5244 tp
->period
= (((sxfer
>>5)+4)*div_10M
[idiv
-1])/np
->clock_khz
;
5246 tp
->period
= 0xffff;
5249 ** Stop there if sync parameters are unchanged
5251 if (tp
->sval
== sxfer
&& tp
->wval
== scntl3
) return;
5256 ** Bells and whistles ;-)
5258 PRINT_TARGET(np
, target
);
5259 if (sxfer
& 0x01f) {
5260 unsigned f10
= 100000 << (tp
->widedone
? tp
->widedone
-1 : 0);
5261 unsigned mb10
= (f10
+ tp
->period
/2) / tp
->period
;
5265 ** Disable extended Sreq/Sack filtering
5267 if (tp
->period
<= 2000) OUTOFFB (nc_stest2
, EXT
);
5270 ** Bells and whistles ;-)
5272 if (tp
->period
< 500) scsi
= "FAST-40";
5273 else if (tp
->period
< 1000) scsi
= "FAST-20";
5274 else if (tp
->period
< 2000) scsi
= "FAST-10";
5275 else scsi
= "FAST-5";
5277 printk ("%s %sSCSI %d.%d MB/s (%d ns, offset %d)\n", scsi
,
5278 tp
->widedone
> 1 ? "WIDE " : "",
5279 mb10
/ 10, mb10
% 10, tp
->period
/ 10, sxfer
& 0x1f);
5281 printk ("%sasynchronous.\n", tp
->widedone
> 1 ? "wide " : "");
5284 ** set actual value and sync_status
5285 ** patch ALL ccbs of this target.
5287 ncr_set_sync_wide_status(np
, target
);
5290 /*==========================================================
5292 ** Switch wide mode for current job and it's target
5293 ** SCSI specs say: a SCSI device that accepts a WDTR
5294 ** message shall reset the synchronous agreement to
5295 ** asynchronous mode.
5297 **==========================================================
5300 static void ncr_setwide (struct ncb
*np
, struct ccb
*cp
, u_char wide
, u_char ack
)
5302 struct scsi_cmnd
*cmd
;
5303 u16 target
= INB (nc_sdid
) & 0x0f;
5308 assert (cp
&& cp
->cmd
);
5314 assert (target
== (cmd
->device
->id
& 0xf));
5316 tp
= &np
->target
[target
];
5317 tp
->widedone
= wide
+1;
5318 scntl3
= (tp
->wval
& (~EWS
)) | (wide
? EWS
: 0);
5320 sxfer
= ack
? 0 : tp
->sval
;
5323 ** Stop there if sync/wide parameters are unchanged
5325 if (tp
->sval
== sxfer
&& tp
->wval
== scntl3
) return;
5330 ** Bells and whistles ;-)
5332 if (bootverbose
>= 2) {
5333 PRINT_TARGET(np
, target
);
5335 printk ("WIDE SCSI (16 bit) enabled.\n");
5337 printk ("WIDE SCSI disabled.\n");
5341 ** set actual value and sync_status
5342 ** patch ALL ccbs of this target.
5344 ncr_set_sync_wide_status(np
, target
);
5347 /*==========================================================
5349 ** Switch tagged mode for a target.
5351 **==========================================================
5354 static void ncr_setup_tags (struct ncb
*np
, u_char tn
, u_char ln
)
5356 struct tcb
*tp
= &np
->target
[tn
];
5357 struct lcb
*lp
= tp
->lp
[ln
];
5358 u_char reqtags
, maxdepth
;
5367 ** If SCSI device queue depth is not yet set, leave here.
5369 if (!lp
->scdev_depth
)
5373 ** Donnot allow more tags than the SCSI driver can queue
5375 ** Donnot allow more tags than we can handle.
5377 maxdepth
= lp
->scdev_depth
;
5378 if (maxdepth
> lp
->maxnxs
) maxdepth
= lp
->maxnxs
;
5379 if (lp
->maxtags
> maxdepth
) lp
->maxtags
= maxdepth
;
5380 if (lp
->numtags
> maxdepth
) lp
->numtags
= maxdepth
;
5383 ** only devices conformant to ANSI Version >= 2
5384 ** only devices capable of tagged commands
5385 ** only if enabled by user ..
5387 if ((lp
->inq_byte7
& INQ7_QUEUE
) && lp
->numtags
> 1) {
5388 reqtags
= lp
->numtags
;
5394 ** Update max number of tags
5396 lp
->numtags
= reqtags
;
5397 if (lp
->numtags
> lp
->maxtags
)
5398 lp
->maxtags
= lp
->numtags
;
5401 ** If we want to switch tag mode, we must wait
5402 ** for no CCB to be active.
5404 if (reqtags
> 1 && lp
->usetags
) { /* Stay in tagged mode */
5405 if (lp
->queuedepth
== reqtags
) /* Already announced */
5407 lp
->queuedepth
= reqtags
;
5409 else if (reqtags
<= 1 && !lp
->usetags
) { /* Stay in untagged mode */
5410 lp
->queuedepth
= reqtags
;
5413 else { /* Want to switch tag mode */
5414 if (lp
->busyccbs
) /* If not yet safe, return */
5416 lp
->queuedepth
= reqtags
;
5417 lp
->usetags
= reqtags
> 1 ? 1 : 0;
5421 ** Patch the lun mini-script, according to tag mode.
5423 lp
->jump_tag
.l_paddr
= lp
->usetags
?
5424 cpu_to_scr(NCB_SCRIPT_PHYS(np
, resel_tag
)) :
5425 cpu_to_scr(NCB_SCRIPT_PHYS(np
, resel_notag
));
5428 ** Announce change to user.
5431 PRINT_LUN(np
, tn
, ln
);
5433 printk("tagged command queue depth set to %d\n", reqtags
);
5436 printk("tagged command queueing disabled\n");
5441 /*----------------------------------------------------
5443 ** handle user commands
5445 **----------------------------------------------------
5448 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
5450 static void ncr_usercmd (struct ncb
*np
)
5455 switch (np
->user
.cmd
) {
5460 for (t
=0; t
<MAX_TARGET
; t
++) {
5461 if (!((np
->user
.target
>>t
)&1)) continue;
5462 tp
= &np
->target
[t
];
5463 tp
->usrsync
= np
->user
.data
;
5464 ncr_negotiate (np
, tp
);
5469 for (t
=0; t
<MAX_TARGET
; t
++) {
5471 if (!((np
->user
.target
>>t
)&1)) continue;
5472 np
->target
[t
].usrtags
= np
->user
.data
;
5473 for (ln
= 0; ln
< MAX_LUN
; ln
++) {
5474 struct lcb
*lp
= np
->target
[t
].lp
[ln
];
5477 lp
->maxtags
= lp
->numtags
= np
->user
.data
;
5478 ncr_setup_tags (np
, t
, ln
);
5484 #ifdef SCSI_NCR_DEBUG_INFO_SUPPORT
5485 ncr_debug
= np
->user
.data
;
5490 np
->order
= np
->user
.data
;
5494 np
->verbose
= np
->user
.data
;
5498 for (t
=0; t
<MAX_TARGET
; t
++) {
5500 if (!((np
->user
.target
>>t
)&1)) continue;
5501 tp
= &np
->target
[t
];
5502 size
= np
->user
.data
;
5503 if (size
> np
->maxwide
) size
=np
->maxwide
;
5505 ncr_negotiate (np
, tp
);
5510 for (t
=0; t
<MAX_TARGET
; t
++) {
5511 if (!((np
->user
.target
>>t
)&1)) continue;
5512 tp
= &np
->target
[t
];
5513 tp
->usrflag
= np
->user
.data
;
5521 /*==========================================================
5524 ** ncr timeout handler.
5527 **==========================================================
5529 ** Misused to keep the driver running when
5530 ** interrupts are not configured correctly.
5532 **----------------------------------------------------------
5535 static void ncr_timeout (struct ncb
*np
)
5537 u_long thistime
= ktime_get(0);
5540 ** If release process in progress, let's go
5541 ** Set the release stage from 1 to 2 to synchronize
5542 ** with the release process.
5545 if (np
->release_stage
) {
5546 if (np
->release_stage
== 1) np
->release_stage
= 2;
5550 np
->timer
.expires
= ktime_get(SCSI_NCR_TIMER_INTERVAL
);
5551 add_timer(&np
->timer
);
5554 ** If we are resetting the ncr, wait for settle_time before
5555 ** clearing it. Then command processing will be resumed.
5557 if (np
->settle_time
) {
5558 if (np
->settle_time
<= thistime
) {
5559 if (bootverbose
> 1)
5560 printk("%s: command processing resumed\n", ncr_name(np
));
5561 np
->settle_time
= 0;
5563 requeue_waiting_list(np
);
5569 ** Since the generic scsi driver only allows us 0.5 second
5570 ** to perform abort of a command, we must look at ccbs about
5571 ** every 0.25 second.
5573 if (np
->lasttime
+ 4*HZ
< thistime
) {
5575 ** block ncr interrupts
5577 np
->lasttime
= thistime
;
5580 #ifdef SCSI_NCR_BROKEN_INTR
5581 if (INB(nc_istat
) & (INTF
|SIP
|DIP
)) {
5584 ** Process pending interrupts.
5586 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("{");
5588 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("}");
5590 #endif /* SCSI_NCR_BROKEN_INTR */
5593 /*==========================================================
5595 ** log message for real hard errors
5597 ** "ncr0 targ 0?: ERROR (ds:si) (so-si-sd) (sxfer/scntl3) @ name (dsp:dbc)."
5598 ** " reg: r0 r1 r2 r3 r4 r5 r6 ..... rf."
5600 ** exception register:
5605 ** so: control lines as driver by NCR.
5606 ** si: control lines as seen by NCR.
5607 ** sd: scsi data lines as seen by NCR.
5610 ** sxfer: (see the manual)
5611 ** scntl3: (see the manual)
5613 ** current script command:
5614 ** dsp: script address (relative to start of script).
5615 ** dbc: first word of script command.
5617 ** First 16 register of the chip:
5620 **==========================================================
5623 static void ncr_log_hard_error(struct ncb
*np
, u16 sist
, u_char dstat
)
5629 u_char
*script_base
;
5634 if (dsp
> np
->p_script
&& dsp
<= np
->p_script
+ sizeof(struct script
)) {
5635 script_ofs
= dsp
- np
->p_script
;
5636 script_size
= sizeof(struct script
);
5637 script_base
= (u_char
*) np
->script0
;
5638 script_name
= "script";
5640 else if (np
->p_scripth
< dsp
&&
5641 dsp
<= np
->p_scripth
+ sizeof(struct scripth
)) {
5642 script_ofs
= dsp
- np
->p_scripth
;
5643 script_size
= sizeof(struct scripth
);
5644 script_base
= (u_char
*) np
->scripth0
;
5645 script_name
= "scripth";
5650 script_name
= "mem";
5653 printk ("%s:%d: ERROR (%x:%x) (%x-%x-%x) (%x/%x) @ (%s %x:%08x).\n",
5654 ncr_name (np
), (unsigned)INB (nc_sdid
)&0x0f, dstat
, sist
,
5655 (unsigned)INB (nc_socl
), (unsigned)INB (nc_sbcl
), (unsigned)INB (nc_sbdl
),
5656 (unsigned)INB (nc_sxfer
),(unsigned)INB (nc_scntl3
), script_name
, script_ofs
,
5657 (unsigned)INL (nc_dbc
));
5659 if (((script_ofs
& 3) == 0) &&
5660 (unsigned)script_ofs
< script_size
) {
5661 printk ("%s: script cmd = %08x\n", ncr_name(np
),
5662 scr_to_cpu((int) *(ncrcmd
*)(script_base
+ script_ofs
)));
5665 printk ("%s: regdump:", ncr_name(np
));
5667 printk (" %02x", (unsigned)INB_OFF(i
));
5671 /*============================================================
5673 ** ncr chip exception handler.
5675 **============================================================
5677 ** In normal cases, interrupt conditions occur one at a
5678 ** time. The ncr is able to stack in some extra registers
5679 ** other interrupts that will occurs after the first one.
5680 ** But severall interrupts may occur at the same time.
5682 ** We probably should only try to deal with the normal
5683 ** case, but it seems that multiple interrupts occur in
5684 ** some cases that are not abnormal at all.
5686 ** The most frequent interrupt condition is Phase Mismatch.
5687 ** We should want to service this interrupt quickly.
5688 ** A SCSI parity error may be delivered at the same time.
5689 ** The SIR interrupt is not very frequent in this driver,
5690 ** since the INTFLY is likely used for command completion
5692 ** The Selection Timeout interrupt may be triggered with
5694 ** The SBMC interrupt (SCSI Bus Mode Change) may probably
5695 ** occur at any time.
5697 ** This handler try to deal as cleverly as possible with all
5700 **============================================================
5703 void ncr_exception (struct ncb
*np
)
5705 u_char istat
, dstat
;
5710 ** interrupt on the fly ?
5711 ** Since the global header may be copied back to a CCB
5712 ** using a posted PCI memory write, the last operation on
5713 ** the istat register is a READ in order to flush posted
5714 ** PCI write commands.
5716 istat
= INB (nc_istat
);
5718 OUTB (nc_istat
, (istat
& SIGP
) | INTF
);
5719 istat
= INB (nc_istat
);
5720 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("F ");
5721 ncr_wakeup_done (np
);
5724 if (!(istat
& (SIP
|DIP
)))
5728 OUTB (nc_istat
, CABRT
);
5731 ** Steinbach's Guideline for Systems Programming:
5732 ** Never test for an error condition you don't know how to handle.
5735 sist
= (istat
& SIP
) ? INW (nc_sist
) : 0;
5736 dstat
= (istat
& DIP
) ? INB (nc_dstat
) : 0;
5738 if (DEBUG_FLAGS
& DEBUG_TINY
)
5739 printk ("<%d|%x:%x|%x:%x>",
5742 (unsigned)INL(nc_dsp
),
5743 (unsigned)INL(nc_dbc
));
5745 /*========================================================
5746 ** First, interrupts we want to service cleanly.
5748 ** Phase mismatch is the most frequent interrupt, and
5749 ** so we have to service it as quickly and as cleanly
5751 ** Programmed interrupts are rarely used in this driver,
5752 ** but we must handle them cleanly anyway.
5753 ** We try to deal with PAR and SBMC combined with
5754 ** some other interrupt(s).
5755 **=========================================================
5758 if (!(sist
& (STO
|GEN
|HTH
|SGE
|UDC
|RST
)) &&
5759 !(dstat
& (MDPE
|BF
|ABRT
|IID
))) {
5760 if ((sist
& SBMC
) && ncr_int_sbmc (np
))
5762 if ((sist
& PAR
) && ncr_int_par (np
))
5773 ** DEL 397 - 53C875 Rev 3 - Part Number 609-0392410 - ITEM 2.
5775 if (!(sist
& (SBMC
|PAR
)) && !(dstat
& SSI
)) {
5776 printk( "%s: unknown interrupt(s) ignored, "
5777 "ISTAT=%x DSTAT=%x SIST=%x\n",
5778 ncr_name(np
), istat
, dstat
, sist
);
5785 /*========================================================
5786 ** Now, interrupts that need some fixing up.
5787 ** Order and multiple interrupts is so less important.
5789 ** If SRST has been asserted, we just reset the chip.
5791 ** Selection is intirely handled by the chip. If the
5792 ** chip says STO, we trust it. Seems some other
5793 ** interrupts may occur at the same time (UDC, IID), so
5794 ** we ignore them. In any case we do enough fix-up
5795 ** in the service routine.
5796 ** We just exclude some fatal dma errors.
5797 **=========================================================
5801 ncr_init (np
, 1, bootverbose
? "scsi reset" : NULL
, HS_RESET
);
5806 !(dstat
& (MDPE
|BF
|ABRT
))) {
5808 ** DEL 397 - 53C875 Rev 3 - Part Number 609-0392410 - ITEM 1.
5810 OUTONB (nc_ctest3
, CLF
);
5816 /*=========================================================
5817 ** Now, interrupts we are not able to recover cleanly.
5818 ** (At least for the moment).
5820 ** Do the register dump.
5821 ** Log message for real hard errors.
5823 ** For MDPE, BF, ABORT, IID, SGE and HTH we reset the
5824 ** BUS and the chip.
5825 ** We are more soft for UDC.
5826 **=========================================================
5829 if (ktime_exp(np
->regtime
)) {
5830 np
->regtime
= ktime_get(10*HZ
);
5831 for (i
= 0; i
<sizeof(np
->regdump
); i
++)
5832 ((char*)&np
->regdump
)[i
] = INB_OFF(i
);
5833 np
->regdump
.nc_dstat
= dstat
;
5834 np
->regdump
.nc_sist
= sist
;
5837 ncr_log_hard_error(np
, sist
, dstat
);
5839 printk ("%s: have to clear fifos.\n", ncr_name (np
));
5840 OUTB (nc_stest3
, TE
|CSF
);
5841 OUTONB (nc_ctest3
, CLF
);
5843 if ((sist
& (SGE
)) ||
5844 (dstat
& (MDPE
|BF
|ABRT
|IID
))) {
5845 ncr_start_reset(np
);
5850 printk ("%s: handshake timeout\n", ncr_name(np
));
5851 ncr_start_reset(np
);
5856 printk ("%s: unexpected disconnect\n", ncr_name(np
));
5857 OUTB (HS_PRT
, HS_UNEXPECTED
);
5858 OUTL_DSP (NCB_SCRIPT_PHYS (np
, cleanup
));
5862 /*=========================================================
5863 ** We just miss the cause of the interrupt. :(
5864 ** Print a message. The timeout will do the real work.
5865 **=========================================================
5867 printk ("%s: unknown interrupt\n", ncr_name(np
));
5870 /*==========================================================
5872 ** ncr chip exception handler for selection timeout
5874 **==========================================================
5876 ** There seems to be a bug in the 53c810.
5877 ** Although a STO-Interrupt is pending,
5878 ** it continues executing script commands.
5879 ** But it will fail and interrupt (IID) on
5880 ** the next instruction where it's looking
5881 ** for a valid phase.
5883 **----------------------------------------------------------
5886 void ncr_int_sto (struct ncb
*np
)
5890 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("T");
5893 ** look for ccb and set the status.
5898 while (cp
&& (CCB_PHYS (cp
, phys
) != dsa
))
5902 cp
-> host_status
= HS_SEL_TIMEOUT
;
5903 ncr_complete (np
, cp
);
5907 ** repair start queue and jump to start point.
5910 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, sto_restart
));
5914 /*==========================================================
5916 ** ncr chip exception handler for SCSI bus mode change
5918 **==========================================================
5920 ** spi2-r12 11.2.3 says a transceiver mode change must
5921 ** generate a reset event and a device that detects a reset
5922 ** event shall initiate a hard reset. It says also that a
5923 ** device that detects a mode change shall set data transfer
5924 ** mode to eight bit asynchronous, etc...
5925 ** So, just resetting should be enough.
5928 **----------------------------------------------------------
5931 static int ncr_int_sbmc (struct ncb
*np
)
5933 u_char scsi_mode
= INB (nc_stest4
) & SMODE
;
5935 if (scsi_mode
!= np
->scsi_mode
) {
5936 printk("%s: SCSI bus mode change from %x to %x.\n",
5937 ncr_name(np
), np
->scsi_mode
, scsi_mode
);
5939 np
->scsi_mode
= scsi_mode
;
5943 ** Suspend command processing for 1 second and
5944 ** reinitialize all except the chip.
5946 np
->settle_time
= ktime_get(1*HZ
);
5947 ncr_init (np
, 0, bootverbose
? "scsi mode change" : NULL
, HS_RESET
);
5953 /*==========================================================
5955 ** ncr chip exception handler for SCSI parity error.
5957 **==========================================================
5960 **----------------------------------------------------------
5963 static int ncr_int_par (struct ncb
*np
)
5965 u_char hsts
= INB (HS_PRT
);
5966 u32 dbc
= INL (nc_dbc
);
5967 u_char sstat1
= INB (nc_sstat1
);
5972 printk("%s: SCSI parity error detected: SCR1=%d DBC=%x SSTAT1=%x\n",
5973 ncr_name(np
), hsts
, dbc
, sstat1
);
5976 * Ignore the interrupt if the NCR is not connected
5977 * to the SCSI bus, since the right work should have
5978 * been done on unexpected disconnection handling.
5980 if (!(INB (nc_scntl1
) & ISCON
))
5984 * If the nexus is not clearly identified, reset the bus.
5985 * We will try to do better later.
5987 if (hsts
& HS_INVALMASK
)
5991 * If the SCSI parity error occurs in MSG IN phase, prepare a
5992 * MSG PARITY message. Otherwise, prepare a INITIATOR DETECTED
5993 * ERROR message and let the device decide to retry the command
5994 * or to terminate with check condition. If we were in MSG IN
5995 * phase waiting for the response of a negotiation, we will
5996 * get SIR_NEGO_FAILED at dispatch.
5998 if (!(dbc
& 0xc0000000))
5999 phase
= (dbc
>> 24) & 7;
6005 #ifdef SCSI_NCR_INTEGRITY_CHECKING
6007 ** Save error message. For integrity check use only.
6009 if (np
->check_integrity
)
6010 np
->check_integ_par
= msg
;
6014 * If the NCR stopped on a MOVE ^ DATA_IN, we jump to a
6015 * script that will ignore all data in bytes until phase
6016 * change, since we are not sure the chip will wait the phase
6017 * change prior to delivering the interrupt.
6020 jmp
= NCB_SCRIPTH_PHYS (np
, par_err_data_in
);
6022 jmp
= NCB_SCRIPTH_PHYS (np
, par_err_other
);
6024 OUTONB (nc_ctest3
, CLF
); /* clear dma fifo */
6025 OUTB (nc_stest3
, TE
|CSF
); /* clear scsi fifo */
6027 np
->msgout
[0] = msg
;
6032 ncr_start_reset(np
);
6036 /*==========================================================
6039 ** ncr chip exception handler for phase errors.
6042 **==========================================================
6044 ** We have to construct a new transfer descriptor,
6045 ** to transfer the rest of the current block.
6047 **----------------------------------------------------------
6050 static void ncr_int_ma (struct ncb
*np
)
6067 sbcl
= INB (nc_sbcl
);
6070 rest
= dbc
& 0xffffff;
6073 ** Take into account dma fifo and various buffers and latches,
6074 ** only if the interrupted phase is an OUTPUT phase.
6077 if ((cmd
& 1) == 0) {
6078 u_char ctest5
, ss0
, ss2
;
6081 ctest5
= (np
->rv_ctest5
& DFS
) ? INB (nc_ctest5
) : 0;
6083 delta
=(((ctest5
<< 8) | (INB (nc_dfifo
) & 0xff)) - rest
) & 0x3ff;
6085 delta
=(INB (nc_dfifo
) - rest
) & 0x7f;
6088 ** The data in the dma fifo has not been transferred to
6089 ** the target -> add the amount to the rest
6090 ** and clear the data.
6091 ** Check the sstat2 register in case of wide transfer.
6095 ss0
= INB (nc_sstat0
);
6096 if (ss0
& OLF
) rest
++;
6097 if (ss0
& ORF
) rest
++;
6098 if (INB(nc_scntl3
) & EWS
) {
6099 ss2
= INB (nc_sstat2
);
6100 if (ss2
& OLF1
) rest
++;
6101 if (ss2
& ORF1
) rest
++;
6104 if (DEBUG_FLAGS
& (DEBUG_TINY
|DEBUG_PHASE
))
6105 printk ("P%x%x RL=%d D=%d SS0=%x ", cmd
&7, sbcl
&7,
6106 (unsigned) rest
, (unsigned) delta
, ss0
);
6109 if (DEBUG_FLAGS
& (DEBUG_TINY
|DEBUG_PHASE
))
6110 printk ("P%x%x RL=%d ", cmd
&7, sbcl
&7, rest
);
6116 OUTONB (nc_ctest3
, CLF
); /* clear dma fifo */
6117 OUTB (nc_stest3
, TE
|CSF
); /* clear scsi fifo */
6120 ** locate matching cp.
6121 ** if the interrupted phase is DATA IN or DATA OUT,
6122 ** trust the global header.
6127 if (CCB_PHYS(cp
, phys
) != dsa
)
6131 while (cp
&& (CCB_PHYS (cp
, phys
) != dsa
))
6136 ** try to find the interrupted script command,
6137 ** and the address at which to continue.
6141 if (dsp
> np
->p_script
&&
6142 dsp
<= np
->p_script
+ sizeof(struct script
)) {
6143 vdsp
= (u32
*)((char*)np
->script0
+ (dsp
-np
->p_script
-8));
6146 else if (dsp
> np
->p_scripth
&&
6147 dsp
<= np
->p_scripth
+ sizeof(struct scripth
)) {
6148 vdsp
= (u32
*)((char*)np
->scripth0
+ (dsp
-np
->p_scripth
-8));
6152 if (dsp
== CCB_PHYS (cp
, patch
[2])) {
6153 vdsp
= &cp
->patch
[0];
6154 nxtdsp
= scr_to_cpu(vdsp
[3]);
6156 else if (dsp
== CCB_PHYS (cp
, patch
[6])) {
6157 vdsp
= &cp
->patch
[4];
6158 nxtdsp
= scr_to_cpu(vdsp
[3]);
6163 ** log the information
6166 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
6167 printk ("\nCP=%p CP2=%p DSP=%x NXT=%x VDSP=%p CMD=%x ",
6170 (unsigned)nxtdsp
, vdsp
, cmd
);
6174 ** cp=0 means that the DSA does not point to a valid control
6175 ** block. This should not happen since we donnot use multi-byte
6176 ** move while we are being reselected ot after command complete.
6177 ** We are not able to recover from such a phase error.
6180 printk ("%s: SCSI phase error fixup: "
6181 "CCB already dequeued (0x%08lx)\n",
6182 ncr_name (np
), (u_long
) np
->header
.cp
);
6187 ** get old startaddress and old length.
6190 oadr
= scr_to_cpu(vdsp
[1]);
6192 if (cmd
& 0x10) { /* Table indirect */
6193 tblp
= (u32
*) ((char*) &cp
->phys
+ oadr
);
6194 olen
= scr_to_cpu(tblp
[0]);
6195 oadr
= scr_to_cpu(tblp
[1]);
6198 olen
= scr_to_cpu(vdsp
[0]) & 0xffffff;
6201 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
6202 printk ("OCMD=%x\nTBLP=%p OLEN=%x OADR=%x\n",
6203 (unsigned) (scr_to_cpu(vdsp
[0]) >> 24),
6210 ** check cmd against assumed interrupted script command.
6213 if (cmd
!= (scr_to_cpu(vdsp
[0]) >> 24)) {
6214 PRINT_ADDR(cp
->cmd
);
6215 printk ("internal error: cmd=%02x != %02x=(vdsp[0] >> 24)\n",
6216 (unsigned)cmd
, (unsigned)scr_to_cpu(vdsp
[0]) >> 24);
6222 ** cp != np->header.cp means that the header of the CCB
6223 ** currently being processed has not yet been copied to
6224 ** the global header area. That may happen if the device did
6225 ** not accept all our messages after having been selected.
6227 if (cp
!= np
->header
.cp
) {
6228 printk ("%s: SCSI phase error fixup: "
6229 "CCB address mismatch (0x%08lx != 0x%08lx)\n",
6230 ncr_name (np
), (u_long
) cp
, (u_long
) np
->header
.cp
);
6234 ** if old phase not dataphase, leave here.
6238 PRINT_ADDR(cp
->cmd
);
6239 printk ("phase change %x-%x %d@%08x resid=%d.\n",
6240 cmd
&7, sbcl
&7, (unsigned)olen
,
6241 (unsigned)oadr
, (unsigned)rest
);
6242 goto unexpected_phase
;
6246 ** choose the correct patch area.
6247 ** if savep points to one, choose the other.
6251 newtmp
= CCB_PHYS (cp
, patch
);
6252 if (newtmp
== scr_to_cpu(cp
->phys
.header
.savep
)) {
6253 newcmd
= &cp
->patch
[4];
6254 newtmp
= CCB_PHYS (cp
, patch
[4]);
6258 ** fillin the commands
6261 newcmd
[0] = cpu_to_scr(((cmd
& 0x0f) << 24) | rest
);
6262 newcmd
[1] = cpu_to_scr(oadr
+ olen
- rest
);
6263 newcmd
[2] = cpu_to_scr(SCR_JUMP
);
6264 newcmd
[3] = cpu_to_scr(nxtdsp
);
6266 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
6267 PRINT_ADDR(cp
->cmd
);
6268 printk ("newcmd[%d] %x %x %x %x.\n",
6269 (int) (newcmd
- cp
->patch
),
6270 (unsigned)scr_to_cpu(newcmd
[0]),
6271 (unsigned)scr_to_cpu(newcmd
[1]),
6272 (unsigned)scr_to_cpu(newcmd
[2]),
6273 (unsigned)scr_to_cpu(newcmd
[3]));
6276 ** fake the return address (to the patch).
6277 ** and restart script processor at dispatcher.
6279 OUTL (nc_temp
, newtmp
);
6280 OUTL_DSP (NCB_SCRIPT_PHYS (np
, dispatch
));
6284 ** Unexpected phase changes that occurs when the current phase
6285 ** is not a DATA IN or DATA OUT phase are due to error conditions.
6286 ** Such event may only happen when the SCRIPTS is using a
6287 ** multibyte SCSI MOVE.
6289 ** Phase change Some possible cause
6291 ** COMMAND --> MSG IN SCSI parity error detected by target.
6292 ** COMMAND --> STATUS Bad command or refused by target.
6293 ** MSG OUT --> MSG IN Message rejected by target.
6294 ** MSG OUT --> COMMAND Bogus target that discards extended
6295 ** negotiation messages.
6297 ** The code below does not care of the new phase and so
6298 ** trusts the target. Why to annoy it ?
6299 ** If the interrupted phase is COMMAND phase, we restart at
6301 ** If a target does not get all the messages after selection,
6302 ** the code assumes blindly that the target discards extended
6303 ** messages and clears the negotiation status.
6304 ** If the target does not want all our response to negotiation,
6305 ** we force a SIR_NEGO_PROTO interrupt (it is a hack that avoids
6306 ** bloat for such a should_not_happen situation).
6307 ** In all other situation, we reset the BUS.
6308 ** Are these assumptions reasonnable ? (Wait and see ...)
6315 case 2: /* COMMAND phase */
6316 nxtdsp
= NCB_SCRIPT_PHYS (np
, dispatch
);
6319 case 3: /* STATUS phase */
6320 nxtdsp
= NCB_SCRIPT_PHYS (np
, dispatch
);
6323 case 6: /* MSG OUT phase */
6324 np
->scripth
->nxtdsp_go_on
[0] = cpu_to_scr(dsp
+ 8);
6325 if (dsp
== NCB_SCRIPT_PHYS (np
, send_ident
)) {
6326 cp
->host_status
= HS_BUSY
;
6327 nxtdsp
= NCB_SCRIPTH_PHYS (np
, clratn_go_on
);
6329 else if (dsp
== NCB_SCRIPTH_PHYS (np
, send_wdtr
) ||
6330 dsp
== NCB_SCRIPTH_PHYS (np
, send_sdtr
)) {
6331 nxtdsp
= NCB_SCRIPTH_PHYS (np
, nego_bad_phase
);
6335 case 7: /* MSG IN phase */
6336 nxtdsp
= NCB_SCRIPT_PHYS (np
, clrack
);
6347 ncr_start_reset(np
);
6351 static void ncr_sir_to_redo(struct ncb
*np
, int num
, struct ccb
*cp
)
6353 struct scsi_cmnd
*cmd
= cp
->cmd
;
6354 struct tcb
*tp
= &np
->target
[cmd
->device
->id
];
6355 struct lcb
*lp
= tp
->lp
[cmd
->device
->lun
];
6361 u_char s_status
= INB (SS_PRT
);
6364 ** Let the SCRIPTS processor skip all not yet started CCBs,
6365 ** and count disconnected CCBs. Since the busy queue is in
6366 ** the same order as the chip start queue, disconnected CCBs
6367 ** are before cp and busy ones after.
6370 qp
= lp
->busy_ccbq
.blink
;
6371 while (qp
!= &lp
->busy_ccbq
) {
6372 cp2
= xpt_que_entry(qp
, struct ccb
, link_ccbq
);
6377 cp2
->start
.schedule
.l_paddr
=
6378 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, skip
));
6380 lp
->held_ccb
= cp
; /* Requeue when this one completes */
6381 disc_cnt
= lp
->queuedccbs
- busy_cnt
;
6385 default: /* Just for safety, should never happen */
6388 ** Decrease number of tags to the number of
6389 ** disconnected commands.
6393 if (bootverbose
>= 1) {
6395 printk ("QUEUE FULL! %d busy, %d disconnected CCBs\n",
6396 busy_cnt
, disc_cnt
);
6398 if (disc_cnt
< lp
->numtags
) {
6399 lp
->numtags
= disc_cnt
> 2 ? disc_cnt
: 2;
6401 ncr_setup_tags (np
, cmd
->device
->id
, cmd
->device
->lun
);
6404 ** Requeue the command to the start queue.
6405 ** If any disconnected commands,
6407 ** Jump to reselect.
6409 cp
->phys
.header
.savep
= cp
->startp
;
6410 cp
->host_status
= HS_BUSY
;
6411 cp
->scsi_status
= S_ILLEGAL
;
6413 ncr_put_start_queue(np
, cp
);
6415 INB (nc_ctest2
); /* Clear SIGP */
6416 OUTL_DSP (NCB_SCRIPT_PHYS (np
, reselect
));
6421 ** If we were requesting sense, give up.
6427 ** Device returned CHECK CONDITION status.
6428 ** Prepare all needed data strutures for getting
6433 cp
->scsi_smsg2
[0] = M_IDENTIFY
| cmd
->device
->lun
;
6434 cp
->phys
.smsg
.addr
= cpu_to_scr(CCB_PHYS (cp
, scsi_smsg2
));
6435 cp
->phys
.smsg
.size
= cpu_to_scr(1);
6440 cp
->phys
.cmd
.addr
= cpu_to_scr(CCB_PHYS (cp
, sensecmd
));
6441 cp
->phys
.cmd
.size
= cpu_to_scr(6);
6444 ** patch requested size into sense command
6446 cp
->sensecmd
[0] = 0x03;
6447 cp
->sensecmd
[1] = cmd
->device
->lun
<< 5;
6448 cp
->sensecmd
[4] = sizeof(cp
->sense_buf
);
6453 bzero(cp
->sense_buf
, sizeof(cp
->sense_buf
));
6454 cp
->phys
.sense
.addr
= cpu_to_scr(CCB_PHYS(cp
,sense_buf
[0]));
6455 cp
->phys
.sense
.size
= cpu_to_scr(sizeof(cp
->sense_buf
));
6458 ** requeue the command.
6460 startp
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, sdata_in
));
6462 cp
->phys
.header
.savep
= startp
;
6463 cp
->phys
.header
.goalp
= startp
+ 24;
6464 cp
->phys
.header
.lastp
= startp
;
6465 cp
->phys
.header
.wgoalp
= startp
+ 24;
6466 cp
->phys
.header
.wlastp
= startp
;
6468 cp
->host_status
= HS_BUSY
;
6469 cp
->scsi_status
= S_ILLEGAL
;
6470 cp
->auto_sense
= s_status
;
6472 cp
->start
.schedule
.l_paddr
=
6473 cpu_to_scr(NCB_SCRIPT_PHYS (np
, select
));
6476 ** Select without ATN for quirky devices.
6478 if (tp
->quirks
& QUIRK_NOMSG
)
6479 cp
->start
.schedule
.l_paddr
=
6480 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, select_no_atn
));
6482 ncr_put_start_queue(np
, cp
);
6484 OUTL_DSP (NCB_SCRIPT_PHYS (np
, start
));
6494 /*==========================================================
6497 ** ncr chip exception handler for programmed interrupts.
6500 **==========================================================
6503 static int ncr_show_msg (u_char
* msg
)
6507 if (*msg
==M_EXTENDED
) {
6509 if (i
-1>msg
[1]) break;
6510 printk ("-%x",msg
[i
]);
6513 } else if ((*msg
& 0xf0) == 0x20) {
6514 printk ("-%x",msg
[1]);
6520 static void ncr_print_msg ( struct ccb
*cp
, char *label
, u_char
*msg
)
6523 PRINT_ADDR(cp
->cmd
);
6525 printk("%s: ", label
);
6527 (void) ncr_show_msg (msg
);
6531 void ncr_int_sir (struct ncb
*np
)
6534 u_char chg
, ofs
, per
, fak
, wide
;
6535 u_char num
= INB (nc_dsps
);
6536 struct ccb
*cp
=NULL
;
6537 u_long dsa
= INL (nc_dsa
);
6538 u_char target
= INB (nc_sdid
) & 0x0f;
6539 struct tcb
*tp
= &np
->target
[target
];
6541 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("I#%d", num
);
6546 ** This is used for HP Zalon/53c720 where INTFLY
6547 ** operation is currently broken.
6549 ncr_wakeup_done(np
);
6550 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
6551 OUTL(nc_dsp
, NCB_SCRIPT_PHYS (np
, done_end
) + 8);
6553 OUTL(nc_dsp
, NCB_SCRIPT_PHYS (np
, start
));
6556 case SIR_RESEL_NO_MSG_IN
:
6557 case SIR_RESEL_NO_IDENTIFY
:
6559 ** If devices reselecting without sending an IDENTIFY
6560 ** message still exist, this should help.
6561 ** We just assume lun=0, 1 CCB, no tag.
6564 OUTL_DSP (scr_to_cpu(tp
->lp
[0]->jump_ccb
[0]));
6567 case SIR_RESEL_BAD_TARGET
: /* Will send a TARGET RESET message */
6568 case SIR_RESEL_BAD_LUN
: /* Will send a TARGET RESET message */
6569 case SIR_RESEL_BAD_I_T_L_Q
: /* Will send an ABORT TAG message */
6570 case SIR_RESEL_BAD_I_T_L
: /* Will send an ABORT message */
6571 printk ("%s:%d: SIR %d, "
6572 "incorrect nexus identification on reselection\n",
6573 ncr_name (np
), target
, num
);
6575 case SIR_DONE_OVERFLOW
:
6576 printk ("%s:%d: SIR %d, "
6577 "CCB done queue overflow\n",
6578 ncr_name (np
), target
, num
);
6580 case SIR_BAD_STATUS
:
6582 if (!cp
|| CCB_PHYS (cp
, phys
) != dsa
)
6584 ncr_sir_to_redo(np
, num
, cp
);
6591 while (cp
&& (CCB_PHYS (cp
, phys
) != dsa
))
6594 assert (cp
&& cp
== np
->header
.cp
);
6596 if (!cp
|| cp
!= np
->header
.cp
)
6601 /*-----------------------------------------------------------------------------
6603 ** Was Sie schon immer ueber transfermode negotiation wissen wollten ...
6605 ** We try to negotiate sync and wide transfer only after
6606 ** a successful inquire command. We look at byte 7 of the
6607 ** inquire data to determine the capabilities of the target.
6609 ** When we try to negotiate, we append the negotiation message
6610 ** to the identify and (maybe) simple tag message.
6611 ** The host status field is set to HS_NEGOTIATE to mark this
6614 ** If the target doesn't answer this message immidiately
6615 ** (as required by the standard), the SIR_NEGO_FAIL interrupt
6616 ** will be raised eventually.
6617 ** The handler removes the HS_NEGOTIATE status, and sets the
6618 ** negotiated value to the default (async / nowide).
6620 ** If we receive a matching answer immediately, we check it
6621 ** for validity, and set the values.
6623 ** If we receive a Reject message immediately, we assume the
6624 ** negotiation has failed, and fall back to standard values.
6626 ** If we receive a negotiation message while not in HS_NEGOTIATE
6627 ** state, it's a target initiated negotiation. We prepare a
6628 ** (hopefully) valid answer, set our parameters, and send back
6629 ** this answer to the target.
6631 ** If the target doesn't fetch the answer (no message out phase),
6632 ** we assume the negotiation has failed, and fall back to default
6635 ** When we set the values, we adjust them in all ccbs belonging
6636 ** to this target, in the controller's register, and in the "phys"
6637 ** field of the controller's struct ncb.
6639 ** Possible cases: hs sir msg_in value send goto
6640 ** We try to negotiate:
6641 ** -> target doesn't msgin NEG FAIL noop defa. - dispatch
6642 ** -> target rejected our msg NEG FAIL reject defa. - dispatch
6643 ** -> target answered (ok) NEG SYNC sdtr set - clrack
6644 ** -> target answered (!ok) NEG SYNC sdtr defa. REJ--->msg_bad
6645 ** -> target answered (ok) NEG WIDE wdtr set - clrack
6646 ** -> target answered (!ok) NEG WIDE wdtr defa. REJ--->msg_bad
6647 ** -> any other msgin NEG FAIL noop defa. - dispatch
6649 ** Target tries to negotiate:
6650 ** -> incoming message --- SYNC sdtr set SDTR -
6651 ** -> incoming message --- WIDE wdtr set WDTR -
6652 ** We sent our answer:
6653 ** -> target doesn't msgout --- PROTO ? defa. - dispatch
6655 **-----------------------------------------------------------------------------
6658 case SIR_NEGO_FAILED
:
6659 /*-------------------------------------------------------
6661 ** Negotiation failed.
6662 ** Target doesn't send an answer message,
6663 ** or target rejected our message.
6665 ** Remove negotiation request.
6667 **-------------------------------------------------------
6669 OUTB (HS_PRT
, HS_BUSY
);
6673 case SIR_NEGO_PROTO
:
6674 /*-------------------------------------------------------
6676 ** Negotiation failed.
6677 ** Target doesn't fetch the answer message.
6679 **-------------------------------------------------------
6682 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6683 PRINT_ADDR(cp
->cmd
);
6684 printk ("negotiation failed sir=%x status=%x.\n",
6685 num
, cp
->nego_status
);
6689 ** any error in negotiation:
6690 ** fall back to default mode.
6692 switch (cp
->nego_status
) {
6695 ncr_setsync (np
, cp
, 0, 0xe0);
6699 ncr_setwide (np
, cp
, 0, 0);
6703 np
->msgin
[0] = M_NOOP
;
6704 np
->msgout
[0] = M_NOOP
;
6705 cp
->nego_status
= 0;
6710 ** Synchronous request message received.
6713 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6714 PRINT_ADDR(cp
->cmd
);
6715 printk ("sync msgin: ");
6716 (void) ncr_show_msg (np
->msgin
);
6721 ** get requested values.
6727 if (ofs
==0) per
=255;
6730 ** if target sends SDTR message,
6731 ** it CAN transfer synch.
6735 tp
->inq_byte7
|= INQ7_SYNC
;
6738 ** check values against driver limits.
6741 if (per
< np
->minsync
)
6742 {chg
= 1; per
= np
->minsync
;}
6743 if (per
< tp
->minsync
)
6744 {chg
= 1; per
= tp
->minsync
;}
6745 if (ofs
> tp
->maxoffs
)
6746 {chg
= 1; ofs
= tp
->maxoffs
;}
6749 ** Check against controller limits.
6754 ncr_getsync(np
, per
, &fak
, &scntl3
);
6767 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6768 PRINT_ADDR(cp
->cmd
);
6769 printk ("sync: per=%d scntl3=0x%x ofs=%d fak=%d chg=%d.\n",
6770 per
, scntl3
, ofs
, fak
, chg
);
6773 if (INB (HS_PRT
) == HS_NEGOTIATE
) {
6774 OUTB (HS_PRT
, HS_BUSY
);
6775 switch (cp
->nego_status
) {
6779 ** This was an answer message
6783 ** Answer wasn't acceptable.
6785 ncr_setsync (np
, cp
, 0, 0xe0);
6786 OUTL_DSP (NCB_SCRIPT_PHYS (np
, msg_bad
));
6791 ncr_setsync (np
, cp
, scntl3
, (fak
<<5)|ofs
);
6792 OUTL_DSP (NCB_SCRIPT_PHYS (np
, clrack
));
6797 ncr_setwide (np
, cp
, 0, 0);
6803 ** It was a request. Set value and
6804 ** prepare an answer message
6807 ncr_setsync (np
, cp
, scntl3
, (fak
<<5)|ofs
);
6809 np
->msgout
[0] = M_EXTENDED
;
6811 np
->msgout
[2] = M_X_SYNC_REQ
;
6812 np
->msgout
[3] = per
;
6813 np
->msgout
[4] = ofs
;
6815 cp
->nego_status
= NS_SYNC
;
6817 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6818 PRINT_ADDR(cp
->cmd
);
6819 printk ("sync msgout: ");
6820 (void) ncr_show_msg (np
->msgout
);
6825 OUTL_DSP (NCB_SCRIPT_PHYS (np
, msg_bad
));
6828 np
->msgin
[0] = M_NOOP
;
6834 ** Wide request message received.
6836 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6837 PRINT_ADDR(cp
->cmd
);
6838 printk ("wide msgin: ");
6839 (void) ncr_show_msg (np
->msgin
);
6844 ** get requested values.
6848 wide
= np
->msgin
[3];
6851 ** if target sends WDTR message,
6852 ** it CAN transfer wide.
6856 tp
->inq_byte7
|= INQ7_WIDE16
;
6859 ** check values against driver limits.
6862 if (wide
> tp
->usrwide
)
6863 {chg
= 1; wide
= tp
->usrwide
;}
6865 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6866 PRINT_ADDR(cp
->cmd
);
6867 printk ("wide: wide=%d chg=%d.\n", wide
, chg
);
6870 if (INB (HS_PRT
) == HS_NEGOTIATE
) {
6871 OUTB (HS_PRT
, HS_BUSY
);
6872 switch (cp
->nego_status
) {
6876 ** This was an answer message
6880 ** Answer wasn't acceptable.
6882 ncr_setwide (np
, cp
, 0, 1);
6883 OUTL_DSP (NCB_SCRIPT_PHYS (np
, msg_bad
));
6888 ncr_setwide (np
, cp
, wide
, 1);
6889 OUTL_DSP (NCB_SCRIPT_PHYS (np
, clrack
));
6894 ncr_setsync (np
, cp
, 0, 0xe0);
6900 ** It was a request, set value and
6901 ** prepare an answer message
6904 ncr_setwide (np
, cp
, wide
, 1);
6906 np
->msgout
[0] = M_EXTENDED
;
6908 np
->msgout
[2] = M_X_WIDE_REQ
;
6909 np
->msgout
[3] = wide
;
6911 np
->msgin
[0] = M_NOOP
;
6913 cp
->nego_status
= NS_WIDE
;
6915 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6916 PRINT_ADDR(cp
->cmd
);
6917 printk ("wide msgout: ");
6918 (void) ncr_show_msg (np
->msgin
);
6923 /*--------------------------------------------------------------------
6925 ** Processing of special messages
6927 **--------------------------------------------------------------------
6930 case SIR_REJECT_RECEIVED
:
6931 /*-----------------------------------------------
6933 ** We received a M_REJECT message.
6935 **-----------------------------------------------
6938 PRINT_ADDR(cp
->cmd
);
6939 printk ("M_REJECT received (%x:%x).\n",
6940 (unsigned)scr_to_cpu(np
->lastmsg
), np
->msgout
[0]);
6943 case SIR_REJECT_SENT
:
6944 /*-----------------------------------------------
6946 ** We received an unknown message
6948 **-----------------------------------------------
6951 PRINT_ADDR(cp
->cmd
);
6952 printk ("M_REJECT sent for ");
6953 (void) ncr_show_msg (np
->msgin
);
6957 /*--------------------------------------------------------------------
6959 ** Processing of special messages
6961 **--------------------------------------------------------------------
6964 case SIR_IGN_RESIDUE
:
6965 /*-----------------------------------------------
6967 ** We received an IGNORE RESIDUE message,
6968 ** which couldn't be handled by the script.
6970 **-----------------------------------------------
6973 PRINT_ADDR(cp
->cmd
);
6974 printk ("M_IGN_RESIDUE received, but not yet implemented.\n");
6977 case SIR_MISSING_SAVE
:
6978 /*-----------------------------------------------
6980 ** We received an DISCONNECT message,
6981 ** but the datapointer wasn't saved before.
6983 **-----------------------------------------------
6986 PRINT_ADDR(cp
->cmd
);
6987 printk ("M_DISCONNECT received, but datapointer not saved: "
6988 "data=%x save=%x goal=%x.\n",
6989 (unsigned) INL (nc_temp
),
6990 (unsigned) scr_to_cpu(np
->header
.savep
),
6991 (unsigned) scr_to_cpu(np
->header
.goalp
));
7000 /*==========================================================
7003 ** Acquire a control block
7006 **==========================================================
7009 static struct ccb
*ncr_get_ccb (struct ncb
*np
, u_char tn
, u_char ln
)
7011 struct tcb
*tp
= &np
->target
[tn
];
7012 struct lcb
*lp
= tp
->lp
[ln
];
7013 u_char tag
= NO_TAG
;
7014 struct ccb
*cp
= NULL
;
7017 ** Lun structure available ?
7022 ** Keep from using more tags than we can handle.
7024 if (lp
->usetags
&& lp
->busyccbs
>= lp
->maxnxs
)
7028 ** Allocate a new CCB if needed.
7030 if (xpt_que_empty(&lp
->free_ccbq
))
7031 ncr_alloc_ccb(np
, tn
, ln
);
7034 ** Tune tag mode if asked by user.
7036 if (lp
->queuedepth
!= lp
->numtags
) {
7037 ncr_setup_tags(np
, tn
, ln
);
7041 ** Look for free CCB
7043 qp
= xpt_remque_head(&lp
->free_ccbq
);
7045 cp
= xpt_que_entry(qp
, struct ccb
, link_ccbq
);
7047 PRINT_LUN(np
, tn
, ln
);
7048 printk ("ccb free list corrupted (@%p)\n", cp
);
7052 xpt_insque_tail(qp
, &lp
->wait_ccbq
);
7058 ** If a CCB is available,
7059 ** Get a tag for this nexus if required.
7063 tag
= lp
->cb_tags
[lp
->ia_tag
];
7065 else if (lp
->actccbs
> 0)
7070 ** if nothing available, take the default.
7076 ** Wait until available.
7080 if (flags
& SCSI_NOSLEEP
) break;
7081 if (tsleep ((caddr_t
)cp
, PRIBIO
|PCATCH
, "ncr", 0))
7092 ** Move to next available tag if tag used.
7095 if (tag
!= NO_TAG
) {
7097 if (lp
->ia_tag
== MAX_TAGS
)
7099 lp
->tags_umap
|= (((tagmap_t
) 1) << tag
);
7104 ** Remember all informations needed to free this CCB.
7110 if (DEBUG_FLAGS
& DEBUG_TAGS
) {
7111 PRINT_LUN(np
, tn
, ln
);
7112 printk ("ccb @%p using tag %d.\n", cp
, tag
);
7118 /*==========================================================
7121 ** Release one control block
7124 **==========================================================
7127 static void ncr_free_ccb (struct ncb
*np
, struct ccb
*cp
)
7129 struct tcb
*tp
= &np
->target
[cp
->target
];
7130 struct lcb
*lp
= tp
->lp
[cp
->lun
];
7132 if (DEBUG_FLAGS
& DEBUG_TAGS
) {
7133 PRINT_LUN(np
, cp
->target
, cp
->lun
);
7134 printk ("ccb @%p freeing tag %d.\n", cp
, cp
->tag
);
7138 ** If lun control block available,
7139 ** decrement active commands and increment credit,
7140 ** free the tag if any and remove the JUMP for reselect.
7143 if (cp
->tag
!= NO_TAG
) {
7144 lp
->cb_tags
[lp
->if_tag
++] = cp
->tag
;
7145 if (lp
->if_tag
== MAX_TAGS
)
7147 lp
->tags_umap
&= ~(((tagmap_t
) 1) << cp
->tag
);
7148 lp
->tags_smap
&= lp
->tags_umap
;
7149 lp
->jump_ccb
[cp
->tag
] =
7150 cpu_to_scr(NCB_SCRIPTH_PHYS(np
, bad_i_t_l_q
));
7153 cpu_to_scr(NCB_SCRIPTH_PHYS(np
, bad_i_t_l
));
7158 ** Make this CCB available.
7162 if (cp
!= np
->ccb
) {
7163 xpt_remque(&cp
->link_ccbq
);
7164 xpt_insque_head(&cp
->link_ccbq
, &lp
->free_ccbq
);
7171 cp
-> host_status
= HS_IDLE
;
7180 wakeup ((caddr_t
) cp
);
7185 #define ncr_reg_bus_addr(r) (np->paddr + offsetof (struct ncr_reg, r))
7187 /*------------------------------------------------------------------------
7188 ** Initialize the fixed part of a CCB structure.
7189 **------------------------------------------------------------------------
7190 **------------------------------------------------------------------------
7192 static void ncr_init_ccb(struct ncb
*np
, struct ccb
*cp
)
7194 ncrcmd copy_4
= np
->features
& FE_PFEN
? SCR_COPY(4) : SCR_COPY_F(4);
7197 ** Remember virtual and bus address of this ccb.
7199 cp
->p_ccb
= vtobus(cp
);
7200 cp
->phys
.header
.cp
= cp
;
7203 ** This allows xpt_remque to work for the default ccb.
7205 xpt_que_init(&cp
->link_ccbq
);
7208 ** Initialyze the start and restart launch script.
7210 ** COPY(4) @(...p_phys), @(dsa)
7211 ** JUMP @(sched_point)
7213 cp
->start
.setup_dsa
[0] = cpu_to_scr(copy_4
);
7214 cp
->start
.setup_dsa
[1] = cpu_to_scr(CCB_PHYS(cp
, start
.p_phys
));
7215 cp
->start
.setup_dsa
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_dsa
));
7216 cp
->start
.schedule
.l_cmd
= cpu_to_scr(SCR_JUMP
);
7217 cp
->start
.p_phys
= cpu_to_scr(CCB_PHYS(cp
, phys
));
7219 memcpy(&cp
->restart
, &cp
->start
, sizeof(cp
->restart
));
7221 cp
->start
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
7222 cp
->restart
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, abort
));
7226 /*------------------------------------------------------------------------
7227 ** Allocate a CCB and initialize its fixed part.
7228 **------------------------------------------------------------------------
7229 **------------------------------------------------------------------------
7231 static void ncr_alloc_ccb(struct ncb
*np
, u_char tn
, u_char ln
)
7233 struct tcb
*tp
= &np
->target
[tn
];
7234 struct lcb
*lp
= tp
->lp
[ln
];
7235 struct ccb
*cp
= NULL
;
7238 ** Allocate memory for this CCB.
7240 cp
= m_calloc_dma(sizeof(struct ccb
), "CCB");
7245 ** Count it and initialyze it.
7249 bzero (cp
, sizeof (*cp
));
7250 ncr_init_ccb(np
, cp
);
7253 ** Chain into wakeup list and free ccb queue and take it
7254 ** into account for tagged commands.
7256 cp
->link_ccb
= np
->ccb
->link_ccb
;
7257 np
->ccb
->link_ccb
= cp
;
7259 xpt_insque_head(&cp
->link_ccbq
, &lp
->free_ccbq
);
7260 ncr_setup_tags (np
, tn
, ln
);
7263 /*==========================================================
7266 ** Allocation of resources for Targets/Luns/Tags.
7269 **==========================================================
7273 /*------------------------------------------------------------------------
7274 ** Target control block initialisation.
7275 **------------------------------------------------------------------------
7276 ** This data structure is fully initialized after a SCSI command
7277 ** has been successfully completed for this target.
7278 ** It contains a SCRIPT that is called on target reselection.
7279 **------------------------------------------------------------------------
7281 static void ncr_init_tcb (struct ncb
*np
, u_char tn
)
7283 struct tcb
*tp
= &np
->target
[tn
];
7284 ncrcmd copy_1
= np
->features
& FE_PFEN
? SCR_COPY(1) : SCR_COPY_F(1);
7289 ** Jump to next tcb if SFBR does not match this target.
7290 ** JUMP IF (SFBR != #target#), @(next tcb)
7292 tp
->jump_tcb
.l_cmd
=
7293 cpu_to_scr((SCR_JUMP
^ IFFALSE (DATA (0x80 + tn
))));
7294 tp
->jump_tcb
.l_paddr
= np
->jump_tcb
[th
].l_paddr
;
7297 ** Load the synchronous transfer register.
7298 ** COPY @(tp->sval), @(sxfer)
7300 tp
->getscr
[0] = cpu_to_scr(copy_1
);
7301 tp
->getscr
[1] = cpu_to_scr(vtobus (&tp
->sval
));
7302 #ifdef SCSI_NCR_BIG_ENDIAN
7303 tp
->getscr
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_sxfer
) ^ 3);
7305 tp
->getscr
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_sxfer
));
7309 ** Load the timing register.
7310 ** COPY @(tp->wval), @(scntl3)
7312 tp
->getscr
[3] = cpu_to_scr(copy_1
);
7313 tp
->getscr
[4] = cpu_to_scr(vtobus (&tp
->wval
));
7314 #ifdef SCSI_NCR_BIG_ENDIAN
7315 tp
->getscr
[5] = cpu_to_scr(ncr_reg_bus_addr(nc_scntl3
) ^ 3);
7317 tp
->getscr
[5] = cpu_to_scr(ncr_reg_bus_addr(nc_scntl3
));
7321 ** Get the IDENTIFY message and the lun.
7322 ** CALL @script(resel_lun)
7324 tp
->call_lun
.l_cmd
= cpu_to_scr(SCR_CALL
);
7325 tp
->call_lun
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, resel_lun
));
7328 ** Look for the lun control block of this nexus.
7330 ** JUMP ^ IFTRUE (MASK (i, 3)), @(next_lcb)
7332 for (i
= 0 ; i
< 4 ; i
++) {
7333 tp
->jump_lcb
[i
].l_cmd
=
7334 cpu_to_scr((SCR_JUMP
^ IFTRUE (MASK (i
, 3))));
7335 tp
->jump_lcb
[i
].l_paddr
=
7336 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_identify
));
7340 ** Link this target control block to the JUMP chain.
7342 np
->jump_tcb
[th
].l_paddr
= cpu_to_scr(vtobus (&tp
->jump_tcb
));
7345 ** These assert's should be moved at driver initialisations.
7347 #ifdef SCSI_NCR_BIG_ENDIAN
7348 assert (( (offsetof(struct ncr_reg
, nc_sxfer
) ^
7349 offsetof(struct tcb
, sval
)) &3) == 3);
7350 assert (( (offsetof(struct ncr_reg
, nc_scntl3
) ^
7351 offsetof(struct tcb
, wval
)) &3) == 3);
7353 assert (( (offsetof(struct ncr_reg
, nc_sxfer
) ^
7354 offsetof(struct tcb
, sval
)) &3) == 0);
7355 assert (( (offsetof(struct ncr_reg
, nc_scntl3
) ^
7356 offsetof(struct tcb
, wval
)) &3) == 0);
7361 /*------------------------------------------------------------------------
7362 ** Lun control block allocation and initialization.
7363 **------------------------------------------------------------------------
7364 ** This data structure is allocated and initialized after a SCSI
7365 ** command has been successfully completed for this target/lun.
7366 **------------------------------------------------------------------------
7368 static struct lcb
*ncr_alloc_lcb (struct ncb
*np
, u_char tn
, u_char ln
)
7370 struct tcb
*tp
= &np
->target
[tn
];
7371 struct lcb
*lp
= tp
->lp
[ln
];
7372 ncrcmd copy_4
= np
->features
& FE_PFEN
? SCR_COPY(4) : SCR_COPY_F(4);
7376 ** Already done, return.
7382 ** Allocate the lcb.
7384 lp
= m_calloc_dma(sizeof(struct lcb
), "LCB");
7387 bzero(lp
, sizeof(*lp
));
7391 ** Initialize the target control block if not yet.
7393 if (!tp
->jump_tcb
.l_cmd
)
7394 ncr_init_tcb(np
, tn
);
7397 ** Initialize the CCB queue headers.
7399 xpt_que_init(&lp
->free_ccbq
);
7400 xpt_que_init(&lp
->busy_ccbq
);
7401 xpt_que_init(&lp
->wait_ccbq
);
7402 xpt_que_init(&lp
->skip_ccbq
);
7405 ** Set max CCBs to 1 and use the default 1 entry
7406 ** jump table by default.
7409 lp
->jump_ccb
= &lp
->jump_ccb_0
;
7410 lp
->p_jump_ccb
= cpu_to_scr(vtobus(lp
->jump_ccb
));
7413 ** Initilialyze the reselect script:
7415 ** Jump to next lcb if SFBR does not match this lun.
7416 ** Load TEMP with the CCB direct jump table bus address.
7417 ** Get the SIMPLE TAG message and the tag.
7419 ** JUMP IF (SFBR != #lun#), @(next lcb)
7420 ** COPY @(lp->p_jump_ccb), @(temp)
7421 ** JUMP @script(resel_notag)
7423 lp
->jump_lcb
.l_cmd
=
7424 cpu_to_scr((SCR_JUMP
^ IFFALSE (MASK (0x80+ln
, 0xff))));
7425 lp
->jump_lcb
.l_paddr
= tp
->jump_lcb
[lh
].l_paddr
;
7427 lp
->load_jump_ccb
[0] = cpu_to_scr(copy_4
);
7428 lp
->load_jump_ccb
[1] = cpu_to_scr(vtobus (&lp
->p_jump_ccb
));
7429 lp
->load_jump_ccb
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_temp
));
7431 lp
->jump_tag
.l_cmd
= cpu_to_scr(SCR_JUMP
);
7432 lp
->jump_tag
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, resel_notag
));
7435 ** Link this lun control block to the JUMP chain.
7437 tp
->jump_lcb
[lh
].l_paddr
= cpu_to_scr(vtobus (&lp
->jump_lcb
));
7440 ** Initialize command queuing control.
7450 /*------------------------------------------------------------------------
7451 ** Lun control block setup on INQUIRY data received.
7452 **------------------------------------------------------------------------
7453 ** We only support WIDE, SYNC for targets and CMDQ for logical units.
7454 ** This setup is done on each INQUIRY since we are expecting user
7455 ** will play with CHANGE DEFINITION commands. :-)
7456 **------------------------------------------------------------------------
7458 static struct lcb
*ncr_setup_lcb (struct ncb
*np
, u_char tn
, u_char ln
, u_char
*inq_data
)
7460 struct tcb
*tp
= &np
->target
[tn
];
7461 struct lcb
*lp
= tp
->lp
[ln
];
7465 ** If no lcb, try to allocate it.
7467 if (!lp
&& !(lp
= ncr_alloc_lcb(np
, tn
, ln
)))
7471 ** Get device quirks from a speciality table.
7473 tp
->quirks
= ncr_lookup (inq_data
);
7474 if (tp
->quirks
&& bootverbose
) {
7475 PRINT_LUN(np
, tn
, ln
);
7476 printk ("quirks=%x.\n", tp
->quirks
);
7480 ** Evaluate trustable target/unit capabilities.
7481 ** We only believe device version >= SCSI-2 that
7482 ** use appropriate response data format (2).
7483 ** But it seems that some CCS devices also
7484 ** support SYNC and I donnot want to frustrate
7488 if ((inq_data
[2] & 0x7) >= 2 && (inq_data
[3] & 0xf) == 2)
7489 inq_byte7
= inq_data
[7];
7490 else if ((inq_data
[2] & 0x7) == 1 && (inq_data
[3] & 0xf) == 1)
7491 inq_byte7
= INQ7_SYNC
;
7494 ** Throw away announced LUN capabilities if we are told
7495 ** that there is no real device supported by the logical unit.
7497 if ((inq_data
[0] & 0xe0) > 0x20 || (inq_data
[0] & 0x1f) == 0x1f)
7498 inq_byte7
&= (INQ7_SYNC
| INQ7_WIDE16
);
7501 ** If user is wanting SYNC, force this feature.
7503 if (driver_setup
.force_sync_nego
)
7504 inq_byte7
|= INQ7_SYNC
;
7507 ** Prepare negotiation if SIP capabilities have changed.
7510 if ((inq_byte7
^ tp
->inq_byte7
) & (INQ7_SYNC
| INQ7_WIDE16
)) {
7511 tp
->inq_byte7
= inq_byte7
;
7512 ncr_negotiate(np
, tp
);
7516 ** If unit supports tagged commands, allocate the
7517 ** CCB JUMP table if not yet.
7519 if ((inq_byte7
& INQ7_QUEUE
) && lp
->jump_ccb
== &lp
->jump_ccb_0
) {
7521 lp
->jump_ccb
= m_calloc_dma(256, "JUMP_CCB");
7522 if (!lp
->jump_ccb
) {
7523 lp
->jump_ccb
= &lp
->jump_ccb_0
;
7526 lp
->p_jump_ccb
= cpu_to_scr(vtobus(lp
->jump_ccb
));
7527 for (i
= 0 ; i
< 64 ; i
++)
7529 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_i_t_l_q
));
7530 for (i
= 0 ; i
< MAX_TAGS
; i
++)
7532 lp
->maxnxs
= MAX_TAGS
;
7533 lp
->tags_stime
= ktime_get(3*HZ
);
7537 ** Adjust tagged queueing status if needed.
7539 if ((inq_byte7
^ lp
->inq_byte7
) & INQ7_QUEUE
) {
7540 lp
->inq_byte7
= inq_byte7
;
7541 lp
->numtags
= lp
->maxtags
;
7542 ncr_setup_tags (np
, tn
, ln
);
7549 /*==========================================================
7552 ** Build Scatter Gather Block
7555 **==========================================================
7557 ** The transfer area may be scattered among
7558 ** several non adjacent physical pages.
7560 ** We may use MAX_SCATTER blocks.
7562 **----------------------------------------------------------
7566 ** We try to reduce the number of interrupts caused
7567 ** by unexpected phase changes due to disconnects.
7568 ** A typical harddisk may disconnect before ANY block.
7569 ** If we wanted to avoid unexpected phase changes at all
7570 ** we had to use a break point every 512 bytes.
7571 ** Of course the number of scatter/gather blocks is
7573 ** Under Linux, the scatter/gatter blocks are provided by
7574 ** the generic driver. We just have to copy addresses and
7575 ** sizes to the data segment array.
7578 static int ncr_scatter_no_sglist(struct ncb
*np
, struct ccb
*cp
, struct scsi_cmnd
*cmd
)
7580 struct scr_tblmove
*data
= &cp
->phys
.data
[MAX_SCATTER
- 1];
7583 cp
->data_len
= cmd
->request_bufflen
;
7585 if (cmd
->request_bufflen
) {
7586 dma_addr_t baddr
= map_scsi_single_data(np
, cmd
);
7588 ncr_build_sge(np
, data
, baddr
, cmd
->request_bufflen
);
7600 static int ncr_scatter(struct ncb
*np
, struct ccb
*cp
, struct scsi_cmnd
*cmd
)
7603 int use_sg
= (int) cmd
->use_sg
;
7608 segment
= ncr_scatter_no_sglist(np
, cp
, cmd
);
7609 else if ((use_sg
= map_scsi_sg_data(np
, cmd
)) > 0) {
7610 struct scatterlist
*scatter
= (struct scatterlist
*)cmd
->buffer
;
7611 struct scr_tblmove
*data
;
7613 if (use_sg
> MAX_SCATTER
) {
7614 unmap_scsi_data(np
, cmd
);
7618 data
= &cp
->phys
.data
[MAX_SCATTER
- use_sg
];
7620 for (segment
= 0; segment
< use_sg
; segment
++) {
7621 dma_addr_t baddr
= sg_dma_address(&scatter
[segment
]);
7622 unsigned int len
= sg_dma_len(&scatter
[segment
]);
7624 ncr_build_sge(np
, &data
[segment
], baddr
, len
);
7625 cp
->data_len
+= len
;
7634 /*==========================================================
7637 ** Test the bus snoop logic :-(
7639 ** Has to be called with interrupts disabled.
7642 **==========================================================
7645 static int __init
ncr_regtest (struct ncb
* np
)
7647 register volatile u32 data
;
7649 ** ncr registers may NOT be cached.
7650 ** write 0xffffffff to a read only register area,
7651 ** and try to read it back.
7654 OUTL_OFF(offsetof(struct ncr_reg
, nc_dstat
), data
);
7655 data
= INL_OFF(offsetof(struct ncr_reg
, nc_dstat
));
7657 if (data
== 0xffffffff) {
7659 if ((data
& 0xe2f0fffd) != 0x02000080) {
7661 printk ("CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
7668 static int __init
ncr_snooptest (struct ncb
* np
)
7670 u32 ncr_rd
, ncr_wr
, ncr_bk
, host_rd
, host_wr
, pc
;
7673 err
|= ncr_regtest (np
);
7679 pc
= NCB_SCRIPTH_PHYS (np
, snooptest
);
7683 ** Set memory and register.
7685 np
->ncr_cache
= cpu_to_scr(host_wr
);
7686 OUTL (nc_temp
, ncr_wr
);
7688 ** Start script (exchange values)
7692 ** Wait 'til done (with timeout)
7694 for (i
=0; i
<NCR_SNOOP_TIMEOUT
; i
++)
7695 if (INB(nc_istat
) & (INTF
|SIP
|DIP
))
7698 ** Save termination position.
7702 ** Read memory and register.
7704 host_rd
= scr_to_cpu(np
->ncr_cache
);
7705 ncr_rd
= INL (nc_scratcha
);
7706 ncr_bk
= INL (nc_temp
);
7710 ncr_chip_reset(np
, 100);
7712 ** check for timeout
7714 if (i
>=NCR_SNOOP_TIMEOUT
) {
7715 printk ("CACHE TEST FAILED: timeout.\n");
7719 ** Check termination position.
7721 if (pc
!= NCB_SCRIPTH_PHYS (np
, snoopend
)+8) {
7722 printk ("CACHE TEST FAILED: script execution failed.\n");
7723 printk ("start=%08lx, pc=%08lx, end=%08lx\n",
7724 (u_long
) NCB_SCRIPTH_PHYS (np
, snooptest
), (u_long
) pc
,
7725 (u_long
) NCB_SCRIPTH_PHYS (np
, snoopend
) +8);
7731 if (host_wr
!= ncr_rd
) {
7732 printk ("CACHE TEST FAILED: host wrote %d, ncr read %d.\n",
7733 (int) host_wr
, (int) ncr_rd
);
7736 if (host_rd
!= ncr_wr
) {
7737 printk ("CACHE TEST FAILED: ncr wrote %d, host read %d.\n",
7738 (int) ncr_wr
, (int) host_rd
);
7741 if (ncr_bk
!= ncr_wr
) {
7742 printk ("CACHE TEST FAILED: ncr wrote %d, read back %d.\n",
7743 (int) ncr_wr
, (int) ncr_bk
);
7749 /*==========================================================
7754 ** @GENSCSI@ should be integrated to scsiconf.c
7757 **==========================================================
7760 struct table_entry
{
7761 char * manufacturer
;
7767 static struct table_entry device_tab
[] =
7770 {"", "", "", QUIRK_NOMSG
},
7772 {"SONY", "SDT-5000", "3.17", QUIRK_NOMSG
},
7773 {"WangDAT", "Model 2600", "01.7", QUIRK_NOMSG
},
7774 {"WangDAT", "Model 3200", "02.2", QUIRK_NOMSG
},
7775 {"WangDAT", "Model 1300", "02.4", QUIRK_NOMSG
},
7776 {"", "", "", 0} /* catch all: must be last entry. */
7779 static u_long
ncr_lookup(char * id
)
7781 struct table_entry
* p
= device_tab
;
7787 r
= p
->manufacturer
;
7788 while ((c
=*r
++)) if (c
!=*d
++) break;
7793 while ((c
=*r
++)) if (c
!=*d
++) break;
7798 while ((c
=*r
++)) if (c
!=*d
++) break;
7805 /*==========================================================
7807 ** Determine the ncr's clock frequency.
7808 ** This is essential for the negotiation
7809 ** of the synchronous transfer rate.
7811 **==========================================================
7813 ** Note: we have to return the correct value.
7814 ** THERE IS NO SAVE DEFAULT VALUE.
7816 ** Most NCR/SYMBIOS boards are delivered with a 40 Mhz clock.
7817 ** 53C860 and 53C875 rev. 1 support fast20 transfers but
7818 ** do not have a clock doubler and so are provided with a
7819 ** 80 MHz clock. All other fast20 boards incorporate a doubler
7820 ** and so should be delivered with a 40 MHz clock.
7821 ** The future fast40 chips (895/895) use a 40 Mhz base clock
7822 ** and provide a clock quadrupler (160 Mhz). The code below
7823 ** tries to deal as cleverly as possible with all this stuff.
7825 **----------------------------------------------------------
7829 * Select NCR SCSI clock frequency
7831 static void ncr_selectclock(struct ncb
*np
, u_char scntl3
)
7833 if (np
->multiplier
< 2) {
7834 OUTB(nc_scntl3
, scntl3
);
7838 if (bootverbose
>= 2)
7839 printk ("%s: enabling clock multiplier\n", ncr_name(np
));
7841 OUTB(nc_stest1
, DBLEN
); /* Enable clock multiplier */
7842 if (np
->multiplier
> 2) { /* Poll bit 5 of stest4 for quadrupler */
7844 while (!(INB(nc_stest4
) & LCKFRQ
) && --i
> 0)
7847 printk("%s: the chip cannot lock the frequency\n", ncr_name(np
));
7848 } else /* Wait 20 micro-seconds for doubler */
7850 OUTB(nc_stest3
, HSC
); /* Halt the scsi clock */
7851 OUTB(nc_scntl3
, scntl3
);
7852 OUTB(nc_stest1
, (DBLEN
|DBLSEL
));/* Select clock multiplier */
7853 OUTB(nc_stest3
, 0x00); /* Restart scsi clock */
7858 * calculate NCR SCSI clock frequency (in KHz)
7860 static unsigned __init
ncrgetfreq (struct ncb
*np
, int gen
)
7866 * Measure GEN timer delay in order
7867 * to calculate SCSI clock frequency
7869 * This code will never execute too
7870 * many loop iterations (if DELAY is
7871 * reasonably correct). It could get
7872 * too low a delay (too high a freq.)
7873 * if the CPU is slow executing the
7874 * loop for some reason (an NMI, for
7875 * example). For this reason we will
7876 * if multiple measurements are to be
7877 * performed trust the higher delay
7878 * (lower frequency returned).
7880 OUTB (nc_stest1
, 0); /* make sure clock doubler is OFF */
7881 OUTW (nc_sien
, 0); /* mask all scsi interrupts */
7882 (void) INW (nc_sist
); /* clear pending scsi interrupt */
7883 OUTB (nc_dien
, 0); /* mask all dma interrupts */
7884 (void) INW (nc_sist
); /* another one, just to be sure :) */
7885 OUTB (nc_scntl3
, 4); /* set pre-scaler to divide by 3 */
7886 OUTB (nc_stime1
, 0); /* disable general purpose timer */
7887 OUTB (nc_stime1
, gen
); /* set to nominal delay of 1<<gen * 125us */
7888 while (!(INW(nc_sist
) & GEN
) && ms
++ < 100000) {
7889 for (count
= 0; count
< 10; count
++)
7890 UDELAY (100); /* count ms */
7892 OUTB (nc_stime1
, 0); /* disable general purpose timer */
7894 * set prescaler to divide by whatever 0 means
7895 * 0 ought to choose divide by 2, but appears
7896 * to set divide by 3.5 mode in my 53c810 ...
7898 OUTB (nc_scntl3
, 0);
7900 if (bootverbose
>= 2)
7901 printk ("%s: Delay (GEN=%d): %u msec\n", ncr_name(np
), gen
, ms
);
7903 * adjust for prescaler, and convert into KHz
7905 return ms
? ((1 << gen
) * 4340) / ms
: 0;
7909 * Get/probe NCR SCSI clock frequency
7911 static void __init
ncr_getclock (struct ncb
*np
, int mult
)
7913 unsigned char scntl3
= INB(nc_scntl3
);
7914 unsigned char stest1
= INB(nc_stest1
);
7921 ** True with 875 or 895 with clock multiplier selected
7923 if (mult
> 1 && (stest1
& (DBLEN
+DBLSEL
)) == DBLEN
+DBLSEL
) {
7924 if (bootverbose
>= 2)
7925 printk ("%s: clock multiplier found\n", ncr_name(np
));
7926 np
->multiplier
= mult
;
7930 ** If multiplier not found or scntl3 not 7,5,3,
7931 ** reset chip and get frequency from general purpose timer.
7932 ** Otherwise trust scntl3 BIOS setting.
7934 if (np
->multiplier
!= mult
|| (scntl3
& 7) < 3 || !(scntl3
& 1)) {
7937 ncr_chip_reset(np
, 5);
7939 (void) ncrgetfreq (np
, 11); /* throw away first result */
7940 f1
= ncrgetfreq (np
, 11);
7941 f2
= ncrgetfreq (np
, 11);
7944 printk ("%s: NCR clock is %uKHz, %uKHz\n", ncr_name(np
), f1
, f2
);
7946 if (f1
> f2
) f1
= f2
; /* trust lower result */
7948 if (f1
< 45000) f1
= 40000;
7949 else if (f1
< 55000) f1
= 50000;
7952 if (f1
< 80000 && mult
> 1) {
7953 if (bootverbose
>= 2)
7954 printk ("%s: clock multiplier assumed\n", ncr_name(np
));
7955 np
->multiplier
= mult
;
7958 if ((scntl3
& 7) == 3) f1
= 40000;
7959 else if ((scntl3
& 7) == 5) f1
= 80000;
7962 f1
/= np
->multiplier
;
7966 ** Compute controller synchronous parameters.
7968 f1
*= np
->multiplier
;
7972 /*===================== LINUX ENTRY POINTS SECTION ==========================*/
7975 ** Linux select queue depths function
7978 int ncr53c8xx_slave_configure(struct scsi_device
*device
)
7980 struct Scsi_Host
*host
= device
->host
;
7984 int numtags
, depth_to_use
;
7986 np
= ((struct host_data
*) host
->hostdata
)->ncb
;
7987 tp
= &np
->target
[device
->id
];
7988 lp
= tp
->lp
[device
->lun
];
7991 ** Select queue depth from driver setup.
7992 ** Donnot use more than configured by user.
7994 ** Donnot use more than our maximum.
7996 numtags
= device_queue_depth(np
->unit
, device
->id
, device
->lun
);
7997 if (numtags
> tp
->usrtags
)
7998 numtags
= tp
->usrtags
;
7999 if (!device
->tagged_supported
)
8001 depth_to_use
= numtags
;
8002 if (depth_to_use
< 2)
8004 if (depth_to_use
> MAX_TAGS
)
8005 depth_to_use
= MAX_TAGS
;
8007 scsi_adjust_queue_depth(device
,
8008 (device
->tagged_supported
?
8009 MSG_SIMPLE_TAG
: 0),
8013 ** Since the queue depth is not tunable under Linux,
8014 ** we need to know this value in order not to
8015 ** announce stupid things to user.
8018 lp
->numtags
= lp
->maxtags
= numtags
;
8019 lp
->scdev_depth
= depth_to_use
;
8021 ncr_setup_tags (np
, device
->id
, device
->lun
);
8023 #ifdef DEBUG_NCR53C8XX
8024 printk("ncr53c8xx_select_queue_depth: host=%d, id=%d, lun=%d, depth=%d\n",
8025 np
->unit
, device
->id
, device
->lun
, depth_to_use
);
8032 ** Linux entry point of queuecommand() function
8035 int ncr53c8xx_queue_command (struct scsi_cmnd
*cmd
, void (* done
)(struct scsi_cmnd
*))
8037 struct ncb
*np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
8038 unsigned long flags
;
8041 #ifdef DEBUG_NCR53C8XX
8042 printk("ncr53c8xx_queue_command\n");
8045 cmd
->scsi_done
= done
;
8046 cmd
->host_scribble
= NULL
;
8047 cmd
->__data_mapped
= 0;
8048 cmd
->__data_mapping
= 0;
8050 NCR_LOCK_NCB(np
, flags
);
8052 if ((sts
= ncr_queue_command(np
, cmd
)) != DID_OK
) {
8053 cmd
->result
= ScsiResult(sts
, 0);
8054 #ifdef DEBUG_NCR53C8XX
8055 printk("ncr53c8xx : command not queued - result=%d\n", sts
);
8058 #ifdef DEBUG_NCR53C8XX
8060 printk("ncr53c8xx : command successfully queued\n");
8063 NCR_UNLOCK_NCB(np
, flags
);
8065 if (sts
!= DID_OK
) {
8066 unmap_scsi_data(np
, cmd
);
8074 ** Linux entry point of the interrupt handler.
8075 ** Since linux versions > 1.3.70, we trust the kernel for
8076 ** passing the internal host descriptor as 'dev_id'.
8077 ** Otherwise, we scan the host list and call the interrupt
8078 ** routine for each host that uses this IRQ.
8081 irqreturn_t
ncr53c8xx_intr(int irq
, void *dev_id
, struct pt_regs
* regs
)
8083 unsigned long flags
;
8084 struct Scsi_Host
*shost
= (struct Scsi_Host
*)dev_id
;
8085 struct host_data
*host_data
= (struct host_data
*)shost
->hostdata
;
8086 struct ncb
*np
= host_data
->ncb
;
8087 struct scsi_cmnd
*done_list
;
8089 #ifdef DEBUG_NCR53C8XX
8090 printk("ncr53c8xx : interrupt received\n");
8093 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("[");
8095 NCR_LOCK_NCB(np
, flags
);
8097 done_list
= np
->done_list
;
8098 np
->done_list
= NULL
;
8099 NCR_UNLOCK_NCB(np
, flags
);
8101 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("]\n");
8104 NCR_LOCK_SCSI_DONE(done_list
->device
->host
, flags
);
8105 ncr_flush_done_cmds(done_list
);
8106 NCR_UNLOCK_SCSI_DONE(done_list
->device
->host
, flags
);
8112 ** Linux entry point of the timer handler
8115 static void ncr53c8xx_timeout(unsigned long npref
)
8117 struct ncb
*np
= (struct ncb
*) npref
;
8118 unsigned long flags
;
8119 struct scsi_cmnd
*done_list
;
8121 NCR_LOCK_NCB(np
, flags
);
8123 done_list
= np
->done_list
;
8124 np
->done_list
= NULL
;
8125 NCR_UNLOCK_NCB(np
, flags
);
8128 NCR_LOCK_SCSI_DONE(done_list
->device
->host
, flags
);
8129 ncr_flush_done_cmds(done_list
);
8130 NCR_UNLOCK_SCSI_DONE(done_list
->device
->host
, flags
);
8135 ** Linux entry point of reset() function
8138 int ncr53c8xx_bus_reset(struct scsi_cmnd
*cmd
)
8140 struct ncb
*np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
8142 unsigned long flags
;
8143 struct scsi_cmnd
*done_list
;
8145 NCR_LOCK_NCB(np
, flags
);
8148 * If the mid-level driver told us reset is synchronous, it seems
8149 * that we must call the done() callback for the involved command,
8150 * even if this command was not queued to the low-level driver,
8151 * before returning SUCCESS.
8154 sts
= ncr_reset_bus(np
, cmd
, 1);
8156 done_list
= np
->done_list
;
8157 np
->done_list
= NULL
;
8158 NCR_UNLOCK_NCB(np
, flags
);
8160 ncr_flush_done_cmds(done_list
);
8166 ** Linux entry point of abort() function
8169 int ncr53c8xx_abort(struct scsi_cmnd
*cmd
)
8171 struct ncb
*np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
8173 unsigned long flags
;
8174 struct scsi_cmnd
*done_list
;
8176 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
8177 printk("ncr53c8xx_abort: pid=%lu serial_number=%ld serial_number_at_timeout=%ld\n",
8178 cmd
->pid
, cmd
->serial_number
, cmd
->serial_number_at_timeout
);
8180 printk("ncr53c8xx_abort: command pid %lu\n", cmd
->pid
);
8183 NCR_LOCK_NCB(np
, flags
);
8185 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
8187 * We have to just ignore abort requests in some situations.
8189 if (cmd
->serial_number
!= cmd
->serial_number_at_timeout
) {
8190 sts
= SCSI_ABORT_NOT_RUNNING
;
8195 sts
= ncr_abort_command(np
, cmd
);
8197 done_list
= np
->done_list
;
8198 np
->done_list
= NULL
;
8199 NCR_UNLOCK_NCB(np
, flags
);
8201 ncr_flush_done_cmds(done_list
);
8208 ** Scsi command waiting list management.
8210 ** It may happen that we cannot insert a scsi command into the start queue,
8211 ** in the following circumstances.
8212 ** Too few preallocated ccb(s),
8213 ** maxtags < cmd_per_lun of the Linux host control block,
8215 ** Such scsi commands are inserted into a waiting list.
8216 ** When a scsi command complete, we try to requeue the commands of the
8220 #define next_wcmd host_scribble
8222 static void insert_into_waiting_list(struct ncb
*np
, struct scsi_cmnd
*cmd
)
8224 struct scsi_cmnd
*wcmd
;
8226 #ifdef DEBUG_WAITING_LIST
8227 printk("%s: cmd %lx inserted into waiting list\n", ncr_name(np
), (u_long
) cmd
);
8229 cmd
->next_wcmd
= NULL
;
8230 if (!(wcmd
= np
->waiting_list
)) np
->waiting_list
= cmd
;
8232 while ((wcmd
->next_wcmd
) != 0)
8233 wcmd
= (struct scsi_cmnd
*) wcmd
->next_wcmd
;
8234 wcmd
->next_wcmd
= (char *) cmd
;
8238 static struct scsi_cmnd
*retrieve_from_waiting_list(int to_remove
, struct ncb
*np
, struct scsi_cmnd
*cmd
)
8240 struct scsi_cmnd
**pcmd
= &np
->waiting_list
;
8245 *pcmd
= (struct scsi_cmnd
*) cmd
->next_wcmd
;
8246 cmd
->next_wcmd
= NULL
;
8248 #ifdef DEBUG_WAITING_LIST
8249 printk("%s: cmd %lx retrieved from waiting list\n", ncr_name(np
), (u_long
) cmd
);
8253 pcmd
= (struct scsi_cmnd
**) &(*pcmd
)->next_wcmd
;
8258 static void process_waiting_list(struct ncb
*np
, int sts
)
8260 struct scsi_cmnd
*waiting_list
, *wcmd
;
8262 waiting_list
= np
->waiting_list
;
8263 np
->waiting_list
= NULL
;
8265 #ifdef DEBUG_WAITING_LIST
8266 if (waiting_list
) printk("%s: waiting_list=%lx processing sts=%d\n", ncr_name(np
), (u_long
) waiting_list
, sts
);
8268 while ((wcmd
= waiting_list
) != 0) {
8269 waiting_list
= (struct scsi_cmnd
*) wcmd
->next_wcmd
;
8270 wcmd
->next_wcmd
= NULL
;
8271 if (sts
== DID_OK
) {
8272 #ifdef DEBUG_WAITING_LIST
8273 printk("%s: cmd %lx trying to requeue\n", ncr_name(np
), (u_long
) wcmd
);
8275 sts
= ncr_queue_command(np
, wcmd
);
8277 if (sts
!= DID_OK
) {
8278 #ifdef DEBUG_WAITING_LIST
8279 printk("%s: cmd %lx done forced sts=%d\n", ncr_name(np
), (u_long
) wcmd
, sts
);
8281 wcmd
->result
= ScsiResult(sts
, 0);
8282 ncr_queue_done_cmd(np
, wcmd
);
8289 #ifdef SCSI_NCR_PROC_INFO_SUPPORT
8291 /*=========================================================================
8292 ** Proc file system stuff
8294 ** A read operation returns profile information.
8295 ** A write operation is a control command.
8296 ** The string is parsed in the driver code and the command is passed
8297 ** to the ncr_usercmd() function.
8298 **=========================================================================
8301 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
8303 #define is_digit(c) ((c) >= '0' && (c) <= '9')
8304 #define digit_to_bin(c) ((c) - '0')
8305 #define is_space(c) ((c) == ' ' || (c) == '\t')
8307 static int skip_spaces(char *ptr
, int len
)
8311 for (cnt
= len
; cnt
> 0 && (c
= *ptr
++) && is_space(c
); cnt
--);
8316 static int get_int_arg(char *ptr
, int len
, u_long
*pv
)
8321 for (v
= 0, cnt
= len
; cnt
> 0 && (c
= *ptr
++) && is_digit(c
); cnt
--) {
8322 v
= (v
* 10) + digit_to_bin(c
);
8331 static int is_keyword(char *ptr
, int len
, char *verb
)
8333 int verb_len
= strlen(verb
);
8335 if (len
>= strlen(verb
) && !memcmp(verb
, ptr
, verb_len
))
8342 #define SKIP_SPACES(min_spaces) \
8343 if ((arg_len = skip_spaces(ptr, len)) < (min_spaces)) \
8345 ptr += arg_len; len -= arg_len;
8347 #define GET_INT_ARG(v) \
8348 if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
8350 ptr += arg_len; len -= arg_len;
8354 ** Parse a control command
8357 static int ncr_user_command(struct ncb
*np
, char *buffer
, int length
)
8361 struct usrcmd
*uc
= &np
->user
;
8365 bzero(uc
, sizeof(*uc
));
8367 if (len
> 0 && ptr
[len
-1] == '\n')
8370 if ((arg_len
= is_keyword(ptr
, len
, "setsync")) != 0)
8371 uc
->cmd
= UC_SETSYNC
;
8372 else if ((arg_len
= is_keyword(ptr
, len
, "settags")) != 0)
8373 uc
->cmd
= UC_SETTAGS
;
8374 else if ((arg_len
= is_keyword(ptr
, len
, "setorder")) != 0)
8375 uc
->cmd
= UC_SETORDER
;
8376 else if ((arg_len
= is_keyword(ptr
, len
, "setverbose")) != 0)
8377 uc
->cmd
= UC_SETVERBOSE
;
8378 else if ((arg_len
= is_keyword(ptr
, len
, "setwide")) != 0)
8379 uc
->cmd
= UC_SETWIDE
;
8380 else if ((arg_len
= is_keyword(ptr
, len
, "setdebug")) != 0)
8381 uc
->cmd
= UC_SETDEBUG
;
8382 else if ((arg_len
= is_keyword(ptr
, len
, "setflag")) != 0)
8383 uc
->cmd
= UC_SETFLAG
;
8387 #ifdef DEBUG_PROC_INFO
8388 printk("ncr_user_command: arg_len=%d, cmd=%ld\n", arg_len
, uc
->cmd
);
8393 ptr
+= arg_len
; len
-= arg_len
;
8401 if ((arg_len
= is_keyword(ptr
, len
, "all")) != 0) {
8402 ptr
+= arg_len
; len
-= arg_len
;
8405 GET_INT_ARG(target
);
8406 uc
->target
= (1<<target
);
8407 #ifdef DEBUG_PROC_INFO
8408 printk("ncr_user_command: target=%ld\n", target
);
8420 GET_INT_ARG(uc
->data
);
8421 #ifdef DEBUG_PROC_INFO
8422 printk("ncr_user_command: data=%ld\n", uc
->data
);
8427 if ((arg_len
= is_keyword(ptr
, len
, "simple")))
8428 uc
->data
= M_SIMPLE_TAG
;
8429 else if ((arg_len
= is_keyword(ptr
, len
, "ordered")))
8430 uc
->data
= M_ORDERED_TAG
;
8431 else if ((arg_len
= is_keyword(ptr
, len
, "default")))
8439 if ((arg_len
= is_keyword(ptr
, len
, "alloc")))
8440 uc
->data
|= DEBUG_ALLOC
;
8441 else if ((arg_len
= is_keyword(ptr
, len
, "phase")))
8442 uc
->data
|= DEBUG_PHASE
;
8443 else if ((arg_len
= is_keyword(ptr
, len
, "queue")))
8444 uc
->data
|= DEBUG_QUEUE
;
8445 else if ((arg_len
= is_keyword(ptr
, len
, "result")))
8446 uc
->data
|= DEBUG_RESULT
;
8447 else if ((arg_len
= is_keyword(ptr
, len
, "scatter")))
8448 uc
->data
|= DEBUG_SCATTER
;
8449 else if ((arg_len
= is_keyword(ptr
, len
, "script")))
8450 uc
->data
|= DEBUG_SCRIPT
;
8451 else if ((arg_len
= is_keyword(ptr
, len
, "tiny")))
8452 uc
->data
|= DEBUG_TINY
;
8453 else if ((arg_len
= is_keyword(ptr
, len
, "timing")))
8454 uc
->data
|= DEBUG_TIMING
;
8455 else if ((arg_len
= is_keyword(ptr
, len
, "nego")))
8456 uc
->data
|= DEBUG_NEGO
;
8457 else if ((arg_len
= is_keyword(ptr
, len
, "tags")))
8458 uc
->data
|= DEBUG_TAGS
;
8461 ptr
+= arg_len
; len
-= arg_len
;
8463 #ifdef DEBUG_PROC_INFO
8464 printk("ncr_user_command: data=%ld\n", uc
->data
);
8470 if ((arg_len
= is_keyword(ptr
, len
, "trace")))
8471 uc
->data
|= UF_TRACE
;
8472 else if ((arg_len
= is_keyword(ptr
, len
, "no_disc")))
8473 uc
->data
|= UF_NODISC
;
8476 ptr
+= arg_len
; len
-= arg_len
;
8486 unsigned long flags
;
8488 NCR_LOCK_NCB(np
, flags
);
8490 NCR_UNLOCK_NCB(np
, flags
);
8495 #endif /* SCSI_NCR_USER_COMMAND_SUPPORT */
8498 #ifdef SCSI_NCR_USER_INFO_SUPPORT
8500 ** Copy formatted information into the input buffer.
8503 static int ncr_host_info(struct ncb
*np
, char *ptr
, off_t offset
, int len
)
8505 struct info_str info
;
8509 info
.offset
= offset
;
8512 copy_info(&info
, " Chip NCR53C720, revision id 0x%x, IRQ %d\n",
8513 np
->revision_id
, (int) np
->irq
);
8514 copy_info(&info
, " Synchronous period factor %d, "
8515 "max commands per lun %d\n",
8516 (int) np
->minsync
, MAX_TAGS
);
8518 if (driver_setup
.debug
|| driver_setup
.verbose
> 1) {
8519 copy_info(&info
, " Debug flags 0x%x, verbosity level %d\n",
8520 driver_setup
.debug
, driver_setup
.verbose
);
8523 return info
.pos
> info
.offset
? info
.pos
- info
.offset
: 0;
8526 #endif /* SCSI_NCR_USER_INFO_SUPPORT */
8529 ** Entry point of the scsi proc fs of the driver.
8530 ** - func = 0 means read (returns profile data)
8531 ** - func = 1 means write (parse user control command)
8534 static int ncr53c8xx_proc_info(struct Scsi_Host
*host
, char *buffer
, char **start
, off_t offset
,
8535 int length
, int func
)
8537 struct host_data
*host_data
;
8538 struct ncb
*ncb
= NULL
;
8541 #ifdef DEBUG_PROC_INFO
8542 printk("ncr53c8xx_proc_info: hostno=%d, func=%d\n", host
->host_no
, func
);
8545 host_data
= (struct host_data
*) host
->hostdata
;
8546 ncb
= host_data
->ncb
;
8549 #ifdef SCSI_NCR_USER_COMMAND_SUPPORT
8550 retv
= ncr_user_command(ncb
, buffer
, length
);
8558 #ifdef SCSI_NCR_USER_INFO_SUPPORT
8559 retv
= ncr_host_info(ncb
, buffer
, offset
, length
);
8568 /*=========================================================================
8569 ** End of proc file system stuff
8570 **=========================================================================
8575 /*==========================================================
8577 ** Boot command line.
8579 **==========================================================
8582 char *ncr53c8xx
; /* command line passed by insmod */
8583 MODULE_PARM(ncr53c8xx
, "s");
8586 int __init
ncr53c8xx_setup(char *str
)
8588 return sym53c8xx__setup(str
);
8592 __setup("ncr53c8xx=", ncr53c8xx_setup
);
8595 /*==========================================================
8597 ** Entry point for info() function
8599 **==========================================================
8601 const char *ncr53c8xx_info (struct Scsi_Host
*host
)
8603 return SCSI_NCR_DRIVER_NAME
;
8608 * Host attach and initialisations.
8610 * Allocate host data and ncb structure.
8611 * Request IO region and remap MMIO region.
8612 * Do chip initialization.
8613 * If all is OK, install interrupt handling and
8614 * start the timer daemon.
8616 struct Scsi_Host
* __init
ncr_attach(struct scsi_host_template
*tpnt
,
8617 int unit
, struct ncr_device
*device
)
8619 struct host_data
*host_data
;
8620 struct ncb
*np
= NULL
;
8621 struct Scsi_Host
*instance
= NULL
;
8625 #ifdef SCSI_NCR_PROC_INFO_SUPPORT
8626 tpnt
->proc_info
= ncr53c8xx_proc_info
,
8628 tpnt
->info
= ncr53c8xx_info
;
8629 tpnt
->queuecommand
= ncr53c8xx_queue_command
;
8630 tpnt
->slave_configure
= ncr53c8xx_slave_configure
;
8631 tpnt
->eh_bus_reset_handler
= ncr53c8xx_bus_reset
;
8632 tpnt
->can_queue
= SCSI_NCR_CAN_QUEUE
;
8634 tpnt
->sg_tablesize
= SCSI_NCR_SG_TABLESIZE
;
8635 tpnt
->cmd_per_lun
= SCSI_NCR_CMD_PER_LUN
;
8636 tpnt
->use_clustering
= ENABLE_CLUSTERING
;
8638 if (device
->differential
)
8639 driver_setup
.diff_support
= device
->differential
;
8641 printk(KERN_INFO
"ncr53c720-%d: rev 0x%x irq %d\n",
8642 unit
, device
->chip
.revision_id
, device
->slot
.irq
);
8644 instance
= scsi_host_alloc(tpnt
, sizeof(*host_data
));
8647 host_data
= (struct host_data
*) instance
->hostdata
;
8649 np
= __m_calloc_dma(device
->dev
, sizeof(struct ncb
), "NCB");
8652 NCR_INIT_LOCK_NCB(np
);
8653 np
->dev
= device
->dev
;
8654 np
->p_ncb
= vtobus(np
);
8655 host_data
->ncb
= np
;
8657 np
->ccb
= m_calloc_dma(sizeof(struct ccb
), "CCB");
8661 /* Store input information in the host data structure. */
8663 np
->verbose
= driver_setup
.verbose
;
8664 sprintf(np
->inst_name
, "ncr53c720-%d", np
->unit
);
8665 np
->revision_id
= device
->chip
.revision_id
;
8666 np
->features
= device
->chip
.features
;
8667 np
->clock_divn
= device
->chip
.nr_divisor
;
8668 np
->maxoffs
= device
->chip
.offset_max
;
8669 np
->maxburst
= device
->chip
.burst_max
;
8670 np
->myaddr
= device
->host_id
;
8672 /* Allocate SCRIPTS areas. */
8673 np
->script0
= m_calloc_dma(sizeof(struct script
), "SCRIPT");
8676 np
->scripth0
= m_calloc_dma(sizeof(struct scripth
), "SCRIPTH");
8680 init_timer(&np
->timer
);
8681 np
->timer
.data
= (unsigned long) np
;
8682 np
->timer
.function
= ncr53c8xx_timeout
;
8684 /* Try to map the controller chip to virtual and physical memory. */
8686 np
->paddr
= device
->slot
.base
;
8687 np
->paddr2
= (np
->features
& FE_RAM
) ? device
->slot
.base_2
: 0;
8689 if (device
->slot
.base_v
)
8690 np
->vaddr
= device
->slot
.base_v
;
8692 np
->vaddr
= (unsigned long)ioremap(device
->slot
.base_c
, 128);
8696 "%s: can't map memory mapped IO region\n",ncr_name(np
));
8699 if (bootverbose
> 1)
8701 "%s: using memory mapped IO at virtual address 0x%lx\n", ncr_name(np
), (u_long
) np
->vaddr
);
8704 /* Make the controller's registers available. Now the INB INW INL
8705 * OUTB OUTW OUTL macros can be used safely.
8708 np
->reg
= (struct ncr_reg
*) np
->vaddr
;
8710 /* Do chip dependent initialization. */
8711 ncr_prepare_setting(np
);
8713 if (np
->paddr2
&& sizeof(struct script
) > 4096) {
8715 printk(KERN_WARNING
"%s: script too large, NOT using on chip RAM.\n",
8719 /* Fill Linux host instance structure */
8720 instance
->max_channel
= 0;
8721 instance
->this_id
= np
->myaddr
;
8722 instance
->max_id
= np
->maxwide
? 16 : 8;
8723 instance
->max_lun
= SCSI_NCR_MAX_LUN
;
8724 instance
->base
= (unsigned long) np
->reg
;
8725 instance
->irq
= device
->slot
.irq
;
8726 instance
->unique_id
= device
->slot
.base
;
8727 instance
->dma_channel
= 0;
8728 instance
->cmd_per_lun
= MAX_TAGS
;
8729 instance
->can_queue
= (MAX_START
-4);
8730 scsi_set_device(instance
, device
->dev
);
8732 #ifdef SCSI_NCR_INTEGRITY_CHECKING
8733 np
->check_integrity
= 0;
8734 instance
->check_integrity
= 0;
8736 #ifdef SCSI_NCR_ENABLE_INTEGRITY_CHECK
8737 if ( !(driver_setup
.bus_check
& 0x04) ) {
8738 np
->check_integrity
= 1;
8739 instance
->check_integrity
= 1;
8743 /* Patch script to physical addresses */
8744 ncr_script_fill(&script0
, &scripth0
);
8746 np
->scripth
= np
->scripth0
;
8747 np
->p_scripth
= vtobus(np
->scripth
);
8748 np
->p_script
= (np
->paddr2
) ? np
->paddr2
: vtobus(np
->script0
);
8750 ncr_script_copy_and_bind(np
, (ncrcmd
*) &script0
,
8751 (ncrcmd
*) np
->script0
, sizeof(struct script
));
8752 ncr_script_copy_and_bind(np
, (ncrcmd
*) &scripth0
,
8753 (ncrcmd
*) np
->scripth0
, sizeof(struct scripth
));
8754 np
->ccb
->p_ccb
= vtobus (np
->ccb
);
8756 /* Patch the script for LED support. */
8758 if (np
->features
& FE_LED0
) {
8759 np
->script0
->idle
[0] =
8760 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_OR
, 0x01));
8761 np
->script0
->reselected
[0] =
8762 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_AND
, 0xfe));
8763 np
->script0
->start
[0] =
8764 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_AND
, 0xfe));
8768 * Look for the target control block of this nexus.
8770 * JUMP ^ IFTRUE (MASK (i, 3)), @(next_lcb)
8772 for (i
= 0 ; i
< 4 ; i
++) {
8773 np
->jump_tcb
[i
].l_cmd
=
8774 cpu_to_scr((SCR_JUMP
^ IFTRUE (MASK (i
, 3))));
8775 np
->jump_tcb
[i
].l_paddr
=
8776 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_target
));
8779 ncr_chip_reset(np
, 100);
8781 /* Now check the cache handling of the chipset. */
8783 if (ncr_snooptest(np
)) {
8784 printk(KERN_ERR
"CACHE INCORRECTLY CONFIGURED.\n");
8788 /* Install the interrupt handler. */
8789 np
->irq
= device
->slot
.irq
;
8791 /* Initialize the fixed part of the default ccb. */
8792 ncr_init_ccb(np
, np
->ccb
);
8795 * After SCSI devices have been opened, we cannot reset the bus
8796 * safely, so we do it here. Interrupt handler does the real work.
8797 * Process the reset exception if interrupts are not enabled yet.
8798 * Then enable disconnects.
8800 NCR_LOCK_NCB(np
, flags
);
8801 if (ncr_reset_scsi_bus(np
, 0, driver_setup
.settle_delay
) != 0) {
8802 printk(KERN_ERR
"%s: FATAL ERROR: CHECK SCSI BUS - CABLES, TERMINATION, DEVICE POWER etc.!\n", ncr_name(np
));
8804 NCR_UNLOCK_NCB(np
, flags
);
8812 * The middle-level SCSI driver does not wait for devices to settle.
8813 * Wait synchronously if more than 2 seconds.
8815 if (driver_setup
.settle_delay
> 2) {
8816 printk(KERN_INFO
"%s: waiting %d seconds for scsi devices to settle...\n",
8817 ncr_name(np
), driver_setup
.settle_delay
);
8818 MDELAY (1000 * driver_setup
.settle_delay
);
8821 /* start the timeout daemon */
8825 /* use SIMPLE TAG messages by default */
8826 #ifdef SCSI_NCR_ALWAYS_SIMPLE_TAG
8827 np
->order
= M_SIMPLE_TAG
;
8830 NCR_UNLOCK_NCB(np
, flags
);
8837 printk(KERN_INFO
"%s: detaching...\n", ncr_name(np
));
8841 m_free_dma(np
->scripth0
, sizeof(struct scripth
), "SCRIPTH");
8843 m_free_dma(np
->script0
, sizeof(struct script
), "SCRIPT");
8845 m_free_dma(np
->ccb
, sizeof(struct ccb
), "CCB");
8846 m_free_dma(np
, sizeof(struct ncb
), "NCB");
8847 host_data
->ncb
= NULL
;
8850 scsi_host_put(instance
);
8856 int ncr53c8xx_release(struct Scsi_Host
*host
)
8858 struct host_data
*host_data
;
8859 #ifdef DEBUG_NCR53C8XX
8860 printk("ncr53c8xx: release\n");
8864 host_data
= (struct host_data
*)host
->hostdata
;
8865 if (host_data
&& host_data
->ncb
)
8866 ncr_detach(host_data
->ncb
);