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 /* Name and version of the driver */
89 #define SCSI_NCR_DRIVER_NAME "ncr53c8xx-3.4.3g"
91 #define SCSI_NCR_DEBUG_FLAGS (0)
93 /*==========================================================
97 **==========================================================
100 #include <linux/blkdev.h>
101 #include <linux/delay.h>
102 #include <linux/dma-mapping.h>
103 #include <linux/errno.h>
104 #include <linux/init.h>
105 #include <linux/interrupt.h>
106 #include <linux/ioport.h>
107 #include <linux/mm.h>
108 #include <linux/module.h>
109 #include <linux/sched.h>
110 #include <linux/signal.h>
111 #include <linux/spinlock.h>
112 #include <linux/stat.h>
113 #include <linux/string.h>
114 #include <linux/time.h>
115 #include <linux/timer.h>
116 #include <linux/types.h>
120 #include <asm/system.h>
122 #include <scsi/scsi.h>
123 #include <scsi/scsi_cmnd.h>
124 #include <scsi/scsi_device.h>
125 #include <scsi/scsi_tcq.h>
126 #include <scsi/scsi_transport.h>
127 #include <scsi/scsi_transport_spi.h>
129 #include "ncr53c8xx.h"
131 #define NAME53C "ncr53c"
132 #define NAME53C8XX "ncr53c8xx"
134 #include "sym53c8xx_comm.h"
137 /*==========================================================
139 ** The CCB done queue uses an array of CCB virtual
140 ** addresses. Empty entries are flagged using the bogus
141 ** virtual address 0xffffffff.
143 ** Since PCI ensures that only aligned DWORDs are accessed
144 ** atomically, 64 bit little-endian architecture requires
145 ** to test the high order DWORD of the entry to determine
146 ** if it is empty or valid.
148 ** BTW, I will make things differently as soon as I will
149 ** have a better idea, but this is simple and should work.
151 **==========================================================
154 #define SCSI_NCR_CCB_DONE_SUPPORT
155 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
158 #define CCB_DONE_EMPTY 0xffffffffUL
160 /* All 32 bit architectures */
161 #if BITS_PER_LONG == 32
162 #define CCB_DONE_VALID(cp) (((u_long) cp) != CCB_DONE_EMPTY)
164 /* All > 32 bit (64 bit) architectures regardless endian-ness */
166 #define CCB_DONE_VALID(cp) \
167 ((((u_long) cp) & 0xffffffff00000000ul) && \
168 (((u_long) cp) & 0xfffffffful) != CCB_DONE_EMPTY)
171 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
173 /*==========================================================
175 ** Configuration and Debugging
177 **==========================================================
181 ** SCSI address of this device.
182 ** The boot routines should have set it.
186 #ifndef SCSI_NCR_MYADDR
187 #define SCSI_NCR_MYADDR (7)
191 ** The maximum number of tags per logic unit.
192 ** Used only for disk devices that support tags.
195 #ifndef SCSI_NCR_MAX_TAGS
196 #define SCSI_NCR_MAX_TAGS (8)
200 ** TAGS are actually limited to 64 tags/lun.
201 ** We need to deal with power of 2, for alignment constraints.
203 #if SCSI_NCR_MAX_TAGS > 64
204 #define MAX_TAGS (64)
206 #define MAX_TAGS SCSI_NCR_MAX_TAGS
212 ** Choose appropriate type for tag bitmap.
215 typedef u64 tagmap_t
;
217 typedef u32 tagmap_t
;
221 ** Number of targets supported by the driver.
222 ** n permits target numbers 0..n-1.
223 ** Default is 16, meaning targets #0..#15.
227 #ifdef SCSI_NCR_MAX_TARGET
228 #define MAX_TARGET (SCSI_NCR_MAX_TARGET)
230 #define MAX_TARGET (16)
234 ** Number of logic units supported by the driver.
235 ** n enables logic unit numbers 0..n-1.
236 ** The common SCSI devices require only
237 ** one lun, so take 1 as the default.
240 #ifdef SCSI_NCR_MAX_LUN
241 #define MAX_LUN SCSI_NCR_MAX_LUN
247 ** Asynchronous pre-scaler (ns). Shall be 40
250 #ifndef SCSI_NCR_MIN_ASYNC
251 #define SCSI_NCR_MIN_ASYNC (40)
255 ** The maximum number of jobs scheduled for starting.
256 ** There should be one slot per target, and one slot
257 ** for each tag of each target in use.
258 ** The calculation below is actually quite silly ...
261 #ifdef SCSI_NCR_CAN_QUEUE
262 #define MAX_START (SCSI_NCR_CAN_QUEUE + 4)
264 #define MAX_START (MAX_TARGET + 7 * MAX_TAGS)
268 ** We limit the max number of pending IO to 250.
269 ** since we donnot want to allocate more than 1
270 ** PAGE for 'scripth'.
274 #define MAX_START 250
278 ** The maximum number of segments a transfer is split into.
279 ** We support up to 127 segments for both read and write.
280 ** The data scripts are broken into 2 sub-scripts.
281 ** 80 (MAX_SCATTERL) segments are moved from a sub-script
282 ** in on-chip RAM. This makes data transfers shorter than
283 ** 80k (assuming 1k fs) as fast as possible.
286 #define MAX_SCATTER (SCSI_NCR_MAX_SCATTER)
288 #if (MAX_SCATTER > 80)
289 #define MAX_SCATTERL 80
290 #define MAX_SCATTERH (MAX_SCATTER - MAX_SCATTERL)
292 #define MAX_SCATTERL (MAX_SCATTER-1)
293 #define MAX_SCATTERH 1
300 #define NCR_SNOOP_TIMEOUT (1000000)
306 #define ScsiResult(host_code, scsi_code) (((host_code) << 16) + ((scsi_code) & 0x7f))
308 #define initverbose (driver_setup.verbose)
309 #define bootverbose (np->verbose)
311 /*==========================================================
313 ** Command control block states.
315 **==========================================================
320 #define HS_NEGOTIATE (2) /* sync/wide data transfer*/
321 #define HS_DISCONNECT (3) /* Disconnected by target */
323 #define HS_DONEMASK (0x80)
324 #define HS_COMPLETE (4|HS_DONEMASK)
325 #define HS_SEL_TIMEOUT (5|HS_DONEMASK) /* Selection timeout */
326 #define HS_RESET (6|HS_DONEMASK) /* SCSI reset */
327 #define HS_ABORTED (7|HS_DONEMASK) /* Transfer aborted */
328 #define HS_TIMEOUT (8|HS_DONEMASK) /* Software timeout */
329 #define HS_FAIL (9|HS_DONEMASK) /* SCSI or PCI bus errors */
330 #define HS_UNEXPECTED (10|HS_DONEMASK)/* Unexpected disconnect */
333 ** Invalid host status values used by the SCRIPTS processor
334 ** when the nexus is not fully identified.
335 ** Shall never appear in a CCB.
338 #define HS_INVALMASK (0x40)
339 #define HS_SELECTING (0|HS_INVALMASK)
340 #define HS_IN_RESELECT (1|HS_INVALMASK)
341 #define HS_STARTING (2|HS_INVALMASK)
344 ** Flags set by the SCRIPT processor for commands
345 ** that have been skipped.
347 #define HS_SKIPMASK (0x20)
349 /*==========================================================
351 ** Software Interrupt Codes
353 **==========================================================
356 #define SIR_BAD_STATUS (1)
357 #define SIR_XXXXXXXXXX (2)
358 #define SIR_NEGO_SYNC (3)
359 #define SIR_NEGO_WIDE (4)
360 #define SIR_NEGO_FAILED (5)
361 #define SIR_NEGO_PROTO (6)
362 #define SIR_REJECT_RECEIVED (7)
363 #define SIR_REJECT_SENT (8)
364 #define SIR_IGN_RESIDUE (9)
365 #define SIR_MISSING_SAVE (10)
366 #define SIR_RESEL_NO_MSG_IN (11)
367 #define SIR_RESEL_NO_IDENTIFY (12)
368 #define SIR_RESEL_BAD_LUN (13)
369 #define SIR_RESEL_BAD_TARGET (14)
370 #define SIR_RESEL_BAD_I_T_L (15)
371 #define SIR_RESEL_BAD_I_T_L_Q (16)
372 #define SIR_DONE_OVERFLOW (17)
373 #define SIR_INTFLY (18)
376 /*==========================================================
378 ** Extended error codes.
379 ** xerr_status field of struct ccb.
381 **==========================================================
385 #define XE_EXTRA_DATA (1) /* unexpected data phase */
386 #define XE_BAD_PHASE (2) /* illegal phase (4/5) */
388 /*==========================================================
390 ** Negotiation status.
391 ** nego_status field of struct ccb.
393 **==========================================================
396 #define NS_NOCHANGE (0)
401 /*==========================================================
405 **==========================================================
408 #define CCB_MAGIC (0xf2691ad2)
410 /*==========================================================
412 ** Declaration of structs.
414 **==========================================================
417 static struct scsi_transport_template
*ncr53c8xx_transport_template
= NULL
;
437 #define UC_SETSYNC 10
438 #define UC_SETTAGS 11
439 #define UC_SETDEBUG 12
440 #define UC_SETORDER 13
441 #define UC_SETWIDE 14
442 #define UC_SETFLAG 15
443 #define UC_SETVERBOSE 17
445 #define UF_TRACE (0x01)
446 #define UF_NODISC (0x02)
447 #define UF_NOSCAN (0x04)
449 /*========================================================================
451 ** Declaration of structs: target control block
453 **========================================================================
456 /*----------------------------------------------------------------
457 ** During reselection the ncr jumps to this point with SFBR
458 ** set to the encoded target number with bit 7 set.
459 ** if it's not this target, jump to the next.
461 ** JUMP IF (SFBR != #target#), @(next tcb)
462 **----------------------------------------------------------------
464 struct link jump_tcb
;
466 /*----------------------------------------------------------------
467 ** Load the actual values for the sxfer and the scntl3
468 ** register (sync/wide mode).
470 ** SCR_COPY (1), @(sval field of this tcb), @(sxfer register)
471 ** SCR_COPY (1), @(wval field of this tcb), @(scntl3 register)
472 **----------------------------------------------------------------
476 /*----------------------------------------------------------------
477 ** Get the IDENTIFY message and load the LUN to SFBR.
480 **----------------------------------------------------------------
482 struct link call_lun
;
484 /*----------------------------------------------------------------
485 ** Now look for the right lun.
488 ** SCR_JUMP ^ IFTRUE(MASK(i, 3)), @(first lcb mod. i)
490 ** Recent chips will prefetch the 4 JUMPS using only 1 burst.
491 ** It is kind of hashcoding.
492 **----------------------------------------------------------------
494 struct link jump_lcb
[4]; /* JUMPs for reselection */
495 struct lcb
* lp
[MAX_LUN
]; /* The lcb's of this tcb */
497 /*----------------------------------------------------------------
498 ** Pointer to the ccb used for negotiation.
499 ** Prevent from starting a negotiation for all queued commands
500 ** when tagged command queuing is enabled.
501 **----------------------------------------------------------------
503 struct ccb
* nego_cp
;
505 /*----------------------------------------------------------------
507 **----------------------------------------------------------------
512 /*----------------------------------------------------------------
513 ** negotiation of wide and synch transfer and device quirks.
514 **----------------------------------------------------------------
516 #ifdef SCSI_NCR_BIG_ENDIAN
519 /*3*/ u_char minsync
;
521 /*1*/ u_char widedone
;
523 /*3*/ u_char maxoffs
;
525 /*0*/ u_char minsync
;
528 /*0*/ u_char maxoffs
;
530 /*2*/ u_char widedone
;
534 /* User settable limits and options. */
539 struct scsi_target
*starget
;
542 /*========================================================================
544 ** Declaration of structs: lun control block
546 **========================================================================
549 /*----------------------------------------------------------------
550 ** During reselection the ncr jumps to this point
551 ** with SFBR set to the "Identify" message.
552 ** if it's not this lun, jump to the next.
554 ** JUMP IF (SFBR != #lun#), @(next lcb of this target)
556 ** It is this lun. Load TEMP with the nexus jumps table
557 ** address and jump to RESEL_TAG (or RESEL_NOTAG).
559 ** SCR_COPY (4), p_jump_ccb, TEMP,
560 ** SCR_JUMP, <RESEL_TAG>
561 **----------------------------------------------------------------
563 struct link jump_lcb
;
564 ncrcmd load_jump_ccb
[3];
565 struct link jump_tag
;
566 ncrcmd p_jump_ccb
; /* Jump table bus address */
568 /*----------------------------------------------------------------
569 ** Jump table used by the script processor to directly jump
570 ** to the CCB corresponding to the reselected nexus.
571 ** Address is allocated on 256 bytes boundary in order to
572 ** allow 8 bit calculation of the tag jump entry for up to
574 **----------------------------------------------------------------
576 u32 jump_ccb_0
; /* Default table if no tags */
577 u32
*jump_ccb
; /* Virtual address */
579 /*----------------------------------------------------------------
580 ** CCB queue management.
581 **----------------------------------------------------------------
583 struct list_head free_ccbq
; /* Queue of available CCBs */
584 struct list_head busy_ccbq
; /* Queue of busy CCBs */
585 struct list_head wait_ccbq
; /* Queue of waiting for IO CCBs */
586 struct list_head skip_ccbq
; /* Queue of skipped CCBs */
587 u_char actccbs
; /* Number of allocated CCBs */
588 u_char busyccbs
; /* CCBs busy for this lun */
589 u_char queuedccbs
; /* CCBs queued to the controller*/
590 u_char queuedepth
; /* Queue depth for this lun */
591 u_char scdev_depth
; /* SCSI device queue depth */
592 u_char maxnxs
; /* Max possible nexuses */
594 /*----------------------------------------------------------------
595 ** Control of tagged command queuing.
596 ** Tags allocation is performed using a circular buffer.
597 ** This avoids using a loop for tag allocation.
598 **----------------------------------------------------------------
600 u_char ia_tag
; /* Allocation index */
601 u_char if_tag
; /* Freeing index */
602 u_char cb_tags
[MAX_TAGS
]; /* Circular tags buffer */
603 u_char usetags
; /* Command queuing is active */
604 u_char maxtags
; /* Max nr of tags asked by user */
605 u_char numtags
; /* Current number of tags */
607 /*----------------------------------------------------------------
608 ** QUEUE FULL control and ORDERED tag control.
609 **----------------------------------------------------------------
611 /*----------------------------------------------------------------
612 ** QUEUE FULL and ORDERED tag control.
613 **----------------------------------------------------------------
615 u16 num_good
; /* Nr of GOOD since QUEUE FULL */
616 tagmap_t tags_umap
; /* Used tags bitmap */
617 tagmap_t tags_smap
; /* Tags in use at 'tag_stime' */
618 u_long tags_stime
; /* Last time we set smap=umap */
619 struct ccb
* held_ccb
; /* CCB held for QUEUE FULL */
622 /*========================================================================
624 ** Declaration of structs: the launch script.
626 **========================================================================
628 ** It is part of the CCB and is called by the scripts processor to
629 ** start or restart the data structure (nexus).
630 ** This 6 DWORDs mini script makes use of prefetching.
632 **------------------------------------------------------------------------
635 /*----------------------------------------------------------------
636 ** SCR_COPY(4), @(p_phys), @(dsa register)
637 ** SCR_JUMP, @(scheduler_point)
638 **----------------------------------------------------------------
640 ncrcmd setup_dsa
[3]; /* Copy 'phys' address to dsa */
641 struct link schedule
; /* Jump to scheduler point */
642 ncrcmd p_phys
; /* 'phys' header bus address */
645 /*========================================================================
647 ** Declaration of structs: global HEADER.
649 **========================================================================
651 ** This substructure is copied from the ccb to a global address after
652 ** selection (or reselection) and copied back before disconnect.
654 ** These fields are accessible to the script processor.
656 **------------------------------------------------------------------------
660 /*----------------------------------------------------------------
661 ** Saved data pointer.
662 ** Points to the position in the script responsible for the
663 ** actual transfer transfer of data.
664 ** It's written after reception of a SAVE_DATA_POINTER message.
665 ** The goalpointer points after the last transfer command.
666 **----------------------------------------------------------------
672 /*----------------------------------------------------------------
673 ** Alternate data pointer.
674 ** They are copied back to savep/lastp/goalp by the SCRIPTS
675 ** when the direction is unknown and the device claims data out.
676 **----------------------------------------------------------------
681 /*----------------------------------------------------------------
682 ** The virtual address of the ccb containing this header.
683 **----------------------------------------------------------------
687 /*----------------------------------------------------------------
689 **----------------------------------------------------------------
691 u_char scr_st
[4]; /* script status */
692 u_char status
[4]; /* host status. must be the */
693 /* last DWORD of the header. */
697 ** The status bytes are used by the host and the script processor.
699 ** The byte corresponding to the host_status must be stored in the
700 ** last DWORD of the CCB header since it is used for command
701 ** completion (ncr_wakeup()). Doing so, we are sure that the header
702 ** has been entirely copied back to the CCB when the host_status is
703 ** seen complete by the CPU.
705 ** The last four bytes (status[4]) are copied to the scratchb register
706 ** (declared as scr0..scr3 in ncr_reg.h) just after the select/reselect,
707 ** and copied back just after disconnecting.
708 ** Inside the script the XX_REG are used.
710 ** The first four bytes (scr_st[4]) are used inside the script by
712 ** Because source and destination must have the same alignment
713 ** in a DWORD, the fields HAVE to be at the choosen offsets.
714 ** xerr_st 0 (0x34) scratcha
715 ** sync_st 1 (0x05) sxfer
716 ** wide_st 3 (0x03) scntl3
720 ** Last four bytes (script)
724 #define HS_PRT nc_scr1
726 #define SS_PRT nc_scr2
730 ** Last four bytes (host)
732 #ifdef SCSI_NCR_BIG_ENDIAN
733 #define actualquirks phys.header.status[3]
734 #define host_status phys.header.status[2]
735 #define scsi_status phys.header.status[1]
736 #define parity_status phys.header.status[0]
738 #define actualquirks phys.header.status[0]
739 #define host_status phys.header.status[1]
740 #define scsi_status phys.header.status[2]
741 #define parity_status phys.header.status[3]
745 ** First four bytes (script)
747 #define xerr_st header.scr_st[0]
748 #define sync_st header.scr_st[1]
749 #define nego_st header.scr_st[2]
750 #define wide_st header.scr_st[3]
753 ** First four bytes (host)
755 #define xerr_status phys.xerr_st
756 #define nego_status phys.nego_st
759 #define sync_status phys.sync_st
760 #define wide_status phys.wide_st
763 /*==========================================================
765 ** Declaration of structs: Data structure block
767 **==========================================================
769 ** During execution of a ccb by the script processor,
770 ** the DSA (data structure address) register points
771 ** to this substructure of the ccb.
772 ** This substructure contains the header with
773 ** the script-processor-changable data and
774 ** data blocks for the indirect move commands.
776 **----------------------------------------------------------
788 ** Table data for Script
791 struct scr_tblsel select
;
792 struct scr_tblmove smsg
;
793 struct scr_tblmove cmd
;
794 struct scr_tblmove sense
;
795 struct scr_tblmove data
[MAX_SCATTER
];
799 /*========================================================================
801 ** Declaration of structs: Command control block.
803 **========================================================================
806 /*----------------------------------------------------------------
807 ** This is the data structure which is pointed by the DSA
808 ** register when it is executed by the script processor.
809 ** It must be the first entry because it contains the header
810 ** as first entry that must be cache line aligned.
811 **----------------------------------------------------------------
815 /*----------------------------------------------------------------
816 ** Mini-script used at CCB execution start-up.
817 ** Load the DSA with the data structure address (phys) and
818 ** jump to SELECT. Jump to CANCEL if CCB is to be canceled.
819 **----------------------------------------------------------------
823 /*----------------------------------------------------------------
824 ** Mini-script used at CCB relection to restart the nexus.
825 ** Load the DSA with the data structure address (phys) and
826 ** jump to RESEL_DSA. Jump to ABORT if CCB is to be aborted.
827 **----------------------------------------------------------------
829 struct launch restart
;
831 /*----------------------------------------------------------------
832 ** If a data transfer phase is terminated too early
833 ** (after reception of a message (i.e. DISCONNECT)),
834 ** we have to prepare a mini script to transfer
835 ** the rest of the data.
836 **----------------------------------------------------------------
840 /*----------------------------------------------------------------
841 ** The general SCSI driver provides a
842 ** pointer to a control block.
843 **----------------------------------------------------------------
845 struct scsi_cmnd
*cmd
; /* SCSI command */
846 u_char cdb_buf
[16]; /* Copy of CDB */
847 u_char sense_buf
[64];
848 int data_len
; /* Total data length */
850 /*----------------------------------------------------------------
852 ** We prepare a message to be sent after selection.
853 ** We may use a second one if the command is rescheduled
854 ** due to GETCC or QFULL.
855 ** Contents are IDENTIFY and SIMPLE_TAG.
856 ** While negotiating sync or wide transfer,
857 ** a SDTR or WDTR message is appended.
858 **----------------------------------------------------------------
860 u_char scsi_smsg
[8];
861 u_char scsi_smsg2
[8];
863 /*----------------------------------------------------------------
865 **----------------------------------------------------------------
867 u_long p_ccb
; /* BUS address of this CCB */
868 u_char sensecmd
[6]; /* Sense command */
869 u_char tag
; /* Tag for this transfer */
870 /* 255 means no tag */
875 struct ccb
* link_ccb
; /* Host adapter CCB chain */
876 struct list_head link_ccbq
; /* Link to unit CCB queue */
877 u32 startp
; /* Initial data pointer */
878 u_long magic
; /* Free / busy CCB flag */
881 #define CCB_PHYS(cp,lbl) (cp->p_ccb + offsetof(struct ccb, lbl))
884 /*========================================================================
886 ** Declaration of structs: NCR device descriptor
888 **========================================================================
891 /*----------------------------------------------------------------
892 ** The global header.
893 ** It is accessible to both the host and the script processor.
894 ** Must be cache line size aligned (32 for x86) in order to
895 ** allow cache line bursting when it is copied to/from CCB.
896 **----------------------------------------------------------------
900 /*----------------------------------------------------------------
901 ** CCBs management queues.
902 **----------------------------------------------------------------
904 struct scsi_cmnd
*waiting_list
; /* Commands waiting for a CCB */
905 /* when lcb is not allocated. */
906 struct scsi_cmnd
*done_list
; /* Commands waiting for done() */
907 /* callback to be invoked. */
908 spinlock_t smp_lock
; /* Lock for SMP threading */
910 /*----------------------------------------------------------------
911 ** Chip and controller indentification.
912 **----------------------------------------------------------------
914 int unit
; /* Unit number */
915 char inst_name
[16]; /* ncb instance name */
917 /*----------------------------------------------------------------
918 ** Initial value of some IO register bits.
919 ** These values are assumed to have been set by BIOS, and may
920 ** be used for probing adapter implementation differences.
921 **----------------------------------------------------------------
923 u_char sv_scntl0
, sv_scntl3
, sv_dmode
, sv_dcntl
, sv_ctest0
, sv_ctest3
,
924 sv_ctest4
, sv_ctest5
, sv_gpcntl
, sv_stest2
, sv_stest4
;
926 /*----------------------------------------------------------------
927 ** Actual initial value of IO register bits used by the
928 ** driver. They are loaded at initialisation according to
929 ** features that are to be enabled.
930 **----------------------------------------------------------------
932 u_char rv_scntl0
, rv_scntl3
, rv_dmode
, rv_dcntl
, rv_ctest0
, rv_ctest3
,
933 rv_ctest4
, rv_ctest5
, rv_stest2
;
935 /*----------------------------------------------------------------
936 ** Targets management.
937 ** During reselection the ncr jumps to jump_tcb.
938 ** The SFBR register is loaded with the encoded target id.
940 ** SCR_JUMP ^ IFTRUE(MASK(i, 3)), @(next tcb mod. i)
942 ** Recent chips will prefetch the 4 JUMPS using only 1 burst.
943 ** It is kind of hashcoding.
944 **----------------------------------------------------------------
946 struct link jump_tcb
[4]; /* JUMPs for reselection */
947 struct tcb target
[MAX_TARGET
]; /* Target data */
949 /*----------------------------------------------------------------
950 ** Virtual and physical bus addresses of the chip.
951 **----------------------------------------------------------------
953 void __iomem
*vaddr
; /* Virtual and bus address of */
954 unsigned long paddr
; /* chip's IO registers. */
955 unsigned long paddr2
; /* On-chip RAM bus address. */
956 volatile /* Pointer to volatile for */
957 struct ncr_reg __iomem
*reg
; /* memory mapped IO. */
959 /*----------------------------------------------------------------
960 ** SCRIPTS virtual and physical bus addresses.
961 ** 'script' is loaded in the on-chip RAM if present.
962 ** 'scripth' stays in main memory.
963 **----------------------------------------------------------------
965 struct script
*script0
; /* Copies of script and scripth */
966 struct scripth
*scripth0
; /* relocated for this ncb. */
967 struct scripth
*scripth
; /* Actual scripth virt. address */
968 u_long p_script
; /* Actual script and scripth */
969 u_long p_scripth
; /* bus addresses. */
971 /*----------------------------------------------------------------
972 ** General controller parameters and configuration.
973 **----------------------------------------------------------------
976 u_char revision_id
; /* PCI device revision id */
977 u32 irq
; /* IRQ level */
978 u32 features
; /* Chip features map */
979 u_char myaddr
; /* SCSI id of the adapter */
980 u_char maxburst
; /* log base 2 of dwords burst */
981 u_char maxwide
; /* Maximum transfer width */
982 u_char minsync
; /* Minimum sync period factor */
983 u_char maxsync
; /* Maximum sync period factor */
984 u_char maxoffs
; /* Max scsi offset */
985 u_char multiplier
; /* Clock multiplier (1,2,4) */
986 u_char clock_divn
; /* Number of clock divisors */
987 u_long clock_khz
; /* SCSI clock frequency in KHz */
989 /*----------------------------------------------------------------
990 ** Start queue management.
991 ** It is filled up by the host processor and accessed by the
992 ** SCRIPTS processor in order to start SCSI commands.
993 **----------------------------------------------------------------
995 u16 squeueput
; /* Next free slot of the queue */
996 u16 actccbs
; /* Number of allocated CCBs */
997 u16 queuedccbs
; /* Number of CCBs in start queue*/
998 u16 queuedepth
; /* Start queue depth */
1000 /*----------------------------------------------------------------
1002 **----------------------------------------------------------------
1004 struct timer_list timer
; /* Timer handler link header */
1006 u_long settle_time
; /* Resetting the SCSI BUS */
1008 /*----------------------------------------------------------------
1009 ** Debugging and profiling.
1010 **----------------------------------------------------------------
1012 struct ncr_reg regdump
; /* Register dump */
1013 u_long regtime
; /* Time it has been done */
1015 /*----------------------------------------------------------------
1016 ** Miscellaneous buffers accessed by the scripts-processor.
1017 ** They shall be DWORD aligned, because they may be read or
1018 ** written with a SCR_COPY script command.
1019 **----------------------------------------------------------------
1021 u_char msgout
[8]; /* Buffer for MESSAGE OUT */
1022 u_char msgin
[8]; /* Buffer for MESSAGE IN */
1023 u32 lastmsg
; /* Last SCSI message sent */
1024 u_char scratch
; /* Scratch for SCSI receive */
1026 /*----------------------------------------------------------------
1027 ** Miscellaneous configuration and status parameters.
1028 **----------------------------------------------------------------
1030 u_char disc
; /* Diconnection allowed */
1031 u_char scsi_mode
; /* Current SCSI BUS mode */
1032 u_char order
; /* Tag order to use */
1033 u_char verbose
; /* Verbosity for this controller*/
1034 int ncr_cache
; /* Used for cache test at init. */
1035 u_long p_ncb
; /* BUS address of this NCB */
1037 /*----------------------------------------------------------------
1038 ** Command completion handling.
1039 **----------------------------------------------------------------
1041 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
1042 struct ccb
*(ccb_done
[MAX_DONE
]);
1045 /*----------------------------------------------------------------
1046 ** Fields that should be removed or changed.
1047 **----------------------------------------------------------------
1049 struct ccb
*ccb
; /* Global CCB */
1050 struct usrcmd user
; /* Command from user */
1051 volatile u_char release_stage
; /* Synchronisation stage on release */
1054 #define NCB_SCRIPT_PHYS(np,lbl) (np->p_script + offsetof (struct script, lbl))
1055 #define NCB_SCRIPTH_PHYS(np,lbl) (np->p_scripth + offsetof (struct scripth,lbl))
1057 /*==========================================================
1060 ** Script for NCR-Processor.
1062 ** Use ncr_script_fill() to create the variable parts.
1063 ** Use ncr_script_copy_and_bind() to make a copy and
1064 ** bind to physical addresses.
1067 **==========================================================
1069 ** We have to know the offsets of all labels before
1070 ** we reach them (for forward jumps).
1071 ** Therefore we declare a struct here.
1072 ** If you make changes inside the script,
1073 ** DONT FORGET TO CHANGE THE LENGTHS HERE!
1075 **----------------------------------------------------------
1079 ** For HP Zalon/53c720 systems, the Zalon interface
1080 ** between CPU and 53c720 does prefetches, which causes
1081 ** problems with self modifying scripts. The problem
1082 ** is overcome by calling a dummy subroutine after each
1083 ** modification, to force a refetch of the script on
1084 ** return from the subroutine.
1087 #ifdef CONFIG_NCR53C8XX_PREFETCH
1088 #define PREFETCH_FLUSH_CNT 2
1089 #define PREFETCH_FLUSH SCR_CALL, PADDRH (wait_dma),
1091 #define PREFETCH_FLUSH_CNT 0
1092 #define PREFETCH_FLUSH
1096 ** Script fragments which are loaded into the on-chip RAM
1097 ** of 825A, 875 and 895 chips.
1101 ncrcmd startpos
[ 1];
1103 ncrcmd select2
[ 9 + PREFETCH_FLUSH_CNT
];
1104 ncrcmd loadpos
[ 4];
1105 ncrcmd send_ident
[ 9];
1106 ncrcmd prepare
[ 6];
1107 ncrcmd prepare2
[ 7];
1108 ncrcmd command
[ 6];
1109 ncrcmd dispatch
[ 32];
1111 ncrcmd no_data
[ 17];
1114 ncrcmd msg_in2
[ 16];
1115 ncrcmd msg_bad
[ 4];
1117 ncrcmd cleanup
[ 6];
1118 ncrcmd complete
[ 9];
1119 ncrcmd cleanup_ok
[ 8 + PREFETCH_FLUSH_CNT
];
1120 ncrcmd cleanup0
[ 1];
1121 #ifndef SCSI_NCR_CCB_DONE_SUPPORT
1122 ncrcmd signal
[ 12];
1125 ncrcmd done_pos
[ 1];
1126 ncrcmd done_plug
[ 2];
1127 ncrcmd done_end
[ 7];
1129 ncrcmd save_dp
[ 7];
1130 ncrcmd restore_dp
[ 5];
1131 ncrcmd disconnect
[ 10];
1132 ncrcmd msg_out
[ 9];
1133 ncrcmd msg_out_done
[ 7];
1135 ncrcmd reselect
[ 8];
1136 ncrcmd reselected
[ 8];
1137 ncrcmd resel_dsa
[ 6 + PREFETCH_FLUSH_CNT
];
1138 ncrcmd loadpos1
[ 4];
1139 ncrcmd resel_lun
[ 6];
1140 ncrcmd resel_tag
[ 6];
1141 ncrcmd jump_to_nexus
[ 4 + PREFETCH_FLUSH_CNT
];
1142 ncrcmd nexus_indirect
[ 4];
1143 ncrcmd resel_notag
[ 4];
1144 ncrcmd data_in
[MAX_SCATTERL
* 4];
1145 ncrcmd data_in2
[ 4];
1146 ncrcmd data_out
[MAX_SCATTERL
* 4];
1147 ncrcmd data_out2
[ 4];
1151 ** Script fragments which stay in main memory for all chips.
1154 ncrcmd tryloop
[MAX_START
*2];
1155 ncrcmd tryloop2
[ 2];
1156 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
1157 ncrcmd done_queue
[MAX_DONE
*5];
1158 ncrcmd done_queue2
[ 2];
1160 ncrcmd select_no_atn
[ 8];
1162 ncrcmd skip
[ 9 + PREFETCH_FLUSH_CNT
];
1164 ncrcmd par_err_data_in
[ 6];
1165 ncrcmd par_err_other
[ 4];
1166 ncrcmd msg_reject
[ 8];
1167 ncrcmd msg_ign_residue
[ 24];
1168 ncrcmd msg_extended
[ 10];
1169 ncrcmd msg_ext_2
[ 10];
1170 ncrcmd msg_wdtr
[ 14];
1171 ncrcmd send_wdtr
[ 7];
1172 ncrcmd msg_ext_3
[ 10];
1173 ncrcmd msg_sdtr
[ 14];
1174 ncrcmd send_sdtr
[ 7];
1175 ncrcmd nego_bad_phase
[ 4];
1176 ncrcmd msg_out_abort
[ 10];
1177 ncrcmd hdata_in
[MAX_SCATTERH
* 4];
1178 ncrcmd hdata_in2
[ 2];
1179 ncrcmd hdata_out
[MAX_SCATTERH
* 4];
1180 ncrcmd hdata_out2
[ 2];
1182 ncrcmd aborttag
[ 4];
1184 ncrcmd abort_resel
[ 20];
1185 ncrcmd resend_ident
[ 4];
1186 ncrcmd clratn_go_on
[ 3];
1187 ncrcmd nxtdsp_go_on
[ 1];
1188 ncrcmd sdata_in
[ 8];
1189 ncrcmd data_io
[ 18];
1190 ncrcmd bad_identify
[ 12];
1191 ncrcmd bad_i_t_l
[ 4];
1192 ncrcmd bad_i_t_l_q
[ 4];
1193 ncrcmd bad_target
[ 8];
1194 ncrcmd bad_status
[ 8];
1195 ncrcmd start_ram
[ 4 + PREFETCH_FLUSH_CNT
];
1196 ncrcmd start_ram0
[ 4];
1197 ncrcmd sto_restart
[ 5];
1198 ncrcmd wait_dma
[ 2];
1199 ncrcmd snooptest
[ 9];
1200 ncrcmd snoopend
[ 2];
1203 /*==========================================================
1206 ** Function headers.
1209 **==========================================================
1212 static void ncr_alloc_ccb (struct ncb
*np
, u_char tn
, u_char ln
);
1213 static void ncr_complete (struct ncb
*np
, struct ccb
*cp
);
1214 static void ncr_exception (struct ncb
*np
);
1215 static void ncr_free_ccb (struct ncb
*np
, struct ccb
*cp
);
1216 static void ncr_init_ccb (struct ncb
*np
, struct ccb
*cp
);
1217 static void ncr_init_tcb (struct ncb
*np
, u_char tn
);
1218 static struct lcb
* ncr_alloc_lcb (struct ncb
*np
, u_char tn
, u_char ln
);
1219 static struct lcb
* ncr_setup_lcb (struct ncb
*np
, struct scsi_device
*sdev
);
1220 static void ncr_getclock (struct ncb
*np
, int mult
);
1221 static void ncr_selectclock (struct ncb
*np
, u_char scntl3
);
1222 static struct ccb
*ncr_get_ccb (struct ncb
*np
, struct scsi_cmnd
*cmd
);
1223 static void ncr_chip_reset (struct ncb
*np
, int delay
);
1224 static void ncr_init (struct ncb
*np
, int reset
, char * msg
, u_long code
);
1225 static int ncr_int_sbmc (struct ncb
*np
);
1226 static int ncr_int_par (struct ncb
*np
);
1227 static void ncr_int_ma (struct ncb
*np
);
1228 static void ncr_int_sir (struct ncb
*np
);
1229 static void ncr_int_sto (struct ncb
*np
);
1230 static void ncr_negotiate (struct ncb
* np
, struct tcb
* tp
);
1231 static int ncr_prepare_nego(struct ncb
*np
, struct ccb
*cp
, u_char
*msgptr
);
1233 static void ncr_script_copy_and_bind
1234 (struct ncb
*np
, ncrcmd
*src
, ncrcmd
*dst
, int len
);
1235 static void ncr_script_fill (struct script
* scr
, struct scripth
* scripth
);
1236 static int ncr_scatter (struct ncb
*np
, struct ccb
*cp
, struct scsi_cmnd
*cmd
);
1237 static void ncr_getsync (struct ncb
*np
, u_char sfac
, u_char
*fakp
, u_char
*scntl3p
);
1238 static void ncr_setsync (struct ncb
*np
, struct ccb
*cp
, u_char scntl3
, u_char sxfer
);
1239 static void ncr_setup_tags (struct ncb
*np
, struct scsi_device
*sdev
);
1240 static void ncr_setwide (struct ncb
*np
, struct ccb
*cp
, u_char wide
, u_char ack
);
1241 static int ncr_snooptest (struct ncb
*np
);
1242 static void ncr_timeout (struct ncb
*np
);
1243 static void ncr_wakeup (struct ncb
*np
, u_long code
);
1244 static void ncr_wakeup_done (struct ncb
*np
);
1245 static void ncr_start_next_ccb (struct ncb
*np
, struct lcb
* lp
, int maxn
);
1246 static void ncr_put_start_queue(struct ncb
*np
, struct ccb
*cp
);
1248 static void insert_into_waiting_list(struct ncb
*np
, struct scsi_cmnd
*cmd
);
1249 static struct scsi_cmnd
*retrieve_from_waiting_list(int to_remove
, struct ncb
*np
, struct scsi_cmnd
*cmd
);
1250 static void process_waiting_list(struct ncb
*np
, int sts
);
1252 #define remove_from_waiting_list(np, cmd) \
1253 retrieve_from_waiting_list(1, (np), (cmd))
1254 #define requeue_waiting_list(np) process_waiting_list((np), DID_OK)
1255 #define reset_waiting_list(np) process_waiting_list((np), DID_RESET)
1257 static inline char *ncr_name (struct ncb
*np
)
1259 return np
->inst_name
;
1263 /*==========================================================
1266 ** Scripts for NCR-Processor.
1268 ** Use ncr_script_bind for binding to physical addresses.
1271 **==========================================================
1273 ** NADDR generates a reference to a field of the controller data.
1274 ** PADDR generates a reference to another part of the script.
1275 ** RADDR generates a reference to a script processor register.
1276 ** FADDR generates a reference to a script processor register
1279 **----------------------------------------------------------
1282 #define RELOC_SOFTC 0x40000000
1283 #define RELOC_LABEL 0x50000000
1284 #define RELOC_REGISTER 0x60000000
1286 #define RELOC_KVAR 0x70000000
1288 #define RELOC_LABELH 0x80000000
1289 #define RELOC_MASK 0xf0000000
1291 #define NADDR(label) (RELOC_SOFTC | offsetof(struct ncb, label))
1292 #define PADDR(label) (RELOC_LABEL | offsetof(struct script, label))
1293 #define PADDRH(label) (RELOC_LABELH | offsetof(struct scripth, label))
1294 #define RADDR(label) (RELOC_REGISTER | REG(label))
1295 #define FADDR(label,ofs)(RELOC_REGISTER | ((REG(label))+(ofs)))
1297 #define KVAR(which) (RELOC_KVAR | (which))
1301 #define SCRIPT_KVAR_JIFFIES (0)
1302 #define SCRIPT_KVAR_FIRST SCRIPT_KVAR_JIFFIES
1303 #define SCRIPT_KVAR_LAST SCRIPT_KVAR_JIFFIES
1305 * Kernel variables referenced in the scripts.
1306 * THESE MUST ALL BE ALIGNED TO A 4-BYTE BOUNDARY.
1308 static void *script_kvars
[] __initdata
=
1309 { (void *)&jiffies
};
1312 static struct script script0 __initdata
= {
1313 /*--------------------------< START >-----------------------*/ {
1315 ** This NOP will be patched with LED ON
1316 ** SCR_REG_REG (gpreg, SCR_AND, 0xfe)
1323 SCR_FROM_REG (ctest2
),
1326 ** Then jump to a certain point in tryloop.
1327 ** Due to the lack of indirect addressing the code
1328 ** is self modifying here.
1331 }/*-------------------------< STARTPOS >--------------------*/,{
1334 }/*-------------------------< SELECT >----------------------*/,{
1336 ** DSA contains the address of a scheduled
1339 ** SCRATCHA contains the address of the script,
1340 ** which starts the next entry.
1342 ** Set Initiator mode.
1344 ** (Target mode is left as an exercise for the reader)
1349 SCR_LOAD_REG (HS_REG
, HS_SELECTING
),
1353 ** And try to select this target.
1355 SCR_SEL_TBL_ATN
^ offsetof (struct dsb
, select
),
1358 }/*-------------------------< SELECT2 >----------------------*/,{
1360 ** Now there are 4 possibilities:
1362 ** (1) The ncr loses arbitration.
1363 ** This is ok, because it will try again,
1364 ** when the bus becomes idle.
1365 ** (But beware of the timeout function!)
1367 ** (2) The ncr is reselected.
1368 ** Then the script processor takes the jump
1369 ** to the RESELECT label.
1371 ** (3) The ncr wins arbitration.
1372 ** Then it will execute SCRIPTS instruction until
1373 ** the next instruction that checks SCSI phase.
1374 ** Then will stop and wait for selection to be
1375 ** complete or selection time-out to occur.
1376 ** As a result the SCRIPTS instructions until
1377 ** LOADPOS + 2 should be executed in parallel with
1378 ** the SCSI core performing selection.
1382 ** The M_REJECT problem seems to be due to a selection
1384 ** Wait immediately for the selection to complete.
1385 ** (2.5x behaves so)
1387 SCR_JUMPR
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
1391 ** Next time use the next slot.
1397 ** The ncr doesn't have an indirect load
1398 ** or store command. So we have to
1399 ** copy part of the control block to a
1400 ** fixed place, where we can access it.
1402 ** We patch the address part of a
1403 ** COPY command with the DSA-register.
1409 ** Flush script prefetch if required
1413 ** then we do the actual copy.
1415 SCR_COPY (sizeof (struct head
)),
1417 ** continued after the next label ...
1419 }/*-------------------------< LOADPOS >---------------------*/,{
1423 ** Wait for the next phase or the selection
1424 ** to complete or time-out.
1426 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
1429 }/*-------------------------< SEND_IDENT >----------------------*/,{
1431 ** Selection complete.
1432 ** Send the IDENTIFY and SIMPLE_TAG messages
1433 ** (and the M_X_SYNC_REQ message)
1435 SCR_MOVE_TBL
^ SCR_MSG_OUT
,
1436 offsetof (struct dsb
, smsg
),
1437 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_OUT
)),
1438 PADDRH (resend_ident
),
1439 SCR_LOAD_REG (scratcha
, 0x80),
1444 }/*-------------------------< PREPARE >----------------------*/,{
1446 ** load the savep (saved pointer) into
1447 ** the TEMP register (actual pointer)
1450 NADDR (header
.savep
),
1453 ** Initialize the status registers
1456 NADDR (header
.status
),
1458 }/*-------------------------< PREPARE2 >---------------------*/,{
1460 ** Initialize the msgout buffer with a NOOP message.
1462 SCR_LOAD_REG (scratcha
, M_NOOP
),
1473 ** Anticipate the COMMAND phase.
1474 ** This is the normal case for initial selection.
1476 SCR_JUMP
^ IFFALSE (WHEN (SCR_COMMAND
)),
1479 }/*-------------------------< COMMAND >--------------------*/,{
1481 ** ... and send the command
1483 SCR_MOVE_TBL
^ SCR_COMMAND
,
1484 offsetof (struct dsb
, cmd
),
1486 ** If status is still HS_NEGOTIATE, negotiation failed.
1487 ** We check this here, since we want to do that
1490 SCR_FROM_REG (HS_REG
),
1492 SCR_INT
^ IFTRUE (DATA (HS_NEGOTIATE
)),
1495 }/*-----------------------< DISPATCH >----------------------*/,{
1497 ** MSG_IN is the only phase that shall be
1498 ** entered at least once for each (re)selection.
1499 ** So we test it first.
1501 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_IN
)),
1504 SCR_RETURN
^ IFTRUE (IF (SCR_DATA_OUT
)),
1507 ** DEL 397 - 53C875 Rev 3 - Part Number 609-0392410 - ITEM 4.
1508 ** Possible data corruption during Memory Write and Invalidate.
1509 ** This work-around resets the addressing logic prior to the
1510 ** start of the first MOVE of a DATA IN phase.
1511 ** (See Documentation/scsi/ncr53c8xx.txt for more information)
1513 SCR_JUMPR
^ IFFALSE (IF (SCR_DATA_IN
)),
1520 SCR_JUMP
^ IFTRUE (IF (SCR_STATUS
)),
1522 SCR_JUMP
^ IFTRUE (IF (SCR_COMMAND
)),
1524 SCR_JUMP
^ IFTRUE (IF (SCR_MSG_OUT
)),
1527 ** Discard one illegal phase byte, if required.
1529 SCR_LOAD_REG (scratcha
, XE_BAD_PHASE
),
1534 SCR_JUMPR
^ IFFALSE (IF (SCR_ILG_OUT
)),
1536 SCR_MOVE_ABS (1) ^ SCR_ILG_OUT
,
1538 SCR_JUMPR
^ IFFALSE (IF (SCR_ILG_IN
)),
1540 SCR_MOVE_ABS (1) ^ SCR_ILG_IN
,
1545 }/*-------------------------< CLRACK >----------------------*/,{
1547 ** Terminate possible pending message phase.
1554 }/*-------------------------< NO_DATA >--------------------*/,{
1556 ** The target wants to tranfer too much data
1557 ** or in the wrong direction.
1558 ** Remember that in extended error.
1560 SCR_LOAD_REG (scratcha
, XE_EXTRA_DATA
),
1566 ** Discard one data byte, if required.
1568 SCR_JUMPR
^ IFFALSE (WHEN (SCR_DATA_OUT
)),
1570 SCR_MOVE_ABS (1) ^ SCR_DATA_OUT
,
1572 SCR_JUMPR
^ IFFALSE (IF (SCR_DATA_IN
)),
1574 SCR_MOVE_ABS (1) ^ SCR_DATA_IN
,
1577 ** .. and repeat as required.
1584 }/*-------------------------< STATUS >--------------------*/,{
1588 SCR_MOVE_ABS (1) ^ SCR_STATUS
,
1591 ** save status to scsi_status.
1592 ** mark as complete.
1594 SCR_TO_REG (SS_REG
),
1596 SCR_LOAD_REG (HS_REG
, HS_COMPLETE
),
1600 }/*-------------------------< MSG_IN >--------------------*/,{
1602 ** Get the first byte of the message
1603 ** and save it to SCRATCHA.
1605 ** The script processor doesn't negate the
1606 ** ACK signal after this transfer.
1608 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
1610 }/*-------------------------< MSG_IN2 >--------------------*/,{
1612 ** Handle this message.
1614 SCR_JUMP
^ IFTRUE (DATA (M_COMPLETE
)),
1616 SCR_JUMP
^ IFTRUE (DATA (M_DISCONNECT
)),
1618 SCR_JUMP
^ IFTRUE (DATA (M_SAVE_DP
)),
1620 SCR_JUMP
^ IFTRUE (DATA (M_RESTORE_DP
)),
1622 SCR_JUMP
^ IFTRUE (DATA (M_EXTENDED
)),
1623 PADDRH (msg_extended
),
1624 SCR_JUMP
^ IFTRUE (DATA (M_NOOP
)),
1626 SCR_JUMP
^ IFTRUE (DATA (M_REJECT
)),
1627 PADDRH (msg_reject
),
1628 SCR_JUMP
^ IFTRUE (DATA (M_IGN_RESIDUE
)),
1629 PADDRH (msg_ign_residue
),
1631 ** Rest of the messages left as
1634 ** Unimplemented messages:
1635 ** fall through to MSG_BAD.
1637 }/*-------------------------< MSG_BAD >------------------*/,{
1639 ** unimplemented message - reject it.
1643 SCR_LOAD_REG (scratcha
, M_REJECT
),
1645 }/*-------------------------< SETMSG >----------------------*/,{
1653 }/*-------------------------< CLEANUP >-------------------*/,{
1655 ** dsa: Pointer to ccb
1656 ** or xxxxxxFF (no ccb)
1658 ** HS_REG: Host-Status (<>0!)
1662 SCR_JUMP
^ IFTRUE (DATA (0xff)),
1666 ** complete the cleanup.
1671 }/*-------------------------< COMPLETE >-----------------*/,{
1673 ** Complete message.
1675 ** Copy TEMP register to LASTP in header.
1679 NADDR (header
.lastp
),
1681 ** When we terminate the cycle by clearing ACK,
1682 ** the target may disconnect immediately.
1684 ** We don't want to be told of an
1685 ** "unexpected disconnect",
1686 ** so we disable this feature.
1688 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
1691 ** Terminate cycle ...
1693 SCR_CLR (SCR_ACK
|SCR_ATN
),
1696 ** ... and wait for the disconnect.
1700 }/*-------------------------< CLEANUP_OK >----------------*/,{
1702 ** Save host status to header.
1706 NADDR (header
.status
),
1708 ** and copy back the header to the ccb.
1714 ** Flush script prefetch if required
1717 SCR_COPY (sizeof (struct head
)),
1719 }/*-------------------------< CLEANUP0 >--------------------*/,{
1721 }/*-------------------------< SIGNAL >----------------------*/,{
1723 ** if job not completed ...
1725 SCR_FROM_REG (HS_REG
),
1728 ** ... start the next command.
1730 SCR_JUMP
^ IFTRUE (MASK (0, (HS_DONEMASK
|HS_SKIPMASK
))),
1733 ** If command resulted in not GOOD status,
1734 ** call the C code if needed.
1736 SCR_FROM_REG (SS_REG
),
1738 SCR_CALL
^ IFFALSE (DATA (S_GOOD
)),
1739 PADDRH (bad_status
),
1741 #ifndef SCSI_NCR_CCB_DONE_SUPPORT
1744 ** ... signal completion to the host
1749 ** Auf zu neuen Schandtaten!
1754 #else /* defined SCSI_NCR_CCB_DONE_SUPPORT */
1757 ** ... signal completion to the host
1760 }/*------------------------< DONE_POS >---------------------*/,{
1761 PADDRH (done_queue
),
1762 }/*------------------------< DONE_PLUG >--------------------*/,{
1765 }/*------------------------< DONE_END >---------------------*/,{
1774 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
1776 }/*-------------------------< SAVE_DP >------------------*/,{
1779 ** Copy TEMP register to SAVEP in header.
1783 NADDR (header
.savep
),
1788 }/*-------------------------< RESTORE_DP >---------------*/,{
1790 ** RESTORE_DP message:
1791 ** Copy SAVEP in header to TEMP register.
1794 NADDR (header
.savep
),
1799 }/*-------------------------< DISCONNECT >---------------*/,{
1801 ** DISCONNECTing ...
1803 ** disable the "unexpected disconnect" feature,
1804 ** and remove the ACK signal.
1806 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
1808 SCR_CLR (SCR_ACK
|SCR_ATN
),
1811 ** Wait for the disconnect.
1816 ** Status is: DISCONNECTED.
1818 SCR_LOAD_REG (HS_REG
, HS_DISCONNECT
),
1823 }/*-------------------------< MSG_OUT >-------------------*/,{
1825 ** The target requests a message.
1827 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT
,
1833 ** If it was no ABORT message ...
1835 SCR_JUMP
^ IFTRUE (DATA (M_ABORT
)),
1836 PADDRH (msg_out_abort
),
1838 ** ... wait for the next phase
1839 ** if it's a message out, send it again, ...
1841 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_OUT
)),
1843 }/*-------------------------< MSG_OUT_DONE >--------------*/,{
1845 ** ... else clear the message ...
1847 SCR_LOAD_REG (scratcha
, M_NOOP
),
1853 ** ... and process the next phase
1857 }/*-------------------------< IDLE >------------------------*/,{
1860 ** Wait for reselect.
1861 ** This NOP will be patched with LED OFF
1862 ** SCR_REG_REG (gpreg, SCR_OR, 0x01)
1866 }/*-------------------------< RESELECT >--------------------*/,{
1868 ** make the DSA invalid.
1870 SCR_LOAD_REG (dsa
, 0xff),
1874 SCR_LOAD_REG (HS_REG
, HS_IN_RESELECT
),
1877 ** Sleep waiting for a reselection.
1878 ** If SIGP is set, special treatment.
1880 ** Zu allem bereit ..
1884 }/*-------------------------< RESELECTED >------------------*/,{
1886 ** This NOP will be patched with LED ON
1887 ** SCR_REG_REG (gpreg, SCR_AND, 0xfe)
1892 ** ... zu nichts zu gebrauchen ?
1894 ** load the target id into the SFBR
1895 ** and jump to the control block.
1897 ** Look at the declarations of
1902 ** to understand what's going on.
1904 SCR_REG_SFBR (ssid
, SCR_AND
, 0x8F),
1911 }/*-------------------------< RESEL_DSA >-------------------*/,{
1913 ** Ack the IDENTIFY or TAG previously received.
1918 ** The ncr doesn't have an indirect load
1919 ** or store command. So we have to
1920 ** copy part of the control block to a
1921 ** fixed place, where we can access it.
1923 ** We patch the address part of a
1924 ** COPY command with the DSA-register.
1930 ** Flush script prefetch if required
1934 ** then we do the actual copy.
1936 SCR_COPY (sizeof (struct head
)),
1938 ** continued after the next label ...
1941 }/*-------------------------< LOADPOS1 >-------------------*/,{
1945 ** The DSA contains the data structure address.
1950 }/*-------------------------< RESEL_LUN >-------------------*/,{
1952 ** come back to this point
1953 ** to get an IDENTIFY message
1954 ** Wait for a msg_in phase.
1956 SCR_INT
^ IFFALSE (WHEN (SCR_MSG_IN
)),
1957 SIR_RESEL_NO_MSG_IN
,
1960 ** Read the data directly from the BUS DATA lines.
1961 ** This helps to support very old SCSI devices that
1962 ** may reselect without sending an IDENTIFY.
1964 SCR_FROM_REG (sbdl
),
1967 ** It should be an Identify message.
1971 }/*-------------------------< RESEL_TAG >-------------------*/,{
1973 ** Read IDENTIFY + SIMPLE + TAG using a single MOVE.
1974 ** Agressive optimization, is'nt it?
1975 ** No need to test the SIMPLE TAG message, since the
1976 ** driver only supports conformant devices for tags. ;-)
1978 SCR_MOVE_ABS (3) ^ SCR_MSG_IN
,
1981 ** Read the TAG from the SIDL.
1982 ** Still an aggressive optimization. ;-)
1983 ** Compute the CCB indirect jump address which
1984 ** is (#TAG*2 & 0xfc) due to tag numbering using
1985 ** 1,3,5..MAXTAGS*2+1 actual values.
1987 SCR_REG_SFBR (sidl
, SCR_SHL
, 0),
1989 SCR_SFBR_REG (temp
, SCR_AND
, 0xfc),
1991 }/*-------------------------< JUMP_TO_NEXUS >-------------------*/,{
1994 PADDR (nexus_indirect
),
1996 ** Flush script prefetch if required
2000 }/*-------------------------< NEXUS_INDIRECT >-------------------*/,{
2005 }/*-------------------------< RESEL_NOTAG >-------------------*/,{
2008 ** Read an throw away the IDENTIFY.
2010 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2013 PADDR (jump_to_nexus
),
2014 }/*-------------------------< DATA_IN >--------------------*/,{
2016 ** Because the size depends on the
2017 ** #define MAX_SCATTERL parameter,
2018 ** it is filled in at runtime.
2020 ** ##===========< i=0; i<MAX_SCATTERL >=========
2021 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN)),
2022 ** || PADDR (dispatch),
2023 ** || SCR_MOVE_TBL ^ SCR_DATA_IN,
2024 ** || offsetof (struct dsb, data[ i]),
2025 ** ##==========================================
2027 **---------------------------------------------------------
2030 }/*-------------------------< DATA_IN2 >-------------------*/,{
2035 }/*-------------------------< DATA_OUT >--------------------*/,{
2037 ** Because the size depends on the
2038 ** #define MAX_SCATTERL parameter,
2039 ** it is filled in at runtime.
2041 ** ##===========< i=0; i<MAX_SCATTERL >=========
2042 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT)),
2043 ** || PADDR (dispatch),
2044 ** || SCR_MOVE_TBL ^ SCR_DATA_OUT,
2045 ** || offsetof (struct dsb, data[ i]),
2046 ** ##==========================================
2048 **---------------------------------------------------------
2051 }/*-------------------------< DATA_OUT2 >-------------------*/,{
2056 }/*--------------------------------------------------------*/
2059 static struct scripth scripth0 __initdata
= {
2060 /*-------------------------< TRYLOOP >---------------------*/{
2062 ** Start the next entry.
2063 ** Called addresses point to the launch script in the CCB.
2064 ** They are patched by the main processor.
2066 ** Because the size depends on the
2067 ** #define MAX_START parameter, it is filled
2070 **-----------------------------------------------------------
2072 ** ##===========< I=0; i<MAX_START >===========
2075 ** ##==========================================
2077 **-----------------------------------------------------------
2080 }/*------------------------< TRYLOOP2 >---------------------*/,{
2084 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
2086 }/*------------------------< DONE_QUEUE >-------------------*/,{
2088 ** Copy the CCB address to the next done entry.
2089 ** Because the size depends on the
2090 ** #define MAX_DONE parameter, it is filled
2093 **-----------------------------------------------------------
2095 ** ##===========< I=0; i<MAX_DONE >===========
2096 ** || SCR_COPY (sizeof(struct ccb *),
2097 ** || NADDR (header.cp),
2098 ** || NADDR (ccb_done[i]),
2100 ** || PADDR (done_end),
2101 ** ##==========================================
2103 **-----------------------------------------------------------
2106 }/*------------------------< DONE_QUEUE2 >------------------*/,{
2108 PADDRH (done_queue
),
2110 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
2111 }/*------------------------< SELECT_NO_ATN >-----------------*/,{
2113 ** Set Initiator mode.
2114 ** And try to select this target without ATN.
2119 SCR_LOAD_REG (HS_REG
, HS_SELECTING
),
2121 SCR_SEL_TBL
^ offsetof (struct dsb
, select
),
2126 }/*-------------------------< CANCEL >------------------------*/,{
2128 SCR_LOAD_REG (scratcha
, HS_ABORTED
),
2132 }/*-------------------------< SKIP >------------------------*/,{
2133 SCR_LOAD_REG (scratcha
, 0),
2136 ** This entry has been canceled.
2137 ** Next time use the next slot.
2143 ** The ncr doesn't have an indirect load
2144 ** or store command. So we have to
2145 ** copy part of the control block to a
2146 ** fixed place, where we can access it.
2148 ** We patch the address part of a
2149 ** COPY command with the DSA-register.
2155 ** Flush script prefetch if required
2159 ** then we do the actual copy.
2161 SCR_COPY (sizeof (struct head
)),
2163 ** continued after the next label ...
2165 }/*-------------------------< SKIP2 >---------------------*/,{
2169 ** Initialize the status registers
2172 NADDR (header
.status
),
2175 ** Force host status.
2177 SCR_FROM_REG (scratcha
),
2179 SCR_JUMPR
^ IFFALSE (MASK (0, HS_DONEMASK
)),
2181 SCR_REG_REG (HS_REG
, SCR_OR
, HS_SKIPMASK
),
2185 SCR_TO_REG (HS_REG
),
2187 SCR_LOAD_REG (SS_REG
, S_GOOD
),
2192 },/*-------------------------< PAR_ERR_DATA_IN >---------------*/{
2194 ** Ignore all data in byte, until next phase
2196 SCR_JUMP
^ IFFALSE (WHEN (SCR_DATA_IN
)),
2197 PADDRH (par_err_other
),
2198 SCR_MOVE_ABS (1) ^ SCR_DATA_IN
,
2202 },/*-------------------------< PAR_ERR_OTHER >------------------*/{
2206 SCR_REG_REG (PS_REG
, SCR_ADD
, 0x01),
2209 ** jump to dispatcher.
2213 }/*-------------------------< MSG_REJECT >---------------*/,{
2215 ** If a negotiation was in progress,
2216 ** negotiation failed.
2217 ** Otherwise, let the C code print
2220 SCR_FROM_REG (HS_REG
),
2222 SCR_INT
^ IFFALSE (DATA (HS_NEGOTIATE
)),
2223 SIR_REJECT_RECEIVED
,
2224 SCR_INT
^ IFTRUE (DATA (HS_NEGOTIATE
)),
2229 }/*-------------------------< MSG_IGN_RESIDUE >----------*/,{
2235 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2238 ** get residue size.
2240 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2243 ** Size is 0 .. ignore message.
2245 SCR_JUMP
^ IFTRUE (DATA (0)),
2248 ** Size is not 1 .. have to interrupt.
2250 SCR_JUMPR
^ IFFALSE (DATA (1)),
2253 ** Check for residue byte in swide register
2255 SCR_FROM_REG (scntl2
),
2257 SCR_JUMPR
^ IFFALSE (MASK (WSR
, WSR
)),
2260 ** There IS data in the swide register.
2263 SCR_REG_REG (scntl2
, SCR_OR
, WSR
),
2268 ** Load again the size to the sfbr register.
2270 SCR_FROM_REG (scratcha
),
2277 }/*-------------------------< MSG_EXTENDED >-------------*/,{
2283 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2288 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2292 SCR_JUMP
^ IFTRUE (DATA (3)),
2294 SCR_JUMP
^ IFFALSE (DATA (2)),
2296 }/*-------------------------< MSG_EXT_2 >----------------*/,{
2299 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2302 ** get extended message code.
2304 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2306 SCR_JUMP
^ IFTRUE (DATA (M_X_WIDE_REQ
)),
2309 ** unknown extended message
2313 }/*-------------------------< MSG_WDTR >-----------------*/,{
2316 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2319 ** get data bus width
2321 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2324 ** let the host do the real work.
2329 ** let the target fetch our answer.
2335 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
2336 PADDRH (nego_bad_phase
),
2338 }/*-------------------------< SEND_WDTR >----------------*/,{
2340 ** Send the M_X_WIDE_REQ
2342 SCR_MOVE_ABS (4) ^ SCR_MSG_OUT
,
2348 PADDR (msg_out_done
),
2350 }/*-------------------------< MSG_EXT_3 >----------------*/,{
2353 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2356 ** get extended message code.
2358 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2360 SCR_JUMP
^ IFTRUE (DATA (M_X_SYNC_REQ
)),
2363 ** unknown extended message
2368 }/*-------------------------< MSG_SDTR >-----------------*/,{
2371 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2374 ** get period and offset
2376 SCR_MOVE_ABS (2) ^ SCR_MSG_IN
,
2379 ** let the host do the real work.
2384 ** let the target fetch our answer.
2390 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
2391 PADDRH (nego_bad_phase
),
2393 }/*-------------------------< SEND_SDTR >-------------*/,{
2395 ** Send the M_X_SYNC_REQ
2397 SCR_MOVE_ABS (5) ^ SCR_MSG_OUT
,
2403 PADDR (msg_out_done
),
2405 }/*-------------------------< NEGO_BAD_PHASE >------------*/,{
2411 }/*-------------------------< MSG_OUT_ABORT >-------------*/,{
2413 ** After ABORT message,
2415 ** expect an immediate disconnect, ...
2417 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
2419 SCR_CLR (SCR_ACK
|SCR_ATN
),
2424 ** ... and set the status to "ABORTED"
2426 SCR_LOAD_REG (HS_REG
, HS_ABORTED
),
2431 }/*-------------------------< HDATA_IN >-------------------*/,{
2433 ** Because the size depends on the
2434 ** #define MAX_SCATTERH parameter,
2435 ** it is filled in at runtime.
2437 ** ##==< i=MAX_SCATTERL; i<MAX_SCATTERL+MAX_SCATTERH >==
2438 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN)),
2439 ** || PADDR (dispatch),
2440 ** || SCR_MOVE_TBL ^ SCR_DATA_IN,
2441 ** || offsetof (struct dsb, data[ i]),
2442 ** ##===================================================
2444 **---------------------------------------------------------
2447 }/*-------------------------< HDATA_IN2 >------------------*/,{
2451 }/*-------------------------< HDATA_OUT >-------------------*/,{
2453 ** Because the size depends on the
2454 ** #define MAX_SCATTERH parameter,
2455 ** it is filled in at runtime.
2457 ** ##==< i=MAX_SCATTERL; i<MAX_SCATTERL+MAX_SCATTERH >==
2458 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT)),
2459 ** || PADDR (dispatch),
2460 ** || SCR_MOVE_TBL ^ SCR_DATA_OUT,
2461 ** || offsetof (struct dsb, data[ i]),
2462 ** ##===================================================
2464 **---------------------------------------------------------
2467 }/*-------------------------< HDATA_OUT2 >------------------*/,{
2471 }/*-------------------------< RESET >----------------------*/,{
2473 ** Send a M_RESET message if bad IDENTIFY
2474 ** received on reselection.
2476 SCR_LOAD_REG (scratcha
, M_ABORT_TAG
),
2479 PADDRH (abort_resel
),
2480 }/*-------------------------< ABORTTAG >-------------------*/,{
2482 ** Abort a wrong tag received on reselection.
2484 SCR_LOAD_REG (scratcha
, M_ABORT_TAG
),
2487 PADDRH (abort_resel
),
2488 }/*-------------------------< ABORT >----------------------*/,{
2490 ** Abort a reselection when no active CCB.
2492 SCR_LOAD_REG (scratcha
, M_ABORT
),
2494 }/*-------------------------< ABORT_RESEL >----------------*/,{
2504 ** we expect an immediate disconnect
2506 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
2508 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT
,
2513 SCR_CLR (SCR_ACK
|SCR_ATN
),
2519 }/*-------------------------< RESEND_IDENT >-------------------*/,{
2521 ** The target stays in MSG OUT phase after having acked
2522 ** Identify [+ Tag [+ Extended message ]]. Targets shall
2523 ** behave this way on parity error.
2524 ** We must send it again all the messages.
2526 SCR_SET (SCR_ATN
), /* Shall be asserted 2 deskew delays before the */
2527 0, /* 1rst ACK = 90 ns. Hope the NCR is'nt too fast */
2530 }/*-------------------------< CLRATN_GO_ON >-------------------*/,{
2534 }/*-------------------------< NXTDSP_GO_ON >-------------------*/,{
2536 }/*-------------------------< SDATA_IN >-------------------*/,{
2537 SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_IN
)),
2539 SCR_MOVE_TBL
^ SCR_DATA_IN
,
2540 offsetof (struct dsb
, sense
),
2545 }/*-------------------------< DATA_IO >--------------------*/,{
2547 ** We jump here if the data direction was unknown at the
2548 ** time we had to queue the command to the scripts processor.
2549 ** Pointers had been set as follow in this situation:
2550 ** savep --> DATA_IO
2551 ** lastp --> start pointer when DATA_IN
2552 ** goalp --> goal pointer when DATA_IN
2553 ** wlastp --> start pointer when DATA_OUT
2554 ** wgoalp --> goal pointer when DATA_OUT
2555 ** This script sets savep/lastp/goalp according to the
2556 ** direction chosen by the target.
2558 SCR_JUMPR
^ IFTRUE (WHEN (SCR_DATA_OUT
)),
2561 ** Direction is DATA IN.
2562 ** Warning: we jump here, even when phase is DATA OUT.
2565 NADDR (header
.lastp
),
2566 NADDR (header
.savep
),
2569 ** Jump to the SCRIPTS according to actual direction.
2572 NADDR (header
.savep
),
2577 ** Direction is DATA OUT.
2580 NADDR (header
.wlastp
),
2581 NADDR (header
.lastp
),
2583 NADDR (header
.wgoalp
),
2584 NADDR (header
.goalp
),
2587 }/*-------------------------< BAD_IDENTIFY >---------------*/,{
2589 ** If message phase but not an IDENTIFY,
2590 ** get some help from the C code.
2591 ** Old SCSI device may behave so.
2593 SCR_JUMPR
^ IFTRUE (MASK (0x80, 0x80)),
2596 SIR_RESEL_NO_IDENTIFY
,
2600 ** Message is an IDENTIFY, but lun is unknown.
2601 ** Read the message, since we got it directly
2602 ** from the SCSI BUS data lines.
2603 ** Signal problem to C code for logging the event.
2604 ** Send a M_ABORT to clear all pending tasks.
2608 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2612 }/*-------------------------< BAD_I_T_L >------------------*/,{
2614 ** We donnot have a task for that I_T_L.
2615 ** Signal problem to C code for logging the event.
2616 ** Send a M_ABORT message.
2619 SIR_RESEL_BAD_I_T_L
,
2622 }/*-------------------------< BAD_I_T_L_Q >----------------*/,{
2624 ** We donnot have a task that matches the tag.
2625 ** Signal problem to C code for logging the event.
2626 ** Send a M_ABORTTAG message.
2629 SIR_RESEL_BAD_I_T_L_Q
,
2632 }/*-------------------------< BAD_TARGET >-----------------*/,{
2634 ** We donnot know the target that reselected us.
2635 ** Grab the first message if any (IDENTIFY).
2636 ** Signal problem to C code for logging the event.
2640 SIR_RESEL_BAD_TARGET
,
2641 SCR_JUMPR
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2643 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2647 }/*-------------------------< BAD_STATUS >-----------------*/,{
2649 ** If command resulted in either QUEUE FULL,
2650 ** CHECK CONDITION or COMMAND TERMINATED,
2653 SCR_INT
^ IFTRUE (DATA (S_QUEUE_FULL
)),
2655 SCR_INT
^ IFTRUE (DATA (S_CHECK_COND
)),
2657 SCR_INT
^ IFTRUE (DATA (S_TERMINATED
)),
2661 }/*-------------------------< START_RAM >-------------------*/,{
2663 ** Load the script into on-chip RAM,
2664 ** and jump to start point.
2668 PADDRH (start_ram0
),
2670 ** Flush script prefetch if required
2673 SCR_COPY (sizeof (struct script
)),
2674 }/*-------------------------< START_RAM0 >--------------------*/,{
2679 }/*-------------------------< STO_RESTART >-------------------*/,{
2682 ** Repair start queue (e.g. next time use the next slot)
2683 ** and jump to start point.
2690 }/*-------------------------< WAIT_DMA >-------------------*/,{
2692 ** For HP Zalon/53c720 systems, the Zalon interface
2693 ** between CPU and 53c720 does prefetches, which causes
2694 ** problems with self modifying scripts. The problem
2695 ** is overcome by calling a dummy subroutine after each
2696 ** modification, to force a refetch of the script on
2697 ** return from the subroutine.
2701 }/*-------------------------< SNOOPTEST >-------------------*/,{
2703 ** Read the variable.
2709 ** Write the variable.
2715 ** Read back the variable.
2720 }/*-------------------------< SNOOPEND >-------------------*/,{
2726 }/*--------------------------------------------------------*/
2729 /*==========================================================
2732 ** Fill in #define dependent parts of the script
2735 **==========================================================
2738 void __init
ncr_script_fill (struct script
* scr
, struct scripth
* scrh
)
2744 for (i
=0; i
<MAX_START
; i
++) {
2749 BUG_ON((u_long
)p
!= (u_long
)&scrh
->tryloop
+ sizeof (scrh
->tryloop
));
2751 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
2753 p
= scrh
->done_queue
;
2754 for (i
= 0; i
<MAX_DONE
; i
++) {
2755 *p
++ =SCR_COPY (sizeof(struct ccb
*));
2756 *p
++ =NADDR (header
.cp
);
2757 *p
++ =NADDR (ccb_done
[i
]);
2759 *p
++ =PADDR (done_end
);
2762 BUG_ON((u_long
)p
!= (u_long
)&scrh
->done_queue
+sizeof(scrh
->done_queue
));
2764 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
2767 for (i
=0; i
<MAX_SCATTERH
; i
++) {
2768 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_IN
));
2769 *p
++ =PADDR (dispatch
);
2770 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_IN
;
2771 *p
++ =offsetof (struct dsb
, data
[i
]);
2774 BUG_ON((u_long
)p
!= (u_long
)&scrh
->hdata_in
+ sizeof (scrh
->hdata_in
));
2777 for (i
=MAX_SCATTERH
; i
<MAX_SCATTERH
+MAX_SCATTERL
; i
++) {
2778 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_IN
));
2779 *p
++ =PADDR (dispatch
);
2780 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_IN
;
2781 *p
++ =offsetof (struct dsb
, data
[i
]);
2784 BUG_ON((u_long
)p
!= (u_long
)&scr
->data_in
+ sizeof (scr
->data_in
));
2786 p
= scrh
->hdata_out
;
2787 for (i
=0; i
<MAX_SCATTERH
; i
++) {
2788 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_OUT
));
2789 *p
++ =PADDR (dispatch
);
2790 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_OUT
;
2791 *p
++ =offsetof (struct dsb
, data
[i
]);
2794 BUG_ON((u_long
)p
!= (u_long
)&scrh
->hdata_out
+ sizeof (scrh
->hdata_out
));
2797 for (i
=MAX_SCATTERH
; i
<MAX_SCATTERH
+MAX_SCATTERL
; i
++) {
2798 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_OUT
));
2799 *p
++ =PADDR (dispatch
);
2800 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_OUT
;
2801 *p
++ =offsetof (struct dsb
, data
[i
]);
2804 BUG_ON((u_long
) p
!= (u_long
)&scr
->data_out
+ sizeof (scr
->data_out
));
2807 /*==========================================================
2810 ** Copy and rebind a script.
2813 **==========================================================
2817 ncr_script_copy_and_bind (struct ncb
*np
, ncrcmd
*src
, ncrcmd
*dst
, int len
)
2819 ncrcmd opcode
, new, old
, tmp1
, tmp2
;
2820 ncrcmd
*start
, *end
;
2830 *dst
++ = cpu_to_scr(opcode
);
2833 ** If we forget to change the length
2834 ** in struct script, a field will be
2835 ** padded with 0. This is an illegal
2840 printk (KERN_ERR
"%s: ERROR0 IN SCRIPT at %d.\n",
2841 ncr_name(np
), (int) (src
-start
-1));
2845 if (DEBUG_FLAGS
& DEBUG_SCRIPT
)
2846 printk (KERN_DEBUG
"%p: <%x>\n",
2847 (src
-1), (unsigned)opcode
);
2850 ** We don't have to decode ALL commands
2852 switch (opcode
>> 28) {
2856 ** COPY has TWO arguments.
2861 if ((tmp1
& RELOC_MASK
) == RELOC_KVAR
)
2866 if ((tmp2
& RELOC_MASK
) == RELOC_KVAR
)
2869 if ((tmp1
^ tmp2
) & 3) {
2870 printk (KERN_ERR
"%s: ERROR1 IN SCRIPT at %d.\n",
2871 ncr_name(np
), (int) (src
-start
-1));
2875 ** If PREFETCH feature not enabled, remove
2876 ** the NO FLUSH bit if present.
2878 if ((opcode
& SCR_NO_FLUSH
) && !(np
->features
& FE_PFEN
)) {
2879 dst
[-1] = cpu_to_scr(opcode
& ~SCR_NO_FLUSH
);
2886 ** MOVE (absolute address)
2894 ** don't relocate if relative :-)
2896 if (opcode
& 0x00800000)
2918 switch (old
& RELOC_MASK
) {
2919 case RELOC_REGISTER
:
2920 new = (old
& ~RELOC_MASK
) + np
->paddr
;
2923 new = (old
& ~RELOC_MASK
) + np
->p_script
;
2926 new = (old
& ~RELOC_MASK
) + np
->p_scripth
;
2929 new = (old
& ~RELOC_MASK
) + np
->p_ncb
;
2933 if (((old
& ~RELOC_MASK
) <
2934 SCRIPT_KVAR_FIRST
) ||
2935 ((old
& ~RELOC_MASK
) >
2937 panic("ncr KVAR out of range");
2938 new = vtophys(script_kvars
[old
&
2943 /* Don't relocate a 0 address. */
2950 panic("ncr_script_copy_and_bind: weird relocation %x\n", old
);
2954 *dst
++ = cpu_to_scr(new);
2957 *dst
++ = cpu_to_scr(*src
++);
2963 ** Linux host data structure
2970 #define PRINT_ADDR(cmd, arg...) dev_info(&cmd->device->sdev_gendev , ## arg)
2972 static void ncr_print_msg(struct ccb
*cp
, char *label
, u_char
*msg
)
2974 PRINT_ADDR(cp
->cmd
, "%s: ", label
);
2980 /*==========================================================
2982 ** NCR chip clock divisor table.
2983 ** Divisors are multiplied by 10,000,000 in order to make
2984 ** calculations more simple.
2986 **==========================================================
2990 static u_long div_10M
[] =
2991 {2*_5M
, 3*_5M
, 4*_5M
, 6*_5M
, 8*_5M
, 12*_5M
, 16*_5M
};
2994 /*===============================================================
2996 ** Prepare io register values used by ncr_init() according
2997 ** to selected and supported features.
2999 ** NCR chips allow burst lengths of 2, 4, 8, 16, 32, 64, 128
3000 ** transfers. 32,64,128 are only supported by 875 and 895 chips.
3001 ** We use log base 2 (burst length) as internal code, with
3002 ** value 0 meaning "burst disabled".
3004 **===============================================================
3008 * Burst length from burst code.
3010 #define burst_length(bc) (!(bc))? 0 : 1 << (bc)
3013 * Burst code from io register bits. Burst enable is ctest0 for c720
3015 #define burst_code(dmode, ctest0) \
3016 (ctest0) & 0x80 ? 0 : (((dmode) & 0xc0) >> 6) + 1
3019 * Set initial io register bits from burst code.
3021 static inline void ncr_init_burst(struct ncb
*np
, u_char bc
)
3023 u_char
*be
= &np
->rv_ctest0
;
3025 np
->rv_dmode
&= ~(0x3 << 6);
3026 np
->rv_ctest5
&= ~0x4;
3032 np
->rv_dmode
|= ((bc
& 0x3) << 6);
3033 np
->rv_ctest5
|= (bc
& 0x4);
3037 static void __init
ncr_prepare_setting(struct ncb
*np
)
3044 ** Save assumed BIOS setting
3047 np
->sv_scntl0
= INB(nc_scntl0
) & 0x0a;
3048 np
->sv_scntl3
= INB(nc_scntl3
) & 0x07;
3049 np
->sv_dmode
= INB(nc_dmode
) & 0xce;
3050 np
->sv_dcntl
= INB(nc_dcntl
) & 0xa8;
3051 np
->sv_ctest0
= INB(nc_ctest0
) & 0x84;
3052 np
->sv_ctest3
= INB(nc_ctest3
) & 0x01;
3053 np
->sv_ctest4
= INB(nc_ctest4
) & 0x80;
3054 np
->sv_ctest5
= INB(nc_ctest5
) & 0x24;
3055 np
->sv_gpcntl
= INB(nc_gpcntl
);
3056 np
->sv_stest2
= INB(nc_stest2
) & 0x20;
3057 np
->sv_stest4
= INB(nc_stest4
);
3063 np
->maxwide
= (np
->features
& FE_WIDE
)? 1 : 0;
3066 * Guess the frequency of the chip's clock.
3068 if (np
->features
& FE_ULTRA
)
3069 np
->clock_khz
= 80000;
3071 np
->clock_khz
= 40000;
3074 * Get the clock multiplier factor.
3076 if (np
->features
& FE_QUAD
)
3078 else if (np
->features
& FE_DBLR
)
3084 * Measure SCSI clock frequency for chips
3085 * it may vary from assumed one.
3087 if (np
->features
& FE_VARCLK
)
3088 ncr_getclock(np
, np
->multiplier
);
3091 * Divisor to be used for async (timer pre-scaler).
3093 i
= np
->clock_divn
- 1;
3095 if (10ul * SCSI_NCR_MIN_ASYNC
* np
->clock_khz
> div_10M
[i
]) {
3100 np
->rv_scntl3
= i
+1;
3103 * Minimum synchronous period factor supported by the chip.
3104 * Btw, 'period' is in tenths of nanoseconds.
3107 period
= (4 * div_10M
[0] + np
->clock_khz
- 1) / np
->clock_khz
;
3108 if (period
<= 250) np
->minsync
= 10;
3109 else if (period
<= 303) np
->minsync
= 11;
3110 else if (period
<= 500) np
->minsync
= 12;
3111 else np
->minsync
= (period
+ 40 - 1) / 40;
3114 * Check against chip SCSI standard support (SCSI-2,ULTRA,ULTRA2).
3117 if (np
->minsync
< 25 && !(np
->features
& FE_ULTRA
))
3121 * Maximum synchronous period factor supported by the chip.
3124 period
= (11 * div_10M
[np
->clock_divn
- 1]) / (4 * np
->clock_khz
);
3125 np
->maxsync
= period
> 2540 ? 254 : period
/ 10;
3128 ** Prepare initial value of other IO registers
3130 #if defined SCSI_NCR_TRUST_BIOS_SETTING
3131 np
->rv_scntl0
= np
->sv_scntl0
;
3132 np
->rv_dmode
= np
->sv_dmode
;
3133 np
->rv_dcntl
= np
->sv_dcntl
;
3134 np
->rv_ctest0
= np
->sv_ctest0
;
3135 np
->rv_ctest3
= np
->sv_ctest3
;
3136 np
->rv_ctest4
= np
->sv_ctest4
;
3137 np
->rv_ctest5
= np
->sv_ctest5
;
3138 burst_max
= burst_code(np
->sv_dmode
, np
->sv_ctest0
);
3142 ** Select burst length (dwords)
3144 burst_max
= driver_setup
.burst_max
;
3145 if (burst_max
== 255)
3146 burst_max
= burst_code(np
->sv_dmode
, np
->sv_ctest0
);
3149 if (burst_max
> np
->maxburst
)
3150 burst_max
= np
->maxburst
;
3153 ** Select all supported special features
3155 if (np
->features
& FE_ERL
)
3156 np
->rv_dmode
|= ERL
; /* Enable Read Line */
3157 if (np
->features
& FE_BOF
)
3158 np
->rv_dmode
|= BOF
; /* Burst Opcode Fetch */
3159 if (np
->features
& FE_ERMP
)
3160 np
->rv_dmode
|= ERMP
; /* Enable Read Multiple */
3161 if (np
->features
& FE_PFEN
)
3162 np
->rv_dcntl
|= PFEN
; /* Prefetch Enable */
3163 if (np
->features
& FE_CLSE
)
3164 np
->rv_dcntl
|= CLSE
; /* Cache Line Size Enable */
3165 if (np
->features
& FE_WRIE
)
3166 np
->rv_ctest3
|= WRIE
; /* Write and Invalidate */
3167 if (np
->features
& FE_DFS
)
3168 np
->rv_ctest5
|= DFS
; /* Dma Fifo Size */
3169 if (np
->features
& FE_MUX
)
3170 np
->rv_ctest4
|= MUX
; /* Host bus multiplex mode */
3171 if (np
->features
& FE_EA
)
3172 np
->rv_dcntl
|= EA
; /* Enable ACK */
3173 if (np
->features
& FE_EHP
)
3174 np
->rv_ctest0
|= EHP
; /* Even host parity */
3177 ** Select some other
3179 if (driver_setup
.master_parity
)
3180 np
->rv_ctest4
|= MPEE
; /* Master parity checking */
3181 if (driver_setup
.scsi_parity
)
3182 np
->rv_scntl0
|= 0x0a; /* full arb., ena parity, par->ATN */
3185 ** Get SCSI addr of host adapter (set by bios?).
3187 if (np
->myaddr
== 255) {
3188 np
->myaddr
= INB(nc_scid
) & 0x07;
3190 np
->myaddr
= SCSI_NCR_MYADDR
;
3193 #endif /* SCSI_NCR_TRUST_BIOS_SETTING */
3196 * Prepare initial io register bits for burst length
3198 ncr_init_burst(np
, burst_max
);
3201 ** Set SCSI BUS mode.
3203 ** - ULTRA2 chips (895/895A/896) report the current
3204 ** BUS mode through the STEST4 IO register.
3205 ** - For previous generation chips (825/825A/875),
3206 ** user has to tell us how to check against HVD,
3207 ** since a 100% safe algorithm is not possible.
3209 np
->scsi_mode
= SMODE_SE
;
3210 if (np
->features
& FE_DIFF
) {
3211 switch(driver_setup
.diff_support
) {
3212 case 4: /* Trust previous settings if present, then GPIO3 */
3213 if (np
->sv_scntl3
) {
3214 if (np
->sv_stest2
& 0x20)
3215 np
->scsi_mode
= SMODE_HVD
;
3218 case 3: /* SYMBIOS controllers report HVD through GPIO3 */
3219 if (INB(nc_gpreg
) & 0x08)
3221 case 2: /* Set HVD unconditionally */
3222 np
->scsi_mode
= SMODE_HVD
;
3223 case 1: /* Trust previous settings for HVD */
3224 if (np
->sv_stest2
& 0x20)
3225 np
->scsi_mode
= SMODE_HVD
;
3227 default:/* Don't care about HVD */
3231 if (np
->scsi_mode
== SMODE_HVD
)
3232 np
->rv_stest2
|= 0x20;
3235 ** Set LED support from SCRIPTS.
3236 ** Ignore this feature for boards known to use a
3237 ** specific GPIO wiring and for the 895A or 896
3238 ** that drive the LED directly.
3239 ** Also probe initial setting of GPIO0 as output.
3241 if ((driver_setup
.led_pin
) &&
3242 !(np
->features
& FE_LEDC
) && !(np
->sv_gpcntl
& 0x01))
3243 np
->features
|= FE_LED0
;
3248 switch(driver_setup
.irqm
& 3) {
3250 np
->rv_dcntl
|= IRQM
;
3253 np
->rv_dcntl
|= (np
->sv_dcntl
& IRQM
);
3260 ** Configure targets according to driver setup.
3261 ** Allow to override sync, wide and NOSCAN from
3262 ** boot command line.
3264 for (i
= 0 ; i
< MAX_TARGET
; i
++) {
3265 struct tcb
*tp
= &np
->target
[i
];
3267 tp
->usrsync
= driver_setup
.default_sync
;
3268 tp
->usrwide
= driver_setup
.max_wide
;
3269 tp
->usrtags
= MAX_TAGS
;
3270 tp
->period
= 0xffff;
3271 if (!driver_setup
.disconnection
)
3272 np
->target
[i
].usrflag
= UF_NODISC
;
3276 ** Announce all that stuff to user.
3279 printk(KERN_INFO
"%s: ID %d, Fast-%d%s%s\n", ncr_name(np
),
3281 np
->minsync
< 12 ? 40 : (np
->minsync
< 25 ? 20 : 10),
3282 (np
->rv_scntl0
& 0xa) ? ", Parity Checking" : ", NO Parity",
3283 (np
->rv_stest2
& 0x20) ? ", Differential" : "");
3285 if (bootverbose
> 1) {
3286 printk (KERN_INFO
"%s: initial SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
3287 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
3288 ncr_name(np
), np
->sv_scntl3
, np
->sv_dmode
, np
->sv_dcntl
,
3289 np
->sv_ctest3
, np
->sv_ctest4
, np
->sv_ctest5
);
3291 printk (KERN_INFO
"%s: final SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
3292 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
3293 ncr_name(np
), np
->rv_scntl3
, np
->rv_dmode
, np
->rv_dcntl
,
3294 np
->rv_ctest3
, np
->rv_ctest4
, np
->rv_ctest5
);
3297 if (bootverbose
&& np
->paddr2
)
3298 printk (KERN_INFO
"%s: on-chip RAM at 0x%lx\n",
3299 ncr_name(np
), np
->paddr2
);
3302 /*==========================================================
3305 ** Done SCSI commands list management.
3307 ** We donnot enter the scsi_done() callback immediately
3308 ** after a command has been seen as completed but we
3309 ** insert it into a list which is flushed outside any kind
3310 ** of driver critical section.
3311 ** This allows to do minimal stuff under interrupt and
3312 ** inside critical sections and to also avoid locking up
3313 ** on recursive calls to driver entry points under SMP.
3314 ** In fact, the only kernel point which is entered by the
3315 ** driver with a driver lock set is kmalloc(GFP_ATOMIC)
3316 ** that shall not reenter the driver under any circumstances,
3319 **==========================================================
3321 static inline void ncr_queue_done_cmd(struct ncb
*np
, struct scsi_cmnd
*cmd
)
3323 unmap_scsi_data(np
, cmd
);
3324 cmd
->host_scribble
= (char *) np
->done_list
;
3325 np
->done_list
= cmd
;
3328 static inline void ncr_flush_done_cmds(struct scsi_cmnd
*lcmd
)
3330 struct scsi_cmnd
*cmd
;
3334 lcmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
3335 cmd
->scsi_done(cmd
);
3339 /*==========================================================
3342 ** Prepare the next negotiation message if needed.
3344 ** Fill in the part of message buffer that contains the
3345 ** negotiation and the nego_status field of the CCB.
3346 ** Returns the size of the message in bytes.
3349 **==========================================================
3353 static int ncr_prepare_nego(struct ncb
*np
, struct ccb
*cp
, u_char
*msgptr
)
3355 struct tcb
*tp
= &np
->target
[cp
->target
];
3358 struct scsi_target
*starget
= tp
->starget
;
3360 /* negotiate wide transfers ? */
3361 if (!tp
->widedone
) {
3362 if (spi_support_wide(starget
)) {
3368 /* negotiate synchronous transfers? */
3369 if (!nego
&& !tp
->period
) {
3370 if (spi_support_sync(starget
)) {
3374 dev_info(&starget
->dev
, "target did not report SYNC.\n");
3380 msgptr
[msglen
++] = M_EXTENDED
;
3381 msgptr
[msglen
++] = 3;
3382 msgptr
[msglen
++] = M_X_SYNC_REQ
;
3383 msgptr
[msglen
++] = tp
->maxoffs
? tp
->minsync
: 0;
3384 msgptr
[msglen
++] = tp
->maxoffs
;
3387 msgptr
[msglen
++] = M_EXTENDED
;
3388 msgptr
[msglen
++] = 2;
3389 msgptr
[msglen
++] = M_X_WIDE_REQ
;
3390 msgptr
[msglen
++] = tp
->usrwide
;
3394 cp
->nego_status
= nego
;
3398 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
3399 ncr_print_msg(cp
, nego
== NS_WIDE
?
3400 "wide msgout":"sync_msgout", msgptr
);
3409 /*==========================================================
3412 ** Start execution of a SCSI command.
3413 ** This is called from the generic SCSI driver.
3416 **==========================================================
3418 static int ncr_queue_command (struct ncb
*np
, struct scsi_cmnd
*cmd
)
3420 struct scsi_device
*sdev
= cmd
->device
;
3421 struct tcb
*tp
= &np
->target
[sdev
->id
];
3422 struct lcb
*lp
= tp
->lp
[sdev
->lun
];
3426 u_char idmsg
, *msgptr
;
3431 /*---------------------------------------------
3433 ** Some shortcuts ...
3435 **---------------------------------------------
3437 if ((sdev
->id
== np
->myaddr
) ||
3438 (sdev
->id
>= MAX_TARGET
) ||
3439 (sdev
->lun
>= MAX_LUN
)) {
3440 return(DID_BAD_TARGET
);
3443 /*---------------------------------------------
3445 ** Complete the 1st TEST UNIT READY command
3446 ** with error condition if the device is
3447 ** flagged NOSCAN, in order to speed up
3450 **---------------------------------------------
3452 if ((cmd
->cmnd
[0] == 0 || cmd
->cmnd
[0] == 0x12) &&
3453 (tp
->usrflag
& UF_NOSCAN
)) {
3454 tp
->usrflag
&= ~UF_NOSCAN
;
3455 return DID_BAD_TARGET
;
3458 if (DEBUG_FLAGS
& DEBUG_TINY
) {
3459 PRINT_ADDR(cmd
, "CMD=%x ", cmd
->cmnd
[0]);
3462 /*---------------------------------------------------
3464 ** Assign a ccb / bind cmd.
3465 ** If resetting, shorten settle_time if necessary
3466 ** in order to avoid spurious timeouts.
3467 ** If resetting or no free ccb,
3468 ** insert cmd into the waiting list.
3470 **----------------------------------------------------
3472 if (np
->settle_time
&& cmd
->timeout_per_command
>= HZ
) {
3473 u_long tlimit
= jiffies
+ cmd
->timeout_per_command
- HZ
;
3474 if (time_after(np
->settle_time
, tlimit
))
3475 np
->settle_time
= tlimit
;
3478 if (np
->settle_time
|| !(cp
=ncr_get_ccb (np
, cmd
))) {
3479 insert_into_waiting_list(np
, cmd
);
3484 /*----------------------------------------------------
3486 ** Build the identify / tag / sdtr message
3488 **----------------------------------------------------
3491 idmsg
= M_IDENTIFY
| sdev
->lun
;
3493 if (cp
->tag
!= NO_TAG
||
3494 (cp
!= np
->ccb
&& np
->disc
&& !(tp
->usrflag
& UF_NODISC
)))
3497 msgptr
= cp
->scsi_smsg
;
3499 msgptr
[msglen
++] = idmsg
;
3501 if (cp
->tag
!= NO_TAG
) {
3502 char order
= np
->order
;
3505 ** Force ordered tag if necessary to avoid timeouts
3506 ** and to preserve interactivity.
3508 if (lp
&& time_after(jiffies
, lp
->tags_stime
)) {
3509 if (lp
->tags_smap
) {
3510 order
= M_ORDERED_TAG
;
3511 if ((DEBUG_FLAGS
& DEBUG_TAGS
)||bootverbose
>2){
3513 "ordered tag forced.\n");
3516 lp
->tags_stime
= jiffies
+ 3*HZ
;
3517 lp
->tags_smap
= lp
->tags_umap
;
3522 ** Ordered write ops, unordered read ops.
3524 switch (cmd
->cmnd
[0]) {
3525 case 0x08: /* READ_SMALL (6) */
3526 case 0x28: /* READ_BIG (10) */
3527 case 0xa8: /* READ_HUGE (12) */
3528 order
= M_SIMPLE_TAG
;
3531 order
= M_ORDERED_TAG
;
3534 msgptr
[msglen
++] = order
;
3536 ** Actual tags are numbered 1,3,5,..2*MAXTAGS+1,
3537 ** since we may have to deal with devices that have
3538 ** problems with #TAG 0 or too great #TAG numbers.
3540 msgptr
[msglen
++] = (cp
->tag
<< 1) + 1;
3543 /*----------------------------------------------------
3545 ** Build the data descriptors
3547 **----------------------------------------------------
3550 direction
= cmd
->sc_data_direction
;
3551 if (direction
!= DMA_NONE
) {
3552 segments
= ncr_scatter(np
, cp
, cp
->cmd
);
3554 ncr_free_ccb(np
, cp
);
3563 /*---------------------------------------------------
3565 ** negotiation required?
3567 ** (nego_status is filled by ncr_prepare_nego())
3569 **---------------------------------------------------
3572 cp
->nego_status
= 0;
3574 if ((!tp
->widedone
|| !tp
->period
) && !tp
->nego_cp
&& lp
) {
3575 msglen
+= ncr_prepare_nego (np
, cp
, msgptr
+ msglen
);
3578 /*----------------------------------------------------
3580 ** Determine xfer direction.
3582 **----------------------------------------------------
3585 direction
= DMA_NONE
;
3588 ** If data direction is BIDIRECTIONAL, speculate FROM_DEVICE
3589 ** but prepare alternate pointers for TO_DEVICE in case
3590 ** of our speculation will be just wrong.
3591 ** SCRIPTS will swap values if needed.
3594 case DMA_BIDIRECTIONAL
:
3596 goalp
= NCB_SCRIPT_PHYS (np
, data_out2
) + 8;
3597 if (segments
<= MAX_SCATTERL
)
3598 lastp
= goalp
- 8 - (segments
* 16);
3600 lastp
= NCB_SCRIPTH_PHYS (np
, hdata_out2
);
3601 lastp
-= (segments
- MAX_SCATTERL
) * 16;
3603 if (direction
!= DMA_BIDIRECTIONAL
)
3605 cp
->phys
.header
.wgoalp
= cpu_to_scr(goalp
);
3606 cp
->phys
.header
.wlastp
= cpu_to_scr(lastp
);
3608 case DMA_FROM_DEVICE
:
3609 goalp
= NCB_SCRIPT_PHYS (np
, data_in2
) + 8;
3610 if (segments
<= MAX_SCATTERL
)
3611 lastp
= goalp
- 8 - (segments
* 16);
3613 lastp
= NCB_SCRIPTH_PHYS (np
, hdata_in2
);
3614 lastp
-= (segments
- MAX_SCATTERL
) * 16;
3619 lastp
= goalp
= NCB_SCRIPT_PHYS (np
, no_data
);
3624 ** Set all pointers values needed by SCRIPTS.
3625 ** If direction is unknown, start at data_io.
3627 cp
->phys
.header
.lastp
= cpu_to_scr(lastp
);
3628 cp
->phys
.header
.goalp
= cpu_to_scr(goalp
);
3630 if (direction
== DMA_BIDIRECTIONAL
)
3631 cp
->phys
.header
.savep
=
3632 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, data_io
));
3634 cp
->phys
.header
.savep
= cpu_to_scr(lastp
);
3637 ** Save the initial data pointer in order to be able
3638 ** to redo the command.
3640 cp
->startp
= cp
->phys
.header
.savep
;
3642 /*----------------------------------------------------
3646 **----------------------------------------------------
3649 ** physical -> virtual backlink
3650 ** Generic SCSI command
3656 cp
->start
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, select
));
3657 cp
->restart
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, resel_dsa
));
3661 cp
->phys
.select
.sel_id
= sdev_id(sdev
);
3662 cp
->phys
.select
.sel_scntl3
= tp
->wval
;
3663 cp
->phys
.select
.sel_sxfer
= tp
->sval
;
3667 cp
->phys
.smsg
.addr
= cpu_to_scr(CCB_PHYS (cp
, scsi_smsg
));
3668 cp
->phys
.smsg
.size
= cpu_to_scr(msglen
);
3673 memcpy(cp
->cdb_buf
, cmd
->cmnd
, min_t(int, cmd
->cmd_len
, sizeof(cp
->cdb_buf
)));
3674 cp
->phys
.cmd
.addr
= cpu_to_scr(CCB_PHYS (cp
, cdb_buf
[0]));
3675 cp
->phys
.cmd
.size
= cpu_to_scr(cmd
->cmd_len
);
3680 cp
->actualquirks
= 0;
3681 cp
->host_status
= cp
->nego_status
? HS_NEGOTIATE
: HS_BUSY
;
3682 cp
->scsi_status
= S_ILLEGAL
;
3683 cp
->parity_status
= 0;
3685 cp
->xerr_status
= XE_OK
;
3687 cp
->sync_status
= tp
->sval
;
3688 cp
->wide_status
= tp
->wval
;
3691 /*----------------------------------------------------
3693 ** Critical region: start this job.
3695 **----------------------------------------------------
3698 /* activate this job. */
3699 cp
->magic
= CCB_MAGIC
;
3702 ** insert next CCBs into start queue.
3703 ** 2 max at a time is enough to flush the CCB wait queue.
3707 ncr_start_next_ccb(np
, lp
, 2);
3709 ncr_put_start_queue(np
, cp
);
3711 /* Command is successfully queued. */
3717 /*==========================================================
3720 ** Insert a CCB into the start queue and wake up the
3721 ** SCRIPTS processor.
3724 **==========================================================
3727 static void ncr_start_next_ccb(struct ncb
*np
, struct lcb
*lp
, int maxn
)
3729 struct list_head
*qp
;
3735 while (maxn
-- && lp
->queuedccbs
< lp
->queuedepth
) {
3736 qp
= ncr_list_pop(&lp
->wait_ccbq
);
3740 cp
= list_entry(qp
, struct ccb
, link_ccbq
);
3741 list_add_tail(qp
, &lp
->busy_ccbq
);
3742 lp
->jump_ccb
[cp
->tag
== NO_TAG
? 0 : cp
->tag
] =
3743 cpu_to_scr(CCB_PHYS (cp
, restart
));
3744 ncr_put_start_queue(np
, cp
);
3748 static void ncr_put_start_queue(struct ncb
*np
, struct ccb
*cp
)
3753 ** insert into start queue.
3755 if (!np
->squeueput
) np
->squeueput
= 1;
3756 qidx
= np
->squeueput
+ 2;
3757 if (qidx
>= MAX_START
+ MAX_START
) qidx
= 1;
3759 np
->scripth
->tryloop
[qidx
] = cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
3761 np
->scripth
->tryloop
[np
->squeueput
] = cpu_to_scr(CCB_PHYS (cp
, start
));
3763 np
->squeueput
= qidx
;
3767 if (DEBUG_FLAGS
& DEBUG_QUEUE
)
3768 printk ("%s: queuepos=%d.\n", ncr_name (np
), np
->squeueput
);
3771 ** Script processor may be waiting for reselect.
3775 OUTB (nc_istat
, SIGP
);
3779 static int ncr_reset_scsi_bus(struct ncb
*np
, int enab_int
, int settle_delay
)
3784 np
->settle_time
= jiffies
+ settle_delay
* HZ
;
3786 if (bootverbose
> 1)
3787 printk("%s: resetting, "
3788 "command processing suspended for %d seconds\n",
3789 ncr_name(np
), settle_delay
);
3791 ncr_chip_reset(np
, 100);
3792 udelay(2000); /* The 895 needs time for the bus mode to settle */
3794 OUTW (nc_sien
, RST
);
3796 ** Enable Tolerant, reset IRQD if present and
3797 ** properly set IRQ mode, prior to resetting the bus.
3799 OUTB (nc_stest3
, TE
);
3800 OUTB (nc_scntl1
, CRST
);
3803 if (!driver_setup
.bus_check
)
3806 ** Check for no terminators or SCSI bus shorts to ground.
3807 ** Read SCSI data bus, data parity bits and control signals.
3808 ** We are expecting RESET to be TRUE and other signals to be
3812 term
= INB(nc_sstat0
);
3813 term
= ((term
& 2) << 7) + ((term
& 1) << 17); /* rst sdp0 */
3814 term
|= ((INB(nc_sstat2
) & 0x01) << 26) | /* sdp1 */
3815 ((INW(nc_sbdl
) & 0xff) << 9) | /* d7-0 */
3816 ((INW(nc_sbdl
) & 0xff00) << 10) | /* d15-8 */
3817 INB(nc_sbcl
); /* req ack bsy sel atn msg cd io */
3819 if (!(np
->features
& FE_WIDE
))
3822 if (term
!= (2<<7)) {
3823 printk("%s: suspicious SCSI data while resetting the BUS.\n",
3825 printk("%s: %sdp0,d7-0,rst,req,ack,bsy,sel,atn,msg,c/d,i/o = "
3826 "0x%lx, expecting 0x%lx\n",
3828 (np
->features
& FE_WIDE
) ? "dp1,d15-8," : "",
3829 (u_long
)term
, (u_long
)(2<<7));
3830 if (driver_setup
.bus_check
== 1)
3834 OUTB (nc_scntl1
, 0);
3839 * Start reset process.
3840 * If reset in progress do nothing.
3841 * The interrupt handler will reinitialize the chip.
3842 * The timeout handler will wait for settle_time before
3843 * clearing it and so resuming command processing.
3845 static void ncr_start_reset(struct ncb
*np
)
3847 if (!np
->settle_time
) {
3848 ncr_reset_scsi_bus(np
, 1, driver_setup
.settle_delay
);
3852 /*==========================================================
3855 ** Reset the SCSI BUS.
3856 ** This is called from the generic SCSI driver.
3859 **==========================================================
3861 static int ncr_reset_bus (struct ncb
*np
, struct scsi_cmnd
*cmd
, int sync_reset
)
3863 /* struct scsi_device *device = cmd->device; */
3868 * Return immediately if reset is in progress.
3870 if (np
->settle_time
) {
3874 * Start the reset process.
3875 * The script processor is then assumed to be stopped.
3876 * Commands will now be queued in the waiting list until a settle
3877 * delay of 2 seconds will be completed.
3879 ncr_start_reset(np
);
3881 * First, look in the wakeup list
3883 for (found
=0, cp
=np
->ccb
; cp
; cp
=cp
->link_ccb
) {
3885 ** look for the ccb of this command.
3887 if (cp
->host_status
== HS_IDLE
) continue;
3888 if (cp
->cmd
== cmd
) {
3894 * Then, look in the waiting list
3896 if (!found
&& retrieve_from_waiting_list(0, np
, cmd
))
3899 * Wake-up all awaiting commands with DID_RESET.
3901 reset_waiting_list(np
);
3903 * Wake-up all pending commands with HS_RESET -> DID_RESET.
3905 ncr_wakeup(np
, HS_RESET
);
3907 * If the involved command was not in a driver queue, and the
3908 * scsi driver told us reset is synchronous, and the command is not
3909 * currently in the waiting list, complete it with DID_RESET status,
3910 * in order to keep it alive.
3912 if (!found
&& sync_reset
&& !retrieve_from_waiting_list(0, np
, cmd
)) {
3913 cmd
->result
= ScsiResult(DID_RESET
, 0);
3914 ncr_queue_done_cmd(np
, cmd
);
3920 #if 0 /* unused and broken.. */
3921 /*==========================================================
3924 ** Abort an SCSI command.
3925 ** This is called from the generic SCSI driver.
3928 **==========================================================
3930 static int ncr_abort_command (struct ncb
*np
, struct scsi_cmnd
*cmd
)
3932 /* struct scsi_device *device = cmd->device; */
3938 * First, look for the scsi command in the waiting list
3940 if (remove_from_waiting_list(np
, cmd
)) {
3941 cmd
->result
= ScsiResult(DID_ABORT
, 0);
3942 ncr_queue_done_cmd(np
, cmd
);
3943 return SCSI_ABORT_SUCCESS
;
3947 * Then, look in the wakeup list
3949 for (found
=0, cp
=np
->ccb
; cp
; cp
=cp
->link_ccb
) {
3951 ** look for the ccb of this command.
3953 if (cp
->host_status
== HS_IDLE
) continue;
3954 if (cp
->cmd
== cmd
) {
3961 return SCSI_ABORT_NOT_RUNNING
;
3964 if (np
->settle_time
) {
3965 return SCSI_ABORT_SNOOZE
;
3969 ** If the CCB is active, patch schedule jumps for the
3970 ** script to abort the command.
3973 switch(cp
->host_status
) {
3976 printk ("%s: abort ccb=%p (cancel)\n", ncr_name (np
), cp
);
3977 cp
->start
.schedule
.l_paddr
=
3978 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, cancel
));
3979 retv
= SCSI_ABORT_PENDING
;
3982 cp
->restart
.schedule
.l_paddr
=
3983 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, abort
));
3984 retv
= SCSI_ABORT_PENDING
;
3987 retv
= SCSI_ABORT_NOT_RUNNING
;
3993 ** If there are no requests, the script
3994 ** processor will sleep on SEL_WAIT_RESEL.
3995 ** Let's wake it up, since it may have to work.
3997 OUTB (nc_istat
, SIGP
);
4003 static void ncr_detach(struct ncb
*np
)
4012 /* Local copy so we don't access np after freeing it! */
4013 strlcpy(inst_name
, ncr_name(np
), sizeof(inst_name
));
4015 printk("%s: releasing host resources\n", ncr_name(np
));
4018 ** Stop the ncr_timeout process
4019 ** Set release_stage to 1 and wait that ncr_timeout() set it to 2.
4022 #ifdef DEBUG_NCR53C8XX
4023 printk("%s: stopping the timer\n", ncr_name(np
));
4025 np
->release_stage
= 1;
4026 for (i
= 50 ; i
&& np
->release_stage
!= 2 ; i
--)
4028 if (np
->release_stage
!= 2)
4029 printk("%s: the timer seems to be already stopped\n", ncr_name(np
));
4030 else np
->release_stage
= 2;
4033 ** Disable chip interrupts
4036 #ifdef DEBUG_NCR53C8XX
4037 printk("%s: disabling chip interrupts\n", ncr_name(np
));
4044 ** Restore bios setting for automatic clock detection.
4047 printk("%s: resetting chip\n", ncr_name(np
));
4048 ncr_chip_reset(np
, 100);
4050 OUTB(nc_dmode
, np
->sv_dmode
);
4051 OUTB(nc_dcntl
, np
->sv_dcntl
);
4052 OUTB(nc_ctest0
, np
->sv_ctest0
);
4053 OUTB(nc_ctest3
, np
->sv_ctest3
);
4054 OUTB(nc_ctest4
, np
->sv_ctest4
);
4055 OUTB(nc_ctest5
, np
->sv_ctest5
);
4056 OUTB(nc_gpcntl
, np
->sv_gpcntl
);
4057 OUTB(nc_stest2
, np
->sv_stest2
);
4059 ncr_selectclock(np
, np
->sv_scntl3
);
4062 ** Free allocated ccb(s)
4065 while ((cp
=np
->ccb
->link_ccb
) != NULL
) {
4066 np
->ccb
->link_ccb
= cp
->link_ccb
;
4067 if (cp
->host_status
) {
4068 printk("%s: shall free an active ccb (host_status=%d)\n",
4069 ncr_name(np
), cp
->host_status
);
4071 #ifdef DEBUG_NCR53C8XX
4072 printk("%s: freeing ccb (%lx)\n", ncr_name(np
), (u_long
) cp
);
4074 m_free_dma(cp
, sizeof(*cp
), "CCB");
4077 /* Free allocated tp(s) */
4079 for (target
= 0; target
< MAX_TARGET
; target
++) {
4080 tp
=&np
->target
[target
];
4081 for (lun
= 0 ; lun
< MAX_LUN
; lun
++) {
4084 #ifdef DEBUG_NCR53C8XX
4085 printk("%s: freeing lp (%lx)\n", ncr_name(np
), (u_long
) lp
);
4087 if (lp
->jump_ccb
!= &lp
->jump_ccb_0
)
4088 m_free_dma(lp
->jump_ccb
,256,"JUMP_CCB");
4089 m_free_dma(lp
, sizeof(*lp
), "LCB");
4095 m_free_dma(np
->scripth0
, sizeof(struct scripth
), "SCRIPTH");
4097 m_free_dma(np
->script0
, sizeof(struct script
), "SCRIPT");
4099 m_free_dma(np
->ccb
, sizeof(struct ccb
), "CCB");
4100 m_free_dma(np
, sizeof(struct ncb
), "NCB");
4102 printk("%s: host resources successfully released\n", inst_name
);
4105 /*==========================================================
4108 ** Complete execution of a SCSI command.
4109 ** Signal completion to the generic SCSI driver.
4112 **==========================================================
4115 void ncr_complete (struct ncb
*np
, struct ccb
*cp
)
4117 struct scsi_cmnd
*cmd
;
4125 if (!cp
|| cp
->magic
!= CCB_MAGIC
|| !cp
->cmd
)
4129 ** Print minimal debug information.
4132 if (DEBUG_FLAGS
& DEBUG_TINY
)
4133 printk ("CCB=%lx STAT=%x/%x\n", (unsigned long)cp
,
4134 cp
->host_status
,cp
->scsi_status
);
4137 ** Get command, target and lun pointers.
4142 tp
= &np
->target
[cmd
->device
->id
];
4143 lp
= tp
->lp
[cmd
->device
->lun
];
4146 ** We donnot queue more than 1 ccb per target
4147 ** with negotiation at any time. If this ccb was
4148 ** used for negotiation, clear this info in the tcb.
4151 if (cp
== tp
->nego_cp
)
4155 ** If auto-sense performed, change scsi status.
4157 if (cp
->auto_sense
) {
4158 cp
->scsi_status
= cp
->auto_sense
;
4162 ** If we were recovering from queue full or performing
4163 ** auto-sense, requeue skipped CCBs to the wait queue.
4166 if (lp
&& lp
->held_ccb
) {
4167 if (cp
== lp
->held_ccb
) {
4168 list_splice_init(&lp
->skip_ccbq
, &lp
->wait_ccbq
);
4169 lp
->held_ccb
= NULL
;
4174 ** Check for parity errors.
4177 if (cp
->parity_status
> 1) {
4178 PRINT_ADDR(cmd
, "%d parity error(s).\n",cp
->parity_status
);
4182 ** Check for extended errors.
4185 if (cp
->xerr_status
!= XE_OK
) {
4186 switch (cp
->xerr_status
) {
4188 PRINT_ADDR(cmd
, "extraneous data discarded.\n");
4191 PRINT_ADDR(cmd
, "invalid scsi phase (4/5).\n");
4194 PRINT_ADDR(cmd
, "extended error %d.\n",
4198 if (cp
->host_status
==HS_COMPLETE
)
4199 cp
->host_status
= HS_FAIL
;
4203 ** Print out any error for debugging purpose.
4205 if (DEBUG_FLAGS
& (DEBUG_RESULT
|DEBUG_TINY
)) {
4206 if (cp
->host_status
!=HS_COMPLETE
|| cp
->scsi_status
!=S_GOOD
) {
4207 PRINT_ADDR(cmd
, "ERROR: cmd=%x host_status=%x "
4208 "scsi_status=%x\n", cmd
->cmnd
[0],
4209 cp
->host_status
, cp
->scsi_status
);
4214 ** Check the status.
4216 if ( (cp
->host_status
== HS_COMPLETE
)
4217 && (cp
->scsi_status
== S_GOOD
||
4218 cp
->scsi_status
== S_COND_MET
)) {
4220 * All went well (GOOD status).
4221 * CONDITION MET status is returned on
4222 * `Pre-Fetch' or `Search data' success.
4224 cmd
->result
= ScsiResult(DID_OK
, cp
->scsi_status
);
4228 ** Could dig out the correct value for resid,
4229 ** but it would be quite complicated.
4231 /* if (cp->phys.header.lastp != cp->phys.header.goalp) */
4234 ** Allocate the lcb if not yet.
4237 ncr_alloc_lcb (np
, cmd
->device
->id
, cmd
->device
->lun
);
4239 tp
->bytes
+= cp
->data_len
;
4243 ** If tags was reduced due to queue full,
4244 ** increase tags if 1000 good status received.
4246 if (lp
&& lp
->usetags
&& lp
->numtags
< lp
->maxtags
) {
4248 if (lp
->num_good
>= 1000) {
4251 ncr_setup_tags (np
, cmd
->device
);
4254 } else if ((cp
->host_status
== HS_COMPLETE
)
4255 && (cp
->scsi_status
== S_CHECK_COND
)) {
4257 ** Check condition code
4259 cmd
->result
= ScsiResult(DID_OK
, S_CHECK_COND
);
4262 ** Copy back sense data to caller's buffer.
4264 memcpy(cmd
->sense_buffer
, cp
->sense_buf
,
4265 min(sizeof(cmd
->sense_buffer
), sizeof(cp
->sense_buf
)));
4267 if (DEBUG_FLAGS
& (DEBUG_RESULT
|DEBUG_TINY
)) {
4268 u_char
* p
= (u_char
*) & cmd
->sense_buffer
;
4270 PRINT_ADDR(cmd
, "sense data:");
4271 for (i
=0; i
<14; i
++) printk (" %x", *p
++);
4274 } else if ((cp
->host_status
== HS_COMPLETE
)
4275 && (cp
->scsi_status
== S_CONFLICT
)) {
4277 ** Reservation Conflict condition code
4279 cmd
->result
= ScsiResult(DID_OK
, S_CONFLICT
);
4281 } else if ((cp
->host_status
== HS_COMPLETE
)
4282 && (cp
->scsi_status
== S_BUSY
||
4283 cp
->scsi_status
== S_QUEUE_FULL
)) {
4288 cmd
->result
= ScsiResult(DID_OK
, cp
->scsi_status
);
4290 } else if ((cp
->host_status
== HS_SEL_TIMEOUT
)
4291 || (cp
->host_status
== HS_TIMEOUT
)) {
4296 cmd
->result
= ScsiResult(DID_TIME_OUT
, cp
->scsi_status
);
4298 } else if (cp
->host_status
== HS_RESET
) {
4303 cmd
->result
= ScsiResult(DID_RESET
, cp
->scsi_status
);
4305 } else if (cp
->host_status
== HS_ABORTED
) {
4310 cmd
->result
= ScsiResult(DID_ABORT
, cp
->scsi_status
);
4315 ** Other protocol messes
4317 PRINT_ADDR(cmd
, "COMMAND FAILED (%x %x) @%p.\n",
4318 cp
->host_status
, cp
->scsi_status
, cp
);
4320 cmd
->result
= ScsiResult(DID_ERROR
, cp
->scsi_status
);
4327 if (tp
->usrflag
& UF_TRACE
) {
4330 PRINT_ADDR(cmd
, " CMD:");
4331 p
= (u_char
*) &cmd
->cmnd
[0];
4332 for (i
=0; i
<cmd
->cmd_len
; i
++) printk (" %x", *p
++);
4334 if (cp
->host_status
==HS_COMPLETE
) {
4335 switch (cp
->scsi_status
) {
4341 p
= (u_char
*) &cmd
->sense_buffer
;
4342 for (i
=0; i
<14; i
++)
4343 printk (" %x", *p
++);
4346 printk (" STAT: %x\n", cp
->scsi_status
);
4349 } else printk (" HOSTERROR: %x", cp
->host_status
);
4356 ncr_free_ccb (np
, cp
);
4359 ** requeue awaiting scsi commands for this lun.
4361 if (lp
&& lp
->queuedccbs
< lp
->queuedepth
&&
4362 !list_empty(&lp
->wait_ccbq
))
4363 ncr_start_next_ccb(np
, lp
, 2);
4366 ** requeue awaiting scsi commands for this controller.
4368 if (np
->waiting_list
)
4369 requeue_waiting_list(np
);
4372 ** signal completion to generic driver.
4374 ncr_queue_done_cmd(np
, cmd
);
4377 /*==========================================================
4380 ** Signal all (or one) control block done.
4383 **==========================================================
4387 ** This CCB has been skipped by the NCR.
4388 ** Queue it in the correponding unit queue.
4390 static void ncr_ccb_skipped(struct ncb
*np
, struct ccb
*cp
)
4392 struct tcb
*tp
= &np
->target
[cp
->target
];
4393 struct lcb
*lp
= tp
->lp
[cp
->lun
];
4395 if (lp
&& cp
!= np
->ccb
) {
4396 cp
->host_status
&= ~HS_SKIPMASK
;
4397 cp
->start
.schedule
.l_paddr
=
4398 cpu_to_scr(NCB_SCRIPT_PHYS (np
, select
));
4399 list_del(&cp
->link_ccbq
);
4400 list_add_tail(&cp
->link_ccbq
, &lp
->skip_ccbq
);
4412 ** The NCR has completed CCBs.
4413 ** Look at the DONE QUEUE if enabled, otherwise scan all CCBs
4415 void ncr_wakeup_done (struct ncb
*np
)
4418 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
4421 i
= np
->ccb_done_ic
;
4427 cp
= np
->ccb_done
[j
];
4428 if (!CCB_DONE_VALID(cp
))
4431 np
->ccb_done
[j
] = (struct ccb
*)CCB_DONE_EMPTY
;
4432 np
->scripth
->done_queue
[5*j
+ 4] =
4433 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_plug
));
4435 np
->scripth
->done_queue
[5*i
+ 4] =
4436 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_end
));
4438 if (cp
->host_status
& HS_DONEMASK
)
4439 ncr_complete (np
, cp
);
4440 else if (cp
->host_status
& HS_SKIPMASK
)
4441 ncr_ccb_skipped (np
, cp
);
4445 np
->ccb_done_ic
= i
;
4449 if (cp
->host_status
& HS_DONEMASK
)
4450 ncr_complete (np
, cp
);
4451 else if (cp
->host_status
& HS_SKIPMASK
)
4452 ncr_ccb_skipped (np
, cp
);
4459 ** Complete all active CCBs.
4461 void ncr_wakeup (struct ncb
*np
, u_long code
)
4463 struct ccb
*cp
= np
->ccb
;
4466 if (cp
->host_status
!= HS_IDLE
) {
4467 cp
->host_status
= code
;
4468 ncr_complete (np
, cp
);
4478 /* Some initialisation must be done immediately following reset, for 53c720,
4479 * at least. EA (dcntl bit 5) isn't set here as it is set once only in
4480 * the _detect function.
4482 static void ncr_chip_reset(struct ncb
*np
, int delay
)
4484 OUTB (nc_istat
, SRST
);
4486 OUTB (nc_istat
, 0 );
4488 if (np
->features
& FE_EHP
)
4489 OUTB (nc_ctest0
, EHP
);
4490 if (np
->features
& FE_MUX
)
4491 OUTB (nc_ctest4
, MUX
);
4495 /*==========================================================
4501 **==========================================================
4504 void ncr_init (struct ncb
*np
, int reset
, char * msg
, u_long code
)
4509 ** Reset chip if asked, otherwise just clear fifos.
4513 OUTB (nc_istat
, SRST
);
4517 OUTB (nc_stest3
, TE
|CSF
);
4518 OUTONB (nc_ctest3
, CLF
);
4525 if (msg
) printk (KERN_INFO
"%s: restart (%s).\n", ncr_name (np
), msg
);
4528 ** Clear Start Queue
4530 np
->queuedepth
= MAX_START
- 1; /* 1 entry needed as end marker */
4531 for (i
= 1; i
< MAX_START
+ MAX_START
; i
+= 2)
4532 np
->scripth0
->tryloop
[i
] =
4533 cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
4536 ** Start at first entry.
4539 np
->script0
->startpos
[0] = cpu_to_scr(NCB_SCRIPTH_PHYS (np
, tryloop
));
4541 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
4545 for (i
= 0; i
< MAX_DONE
; i
++) {
4546 np
->ccb_done
[i
] = (struct ccb
*)CCB_DONE_EMPTY
;
4547 np
->scripth0
->done_queue
[5*i
+ 4] =
4548 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_end
));
4553 ** Start at first entry.
4555 np
->script0
->done_pos
[0] = cpu_to_scr(NCB_SCRIPTH_PHYS (np
,done_queue
));
4556 np
->ccb_done_ic
= MAX_DONE
-1;
4557 np
->scripth0
->done_queue
[5*(MAX_DONE
-1) + 4] =
4558 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_plug
));
4561 ** Wakeup all pending jobs.
4563 ncr_wakeup (np
, code
);
4570 ** Remove reset; big delay because the 895 needs time for the
4571 ** bus mode to settle
4573 ncr_chip_reset(np
, 2000);
4575 OUTB (nc_scntl0
, np
->rv_scntl0
| 0xc0);
4576 /* full arb., ena parity, par->ATN */
4577 OUTB (nc_scntl1
, 0x00); /* odd parity, and remove CRST!! */
4579 ncr_selectclock(np
, np
->rv_scntl3
); /* Select SCSI clock */
4581 OUTB (nc_scid
, RRE
|np
->myaddr
); /* Adapter SCSI address */
4582 OUTW (nc_respid
, 1ul<<np
->myaddr
); /* Id to respond to */
4583 OUTB (nc_istat
, SIGP
); /* Signal Process */
4584 OUTB (nc_dmode
, np
->rv_dmode
); /* Burst length, dma mode */
4585 OUTB (nc_ctest5
, np
->rv_ctest5
); /* Large fifo + large burst */
4587 OUTB (nc_dcntl
, NOCOM
|np
->rv_dcntl
); /* Protect SFBR */
4588 OUTB (nc_ctest0
, np
->rv_ctest0
); /* 720: CDIS and EHP */
4589 OUTB (nc_ctest3
, np
->rv_ctest3
); /* Write and invalidate */
4590 OUTB (nc_ctest4
, np
->rv_ctest4
); /* Master parity checking */
4592 OUTB (nc_stest2
, EXT
|np
->rv_stest2
); /* Extended Sreq/Sack filtering */
4593 OUTB (nc_stest3
, TE
); /* TolerANT enable */
4594 OUTB (nc_stime0
, 0x0c ); /* HTH disabled STO 0.25 sec */
4597 ** Disable disconnects.
4603 ** Enable GPIO0 pin for writing if LED support.
4606 if (np
->features
& FE_LED0
) {
4607 OUTOFFB (nc_gpcntl
, 0x01);
4614 OUTW (nc_sien
, STO
|HTH
|MA
|SGE
|UDC
|RST
|PAR
);
4615 OUTB (nc_dien
, MDPE
|BF
|ABRT
|SSI
|SIR
|IID
);
4618 ** Fill in target structure.
4619 ** Reinitialize usrsync.
4620 ** Reinitialize usrwide.
4621 ** Prepare sync negotiation according to actual SCSI bus mode.
4624 for (i
=0;i
<MAX_TARGET
;i
++) {
4625 struct tcb
*tp
= &np
->target
[i
];
4628 tp
->wval
= np
->rv_scntl3
;
4630 if (tp
->usrsync
!= 255) {
4631 if (tp
->usrsync
<= np
->maxsync
) {
4632 if (tp
->usrsync
< np
->minsync
) {
4633 tp
->usrsync
= np
->minsync
;
4640 if (tp
->usrwide
> np
->maxwide
)
4641 tp
->usrwide
= np
->maxwide
;
4646 ** Start script processor.
4650 printk ("%s: Downloading SCSI SCRIPTS.\n",
4652 OUTL (nc_scratcha
, vtobus(np
->script0
));
4653 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, start_ram
));
4656 OUTL_DSP (NCB_SCRIPT_PHYS (np
, start
));
4659 /*==========================================================
4661 ** Prepare the negotiation values for wide and
4662 ** synchronous transfers.
4664 **==========================================================
4667 static void ncr_negotiate (struct ncb
* np
, struct tcb
* tp
)
4670 ** minsync unit is 4ns !
4673 u_long minsync
= tp
->usrsync
;
4676 ** SCSI bus mode limit
4679 if (np
->scsi_mode
&& np
->scsi_mode
== SMODE_SE
) {
4680 if (minsync
< 12) minsync
= 12;
4687 if (minsync
< np
->minsync
)
4688 minsync
= np
->minsync
;
4694 if (minsync
> np
->maxsync
)
4697 if (tp
->maxoffs
> np
->maxoffs
)
4698 tp
->maxoffs
= np
->maxoffs
;
4700 tp
->minsync
= minsync
;
4701 tp
->maxoffs
= (minsync
<255 ? tp
->maxoffs
: 0);
4704 ** period=0: has to negotiate sync transfer
4710 ** widedone=0: has to negotiate wide transfer
4715 /*==========================================================
4717 ** Get clock factor and sync divisor for a given
4718 ** synchronous factor period.
4719 ** Returns the clock factor (in sxfer) and scntl3
4720 ** synchronous divisor field.
4722 **==========================================================
4725 static void ncr_getsync(struct ncb
*np
, u_char sfac
, u_char
*fakp
, u_char
*scntl3p
)
4727 u_long clk
= np
->clock_khz
; /* SCSI clock frequency in kHz */
4728 int div
= np
->clock_divn
; /* Number of divisors supported */
4729 u_long fak
; /* Sync factor in sxfer */
4730 u_long per
; /* Period in tenths of ns */
4731 u_long kpc
; /* (per * clk) */
4734 ** Compute the synchronous period in tenths of nano-seconds
4736 if (sfac
<= 10) per
= 250;
4737 else if (sfac
== 11) per
= 303;
4738 else if (sfac
== 12) per
= 500;
4739 else per
= 40 * sfac
;
4742 ** Look for the greatest clock divisor that allows an
4743 ** input speed faster than the period.
4747 if (kpc
>= (div_10M
[div
] << 2)) break;
4750 ** Calculate the lowest clock factor that allows an output
4751 ** speed not faster than the period.
4753 fak
= (kpc
- 1) / div_10M
[div
] + 1;
4755 #if 0 /* This optimization does not seem very useful */
4757 per
= (fak
* div_10M
[div
]) / clk
;
4760 ** Why not to try the immediate lower divisor and to choose
4761 ** the one that allows the fastest output speed ?
4762 ** We don't want input speed too much greater than output speed.
4764 if (div
>= 1 && fak
< 8) {
4766 fak2
= (kpc
- 1) / div_10M
[div
-1] + 1;
4767 per2
= (fak2
* div_10M
[div
-1]) / clk
;
4768 if (per2
< per
&& fak2
<= 8) {
4776 if (fak
< 4) fak
= 4; /* Should never happen, too bad ... */
4779 ** Compute and return sync parameters for the ncr
4782 *scntl3p
= ((div
+1) << 4) + (sfac
< 25 ? 0x80 : 0);
4786 /*==========================================================
4788 ** Set actual values, sync status and patch all ccbs of
4789 ** a target according to new sync/wide agreement.
4791 **==========================================================
4794 static void ncr_set_sync_wide_status (struct ncb
*np
, u_char target
)
4797 struct tcb
*tp
= &np
->target
[target
];
4800 ** set actual value and sync_status
4802 OUTB (nc_sxfer
, tp
->sval
);
4803 np
->sync_st
= tp
->sval
;
4804 OUTB (nc_scntl3
, tp
->wval
);
4805 np
->wide_st
= tp
->wval
;
4808 ** patch ALL ccbs of this target.
4810 for (cp
= np
->ccb
; cp
; cp
= cp
->link_ccb
) {
4811 if (!cp
->cmd
) continue;
4812 if (scmd_id(cp
->cmd
) != target
) continue;
4814 cp
->sync_status
= tp
->sval
;
4815 cp
->wide_status
= tp
->wval
;
4817 cp
->phys
.select
.sel_scntl3
= tp
->wval
;
4818 cp
->phys
.select
.sel_sxfer
= tp
->sval
;
4822 /*==========================================================
4824 ** Switch sync mode for current job and it's target
4826 **==========================================================
4829 static void ncr_setsync (struct ncb
*np
, struct ccb
*cp
, u_char scntl3
, u_char sxfer
)
4831 struct scsi_cmnd
*cmd
= cp
->cmd
;
4833 u_char target
= INB (nc_sdid
) & 0x0f;
4836 BUG_ON(target
!= (scmd_id(cmd
) & 0xf));
4838 tp
= &np
->target
[target
];
4840 if (!scntl3
|| !(sxfer
& 0x1f))
4841 scntl3
= np
->rv_scntl3
;
4842 scntl3
= (scntl3
& 0xf0) | (tp
->wval
& EWS
) | (np
->rv_scntl3
& 0x07);
4845 ** Deduce the value of controller sync period from scntl3.
4846 ** period is in tenths of nano-seconds.
4849 idiv
= ((scntl3
>> 4) & 0x7);
4850 if ((sxfer
& 0x1f) && idiv
)
4851 tp
->period
= (((sxfer
>>5)+4)*div_10M
[idiv
-1])/np
->clock_khz
;
4853 tp
->period
= 0xffff;
4855 /* Stop there if sync parameters are unchanged */
4856 if (tp
->sval
== sxfer
&& tp
->wval
== scntl3
)
4861 if (sxfer
& 0x01f) {
4862 /* Disable extended Sreq/Sack filtering */
4863 if (tp
->period
<= 2000)
4864 OUTOFFB(nc_stest2
, EXT
);
4867 spi_display_xfer_agreement(tp
->starget
);
4870 ** set actual value and sync_status
4871 ** patch ALL ccbs of this target.
4873 ncr_set_sync_wide_status(np
, target
);
4876 /*==========================================================
4878 ** Switch wide mode for current job and it's target
4879 ** SCSI specs say: a SCSI device that accepts a WDTR
4880 ** message shall reset the synchronous agreement to
4881 ** asynchronous mode.
4883 **==========================================================
4886 static void ncr_setwide (struct ncb
*np
, struct ccb
*cp
, u_char wide
, u_char ack
)
4888 struct scsi_cmnd
*cmd
= cp
->cmd
;
4889 u16 target
= INB (nc_sdid
) & 0x0f;
4894 BUG_ON(target
!= (scmd_id(cmd
) & 0xf));
4896 tp
= &np
->target
[target
];
4897 tp
->widedone
= wide
+1;
4898 scntl3
= (tp
->wval
& (~EWS
)) | (wide
? EWS
: 0);
4900 sxfer
= ack
? 0 : tp
->sval
;
4903 ** Stop there if sync/wide parameters are unchanged
4905 if (tp
->sval
== sxfer
&& tp
->wval
== scntl3
) return;
4910 ** Bells and whistles ;-)
4912 if (bootverbose
>= 2) {
4913 dev_info(&cmd
->device
->sdev_target
->dev
, "WIDE SCSI %sabled.\n",
4914 (scntl3
& EWS
) ? "en" : "dis");
4918 ** set actual value and sync_status
4919 ** patch ALL ccbs of this target.
4921 ncr_set_sync_wide_status(np
, target
);
4924 /*==========================================================
4926 ** Switch tagged mode for a target.
4928 **==========================================================
4931 static void ncr_setup_tags (struct ncb
*np
, struct scsi_device
*sdev
)
4933 unsigned char tn
= sdev
->id
, ln
= sdev
->lun
;
4934 struct tcb
*tp
= &np
->target
[tn
];
4935 struct lcb
*lp
= tp
->lp
[ln
];
4936 u_char reqtags
, maxdepth
;
4941 if ((!tp
) || (!lp
) || !sdev
)
4945 ** If SCSI device queue depth is not yet set, leave here.
4947 if (!lp
->scdev_depth
)
4951 ** Donnot allow more tags than the SCSI driver can queue
4953 ** Donnot allow more tags than we can handle.
4955 maxdepth
= lp
->scdev_depth
;
4956 if (maxdepth
> lp
->maxnxs
) maxdepth
= lp
->maxnxs
;
4957 if (lp
->maxtags
> maxdepth
) lp
->maxtags
= maxdepth
;
4958 if (lp
->numtags
> maxdepth
) lp
->numtags
= maxdepth
;
4961 ** only devices conformant to ANSI Version >= 2
4962 ** only devices capable of tagged commands
4963 ** only if enabled by user ..
4965 if (sdev
->tagged_supported
&& lp
->numtags
> 1) {
4966 reqtags
= lp
->numtags
;
4972 ** Update max number of tags
4974 lp
->numtags
= reqtags
;
4975 if (lp
->numtags
> lp
->maxtags
)
4976 lp
->maxtags
= lp
->numtags
;
4979 ** If we want to switch tag mode, we must wait
4980 ** for no CCB to be active.
4982 if (reqtags
> 1 && lp
->usetags
) { /* Stay in tagged mode */
4983 if (lp
->queuedepth
== reqtags
) /* Already announced */
4985 lp
->queuedepth
= reqtags
;
4987 else if (reqtags
<= 1 && !lp
->usetags
) { /* Stay in untagged mode */
4988 lp
->queuedepth
= reqtags
;
4991 else { /* Want to switch tag mode */
4992 if (lp
->busyccbs
) /* If not yet safe, return */
4994 lp
->queuedepth
= reqtags
;
4995 lp
->usetags
= reqtags
> 1 ? 1 : 0;
4999 ** Patch the lun mini-script, according to tag mode.
5001 lp
->jump_tag
.l_paddr
= lp
->usetags
?
5002 cpu_to_scr(NCB_SCRIPT_PHYS(np
, resel_tag
)) :
5003 cpu_to_scr(NCB_SCRIPT_PHYS(np
, resel_notag
));
5006 ** Announce change to user.
5010 dev_info(&sdev
->sdev_gendev
,
5011 "tagged command queue depth set to %d\n",
5014 dev_info(&sdev
->sdev_gendev
,
5015 "tagged command queueing disabled\n");
5020 /*==========================================================
5023 ** ncr timeout handler.
5026 **==========================================================
5028 ** Misused to keep the driver running when
5029 ** interrupts are not configured correctly.
5031 **----------------------------------------------------------
5034 static void ncr_timeout (struct ncb
*np
)
5036 u_long thistime
= jiffies
;
5039 ** If release process in progress, let's go
5040 ** Set the release stage from 1 to 2 to synchronize
5041 ** with the release process.
5044 if (np
->release_stage
) {
5045 if (np
->release_stage
== 1) np
->release_stage
= 2;
5049 np
->timer
.expires
= jiffies
+ SCSI_NCR_TIMER_INTERVAL
;
5050 add_timer(&np
->timer
);
5053 ** If we are resetting the ncr, wait for settle_time before
5054 ** clearing it. Then command processing will be resumed.
5056 if (np
->settle_time
) {
5057 if (np
->settle_time
<= thistime
) {
5058 if (bootverbose
> 1)
5059 printk("%s: command processing resumed\n", ncr_name(np
));
5060 np
->settle_time
= 0;
5062 requeue_waiting_list(np
);
5068 ** Since the generic scsi driver only allows us 0.5 second
5069 ** to perform abort of a command, we must look at ccbs about
5070 ** every 0.25 second.
5072 if (np
->lasttime
+ 4*HZ
< thistime
) {
5074 ** block ncr interrupts
5076 np
->lasttime
= thistime
;
5079 #ifdef SCSI_NCR_BROKEN_INTR
5080 if (INB(nc_istat
) & (INTF
|SIP
|DIP
)) {
5083 ** Process pending interrupts.
5085 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("{");
5087 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("}");
5089 #endif /* SCSI_NCR_BROKEN_INTR */
5092 /*==========================================================
5094 ** log message for real hard errors
5096 ** "ncr0 targ 0?: ERROR (ds:si) (so-si-sd) (sxfer/scntl3) @ name (dsp:dbc)."
5097 ** " reg: r0 r1 r2 r3 r4 r5 r6 ..... rf."
5099 ** exception register:
5104 ** so: control lines as driver by NCR.
5105 ** si: control lines as seen by NCR.
5106 ** sd: scsi data lines as seen by NCR.
5109 ** sxfer: (see the manual)
5110 ** scntl3: (see the manual)
5112 ** current script command:
5113 ** dsp: script address (relative to start of script).
5114 ** dbc: first word of script command.
5116 ** First 16 register of the chip:
5119 **==========================================================
5122 static void ncr_log_hard_error(struct ncb
*np
, u16 sist
, u_char dstat
)
5128 u_char
*script_base
;
5133 if (dsp
> np
->p_script
&& dsp
<= np
->p_script
+ sizeof(struct script
)) {
5134 script_ofs
= dsp
- np
->p_script
;
5135 script_size
= sizeof(struct script
);
5136 script_base
= (u_char
*) np
->script0
;
5137 script_name
= "script";
5139 else if (np
->p_scripth
< dsp
&&
5140 dsp
<= np
->p_scripth
+ sizeof(struct scripth
)) {
5141 script_ofs
= dsp
- np
->p_scripth
;
5142 script_size
= sizeof(struct scripth
);
5143 script_base
= (u_char
*) np
->scripth0
;
5144 script_name
= "scripth";
5149 script_name
= "mem";
5152 printk ("%s:%d: ERROR (%x:%x) (%x-%x-%x) (%x/%x) @ (%s %x:%08x).\n",
5153 ncr_name (np
), (unsigned)INB (nc_sdid
)&0x0f, dstat
, sist
,
5154 (unsigned)INB (nc_socl
), (unsigned)INB (nc_sbcl
), (unsigned)INB (nc_sbdl
),
5155 (unsigned)INB (nc_sxfer
),(unsigned)INB (nc_scntl3
), script_name
, script_ofs
,
5156 (unsigned)INL (nc_dbc
));
5158 if (((script_ofs
& 3) == 0) &&
5159 (unsigned)script_ofs
< script_size
) {
5160 printk ("%s: script cmd = %08x\n", ncr_name(np
),
5161 scr_to_cpu((int) *(ncrcmd
*)(script_base
+ script_ofs
)));
5164 printk ("%s: regdump:", ncr_name(np
));
5166 printk (" %02x", (unsigned)INB_OFF(i
));
5170 /*============================================================
5172 ** ncr chip exception handler.
5174 **============================================================
5176 ** In normal cases, interrupt conditions occur one at a
5177 ** time. The ncr is able to stack in some extra registers
5178 ** other interrupts that will occurs after the first one.
5179 ** But severall interrupts may occur at the same time.
5181 ** We probably should only try to deal with the normal
5182 ** case, but it seems that multiple interrupts occur in
5183 ** some cases that are not abnormal at all.
5185 ** The most frequent interrupt condition is Phase Mismatch.
5186 ** We should want to service this interrupt quickly.
5187 ** A SCSI parity error may be delivered at the same time.
5188 ** The SIR interrupt is not very frequent in this driver,
5189 ** since the INTFLY is likely used for command completion
5191 ** The Selection Timeout interrupt may be triggered with
5193 ** The SBMC interrupt (SCSI Bus Mode Change) may probably
5194 ** occur at any time.
5196 ** This handler try to deal as cleverly as possible with all
5199 **============================================================
5202 void ncr_exception (struct ncb
*np
)
5204 u_char istat
, dstat
;
5209 ** interrupt on the fly ?
5210 ** Since the global header may be copied back to a CCB
5211 ** using a posted PCI memory write, the last operation on
5212 ** the istat register is a READ in order to flush posted
5213 ** PCI write commands.
5215 istat
= INB (nc_istat
);
5217 OUTB (nc_istat
, (istat
& SIGP
) | INTF
);
5218 istat
= INB (nc_istat
);
5219 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("F ");
5220 ncr_wakeup_done (np
);
5223 if (!(istat
& (SIP
|DIP
)))
5227 OUTB (nc_istat
, CABRT
);
5230 ** Steinbach's Guideline for Systems Programming:
5231 ** Never test for an error condition you don't know how to handle.
5234 sist
= (istat
& SIP
) ? INW (nc_sist
) : 0;
5235 dstat
= (istat
& DIP
) ? INB (nc_dstat
) : 0;
5237 if (DEBUG_FLAGS
& DEBUG_TINY
)
5238 printk ("<%d|%x:%x|%x:%x>",
5241 (unsigned)INL(nc_dsp
),
5242 (unsigned)INL(nc_dbc
));
5244 /*========================================================
5245 ** First, interrupts we want to service cleanly.
5247 ** Phase mismatch is the most frequent interrupt, and
5248 ** so we have to service it as quickly and as cleanly
5250 ** Programmed interrupts are rarely used in this driver,
5251 ** but we must handle them cleanly anyway.
5252 ** We try to deal with PAR and SBMC combined with
5253 ** some other interrupt(s).
5254 **=========================================================
5257 if (!(sist
& (STO
|GEN
|HTH
|SGE
|UDC
|RST
)) &&
5258 !(dstat
& (MDPE
|BF
|ABRT
|IID
))) {
5259 if ((sist
& SBMC
) && ncr_int_sbmc (np
))
5261 if ((sist
& PAR
) && ncr_int_par (np
))
5272 ** DEL 397 - 53C875 Rev 3 - Part Number 609-0392410 - ITEM 2.
5274 if (!(sist
& (SBMC
|PAR
)) && !(dstat
& SSI
)) {
5275 printk( "%s: unknown interrupt(s) ignored, "
5276 "ISTAT=%x DSTAT=%x SIST=%x\n",
5277 ncr_name(np
), istat
, dstat
, sist
);
5284 /*========================================================
5285 ** Now, interrupts that need some fixing up.
5286 ** Order and multiple interrupts is so less important.
5288 ** If SRST has been asserted, we just reset the chip.
5290 ** Selection is intirely handled by the chip. If the
5291 ** chip says STO, we trust it. Seems some other
5292 ** interrupts may occur at the same time (UDC, IID), so
5293 ** we ignore them. In any case we do enough fix-up
5294 ** in the service routine.
5295 ** We just exclude some fatal dma errors.
5296 **=========================================================
5300 ncr_init (np
, 1, bootverbose
? "scsi reset" : NULL
, HS_RESET
);
5305 !(dstat
& (MDPE
|BF
|ABRT
))) {
5307 ** DEL 397 - 53C875 Rev 3 - Part Number 609-0392410 - ITEM 1.
5309 OUTONB (nc_ctest3
, CLF
);
5315 /*=========================================================
5316 ** Now, interrupts we are not able to recover cleanly.
5317 ** (At least for the moment).
5319 ** Do the register dump.
5320 ** Log message for real hard errors.
5322 ** For MDPE, BF, ABORT, IID, SGE and HTH we reset the
5323 ** BUS and the chip.
5324 ** We are more soft for UDC.
5325 **=========================================================
5328 if (time_after(jiffies
, np
->regtime
)) {
5329 np
->regtime
= jiffies
+ 10*HZ
;
5330 for (i
= 0; i
<sizeof(np
->regdump
); i
++)
5331 ((char*)&np
->regdump
)[i
] = INB_OFF(i
);
5332 np
->regdump
.nc_dstat
= dstat
;
5333 np
->regdump
.nc_sist
= sist
;
5336 ncr_log_hard_error(np
, sist
, dstat
);
5338 printk ("%s: have to clear fifos.\n", ncr_name (np
));
5339 OUTB (nc_stest3
, TE
|CSF
);
5340 OUTONB (nc_ctest3
, CLF
);
5342 if ((sist
& (SGE
)) ||
5343 (dstat
& (MDPE
|BF
|ABRT
|IID
))) {
5344 ncr_start_reset(np
);
5349 printk ("%s: handshake timeout\n", ncr_name(np
));
5350 ncr_start_reset(np
);
5355 printk ("%s: unexpected disconnect\n", ncr_name(np
));
5356 OUTB (HS_PRT
, HS_UNEXPECTED
);
5357 OUTL_DSP (NCB_SCRIPT_PHYS (np
, cleanup
));
5361 /*=========================================================
5362 ** We just miss the cause of the interrupt. :(
5363 ** Print a message. The timeout will do the real work.
5364 **=========================================================
5366 printk ("%s: unknown interrupt\n", ncr_name(np
));
5369 /*==========================================================
5371 ** ncr chip exception handler for selection timeout
5373 **==========================================================
5375 ** There seems to be a bug in the 53c810.
5376 ** Although a STO-Interrupt is pending,
5377 ** it continues executing script commands.
5378 ** But it will fail and interrupt (IID) on
5379 ** the next instruction where it's looking
5380 ** for a valid phase.
5382 **----------------------------------------------------------
5385 void ncr_int_sto (struct ncb
*np
)
5389 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("T");
5392 ** look for ccb and set the status.
5397 while (cp
&& (CCB_PHYS (cp
, phys
) != dsa
))
5401 cp
-> host_status
= HS_SEL_TIMEOUT
;
5402 ncr_complete (np
, cp
);
5406 ** repair start queue and jump to start point.
5409 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, sto_restart
));
5413 /*==========================================================
5415 ** ncr chip exception handler for SCSI bus mode change
5417 **==========================================================
5419 ** spi2-r12 11.2.3 says a transceiver mode change must
5420 ** generate a reset event and a device that detects a reset
5421 ** event shall initiate a hard reset. It says also that a
5422 ** device that detects a mode change shall set data transfer
5423 ** mode to eight bit asynchronous, etc...
5424 ** So, just resetting should be enough.
5427 **----------------------------------------------------------
5430 static int ncr_int_sbmc (struct ncb
*np
)
5432 u_char scsi_mode
= INB (nc_stest4
) & SMODE
;
5434 if (scsi_mode
!= np
->scsi_mode
) {
5435 printk("%s: SCSI bus mode change from %x to %x.\n",
5436 ncr_name(np
), np
->scsi_mode
, scsi_mode
);
5438 np
->scsi_mode
= scsi_mode
;
5442 ** Suspend command processing for 1 second and
5443 ** reinitialize all except the chip.
5445 np
->settle_time
= jiffies
+ HZ
;
5446 ncr_init (np
, 0, bootverbose
? "scsi mode change" : NULL
, HS_RESET
);
5452 /*==========================================================
5454 ** ncr chip exception handler for SCSI parity error.
5456 **==========================================================
5459 **----------------------------------------------------------
5462 static int ncr_int_par (struct ncb
*np
)
5464 u_char hsts
= INB (HS_PRT
);
5465 u32 dbc
= INL (nc_dbc
);
5466 u_char sstat1
= INB (nc_sstat1
);
5471 printk("%s: SCSI parity error detected: SCR1=%d DBC=%x SSTAT1=%x\n",
5472 ncr_name(np
), hsts
, dbc
, sstat1
);
5475 * Ignore the interrupt if the NCR is not connected
5476 * to the SCSI bus, since the right work should have
5477 * been done on unexpected disconnection handling.
5479 if (!(INB (nc_scntl1
) & ISCON
))
5483 * If the nexus is not clearly identified, reset the bus.
5484 * We will try to do better later.
5486 if (hsts
& HS_INVALMASK
)
5490 * If the SCSI parity error occurs in MSG IN phase, prepare a
5491 * MSG PARITY message. Otherwise, prepare a INITIATOR DETECTED
5492 * ERROR message and let the device decide to retry the command
5493 * or to terminate with check condition. If we were in MSG IN
5494 * phase waiting for the response of a negotiation, we will
5495 * get SIR_NEGO_FAILED at dispatch.
5497 if (!(dbc
& 0xc0000000))
5498 phase
= (dbc
>> 24) & 7;
5506 * If the NCR stopped on a MOVE ^ DATA_IN, we jump to a
5507 * script that will ignore all data in bytes until phase
5508 * change, since we are not sure the chip will wait the phase
5509 * change prior to delivering the interrupt.
5512 jmp
= NCB_SCRIPTH_PHYS (np
, par_err_data_in
);
5514 jmp
= NCB_SCRIPTH_PHYS (np
, par_err_other
);
5516 OUTONB (nc_ctest3
, CLF
); /* clear dma fifo */
5517 OUTB (nc_stest3
, TE
|CSF
); /* clear scsi fifo */
5519 np
->msgout
[0] = msg
;
5524 ncr_start_reset(np
);
5528 /*==========================================================
5531 ** ncr chip exception handler for phase errors.
5534 **==========================================================
5536 ** We have to construct a new transfer descriptor,
5537 ** to transfer the rest of the current block.
5539 **----------------------------------------------------------
5542 static void ncr_int_ma (struct ncb
*np
)
5559 sbcl
= INB (nc_sbcl
);
5562 rest
= dbc
& 0xffffff;
5565 ** Take into account dma fifo and various buffers and latches,
5566 ** only if the interrupted phase is an OUTPUT phase.
5569 if ((cmd
& 1) == 0) {
5570 u_char ctest5
, ss0
, ss2
;
5573 ctest5
= (np
->rv_ctest5
& DFS
) ? INB (nc_ctest5
) : 0;
5575 delta
=(((ctest5
<< 8) | (INB (nc_dfifo
) & 0xff)) - rest
) & 0x3ff;
5577 delta
=(INB (nc_dfifo
) - rest
) & 0x7f;
5580 ** The data in the dma fifo has not been transferred to
5581 ** the target -> add the amount to the rest
5582 ** and clear the data.
5583 ** Check the sstat2 register in case of wide transfer.
5587 ss0
= INB (nc_sstat0
);
5588 if (ss0
& OLF
) rest
++;
5589 if (ss0
& ORF
) rest
++;
5590 if (INB(nc_scntl3
) & EWS
) {
5591 ss2
= INB (nc_sstat2
);
5592 if (ss2
& OLF1
) rest
++;
5593 if (ss2
& ORF1
) rest
++;
5596 if (DEBUG_FLAGS
& (DEBUG_TINY
|DEBUG_PHASE
))
5597 printk ("P%x%x RL=%d D=%d SS0=%x ", cmd
&7, sbcl
&7,
5598 (unsigned) rest
, (unsigned) delta
, ss0
);
5601 if (DEBUG_FLAGS
& (DEBUG_TINY
|DEBUG_PHASE
))
5602 printk ("P%x%x RL=%d ", cmd
&7, sbcl
&7, rest
);
5608 OUTONB (nc_ctest3
, CLF
); /* clear dma fifo */
5609 OUTB (nc_stest3
, TE
|CSF
); /* clear scsi fifo */
5612 ** locate matching cp.
5613 ** if the interrupted phase is DATA IN or DATA OUT,
5614 ** trust the global header.
5619 if (CCB_PHYS(cp
, phys
) != dsa
)
5623 while (cp
&& (CCB_PHYS (cp
, phys
) != dsa
))
5628 ** try to find the interrupted script command,
5629 ** and the address at which to continue.
5633 if (dsp
> np
->p_script
&&
5634 dsp
<= np
->p_script
+ sizeof(struct script
)) {
5635 vdsp
= (u32
*)((char*)np
->script0
+ (dsp
-np
->p_script
-8));
5638 else if (dsp
> np
->p_scripth
&&
5639 dsp
<= np
->p_scripth
+ sizeof(struct scripth
)) {
5640 vdsp
= (u32
*)((char*)np
->scripth0
+ (dsp
-np
->p_scripth
-8));
5644 if (dsp
== CCB_PHYS (cp
, patch
[2])) {
5645 vdsp
= &cp
->patch
[0];
5646 nxtdsp
= scr_to_cpu(vdsp
[3]);
5648 else if (dsp
== CCB_PHYS (cp
, patch
[6])) {
5649 vdsp
= &cp
->patch
[4];
5650 nxtdsp
= scr_to_cpu(vdsp
[3]);
5655 ** log the information
5658 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
5659 printk ("\nCP=%p CP2=%p DSP=%x NXT=%x VDSP=%p CMD=%x ",
5662 (unsigned)nxtdsp
, vdsp
, cmd
);
5666 ** cp=0 means that the DSA does not point to a valid control
5667 ** block. This should not happen since we donnot use multi-byte
5668 ** move while we are being reselected ot after command complete.
5669 ** We are not able to recover from such a phase error.
5672 printk ("%s: SCSI phase error fixup: "
5673 "CCB already dequeued (0x%08lx)\n",
5674 ncr_name (np
), (u_long
) np
->header
.cp
);
5679 ** get old startaddress and old length.
5682 oadr
= scr_to_cpu(vdsp
[1]);
5684 if (cmd
& 0x10) { /* Table indirect */
5685 tblp
= (u32
*) ((char*) &cp
->phys
+ oadr
);
5686 olen
= scr_to_cpu(tblp
[0]);
5687 oadr
= scr_to_cpu(tblp
[1]);
5690 olen
= scr_to_cpu(vdsp
[0]) & 0xffffff;
5693 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
5694 printk ("OCMD=%x\nTBLP=%p OLEN=%x OADR=%x\n",
5695 (unsigned) (scr_to_cpu(vdsp
[0]) >> 24),
5702 ** check cmd against assumed interrupted script command.
5705 if (cmd
!= (scr_to_cpu(vdsp
[0]) >> 24)) {
5706 PRINT_ADDR(cp
->cmd
, "internal error: cmd=%02x != %02x=(vdsp[0] "
5707 ">> 24)\n", cmd
, scr_to_cpu(vdsp
[0]) >> 24);
5713 ** cp != np->header.cp means that the header of the CCB
5714 ** currently being processed has not yet been copied to
5715 ** the global header area. That may happen if the device did
5716 ** not accept all our messages after having been selected.
5718 if (cp
!= np
->header
.cp
) {
5719 printk ("%s: SCSI phase error fixup: "
5720 "CCB address mismatch (0x%08lx != 0x%08lx)\n",
5721 ncr_name (np
), (u_long
) cp
, (u_long
) np
->header
.cp
);
5725 ** if old phase not dataphase, leave here.
5729 PRINT_ADDR(cp
->cmd
, "phase change %x-%x %d@%08x resid=%d.\n",
5730 cmd
&7, sbcl
&7, (unsigned)olen
,
5731 (unsigned)oadr
, (unsigned)rest
);
5732 goto unexpected_phase
;
5736 ** choose the correct patch area.
5737 ** if savep points to one, choose the other.
5741 newtmp
= CCB_PHYS (cp
, patch
);
5742 if (newtmp
== scr_to_cpu(cp
->phys
.header
.savep
)) {
5743 newcmd
= &cp
->patch
[4];
5744 newtmp
= CCB_PHYS (cp
, patch
[4]);
5748 ** fillin the commands
5751 newcmd
[0] = cpu_to_scr(((cmd
& 0x0f) << 24) | rest
);
5752 newcmd
[1] = cpu_to_scr(oadr
+ olen
- rest
);
5753 newcmd
[2] = cpu_to_scr(SCR_JUMP
);
5754 newcmd
[3] = cpu_to_scr(nxtdsp
);
5756 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
5757 PRINT_ADDR(cp
->cmd
, "newcmd[%d] %x %x %x %x.\n",
5758 (int) (newcmd
- cp
->patch
),
5759 (unsigned)scr_to_cpu(newcmd
[0]),
5760 (unsigned)scr_to_cpu(newcmd
[1]),
5761 (unsigned)scr_to_cpu(newcmd
[2]),
5762 (unsigned)scr_to_cpu(newcmd
[3]));
5765 ** fake the return address (to the patch).
5766 ** and restart script processor at dispatcher.
5768 OUTL (nc_temp
, newtmp
);
5769 OUTL_DSP (NCB_SCRIPT_PHYS (np
, dispatch
));
5773 ** Unexpected phase changes that occurs when the current phase
5774 ** is not a DATA IN or DATA OUT phase are due to error conditions.
5775 ** Such event may only happen when the SCRIPTS is using a
5776 ** multibyte SCSI MOVE.
5778 ** Phase change Some possible cause
5780 ** COMMAND --> MSG IN SCSI parity error detected by target.
5781 ** COMMAND --> STATUS Bad command or refused by target.
5782 ** MSG OUT --> MSG IN Message rejected by target.
5783 ** MSG OUT --> COMMAND Bogus target that discards extended
5784 ** negotiation messages.
5786 ** The code below does not care of the new phase and so
5787 ** trusts the target. Why to annoy it ?
5788 ** If the interrupted phase is COMMAND phase, we restart at
5790 ** If a target does not get all the messages after selection,
5791 ** the code assumes blindly that the target discards extended
5792 ** messages and clears the negotiation status.
5793 ** If the target does not want all our response to negotiation,
5794 ** we force a SIR_NEGO_PROTO interrupt (it is a hack that avoids
5795 ** bloat for such a should_not_happen situation).
5796 ** In all other situation, we reset the BUS.
5797 ** Are these assumptions reasonnable ? (Wait and see ...)
5804 case 2: /* COMMAND phase */
5805 nxtdsp
= NCB_SCRIPT_PHYS (np
, dispatch
);
5808 case 3: /* STATUS phase */
5809 nxtdsp
= NCB_SCRIPT_PHYS (np
, dispatch
);
5812 case 6: /* MSG OUT phase */
5813 np
->scripth
->nxtdsp_go_on
[0] = cpu_to_scr(dsp
+ 8);
5814 if (dsp
== NCB_SCRIPT_PHYS (np
, send_ident
)) {
5815 cp
->host_status
= HS_BUSY
;
5816 nxtdsp
= NCB_SCRIPTH_PHYS (np
, clratn_go_on
);
5818 else if (dsp
== NCB_SCRIPTH_PHYS (np
, send_wdtr
) ||
5819 dsp
== NCB_SCRIPTH_PHYS (np
, send_sdtr
)) {
5820 nxtdsp
= NCB_SCRIPTH_PHYS (np
, nego_bad_phase
);
5824 case 7: /* MSG IN phase */
5825 nxtdsp
= NCB_SCRIPT_PHYS (np
, clrack
);
5836 ncr_start_reset(np
);
5840 static void ncr_sir_to_redo(struct ncb
*np
, int num
, struct ccb
*cp
)
5842 struct scsi_cmnd
*cmd
= cp
->cmd
;
5843 struct tcb
*tp
= &np
->target
[cmd
->device
->id
];
5844 struct lcb
*lp
= tp
->lp
[cmd
->device
->lun
];
5845 struct list_head
*qp
;
5850 u_char s_status
= INB (SS_PRT
);
5853 ** Let the SCRIPTS processor skip all not yet started CCBs,
5854 ** and count disconnected CCBs. Since the busy queue is in
5855 ** the same order as the chip start queue, disconnected CCBs
5856 ** are before cp and busy ones after.
5859 qp
= lp
->busy_ccbq
.prev
;
5860 while (qp
!= &lp
->busy_ccbq
) {
5861 cp2
= list_entry(qp
, struct ccb
, link_ccbq
);
5866 cp2
->start
.schedule
.l_paddr
=
5867 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, skip
));
5869 lp
->held_ccb
= cp
; /* Requeue when this one completes */
5870 disc_cnt
= lp
->queuedccbs
- busy_cnt
;
5874 default: /* Just for safety, should never happen */
5877 ** Decrease number of tags to the number of
5878 ** disconnected commands.
5882 if (bootverbose
>= 1) {
5883 PRINT_ADDR(cmd
, "QUEUE FULL! %d busy, %d disconnected "
5884 "CCBs\n", busy_cnt
, disc_cnt
);
5886 if (disc_cnt
< lp
->numtags
) {
5887 lp
->numtags
= disc_cnt
> 2 ? disc_cnt
: 2;
5889 ncr_setup_tags (np
, cmd
->device
);
5892 ** Requeue the command to the start queue.
5893 ** If any disconnected commands,
5895 ** Jump to reselect.
5897 cp
->phys
.header
.savep
= cp
->startp
;
5898 cp
->host_status
= HS_BUSY
;
5899 cp
->scsi_status
= S_ILLEGAL
;
5901 ncr_put_start_queue(np
, cp
);
5903 INB (nc_ctest2
); /* Clear SIGP */
5904 OUTL_DSP (NCB_SCRIPT_PHYS (np
, reselect
));
5909 ** If we were requesting sense, give up.
5915 ** Device returned CHECK CONDITION status.
5916 ** Prepare all needed data strutures for getting
5921 cp
->scsi_smsg2
[0] = IDENTIFY(0, cmd
->device
->lun
);
5922 cp
->phys
.smsg
.addr
= cpu_to_scr(CCB_PHYS (cp
, scsi_smsg2
));
5923 cp
->phys
.smsg
.size
= cpu_to_scr(1);
5928 cp
->phys
.cmd
.addr
= cpu_to_scr(CCB_PHYS (cp
, sensecmd
));
5929 cp
->phys
.cmd
.size
= cpu_to_scr(6);
5932 ** patch requested size into sense command
5934 cp
->sensecmd
[0] = 0x03;
5935 cp
->sensecmd
[1] = cmd
->device
->lun
<< 5;
5936 cp
->sensecmd
[4] = sizeof(cp
->sense_buf
);
5941 memset(cp
->sense_buf
, 0, sizeof(cp
->sense_buf
));
5942 cp
->phys
.sense
.addr
= cpu_to_scr(CCB_PHYS(cp
,sense_buf
[0]));
5943 cp
->phys
.sense
.size
= cpu_to_scr(sizeof(cp
->sense_buf
));
5946 ** requeue the command.
5948 startp
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, sdata_in
));
5950 cp
->phys
.header
.savep
= startp
;
5951 cp
->phys
.header
.goalp
= startp
+ 24;
5952 cp
->phys
.header
.lastp
= startp
;
5953 cp
->phys
.header
.wgoalp
= startp
+ 24;
5954 cp
->phys
.header
.wlastp
= startp
;
5956 cp
->host_status
= HS_BUSY
;
5957 cp
->scsi_status
= S_ILLEGAL
;
5958 cp
->auto_sense
= s_status
;
5960 cp
->start
.schedule
.l_paddr
=
5961 cpu_to_scr(NCB_SCRIPT_PHYS (np
, select
));
5964 ** Select without ATN for quirky devices.
5966 if (cmd
->device
->select_no_atn
)
5967 cp
->start
.schedule
.l_paddr
=
5968 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, select_no_atn
));
5970 ncr_put_start_queue(np
, cp
);
5972 OUTL_DSP (NCB_SCRIPT_PHYS (np
, start
));
5982 /*==========================================================
5985 ** ncr chip exception handler for programmed interrupts.
5988 **==========================================================
5991 void ncr_int_sir (struct ncb
*np
)
5994 u_char chg
, ofs
, per
, fak
, wide
;
5995 u_char num
= INB (nc_dsps
);
5996 struct ccb
*cp
=NULL
;
5997 u_long dsa
= INL (nc_dsa
);
5998 u_char target
= INB (nc_sdid
) & 0x0f;
5999 struct tcb
*tp
= &np
->target
[target
];
6000 struct scsi_target
*starget
= tp
->starget
;
6002 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("I#%d", num
);
6007 ** This is used for HP Zalon/53c720 where INTFLY
6008 ** operation is currently broken.
6010 ncr_wakeup_done(np
);
6011 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
6012 OUTL(nc_dsp
, NCB_SCRIPT_PHYS (np
, done_end
) + 8);
6014 OUTL(nc_dsp
, NCB_SCRIPT_PHYS (np
, start
));
6017 case SIR_RESEL_NO_MSG_IN
:
6018 case SIR_RESEL_NO_IDENTIFY
:
6020 ** If devices reselecting without sending an IDENTIFY
6021 ** message still exist, this should help.
6022 ** We just assume lun=0, 1 CCB, no tag.
6025 OUTL_DSP (scr_to_cpu(tp
->lp
[0]->jump_ccb
[0]));
6028 case SIR_RESEL_BAD_TARGET
: /* Will send a TARGET RESET message */
6029 case SIR_RESEL_BAD_LUN
: /* Will send a TARGET RESET message */
6030 case SIR_RESEL_BAD_I_T_L_Q
: /* Will send an ABORT TAG message */
6031 case SIR_RESEL_BAD_I_T_L
: /* Will send an ABORT message */
6032 printk ("%s:%d: SIR %d, "
6033 "incorrect nexus identification on reselection\n",
6034 ncr_name (np
), target
, num
);
6036 case SIR_DONE_OVERFLOW
:
6037 printk ("%s:%d: SIR %d, "
6038 "CCB done queue overflow\n",
6039 ncr_name (np
), target
, num
);
6041 case SIR_BAD_STATUS
:
6043 if (!cp
|| CCB_PHYS (cp
, phys
) != dsa
)
6045 ncr_sir_to_redo(np
, num
, cp
);
6052 while (cp
&& (CCB_PHYS (cp
, phys
) != dsa
))
6056 BUG_ON(cp
!= np
->header
.cp
);
6058 if (!cp
|| cp
!= np
->header
.cp
)
6063 /*-----------------------------------------------------------------------------
6065 ** Was Sie schon immer ueber transfermode negotiation wissen wollten ...
6067 ** We try to negotiate sync and wide transfer only after
6068 ** a successful inquire command. We look at byte 7 of the
6069 ** inquire data to determine the capabilities of the target.
6071 ** When we try to negotiate, we append the negotiation message
6072 ** to the identify and (maybe) simple tag message.
6073 ** The host status field is set to HS_NEGOTIATE to mark this
6076 ** If the target doesn't answer this message immidiately
6077 ** (as required by the standard), the SIR_NEGO_FAIL interrupt
6078 ** will be raised eventually.
6079 ** The handler removes the HS_NEGOTIATE status, and sets the
6080 ** negotiated value to the default (async / nowide).
6082 ** If we receive a matching answer immediately, we check it
6083 ** for validity, and set the values.
6085 ** If we receive a Reject message immediately, we assume the
6086 ** negotiation has failed, and fall back to standard values.
6088 ** If we receive a negotiation message while not in HS_NEGOTIATE
6089 ** state, it's a target initiated negotiation. We prepare a
6090 ** (hopefully) valid answer, set our parameters, and send back
6091 ** this answer to the target.
6093 ** If the target doesn't fetch the answer (no message out phase),
6094 ** we assume the negotiation has failed, and fall back to default
6097 ** When we set the values, we adjust them in all ccbs belonging
6098 ** to this target, in the controller's register, and in the "phys"
6099 ** field of the controller's struct ncb.
6101 ** Possible cases: hs sir msg_in value send goto
6102 ** We try to negotiate:
6103 ** -> target doesn't msgin NEG FAIL noop defa. - dispatch
6104 ** -> target rejected our msg NEG FAIL reject defa. - dispatch
6105 ** -> target answered (ok) NEG SYNC sdtr set - clrack
6106 ** -> target answered (!ok) NEG SYNC sdtr defa. REJ--->msg_bad
6107 ** -> target answered (ok) NEG WIDE wdtr set - clrack
6108 ** -> target answered (!ok) NEG WIDE wdtr defa. REJ--->msg_bad
6109 ** -> any other msgin NEG FAIL noop defa. - dispatch
6111 ** Target tries to negotiate:
6112 ** -> incoming message --- SYNC sdtr set SDTR -
6113 ** -> incoming message --- WIDE wdtr set WDTR -
6114 ** We sent our answer:
6115 ** -> target doesn't msgout --- PROTO ? defa. - dispatch
6117 **-----------------------------------------------------------------------------
6120 case SIR_NEGO_FAILED
:
6121 /*-------------------------------------------------------
6123 ** Negotiation failed.
6124 ** Target doesn't send an answer message,
6125 ** or target rejected our message.
6127 ** Remove negotiation request.
6129 **-------------------------------------------------------
6131 OUTB (HS_PRT
, HS_BUSY
);
6135 case SIR_NEGO_PROTO
:
6136 /*-------------------------------------------------------
6138 ** Negotiation failed.
6139 ** Target doesn't fetch the answer message.
6141 **-------------------------------------------------------
6144 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6145 PRINT_ADDR(cp
->cmd
, "negotiation failed sir=%x "
6146 "status=%x.\n", num
, cp
->nego_status
);
6150 ** any error in negotiation:
6151 ** fall back to default mode.
6153 switch (cp
->nego_status
) {
6156 spi_period(starget
) = 0;
6157 spi_offset(starget
) = 0;
6158 ncr_setsync (np
, cp
, 0, 0xe0);
6162 spi_width(starget
) = 0;
6163 ncr_setwide (np
, cp
, 0, 0);
6167 np
->msgin
[0] = M_NOOP
;
6168 np
->msgout
[0] = M_NOOP
;
6169 cp
->nego_status
= 0;
6173 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6174 ncr_print_msg(cp
, "sync msgin", np
->msgin
);
6180 if (ofs
==0) per
=255;
6183 ** if target sends SDTR message,
6184 ** it CAN transfer synch.
6188 spi_support_sync(starget
) = 1;
6191 ** check values against driver limits.
6194 if (per
< np
->minsync
)
6195 {chg
= 1; per
= np
->minsync
;}
6196 if (per
< tp
->minsync
)
6197 {chg
= 1; per
= tp
->minsync
;}
6198 if (ofs
> tp
->maxoffs
)
6199 {chg
= 1; ofs
= tp
->maxoffs
;}
6202 ** Check against controller limits.
6207 ncr_getsync(np
, per
, &fak
, &scntl3
);
6220 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6221 PRINT_ADDR(cp
->cmd
, "sync: per=%d scntl3=0x%x ofs=%d "
6222 "fak=%d chg=%d.\n", per
, scntl3
, ofs
, fak
, chg
);
6225 if (INB (HS_PRT
) == HS_NEGOTIATE
) {
6226 OUTB (HS_PRT
, HS_BUSY
);
6227 switch (cp
->nego_status
) {
6230 /* This was an answer message */
6232 /* Answer wasn't acceptable. */
6233 spi_period(starget
) = 0;
6234 spi_offset(starget
) = 0;
6235 ncr_setsync(np
, cp
, 0, 0xe0);
6236 OUTL_DSP(NCB_SCRIPT_PHYS (np
, msg_bad
));
6239 spi_period(starget
) = per
;
6240 spi_offset(starget
) = ofs
;
6241 ncr_setsync(np
, cp
, scntl3
, (fak
<<5)|ofs
);
6242 OUTL_DSP(NCB_SCRIPT_PHYS (np
, clrack
));
6247 spi_width(starget
) = 0;
6248 ncr_setwide(np
, cp
, 0, 0);
6254 ** It was a request. Set value and
6255 ** prepare an answer message
6258 spi_period(starget
) = per
;
6259 spi_offset(starget
) = ofs
;
6260 ncr_setsync(np
, cp
, scntl3
, (fak
<<5)|ofs
);
6262 np
->msgout
[0] = M_EXTENDED
;
6264 np
->msgout
[2] = M_X_SYNC_REQ
;
6265 np
->msgout
[3] = per
;
6266 np
->msgout
[4] = ofs
;
6268 cp
->nego_status
= NS_SYNC
;
6270 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6271 ncr_print_msg(cp
, "sync msgout", np
->msgout
);
6275 OUTL_DSP (NCB_SCRIPT_PHYS (np
, msg_bad
));
6278 np
->msgin
[0] = M_NOOP
;
6284 ** Wide request message received.
6286 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6287 ncr_print_msg(cp
, "wide msgin", np
->msgin
);
6291 ** get requested values.
6295 wide
= np
->msgin
[3];
6298 ** if target sends WDTR message,
6299 ** it CAN transfer wide.
6302 if (wide
&& starget
)
6303 spi_support_wide(starget
) = 1;
6306 ** check values against driver limits.
6309 if (wide
> tp
->usrwide
)
6310 {chg
= 1; wide
= tp
->usrwide
;}
6312 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6313 PRINT_ADDR(cp
->cmd
, "wide: wide=%d chg=%d.\n", wide
,
6317 if (INB (HS_PRT
) == HS_NEGOTIATE
) {
6318 OUTB (HS_PRT
, HS_BUSY
);
6319 switch (cp
->nego_status
) {
6323 ** This was an answer message
6326 /* Answer wasn't acceptable. */
6327 spi_width(starget
) = 0;
6328 ncr_setwide(np
, cp
, 0, 1);
6329 OUTL_DSP (NCB_SCRIPT_PHYS (np
, msg_bad
));
6332 spi_width(starget
) = wide
;
6333 ncr_setwide(np
, cp
, wide
, 1);
6334 OUTL_DSP (NCB_SCRIPT_PHYS (np
, clrack
));
6339 spi_period(starget
) = 0;
6340 spi_offset(starget
) = 0;
6341 ncr_setsync(np
, cp
, 0, 0xe0);
6347 ** It was a request, set value and
6348 ** prepare an answer message
6351 spi_width(starget
) = wide
;
6352 ncr_setwide(np
, cp
, wide
, 1);
6354 np
->msgout
[0] = M_EXTENDED
;
6356 np
->msgout
[2] = M_X_WIDE_REQ
;
6357 np
->msgout
[3] = wide
;
6359 np
->msgin
[0] = M_NOOP
;
6361 cp
->nego_status
= NS_WIDE
;
6363 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6364 ncr_print_msg(cp
, "wide msgout", np
->msgin
);
6368 /*--------------------------------------------------------------------
6370 ** Processing of special messages
6372 **--------------------------------------------------------------------
6375 case SIR_REJECT_RECEIVED
:
6376 /*-----------------------------------------------
6378 ** We received a M_REJECT message.
6380 **-----------------------------------------------
6383 PRINT_ADDR(cp
->cmd
, "M_REJECT received (%x:%x).\n",
6384 (unsigned)scr_to_cpu(np
->lastmsg
), np
->msgout
[0]);
6387 case SIR_REJECT_SENT
:
6388 /*-----------------------------------------------
6390 ** We received an unknown message
6392 **-----------------------------------------------
6395 ncr_print_msg(cp
, "M_REJECT sent for", np
->msgin
);
6398 /*--------------------------------------------------------------------
6400 ** Processing of special messages
6402 **--------------------------------------------------------------------
6405 case SIR_IGN_RESIDUE
:
6406 /*-----------------------------------------------
6408 ** We received an IGNORE RESIDUE message,
6409 ** which couldn't be handled by the script.
6411 **-----------------------------------------------
6414 PRINT_ADDR(cp
->cmd
, "M_IGN_RESIDUE received, but not yet "
6418 case SIR_MISSING_SAVE
:
6419 /*-----------------------------------------------
6421 ** We received an DISCONNECT message,
6422 ** but the datapointer wasn't saved before.
6424 **-----------------------------------------------
6427 PRINT_ADDR(cp
->cmd
, "M_DISCONNECT received, but datapointer "
6428 "not saved: data=%x save=%x goal=%x.\n",
6429 (unsigned) INL (nc_temp
),
6430 (unsigned) scr_to_cpu(np
->header
.savep
),
6431 (unsigned) scr_to_cpu(np
->header
.goalp
));
6440 /*==========================================================
6443 ** Acquire a control block
6446 **==========================================================
6449 static struct ccb
*ncr_get_ccb(struct ncb
*np
, struct scsi_cmnd
*cmd
)
6451 u_char tn
= cmd
->device
->id
;
6452 u_char ln
= cmd
->device
->lun
;
6453 struct tcb
*tp
= &np
->target
[tn
];
6454 struct lcb
*lp
= tp
->lp
[ln
];
6455 u_char tag
= NO_TAG
;
6456 struct ccb
*cp
= NULL
;
6459 ** Lun structure available ?
6462 struct list_head
*qp
;
6464 ** Keep from using more tags than we can handle.
6466 if (lp
->usetags
&& lp
->busyccbs
>= lp
->maxnxs
)
6470 ** Allocate a new CCB if needed.
6472 if (list_empty(&lp
->free_ccbq
))
6473 ncr_alloc_ccb(np
, tn
, ln
);
6476 ** Look for free CCB
6478 qp
= ncr_list_pop(&lp
->free_ccbq
);
6480 cp
= list_entry(qp
, struct ccb
, link_ccbq
);
6482 PRINT_ADDR(cmd
, "ccb free list corrupted "
6486 list_add_tail(qp
, &lp
->wait_ccbq
);
6492 ** If a CCB is available,
6493 ** Get a tag for this nexus if required.
6497 tag
= lp
->cb_tags
[lp
->ia_tag
];
6499 else if (lp
->actccbs
> 0)
6504 ** if nothing available, take the default.
6510 ** Wait until available.
6514 if (flags
& SCSI_NOSLEEP
) break;
6515 if (tsleep ((caddr_t
)cp
, PRIBIO
|PCATCH
, "ncr", 0))
6526 ** Move to next available tag if tag used.
6529 if (tag
!= NO_TAG
) {
6531 if (lp
->ia_tag
== MAX_TAGS
)
6533 lp
->tags_umap
|= (((tagmap_t
) 1) << tag
);
6538 ** Remember all informations needed to free this CCB.
6544 if (DEBUG_FLAGS
& DEBUG_TAGS
) {
6545 PRINT_ADDR(cmd
, "ccb @%p using tag %d.\n", cp
, tag
);
6551 /*==========================================================
6554 ** Release one control block
6557 **==========================================================
6560 static void ncr_free_ccb (struct ncb
*np
, struct ccb
*cp
)
6562 struct tcb
*tp
= &np
->target
[cp
->target
];
6563 struct lcb
*lp
= tp
->lp
[cp
->lun
];
6565 if (DEBUG_FLAGS
& DEBUG_TAGS
) {
6566 PRINT_ADDR(cp
->cmd
, "ccb @%p freeing tag %d.\n", cp
, cp
->tag
);
6570 ** If lun control block available,
6571 ** decrement active commands and increment credit,
6572 ** free the tag if any and remove the JUMP for reselect.
6575 if (cp
->tag
!= NO_TAG
) {
6576 lp
->cb_tags
[lp
->if_tag
++] = cp
->tag
;
6577 if (lp
->if_tag
== MAX_TAGS
)
6579 lp
->tags_umap
&= ~(((tagmap_t
) 1) << cp
->tag
);
6580 lp
->tags_smap
&= lp
->tags_umap
;
6581 lp
->jump_ccb
[cp
->tag
] =
6582 cpu_to_scr(NCB_SCRIPTH_PHYS(np
, bad_i_t_l_q
));
6585 cpu_to_scr(NCB_SCRIPTH_PHYS(np
, bad_i_t_l
));
6590 ** Make this CCB available.
6595 list_move(&cp
->link_ccbq
, &lp
->free_ccbq
);
6601 cp
-> host_status
= HS_IDLE
;
6610 wakeup ((caddr_t
) cp
);
6615 #define ncr_reg_bus_addr(r) (np->paddr + offsetof (struct ncr_reg, r))
6617 /*------------------------------------------------------------------------
6618 ** Initialize the fixed part of a CCB structure.
6619 **------------------------------------------------------------------------
6620 **------------------------------------------------------------------------
6622 static void ncr_init_ccb(struct ncb
*np
, struct ccb
*cp
)
6624 ncrcmd copy_4
= np
->features
& FE_PFEN
? SCR_COPY(4) : SCR_COPY_F(4);
6627 ** Remember virtual and bus address of this ccb.
6629 cp
->p_ccb
= vtobus(cp
);
6630 cp
->phys
.header
.cp
= cp
;
6633 ** This allows list_del to work for the default ccb.
6635 INIT_LIST_HEAD(&cp
->link_ccbq
);
6638 ** Initialyze the start and restart launch script.
6640 ** COPY(4) @(...p_phys), @(dsa)
6641 ** JUMP @(sched_point)
6643 cp
->start
.setup_dsa
[0] = cpu_to_scr(copy_4
);
6644 cp
->start
.setup_dsa
[1] = cpu_to_scr(CCB_PHYS(cp
, start
.p_phys
));
6645 cp
->start
.setup_dsa
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_dsa
));
6646 cp
->start
.schedule
.l_cmd
= cpu_to_scr(SCR_JUMP
);
6647 cp
->start
.p_phys
= cpu_to_scr(CCB_PHYS(cp
, phys
));
6649 memcpy(&cp
->restart
, &cp
->start
, sizeof(cp
->restart
));
6651 cp
->start
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
6652 cp
->restart
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, abort
));
6656 /*------------------------------------------------------------------------
6657 ** Allocate a CCB and initialize its fixed part.
6658 **------------------------------------------------------------------------
6659 **------------------------------------------------------------------------
6661 static void ncr_alloc_ccb(struct ncb
*np
, u_char tn
, u_char ln
)
6663 struct tcb
*tp
= &np
->target
[tn
];
6664 struct lcb
*lp
= tp
->lp
[ln
];
6665 struct ccb
*cp
= NULL
;
6668 ** Allocate memory for this CCB.
6670 cp
= m_calloc_dma(sizeof(struct ccb
), "CCB");
6675 ** Count it and initialyze it.
6679 memset(cp
, 0, sizeof (*cp
));
6680 ncr_init_ccb(np
, cp
);
6683 ** Chain into wakeup list and free ccb queue and take it
6684 ** into account for tagged commands.
6686 cp
->link_ccb
= np
->ccb
->link_ccb
;
6687 np
->ccb
->link_ccb
= cp
;
6689 list_add(&cp
->link_ccbq
, &lp
->free_ccbq
);
6692 /*==========================================================
6695 ** Allocation of resources for Targets/Luns/Tags.
6698 **==========================================================
6702 /*------------------------------------------------------------------------
6703 ** Target control block initialisation.
6704 **------------------------------------------------------------------------
6705 ** This data structure is fully initialized after a SCSI command
6706 ** has been successfully completed for this target.
6707 ** It contains a SCRIPT that is called on target reselection.
6708 **------------------------------------------------------------------------
6710 static void ncr_init_tcb (struct ncb
*np
, u_char tn
)
6712 struct tcb
*tp
= &np
->target
[tn
];
6713 ncrcmd copy_1
= np
->features
& FE_PFEN
? SCR_COPY(1) : SCR_COPY_F(1);
6718 ** Jump to next tcb if SFBR does not match this target.
6719 ** JUMP IF (SFBR != #target#), @(next tcb)
6721 tp
->jump_tcb
.l_cmd
=
6722 cpu_to_scr((SCR_JUMP
^ IFFALSE (DATA (0x80 + tn
))));
6723 tp
->jump_tcb
.l_paddr
= np
->jump_tcb
[th
].l_paddr
;
6726 ** Load the synchronous transfer register.
6727 ** COPY @(tp->sval), @(sxfer)
6729 tp
->getscr
[0] = cpu_to_scr(copy_1
);
6730 tp
->getscr
[1] = cpu_to_scr(vtobus (&tp
->sval
));
6731 #ifdef SCSI_NCR_BIG_ENDIAN
6732 tp
->getscr
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_sxfer
) ^ 3);
6734 tp
->getscr
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_sxfer
));
6738 ** Load the timing register.
6739 ** COPY @(tp->wval), @(scntl3)
6741 tp
->getscr
[3] = cpu_to_scr(copy_1
);
6742 tp
->getscr
[4] = cpu_to_scr(vtobus (&tp
->wval
));
6743 #ifdef SCSI_NCR_BIG_ENDIAN
6744 tp
->getscr
[5] = cpu_to_scr(ncr_reg_bus_addr(nc_scntl3
) ^ 3);
6746 tp
->getscr
[5] = cpu_to_scr(ncr_reg_bus_addr(nc_scntl3
));
6750 ** Get the IDENTIFY message and the lun.
6751 ** CALL @script(resel_lun)
6753 tp
->call_lun
.l_cmd
= cpu_to_scr(SCR_CALL
);
6754 tp
->call_lun
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, resel_lun
));
6757 ** Look for the lun control block of this nexus.
6759 ** JUMP ^ IFTRUE (MASK (i, 3)), @(next_lcb)
6761 for (i
= 0 ; i
< 4 ; i
++) {
6762 tp
->jump_lcb
[i
].l_cmd
=
6763 cpu_to_scr((SCR_JUMP
^ IFTRUE (MASK (i
, 3))));
6764 tp
->jump_lcb
[i
].l_paddr
=
6765 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_identify
));
6769 ** Link this target control block to the JUMP chain.
6771 np
->jump_tcb
[th
].l_paddr
= cpu_to_scr(vtobus (&tp
->jump_tcb
));
6774 ** These assert's should be moved at driver initialisations.
6776 #ifdef SCSI_NCR_BIG_ENDIAN
6777 BUG_ON(((offsetof(struct ncr_reg
, nc_sxfer
) ^
6778 offsetof(struct tcb
, sval
)) &3) != 3);
6779 BUG_ON(((offsetof(struct ncr_reg
, nc_scntl3
) ^
6780 offsetof(struct tcb
, wval
)) &3) != 3);
6782 BUG_ON(((offsetof(struct ncr_reg
, nc_sxfer
) ^
6783 offsetof(struct tcb
, sval
)) &3) != 0);
6784 BUG_ON(((offsetof(struct ncr_reg
, nc_scntl3
) ^
6785 offsetof(struct tcb
, wval
)) &3) != 0);
6790 /*------------------------------------------------------------------------
6791 ** Lun control block allocation and initialization.
6792 **------------------------------------------------------------------------
6793 ** This data structure is allocated and initialized after a SCSI
6794 ** command has been successfully completed for this target/lun.
6795 **------------------------------------------------------------------------
6797 static struct lcb
*ncr_alloc_lcb (struct ncb
*np
, u_char tn
, u_char ln
)
6799 struct tcb
*tp
= &np
->target
[tn
];
6800 struct lcb
*lp
= tp
->lp
[ln
];
6801 ncrcmd copy_4
= np
->features
& FE_PFEN
? SCR_COPY(4) : SCR_COPY_F(4);
6805 ** Already done, return.
6811 ** Allocate the lcb.
6813 lp
= m_calloc_dma(sizeof(struct lcb
), "LCB");
6816 memset(lp
, 0, sizeof(*lp
));
6820 ** Initialize the target control block if not yet.
6822 if (!tp
->jump_tcb
.l_cmd
)
6823 ncr_init_tcb(np
, tn
);
6826 ** Initialize the CCB queue headers.
6828 INIT_LIST_HEAD(&lp
->free_ccbq
);
6829 INIT_LIST_HEAD(&lp
->busy_ccbq
);
6830 INIT_LIST_HEAD(&lp
->wait_ccbq
);
6831 INIT_LIST_HEAD(&lp
->skip_ccbq
);
6834 ** Set max CCBs to 1 and use the default 1 entry
6835 ** jump table by default.
6838 lp
->jump_ccb
= &lp
->jump_ccb_0
;
6839 lp
->p_jump_ccb
= cpu_to_scr(vtobus(lp
->jump_ccb
));
6842 ** Initilialyze the reselect script:
6844 ** Jump to next lcb if SFBR does not match this lun.
6845 ** Load TEMP with the CCB direct jump table bus address.
6846 ** Get the SIMPLE TAG message and the tag.
6848 ** JUMP IF (SFBR != #lun#), @(next lcb)
6849 ** COPY @(lp->p_jump_ccb), @(temp)
6850 ** JUMP @script(resel_notag)
6852 lp
->jump_lcb
.l_cmd
=
6853 cpu_to_scr((SCR_JUMP
^ IFFALSE (MASK (0x80+ln
, 0xff))));
6854 lp
->jump_lcb
.l_paddr
= tp
->jump_lcb
[lh
].l_paddr
;
6856 lp
->load_jump_ccb
[0] = cpu_to_scr(copy_4
);
6857 lp
->load_jump_ccb
[1] = cpu_to_scr(vtobus (&lp
->p_jump_ccb
));
6858 lp
->load_jump_ccb
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_temp
));
6860 lp
->jump_tag
.l_cmd
= cpu_to_scr(SCR_JUMP
);
6861 lp
->jump_tag
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, resel_notag
));
6864 ** Link this lun control block to the JUMP chain.
6866 tp
->jump_lcb
[lh
].l_paddr
= cpu_to_scr(vtobus (&lp
->jump_lcb
));
6869 ** Initialize command queuing control.
6879 /*------------------------------------------------------------------------
6880 ** Lun control block setup on INQUIRY data received.
6881 **------------------------------------------------------------------------
6882 ** We only support WIDE, SYNC for targets and CMDQ for logical units.
6883 ** This setup is done on each INQUIRY since we are expecting user
6884 ** will play with CHANGE DEFINITION commands. :-)
6885 **------------------------------------------------------------------------
6887 static struct lcb
*ncr_setup_lcb (struct ncb
*np
, struct scsi_device
*sdev
)
6889 unsigned char tn
= sdev
->id
, ln
= sdev
->lun
;
6890 struct tcb
*tp
= &np
->target
[tn
];
6891 struct lcb
*lp
= tp
->lp
[ln
];
6893 /* If no lcb, try to allocate it. */
6894 if (!lp
&& !(lp
= ncr_alloc_lcb(np
, tn
, ln
)))
6898 ** If unit supports tagged commands, allocate the
6899 ** CCB JUMP table if not yet.
6901 if (sdev
->tagged_supported
&& lp
->jump_ccb
== &lp
->jump_ccb_0
) {
6903 lp
->jump_ccb
= m_calloc_dma(256, "JUMP_CCB");
6904 if (!lp
->jump_ccb
) {
6905 lp
->jump_ccb
= &lp
->jump_ccb_0
;
6908 lp
->p_jump_ccb
= cpu_to_scr(vtobus(lp
->jump_ccb
));
6909 for (i
= 0 ; i
< 64 ; i
++)
6911 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_i_t_l_q
));
6912 for (i
= 0 ; i
< MAX_TAGS
; i
++)
6914 lp
->maxnxs
= MAX_TAGS
;
6915 lp
->tags_stime
= jiffies
+ 3*HZ
;
6916 ncr_setup_tags (np
, sdev
);
6924 /*==========================================================
6927 ** Build Scatter Gather Block
6930 **==========================================================
6932 ** The transfer area may be scattered among
6933 ** several non adjacent physical pages.
6935 ** We may use MAX_SCATTER blocks.
6937 **----------------------------------------------------------
6941 ** We try to reduce the number of interrupts caused
6942 ** by unexpected phase changes due to disconnects.
6943 ** A typical harddisk may disconnect before ANY block.
6944 ** If we wanted to avoid unexpected phase changes at all
6945 ** we had to use a break point every 512 bytes.
6946 ** Of course the number of scatter/gather blocks is
6948 ** Under Linux, the scatter/gatter blocks are provided by
6949 ** the generic driver. We just have to copy addresses and
6950 ** sizes to the data segment array.
6953 static int ncr_scatter_no_sglist(struct ncb
*np
, struct ccb
*cp
, struct scsi_cmnd
*cmd
)
6955 struct scr_tblmove
*data
= &cp
->phys
.data
[MAX_SCATTER
- 1];
6958 cp
->data_len
= cmd
->request_bufflen
;
6960 if (cmd
->request_bufflen
) {
6961 dma_addr_t baddr
= map_scsi_single_data(np
, cmd
);
6963 ncr_build_sge(np
, data
, baddr
, cmd
->request_bufflen
);
6975 static int ncr_scatter(struct ncb
*np
, struct ccb
*cp
, struct scsi_cmnd
*cmd
)
6978 int use_sg
= (int) cmd
->use_sg
;
6983 segment
= ncr_scatter_no_sglist(np
, cp
, cmd
);
6984 else if ((use_sg
= map_scsi_sg_data(np
, cmd
)) > 0) {
6985 struct scatterlist
*scatter
= (struct scatterlist
*)cmd
->buffer
;
6986 struct scr_tblmove
*data
;
6988 if (use_sg
> MAX_SCATTER
) {
6989 unmap_scsi_data(np
, cmd
);
6993 data
= &cp
->phys
.data
[MAX_SCATTER
- use_sg
];
6995 for (segment
= 0; segment
< use_sg
; segment
++) {
6996 dma_addr_t baddr
= sg_dma_address(&scatter
[segment
]);
6997 unsigned int len
= sg_dma_len(&scatter
[segment
]);
6999 ncr_build_sge(np
, &data
[segment
], baddr
, len
);
7000 cp
->data_len
+= len
;
7009 /*==========================================================
7012 ** Test the bus snoop logic :-(
7014 ** Has to be called with interrupts disabled.
7017 **==========================================================
7020 static int __init
ncr_regtest (struct ncb
* np
)
7022 register volatile u32 data
;
7024 ** ncr registers may NOT be cached.
7025 ** write 0xffffffff to a read only register area,
7026 ** and try to read it back.
7029 OUTL_OFF(offsetof(struct ncr_reg
, nc_dstat
), data
);
7030 data
= INL_OFF(offsetof(struct ncr_reg
, nc_dstat
));
7032 if (data
== 0xffffffff) {
7034 if ((data
& 0xe2f0fffd) != 0x02000080) {
7036 printk ("CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
7043 static int __init
ncr_snooptest (struct ncb
* np
)
7045 u32 ncr_rd
, ncr_wr
, ncr_bk
, host_rd
, host_wr
, pc
;
7048 err
|= ncr_regtest (np
);
7054 pc
= NCB_SCRIPTH_PHYS (np
, snooptest
);
7058 ** Set memory and register.
7060 np
->ncr_cache
= cpu_to_scr(host_wr
);
7061 OUTL (nc_temp
, ncr_wr
);
7063 ** Start script (exchange values)
7067 ** Wait 'til done (with timeout)
7069 for (i
=0; i
<NCR_SNOOP_TIMEOUT
; i
++)
7070 if (INB(nc_istat
) & (INTF
|SIP
|DIP
))
7073 ** Save termination position.
7077 ** Read memory and register.
7079 host_rd
= scr_to_cpu(np
->ncr_cache
);
7080 ncr_rd
= INL (nc_scratcha
);
7081 ncr_bk
= INL (nc_temp
);
7085 ncr_chip_reset(np
, 100);
7087 ** check for timeout
7089 if (i
>=NCR_SNOOP_TIMEOUT
) {
7090 printk ("CACHE TEST FAILED: timeout.\n");
7094 ** Check termination position.
7096 if (pc
!= NCB_SCRIPTH_PHYS (np
, snoopend
)+8) {
7097 printk ("CACHE TEST FAILED: script execution failed.\n");
7098 printk ("start=%08lx, pc=%08lx, end=%08lx\n",
7099 (u_long
) NCB_SCRIPTH_PHYS (np
, snooptest
), (u_long
) pc
,
7100 (u_long
) NCB_SCRIPTH_PHYS (np
, snoopend
) +8);
7106 if (host_wr
!= ncr_rd
) {
7107 printk ("CACHE TEST FAILED: host wrote %d, ncr read %d.\n",
7108 (int) host_wr
, (int) ncr_rd
);
7111 if (host_rd
!= ncr_wr
) {
7112 printk ("CACHE TEST FAILED: ncr wrote %d, host read %d.\n",
7113 (int) ncr_wr
, (int) host_rd
);
7116 if (ncr_bk
!= ncr_wr
) {
7117 printk ("CACHE TEST FAILED: ncr wrote %d, read back %d.\n",
7118 (int) ncr_wr
, (int) ncr_bk
);
7124 /*==========================================================
7126 ** Determine the ncr's clock frequency.
7127 ** This is essential for the negotiation
7128 ** of the synchronous transfer rate.
7130 **==========================================================
7132 ** Note: we have to return the correct value.
7133 ** THERE IS NO SAVE DEFAULT VALUE.
7135 ** Most NCR/SYMBIOS boards are delivered with a 40 Mhz clock.
7136 ** 53C860 and 53C875 rev. 1 support fast20 transfers but
7137 ** do not have a clock doubler and so are provided with a
7138 ** 80 MHz clock. All other fast20 boards incorporate a doubler
7139 ** and so should be delivered with a 40 MHz clock.
7140 ** The future fast40 chips (895/895) use a 40 Mhz base clock
7141 ** and provide a clock quadrupler (160 Mhz). The code below
7142 ** tries to deal as cleverly as possible with all this stuff.
7144 **----------------------------------------------------------
7148 * Select NCR SCSI clock frequency
7150 static void ncr_selectclock(struct ncb
*np
, u_char scntl3
)
7152 if (np
->multiplier
< 2) {
7153 OUTB(nc_scntl3
, scntl3
);
7157 if (bootverbose
>= 2)
7158 printk ("%s: enabling clock multiplier\n", ncr_name(np
));
7160 OUTB(nc_stest1
, DBLEN
); /* Enable clock multiplier */
7161 if (np
->multiplier
> 2) { /* Poll bit 5 of stest4 for quadrupler */
7163 while (!(INB(nc_stest4
) & LCKFRQ
) && --i
> 0)
7166 printk("%s: the chip cannot lock the frequency\n", ncr_name(np
));
7167 } else /* Wait 20 micro-seconds for doubler */
7169 OUTB(nc_stest3
, HSC
); /* Halt the scsi clock */
7170 OUTB(nc_scntl3
, scntl3
);
7171 OUTB(nc_stest1
, (DBLEN
|DBLSEL
));/* Select clock multiplier */
7172 OUTB(nc_stest3
, 0x00); /* Restart scsi clock */
7177 * calculate NCR SCSI clock frequency (in KHz)
7179 static unsigned __init
ncrgetfreq (struct ncb
*np
, int gen
)
7185 * Measure GEN timer delay in order
7186 * to calculate SCSI clock frequency
7188 * This code will never execute too
7189 * many loop iterations (if DELAY is
7190 * reasonably correct). It could get
7191 * too low a delay (too high a freq.)
7192 * if the CPU is slow executing the
7193 * loop for some reason (an NMI, for
7194 * example). For this reason we will
7195 * if multiple measurements are to be
7196 * performed trust the higher delay
7197 * (lower frequency returned).
7199 OUTB (nc_stest1
, 0); /* make sure clock doubler is OFF */
7200 OUTW (nc_sien
, 0); /* mask all scsi interrupts */
7201 (void) INW (nc_sist
); /* clear pending scsi interrupt */
7202 OUTB (nc_dien
, 0); /* mask all dma interrupts */
7203 (void) INW (nc_sist
); /* another one, just to be sure :) */
7204 OUTB (nc_scntl3
, 4); /* set pre-scaler to divide by 3 */
7205 OUTB (nc_stime1
, 0); /* disable general purpose timer */
7206 OUTB (nc_stime1
, gen
); /* set to nominal delay of 1<<gen * 125us */
7207 while (!(INW(nc_sist
) & GEN
) && ms
++ < 100000) {
7208 for (count
= 0; count
< 10; count
++)
7209 udelay(100); /* count ms */
7211 OUTB (nc_stime1
, 0); /* disable general purpose timer */
7213 * set prescaler to divide by whatever 0 means
7214 * 0 ought to choose divide by 2, but appears
7215 * to set divide by 3.5 mode in my 53c810 ...
7217 OUTB (nc_scntl3
, 0);
7219 if (bootverbose
>= 2)
7220 printk ("%s: Delay (GEN=%d): %u msec\n", ncr_name(np
), gen
, ms
);
7222 * adjust for prescaler, and convert into KHz
7224 return ms
? ((1 << gen
) * 4340) / ms
: 0;
7228 * Get/probe NCR SCSI clock frequency
7230 static void __init
ncr_getclock (struct ncb
*np
, int mult
)
7232 unsigned char scntl3
= INB(nc_scntl3
);
7233 unsigned char stest1
= INB(nc_stest1
);
7240 ** True with 875 or 895 with clock multiplier selected
7242 if (mult
> 1 && (stest1
& (DBLEN
+DBLSEL
)) == DBLEN
+DBLSEL
) {
7243 if (bootverbose
>= 2)
7244 printk ("%s: clock multiplier found\n", ncr_name(np
));
7245 np
->multiplier
= mult
;
7249 ** If multiplier not found or scntl3 not 7,5,3,
7250 ** reset chip and get frequency from general purpose timer.
7251 ** Otherwise trust scntl3 BIOS setting.
7253 if (np
->multiplier
!= mult
|| (scntl3
& 7) < 3 || !(scntl3
& 1)) {
7256 ncr_chip_reset(np
, 5);
7258 (void) ncrgetfreq (np
, 11); /* throw away first result */
7259 f1
= ncrgetfreq (np
, 11);
7260 f2
= ncrgetfreq (np
, 11);
7263 printk ("%s: NCR clock is %uKHz, %uKHz\n", ncr_name(np
), f1
, f2
);
7265 if (f1
> f2
) f1
= f2
; /* trust lower result */
7267 if (f1
< 45000) f1
= 40000;
7268 else if (f1
< 55000) f1
= 50000;
7271 if (f1
< 80000 && mult
> 1) {
7272 if (bootverbose
>= 2)
7273 printk ("%s: clock multiplier assumed\n", ncr_name(np
));
7274 np
->multiplier
= mult
;
7277 if ((scntl3
& 7) == 3) f1
= 40000;
7278 else if ((scntl3
& 7) == 5) f1
= 80000;
7281 f1
/= np
->multiplier
;
7285 ** Compute controller synchronous parameters.
7287 f1
*= np
->multiplier
;
7291 /*===================== LINUX ENTRY POINTS SECTION ==========================*/
7293 static int ncr53c8xx_slave_alloc(struct scsi_device
*device
)
7295 struct Scsi_Host
*host
= device
->host
;
7296 struct ncb
*np
= ((struct host_data
*) host
->hostdata
)->ncb
;
7297 struct tcb
*tp
= &np
->target
[device
->id
];
7298 tp
->starget
= device
->sdev_target
;
7303 static int ncr53c8xx_slave_configure(struct scsi_device
*device
)
7305 struct Scsi_Host
*host
= device
->host
;
7306 struct ncb
*np
= ((struct host_data
*) host
->hostdata
)->ncb
;
7307 struct tcb
*tp
= &np
->target
[device
->id
];
7308 struct lcb
*lp
= tp
->lp
[device
->lun
];
7309 int numtags
, depth_to_use
;
7311 ncr_setup_lcb(np
, device
);
7314 ** Select queue depth from driver setup.
7315 ** Donnot use more than configured by user.
7317 ** Donnot use more than our maximum.
7319 numtags
= device_queue_depth(np
->unit
, device
->id
, device
->lun
);
7320 if (numtags
> tp
->usrtags
)
7321 numtags
= tp
->usrtags
;
7322 if (!device
->tagged_supported
)
7324 depth_to_use
= numtags
;
7325 if (depth_to_use
< 2)
7327 if (depth_to_use
> MAX_TAGS
)
7328 depth_to_use
= MAX_TAGS
;
7330 scsi_adjust_queue_depth(device
,
7331 (device
->tagged_supported
?
7332 MSG_SIMPLE_TAG
: 0),
7336 ** Since the queue depth is not tunable under Linux,
7337 ** we need to know this value in order not to
7338 ** announce stupid things to user.
7340 ** XXX(hch): As of Linux 2.6 it certainly _is_ tunable..
7341 ** In fact we just tuned it, or did I miss
7342 ** something important? :)
7345 lp
->numtags
= lp
->maxtags
= numtags
;
7346 lp
->scdev_depth
= depth_to_use
;
7348 ncr_setup_tags (np
, device
);
7350 #ifdef DEBUG_NCR53C8XX
7351 printk("ncr53c8xx_select_queue_depth: host=%d, id=%d, lun=%d, depth=%d\n",
7352 np
->unit
, device
->id
, device
->lun
, depth_to_use
);
7355 if (spi_support_sync(device
->sdev_target
) &&
7356 !spi_initial_dv(device
->sdev_target
))
7357 spi_dv_device(device
);
7361 static int ncr53c8xx_queue_command (struct scsi_cmnd
*cmd
, void (* done
)(struct scsi_cmnd
*))
7363 struct ncb
*np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
7364 unsigned long flags
;
7367 #ifdef DEBUG_NCR53C8XX
7368 printk("ncr53c8xx_queue_command\n");
7371 cmd
->scsi_done
= done
;
7372 cmd
->host_scribble
= NULL
;
7373 cmd
->__data_mapped
= 0;
7374 cmd
->__data_mapping
= 0;
7376 spin_lock_irqsave(&np
->smp_lock
, flags
);
7378 if ((sts
= ncr_queue_command(np
, cmd
)) != DID_OK
) {
7379 cmd
->result
= ScsiResult(sts
, 0);
7380 #ifdef DEBUG_NCR53C8XX
7381 printk("ncr53c8xx : command not queued - result=%d\n", sts
);
7384 #ifdef DEBUG_NCR53C8XX
7386 printk("ncr53c8xx : command successfully queued\n");
7389 spin_unlock_irqrestore(&np
->smp_lock
, flags
);
7391 if (sts
!= DID_OK
) {
7392 unmap_scsi_data(np
, cmd
);
7400 irqreturn_t
ncr53c8xx_intr(int irq
, void *dev_id
, struct pt_regs
* regs
)
7402 unsigned long flags
;
7403 struct Scsi_Host
*shost
= (struct Scsi_Host
*)dev_id
;
7404 struct host_data
*host_data
= (struct host_data
*)shost
->hostdata
;
7405 struct ncb
*np
= host_data
->ncb
;
7406 struct scsi_cmnd
*done_list
;
7408 #ifdef DEBUG_NCR53C8XX
7409 printk("ncr53c8xx : interrupt received\n");
7412 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("[");
7414 spin_lock_irqsave(&np
->smp_lock
, flags
);
7416 done_list
= np
->done_list
;
7417 np
->done_list
= NULL
;
7418 spin_unlock_irqrestore(&np
->smp_lock
, flags
);
7420 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("]\n");
7423 ncr_flush_done_cmds(done_list
);
7427 static void ncr53c8xx_timeout(unsigned long npref
)
7429 struct ncb
*np
= (struct ncb
*) npref
;
7430 unsigned long flags
;
7431 struct scsi_cmnd
*done_list
;
7433 spin_lock_irqsave(&np
->smp_lock
, flags
);
7435 done_list
= np
->done_list
;
7436 np
->done_list
= NULL
;
7437 spin_unlock_irqrestore(&np
->smp_lock
, flags
);
7440 ncr_flush_done_cmds(done_list
);
7443 static int ncr53c8xx_bus_reset(struct scsi_cmnd
*cmd
)
7445 struct ncb
*np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
7447 unsigned long flags
;
7448 struct scsi_cmnd
*done_list
;
7451 * If the mid-level driver told us reset is synchronous, it seems
7452 * that we must call the done() callback for the involved command,
7453 * even if this command was not queued to the low-level driver,
7454 * before returning SUCCESS.
7457 spin_lock_irqsave(&np
->smp_lock
, flags
);
7458 sts
= ncr_reset_bus(np
, cmd
, 1);
7460 done_list
= np
->done_list
;
7461 np
->done_list
= NULL
;
7462 spin_unlock_irqrestore(&np
->smp_lock
, flags
);
7464 ncr_flush_done_cmds(done_list
);
7469 #if 0 /* unused and broken */
7470 static int ncr53c8xx_abort(struct scsi_cmnd
*cmd
)
7472 struct ncb
*np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
7474 unsigned long flags
;
7475 struct scsi_cmnd
*done_list
;
7477 #if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
7478 printk("ncr53c8xx_abort: pid=%lu serial_number=%ld\n",
7479 cmd
->pid
, cmd
->serial_number
);
7481 printk("ncr53c8xx_abort: command pid %lu\n", cmd
->pid
);
7484 NCR_LOCK_NCB(np
, flags
);
7486 sts
= ncr_abort_command(np
, cmd
);
7488 done_list
= np
->done_list
;
7489 np
->done_list
= NULL
;
7490 NCR_UNLOCK_NCB(np
, flags
);
7492 ncr_flush_done_cmds(done_list
);
7500 ** Scsi command waiting list management.
7502 ** It may happen that we cannot insert a scsi command into the start queue,
7503 ** in the following circumstances.
7504 ** Too few preallocated ccb(s),
7505 ** maxtags < cmd_per_lun of the Linux host control block,
7507 ** Such scsi commands are inserted into a waiting list.
7508 ** When a scsi command complete, we try to requeue the commands of the
7512 #define next_wcmd host_scribble
7514 static void insert_into_waiting_list(struct ncb
*np
, struct scsi_cmnd
*cmd
)
7516 struct scsi_cmnd
*wcmd
;
7518 #ifdef DEBUG_WAITING_LIST
7519 printk("%s: cmd %lx inserted into waiting list\n", ncr_name(np
), (u_long
) cmd
);
7521 cmd
->next_wcmd
= NULL
;
7522 if (!(wcmd
= np
->waiting_list
)) np
->waiting_list
= cmd
;
7524 while ((wcmd
->next_wcmd
) != 0)
7525 wcmd
= (struct scsi_cmnd
*) wcmd
->next_wcmd
;
7526 wcmd
->next_wcmd
= (char *) cmd
;
7530 static struct scsi_cmnd
*retrieve_from_waiting_list(int to_remove
, struct ncb
*np
, struct scsi_cmnd
*cmd
)
7532 struct scsi_cmnd
**pcmd
= &np
->waiting_list
;
7537 *pcmd
= (struct scsi_cmnd
*) cmd
->next_wcmd
;
7538 cmd
->next_wcmd
= NULL
;
7540 #ifdef DEBUG_WAITING_LIST
7541 printk("%s: cmd %lx retrieved from waiting list\n", ncr_name(np
), (u_long
) cmd
);
7545 pcmd
= (struct scsi_cmnd
**) &(*pcmd
)->next_wcmd
;
7550 static void process_waiting_list(struct ncb
*np
, int sts
)
7552 struct scsi_cmnd
*waiting_list
, *wcmd
;
7554 waiting_list
= np
->waiting_list
;
7555 np
->waiting_list
= NULL
;
7557 #ifdef DEBUG_WAITING_LIST
7558 if (waiting_list
) printk("%s: waiting_list=%lx processing sts=%d\n", ncr_name(np
), (u_long
) waiting_list
, sts
);
7560 while ((wcmd
= waiting_list
) != 0) {
7561 waiting_list
= (struct scsi_cmnd
*) wcmd
->next_wcmd
;
7562 wcmd
->next_wcmd
= NULL
;
7563 if (sts
== DID_OK
) {
7564 #ifdef DEBUG_WAITING_LIST
7565 printk("%s: cmd %lx trying to requeue\n", ncr_name(np
), (u_long
) wcmd
);
7567 sts
= ncr_queue_command(np
, wcmd
);
7569 if (sts
!= DID_OK
) {
7570 #ifdef DEBUG_WAITING_LIST
7571 printk("%s: cmd %lx done forced sts=%d\n", ncr_name(np
), (u_long
) wcmd
, sts
);
7573 wcmd
->result
= ScsiResult(sts
, 0);
7574 ncr_queue_done_cmd(np
, wcmd
);
7581 static ssize_t
show_ncr53c8xx_revision(struct class_device
*dev
, char *buf
)
7583 struct Scsi_Host
*host
= class_to_shost(dev
);
7584 struct host_data
*host_data
= (struct host_data
*)host
->hostdata
;
7586 return snprintf(buf
, 20, "0x%x\n", host_data
->ncb
->revision_id
);
7589 static struct class_device_attribute ncr53c8xx_revision_attr
= {
7590 .attr
= { .name
= "revision", .mode
= S_IRUGO
, },
7591 .show
= show_ncr53c8xx_revision
,
7594 static struct class_device_attribute
*ncr53c8xx_host_attrs
[] = {
7595 &ncr53c8xx_revision_attr
,
7599 /*==========================================================
7601 ** Boot command line.
7603 **==========================================================
7606 char *ncr53c8xx
; /* command line passed by insmod */
7607 module_param(ncr53c8xx
, charp
, 0);
7610 static int __init
ncr53c8xx_setup(char *str
)
7612 return sym53c8xx__setup(str
);
7616 __setup("ncr53c8xx=", ncr53c8xx_setup
);
7621 * Host attach and initialisations.
7623 * Allocate host data and ncb structure.
7624 * Request IO region and remap MMIO region.
7625 * Do chip initialization.
7626 * If all is OK, install interrupt handling and
7627 * start the timer daemon.
7629 struct Scsi_Host
* __init
ncr_attach(struct scsi_host_template
*tpnt
,
7630 int unit
, struct ncr_device
*device
)
7632 struct host_data
*host_data
;
7633 struct ncb
*np
= NULL
;
7634 struct Scsi_Host
*instance
= NULL
;
7639 tpnt
->name
= SCSI_NCR_DRIVER_NAME
;
7640 if (!tpnt
->shost_attrs
)
7641 tpnt
->shost_attrs
= ncr53c8xx_host_attrs
;
7643 tpnt
->queuecommand
= ncr53c8xx_queue_command
;
7644 tpnt
->slave_configure
= ncr53c8xx_slave_configure
;
7645 tpnt
->slave_alloc
= ncr53c8xx_slave_alloc
;
7646 tpnt
->eh_bus_reset_handler
= ncr53c8xx_bus_reset
;
7647 tpnt
->can_queue
= SCSI_NCR_CAN_QUEUE
;
7649 tpnt
->sg_tablesize
= SCSI_NCR_SG_TABLESIZE
;
7650 tpnt
->cmd_per_lun
= SCSI_NCR_CMD_PER_LUN
;
7651 tpnt
->use_clustering
= ENABLE_CLUSTERING
;
7653 if (device
->differential
)
7654 driver_setup
.diff_support
= device
->differential
;
7656 printk(KERN_INFO
"ncr53c720-%d: rev 0x%x irq %d\n",
7657 unit
, device
->chip
.revision_id
, device
->slot
.irq
);
7659 instance
= scsi_host_alloc(tpnt
, sizeof(*host_data
));
7662 host_data
= (struct host_data
*) instance
->hostdata
;
7664 np
= __m_calloc_dma(device
->dev
, sizeof(struct ncb
), "NCB");
7667 spin_lock_init(&np
->smp_lock
);
7668 np
->dev
= device
->dev
;
7669 np
->p_ncb
= vtobus(np
);
7670 host_data
->ncb
= np
;
7672 np
->ccb
= m_calloc_dma(sizeof(struct ccb
), "CCB");
7676 /* Store input information in the host data structure. */
7678 np
->verbose
= driver_setup
.verbose
;
7679 sprintf(np
->inst_name
, "ncr53c720-%d", np
->unit
);
7680 np
->revision_id
= device
->chip
.revision_id
;
7681 np
->features
= device
->chip
.features
;
7682 np
->clock_divn
= device
->chip
.nr_divisor
;
7683 np
->maxoffs
= device
->chip
.offset_max
;
7684 np
->maxburst
= device
->chip
.burst_max
;
7685 np
->myaddr
= device
->host_id
;
7687 /* Allocate SCRIPTS areas. */
7688 np
->script0
= m_calloc_dma(sizeof(struct script
), "SCRIPT");
7691 np
->scripth0
= m_calloc_dma(sizeof(struct scripth
), "SCRIPTH");
7695 init_timer(&np
->timer
);
7696 np
->timer
.data
= (unsigned long) np
;
7697 np
->timer
.function
= ncr53c8xx_timeout
;
7699 /* Try to map the controller chip to virtual and physical memory. */
7701 np
->paddr
= device
->slot
.base
;
7702 np
->paddr2
= (np
->features
& FE_RAM
) ? device
->slot
.base_2
: 0;
7704 if (device
->slot
.base_v
)
7705 np
->vaddr
= device
->slot
.base_v
;
7707 np
->vaddr
= ioremap(device
->slot
.base_c
, 128);
7711 "%s: can't map memory mapped IO region\n",ncr_name(np
));
7714 if (bootverbose
> 1)
7716 "%s: using memory mapped IO at virtual address 0x%lx\n", ncr_name(np
), (u_long
) np
->vaddr
);
7719 /* Make the controller's registers available. Now the INB INW INL
7720 * OUTB OUTW OUTL macros can be used safely.
7723 np
->reg
= (struct ncr_reg __iomem
*)np
->vaddr
;
7725 /* Do chip dependent initialization. */
7726 ncr_prepare_setting(np
);
7728 if (np
->paddr2
&& sizeof(struct script
) > 4096) {
7730 printk(KERN_WARNING
"%s: script too large, NOT using on chip RAM.\n",
7734 instance
->max_channel
= 0;
7735 instance
->this_id
= np
->myaddr
;
7736 instance
->max_id
= np
->maxwide
? 16 : 8;
7737 instance
->max_lun
= SCSI_NCR_MAX_LUN
;
7738 instance
->base
= (unsigned long) np
->reg
;
7739 instance
->irq
= device
->slot
.irq
;
7740 instance
->unique_id
= device
->slot
.base
;
7741 instance
->dma_channel
= 0;
7742 instance
->cmd_per_lun
= MAX_TAGS
;
7743 instance
->can_queue
= (MAX_START
-4);
7744 /* This can happen if you forget to call ncr53c8xx_init from
7745 * your module_init */
7746 BUG_ON(!ncr53c8xx_transport_template
);
7747 instance
->transportt
= ncr53c8xx_transport_template
;
7749 /* Patch script to physical addresses */
7750 ncr_script_fill(&script0
, &scripth0
);
7752 np
->scripth
= np
->scripth0
;
7753 np
->p_scripth
= vtobus(np
->scripth
);
7754 np
->p_script
= (np
->paddr2
) ? np
->paddr2
: vtobus(np
->script0
);
7756 ncr_script_copy_and_bind(np
, (ncrcmd
*) &script0
,
7757 (ncrcmd
*) np
->script0
, sizeof(struct script
));
7758 ncr_script_copy_and_bind(np
, (ncrcmd
*) &scripth0
,
7759 (ncrcmd
*) np
->scripth0
, sizeof(struct scripth
));
7760 np
->ccb
->p_ccb
= vtobus (np
->ccb
);
7762 /* Patch the script for LED support. */
7764 if (np
->features
& FE_LED0
) {
7765 np
->script0
->idle
[0] =
7766 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_OR
, 0x01));
7767 np
->script0
->reselected
[0] =
7768 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_AND
, 0xfe));
7769 np
->script0
->start
[0] =
7770 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_AND
, 0xfe));
7774 * Look for the target control block of this nexus.
7776 * JUMP ^ IFTRUE (MASK (i, 3)), @(next_lcb)
7778 for (i
= 0 ; i
< 4 ; i
++) {
7779 np
->jump_tcb
[i
].l_cmd
=
7780 cpu_to_scr((SCR_JUMP
^ IFTRUE (MASK (i
, 3))));
7781 np
->jump_tcb
[i
].l_paddr
=
7782 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_target
));
7785 ncr_chip_reset(np
, 100);
7787 /* Now check the cache handling of the chipset. */
7789 if (ncr_snooptest(np
)) {
7790 printk(KERN_ERR
"CACHE INCORRECTLY CONFIGURED.\n");
7794 /* Install the interrupt handler. */
7795 np
->irq
= device
->slot
.irq
;
7797 /* Initialize the fixed part of the default ccb. */
7798 ncr_init_ccb(np
, np
->ccb
);
7801 * After SCSI devices have been opened, we cannot reset the bus
7802 * safely, so we do it here. Interrupt handler does the real work.
7803 * Process the reset exception if interrupts are not enabled yet.
7804 * Then enable disconnects.
7806 spin_lock_irqsave(&np
->smp_lock
, flags
);
7807 if (ncr_reset_scsi_bus(np
, 0, driver_setup
.settle_delay
) != 0) {
7808 printk(KERN_ERR
"%s: FATAL ERROR: CHECK SCSI BUS - CABLES, TERMINATION, DEVICE POWER etc.!\n", ncr_name(np
));
7810 spin_unlock_irqrestore(&np
->smp_lock
, flags
);
7818 * The middle-level SCSI driver does not wait for devices to settle.
7819 * Wait synchronously if more than 2 seconds.
7821 if (driver_setup
.settle_delay
> 2) {
7822 printk(KERN_INFO
"%s: waiting %d seconds for scsi devices to settle...\n",
7823 ncr_name(np
), driver_setup
.settle_delay
);
7824 mdelay(1000 * driver_setup
.settle_delay
);
7827 /* start the timeout daemon */
7831 /* use SIMPLE TAG messages by default */
7832 #ifdef SCSI_NCR_ALWAYS_SIMPLE_TAG
7833 np
->order
= M_SIMPLE_TAG
;
7836 spin_unlock_irqrestore(&np
->smp_lock
, flags
);
7843 printk(KERN_INFO
"%s: detaching...\n", ncr_name(np
));
7847 m_free_dma(np
->scripth0
, sizeof(struct scripth
), "SCRIPTH");
7849 m_free_dma(np
->script0
, sizeof(struct script
), "SCRIPT");
7851 m_free_dma(np
->ccb
, sizeof(struct ccb
), "CCB");
7852 m_free_dma(np
, sizeof(struct ncb
), "NCB");
7853 host_data
->ncb
= NULL
;
7856 scsi_host_put(instance
);
7862 int ncr53c8xx_release(struct Scsi_Host
*host
)
7864 struct host_data
*host_data
;
7865 #ifdef DEBUG_NCR53C8XX
7866 printk("ncr53c8xx: release\n");
7870 host_data
= (struct host_data
*)host
->hostdata
;
7871 if (host_data
&& host_data
->ncb
)
7872 ncr_detach(host_data
->ncb
);
7876 static void ncr53c8xx_set_period(struct scsi_target
*starget
, int period
)
7878 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
7879 struct ncb
*np
= ((struct host_data
*)shost
->hostdata
)->ncb
;
7880 struct tcb
*tp
= &np
->target
[starget
->id
];
7882 if (period
> np
->maxsync
)
7883 period
= np
->maxsync
;
7884 else if (period
< np
->minsync
)
7885 period
= np
->minsync
;
7887 tp
->usrsync
= period
;
7889 ncr_negotiate(np
, tp
);
7892 static void ncr53c8xx_set_offset(struct scsi_target
*starget
, int offset
)
7894 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
7895 struct ncb
*np
= ((struct host_data
*)shost
->hostdata
)->ncb
;
7896 struct tcb
*tp
= &np
->target
[starget
->id
];
7898 if (offset
> np
->maxoffs
)
7899 offset
= np
->maxoffs
;
7900 else if (offset
< 0)
7903 tp
->maxoffs
= offset
;
7905 ncr_negotiate(np
, tp
);
7908 static void ncr53c8xx_set_width(struct scsi_target
*starget
, int width
)
7910 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
7911 struct ncb
*np
= ((struct host_data
*)shost
->hostdata
)->ncb
;
7912 struct tcb
*tp
= &np
->target
[starget
->id
];
7914 if (width
> np
->maxwide
)
7915 width
= np
->maxwide
;
7919 tp
->usrwide
= width
;
7921 ncr_negotiate(np
, tp
);
7924 static void ncr53c8xx_get_signalling(struct Scsi_Host
*shost
)
7926 struct ncb
*np
= ((struct host_data
*)shost
->hostdata
)->ncb
;
7927 enum spi_signal_type type
;
7929 switch (np
->scsi_mode
) {
7931 type
= SPI_SIGNAL_SE
;
7934 type
= SPI_SIGNAL_HVD
;
7937 type
= SPI_SIGNAL_UNKNOWN
;
7940 spi_signalling(shost
) = type
;
7943 static struct spi_function_template ncr53c8xx_transport_functions
= {
7944 .set_period
= ncr53c8xx_set_period
,
7946 .set_offset
= ncr53c8xx_set_offset
,
7948 .set_width
= ncr53c8xx_set_width
,
7950 .get_signalling
= ncr53c8xx_get_signalling
,
7953 int __init
ncr53c8xx_init(void)
7955 ncr53c8xx_transport_template
= spi_attach_transport(&ncr53c8xx_transport_functions
);
7956 if (!ncr53c8xx_transport_template
)
7961 void ncr53c8xx_exit(void)
7963 spi_release_transport(ncr53c8xx_transport_template
);