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 ** 2005 by Matthew Wilcox and James Bottomley
73 ** PCI-ectomy. This driver now supports only the 720 chip (see the
74 ** NCR_Q720 and zalon drivers for the bus probe logic).
76 *******************************************************************************
80 ** Supported SCSI-II features:
81 ** Synchronous negotiation
82 ** Wide negotiation (depends on the NCR Chip)
83 ** Enable disconnection
84 ** Tagged command queuing
88 ** Supported NCR/SYMBIOS chips:
89 ** 53C720 (Wide, Fast SCSI-2, intfly problems)
92 /* Name and version of the driver */
93 #define SCSI_NCR_DRIVER_NAME "ncr53c8xx-3.4.3g"
95 #define SCSI_NCR_DEBUG_FLAGS (0)
97 #include <linux/blkdev.h>
98 #include <linux/delay.h>
99 #include <linux/dma-mapping.h>
100 #include <linux/errno.h>
101 #include <linux/init.h>
102 #include <linux/interrupt.h>
103 #include <linux/ioport.h>
104 #include <linux/mm.h>
105 #include <linux/module.h>
106 #include <linux/sched.h>
107 #include <linux/signal.h>
108 #include <linux/spinlock.h>
109 #include <linux/stat.h>
110 #include <linux/string.h>
111 #include <linux/time.h>
112 #include <linux/timer.h>
113 #include <linux/types.h>
117 #include <asm/system.h>
119 #include <scsi/scsi.h>
120 #include <scsi/scsi_cmnd.h>
121 #include <scsi/scsi_dbg.h>
122 #include <scsi/scsi_device.h>
123 #include <scsi/scsi_tcq.h>
124 #include <scsi/scsi_transport.h>
125 #include <scsi/scsi_transport_spi.h>
127 #include "ncr53c8xx.h"
129 #define NAME53C8XX "ncr53c8xx"
131 /*==========================================================
135 **==========================================================
138 #define DEBUG_ALLOC (0x0001)
139 #define DEBUG_PHASE (0x0002)
140 #define DEBUG_QUEUE (0x0008)
141 #define DEBUG_RESULT (0x0010)
142 #define DEBUG_POINTER (0x0020)
143 #define DEBUG_SCRIPT (0x0040)
144 #define DEBUG_TINY (0x0080)
145 #define DEBUG_TIMING (0x0100)
146 #define DEBUG_NEGO (0x0200)
147 #define DEBUG_TAGS (0x0400)
148 #define DEBUG_SCATTER (0x0800)
149 #define DEBUG_IC (0x1000)
152 ** Enable/Disable debug messages.
153 ** Can be changed at runtime too.
156 #ifdef SCSI_NCR_DEBUG_INFO_SUPPORT
157 static int ncr_debug
= SCSI_NCR_DEBUG_FLAGS
;
158 #define DEBUG_FLAGS ncr_debug
160 #define DEBUG_FLAGS SCSI_NCR_DEBUG_FLAGS
163 static inline struct list_head
*ncr_list_pop(struct list_head
*head
)
165 if (!list_empty(head
)) {
166 struct list_head
*elem
= head
->next
;
175 /*==========================================================
177 ** Simple power of two buddy-like allocator.
179 ** This simple code is not intended to be fast, but to
180 ** provide power of 2 aligned memory allocations.
181 ** Since the SCRIPTS processor only supplies 8 bit
182 ** arithmetic, this allocator allows simple and fast
183 ** address calculations from the SCRIPTS code.
184 ** In addition, cache line alignment is guaranteed for
185 ** power of 2 cache line size.
186 ** Enhanced in linux-2.3.44 to provide a memory pool
187 ** per pcidev to support dynamic dma mapping. (I would
188 ** have preferred a real bus abstraction, btw).
190 **==========================================================
193 #define MEMO_SHIFT 4 /* 16 bytes minimum memory chunk */
194 #if PAGE_SIZE >= 8192
195 #define MEMO_PAGE_ORDER 0 /* 1 PAGE maximum */
197 #define MEMO_PAGE_ORDER 1 /* 2 PAGES maximum */
199 #define MEMO_FREE_UNUSED /* Free unused pages immediately */
201 #define MEMO_GFP_FLAGS GFP_ATOMIC
202 #define MEMO_CLUSTER_SHIFT (PAGE_SHIFT+MEMO_PAGE_ORDER)
203 #define MEMO_CLUSTER_SIZE (1UL << MEMO_CLUSTER_SHIFT)
204 #define MEMO_CLUSTER_MASK (MEMO_CLUSTER_SIZE-1)
206 typedef u_long m_addr_t
; /* Enough bits to bit-hack addresses */
207 typedef struct device
*m_bush_t
; /* Something that addresses DMAable */
209 typedef struct m_link
{ /* Link between free memory chunks */
213 typedef struct m_vtob
{ /* Virtual to Bus address translation */
218 #define VTOB_HASH_SHIFT 5
219 #define VTOB_HASH_SIZE (1UL << VTOB_HASH_SHIFT)
220 #define VTOB_HASH_MASK (VTOB_HASH_SIZE-1)
221 #define VTOB_HASH_CODE(m) \
222 ((((m_addr_t) (m)) >> MEMO_CLUSTER_SHIFT) & VTOB_HASH_MASK)
224 typedef struct m_pool
{ /* Memory pool of a given kind */
226 m_addr_t (*getp
)(struct m_pool
*);
227 void (*freep
)(struct m_pool
*, m_addr_t
);
229 m_vtob_s
*(vtob
[VTOB_HASH_SIZE
]);
231 struct m_link h
[PAGE_SHIFT
-MEMO_SHIFT
+MEMO_PAGE_ORDER
+1];
234 static void *___m_alloc(m_pool_s
*mp
, int size
)
237 int s
= (1 << MEMO_SHIFT
);
242 if (size
> (PAGE_SIZE
<< MEMO_PAGE_ORDER
))
252 if (s
== (PAGE_SIZE
<< MEMO_PAGE_ORDER
)) {
253 h
[j
].next
= (m_link_s
*)mp
->getp(mp
);
255 h
[j
].next
->next
= NULL
;
261 a
= (m_addr_t
) h
[j
].next
;
263 h
[j
].next
= h
[j
].next
->next
;
267 h
[j
].next
= (m_link_s
*) (a
+s
);
268 h
[j
].next
->next
= NULL
;
272 printk("___m_alloc(%d) = %p\n", size
, (void *) a
);
277 static void ___m_free(m_pool_s
*mp
, void *ptr
, int size
)
280 int s
= (1 << MEMO_SHIFT
);
286 printk("___m_free(%p, %d)\n", ptr
, size
);
289 if (size
> (PAGE_SIZE
<< MEMO_PAGE_ORDER
))
300 #ifdef MEMO_FREE_UNUSED
301 if (s
== (PAGE_SIZE
<< MEMO_PAGE_ORDER
)) {
308 while (q
->next
&& q
->next
!= (m_link_s
*) b
) {
312 ((m_link_s
*) a
)->next
= h
[i
].next
;
313 h
[i
].next
= (m_link_s
*) a
;
316 q
->next
= q
->next
->next
;
323 static DEFINE_SPINLOCK(ncr53c8xx_lock
);
325 static void *__m_calloc2(m_pool_s
*mp
, int size
, char *name
, int uflags
)
329 p
= ___m_alloc(mp
, size
);
331 if (DEBUG_FLAGS
& DEBUG_ALLOC
)
332 printk ("new %-10s[%4d] @%p.\n", name
, size
, p
);
336 else if (uflags
& MEMO_WARN
)
337 printk (NAME53C8XX
": failed to allocate %s[%d]\n", name
, size
);
342 #define __m_calloc(mp, s, n) __m_calloc2(mp, s, n, MEMO_WARN)
344 static void __m_free(m_pool_s
*mp
, void *ptr
, int size
, char *name
)
346 if (DEBUG_FLAGS
& DEBUG_ALLOC
)
347 printk ("freeing %-10s[%4d] @%p.\n", name
, size
, ptr
);
349 ___m_free(mp
, ptr
, size
);
354 * With pci bus iommu support, we use a default pool of unmapped memory
355 * for memory we donnot need to DMA from/to and one pool per pcidev for
356 * memory accessed by the PCI chip. `mp0' is the default not DMAable pool.
359 static m_addr_t
___mp0_getp(m_pool_s
*mp
)
361 m_addr_t m
= __get_free_pages(MEMO_GFP_FLAGS
, MEMO_PAGE_ORDER
);
367 static void ___mp0_freep(m_pool_s
*mp
, m_addr_t m
)
369 free_pages(m
, MEMO_PAGE_ORDER
);
373 static m_pool_s mp0
= {NULL
, ___mp0_getp
, ___mp0_freep
};
380 * With pci bus iommu support, we maintain one pool per pcidev and a
381 * hashed reverse table for virtual to bus physical address translations.
383 static m_addr_t
___dma_getp(m_pool_s
*mp
)
388 vbp
= __m_calloc(&mp0
, sizeof(*vbp
), "VTOB");
391 vp
= (m_addr_t
) dma_alloc_coherent(mp
->bush
,
392 PAGE_SIZE
<<MEMO_PAGE_ORDER
,
395 int hc
= VTOB_HASH_CODE(vp
);
398 vbp
->next
= mp
->vtob
[hc
];
405 __m_free(&mp0
, vbp
, sizeof(*vbp
), "VTOB");
409 static void ___dma_freep(m_pool_s
*mp
, m_addr_t m
)
411 m_vtob_s
**vbpp
, *vbp
;
412 int hc
= VTOB_HASH_CODE(m
);
414 vbpp
= &mp
->vtob
[hc
];
415 while (*vbpp
&& (*vbpp
)->vaddr
!= m
)
416 vbpp
= &(*vbpp
)->next
;
419 *vbpp
= (*vbpp
)->next
;
420 dma_free_coherent(mp
->bush
, PAGE_SIZE
<<MEMO_PAGE_ORDER
,
421 (void *)vbp
->vaddr
, (dma_addr_t
)vbp
->baddr
);
422 __m_free(&mp0
, vbp
, sizeof(*vbp
), "VTOB");
427 static inline m_pool_s
*___get_dma_pool(m_bush_t bush
)
430 for (mp
= mp0
.next
; mp
&& mp
->bush
!= bush
; mp
= mp
->next
);
434 static m_pool_s
*___cre_dma_pool(m_bush_t bush
)
437 mp
= __m_calloc(&mp0
, sizeof(*mp
), "MPOOL");
439 memset(mp
, 0, sizeof(*mp
));
441 mp
->getp
= ___dma_getp
;
442 mp
->freep
= ___dma_freep
;
449 static void ___del_dma_pool(m_pool_s
*p
)
451 struct m_pool
**pp
= &mp0
.next
;
453 while (*pp
&& *pp
!= p
)
457 __m_free(&mp0
, p
, sizeof(*p
), "MPOOL");
461 static void *__m_calloc_dma(m_bush_t bush
, int size
, char *name
)
467 spin_lock_irqsave(&ncr53c8xx_lock
, flags
);
468 mp
= ___get_dma_pool(bush
);
470 mp
= ___cre_dma_pool(bush
);
472 m
= __m_calloc(mp
, size
, name
);
475 spin_unlock_irqrestore(&ncr53c8xx_lock
, flags
);
480 static void __m_free_dma(m_bush_t bush
, void *m
, int size
, char *name
)
485 spin_lock_irqsave(&ncr53c8xx_lock
, flags
);
486 mp
= ___get_dma_pool(bush
);
488 __m_free(mp
, m
, size
, name
);
491 spin_unlock_irqrestore(&ncr53c8xx_lock
, flags
);
494 static m_addr_t
__vtobus(m_bush_t bush
, void *m
)
498 int hc
= VTOB_HASH_CODE(m
);
500 m_addr_t a
= ((m_addr_t
) m
) & ~MEMO_CLUSTER_MASK
;
502 spin_lock_irqsave(&ncr53c8xx_lock
, flags
);
503 mp
= ___get_dma_pool(bush
);
506 while (vp
&& (m_addr_t
) vp
->vaddr
!= a
)
509 spin_unlock_irqrestore(&ncr53c8xx_lock
, flags
);
510 return vp
? vp
->baddr
+ (((m_addr_t
) m
) - a
) : 0;
513 #define _m_calloc_dma(np, s, n) __m_calloc_dma(np->dev, s, n)
514 #define _m_free_dma(np, p, s, n) __m_free_dma(np->dev, p, s, n)
515 #define m_calloc_dma(s, n) _m_calloc_dma(np, s, n)
516 #define m_free_dma(p, s, n) _m_free_dma(np, p, s, n)
517 #define _vtobus(np, p) __vtobus(np->dev, p)
518 #define vtobus(p) _vtobus(np, p)
521 * Deal with DMA mapping/unmapping.
524 /* To keep track of the dma mapping (sg/single) that has been set */
525 #define __data_mapped SCp.phase
526 #define __data_mapping SCp.have_data_in
528 static void __unmap_scsi_data(struct device
*dev
, struct scsi_cmnd
*cmd
)
530 switch(cmd
->__data_mapped
) {
535 cmd
->__data_mapped
= 0;
538 static int __map_scsi_sg_data(struct device
*dev
, struct scsi_cmnd
*cmd
)
542 use_sg
= scsi_dma_map(cmd
);
546 cmd
->__data_mapped
= 2;
547 cmd
->__data_mapping
= use_sg
;
552 #define unmap_scsi_data(np, cmd) __unmap_scsi_data(np->dev, cmd)
553 #define map_scsi_sg_data(np, cmd) __map_scsi_sg_data(np->dev, cmd)
555 /*==========================================================
559 ** This structure is initialized from linux config
560 ** options. It can be overridden at boot-up by the boot
563 **==========================================================
565 static struct ncr_driver_setup
566 driver_setup
= SCSI_NCR_DRIVER_SETUP
;
569 #ifdef SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT
570 static struct ncr_driver_setup
571 driver_safe_setup __initdata
= SCSI_NCR_DRIVER_SAFE_SETUP
;
575 #define initverbose (driver_setup.verbose)
576 #define bootverbose (np->verbose)
579 /*===================================================================
581 ** Driver setup from the boot command line
583 **===================================================================
593 #define OPT_MASTER_PARITY 2
594 #define OPT_SCSI_PARITY 3
595 #define OPT_DISCONNECTION 4
596 #define OPT_SPECIAL_FEATURES 5
597 #define OPT_UNUSED_1 6
598 #define OPT_FORCE_SYNC_NEGO 7
599 #define OPT_REVERSE_PROBE 8
600 #define OPT_DEFAULT_SYNC 9
601 #define OPT_VERBOSE 10
603 #define OPT_BURST_MAX 12
604 #define OPT_LED_PIN 13
605 #define OPT_MAX_WIDE 14
606 #define OPT_SETTLE_DELAY 15
607 #define OPT_DIFF_SUPPORT 16
609 #define OPT_PCI_FIX_UP 18
610 #define OPT_BUS_CHECK 19
611 #define OPT_OPTIMIZE 20
612 #define OPT_RECOVERY 21
613 #define OPT_SAFE_SETUP 22
614 #define OPT_USE_NVRAM 23
615 #define OPT_EXCLUDE 24
616 #define OPT_HOST_ID 25
618 #ifdef SCSI_NCR_IARB_SUPPORT
629 static char setup_token
[] __initdata
=
643 #ifdef SCSI_NCR_IARB_SUPPORT
646 ; /* DONNOT REMOVE THIS ';' */
648 static int __init
get_setup_token(char *p
)
650 char *cur
= setup_token
;
654 while (cur
!= NULL
&& (pc
= strchr(cur
, ':')) != NULL
) {
657 if (!strncmp(p
, cur
, pc
- cur
))
664 static int __init
sym53c8xx__setup(char *str
)
666 #ifdef SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT
672 while (cur
!= NULL
&& (pc
= strchr(cur
, ':')) != NULL
) {
684 val
= (int) simple_strtoul(pv
, &pe
, 0);
686 switch (get_setup_token(cur
)) {
688 driver_setup
.default_tags
= val
;
689 if (pe
&& *pe
== '/') {
691 while (*pe
&& *pe
!= ARG_SEP
&&
692 i
< sizeof(driver_setup
.tag_ctrl
)-1) {
693 driver_setup
.tag_ctrl
[i
++] = *pe
++;
695 driver_setup
.tag_ctrl
[i
] = '\0';
698 case OPT_MASTER_PARITY
:
699 driver_setup
.master_parity
= val
;
701 case OPT_SCSI_PARITY
:
702 driver_setup
.scsi_parity
= val
;
704 case OPT_DISCONNECTION
:
705 driver_setup
.disconnection
= val
;
707 case OPT_SPECIAL_FEATURES
:
708 driver_setup
.special_features
= val
;
710 case OPT_FORCE_SYNC_NEGO
:
711 driver_setup
.force_sync_nego
= val
;
713 case OPT_REVERSE_PROBE
:
714 driver_setup
.reverse_probe
= val
;
716 case OPT_DEFAULT_SYNC
:
717 driver_setup
.default_sync
= val
;
720 driver_setup
.verbose
= val
;
723 driver_setup
.debug
= val
;
726 driver_setup
.burst_max
= val
;
729 driver_setup
.led_pin
= val
;
732 driver_setup
.max_wide
= val
? 1:0;
734 case OPT_SETTLE_DELAY
:
735 driver_setup
.settle_delay
= val
;
737 case OPT_DIFF_SUPPORT
:
738 driver_setup
.diff_support
= val
;
741 driver_setup
.irqm
= val
;
744 driver_setup
.pci_fix_up
= val
;
747 driver_setup
.bus_check
= val
;
750 driver_setup
.optimize
= val
;
753 driver_setup
.recovery
= val
;
756 driver_setup
.use_nvram
= val
;
759 memcpy(&driver_setup
, &driver_safe_setup
,
760 sizeof(driver_setup
));
763 if (xi
< SCSI_NCR_MAX_EXCLUDES
)
764 driver_setup
.excludes
[xi
++] = val
;
767 driver_setup
.host_id
= val
;
769 #ifdef SCSI_NCR_IARB_SUPPORT
771 driver_setup
.iarb
= val
;
775 printk("sym53c8xx_setup: unexpected boot option '%.*s' ignored\n", (int)(pc
-cur
+1), cur
);
779 if ((cur
= strchr(cur
, ARG_SEP
)) != NULL
)
782 #endif /* SCSI_NCR_BOOT_COMMAND_LINE_SUPPORT */
787 /*===================================================================
789 ** Get device queue depth from boot command line.
791 **===================================================================
793 #define DEF_DEPTH (driver_setup.default_tags)
794 #define ALL_TARGETS -2
799 static int device_queue_depth(int unit
, int target
, int lun
)
802 char *p
= driver_setup
.tag_ctrl
;
808 while ((c
= *p
++) != 0) {
809 v
= simple_strtoul(p
, &ep
, 0);
818 t
= (target
== v
) ? v
: NO_TARGET
;
823 u
= (lun
== v
) ? v
: NO_LUN
;
827 (t
== ALL_TARGETS
|| t
== target
) &&
828 (u
== ALL_LUNS
|| u
== lun
))
844 /*==========================================================
846 ** The CCB done queue uses an array of CCB virtual
847 ** addresses. Empty entries are flagged using the bogus
848 ** virtual address 0xffffffff.
850 ** Since PCI ensures that only aligned DWORDs are accessed
851 ** atomically, 64 bit little-endian architecture requires
852 ** to test the high order DWORD of the entry to determine
853 ** if it is empty or valid.
855 ** BTW, I will make things differently as soon as I will
856 ** have a better idea, but this is simple and should work.
858 **==========================================================
861 #define SCSI_NCR_CCB_DONE_SUPPORT
862 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
865 #define CCB_DONE_EMPTY 0xffffffffUL
867 /* All 32 bit architectures */
868 #if BITS_PER_LONG == 32
869 #define CCB_DONE_VALID(cp) (((u_long) cp) != CCB_DONE_EMPTY)
871 /* All > 32 bit (64 bit) architectures regardless endian-ness */
873 #define CCB_DONE_VALID(cp) \
874 ((((u_long) cp) & 0xffffffff00000000ul) && \
875 (((u_long) cp) & 0xfffffffful) != CCB_DONE_EMPTY)
878 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
880 /*==========================================================
882 ** Configuration and Debugging
884 **==========================================================
888 ** SCSI address of this device.
889 ** The boot routines should have set it.
893 #ifndef SCSI_NCR_MYADDR
894 #define SCSI_NCR_MYADDR (7)
898 ** The maximum number of tags per logic unit.
899 ** Used only for disk devices that support tags.
902 #ifndef SCSI_NCR_MAX_TAGS
903 #define SCSI_NCR_MAX_TAGS (8)
907 ** TAGS are actually limited to 64 tags/lun.
908 ** We need to deal with power of 2, for alignment constraints.
910 #if SCSI_NCR_MAX_TAGS > 64
911 #define MAX_TAGS (64)
913 #define MAX_TAGS SCSI_NCR_MAX_TAGS
919 ** Choose appropriate type for tag bitmap.
922 typedef u64 tagmap_t
;
924 typedef u32 tagmap_t
;
928 ** Number of targets supported by the driver.
929 ** n permits target numbers 0..n-1.
930 ** Default is 16, meaning targets #0..#15.
934 #ifdef SCSI_NCR_MAX_TARGET
935 #define MAX_TARGET (SCSI_NCR_MAX_TARGET)
937 #define MAX_TARGET (16)
941 ** Number of logic units supported by the driver.
942 ** n enables logic unit numbers 0..n-1.
943 ** The common SCSI devices require only
944 ** one lun, so take 1 as the default.
947 #ifdef SCSI_NCR_MAX_LUN
948 #define MAX_LUN SCSI_NCR_MAX_LUN
954 ** Asynchronous pre-scaler (ns). Shall be 40
957 #ifndef SCSI_NCR_MIN_ASYNC
958 #define SCSI_NCR_MIN_ASYNC (40)
962 ** The maximum number of jobs scheduled for starting.
963 ** There should be one slot per target, and one slot
964 ** for each tag of each target in use.
965 ** The calculation below is actually quite silly ...
968 #ifdef SCSI_NCR_CAN_QUEUE
969 #define MAX_START (SCSI_NCR_CAN_QUEUE + 4)
971 #define MAX_START (MAX_TARGET + 7 * MAX_TAGS)
975 ** We limit the max number of pending IO to 250.
976 ** since we donnot want to allocate more than 1
977 ** PAGE for 'scripth'.
981 #define MAX_START 250
985 ** The maximum number of segments a transfer is split into.
986 ** We support up to 127 segments for both read and write.
987 ** The data scripts are broken into 2 sub-scripts.
988 ** 80 (MAX_SCATTERL) segments are moved from a sub-script
989 ** in on-chip RAM. This makes data transfers shorter than
990 ** 80k (assuming 1k fs) as fast as possible.
993 #define MAX_SCATTER (SCSI_NCR_MAX_SCATTER)
995 #if (MAX_SCATTER > 80)
996 #define MAX_SCATTERL 80
997 #define MAX_SCATTERH (MAX_SCATTER - MAX_SCATTERL)
999 #define MAX_SCATTERL (MAX_SCATTER-1)
1000 #define MAX_SCATTERH 1
1007 #define NCR_SNOOP_TIMEOUT (1000000)
1010 ** Other definitions
1013 #define ScsiResult(host_code, scsi_code) (((host_code) << 16) + ((scsi_code) & 0x7f))
1015 #define initverbose (driver_setup.verbose)
1016 #define bootverbose (np->verbose)
1018 /*==========================================================
1020 ** Command control block states.
1022 **==========================================================
1027 #define HS_NEGOTIATE (2) /* sync/wide data transfer*/
1028 #define HS_DISCONNECT (3) /* Disconnected by target */
1030 #define HS_DONEMASK (0x80)
1031 #define HS_COMPLETE (4|HS_DONEMASK)
1032 #define HS_SEL_TIMEOUT (5|HS_DONEMASK) /* Selection timeout */
1033 #define HS_RESET (6|HS_DONEMASK) /* SCSI reset */
1034 #define HS_ABORTED (7|HS_DONEMASK) /* Transfer aborted */
1035 #define HS_TIMEOUT (8|HS_DONEMASK) /* Software timeout */
1036 #define HS_FAIL (9|HS_DONEMASK) /* SCSI or PCI bus errors */
1037 #define HS_UNEXPECTED (10|HS_DONEMASK)/* Unexpected disconnect */
1040 ** Invalid host status values used by the SCRIPTS processor
1041 ** when the nexus is not fully identified.
1042 ** Shall never appear in a CCB.
1045 #define HS_INVALMASK (0x40)
1046 #define HS_SELECTING (0|HS_INVALMASK)
1047 #define HS_IN_RESELECT (1|HS_INVALMASK)
1048 #define HS_STARTING (2|HS_INVALMASK)
1051 ** Flags set by the SCRIPT processor for commands
1052 ** that have been skipped.
1054 #define HS_SKIPMASK (0x20)
1056 /*==========================================================
1058 ** Software Interrupt Codes
1060 **==========================================================
1063 #define SIR_BAD_STATUS (1)
1064 #define SIR_XXXXXXXXXX (2)
1065 #define SIR_NEGO_SYNC (3)
1066 #define SIR_NEGO_WIDE (4)
1067 #define SIR_NEGO_FAILED (5)
1068 #define SIR_NEGO_PROTO (6)
1069 #define SIR_REJECT_RECEIVED (7)
1070 #define SIR_REJECT_SENT (8)
1071 #define SIR_IGN_RESIDUE (9)
1072 #define SIR_MISSING_SAVE (10)
1073 #define SIR_RESEL_NO_MSG_IN (11)
1074 #define SIR_RESEL_NO_IDENTIFY (12)
1075 #define SIR_RESEL_BAD_LUN (13)
1076 #define SIR_RESEL_BAD_TARGET (14)
1077 #define SIR_RESEL_BAD_I_T_L (15)
1078 #define SIR_RESEL_BAD_I_T_L_Q (16)
1079 #define SIR_DONE_OVERFLOW (17)
1080 #define SIR_INTFLY (18)
1081 #define SIR_MAX (18)
1083 /*==========================================================
1085 ** Extended error codes.
1086 ** xerr_status field of struct ccb.
1088 **==========================================================
1092 #define XE_EXTRA_DATA (1) /* unexpected data phase */
1093 #define XE_BAD_PHASE (2) /* illegal phase (4/5) */
1095 /*==========================================================
1097 ** Negotiation status.
1098 ** nego_status field of struct ccb.
1100 **==========================================================
1103 #define NS_NOCHANGE (0)
1108 /*==========================================================
1112 **==========================================================
1115 #define CCB_MAGIC (0xf2691ad2)
1117 /*==========================================================
1119 ** Declaration of structs.
1121 **==========================================================
1124 static struct scsi_transport_template
*ncr53c8xx_transport_template
= NULL
;
1144 #define UC_SETSYNC 10
1145 #define UC_SETTAGS 11
1146 #define UC_SETDEBUG 12
1147 #define UC_SETORDER 13
1148 #define UC_SETWIDE 14
1149 #define UC_SETFLAG 15
1150 #define UC_SETVERBOSE 17
1152 #define UF_TRACE (0x01)
1153 #define UF_NODISC (0x02)
1154 #define UF_NOSCAN (0x04)
1156 /*========================================================================
1158 ** Declaration of structs: target control block
1160 **========================================================================
1163 /*----------------------------------------------------------------
1164 ** During reselection the ncr jumps to this point with SFBR
1165 ** set to the encoded target number with bit 7 set.
1166 ** if it's not this target, jump to the next.
1168 ** JUMP IF (SFBR != #target#), @(next tcb)
1169 **----------------------------------------------------------------
1171 struct link jump_tcb
;
1173 /*----------------------------------------------------------------
1174 ** Load the actual values for the sxfer and the scntl3
1175 ** register (sync/wide mode).
1177 ** SCR_COPY (1), @(sval field of this tcb), @(sxfer register)
1178 ** SCR_COPY (1), @(wval field of this tcb), @(scntl3 register)
1179 **----------------------------------------------------------------
1183 /*----------------------------------------------------------------
1184 ** Get the IDENTIFY message and load the LUN to SFBR.
1186 ** CALL, <RESEL_LUN>
1187 **----------------------------------------------------------------
1189 struct link call_lun
;
1191 /*----------------------------------------------------------------
1192 ** Now look for the right lun.
1195 ** SCR_JUMP ^ IFTRUE(MASK(i, 3)), @(first lcb mod. i)
1197 ** Recent chips will prefetch the 4 JUMPS using only 1 burst.
1198 ** It is kind of hashcoding.
1199 **----------------------------------------------------------------
1201 struct link jump_lcb
[4]; /* JUMPs for reselection */
1202 struct lcb
* lp
[MAX_LUN
]; /* The lcb's of this tcb */
1204 /*----------------------------------------------------------------
1205 ** Pointer to the ccb used for negotiation.
1206 ** Prevent from starting a negotiation for all queued commands
1207 ** when tagged command queuing is enabled.
1208 **----------------------------------------------------------------
1210 struct ccb
* nego_cp
;
1212 /*----------------------------------------------------------------
1214 **----------------------------------------------------------------
1219 /*----------------------------------------------------------------
1220 ** negotiation of wide and synch transfer and device quirks.
1221 **----------------------------------------------------------------
1223 #ifdef SCSI_NCR_BIG_ENDIAN
1226 /*3*/ u_char minsync
;
1228 /*1*/ u_char widedone
;
1229 /*2*/ u_char quirks
;
1230 /*3*/ u_char maxoffs
;
1232 /*0*/ u_char minsync
;
1235 /*0*/ u_char maxoffs
;
1236 /*1*/ u_char quirks
;
1237 /*2*/ u_char widedone
;
1241 /* User settable limits and options. */
1246 struct scsi_target
*starget
;
1249 /*========================================================================
1251 ** Declaration of structs: lun control block
1253 **========================================================================
1256 /*----------------------------------------------------------------
1257 ** During reselection the ncr jumps to this point
1258 ** with SFBR set to the "Identify" message.
1259 ** if it's not this lun, jump to the next.
1261 ** JUMP IF (SFBR != #lun#), @(next lcb of this target)
1263 ** It is this lun. Load TEMP with the nexus jumps table
1264 ** address and jump to RESEL_TAG (or RESEL_NOTAG).
1266 ** SCR_COPY (4), p_jump_ccb, TEMP,
1267 ** SCR_JUMP, <RESEL_TAG>
1268 **----------------------------------------------------------------
1270 struct link jump_lcb
;
1271 ncrcmd load_jump_ccb
[3];
1272 struct link jump_tag
;
1273 ncrcmd p_jump_ccb
; /* Jump table bus address */
1275 /*----------------------------------------------------------------
1276 ** Jump table used by the script processor to directly jump
1277 ** to the CCB corresponding to the reselected nexus.
1278 ** Address is allocated on 256 bytes boundary in order to
1279 ** allow 8 bit calculation of the tag jump entry for up to
1280 ** 64 possible tags.
1281 **----------------------------------------------------------------
1283 u32 jump_ccb_0
; /* Default table if no tags */
1284 u32
*jump_ccb
; /* Virtual address */
1286 /*----------------------------------------------------------------
1287 ** CCB queue management.
1288 **----------------------------------------------------------------
1290 struct list_head free_ccbq
; /* Queue of available CCBs */
1291 struct list_head busy_ccbq
; /* Queue of busy CCBs */
1292 struct list_head wait_ccbq
; /* Queue of waiting for IO CCBs */
1293 struct list_head skip_ccbq
; /* Queue of skipped CCBs */
1294 u_char actccbs
; /* Number of allocated CCBs */
1295 u_char busyccbs
; /* CCBs busy for this lun */
1296 u_char queuedccbs
; /* CCBs queued to the controller*/
1297 u_char queuedepth
; /* Queue depth for this lun */
1298 u_char scdev_depth
; /* SCSI device queue depth */
1299 u_char maxnxs
; /* Max possible nexuses */
1301 /*----------------------------------------------------------------
1302 ** Control of tagged command queuing.
1303 ** Tags allocation is performed using a circular buffer.
1304 ** This avoids using a loop for tag allocation.
1305 **----------------------------------------------------------------
1307 u_char ia_tag
; /* Allocation index */
1308 u_char if_tag
; /* Freeing index */
1309 u_char cb_tags
[MAX_TAGS
]; /* Circular tags buffer */
1310 u_char usetags
; /* Command queuing is active */
1311 u_char maxtags
; /* Max nr of tags asked by user */
1312 u_char numtags
; /* Current number of tags */
1314 /*----------------------------------------------------------------
1315 ** QUEUE FULL control and ORDERED tag control.
1316 **----------------------------------------------------------------
1318 /*----------------------------------------------------------------
1319 ** QUEUE FULL and ORDERED tag control.
1320 **----------------------------------------------------------------
1322 u16 num_good
; /* Nr of GOOD since QUEUE FULL */
1323 tagmap_t tags_umap
; /* Used tags bitmap */
1324 tagmap_t tags_smap
; /* Tags in use at 'tag_stime' */
1325 u_long tags_stime
; /* Last time we set smap=umap */
1326 struct ccb
* held_ccb
; /* CCB held for QUEUE FULL */
1329 /*========================================================================
1331 ** Declaration of structs: the launch script.
1333 **========================================================================
1335 ** It is part of the CCB and is called by the scripts processor to
1336 ** start or restart the data structure (nexus).
1337 ** This 6 DWORDs mini script makes use of prefetching.
1339 **------------------------------------------------------------------------
1342 /*----------------------------------------------------------------
1343 ** SCR_COPY(4), @(p_phys), @(dsa register)
1344 ** SCR_JUMP, @(scheduler_point)
1345 **----------------------------------------------------------------
1347 ncrcmd setup_dsa
[3]; /* Copy 'phys' address to dsa */
1348 struct link schedule
; /* Jump to scheduler point */
1349 ncrcmd p_phys
; /* 'phys' header bus address */
1352 /*========================================================================
1354 ** Declaration of structs: global HEADER.
1356 **========================================================================
1358 ** This substructure is copied from the ccb to a global address after
1359 ** selection (or reselection) and copied back before disconnect.
1361 ** These fields are accessible to the script processor.
1363 **------------------------------------------------------------------------
1367 /*----------------------------------------------------------------
1368 ** Saved data pointer.
1369 ** Points to the position in the script responsible for the
1370 ** actual transfer transfer of data.
1371 ** It's written after reception of a SAVE_DATA_POINTER message.
1372 ** The goalpointer points after the last transfer command.
1373 **----------------------------------------------------------------
1379 /*----------------------------------------------------------------
1380 ** Alternate data pointer.
1381 ** They are copied back to savep/lastp/goalp by the SCRIPTS
1382 ** when the direction is unknown and the device claims data out.
1383 **----------------------------------------------------------------
1388 /*----------------------------------------------------------------
1389 ** The virtual address of the ccb containing this header.
1390 **----------------------------------------------------------------
1394 /*----------------------------------------------------------------
1396 **----------------------------------------------------------------
1398 u_char scr_st
[4]; /* script status */
1399 u_char status
[4]; /* host status. must be the */
1400 /* last DWORD of the header. */
1404 ** The status bytes are used by the host and the script processor.
1406 ** The byte corresponding to the host_status must be stored in the
1407 ** last DWORD of the CCB header since it is used for command
1408 ** completion (ncr_wakeup()). Doing so, we are sure that the header
1409 ** has been entirely copied back to the CCB when the host_status is
1410 ** seen complete by the CPU.
1412 ** The last four bytes (status[4]) are copied to the scratchb register
1413 ** (declared as scr0..scr3 in ncr_reg.h) just after the select/reselect,
1414 ** and copied back just after disconnecting.
1415 ** Inside the script the XX_REG are used.
1417 ** The first four bytes (scr_st[4]) are used inside the script by
1419 ** Because source and destination must have the same alignment
1420 ** in a DWORD, the fields HAVE to be at the chosen offsets.
1421 ** xerr_st 0 (0x34) scratcha
1422 ** sync_st 1 (0x05) sxfer
1423 ** wide_st 3 (0x03) scntl3
1427 ** Last four bytes (script)
1431 #define HS_PRT nc_scr1
1433 #define SS_PRT nc_scr2
1437 ** Last four bytes (host)
1439 #ifdef SCSI_NCR_BIG_ENDIAN
1440 #define actualquirks phys.header.status[3]
1441 #define host_status phys.header.status[2]
1442 #define scsi_status phys.header.status[1]
1443 #define parity_status phys.header.status[0]
1445 #define actualquirks phys.header.status[0]
1446 #define host_status phys.header.status[1]
1447 #define scsi_status phys.header.status[2]
1448 #define parity_status phys.header.status[3]
1452 ** First four bytes (script)
1454 #define xerr_st header.scr_st[0]
1455 #define sync_st header.scr_st[1]
1456 #define nego_st header.scr_st[2]
1457 #define wide_st header.scr_st[3]
1460 ** First four bytes (host)
1462 #define xerr_status phys.xerr_st
1463 #define nego_status phys.nego_st
1466 #define sync_status phys.sync_st
1467 #define wide_status phys.wide_st
1470 /*==========================================================
1472 ** Declaration of structs: Data structure block
1474 **==========================================================
1476 ** During execution of a ccb by the script processor,
1477 ** the DSA (data structure address) register points
1478 ** to this substructure of the ccb.
1479 ** This substructure contains the header with
1480 ** the script-processor-changeable data and
1481 ** data blocks for the indirect move commands.
1483 **----------------------------------------------------------
1495 ** Table data for Script
1498 struct scr_tblsel select
;
1499 struct scr_tblmove smsg
;
1500 struct scr_tblmove cmd
;
1501 struct scr_tblmove sense
;
1502 struct scr_tblmove data
[MAX_SCATTER
];
1506 /*========================================================================
1508 ** Declaration of structs: Command control block.
1510 **========================================================================
1513 /*----------------------------------------------------------------
1514 ** This is the data structure which is pointed by the DSA
1515 ** register when it is executed by the script processor.
1516 ** It must be the first entry because it contains the header
1517 ** as first entry that must be cache line aligned.
1518 **----------------------------------------------------------------
1522 /*----------------------------------------------------------------
1523 ** Mini-script used at CCB execution start-up.
1524 ** Load the DSA with the data structure address (phys) and
1525 ** jump to SELECT. Jump to CANCEL if CCB is to be canceled.
1526 **----------------------------------------------------------------
1528 struct launch start
;
1530 /*----------------------------------------------------------------
1531 ** Mini-script used at CCB relection to restart the nexus.
1532 ** Load the DSA with the data structure address (phys) and
1533 ** jump to RESEL_DSA. Jump to ABORT if CCB is to be aborted.
1534 **----------------------------------------------------------------
1536 struct launch restart
;
1538 /*----------------------------------------------------------------
1539 ** If a data transfer phase is terminated too early
1540 ** (after reception of a message (i.e. DISCONNECT)),
1541 ** we have to prepare a mini script to transfer
1542 ** the rest of the data.
1543 **----------------------------------------------------------------
1547 /*----------------------------------------------------------------
1548 ** The general SCSI driver provides a
1549 ** pointer to a control block.
1550 **----------------------------------------------------------------
1552 struct scsi_cmnd
*cmd
; /* SCSI command */
1553 u_char cdb_buf
[16]; /* Copy of CDB */
1554 u_char sense_buf
[64];
1555 int data_len
; /* Total data length */
1557 /*----------------------------------------------------------------
1559 ** We prepare a message to be sent after selection.
1560 ** We may use a second one if the command is rescheduled
1561 ** due to GETCC or QFULL.
1562 ** Contents are IDENTIFY and SIMPLE_TAG.
1563 ** While negotiating sync or wide transfer,
1564 ** a SDTR or WDTR message is appended.
1565 **----------------------------------------------------------------
1567 u_char scsi_smsg
[8];
1568 u_char scsi_smsg2
[8];
1570 /*----------------------------------------------------------------
1572 **----------------------------------------------------------------
1574 u_long p_ccb
; /* BUS address of this CCB */
1575 u_char sensecmd
[6]; /* Sense command */
1576 u_char tag
; /* Tag for this transfer */
1577 /* 255 means no tag */
1582 struct ccb
* link_ccb
; /* Host adapter CCB chain */
1583 struct list_head link_ccbq
; /* Link to unit CCB queue */
1584 u32 startp
; /* Initial data pointer */
1585 u_long magic
; /* Free / busy CCB flag */
1588 #define CCB_PHYS(cp,lbl) (cp->p_ccb + offsetof(struct ccb, lbl))
1591 /*========================================================================
1593 ** Declaration of structs: NCR device descriptor
1595 **========================================================================
1598 /*----------------------------------------------------------------
1599 ** The global header.
1600 ** It is accessible to both the host and the script processor.
1601 ** Must be cache line size aligned (32 for x86) in order to
1602 ** allow cache line bursting when it is copied to/from CCB.
1603 **----------------------------------------------------------------
1607 /*----------------------------------------------------------------
1608 ** CCBs management queues.
1609 **----------------------------------------------------------------
1611 struct scsi_cmnd
*waiting_list
; /* Commands waiting for a CCB */
1612 /* when lcb is not allocated. */
1613 struct scsi_cmnd
*done_list
; /* Commands waiting for done() */
1614 /* callback to be invoked. */
1615 spinlock_t smp_lock
; /* Lock for SMP threading */
1617 /*----------------------------------------------------------------
1618 ** Chip and controller indentification.
1619 **----------------------------------------------------------------
1621 int unit
; /* Unit number */
1622 char inst_name
[16]; /* ncb instance name */
1624 /*----------------------------------------------------------------
1625 ** Initial value of some IO register bits.
1626 ** These values are assumed to have been set by BIOS, and may
1627 ** be used for probing adapter implementation differences.
1628 **----------------------------------------------------------------
1630 u_char sv_scntl0
, sv_scntl3
, sv_dmode
, sv_dcntl
, sv_ctest0
, sv_ctest3
,
1631 sv_ctest4
, sv_ctest5
, sv_gpcntl
, sv_stest2
, sv_stest4
;
1633 /*----------------------------------------------------------------
1634 ** Actual initial value of IO register bits used by the
1635 ** driver. They are loaded at initialisation according to
1636 ** features that are to be enabled.
1637 **----------------------------------------------------------------
1639 u_char rv_scntl0
, rv_scntl3
, rv_dmode
, rv_dcntl
, rv_ctest0
, rv_ctest3
,
1640 rv_ctest4
, rv_ctest5
, rv_stest2
;
1642 /*----------------------------------------------------------------
1643 ** Targets management.
1644 ** During reselection the ncr jumps to jump_tcb.
1645 ** The SFBR register is loaded with the encoded target id.
1647 ** SCR_JUMP ^ IFTRUE(MASK(i, 3)), @(next tcb mod. i)
1649 ** Recent chips will prefetch the 4 JUMPS using only 1 burst.
1650 ** It is kind of hashcoding.
1651 **----------------------------------------------------------------
1653 struct link jump_tcb
[4]; /* JUMPs for reselection */
1654 struct tcb target
[MAX_TARGET
]; /* Target data */
1656 /*----------------------------------------------------------------
1657 ** Virtual and physical bus addresses of the chip.
1658 **----------------------------------------------------------------
1660 void __iomem
*vaddr
; /* Virtual and bus address of */
1661 unsigned long paddr
; /* chip's IO registers. */
1662 unsigned long paddr2
; /* On-chip RAM bus address. */
1663 volatile /* Pointer to volatile for */
1664 struct ncr_reg __iomem
*reg
; /* memory mapped IO. */
1666 /*----------------------------------------------------------------
1667 ** SCRIPTS virtual and physical bus addresses.
1668 ** 'script' is loaded in the on-chip RAM if present.
1669 ** 'scripth' stays in main memory.
1670 **----------------------------------------------------------------
1672 struct script
*script0
; /* Copies of script and scripth */
1673 struct scripth
*scripth0
; /* relocated for this ncb. */
1674 struct scripth
*scripth
; /* Actual scripth virt. address */
1675 u_long p_script
; /* Actual script and scripth */
1676 u_long p_scripth
; /* bus addresses. */
1678 /*----------------------------------------------------------------
1679 ** General controller parameters and configuration.
1680 **----------------------------------------------------------------
1683 u_char revision_id
; /* PCI device revision id */
1684 u32 irq
; /* IRQ level */
1685 u32 features
; /* Chip features map */
1686 u_char myaddr
; /* SCSI id of the adapter */
1687 u_char maxburst
; /* log base 2 of dwords burst */
1688 u_char maxwide
; /* Maximum transfer width */
1689 u_char minsync
; /* Minimum sync period factor */
1690 u_char maxsync
; /* Maximum sync period factor */
1691 u_char maxoffs
; /* Max scsi offset */
1692 u_char multiplier
; /* Clock multiplier (1,2,4) */
1693 u_char clock_divn
; /* Number of clock divisors */
1694 u_long clock_khz
; /* SCSI clock frequency in KHz */
1696 /*----------------------------------------------------------------
1697 ** Start queue management.
1698 ** It is filled up by the host processor and accessed by the
1699 ** SCRIPTS processor in order to start SCSI commands.
1700 **----------------------------------------------------------------
1702 u16 squeueput
; /* Next free slot of the queue */
1703 u16 actccbs
; /* Number of allocated CCBs */
1704 u16 queuedccbs
; /* Number of CCBs in start queue*/
1705 u16 queuedepth
; /* Start queue depth */
1707 /*----------------------------------------------------------------
1709 **----------------------------------------------------------------
1711 struct timer_list timer
; /* Timer handler link header */
1713 u_long settle_time
; /* Resetting the SCSI BUS */
1715 /*----------------------------------------------------------------
1716 ** Debugging and profiling.
1717 **----------------------------------------------------------------
1719 struct ncr_reg regdump
; /* Register dump */
1720 u_long regtime
; /* Time it has been done */
1722 /*----------------------------------------------------------------
1723 ** Miscellaneous buffers accessed by the scripts-processor.
1724 ** They shall be DWORD aligned, because they may be read or
1725 ** written with a SCR_COPY script command.
1726 **----------------------------------------------------------------
1728 u_char msgout
[8]; /* Buffer for MESSAGE OUT */
1729 u_char msgin
[8]; /* Buffer for MESSAGE IN */
1730 u32 lastmsg
; /* Last SCSI message sent */
1731 u_char scratch
; /* Scratch for SCSI receive */
1733 /*----------------------------------------------------------------
1734 ** Miscellaneous configuration and status parameters.
1735 **----------------------------------------------------------------
1737 u_char disc
; /* Diconnection allowed */
1738 u_char scsi_mode
; /* Current SCSI BUS mode */
1739 u_char order
; /* Tag order to use */
1740 u_char verbose
; /* Verbosity for this controller*/
1741 int ncr_cache
; /* Used for cache test at init. */
1742 u_long p_ncb
; /* BUS address of this NCB */
1744 /*----------------------------------------------------------------
1745 ** Command completion handling.
1746 **----------------------------------------------------------------
1748 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
1749 struct ccb
*(ccb_done
[MAX_DONE
]);
1752 /*----------------------------------------------------------------
1753 ** Fields that should be removed or changed.
1754 **----------------------------------------------------------------
1756 struct ccb
*ccb
; /* Global CCB */
1757 struct usrcmd user
; /* Command from user */
1758 volatile u_char release_stage
; /* Synchronisation stage on release */
1761 #define NCB_SCRIPT_PHYS(np,lbl) (np->p_script + offsetof (struct script, lbl))
1762 #define NCB_SCRIPTH_PHYS(np,lbl) (np->p_scripth + offsetof (struct scripth,lbl))
1764 /*==========================================================
1767 ** Script for NCR-Processor.
1769 ** Use ncr_script_fill() to create the variable parts.
1770 ** Use ncr_script_copy_and_bind() to make a copy and
1771 ** bind to physical addresses.
1774 **==========================================================
1776 ** We have to know the offsets of all labels before
1777 ** we reach them (for forward jumps).
1778 ** Therefore we declare a struct here.
1779 ** If you make changes inside the script,
1780 ** DONT FORGET TO CHANGE THE LENGTHS HERE!
1782 **----------------------------------------------------------
1786 ** For HP Zalon/53c720 systems, the Zalon interface
1787 ** between CPU and 53c720 does prefetches, which causes
1788 ** problems with self modifying scripts. The problem
1789 ** is overcome by calling a dummy subroutine after each
1790 ** modification, to force a refetch of the script on
1791 ** return from the subroutine.
1794 #ifdef CONFIG_NCR53C8XX_PREFETCH
1795 #define PREFETCH_FLUSH_CNT 2
1796 #define PREFETCH_FLUSH SCR_CALL, PADDRH (wait_dma),
1798 #define PREFETCH_FLUSH_CNT 0
1799 #define PREFETCH_FLUSH
1803 ** Script fragments which are loaded into the on-chip RAM
1804 ** of 825A, 875 and 895 chips.
1808 ncrcmd startpos
[ 1];
1810 ncrcmd select2
[ 9 + PREFETCH_FLUSH_CNT
];
1811 ncrcmd loadpos
[ 4];
1812 ncrcmd send_ident
[ 9];
1813 ncrcmd prepare
[ 6];
1814 ncrcmd prepare2
[ 7];
1815 ncrcmd command
[ 6];
1816 ncrcmd dispatch
[ 32];
1818 ncrcmd no_data
[ 17];
1821 ncrcmd msg_in2
[ 16];
1822 ncrcmd msg_bad
[ 4];
1824 ncrcmd cleanup
[ 6];
1825 ncrcmd complete
[ 9];
1826 ncrcmd cleanup_ok
[ 8 + PREFETCH_FLUSH_CNT
];
1827 ncrcmd cleanup0
[ 1];
1828 #ifndef SCSI_NCR_CCB_DONE_SUPPORT
1829 ncrcmd signal
[ 12];
1832 ncrcmd done_pos
[ 1];
1833 ncrcmd done_plug
[ 2];
1834 ncrcmd done_end
[ 7];
1836 ncrcmd save_dp
[ 7];
1837 ncrcmd restore_dp
[ 5];
1838 ncrcmd disconnect
[ 10];
1839 ncrcmd msg_out
[ 9];
1840 ncrcmd msg_out_done
[ 7];
1842 ncrcmd reselect
[ 8];
1843 ncrcmd reselected
[ 8];
1844 ncrcmd resel_dsa
[ 6 + PREFETCH_FLUSH_CNT
];
1845 ncrcmd loadpos1
[ 4];
1846 ncrcmd resel_lun
[ 6];
1847 ncrcmd resel_tag
[ 6];
1848 ncrcmd jump_to_nexus
[ 4 + PREFETCH_FLUSH_CNT
];
1849 ncrcmd nexus_indirect
[ 4];
1850 ncrcmd resel_notag
[ 4];
1851 ncrcmd data_in
[MAX_SCATTERL
* 4];
1852 ncrcmd data_in2
[ 4];
1853 ncrcmd data_out
[MAX_SCATTERL
* 4];
1854 ncrcmd data_out2
[ 4];
1858 ** Script fragments which stay in main memory for all chips.
1861 ncrcmd tryloop
[MAX_START
*2];
1862 ncrcmd tryloop2
[ 2];
1863 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
1864 ncrcmd done_queue
[MAX_DONE
*5];
1865 ncrcmd done_queue2
[ 2];
1867 ncrcmd select_no_atn
[ 8];
1869 ncrcmd skip
[ 9 + PREFETCH_FLUSH_CNT
];
1871 ncrcmd par_err_data_in
[ 6];
1872 ncrcmd par_err_other
[ 4];
1873 ncrcmd msg_reject
[ 8];
1874 ncrcmd msg_ign_residue
[ 24];
1875 ncrcmd msg_extended
[ 10];
1876 ncrcmd msg_ext_2
[ 10];
1877 ncrcmd msg_wdtr
[ 14];
1878 ncrcmd send_wdtr
[ 7];
1879 ncrcmd msg_ext_3
[ 10];
1880 ncrcmd msg_sdtr
[ 14];
1881 ncrcmd send_sdtr
[ 7];
1882 ncrcmd nego_bad_phase
[ 4];
1883 ncrcmd msg_out_abort
[ 10];
1884 ncrcmd hdata_in
[MAX_SCATTERH
* 4];
1885 ncrcmd hdata_in2
[ 2];
1886 ncrcmd hdata_out
[MAX_SCATTERH
* 4];
1887 ncrcmd hdata_out2
[ 2];
1889 ncrcmd aborttag
[ 4];
1891 ncrcmd abort_resel
[ 20];
1892 ncrcmd resend_ident
[ 4];
1893 ncrcmd clratn_go_on
[ 3];
1894 ncrcmd nxtdsp_go_on
[ 1];
1895 ncrcmd sdata_in
[ 8];
1896 ncrcmd data_io
[ 18];
1897 ncrcmd bad_identify
[ 12];
1898 ncrcmd bad_i_t_l
[ 4];
1899 ncrcmd bad_i_t_l_q
[ 4];
1900 ncrcmd bad_target
[ 8];
1901 ncrcmd bad_status
[ 8];
1902 ncrcmd start_ram
[ 4 + PREFETCH_FLUSH_CNT
];
1903 ncrcmd start_ram0
[ 4];
1904 ncrcmd sto_restart
[ 5];
1905 ncrcmd wait_dma
[ 2];
1906 ncrcmd snooptest
[ 9];
1907 ncrcmd snoopend
[ 2];
1910 /*==========================================================
1913 ** Function headers.
1916 **==========================================================
1919 static void ncr_alloc_ccb (struct ncb
*np
, u_char tn
, u_char ln
);
1920 static void ncr_complete (struct ncb
*np
, struct ccb
*cp
);
1921 static void ncr_exception (struct ncb
*np
);
1922 static void ncr_free_ccb (struct ncb
*np
, struct ccb
*cp
);
1923 static void ncr_init_ccb (struct ncb
*np
, struct ccb
*cp
);
1924 static void ncr_init_tcb (struct ncb
*np
, u_char tn
);
1925 static struct lcb
* ncr_alloc_lcb (struct ncb
*np
, u_char tn
, u_char ln
);
1926 static struct lcb
* ncr_setup_lcb (struct ncb
*np
, struct scsi_device
*sdev
);
1927 static void ncr_getclock (struct ncb
*np
, int mult
);
1928 static void ncr_selectclock (struct ncb
*np
, u_char scntl3
);
1929 static struct ccb
*ncr_get_ccb (struct ncb
*np
, struct scsi_cmnd
*cmd
);
1930 static void ncr_chip_reset (struct ncb
*np
, int delay
);
1931 static void ncr_init (struct ncb
*np
, int reset
, char * msg
, u_long code
);
1932 static int ncr_int_sbmc (struct ncb
*np
);
1933 static int ncr_int_par (struct ncb
*np
);
1934 static void ncr_int_ma (struct ncb
*np
);
1935 static void ncr_int_sir (struct ncb
*np
);
1936 static void ncr_int_sto (struct ncb
*np
);
1937 static void ncr_negotiate (struct ncb
* np
, struct tcb
* tp
);
1938 static int ncr_prepare_nego(struct ncb
*np
, struct ccb
*cp
, u_char
*msgptr
);
1940 static void ncr_script_copy_and_bind
1941 (struct ncb
*np
, ncrcmd
*src
, ncrcmd
*dst
, int len
);
1942 static void ncr_script_fill (struct script
* scr
, struct scripth
* scripth
);
1943 static int ncr_scatter (struct ncb
*np
, struct ccb
*cp
, struct scsi_cmnd
*cmd
);
1944 static void ncr_getsync (struct ncb
*np
, u_char sfac
, u_char
*fakp
, u_char
*scntl3p
);
1945 static void ncr_setsync (struct ncb
*np
, struct ccb
*cp
, u_char scntl3
, u_char sxfer
);
1946 static void ncr_setup_tags (struct ncb
*np
, struct scsi_device
*sdev
);
1947 static void ncr_setwide (struct ncb
*np
, struct ccb
*cp
, u_char wide
, u_char ack
);
1948 static int ncr_snooptest (struct ncb
*np
);
1949 static void ncr_timeout (struct ncb
*np
);
1950 static void ncr_wakeup (struct ncb
*np
, u_long code
);
1951 static void ncr_wakeup_done (struct ncb
*np
);
1952 static void ncr_start_next_ccb (struct ncb
*np
, struct lcb
* lp
, int maxn
);
1953 static void ncr_put_start_queue(struct ncb
*np
, struct ccb
*cp
);
1955 static void insert_into_waiting_list(struct ncb
*np
, struct scsi_cmnd
*cmd
);
1956 static struct scsi_cmnd
*retrieve_from_waiting_list(int to_remove
, struct ncb
*np
, struct scsi_cmnd
*cmd
);
1957 static void process_waiting_list(struct ncb
*np
, int sts
);
1959 #define remove_from_waiting_list(np, cmd) \
1960 retrieve_from_waiting_list(1, (np), (cmd))
1961 #define requeue_waiting_list(np) process_waiting_list((np), DID_OK)
1962 #define reset_waiting_list(np) process_waiting_list((np), DID_RESET)
1964 static inline char *ncr_name (struct ncb
*np
)
1966 return np
->inst_name
;
1970 /*==========================================================
1973 ** Scripts for NCR-Processor.
1975 ** Use ncr_script_bind for binding to physical addresses.
1978 **==========================================================
1980 ** NADDR generates a reference to a field of the controller data.
1981 ** PADDR generates a reference to another part of the script.
1982 ** RADDR generates a reference to a script processor register.
1983 ** FADDR generates a reference to a script processor register
1986 **----------------------------------------------------------
1989 #define RELOC_SOFTC 0x40000000
1990 #define RELOC_LABEL 0x50000000
1991 #define RELOC_REGISTER 0x60000000
1993 #define RELOC_KVAR 0x70000000
1995 #define RELOC_LABELH 0x80000000
1996 #define RELOC_MASK 0xf0000000
1998 #define NADDR(label) (RELOC_SOFTC | offsetof(struct ncb, label))
1999 #define PADDR(label) (RELOC_LABEL | offsetof(struct script, label))
2000 #define PADDRH(label) (RELOC_LABELH | offsetof(struct scripth, label))
2001 #define RADDR(label) (RELOC_REGISTER | REG(label))
2002 #define FADDR(label,ofs)(RELOC_REGISTER | ((REG(label))+(ofs)))
2004 #define KVAR(which) (RELOC_KVAR | (which))
2008 #define SCRIPT_KVAR_JIFFIES (0)
2009 #define SCRIPT_KVAR_FIRST SCRIPT_KVAR_JIFFIES
2010 #define SCRIPT_KVAR_LAST SCRIPT_KVAR_JIFFIES
2012 * Kernel variables referenced in the scripts.
2013 * THESE MUST ALL BE ALIGNED TO A 4-BYTE BOUNDARY.
2015 static void *script_kvars
[] __initdata
=
2016 { (void *)&jiffies
};
2019 static struct script script0 __initdata
= {
2020 /*--------------------------< START >-----------------------*/ {
2022 ** This NOP will be patched with LED ON
2023 ** SCR_REG_REG (gpreg, SCR_AND, 0xfe)
2030 SCR_FROM_REG (ctest2
),
2033 ** Then jump to a certain point in tryloop.
2034 ** Due to the lack of indirect addressing the code
2035 ** is self modifying here.
2038 }/*-------------------------< STARTPOS >--------------------*/,{
2041 }/*-------------------------< SELECT >----------------------*/,{
2043 ** DSA contains the address of a scheduled
2046 ** SCRATCHA contains the address of the script,
2047 ** which starts the next entry.
2049 ** Set Initiator mode.
2051 ** (Target mode is left as an exercise for the reader)
2056 SCR_LOAD_REG (HS_REG
, HS_SELECTING
),
2060 ** And try to select this target.
2062 SCR_SEL_TBL_ATN
^ offsetof (struct dsb
, select
),
2065 }/*-------------------------< SELECT2 >----------------------*/,{
2067 ** Now there are 4 possibilities:
2069 ** (1) The ncr loses arbitration.
2070 ** This is ok, because it will try again,
2071 ** when the bus becomes idle.
2072 ** (But beware of the timeout function!)
2074 ** (2) The ncr is reselected.
2075 ** Then the script processor takes the jump
2076 ** to the RESELECT label.
2078 ** (3) The ncr wins arbitration.
2079 ** Then it will execute SCRIPTS instruction until
2080 ** the next instruction that checks SCSI phase.
2081 ** Then will stop and wait for selection to be
2082 ** complete or selection time-out to occur.
2083 ** As a result the SCRIPTS instructions until
2084 ** LOADPOS + 2 should be executed in parallel with
2085 ** the SCSI core performing selection.
2089 ** The MESSAGE_REJECT problem seems to be due to a selection
2091 ** Wait immediately for the selection to complete.
2092 ** (2.5x behaves so)
2094 SCR_JUMPR
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
2098 ** Next time use the next slot.
2104 ** The ncr doesn't have an indirect load
2105 ** or store command. So we have to
2106 ** copy part of the control block to a
2107 ** fixed place, where we can access it.
2109 ** We patch the address part of a
2110 ** COPY command with the DSA-register.
2116 ** Flush script prefetch if required
2120 ** then we do the actual copy.
2122 SCR_COPY (sizeof (struct head
)),
2124 ** continued after the next label ...
2126 }/*-------------------------< LOADPOS >---------------------*/,{
2130 ** Wait for the next phase or the selection
2131 ** to complete or time-out.
2133 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
2136 }/*-------------------------< SEND_IDENT >----------------------*/,{
2138 ** Selection complete.
2139 ** Send the IDENTIFY and SIMPLE_TAG messages
2140 ** (and the EXTENDED_SDTR message)
2142 SCR_MOVE_TBL
^ SCR_MSG_OUT
,
2143 offsetof (struct dsb
, smsg
),
2144 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_OUT
)),
2145 PADDRH (resend_ident
),
2146 SCR_LOAD_REG (scratcha
, 0x80),
2151 }/*-------------------------< PREPARE >----------------------*/,{
2153 ** load the savep (saved pointer) into
2154 ** the TEMP register (actual pointer)
2157 NADDR (header
.savep
),
2160 ** Initialize the status registers
2163 NADDR (header
.status
),
2165 }/*-------------------------< PREPARE2 >---------------------*/,{
2167 ** Initialize the msgout buffer with a NOOP message.
2169 SCR_LOAD_REG (scratcha
, NOP
),
2180 ** Anticipate the COMMAND phase.
2181 ** This is the normal case for initial selection.
2183 SCR_JUMP
^ IFFALSE (WHEN (SCR_COMMAND
)),
2186 }/*-------------------------< COMMAND >--------------------*/,{
2188 ** ... and send the command
2190 SCR_MOVE_TBL
^ SCR_COMMAND
,
2191 offsetof (struct dsb
, cmd
),
2193 ** If status is still HS_NEGOTIATE, negotiation failed.
2194 ** We check this here, since we want to do that
2197 SCR_FROM_REG (HS_REG
),
2199 SCR_INT
^ IFTRUE (DATA (HS_NEGOTIATE
)),
2202 }/*-----------------------< DISPATCH >----------------------*/,{
2204 ** MSG_IN is the only phase that shall be
2205 ** entered at least once for each (re)selection.
2206 ** So we test it first.
2208 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_IN
)),
2211 SCR_RETURN
^ IFTRUE (IF (SCR_DATA_OUT
)),
2214 ** DEL 397 - 53C875 Rev 3 - Part Number 609-0392410 - ITEM 4.
2215 ** Possible data corruption during Memory Write and Invalidate.
2216 ** This work-around resets the addressing logic prior to the
2217 ** start of the first MOVE of a DATA IN phase.
2218 ** (See Documentation/scsi/ncr53c8xx.txt for more information)
2220 SCR_JUMPR
^ IFFALSE (IF (SCR_DATA_IN
)),
2227 SCR_JUMP
^ IFTRUE (IF (SCR_STATUS
)),
2229 SCR_JUMP
^ IFTRUE (IF (SCR_COMMAND
)),
2231 SCR_JUMP
^ IFTRUE (IF (SCR_MSG_OUT
)),
2234 ** Discard one illegal phase byte, if required.
2236 SCR_LOAD_REG (scratcha
, XE_BAD_PHASE
),
2241 SCR_JUMPR
^ IFFALSE (IF (SCR_ILG_OUT
)),
2243 SCR_MOVE_ABS (1) ^ SCR_ILG_OUT
,
2245 SCR_JUMPR
^ IFFALSE (IF (SCR_ILG_IN
)),
2247 SCR_MOVE_ABS (1) ^ SCR_ILG_IN
,
2252 }/*-------------------------< CLRACK >----------------------*/,{
2254 ** Terminate possible pending message phase.
2261 }/*-------------------------< NO_DATA >--------------------*/,{
2263 ** The target wants to tranfer too much data
2264 ** or in the wrong direction.
2265 ** Remember that in extended error.
2267 SCR_LOAD_REG (scratcha
, XE_EXTRA_DATA
),
2273 ** Discard one data byte, if required.
2275 SCR_JUMPR
^ IFFALSE (WHEN (SCR_DATA_OUT
)),
2277 SCR_MOVE_ABS (1) ^ SCR_DATA_OUT
,
2279 SCR_JUMPR
^ IFFALSE (IF (SCR_DATA_IN
)),
2281 SCR_MOVE_ABS (1) ^ SCR_DATA_IN
,
2284 ** .. and repeat as required.
2291 }/*-------------------------< STATUS >--------------------*/,{
2295 SCR_MOVE_ABS (1) ^ SCR_STATUS
,
2298 ** save status to scsi_status.
2299 ** mark as complete.
2301 SCR_TO_REG (SS_REG
),
2303 SCR_LOAD_REG (HS_REG
, HS_COMPLETE
),
2307 }/*-------------------------< MSG_IN >--------------------*/,{
2309 ** Get the first byte of the message
2310 ** and save it to SCRATCHA.
2312 ** The script processor doesn't negate the
2313 ** ACK signal after this transfer.
2315 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2317 }/*-------------------------< MSG_IN2 >--------------------*/,{
2319 ** Handle this message.
2321 SCR_JUMP
^ IFTRUE (DATA (COMMAND_COMPLETE
)),
2323 SCR_JUMP
^ IFTRUE (DATA (DISCONNECT
)),
2325 SCR_JUMP
^ IFTRUE (DATA (SAVE_POINTERS
)),
2327 SCR_JUMP
^ IFTRUE (DATA (RESTORE_POINTERS
)),
2329 SCR_JUMP
^ IFTRUE (DATA (EXTENDED_MESSAGE
)),
2330 PADDRH (msg_extended
),
2331 SCR_JUMP
^ IFTRUE (DATA (NOP
)),
2333 SCR_JUMP
^ IFTRUE (DATA (MESSAGE_REJECT
)),
2334 PADDRH (msg_reject
),
2335 SCR_JUMP
^ IFTRUE (DATA (IGNORE_WIDE_RESIDUE
)),
2336 PADDRH (msg_ign_residue
),
2338 ** Rest of the messages left as
2341 ** Unimplemented messages:
2342 ** fall through to MSG_BAD.
2344 }/*-------------------------< MSG_BAD >------------------*/,{
2346 ** unimplemented message - reject it.
2350 SCR_LOAD_REG (scratcha
, MESSAGE_REJECT
),
2352 }/*-------------------------< SETMSG >----------------------*/,{
2360 }/*-------------------------< CLEANUP >-------------------*/,{
2362 ** dsa: Pointer to ccb
2363 ** or xxxxxxFF (no ccb)
2365 ** HS_REG: Host-Status (<>0!)
2369 SCR_JUMP
^ IFTRUE (DATA (0xff)),
2373 ** complete the cleanup.
2378 }/*-------------------------< COMPLETE >-----------------*/,{
2380 ** Complete message.
2382 ** Copy TEMP register to LASTP in header.
2386 NADDR (header
.lastp
),
2388 ** When we terminate the cycle by clearing ACK,
2389 ** the target may disconnect immediately.
2391 ** We don't want to be told of an
2392 ** "unexpected disconnect",
2393 ** so we disable this feature.
2395 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
2398 ** Terminate cycle ...
2400 SCR_CLR (SCR_ACK
|SCR_ATN
),
2403 ** ... and wait for the disconnect.
2407 }/*-------------------------< CLEANUP_OK >----------------*/,{
2409 ** Save host status to header.
2413 NADDR (header
.status
),
2415 ** and copy back the header to the ccb.
2421 ** Flush script prefetch if required
2424 SCR_COPY (sizeof (struct head
)),
2426 }/*-------------------------< CLEANUP0 >--------------------*/,{
2428 }/*-------------------------< SIGNAL >----------------------*/,{
2430 ** if job not completed ...
2432 SCR_FROM_REG (HS_REG
),
2435 ** ... start the next command.
2437 SCR_JUMP
^ IFTRUE (MASK (0, (HS_DONEMASK
|HS_SKIPMASK
))),
2440 ** If command resulted in not GOOD status,
2441 ** call the C code if needed.
2443 SCR_FROM_REG (SS_REG
),
2445 SCR_CALL
^ IFFALSE (DATA (S_GOOD
)),
2446 PADDRH (bad_status
),
2448 #ifndef SCSI_NCR_CCB_DONE_SUPPORT
2451 ** ... signal completion to the host
2456 ** Auf zu neuen Schandtaten!
2461 #else /* defined SCSI_NCR_CCB_DONE_SUPPORT */
2464 ** ... signal completion to the host
2467 }/*------------------------< DONE_POS >---------------------*/,{
2468 PADDRH (done_queue
),
2469 }/*------------------------< DONE_PLUG >--------------------*/,{
2472 }/*------------------------< DONE_END >---------------------*/,{
2481 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
2483 }/*-------------------------< SAVE_DP >------------------*/,{
2486 ** Copy TEMP register to SAVEP in header.
2490 NADDR (header
.savep
),
2495 }/*-------------------------< RESTORE_DP >---------------*/,{
2497 ** RESTORE_DP message:
2498 ** Copy SAVEP in header to TEMP register.
2501 NADDR (header
.savep
),
2506 }/*-------------------------< DISCONNECT >---------------*/,{
2508 ** DISCONNECTing ...
2510 ** disable the "unexpected disconnect" feature,
2511 ** and remove the ACK signal.
2513 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
2515 SCR_CLR (SCR_ACK
|SCR_ATN
),
2518 ** Wait for the disconnect.
2523 ** Status is: DISCONNECTED.
2525 SCR_LOAD_REG (HS_REG
, HS_DISCONNECT
),
2530 }/*-------------------------< MSG_OUT >-------------------*/,{
2532 ** The target requests a message.
2534 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT
,
2540 ** If it was no ABORT message ...
2542 SCR_JUMP
^ IFTRUE (DATA (ABORT_TASK_SET
)),
2543 PADDRH (msg_out_abort
),
2545 ** ... wait for the next phase
2546 ** if it's a message out, send it again, ...
2548 SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_OUT
)),
2550 }/*-------------------------< MSG_OUT_DONE >--------------*/,{
2552 ** ... else clear the message ...
2554 SCR_LOAD_REG (scratcha
, NOP
),
2560 ** ... and process the next phase
2564 }/*-------------------------< IDLE >------------------------*/,{
2567 ** Wait for reselect.
2568 ** This NOP will be patched with LED OFF
2569 ** SCR_REG_REG (gpreg, SCR_OR, 0x01)
2573 }/*-------------------------< RESELECT >--------------------*/,{
2575 ** make the DSA invalid.
2577 SCR_LOAD_REG (dsa
, 0xff),
2581 SCR_LOAD_REG (HS_REG
, HS_IN_RESELECT
),
2584 ** Sleep waiting for a reselection.
2585 ** If SIGP is set, special treatment.
2587 ** Zu allem bereit ..
2591 }/*-------------------------< RESELECTED >------------------*/,{
2593 ** This NOP will be patched with LED ON
2594 ** SCR_REG_REG (gpreg, SCR_AND, 0xfe)
2599 ** ... zu nichts zu gebrauchen ?
2601 ** load the target id into the SFBR
2602 ** and jump to the control block.
2604 ** Look at the declarations of
2609 ** to understand what's going on.
2611 SCR_REG_SFBR (ssid
, SCR_AND
, 0x8F),
2618 }/*-------------------------< RESEL_DSA >-------------------*/,{
2620 ** Ack the IDENTIFY or TAG previously received.
2625 ** The ncr doesn't have an indirect load
2626 ** or store command. So we have to
2627 ** copy part of the control block to a
2628 ** fixed place, where we can access it.
2630 ** We patch the address part of a
2631 ** COPY command with the DSA-register.
2637 ** Flush script prefetch if required
2641 ** then we do the actual copy.
2643 SCR_COPY (sizeof (struct head
)),
2645 ** continued after the next label ...
2648 }/*-------------------------< LOADPOS1 >-------------------*/,{
2652 ** The DSA contains the data structure address.
2657 }/*-------------------------< RESEL_LUN >-------------------*/,{
2659 ** come back to this point
2660 ** to get an IDENTIFY message
2661 ** Wait for a msg_in phase.
2663 SCR_INT
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2664 SIR_RESEL_NO_MSG_IN
,
2667 ** Read the data directly from the BUS DATA lines.
2668 ** This helps to support very old SCSI devices that
2669 ** may reselect without sending an IDENTIFY.
2671 SCR_FROM_REG (sbdl
),
2674 ** It should be an Identify message.
2678 }/*-------------------------< RESEL_TAG >-------------------*/,{
2680 ** Read IDENTIFY + SIMPLE + TAG using a single MOVE.
2681 ** Agressive optimization, is'nt it?
2682 ** No need to test the SIMPLE TAG message, since the
2683 ** driver only supports conformant devices for tags. ;-)
2685 SCR_MOVE_ABS (3) ^ SCR_MSG_IN
,
2688 ** Read the TAG from the SIDL.
2689 ** Still an aggressive optimization. ;-)
2690 ** Compute the CCB indirect jump address which
2691 ** is (#TAG*2 & 0xfc) due to tag numbering using
2692 ** 1,3,5..MAXTAGS*2+1 actual values.
2694 SCR_REG_SFBR (sidl
, SCR_SHL
, 0),
2696 SCR_SFBR_REG (temp
, SCR_AND
, 0xfc),
2698 }/*-------------------------< JUMP_TO_NEXUS >-------------------*/,{
2701 PADDR (nexus_indirect
),
2703 ** Flush script prefetch if required
2707 }/*-------------------------< NEXUS_INDIRECT >-------------------*/,{
2712 }/*-------------------------< RESEL_NOTAG >-------------------*/,{
2715 ** Read an throw away the IDENTIFY.
2717 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2720 PADDR (jump_to_nexus
),
2721 }/*-------------------------< DATA_IN >--------------------*/,{
2723 ** Because the size depends on the
2724 ** #define MAX_SCATTERL parameter,
2725 ** it is filled in at runtime.
2727 ** ##===========< i=0; i<MAX_SCATTERL >=========
2728 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN)),
2729 ** || PADDR (dispatch),
2730 ** || SCR_MOVE_TBL ^ SCR_DATA_IN,
2731 ** || offsetof (struct dsb, data[ i]),
2732 ** ##==========================================
2734 **---------------------------------------------------------
2737 }/*-------------------------< DATA_IN2 >-------------------*/,{
2742 }/*-------------------------< DATA_OUT >--------------------*/,{
2744 ** Because the size depends on the
2745 ** #define MAX_SCATTERL parameter,
2746 ** it is filled in at runtime.
2748 ** ##===========< i=0; i<MAX_SCATTERL >=========
2749 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT)),
2750 ** || PADDR (dispatch),
2751 ** || SCR_MOVE_TBL ^ SCR_DATA_OUT,
2752 ** || offsetof (struct dsb, data[ i]),
2753 ** ##==========================================
2755 **---------------------------------------------------------
2758 }/*-------------------------< DATA_OUT2 >-------------------*/,{
2763 }/*--------------------------------------------------------*/
2766 static struct scripth scripth0 __initdata
= {
2767 /*-------------------------< TRYLOOP >---------------------*/{
2769 ** Start the next entry.
2770 ** Called addresses point to the launch script in the CCB.
2771 ** They are patched by the main processor.
2773 ** Because the size depends on the
2774 ** #define MAX_START parameter, it is filled
2777 **-----------------------------------------------------------
2779 ** ##===========< I=0; i<MAX_START >===========
2782 ** ##==========================================
2784 **-----------------------------------------------------------
2787 }/*------------------------< TRYLOOP2 >---------------------*/,{
2791 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
2793 }/*------------------------< DONE_QUEUE >-------------------*/,{
2795 ** Copy the CCB address to the next done entry.
2796 ** Because the size depends on the
2797 ** #define MAX_DONE parameter, it is filled
2800 **-----------------------------------------------------------
2802 ** ##===========< I=0; i<MAX_DONE >===========
2803 ** || SCR_COPY (sizeof(struct ccb *),
2804 ** || NADDR (header.cp),
2805 ** || NADDR (ccb_done[i]),
2807 ** || PADDR (done_end),
2808 ** ##==========================================
2810 **-----------------------------------------------------------
2813 }/*------------------------< DONE_QUEUE2 >------------------*/,{
2815 PADDRH (done_queue
),
2817 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
2818 }/*------------------------< SELECT_NO_ATN >-----------------*/,{
2820 ** Set Initiator mode.
2821 ** And try to select this target without ATN.
2826 SCR_LOAD_REG (HS_REG
, HS_SELECTING
),
2828 SCR_SEL_TBL
^ offsetof (struct dsb
, select
),
2833 }/*-------------------------< CANCEL >------------------------*/,{
2835 SCR_LOAD_REG (scratcha
, HS_ABORTED
),
2839 }/*-------------------------< SKIP >------------------------*/,{
2840 SCR_LOAD_REG (scratcha
, 0),
2843 ** This entry has been canceled.
2844 ** Next time use the next slot.
2850 ** The ncr doesn't have an indirect load
2851 ** or store command. So we have to
2852 ** copy part of the control block to a
2853 ** fixed place, where we can access it.
2855 ** We patch the address part of a
2856 ** COPY command with the DSA-register.
2862 ** Flush script prefetch if required
2866 ** then we do the actual copy.
2868 SCR_COPY (sizeof (struct head
)),
2870 ** continued after the next label ...
2872 }/*-------------------------< SKIP2 >---------------------*/,{
2876 ** Initialize the status registers
2879 NADDR (header
.status
),
2882 ** Force host status.
2884 SCR_FROM_REG (scratcha
),
2886 SCR_JUMPR
^ IFFALSE (MASK (0, HS_DONEMASK
)),
2888 SCR_REG_REG (HS_REG
, SCR_OR
, HS_SKIPMASK
),
2892 SCR_TO_REG (HS_REG
),
2894 SCR_LOAD_REG (SS_REG
, S_GOOD
),
2899 },/*-------------------------< PAR_ERR_DATA_IN >---------------*/{
2901 ** Ignore all data in byte, until next phase
2903 SCR_JUMP
^ IFFALSE (WHEN (SCR_DATA_IN
)),
2904 PADDRH (par_err_other
),
2905 SCR_MOVE_ABS (1) ^ SCR_DATA_IN
,
2909 },/*-------------------------< PAR_ERR_OTHER >------------------*/{
2913 SCR_REG_REG (PS_REG
, SCR_ADD
, 0x01),
2916 ** jump to dispatcher.
2920 }/*-------------------------< MSG_REJECT >---------------*/,{
2922 ** If a negotiation was in progress,
2923 ** negotiation failed.
2924 ** Otherwise, let the C code print
2927 SCR_FROM_REG (HS_REG
),
2929 SCR_INT
^ IFFALSE (DATA (HS_NEGOTIATE
)),
2930 SIR_REJECT_RECEIVED
,
2931 SCR_INT
^ IFTRUE (DATA (HS_NEGOTIATE
)),
2936 }/*-------------------------< MSG_IGN_RESIDUE >----------*/,{
2942 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2945 ** get residue size.
2947 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2950 ** Size is 0 .. ignore message.
2952 SCR_JUMP
^ IFTRUE (DATA (0)),
2955 ** Size is not 1 .. have to interrupt.
2957 SCR_JUMPR
^ IFFALSE (DATA (1)),
2960 ** Check for residue byte in swide register
2962 SCR_FROM_REG (scntl2
),
2964 SCR_JUMPR
^ IFFALSE (MASK (WSR
, WSR
)),
2967 ** There IS data in the swide register.
2970 SCR_REG_REG (scntl2
, SCR_OR
, WSR
),
2975 ** Load again the size to the sfbr register.
2977 SCR_FROM_REG (scratcha
),
2984 }/*-------------------------< MSG_EXTENDED >-------------*/,{
2990 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
2995 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
2999 SCR_JUMP
^ IFTRUE (DATA (3)),
3001 SCR_JUMP
^ IFFALSE (DATA (2)),
3003 }/*-------------------------< MSG_EXT_2 >----------------*/,{
3006 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
3009 ** get extended message code.
3011 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3013 SCR_JUMP
^ IFTRUE (DATA (EXTENDED_WDTR
)),
3016 ** unknown extended message
3020 }/*-------------------------< MSG_WDTR >-----------------*/,{
3023 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
3026 ** get data bus width
3028 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3031 ** let the host do the real work.
3036 ** let the target fetch our answer.
3042 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
3043 PADDRH (nego_bad_phase
),
3045 }/*-------------------------< SEND_WDTR >----------------*/,{
3047 ** Send the EXTENDED_WDTR
3049 SCR_MOVE_ABS (4) ^ SCR_MSG_OUT
,
3055 PADDR (msg_out_done
),
3057 }/*-------------------------< MSG_EXT_3 >----------------*/,{
3060 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
3063 ** get extended message code.
3065 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3067 SCR_JUMP
^ IFTRUE (DATA (EXTENDED_SDTR
)),
3070 ** unknown extended message
3075 }/*-------------------------< MSG_SDTR >-----------------*/,{
3078 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_IN
)),
3081 ** get period and offset
3083 SCR_MOVE_ABS (2) ^ SCR_MSG_IN
,
3086 ** let the host do the real work.
3091 ** let the target fetch our answer.
3097 SCR_JUMP
^ IFFALSE (WHEN (SCR_MSG_OUT
)),
3098 PADDRH (nego_bad_phase
),
3100 }/*-------------------------< SEND_SDTR >-------------*/,{
3102 ** Send the EXTENDED_SDTR
3104 SCR_MOVE_ABS (5) ^ SCR_MSG_OUT
,
3110 PADDR (msg_out_done
),
3112 }/*-------------------------< NEGO_BAD_PHASE >------------*/,{
3118 }/*-------------------------< MSG_OUT_ABORT >-------------*/,{
3120 ** After ABORT message,
3122 ** expect an immediate disconnect, ...
3124 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
3126 SCR_CLR (SCR_ACK
|SCR_ATN
),
3131 ** ... and set the status to "ABORTED"
3133 SCR_LOAD_REG (HS_REG
, HS_ABORTED
),
3138 }/*-------------------------< HDATA_IN >-------------------*/,{
3140 ** Because the size depends on the
3141 ** #define MAX_SCATTERH parameter,
3142 ** it is filled in at runtime.
3144 ** ##==< i=MAX_SCATTERL; i<MAX_SCATTERL+MAX_SCATTERH >==
3145 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_IN)),
3146 ** || PADDR (dispatch),
3147 ** || SCR_MOVE_TBL ^ SCR_DATA_IN,
3148 ** || offsetof (struct dsb, data[ i]),
3149 ** ##===================================================
3151 **---------------------------------------------------------
3154 }/*-------------------------< HDATA_IN2 >------------------*/,{
3158 }/*-------------------------< HDATA_OUT >-------------------*/,{
3160 ** Because the size depends on the
3161 ** #define MAX_SCATTERH parameter,
3162 ** it is filled in at runtime.
3164 ** ##==< i=MAX_SCATTERL; i<MAX_SCATTERL+MAX_SCATTERH >==
3165 ** || SCR_CALL ^ IFFALSE (WHEN (SCR_DATA_OUT)),
3166 ** || PADDR (dispatch),
3167 ** || SCR_MOVE_TBL ^ SCR_DATA_OUT,
3168 ** || offsetof (struct dsb, data[ i]),
3169 ** ##===================================================
3171 **---------------------------------------------------------
3174 }/*-------------------------< HDATA_OUT2 >------------------*/,{
3178 }/*-------------------------< RESET >----------------------*/,{
3180 ** Send a TARGET_RESET message if bad IDENTIFY
3181 ** received on reselection.
3183 SCR_LOAD_REG (scratcha
, ABORT_TASK
),
3186 PADDRH (abort_resel
),
3187 }/*-------------------------< ABORTTAG >-------------------*/,{
3189 ** Abort a wrong tag received on reselection.
3191 SCR_LOAD_REG (scratcha
, ABORT_TASK
),
3194 PADDRH (abort_resel
),
3195 }/*-------------------------< ABORT >----------------------*/,{
3197 ** Abort a reselection when no active CCB.
3199 SCR_LOAD_REG (scratcha
, ABORT_TASK_SET
),
3201 }/*-------------------------< ABORT_RESEL >----------------*/,{
3211 ** we expect an immediate disconnect
3213 SCR_REG_REG (scntl2
, SCR_AND
, 0x7f),
3215 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT
,
3220 SCR_CLR (SCR_ACK
|SCR_ATN
),
3226 }/*-------------------------< RESEND_IDENT >-------------------*/,{
3228 ** The target stays in MSG OUT phase after having acked
3229 ** Identify [+ Tag [+ Extended message ]]. Targets shall
3230 ** behave this way on parity error.
3231 ** We must send it again all the messages.
3233 SCR_SET (SCR_ATN
), /* Shall be asserted 2 deskew delays before the */
3234 0, /* 1rst ACK = 90 ns. Hope the NCR is'nt too fast */
3237 }/*-------------------------< CLRATN_GO_ON >-------------------*/,{
3241 }/*-------------------------< NXTDSP_GO_ON >-------------------*/,{
3243 }/*-------------------------< SDATA_IN >-------------------*/,{
3244 SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_IN
)),
3246 SCR_MOVE_TBL
^ SCR_DATA_IN
,
3247 offsetof (struct dsb
, sense
),
3252 }/*-------------------------< DATA_IO >--------------------*/,{
3254 ** We jump here if the data direction was unknown at the
3255 ** time we had to queue the command to the scripts processor.
3256 ** Pointers had been set as follow in this situation:
3257 ** savep --> DATA_IO
3258 ** lastp --> start pointer when DATA_IN
3259 ** goalp --> goal pointer when DATA_IN
3260 ** wlastp --> start pointer when DATA_OUT
3261 ** wgoalp --> goal pointer when DATA_OUT
3262 ** This script sets savep/lastp/goalp according to the
3263 ** direction chosen by the target.
3265 SCR_JUMPR
^ IFTRUE (WHEN (SCR_DATA_OUT
)),
3268 ** Direction is DATA IN.
3269 ** Warning: we jump here, even when phase is DATA OUT.
3272 NADDR (header
.lastp
),
3273 NADDR (header
.savep
),
3276 ** Jump to the SCRIPTS according to actual direction.
3279 NADDR (header
.savep
),
3284 ** Direction is DATA OUT.
3287 NADDR (header
.wlastp
),
3288 NADDR (header
.lastp
),
3290 NADDR (header
.wgoalp
),
3291 NADDR (header
.goalp
),
3294 }/*-------------------------< BAD_IDENTIFY >---------------*/,{
3296 ** If message phase but not an IDENTIFY,
3297 ** get some help from the C code.
3298 ** Old SCSI device may behave so.
3300 SCR_JUMPR
^ IFTRUE (MASK (0x80, 0x80)),
3303 SIR_RESEL_NO_IDENTIFY
,
3307 ** Message is an IDENTIFY, but lun is unknown.
3308 ** Read the message, since we got it directly
3309 ** from the SCSI BUS data lines.
3310 ** Signal problem to C code for logging the event.
3311 ** Send an ABORT_TASK_SET to clear all pending tasks.
3315 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3319 }/*-------------------------< BAD_I_T_L >------------------*/,{
3321 ** We donnot have a task for that I_T_L.
3322 ** Signal problem to C code for logging the event.
3323 ** Send an ABORT_TASK_SET message.
3326 SIR_RESEL_BAD_I_T_L
,
3329 }/*-------------------------< BAD_I_T_L_Q >----------------*/,{
3331 ** We donnot have a task that matches the tag.
3332 ** Signal problem to C code for logging the event.
3333 ** Send an ABORT_TASK message.
3336 SIR_RESEL_BAD_I_T_L_Q
,
3339 }/*-------------------------< BAD_TARGET >-----------------*/,{
3341 ** We donnot know the target that reselected us.
3342 ** Grab the first message if any (IDENTIFY).
3343 ** Signal problem to C code for logging the event.
3344 ** TARGET_RESET message.
3347 SIR_RESEL_BAD_TARGET
,
3348 SCR_JUMPR
^ IFFALSE (WHEN (SCR_MSG_IN
)),
3350 SCR_MOVE_ABS (1) ^ SCR_MSG_IN
,
3354 }/*-------------------------< BAD_STATUS >-----------------*/,{
3356 ** If command resulted in either QUEUE FULL,
3357 ** CHECK CONDITION or COMMAND TERMINATED,
3360 SCR_INT
^ IFTRUE (DATA (S_QUEUE_FULL
)),
3362 SCR_INT
^ IFTRUE (DATA (S_CHECK_COND
)),
3364 SCR_INT
^ IFTRUE (DATA (S_TERMINATED
)),
3368 }/*-------------------------< START_RAM >-------------------*/,{
3370 ** Load the script into on-chip RAM,
3371 ** and jump to start point.
3375 PADDRH (start_ram0
),
3377 ** Flush script prefetch if required
3380 SCR_COPY (sizeof (struct script
)),
3381 }/*-------------------------< START_RAM0 >--------------------*/,{
3386 }/*-------------------------< STO_RESTART >-------------------*/,{
3389 ** Repair start queue (e.g. next time use the next slot)
3390 ** and jump to start point.
3397 }/*-------------------------< WAIT_DMA >-------------------*/,{
3399 ** For HP Zalon/53c720 systems, the Zalon interface
3400 ** between CPU and 53c720 does prefetches, which causes
3401 ** problems with self modifying scripts. The problem
3402 ** is overcome by calling a dummy subroutine after each
3403 ** modification, to force a refetch of the script on
3404 ** return from the subroutine.
3408 }/*-------------------------< SNOOPTEST >-------------------*/,{
3410 ** Read the variable.
3416 ** Write the variable.
3422 ** Read back the variable.
3427 }/*-------------------------< SNOOPEND >-------------------*/,{
3433 }/*--------------------------------------------------------*/
3436 /*==========================================================
3439 ** Fill in #define dependent parts of the script
3442 **==========================================================
3445 void __init
ncr_script_fill (struct script
* scr
, struct scripth
* scrh
)
3451 for (i
=0; i
<MAX_START
; i
++) {
3456 BUG_ON((u_long
)p
!= (u_long
)&scrh
->tryloop
+ sizeof (scrh
->tryloop
));
3458 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
3460 p
= scrh
->done_queue
;
3461 for (i
= 0; i
<MAX_DONE
; i
++) {
3462 *p
++ =SCR_COPY (sizeof(struct ccb
*));
3463 *p
++ =NADDR (header
.cp
);
3464 *p
++ =NADDR (ccb_done
[i
]);
3466 *p
++ =PADDR (done_end
);
3469 BUG_ON((u_long
)p
!= (u_long
)&scrh
->done_queue
+sizeof(scrh
->done_queue
));
3471 #endif /* SCSI_NCR_CCB_DONE_SUPPORT */
3474 for (i
=0; i
<MAX_SCATTERH
; i
++) {
3475 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_IN
));
3476 *p
++ =PADDR (dispatch
);
3477 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_IN
;
3478 *p
++ =offsetof (struct dsb
, data
[i
]);
3481 BUG_ON((u_long
)p
!= (u_long
)&scrh
->hdata_in
+ sizeof (scrh
->hdata_in
));
3484 for (i
=MAX_SCATTERH
; i
<MAX_SCATTERH
+MAX_SCATTERL
; i
++) {
3485 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_IN
));
3486 *p
++ =PADDR (dispatch
);
3487 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_IN
;
3488 *p
++ =offsetof (struct dsb
, data
[i
]);
3491 BUG_ON((u_long
)p
!= (u_long
)&scr
->data_in
+ sizeof (scr
->data_in
));
3493 p
= scrh
->hdata_out
;
3494 for (i
=0; i
<MAX_SCATTERH
; i
++) {
3495 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_OUT
));
3496 *p
++ =PADDR (dispatch
);
3497 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_OUT
;
3498 *p
++ =offsetof (struct dsb
, data
[i
]);
3501 BUG_ON((u_long
)p
!= (u_long
)&scrh
->hdata_out
+ sizeof (scrh
->hdata_out
));
3504 for (i
=MAX_SCATTERH
; i
<MAX_SCATTERH
+MAX_SCATTERL
; i
++) {
3505 *p
++ =SCR_CALL
^ IFFALSE (WHEN (SCR_DATA_OUT
));
3506 *p
++ =PADDR (dispatch
);
3507 *p
++ =SCR_MOVE_TBL
^ SCR_DATA_OUT
;
3508 *p
++ =offsetof (struct dsb
, data
[i
]);
3511 BUG_ON((u_long
) p
!= (u_long
)&scr
->data_out
+ sizeof (scr
->data_out
));
3514 /*==========================================================
3517 ** Copy and rebind a script.
3520 **==========================================================
3524 ncr_script_copy_and_bind (struct ncb
*np
, ncrcmd
*src
, ncrcmd
*dst
, int len
)
3526 ncrcmd opcode
, new, old
, tmp1
, tmp2
;
3527 ncrcmd
*start
, *end
;
3537 *dst
++ = cpu_to_scr(opcode
);
3540 ** If we forget to change the length
3541 ** in struct script, a field will be
3542 ** padded with 0. This is an illegal
3547 printk (KERN_ERR
"%s: ERROR0 IN SCRIPT at %d.\n",
3548 ncr_name(np
), (int) (src
-start
-1));
3552 if (DEBUG_FLAGS
& DEBUG_SCRIPT
)
3553 printk (KERN_DEBUG
"%p: <%x>\n",
3554 (src
-1), (unsigned)opcode
);
3557 ** We don't have to decode ALL commands
3559 switch (opcode
>> 28) {
3563 ** COPY has TWO arguments.
3568 if ((tmp1
& RELOC_MASK
) == RELOC_KVAR
)
3573 if ((tmp2
& RELOC_MASK
) == RELOC_KVAR
)
3576 if ((tmp1
^ tmp2
) & 3) {
3577 printk (KERN_ERR
"%s: ERROR1 IN SCRIPT at %d.\n",
3578 ncr_name(np
), (int) (src
-start
-1));
3582 ** If PREFETCH feature not enabled, remove
3583 ** the NO FLUSH bit if present.
3585 if ((opcode
& SCR_NO_FLUSH
) && !(np
->features
& FE_PFEN
)) {
3586 dst
[-1] = cpu_to_scr(opcode
& ~SCR_NO_FLUSH
);
3593 ** MOVE (absolute address)
3601 ** don't relocate if relative :-)
3603 if (opcode
& 0x00800000)
3625 switch (old
& RELOC_MASK
) {
3626 case RELOC_REGISTER
:
3627 new = (old
& ~RELOC_MASK
) + np
->paddr
;
3630 new = (old
& ~RELOC_MASK
) + np
->p_script
;
3633 new = (old
& ~RELOC_MASK
) + np
->p_scripth
;
3636 new = (old
& ~RELOC_MASK
) + np
->p_ncb
;
3640 if (((old
& ~RELOC_MASK
) <
3641 SCRIPT_KVAR_FIRST
) ||
3642 ((old
& ~RELOC_MASK
) >
3644 panic("ncr KVAR out of range");
3645 new = vtophys(script_kvars
[old
&
3650 /* Don't relocate a 0 address. */
3657 panic("ncr_script_copy_and_bind: weird relocation %x\n", old
);
3661 *dst
++ = cpu_to_scr(new);
3664 *dst
++ = cpu_to_scr(*src
++);
3670 ** Linux host data structure
3677 #define PRINT_ADDR(cmd, arg...) dev_info(&cmd->device->sdev_gendev , ## arg)
3679 static void ncr_print_msg(struct ccb
*cp
, char *label
, u_char
*msg
)
3681 PRINT_ADDR(cp
->cmd
, "%s: ", label
);
3687 /*==========================================================
3689 ** NCR chip clock divisor table.
3690 ** Divisors are multiplied by 10,000,000 in order to make
3691 ** calculations more simple.
3693 **==========================================================
3697 static u_long div_10M
[] =
3698 {2*_5M
, 3*_5M
, 4*_5M
, 6*_5M
, 8*_5M
, 12*_5M
, 16*_5M
};
3701 /*===============================================================
3703 ** Prepare io register values used by ncr_init() according
3704 ** to selected and supported features.
3706 ** NCR chips allow burst lengths of 2, 4, 8, 16, 32, 64, 128
3707 ** transfers. 32,64,128 are only supported by 875 and 895 chips.
3708 ** We use log base 2 (burst length) as internal code, with
3709 ** value 0 meaning "burst disabled".
3711 **===============================================================
3715 * Burst length from burst code.
3717 #define burst_length(bc) (!(bc))? 0 : 1 << (bc)
3720 * Burst code from io register bits. Burst enable is ctest0 for c720
3722 #define burst_code(dmode, ctest0) \
3723 (ctest0) & 0x80 ? 0 : (((dmode) & 0xc0) >> 6) + 1
3726 * Set initial io register bits from burst code.
3728 static inline void ncr_init_burst(struct ncb
*np
, u_char bc
)
3730 u_char
*be
= &np
->rv_ctest0
;
3732 np
->rv_dmode
&= ~(0x3 << 6);
3733 np
->rv_ctest5
&= ~0x4;
3739 np
->rv_dmode
|= ((bc
& 0x3) << 6);
3740 np
->rv_ctest5
|= (bc
& 0x4);
3744 static void __init
ncr_prepare_setting(struct ncb
*np
)
3751 ** Save assumed BIOS setting
3754 np
->sv_scntl0
= INB(nc_scntl0
) & 0x0a;
3755 np
->sv_scntl3
= INB(nc_scntl3
) & 0x07;
3756 np
->sv_dmode
= INB(nc_dmode
) & 0xce;
3757 np
->sv_dcntl
= INB(nc_dcntl
) & 0xa8;
3758 np
->sv_ctest0
= INB(nc_ctest0
) & 0x84;
3759 np
->sv_ctest3
= INB(nc_ctest3
) & 0x01;
3760 np
->sv_ctest4
= INB(nc_ctest4
) & 0x80;
3761 np
->sv_ctest5
= INB(nc_ctest5
) & 0x24;
3762 np
->sv_gpcntl
= INB(nc_gpcntl
);
3763 np
->sv_stest2
= INB(nc_stest2
) & 0x20;
3764 np
->sv_stest4
= INB(nc_stest4
);
3770 np
->maxwide
= (np
->features
& FE_WIDE
)? 1 : 0;
3773 * Guess the frequency of the chip's clock.
3775 if (np
->features
& FE_ULTRA
)
3776 np
->clock_khz
= 80000;
3778 np
->clock_khz
= 40000;
3781 * Get the clock multiplier factor.
3783 if (np
->features
& FE_QUAD
)
3785 else if (np
->features
& FE_DBLR
)
3791 * Measure SCSI clock frequency for chips
3792 * it may vary from assumed one.
3794 if (np
->features
& FE_VARCLK
)
3795 ncr_getclock(np
, np
->multiplier
);
3798 * Divisor to be used for async (timer pre-scaler).
3800 i
= np
->clock_divn
- 1;
3802 if (10ul * SCSI_NCR_MIN_ASYNC
* np
->clock_khz
> div_10M
[i
]) {
3807 np
->rv_scntl3
= i
+1;
3810 * Minimum synchronous period factor supported by the chip.
3811 * Btw, 'period' is in tenths of nanoseconds.
3814 period
= (4 * div_10M
[0] + np
->clock_khz
- 1) / np
->clock_khz
;
3815 if (period
<= 250) np
->minsync
= 10;
3816 else if (period
<= 303) np
->minsync
= 11;
3817 else if (period
<= 500) np
->minsync
= 12;
3818 else np
->minsync
= (period
+ 40 - 1) / 40;
3821 * Check against chip SCSI standard support (SCSI-2,ULTRA,ULTRA2).
3824 if (np
->minsync
< 25 && !(np
->features
& FE_ULTRA
))
3828 * Maximum synchronous period factor supported by the chip.
3831 period
= (11 * div_10M
[np
->clock_divn
- 1]) / (4 * np
->clock_khz
);
3832 np
->maxsync
= period
> 2540 ? 254 : period
/ 10;
3835 ** Prepare initial value of other IO registers
3837 #if defined SCSI_NCR_TRUST_BIOS_SETTING
3838 np
->rv_scntl0
= np
->sv_scntl0
;
3839 np
->rv_dmode
= np
->sv_dmode
;
3840 np
->rv_dcntl
= np
->sv_dcntl
;
3841 np
->rv_ctest0
= np
->sv_ctest0
;
3842 np
->rv_ctest3
= np
->sv_ctest3
;
3843 np
->rv_ctest4
= np
->sv_ctest4
;
3844 np
->rv_ctest5
= np
->sv_ctest5
;
3845 burst_max
= burst_code(np
->sv_dmode
, np
->sv_ctest0
);
3849 ** Select burst length (dwords)
3851 burst_max
= driver_setup
.burst_max
;
3852 if (burst_max
== 255)
3853 burst_max
= burst_code(np
->sv_dmode
, np
->sv_ctest0
);
3856 if (burst_max
> np
->maxburst
)
3857 burst_max
= np
->maxburst
;
3860 ** Select all supported special features
3862 if (np
->features
& FE_ERL
)
3863 np
->rv_dmode
|= ERL
; /* Enable Read Line */
3864 if (np
->features
& FE_BOF
)
3865 np
->rv_dmode
|= BOF
; /* Burst Opcode Fetch */
3866 if (np
->features
& FE_ERMP
)
3867 np
->rv_dmode
|= ERMP
; /* Enable Read Multiple */
3868 if (np
->features
& FE_PFEN
)
3869 np
->rv_dcntl
|= PFEN
; /* Prefetch Enable */
3870 if (np
->features
& FE_CLSE
)
3871 np
->rv_dcntl
|= CLSE
; /* Cache Line Size Enable */
3872 if (np
->features
& FE_WRIE
)
3873 np
->rv_ctest3
|= WRIE
; /* Write and Invalidate */
3874 if (np
->features
& FE_DFS
)
3875 np
->rv_ctest5
|= DFS
; /* Dma Fifo Size */
3876 if (np
->features
& FE_MUX
)
3877 np
->rv_ctest4
|= MUX
; /* Host bus multiplex mode */
3878 if (np
->features
& FE_EA
)
3879 np
->rv_dcntl
|= EA
; /* Enable ACK */
3880 if (np
->features
& FE_EHP
)
3881 np
->rv_ctest0
|= EHP
; /* Even host parity */
3884 ** Select some other
3886 if (driver_setup
.master_parity
)
3887 np
->rv_ctest4
|= MPEE
; /* Master parity checking */
3888 if (driver_setup
.scsi_parity
)
3889 np
->rv_scntl0
|= 0x0a; /* full arb., ena parity, par->ATN */
3892 ** Get SCSI addr of host adapter (set by bios?).
3894 if (np
->myaddr
== 255) {
3895 np
->myaddr
= INB(nc_scid
) & 0x07;
3897 np
->myaddr
= SCSI_NCR_MYADDR
;
3900 #endif /* SCSI_NCR_TRUST_BIOS_SETTING */
3903 * Prepare initial io register bits for burst length
3905 ncr_init_burst(np
, burst_max
);
3908 ** Set SCSI BUS mode.
3910 ** - ULTRA2 chips (895/895A/896) report the current
3911 ** BUS mode through the STEST4 IO register.
3912 ** - For previous generation chips (825/825A/875),
3913 ** user has to tell us how to check against HVD,
3914 ** since a 100% safe algorithm is not possible.
3916 np
->scsi_mode
= SMODE_SE
;
3917 if (np
->features
& FE_DIFF
) {
3918 switch(driver_setup
.diff_support
) {
3919 case 4: /* Trust previous settings if present, then GPIO3 */
3920 if (np
->sv_scntl3
) {
3921 if (np
->sv_stest2
& 0x20)
3922 np
->scsi_mode
= SMODE_HVD
;
3925 case 3: /* SYMBIOS controllers report HVD through GPIO3 */
3926 if (INB(nc_gpreg
) & 0x08)
3928 case 2: /* Set HVD unconditionally */
3929 np
->scsi_mode
= SMODE_HVD
;
3930 case 1: /* Trust previous settings for HVD */
3931 if (np
->sv_stest2
& 0x20)
3932 np
->scsi_mode
= SMODE_HVD
;
3934 default:/* Don't care about HVD */
3938 if (np
->scsi_mode
== SMODE_HVD
)
3939 np
->rv_stest2
|= 0x20;
3942 ** Set LED support from SCRIPTS.
3943 ** Ignore this feature for boards known to use a
3944 ** specific GPIO wiring and for the 895A or 896
3945 ** that drive the LED directly.
3946 ** Also probe initial setting of GPIO0 as output.
3948 if ((driver_setup
.led_pin
) &&
3949 !(np
->features
& FE_LEDC
) && !(np
->sv_gpcntl
& 0x01))
3950 np
->features
|= FE_LED0
;
3955 switch(driver_setup
.irqm
& 3) {
3957 np
->rv_dcntl
|= IRQM
;
3960 np
->rv_dcntl
|= (np
->sv_dcntl
& IRQM
);
3967 ** Configure targets according to driver setup.
3968 ** Allow to override sync, wide and NOSCAN from
3969 ** boot command line.
3971 for (i
= 0 ; i
< MAX_TARGET
; i
++) {
3972 struct tcb
*tp
= &np
->target
[i
];
3974 tp
->usrsync
= driver_setup
.default_sync
;
3975 tp
->usrwide
= driver_setup
.max_wide
;
3976 tp
->usrtags
= MAX_TAGS
;
3977 tp
->period
= 0xffff;
3978 if (!driver_setup
.disconnection
)
3979 np
->target
[i
].usrflag
= UF_NODISC
;
3983 ** Announce all that stuff to user.
3986 printk(KERN_INFO
"%s: ID %d, Fast-%d%s%s\n", ncr_name(np
),
3988 np
->minsync
< 12 ? 40 : (np
->minsync
< 25 ? 20 : 10),
3989 (np
->rv_scntl0
& 0xa) ? ", Parity Checking" : ", NO Parity",
3990 (np
->rv_stest2
& 0x20) ? ", Differential" : "");
3992 if (bootverbose
> 1) {
3993 printk (KERN_INFO
"%s: initial SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
3994 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
3995 ncr_name(np
), np
->sv_scntl3
, np
->sv_dmode
, np
->sv_dcntl
,
3996 np
->sv_ctest3
, np
->sv_ctest4
, np
->sv_ctest5
);
3998 printk (KERN_INFO
"%s: final SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
3999 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
4000 ncr_name(np
), np
->rv_scntl3
, np
->rv_dmode
, np
->rv_dcntl
,
4001 np
->rv_ctest3
, np
->rv_ctest4
, np
->rv_ctest5
);
4004 if (bootverbose
&& np
->paddr2
)
4005 printk (KERN_INFO
"%s: on-chip RAM at 0x%lx\n",
4006 ncr_name(np
), np
->paddr2
);
4009 /*==========================================================
4012 ** Done SCSI commands list management.
4014 ** We donnot enter the scsi_done() callback immediately
4015 ** after a command has been seen as completed but we
4016 ** insert it into a list which is flushed outside any kind
4017 ** of driver critical section.
4018 ** This allows to do minimal stuff under interrupt and
4019 ** inside critical sections and to also avoid locking up
4020 ** on recursive calls to driver entry points under SMP.
4021 ** In fact, the only kernel point which is entered by the
4022 ** driver with a driver lock set is kmalloc(GFP_ATOMIC)
4023 ** that shall not reenter the driver under any circumstances,
4026 **==========================================================
4028 static inline void ncr_queue_done_cmd(struct ncb
*np
, struct scsi_cmnd
*cmd
)
4030 unmap_scsi_data(np
, cmd
);
4031 cmd
->host_scribble
= (char *) np
->done_list
;
4032 np
->done_list
= cmd
;
4035 static inline void ncr_flush_done_cmds(struct scsi_cmnd
*lcmd
)
4037 struct scsi_cmnd
*cmd
;
4041 lcmd
= (struct scsi_cmnd
*) cmd
->host_scribble
;
4042 cmd
->scsi_done(cmd
);
4046 /*==========================================================
4049 ** Prepare the next negotiation message if needed.
4051 ** Fill in the part of message buffer that contains the
4052 ** negotiation and the nego_status field of the CCB.
4053 ** Returns the size of the message in bytes.
4056 **==========================================================
4060 static int ncr_prepare_nego(struct ncb
*np
, struct ccb
*cp
, u_char
*msgptr
)
4062 struct tcb
*tp
= &np
->target
[cp
->target
];
4065 struct scsi_target
*starget
= tp
->starget
;
4067 /* negotiate wide transfers ? */
4068 if (!tp
->widedone
) {
4069 if (spi_support_wide(starget
)) {
4075 /* negotiate synchronous transfers? */
4076 if (!nego
&& !tp
->period
) {
4077 if (spi_support_sync(starget
)) {
4081 dev_info(&starget
->dev
, "target did not report SYNC.\n");
4087 msglen
+= spi_populate_sync_msg(msgptr
+ msglen
,
4088 tp
->maxoffs
? tp
->minsync
: 0, tp
->maxoffs
);
4091 msglen
+= spi_populate_width_msg(msgptr
+ msglen
, tp
->usrwide
);
4095 cp
->nego_status
= nego
;
4099 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
4100 ncr_print_msg(cp
, nego
== NS_WIDE
?
4101 "wide msgout":"sync_msgout", msgptr
);
4110 /*==========================================================
4113 ** Start execution of a SCSI command.
4114 ** This is called from the generic SCSI driver.
4117 **==========================================================
4119 static int ncr_queue_command (struct ncb
*np
, struct scsi_cmnd
*cmd
)
4121 struct scsi_device
*sdev
= cmd
->device
;
4122 struct tcb
*tp
= &np
->target
[sdev
->id
];
4123 struct lcb
*lp
= tp
->lp
[sdev
->lun
];
4127 u_char idmsg
, *msgptr
;
4132 /*---------------------------------------------
4134 ** Some shortcuts ...
4136 **---------------------------------------------
4138 if ((sdev
->id
== np
->myaddr
) ||
4139 (sdev
->id
>= MAX_TARGET
) ||
4140 (sdev
->lun
>= MAX_LUN
)) {
4141 return(DID_BAD_TARGET
);
4144 /*---------------------------------------------
4146 ** Complete the 1st TEST UNIT READY command
4147 ** with error condition if the device is
4148 ** flagged NOSCAN, in order to speed up
4151 **---------------------------------------------
4153 if ((cmd
->cmnd
[0] == 0 || cmd
->cmnd
[0] == 0x12) &&
4154 (tp
->usrflag
& UF_NOSCAN
)) {
4155 tp
->usrflag
&= ~UF_NOSCAN
;
4156 return DID_BAD_TARGET
;
4159 if (DEBUG_FLAGS
& DEBUG_TINY
) {
4160 PRINT_ADDR(cmd
, "CMD=%x ", cmd
->cmnd
[0]);
4163 /*---------------------------------------------------
4165 ** Assign a ccb / bind cmd.
4166 ** If resetting, shorten settle_time if necessary
4167 ** in order to avoid spurious timeouts.
4168 ** If resetting or no free ccb,
4169 ** insert cmd into the waiting list.
4171 **----------------------------------------------------
4173 if (np
->settle_time
&& cmd
->timeout_per_command
>= HZ
) {
4174 u_long tlimit
= jiffies
+ cmd
->timeout_per_command
- HZ
;
4175 if (time_after(np
->settle_time
, tlimit
))
4176 np
->settle_time
= tlimit
;
4179 if (np
->settle_time
|| !(cp
=ncr_get_ccb (np
, cmd
))) {
4180 insert_into_waiting_list(np
, cmd
);
4185 /*----------------------------------------------------
4187 ** Build the identify / tag / sdtr message
4189 **----------------------------------------------------
4192 idmsg
= IDENTIFY(0, sdev
->lun
);
4194 if (cp
->tag
!= NO_TAG
||
4195 (cp
!= np
->ccb
&& np
->disc
&& !(tp
->usrflag
& UF_NODISC
)))
4198 msgptr
= cp
->scsi_smsg
;
4200 msgptr
[msglen
++] = idmsg
;
4202 if (cp
->tag
!= NO_TAG
) {
4203 char order
= np
->order
;
4206 ** Force ordered tag if necessary to avoid timeouts
4207 ** and to preserve interactivity.
4209 if (lp
&& time_after(jiffies
, lp
->tags_stime
)) {
4210 if (lp
->tags_smap
) {
4211 order
= ORDERED_QUEUE_TAG
;
4212 if ((DEBUG_FLAGS
& DEBUG_TAGS
)||bootverbose
>2){
4214 "ordered tag forced.\n");
4217 lp
->tags_stime
= jiffies
+ 3*HZ
;
4218 lp
->tags_smap
= lp
->tags_umap
;
4223 ** Ordered write ops, unordered read ops.
4225 switch (cmd
->cmnd
[0]) {
4226 case 0x08: /* READ_SMALL (6) */
4227 case 0x28: /* READ_BIG (10) */
4228 case 0xa8: /* READ_HUGE (12) */
4229 order
= SIMPLE_QUEUE_TAG
;
4232 order
= ORDERED_QUEUE_TAG
;
4235 msgptr
[msglen
++] = order
;
4237 ** Actual tags are numbered 1,3,5,..2*MAXTAGS+1,
4238 ** since we may have to deal with devices that have
4239 ** problems with #TAG 0 or too great #TAG numbers.
4241 msgptr
[msglen
++] = (cp
->tag
<< 1) + 1;
4244 /*----------------------------------------------------
4246 ** Build the data descriptors
4248 **----------------------------------------------------
4251 direction
= cmd
->sc_data_direction
;
4252 if (direction
!= DMA_NONE
) {
4253 segments
= ncr_scatter(np
, cp
, cp
->cmd
);
4255 ncr_free_ccb(np
, cp
);
4264 /*---------------------------------------------------
4266 ** negotiation required?
4268 ** (nego_status is filled by ncr_prepare_nego())
4270 **---------------------------------------------------
4273 cp
->nego_status
= 0;
4275 if ((!tp
->widedone
|| !tp
->period
) && !tp
->nego_cp
&& lp
) {
4276 msglen
+= ncr_prepare_nego (np
, cp
, msgptr
+ msglen
);
4279 /*----------------------------------------------------
4281 ** Determine xfer direction.
4283 **----------------------------------------------------
4286 direction
= DMA_NONE
;
4289 ** If data direction is BIDIRECTIONAL, speculate FROM_DEVICE
4290 ** but prepare alternate pointers for TO_DEVICE in case
4291 ** of our speculation will be just wrong.
4292 ** SCRIPTS will swap values if needed.
4295 case DMA_BIDIRECTIONAL
:
4297 goalp
= NCB_SCRIPT_PHYS (np
, data_out2
) + 8;
4298 if (segments
<= MAX_SCATTERL
)
4299 lastp
= goalp
- 8 - (segments
* 16);
4301 lastp
= NCB_SCRIPTH_PHYS (np
, hdata_out2
);
4302 lastp
-= (segments
- MAX_SCATTERL
) * 16;
4304 if (direction
!= DMA_BIDIRECTIONAL
)
4306 cp
->phys
.header
.wgoalp
= cpu_to_scr(goalp
);
4307 cp
->phys
.header
.wlastp
= cpu_to_scr(lastp
);
4309 case DMA_FROM_DEVICE
:
4310 goalp
= NCB_SCRIPT_PHYS (np
, data_in2
) + 8;
4311 if (segments
<= MAX_SCATTERL
)
4312 lastp
= goalp
- 8 - (segments
* 16);
4314 lastp
= NCB_SCRIPTH_PHYS (np
, hdata_in2
);
4315 lastp
-= (segments
- MAX_SCATTERL
) * 16;
4320 lastp
= goalp
= NCB_SCRIPT_PHYS (np
, no_data
);
4325 ** Set all pointers values needed by SCRIPTS.
4326 ** If direction is unknown, start at data_io.
4328 cp
->phys
.header
.lastp
= cpu_to_scr(lastp
);
4329 cp
->phys
.header
.goalp
= cpu_to_scr(goalp
);
4331 if (direction
== DMA_BIDIRECTIONAL
)
4332 cp
->phys
.header
.savep
=
4333 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, data_io
));
4335 cp
->phys
.header
.savep
= cpu_to_scr(lastp
);
4338 ** Save the initial data pointer in order to be able
4339 ** to redo the command.
4341 cp
->startp
= cp
->phys
.header
.savep
;
4343 /*----------------------------------------------------
4347 **----------------------------------------------------
4350 ** physical -> virtual backlink
4351 ** Generic SCSI command
4357 cp
->start
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, select
));
4358 cp
->restart
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, resel_dsa
));
4362 cp
->phys
.select
.sel_id
= sdev_id(sdev
);
4363 cp
->phys
.select
.sel_scntl3
= tp
->wval
;
4364 cp
->phys
.select
.sel_sxfer
= tp
->sval
;
4368 cp
->phys
.smsg
.addr
= cpu_to_scr(CCB_PHYS (cp
, scsi_smsg
));
4369 cp
->phys
.smsg
.size
= cpu_to_scr(msglen
);
4374 memcpy(cp
->cdb_buf
, cmd
->cmnd
, min_t(int, cmd
->cmd_len
, sizeof(cp
->cdb_buf
)));
4375 cp
->phys
.cmd
.addr
= cpu_to_scr(CCB_PHYS (cp
, cdb_buf
[0]));
4376 cp
->phys
.cmd
.size
= cpu_to_scr(cmd
->cmd_len
);
4381 cp
->actualquirks
= 0;
4382 cp
->host_status
= cp
->nego_status
? HS_NEGOTIATE
: HS_BUSY
;
4383 cp
->scsi_status
= S_ILLEGAL
;
4384 cp
->parity_status
= 0;
4386 cp
->xerr_status
= XE_OK
;
4388 cp
->sync_status
= tp
->sval
;
4389 cp
->wide_status
= tp
->wval
;
4392 /*----------------------------------------------------
4394 ** Critical region: start this job.
4396 **----------------------------------------------------
4399 /* activate this job. */
4400 cp
->magic
= CCB_MAGIC
;
4403 ** insert next CCBs into start queue.
4404 ** 2 max at a time is enough to flush the CCB wait queue.
4408 ncr_start_next_ccb(np
, lp
, 2);
4410 ncr_put_start_queue(np
, cp
);
4412 /* Command is successfully queued. */
4418 /*==========================================================
4421 ** Insert a CCB into the start queue and wake up the
4422 ** SCRIPTS processor.
4425 **==========================================================
4428 static void ncr_start_next_ccb(struct ncb
*np
, struct lcb
*lp
, int maxn
)
4430 struct list_head
*qp
;
4436 while (maxn
-- && lp
->queuedccbs
< lp
->queuedepth
) {
4437 qp
= ncr_list_pop(&lp
->wait_ccbq
);
4441 cp
= list_entry(qp
, struct ccb
, link_ccbq
);
4442 list_add_tail(qp
, &lp
->busy_ccbq
);
4443 lp
->jump_ccb
[cp
->tag
== NO_TAG
? 0 : cp
->tag
] =
4444 cpu_to_scr(CCB_PHYS (cp
, restart
));
4445 ncr_put_start_queue(np
, cp
);
4449 static void ncr_put_start_queue(struct ncb
*np
, struct ccb
*cp
)
4454 ** insert into start queue.
4456 if (!np
->squeueput
) np
->squeueput
= 1;
4457 qidx
= np
->squeueput
+ 2;
4458 if (qidx
>= MAX_START
+ MAX_START
) qidx
= 1;
4460 np
->scripth
->tryloop
[qidx
] = cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
4462 np
->scripth
->tryloop
[np
->squeueput
] = cpu_to_scr(CCB_PHYS (cp
, start
));
4464 np
->squeueput
= qidx
;
4468 if (DEBUG_FLAGS
& DEBUG_QUEUE
)
4469 printk ("%s: queuepos=%d.\n", ncr_name (np
), np
->squeueput
);
4472 ** Script processor may be waiting for reselect.
4476 OUTB (nc_istat
, SIGP
);
4480 static int ncr_reset_scsi_bus(struct ncb
*np
, int enab_int
, int settle_delay
)
4485 np
->settle_time
= jiffies
+ settle_delay
* HZ
;
4487 if (bootverbose
> 1)
4488 printk("%s: resetting, "
4489 "command processing suspended for %d seconds\n",
4490 ncr_name(np
), settle_delay
);
4492 ncr_chip_reset(np
, 100);
4493 udelay(2000); /* The 895 needs time for the bus mode to settle */
4495 OUTW (nc_sien
, RST
);
4497 ** Enable Tolerant, reset IRQD if present and
4498 ** properly set IRQ mode, prior to resetting the bus.
4500 OUTB (nc_stest3
, TE
);
4501 OUTB (nc_scntl1
, CRST
);
4504 if (!driver_setup
.bus_check
)
4507 ** Check for no terminators or SCSI bus shorts to ground.
4508 ** Read SCSI data bus, data parity bits and control signals.
4509 ** We are expecting RESET to be TRUE and other signals to be
4513 term
= INB(nc_sstat0
);
4514 term
= ((term
& 2) << 7) + ((term
& 1) << 17); /* rst sdp0 */
4515 term
|= ((INB(nc_sstat2
) & 0x01) << 26) | /* sdp1 */
4516 ((INW(nc_sbdl
) & 0xff) << 9) | /* d7-0 */
4517 ((INW(nc_sbdl
) & 0xff00) << 10) | /* d15-8 */
4518 INB(nc_sbcl
); /* req ack bsy sel atn msg cd io */
4520 if (!(np
->features
& FE_WIDE
))
4523 if (term
!= (2<<7)) {
4524 printk("%s: suspicious SCSI data while resetting the BUS.\n",
4526 printk("%s: %sdp0,d7-0,rst,req,ack,bsy,sel,atn,msg,c/d,i/o = "
4527 "0x%lx, expecting 0x%lx\n",
4529 (np
->features
& FE_WIDE
) ? "dp1,d15-8," : "",
4530 (u_long
)term
, (u_long
)(2<<7));
4531 if (driver_setup
.bus_check
== 1)
4535 OUTB (nc_scntl1
, 0);
4540 * Start reset process.
4541 * If reset in progress do nothing.
4542 * The interrupt handler will reinitialize the chip.
4543 * The timeout handler will wait for settle_time before
4544 * clearing it and so resuming command processing.
4546 static void ncr_start_reset(struct ncb
*np
)
4548 if (!np
->settle_time
) {
4549 ncr_reset_scsi_bus(np
, 1, driver_setup
.settle_delay
);
4553 /*==========================================================
4556 ** Reset the SCSI BUS.
4557 ** This is called from the generic SCSI driver.
4560 **==========================================================
4562 static int ncr_reset_bus (struct ncb
*np
, struct scsi_cmnd
*cmd
, int sync_reset
)
4564 /* struct scsi_device *device = cmd->device; */
4569 * Return immediately if reset is in progress.
4571 if (np
->settle_time
) {
4575 * Start the reset process.
4576 * The script processor is then assumed to be stopped.
4577 * Commands will now be queued in the waiting list until a settle
4578 * delay of 2 seconds will be completed.
4580 ncr_start_reset(np
);
4582 * First, look in the wakeup list
4584 for (found
=0, cp
=np
->ccb
; cp
; cp
=cp
->link_ccb
) {
4586 ** look for the ccb of this command.
4588 if (cp
->host_status
== HS_IDLE
) continue;
4589 if (cp
->cmd
== cmd
) {
4595 * Then, look in the waiting list
4597 if (!found
&& retrieve_from_waiting_list(0, np
, cmd
))
4600 * Wake-up all awaiting commands with DID_RESET.
4602 reset_waiting_list(np
);
4604 * Wake-up all pending commands with HS_RESET -> DID_RESET.
4606 ncr_wakeup(np
, HS_RESET
);
4608 * If the involved command was not in a driver queue, and the
4609 * scsi driver told us reset is synchronous, and the command is not
4610 * currently in the waiting list, complete it with DID_RESET status,
4611 * in order to keep it alive.
4613 if (!found
&& sync_reset
&& !retrieve_from_waiting_list(0, np
, cmd
)) {
4614 cmd
->result
= ScsiResult(DID_RESET
, 0);
4615 ncr_queue_done_cmd(np
, cmd
);
4621 #if 0 /* unused and broken.. */
4622 /*==========================================================
4625 ** Abort an SCSI command.
4626 ** This is called from the generic SCSI driver.
4629 **==========================================================
4631 static int ncr_abort_command (struct ncb
*np
, struct scsi_cmnd
*cmd
)
4633 /* struct scsi_device *device = cmd->device; */
4639 * First, look for the scsi command in the waiting list
4641 if (remove_from_waiting_list(np
, cmd
)) {
4642 cmd
->result
= ScsiResult(DID_ABORT
, 0);
4643 ncr_queue_done_cmd(np
, cmd
);
4644 return SCSI_ABORT_SUCCESS
;
4648 * Then, look in the wakeup list
4650 for (found
=0, cp
=np
->ccb
; cp
; cp
=cp
->link_ccb
) {
4652 ** look for the ccb of this command.
4654 if (cp
->host_status
== HS_IDLE
) continue;
4655 if (cp
->cmd
== cmd
) {
4662 return SCSI_ABORT_NOT_RUNNING
;
4665 if (np
->settle_time
) {
4666 return SCSI_ABORT_SNOOZE
;
4670 ** If the CCB is active, patch schedule jumps for the
4671 ** script to abort the command.
4674 switch(cp
->host_status
) {
4677 printk ("%s: abort ccb=%p (cancel)\n", ncr_name (np
), cp
);
4678 cp
->start
.schedule
.l_paddr
=
4679 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, cancel
));
4680 retv
= SCSI_ABORT_PENDING
;
4683 cp
->restart
.schedule
.l_paddr
=
4684 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, abort
));
4685 retv
= SCSI_ABORT_PENDING
;
4688 retv
= SCSI_ABORT_NOT_RUNNING
;
4694 ** If there are no requests, the script
4695 ** processor will sleep on SEL_WAIT_RESEL.
4696 ** Let's wake it up, since it may have to work.
4698 OUTB (nc_istat
, SIGP
);
4704 static void ncr_detach(struct ncb
*np
)
4713 /* Local copy so we don't access np after freeing it! */
4714 strlcpy(inst_name
, ncr_name(np
), sizeof(inst_name
));
4716 printk("%s: releasing host resources\n", ncr_name(np
));
4719 ** Stop the ncr_timeout process
4720 ** Set release_stage to 1 and wait that ncr_timeout() set it to 2.
4723 #ifdef DEBUG_NCR53C8XX
4724 printk("%s: stopping the timer\n", ncr_name(np
));
4726 np
->release_stage
= 1;
4727 for (i
= 50 ; i
&& np
->release_stage
!= 2 ; i
--)
4729 if (np
->release_stage
!= 2)
4730 printk("%s: the timer seems to be already stopped\n", ncr_name(np
));
4731 else np
->release_stage
= 2;
4734 ** Disable chip interrupts
4737 #ifdef DEBUG_NCR53C8XX
4738 printk("%s: disabling chip interrupts\n", ncr_name(np
));
4745 ** Restore bios setting for automatic clock detection.
4748 printk("%s: resetting chip\n", ncr_name(np
));
4749 ncr_chip_reset(np
, 100);
4751 OUTB(nc_dmode
, np
->sv_dmode
);
4752 OUTB(nc_dcntl
, np
->sv_dcntl
);
4753 OUTB(nc_ctest0
, np
->sv_ctest0
);
4754 OUTB(nc_ctest3
, np
->sv_ctest3
);
4755 OUTB(nc_ctest4
, np
->sv_ctest4
);
4756 OUTB(nc_ctest5
, np
->sv_ctest5
);
4757 OUTB(nc_gpcntl
, np
->sv_gpcntl
);
4758 OUTB(nc_stest2
, np
->sv_stest2
);
4760 ncr_selectclock(np
, np
->sv_scntl3
);
4763 ** Free allocated ccb(s)
4766 while ((cp
=np
->ccb
->link_ccb
) != NULL
) {
4767 np
->ccb
->link_ccb
= cp
->link_ccb
;
4768 if (cp
->host_status
) {
4769 printk("%s: shall free an active ccb (host_status=%d)\n",
4770 ncr_name(np
), cp
->host_status
);
4772 #ifdef DEBUG_NCR53C8XX
4773 printk("%s: freeing ccb (%lx)\n", ncr_name(np
), (u_long
) cp
);
4775 m_free_dma(cp
, sizeof(*cp
), "CCB");
4778 /* Free allocated tp(s) */
4780 for (target
= 0; target
< MAX_TARGET
; target
++) {
4781 tp
=&np
->target
[target
];
4782 for (lun
= 0 ; lun
< MAX_LUN
; lun
++) {
4785 #ifdef DEBUG_NCR53C8XX
4786 printk("%s: freeing lp (%lx)\n", ncr_name(np
), (u_long
) lp
);
4788 if (lp
->jump_ccb
!= &lp
->jump_ccb_0
)
4789 m_free_dma(lp
->jump_ccb
,256,"JUMP_CCB");
4790 m_free_dma(lp
, sizeof(*lp
), "LCB");
4796 m_free_dma(np
->scripth0
, sizeof(struct scripth
), "SCRIPTH");
4798 m_free_dma(np
->script0
, sizeof(struct script
), "SCRIPT");
4800 m_free_dma(np
->ccb
, sizeof(struct ccb
), "CCB");
4801 m_free_dma(np
, sizeof(struct ncb
), "NCB");
4803 printk("%s: host resources successfully released\n", inst_name
);
4806 /*==========================================================
4809 ** Complete execution of a SCSI command.
4810 ** Signal completion to the generic SCSI driver.
4813 **==========================================================
4816 void ncr_complete (struct ncb
*np
, struct ccb
*cp
)
4818 struct scsi_cmnd
*cmd
;
4826 if (!cp
|| cp
->magic
!= CCB_MAGIC
|| !cp
->cmd
)
4830 ** Print minimal debug information.
4833 if (DEBUG_FLAGS
& DEBUG_TINY
)
4834 printk ("CCB=%lx STAT=%x/%x\n", (unsigned long)cp
,
4835 cp
->host_status
,cp
->scsi_status
);
4838 ** Get command, target and lun pointers.
4843 tp
= &np
->target
[cmd
->device
->id
];
4844 lp
= tp
->lp
[cmd
->device
->lun
];
4847 ** We donnot queue more than 1 ccb per target
4848 ** with negotiation at any time. If this ccb was
4849 ** used for negotiation, clear this info in the tcb.
4852 if (cp
== tp
->nego_cp
)
4856 ** If auto-sense performed, change scsi status.
4858 if (cp
->auto_sense
) {
4859 cp
->scsi_status
= cp
->auto_sense
;
4863 ** If we were recovering from queue full or performing
4864 ** auto-sense, requeue skipped CCBs to the wait queue.
4867 if (lp
&& lp
->held_ccb
) {
4868 if (cp
== lp
->held_ccb
) {
4869 list_splice_init(&lp
->skip_ccbq
, &lp
->wait_ccbq
);
4870 lp
->held_ccb
= NULL
;
4875 ** Check for parity errors.
4878 if (cp
->parity_status
> 1) {
4879 PRINT_ADDR(cmd
, "%d parity error(s).\n",cp
->parity_status
);
4883 ** Check for extended errors.
4886 if (cp
->xerr_status
!= XE_OK
) {
4887 switch (cp
->xerr_status
) {
4889 PRINT_ADDR(cmd
, "extraneous data discarded.\n");
4892 PRINT_ADDR(cmd
, "invalid scsi phase (4/5).\n");
4895 PRINT_ADDR(cmd
, "extended error %d.\n",
4899 if (cp
->host_status
==HS_COMPLETE
)
4900 cp
->host_status
= HS_FAIL
;
4904 ** Print out any error for debugging purpose.
4906 if (DEBUG_FLAGS
& (DEBUG_RESULT
|DEBUG_TINY
)) {
4907 if (cp
->host_status
!=HS_COMPLETE
|| cp
->scsi_status
!=S_GOOD
) {
4908 PRINT_ADDR(cmd
, "ERROR: cmd=%x host_status=%x "
4909 "scsi_status=%x\n", cmd
->cmnd
[0],
4910 cp
->host_status
, cp
->scsi_status
);
4915 ** Check the status.
4917 if ( (cp
->host_status
== HS_COMPLETE
)
4918 && (cp
->scsi_status
== S_GOOD
||
4919 cp
->scsi_status
== S_COND_MET
)) {
4921 * All went well (GOOD status).
4922 * CONDITION MET status is returned on
4923 * `Pre-Fetch' or `Search data' success.
4925 cmd
->result
= ScsiResult(DID_OK
, cp
->scsi_status
);
4929 ** Could dig out the correct value for resid,
4930 ** but it would be quite complicated.
4932 /* if (cp->phys.header.lastp != cp->phys.header.goalp) */
4935 ** Allocate the lcb if not yet.
4938 ncr_alloc_lcb (np
, cmd
->device
->id
, cmd
->device
->lun
);
4940 tp
->bytes
+= cp
->data_len
;
4944 ** If tags was reduced due to queue full,
4945 ** increase tags if 1000 good status received.
4947 if (lp
&& lp
->usetags
&& lp
->numtags
< lp
->maxtags
) {
4949 if (lp
->num_good
>= 1000) {
4952 ncr_setup_tags (np
, cmd
->device
);
4955 } else if ((cp
->host_status
== HS_COMPLETE
)
4956 && (cp
->scsi_status
== S_CHECK_COND
)) {
4958 ** Check condition code
4960 cmd
->result
= ScsiResult(DID_OK
, S_CHECK_COND
);
4963 ** Copy back sense data to caller's buffer.
4965 memcpy(cmd
->sense_buffer
, cp
->sense_buf
,
4966 min(sizeof(cmd
->sense_buffer
), sizeof(cp
->sense_buf
)));
4968 if (DEBUG_FLAGS
& (DEBUG_RESULT
|DEBUG_TINY
)) {
4969 u_char
* p
= (u_char
*) & cmd
->sense_buffer
;
4971 PRINT_ADDR(cmd
, "sense data:");
4972 for (i
=0; i
<14; i
++) printk (" %x", *p
++);
4975 } else if ((cp
->host_status
== HS_COMPLETE
)
4976 && (cp
->scsi_status
== S_CONFLICT
)) {
4978 ** Reservation Conflict condition code
4980 cmd
->result
= ScsiResult(DID_OK
, S_CONFLICT
);
4982 } else if ((cp
->host_status
== HS_COMPLETE
)
4983 && (cp
->scsi_status
== S_BUSY
||
4984 cp
->scsi_status
== S_QUEUE_FULL
)) {
4989 cmd
->result
= ScsiResult(DID_OK
, cp
->scsi_status
);
4991 } else if ((cp
->host_status
== HS_SEL_TIMEOUT
)
4992 || (cp
->host_status
== HS_TIMEOUT
)) {
4997 cmd
->result
= ScsiResult(DID_TIME_OUT
, cp
->scsi_status
);
4999 } else if (cp
->host_status
== HS_RESET
) {
5004 cmd
->result
= ScsiResult(DID_RESET
, cp
->scsi_status
);
5006 } else if (cp
->host_status
== HS_ABORTED
) {
5011 cmd
->result
= ScsiResult(DID_ABORT
, cp
->scsi_status
);
5016 ** Other protocol messes
5018 PRINT_ADDR(cmd
, "COMMAND FAILED (%x %x) @%p.\n",
5019 cp
->host_status
, cp
->scsi_status
, cp
);
5021 cmd
->result
= ScsiResult(DID_ERROR
, cp
->scsi_status
);
5028 if (tp
->usrflag
& UF_TRACE
) {
5031 PRINT_ADDR(cmd
, " CMD:");
5032 p
= (u_char
*) &cmd
->cmnd
[0];
5033 for (i
=0; i
<cmd
->cmd_len
; i
++) printk (" %x", *p
++);
5035 if (cp
->host_status
==HS_COMPLETE
) {
5036 switch (cp
->scsi_status
) {
5042 p
= (u_char
*) &cmd
->sense_buffer
;
5043 for (i
=0; i
<14; i
++)
5044 printk (" %x", *p
++);
5047 printk (" STAT: %x\n", cp
->scsi_status
);
5050 } else printk (" HOSTERROR: %x", cp
->host_status
);
5057 ncr_free_ccb (np
, cp
);
5060 ** requeue awaiting scsi commands for this lun.
5062 if (lp
&& lp
->queuedccbs
< lp
->queuedepth
&&
5063 !list_empty(&lp
->wait_ccbq
))
5064 ncr_start_next_ccb(np
, lp
, 2);
5067 ** requeue awaiting scsi commands for this controller.
5069 if (np
->waiting_list
)
5070 requeue_waiting_list(np
);
5073 ** signal completion to generic driver.
5075 ncr_queue_done_cmd(np
, cmd
);
5078 /*==========================================================
5081 ** Signal all (or one) control block done.
5084 **==========================================================
5088 ** This CCB has been skipped by the NCR.
5089 ** Queue it in the corresponding unit queue.
5091 static void ncr_ccb_skipped(struct ncb
*np
, struct ccb
*cp
)
5093 struct tcb
*tp
= &np
->target
[cp
->target
];
5094 struct lcb
*lp
= tp
->lp
[cp
->lun
];
5096 if (lp
&& cp
!= np
->ccb
) {
5097 cp
->host_status
&= ~HS_SKIPMASK
;
5098 cp
->start
.schedule
.l_paddr
=
5099 cpu_to_scr(NCB_SCRIPT_PHYS (np
, select
));
5100 list_move_tail(&cp
->link_ccbq
, &lp
->skip_ccbq
);
5112 ** The NCR has completed CCBs.
5113 ** Look at the DONE QUEUE if enabled, otherwise scan all CCBs
5115 void ncr_wakeup_done (struct ncb
*np
)
5118 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
5121 i
= np
->ccb_done_ic
;
5127 cp
= np
->ccb_done
[j
];
5128 if (!CCB_DONE_VALID(cp
))
5131 np
->ccb_done
[j
] = (struct ccb
*)CCB_DONE_EMPTY
;
5132 np
->scripth
->done_queue
[5*j
+ 4] =
5133 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_plug
));
5135 np
->scripth
->done_queue
[5*i
+ 4] =
5136 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_end
));
5138 if (cp
->host_status
& HS_DONEMASK
)
5139 ncr_complete (np
, cp
);
5140 else if (cp
->host_status
& HS_SKIPMASK
)
5141 ncr_ccb_skipped (np
, cp
);
5145 np
->ccb_done_ic
= i
;
5149 if (cp
->host_status
& HS_DONEMASK
)
5150 ncr_complete (np
, cp
);
5151 else if (cp
->host_status
& HS_SKIPMASK
)
5152 ncr_ccb_skipped (np
, cp
);
5159 ** Complete all active CCBs.
5161 void ncr_wakeup (struct ncb
*np
, u_long code
)
5163 struct ccb
*cp
= np
->ccb
;
5166 if (cp
->host_status
!= HS_IDLE
) {
5167 cp
->host_status
= code
;
5168 ncr_complete (np
, cp
);
5178 /* Some initialisation must be done immediately following reset, for 53c720,
5179 * at least. EA (dcntl bit 5) isn't set here as it is set once only in
5180 * the _detect function.
5182 static void ncr_chip_reset(struct ncb
*np
, int delay
)
5184 OUTB (nc_istat
, SRST
);
5186 OUTB (nc_istat
, 0 );
5188 if (np
->features
& FE_EHP
)
5189 OUTB (nc_ctest0
, EHP
);
5190 if (np
->features
& FE_MUX
)
5191 OUTB (nc_ctest4
, MUX
);
5195 /*==========================================================
5201 **==========================================================
5204 void ncr_init (struct ncb
*np
, int reset
, char * msg
, u_long code
)
5209 ** Reset chip if asked, otherwise just clear fifos.
5213 OUTB (nc_istat
, SRST
);
5217 OUTB (nc_stest3
, TE
|CSF
);
5218 OUTONB (nc_ctest3
, CLF
);
5225 if (msg
) printk (KERN_INFO
"%s: restart (%s).\n", ncr_name (np
), msg
);
5228 ** Clear Start Queue
5230 np
->queuedepth
= MAX_START
- 1; /* 1 entry needed as end marker */
5231 for (i
= 1; i
< MAX_START
+ MAX_START
; i
+= 2)
5232 np
->scripth0
->tryloop
[i
] =
5233 cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
5236 ** Start at first entry.
5239 np
->script0
->startpos
[0] = cpu_to_scr(NCB_SCRIPTH_PHYS (np
, tryloop
));
5241 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
5245 for (i
= 0; i
< MAX_DONE
; i
++) {
5246 np
->ccb_done
[i
] = (struct ccb
*)CCB_DONE_EMPTY
;
5247 np
->scripth0
->done_queue
[5*i
+ 4] =
5248 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_end
));
5253 ** Start at first entry.
5255 np
->script0
->done_pos
[0] = cpu_to_scr(NCB_SCRIPTH_PHYS (np
,done_queue
));
5256 np
->ccb_done_ic
= MAX_DONE
-1;
5257 np
->scripth0
->done_queue
[5*(MAX_DONE
-1) + 4] =
5258 cpu_to_scr(NCB_SCRIPT_PHYS (np
, done_plug
));
5261 ** Wakeup all pending jobs.
5263 ncr_wakeup (np
, code
);
5270 ** Remove reset; big delay because the 895 needs time for the
5271 ** bus mode to settle
5273 ncr_chip_reset(np
, 2000);
5275 OUTB (nc_scntl0
, np
->rv_scntl0
| 0xc0);
5276 /* full arb., ena parity, par->ATN */
5277 OUTB (nc_scntl1
, 0x00); /* odd parity, and remove CRST!! */
5279 ncr_selectclock(np
, np
->rv_scntl3
); /* Select SCSI clock */
5281 OUTB (nc_scid
, RRE
|np
->myaddr
); /* Adapter SCSI address */
5282 OUTW (nc_respid
, 1ul<<np
->myaddr
); /* Id to respond to */
5283 OUTB (nc_istat
, SIGP
); /* Signal Process */
5284 OUTB (nc_dmode
, np
->rv_dmode
); /* Burst length, dma mode */
5285 OUTB (nc_ctest5
, np
->rv_ctest5
); /* Large fifo + large burst */
5287 OUTB (nc_dcntl
, NOCOM
|np
->rv_dcntl
); /* Protect SFBR */
5288 OUTB (nc_ctest0
, np
->rv_ctest0
); /* 720: CDIS and EHP */
5289 OUTB (nc_ctest3
, np
->rv_ctest3
); /* Write and invalidate */
5290 OUTB (nc_ctest4
, np
->rv_ctest4
); /* Master parity checking */
5292 OUTB (nc_stest2
, EXT
|np
->rv_stest2
); /* Extended Sreq/Sack filtering */
5293 OUTB (nc_stest3
, TE
); /* TolerANT enable */
5294 OUTB (nc_stime0
, 0x0c ); /* HTH disabled STO 0.25 sec */
5297 ** Disable disconnects.
5303 ** Enable GPIO0 pin for writing if LED support.
5306 if (np
->features
& FE_LED0
) {
5307 OUTOFFB (nc_gpcntl
, 0x01);
5314 OUTW (nc_sien
, STO
|HTH
|MA
|SGE
|UDC
|RST
|PAR
);
5315 OUTB (nc_dien
, MDPE
|BF
|ABRT
|SSI
|SIR
|IID
);
5318 ** Fill in target structure.
5319 ** Reinitialize usrsync.
5320 ** Reinitialize usrwide.
5321 ** Prepare sync negotiation according to actual SCSI bus mode.
5324 for (i
=0;i
<MAX_TARGET
;i
++) {
5325 struct tcb
*tp
= &np
->target
[i
];
5328 tp
->wval
= np
->rv_scntl3
;
5330 if (tp
->usrsync
!= 255) {
5331 if (tp
->usrsync
<= np
->maxsync
) {
5332 if (tp
->usrsync
< np
->minsync
) {
5333 tp
->usrsync
= np
->minsync
;
5340 if (tp
->usrwide
> np
->maxwide
)
5341 tp
->usrwide
= np
->maxwide
;
5346 ** Start script processor.
5350 printk ("%s: Downloading SCSI SCRIPTS.\n",
5352 OUTL (nc_scratcha
, vtobus(np
->script0
));
5353 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, start_ram
));
5356 OUTL_DSP (NCB_SCRIPT_PHYS (np
, start
));
5359 /*==========================================================
5361 ** Prepare the negotiation values for wide and
5362 ** synchronous transfers.
5364 **==========================================================
5367 static void ncr_negotiate (struct ncb
* np
, struct tcb
* tp
)
5370 ** minsync unit is 4ns !
5373 u_long minsync
= tp
->usrsync
;
5376 ** SCSI bus mode limit
5379 if (np
->scsi_mode
&& np
->scsi_mode
== SMODE_SE
) {
5380 if (minsync
< 12) minsync
= 12;
5387 if (minsync
< np
->minsync
)
5388 minsync
= np
->minsync
;
5394 if (minsync
> np
->maxsync
)
5397 if (tp
->maxoffs
> np
->maxoffs
)
5398 tp
->maxoffs
= np
->maxoffs
;
5400 tp
->minsync
= minsync
;
5401 tp
->maxoffs
= (minsync
<255 ? tp
->maxoffs
: 0);
5404 ** period=0: has to negotiate sync transfer
5410 ** widedone=0: has to negotiate wide transfer
5415 /*==========================================================
5417 ** Get clock factor and sync divisor for a given
5418 ** synchronous factor period.
5419 ** Returns the clock factor (in sxfer) and scntl3
5420 ** synchronous divisor field.
5422 **==========================================================
5425 static void ncr_getsync(struct ncb
*np
, u_char sfac
, u_char
*fakp
, u_char
*scntl3p
)
5427 u_long clk
= np
->clock_khz
; /* SCSI clock frequency in kHz */
5428 int div
= np
->clock_divn
; /* Number of divisors supported */
5429 u_long fak
; /* Sync factor in sxfer */
5430 u_long per
; /* Period in tenths of ns */
5431 u_long kpc
; /* (per * clk) */
5434 ** Compute the synchronous period in tenths of nano-seconds
5436 if (sfac
<= 10) per
= 250;
5437 else if (sfac
== 11) per
= 303;
5438 else if (sfac
== 12) per
= 500;
5439 else per
= 40 * sfac
;
5442 ** Look for the greatest clock divisor that allows an
5443 ** input speed faster than the period.
5447 if (kpc
>= (div_10M
[div
] << 2)) break;
5450 ** Calculate the lowest clock factor that allows an output
5451 ** speed not faster than the period.
5453 fak
= (kpc
- 1) / div_10M
[div
] + 1;
5455 #if 0 /* This optimization does not seem very useful */
5457 per
= (fak
* div_10M
[div
]) / clk
;
5460 ** Why not to try the immediate lower divisor and to choose
5461 ** the one that allows the fastest output speed ?
5462 ** We don't want input speed too much greater than output speed.
5464 if (div
>= 1 && fak
< 8) {
5466 fak2
= (kpc
- 1) / div_10M
[div
-1] + 1;
5467 per2
= (fak2
* div_10M
[div
-1]) / clk
;
5468 if (per2
< per
&& fak2
<= 8) {
5476 if (fak
< 4) fak
= 4; /* Should never happen, too bad ... */
5479 ** Compute and return sync parameters for the ncr
5482 *scntl3p
= ((div
+1) << 4) + (sfac
< 25 ? 0x80 : 0);
5486 /*==========================================================
5488 ** Set actual values, sync status and patch all ccbs of
5489 ** a target according to new sync/wide agreement.
5491 **==========================================================
5494 static void ncr_set_sync_wide_status (struct ncb
*np
, u_char target
)
5497 struct tcb
*tp
= &np
->target
[target
];
5500 ** set actual value and sync_status
5502 OUTB (nc_sxfer
, tp
->sval
);
5503 np
->sync_st
= tp
->sval
;
5504 OUTB (nc_scntl3
, tp
->wval
);
5505 np
->wide_st
= tp
->wval
;
5508 ** patch ALL ccbs of this target.
5510 for (cp
= np
->ccb
; cp
; cp
= cp
->link_ccb
) {
5511 if (!cp
->cmd
) continue;
5512 if (scmd_id(cp
->cmd
) != target
) continue;
5514 cp
->sync_status
= tp
->sval
;
5515 cp
->wide_status
= tp
->wval
;
5517 cp
->phys
.select
.sel_scntl3
= tp
->wval
;
5518 cp
->phys
.select
.sel_sxfer
= tp
->sval
;
5522 /*==========================================================
5524 ** Switch sync mode for current job and it's target
5526 **==========================================================
5529 static void ncr_setsync (struct ncb
*np
, struct ccb
*cp
, u_char scntl3
, u_char sxfer
)
5531 struct scsi_cmnd
*cmd
= cp
->cmd
;
5533 u_char target
= INB (nc_sdid
) & 0x0f;
5536 BUG_ON(target
!= (scmd_id(cmd
) & 0xf));
5538 tp
= &np
->target
[target
];
5540 if (!scntl3
|| !(sxfer
& 0x1f))
5541 scntl3
= np
->rv_scntl3
;
5542 scntl3
= (scntl3
& 0xf0) | (tp
->wval
& EWS
) | (np
->rv_scntl3
& 0x07);
5545 ** Deduce the value of controller sync period from scntl3.
5546 ** period is in tenths of nano-seconds.
5549 idiv
= ((scntl3
>> 4) & 0x7);
5550 if ((sxfer
& 0x1f) && idiv
)
5551 tp
->period
= (((sxfer
>>5)+4)*div_10M
[idiv
-1])/np
->clock_khz
;
5553 tp
->period
= 0xffff;
5555 /* Stop there if sync parameters are unchanged */
5556 if (tp
->sval
== sxfer
&& tp
->wval
== scntl3
)
5561 if (sxfer
& 0x01f) {
5562 /* Disable extended Sreq/Sack filtering */
5563 if (tp
->period
<= 2000)
5564 OUTOFFB(nc_stest2
, EXT
);
5567 spi_display_xfer_agreement(tp
->starget
);
5570 ** set actual value and sync_status
5571 ** patch ALL ccbs of this target.
5573 ncr_set_sync_wide_status(np
, target
);
5576 /*==========================================================
5578 ** Switch wide mode for current job and it's target
5579 ** SCSI specs say: a SCSI device that accepts a WDTR
5580 ** message shall reset the synchronous agreement to
5581 ** asynchronous mode.
5583 **==========================================================
5586 static void ncr_setwide (struct ncb
*np
, struct ccb
*cp
, u_char wide
, u_char ack
)
5588 struct scsi_cmnd
*cmd
= cp
->cmd
;
5589 u16 target
= INB (nc_sdid
) & 0x0f;
5594 BUG_ON(target
!= (scmd_id(cmd
) & 0xf));
5596 tp
= &np
->target
[target
];
5597 tp
->widedone
= wide
+1;
5598 scntl3
= (tp
->wval
& (~EWS
)) | (wide
? EWS
: 0);
5600 sxfer
= ack
? 0 : tp
->sval
;
5603 ** Stop there if sync/wide parameters are unchanged
5605 if (tp
->sval
== sxfer
&& tp
->wval
== scntl3
) return;
5610 ** Bells and whistles ;-)
5612 if (bootverbose
>= 2) {
5613 dev_info(&cmd
->device
->sdev_target
->dev
, "WIDE SCSI %sabled.\n",
5614 (scntl3
& EWS
) ? "en" : "dis");
5618 ** set actual value and sync_status
5619 ** patch ALL ccbs of this target.
5621 ncr_set_sync_wide_status(np
, target
);
5624 /*==========================================================
5626 ** Switch tagged mode for a target.
5628 **==========================================================
5631 static void ncr_setup_tags (struct ncb
*np
, struct scsi_device
*sdev
)
5633 unsigned char tn
= sdev
->id
, ln
= sdev
->lun
;
5634 struct tcb
*tp
= &np
->target
[tn
];
5635 struct lcb
*lp
= tp
->lp
[ln
];
5636 u_char reqtags
, maxdepth
;
5641 if ((!tp
) || (!lp
) || !sdev
)
5645 ** If SCSI device queue depth is not yet set, leave here.
5647 if (!lp
->scdev_depth
)
5651 ** Donnot allow more tags than the SCSI driver can queue
5653 ** Donnot allow more tags than we can handle.
5655 maxdepth
= lp
->scdev_depth
;
5656 if (maxdepth
> lp
->maxnxs
) maxdepth
= lp
->maxnxs
;
5657 if (lp
->maxtags
> maxdepth
) lp
->maxtags
= maxdepth
;
5658 if (lp
->numtags
> maxdepth
) lp
->numtags
= maxdepth
;
5661 ** only devices conformant to ANSI Version >= 2
5662 ** only devices capable of tagged commands
5663 ** only if enabled by user ..
5665 if (sdev
->tagged_supported
&& lp
->numtags
> 1) {
5666 reqtags
= lp
->numtags
;
5672 ** Update max number of tags
5674 lp
->numtags
= reqtags
;
5675 if (lp
->numtags
> lp
->maxtags
)
5676 lp
->maxtags
= lp
->numtags
;
5679 ** If we want to switch tag mode, we must wait
5680 ** for no CCB to be active.
5682 if (reqtags
> 1 && lp
->usetags
) { /* Stay in tagged mode */
5683 if (lp
->queuedepth
== reqtags
) /* Already announced */
5685 lp
->queuedepth
= reqtags
;
5687 else if (reqtags
<= 1 && !lp
->usetags
) { /* Stay in untagged mode */
5688 lp
->queuedepth
= reqtags
;
5691 else { /* Want to switch tag mode */
5692 if (lp
->busyccbs
) /* If not yet safe, return */
5694 lp
->queuedepth
= reqtags
;
5695 lp
->usetags
= reqtags
> 1 ? 1 : 0;
5699 ** Patch the lun mini-script, according to tag mode.
5701 lp
->jump_tag
.l_paddr
= lp
->usetags
?
5702 cpu_to_scr(NCB_SCRIPT_PHYS(np
, resel_tag
)) :
5703 cpu_to_scr(NCB_SCRIPT_PHYS(np
, resel_notag
));
5706 ** Announce change to user.
5710 dev_info(&sdev
->sdev_gendev
,
5711 "tagged command queue depth set to %d\n",
5714 dev_info(&sdev
->sdev_gendev
,
5715 "tagged command queueing disabled\n");
5720 /*==========================================================
5723 ** ncr timeout handler.
5726 **==========================================================
5728 ** Misused to keep the driver running when
5729 ** interrupts are not configured correctly.
5731 **----------------------------------------------------------
5734 static void ncr_timeout (struct ncb
*np
)
5736 u_long thistime
= jiffies
;
5739 ** If release process in progress, let's go
5740 ** Set the release stage from 1 to 2 to synchronize
5741 ** with the release process.
5744 if (np
->release_stage
) {
5745 if (np
->release_stage
== 1) np
->release_stage
= 2;
5749 np
->timer
.expires
= jiffies
+ SCSI_NCR_TIMER_INTERVAL
;
5750 add_timer(&np
->timer
);
5753 ** If we are resetting the ncr, wait for settle_time before
5754 ** clearing it. Then command processing will be resumed.
5756 if (np
->settle_time
) {
5757 if (np
->settle_time
<= thistime
) {
5758 if (bootverbose
> 1)
5759 printk("%s: command processing resumed\n", ncr_name(np
));
5760 np
->settle_time
= 0;
5762 requeue_waiting_list(np
);
5768 ** Since the generic scsi driver only allows us 0.5 second
5769 ** to perform abort of a command, we must look at ccbs about
5770 ** every 0.25 second.
5772 if (np
->lasttime
+ 4*HZ
< thistime
) {
5774 ** block ncr interrupts
5776 np
->lasttime
= thistime
;
5779 #ifdef SCSI_NCR_BROKEN_INTR
5780 if (INB(nc_istat
) & (INTF
|SIP
|DIP
)) {
5783 ** Process pending interrupts.
5785 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("{");
5787 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("}");
5789 #endif /* SCSI_NCR_BROKEN_INTR */
5792 /*==========================================================
5794 ** log message for real hard errors
5796 ** "ncr0 targ 0?: ERROR (ds:si) (so-si-sd) (sxfer/scntl3) @ name (dsp:dbc)."
5797 ** " reg: r0 r1 r2 r3 r4 r5 r6 ..... rf."
5799 ** exception register:
5804 ** so: control lines as driver by NCR.
5805 ** si: control lines as seen by NCR.
5806 ** sd: scsi data lines as seen by NCR.
5809 ** sxfer: (see the manual)
5810 ** scntl3: (see the manual)
5812 ** current script command:
5813 ** dsp: script address (relative to start of script).
5814 ** dbc: first word of script command.
5816 ** First 16 register of the chip:
5819 **==========================================================
5822 static void ncr_log_hard_error(struct ncb
*np
, u16 sist
, u_char dstat
)
5828 u_char
*script_base
;
5833 if (dsp
> np
->p_script
&& dsp
<= np
->p_script
+ sizeof(struct script
)) {
5834 script_ofs
= dsp
- np
->p_script
;
5835 script_size
= sizeof(struct script
);
5836 script_base
= (u_char
*) np
->script0
;
5837 script_name
= "script";
5839 else if (np
->p_scripth
< dsp
&&
5840 dsp
<= np
->p_scripth
+ sizeof(struct scripth
)) {
5841 script_ofs
= dsp
- np
->p_scripth
;
5842 script_size
= sizeof(struct scripth
);
5843 script_base
= (u_char
*) np
->scripth0
;
5844 script_name
= "scripth";
5849 script_name
= "mem";
5852 printk ("%s:%d: ERROR (%x:%x) (%x-%x-%x) (%x/%x) @ (%s %x:%08x).\n",
5853 ncr_name (np
), (unsigned)INB (nc_sdid
)&0x0f, dstat
, sist
,
5854 (unsigned)INB (nc_socl
), (unsigned)INB (nc_sbcl
), (unsigned)INB (nc_sbdl
),
5855 (unsigned)INB (nc_sxfer
),(unsigned)INB (nc_scntl3
), script_name
, script_ofs
,
5856 (unsigned)INL (nc_dbc
));
5858 if (((script_ofs
& 3) == 0) &&
5859 (unsigned)script_ofs
< script_size
) {
5860 printk ("%s: script cmd = %08x\n", ncr_name(np
),
5861 scr_to_cpu((int) *(ncrcmd
*)(script_base
+ script_ofs
)));
5864 printk ("%s: regdump:", ncr_name(np
));
5866 printk (" %02x", (unsigned)INB_OFF(i
));
5870 /*============================================================
5872 ** ncr chip exception handler.
5874 **============================================================
5876 ** In normal cases, interrupt conditions occur one at a
5877 ** time. The ncr is able to stack in some extra registers
5878 ** other interrupts that will occur after the first one.
5879 ** But, several interrupts may occur at the same time.
5881 ** We probably should only try to deal with the normal
5882 ** case, but it seems that multiple interrupts occur in
5883 ** some cases that are not abnormal at all.
5885 ** The most frequent interrupt condition is Phase Mismatch.
5886 ** We should want to service this interrupt quickly.
5887 ** A SCSI parity error may be delivered at the same time.
5888 ** The SIR interrupt is not very frequent in this driver,
5889 ** since the INTFLY is likely used for command completion
5891 ** The Selection Timeout interrupt may be triggered with
5893 ** The SBMC interrupt (SCSI Bus Mode Change) may probably
5894 ** occur at any time.
5896 ** This handler try to deal as cleverly as possible with all
5899 **============================================================
5902 void ncr_exception (struct ncb
*np
)
5904 u_char istat
, dstat
;
5909 ** interrupt on the fly ?
5910 ** Since the global header may be copied back to a CCB
5911 ** using a posted PCI memory write, the last operation on
5912 ** the istat register is a READ in order to flush posted
5913 ** PCI write commands.
5915 istat
= INB (nc_istat
);
5917 OUTB (nc_istat
, (istat
& SIGP
) | INTF
);
5918 istat
= INB (nc_istat
);
5919 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("F ");
5920 ncr_wakeup_done (np
);
5923 if (!(istat
& (SIP
|DIP
)))
5927 OUTB (nc_istat
, CABRT
);
5930 ** Steinbach's Guideline for Systems Programming:
5931 ** Never test for an error condition you don't know how to handle.
5934 sist
= (istat
& SIP
) ? INW (nc_sist
) : 0;
5935 dstat
= (istat
& DIP
) ? INB (nc_dstat
) : 0;
5937 if (DEBUG_FLAGS
& DEBUG_TINY
)
5938 printk ("<%d|%x:%x|%x:%x>",
5941 (unsigned)INL(nc_dsp
),
5942 (unsigned)INL(nc_dbc
));
5944 /*========================================================
5945 ** First, interrupts we want to service cleanly.
5947 ** Phase mismatch is the most frequent interrupt, and
5948 ** so we have to service it as quickly and as cleanly
5950 ** Programmed interrupts are rarely used in this driver,
5951 ** but we must handle them cleanly anyway.
5952 ** We try to deal with PAR and SBMC combined with
5953 ** some other interrupt(s).
5954 **=========================================================
5957 if (!(sist
& (STO
|GEN
|HTH
|SGE
|UDC
|RST
)) &&
5958 !(dstat
& (MDPE
|BF
|ABRT
|IID
))) {
5959 if ((sist
& SBMC
) && ncr_int_sbmc (np
))
5961 if ((sist
& PAR
) && ncr_int_par (np
))
5972 ** DEL 397 - 53C875 Rev 3 - Part Number 609-0392410 - ITEM 2.
5974 if (!(sist
& (SBMC
|PAR
)) && !(dstat
& SSI
)) {
5975 printk( "%s: unknown interrupt(s) ignored, "
5976 "ISTAT=%x DSTAT=%x SIST=%x\n",
5977 ncr_name(np
), istat
, dstat
, sist
);
5984 /*========================================================
5985 ** Now, interrupts that need some fixing up.
5986 ** Order and multiple interrupts is so less important.
5988 ** If SRST has been asserted, we just reset the chip.
5990 ** Selection is intirely handled by the chip. If the
5991 ** chip says STO, we trust it. Seems some other
5992 ** interrupts may occur at the same time (UDC, IID), so
5993 ** we ignore them. In any case we do enough fix-up
5994 ** in the service routine.
5995 ** We just exclude some fatal dma errors.
5996 **=========================================================
6000 ncr_init (np
, 1, bootverbose
? "scsi reset" : NULL
, HS_RESET
);
6005 !(dstat
& (MDPE
|BF
|ABRT
))) {
6007 ** DEL 397 - 53C875 Rev 3 - Part Number 609-0392410 - ITEM 1.
6009 OUTONB (nc_ctest3
, CLF
);
6015 /*=========================================================
6016 ** Now, interrupts we are not able to recover cleanly.
6017 ** (At least for the moment).
6019 ** Do the register dump.
6020 ** Log message for real hard errors.
6022 ** For MDPE, BF, ABORT, IID, SGE and HTH we reset the
6023 ** BUS and the chip.
6024 ** We are more soft for UDC.
6025 **=========================================================
6028 if (time_after(jiffies
, np
->regtime
)) {
6029 np
->regtime
= jiffies
+ 10*HZ
;
6030 for (i
= 0; i
<sizeof(np
->regdump
); i
++)
6031 ((char*)&np
->regdump
)[i
] = INB_OFF(i
);
6032 np
->regdump
.nc_dstat
= dstat
;
6033 np
->regdump
.nc_sist
= sist
;
6036 ncr_log_hard_error(np
, sist
, dstat
);
6038 printk ("%s: have to clear fifos.\n", ncr_name (np
));
6039 OUTB (nc_stest3
, TE
|CSF
);
6040 OUTONB (nc_ctest3
, CLF
);
6042 if ((sist
& (SGE
)) ||
6043 (dstat
& (MDPE
|BF
|ABRT
|IID
))) {
6044 ncr_start_reset(np
);
6049 printk ("%s: handshake timeout\n", ncr_name(np
));
6050 ncr_start_reset(np
);
6055 printk ("%s: unexpected disconnect\n", ncr_name(np
));
6056 OUTB (HS_PRT
, HS_UNEXPECTED
);
6057 OUTL_DSP (NCB_SCRIPT_PHYS (np
, cleanup
));
6061 /*=========================================================
6062 ** We just miss the cause of the interrupt. :(
6063 ** Print a message. The timeout will do the real work.
6064 **=========================================================
6066 printk ("%s: unknown interrupt\n", ncr_name(np
));
6069 /*==========================================================
6071 ** ncr chip exception handler for selection timeout
6073 **==========================================================
6075 ** There seems to be a bug in the 53c810.
6076 ** Although a STO-Interrupt is pending,
6077 ** it continues executing script commands.
6078 ** But it will fail and interrupt (IID) on
6079 ** the next instruction where it's looking
6080 ** for a valid phase.
6082 **----------------------------------------------------------
6085 void ncr_int_sto (struct ncb
*np
)
6089 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("T");
6092 ** look for ccb and set the status.
6097 while (cp
&& (CCB_PHYS (cp
, phys
) != dsa
))
6101 cp
-> host_status
= HS_SEL_TIMEOUT
;
6102 ncr_complete (np
, cp
);
6106 ** repair start queue and jump to start point.
6109 OUTL_DSP (NCB_SCRIPTH_PHYS (np
, sto_restart
));
6113 /*==========================================================
6115 ** ncr chip exception handler for SCSI bus mode change
6117 **==========================================================
6119 ** spi2-r12 11.2.3 says a transceiver mode change must
6120 ** generate a reset event and a device that detects a reset
6121 ** event shall initiate a hard reset. It says also that a
6122 ** device that detects a mode change shall set data transfer
6123 ** mode to eight bit asynchronous, etc...
6124 ** So, just resetting should be enough.
6127 **----------------------------------------------------------
6130 static int ncr_int_sbmc (struct ncb
*np
)
6132 u_char scsi_mode
= INB (nc_stest4
) & SMODE
;
6134 if (scsi_mode
!= np
->scsi_mode
) {
6135 printk("%s: SCSI bus mode change from %x to %x.\n",
6136 ncr_name(np
), np
->scsi_mode
, scsi_mode
);
6138 np
->scsi_mode
= scsi_mode
;
6142 ** Suspend command processing for 1 second and
6143 ** reinitialize all except the chip.
6145 np
->settle_time
= jiffies
+ HZ
;
6146 ncr_init (np
, 0, bootverbose
? "scsi mode change" : NULL
, HS_RESET
);
6152 /*==========================================================
6154 ** ncr chip exception handler for SCSI parity error.
6156 **==========================================================
6159 **----------------------------------------------------------
6162 static int ncr_int_par (struct ncb
*np
)
6164 u_char hsts
= INB (HS_PRT
);
6165 u32 dbc
= INL (nc_dbc
);
6166 u_char sstat1
= INB (nc_sstat1
);
6171 printk("%s: SCSI parity error detected: SCR1=%d DBC=%x SSTAT1=%x\n",
6172 ncr_name(np
), hsts
, dbc
, sstat1
);
6175 * Ignore the interrupt if the NCR is not connected
6176 * to the SCSI bus, since the right work should have
6177 * been done on unexpected disconnection handling.
6179 if (!(INB (nc_scntl1
) & ISCON
))
6183 * If the nexus is not clearly identified, reset the bus.
6184 * We will try to do better later.
6186 if (hsts
& HS_INVALMASK
)
6190 * If the SCSI parity error occurs in MSG IN phase, prepare a
6191 * MSG PARITY message. Otherwise, prepare a INITIATOR DETECTED
6192 * ERROR message and let the device decide to retry the command
6193 * or to terminate with check condition. If we were in MSG IN
6194 * phase waiting for the response of a negotiation, we will
6195 * get SIR_NEGO_FAILED at dispatch.
6197 if (!(dbc
& 0xc0000000))
6198 phase
= (dbc
>> 24) & 7;
6200 msg
= MSG_PARITY_ERROR
;
6202 msg
= INITIATOR_ERROR
;
6206 * If the NCR stopped on a MOVE ^ DATA_IN, we jump to a
6207 * script that will ignore all data in bytes until phase
6208 * change, since we are not sure the chip will wait the phase
6209 * change prior to delivering the interrupt.
6212 jmp
= NCB_SCRIPTH_PHYS (np
, par_err_data_in
);
6214 jmp
= NCB_SCRIPTH_PHYS (np
, par_err_other
);
6216 OUTONB (nc_ctest3
, CLF
); /* clear dma fifo */
6217 OUTB (nc_stest3
, TE
|CSF
); /* clear scsi fifo */
6219 np
->msgout
[0] = msg
;
6224 ncr_start_reset(np
);
6228 /*==========================================================
6231 ** ncr chip exception handler for phase errors.
6234 **==========================================================
6236 ** We have to construct a new transfer descriptor,
6237 ** to transfer the rest of the current block.
6239 **----------------------------------------------------------
6242 static void ncr_int_ma (struct ncb
*np
)
6259 sbcl
= INB (nc_sbcl
);
6262 rest
= dbc
& 0xffffff;
6265 ** Take into account dma fifo and various buffers and latches,
6266 ** only if the interrupted phase is an OUTPUT phase.
6269 if ((cmd
& 1) == 0) {
6270 u_char ctest5
, ss0
, ss2
;
6273 ctest5
= (np
->rv_ctest5
& DFS
) ? INB (nc_ctest5
) : 0;
6275 delta
=(((ctest5
<< 8) | (INB (nc_dfifo
) & 0xff)) - rest
) & 0x3ff;
6277 delta
=(INB (nc_dfifo
) - rest
) & 0x7f;
6280 ** The data in the dma fifo has not been transferred to
6281 ** the target -> add the amount to the rest
6282 ** and clear the data.
6283 ** Check the sstat2 register in case of wide transfer.
6287 ss0
= INB (nc_sstat0
);
6288 if (ss0
& OLF
) rest
++;
6289 if (ss0
& ORF
) rest
++;
6290 if (INB(nc_scntl3
) & EWS
) {
6291 ss2
= INB (nc_sstat2
);
6292 if (ss2
& OLF1
) rest
++;
6293 if (ss2
& ORF1
) rest
++;
6296 if (DEBUG_FLAGS
& (DEBUG_TINY
|DEBUG_PHASE
))
6297 printk ("P%x%x RL=%d D=%d SS0=%x ", cmd
&7, sbcl
&7,
6298 (unsigned) rest
, (unsigned) delta
, ss0
);
6301 if (DEBUG_FLAGS
& (DEBUG_TINY
|DEBUG_PHASE
))
6302 printk ("P%x%x RL=%d ", cmd
&7, sbcl
&7, rest
);
6308 OUTONB (nc_ctest3
, CLF
); /* clear dma fifo */
6309 OUTB (nc_stest3
, TE
|CSF
); /* clear scsi fifo */
6312 ** locate matching cp.
6313 ** if the interrupted phase is DATA IN or DATA OUT,
6314 ** trust the global header.
6319 if (CCB_PHYS(cp
, phys
) != dsa
)
6323 while (cp
&& (CCB_PHYS (cp
, phys
) != dsa
))
6328 ** try to find the interrupted script command,
6329 ** and the address at which to continue.
6333 if (dsp
> np
->p_script
&&
6334 dsp
<= np
->p_script
+ sizeof(struct script
)) {
6335 vdsp
= (u32
*)((char*)np
->script0
+ (dsp
-np
->p_script
-8));
6338 else if (dsp
> np
->p_scripth
&&
6339 dsp
<= np
->p_scripth
+ sizeof(struct scripth
)) {
6340 vdsp
= (u32
*)((char*)np
->scripth0
+ (dsp
-np
->p_scripth
-8));
6344 if (dsp
== CCB_PHYS (cp
, patch
[2])) {
6345 vdsp
= &cp
->patch
[0];
6346 nxtdsp
= scr_to_cpu(vdsp
[3]);
6348 else if (dsp
== CCB_PHYS (cp
, patch
[6])) {
6349 vdsp
= &cp
->patch
[4];
6350 nxtdsp
= scr_to_cpu(vdsp
[3]);
6355 ** log the information
6358 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
6359 printk ("\nCP=%p CP2=%p DSP=%x NXT=%x VDSP=%p CMD=%x ",
6362 (unsigned)nxtdsp
, vdsp
, cmd
);
6366 ** cp=0 means that the DSA does not point to a valid control
6367 ** block. This should not happen since we donnot use multi-byte
6368 ** move while we are being reselected ot after command complete.
6369 ** We are not able to recover from such a phase error.
6372 printk ("%s: SCSI phase error fixup: "
6373 "CCB already dequeued (0x%08lx)\n",
6374 ncr_name (np
), (u_long
) np
->header
.cp
);
6379 ** get old startaddress and old length.
6382 oadr
= scr_to_cpu(vdsp
[1]);
6384 if (cmd
& 0x10) { /* Table indirect */
6385 tblp
= (u32
*) ((char*) &cp
->phys
+ oadr
);
6386 olen
= scr_to_cpu(tblp
[0]);
6387 oadr
= scr_to_cpu(tblp
[1]);
6390 olen
= scr_to_cpu(vdsp
[0]) & 0xffffff;
6393 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
6394 printk ("OCMD=%x\nTBLP=%p OLEN=%x OADR=%x\n",
6395 (unsigned) (scr_to_cpu(vdsp
[0]) >> 24),
6402 ** check cmd against assumed interrupted script command.
6405 if (cmd
!= (scr_to_cpu(vdsp
[0]) >> 24)) {
6406 PRINT_ADDR(cp
->cmd
, "internal error: cmd=%02x != %02x=(vdsp[0] "
6407 ">> 24)\n", cmd
, scr_to_cpu(vdsp
[0]) >> 24);
6413 ** cp != np->header.cp means that the header of the CCB
6414 ** currently being processed has not yet been copied to
6415 ** the global header area. That may happen if the device did
6416 ** not accept all our messages after having been selected.
6418 if (cp
!= np
->header
.cp
) {
6419 printk ("%s: SCSI phase error fixup: "
6420 "CCB address mismatch (0x%08lx != 0x%08lx)\n",
6421 ncr_name (np
), (u_long
) cp
, (u_long
) np
->header
.cp
);
6425 ** if old phase not dataphase, leave here.
6429 PRINT_ADDR(cp
->cmd
, "phase change %x-%x %d@%08x resid=%d.\n",
6430 cmd
&7, sbcl
&7, (unsigned)olen
,
6431 (unsigned)oadr
, (unsigned)rest
);
6432 goto unexpected_phase
;
6436 ** choose the correct patch area.
6437 ** if savep points to one, choose the other.
6441 newtmp
= CCB_PHYS (cp
, patch
);
6442 if (newtmp
== scr_to_cpu(cp
->phys
.header
.savep
)) {
6443 newcmd
= &cp
->patch
[4];
6444 newtmp
= CCB_PHYS (cp
, patch
[4]);
6448 ** fillin the commands
6451 newcmd
[0] = cpu_to_scr(((cmd
& 0x0f) << 24) | rest
);
6452 newcmd
[1] = cpu_to_scr(oadr
+ olen
- rest
);
6453 newcmd
[2] = cpu_to_scr(SCR_JUMP
);
6454 newcmd
[3] = cpu_to_scr(nxtdsp
);
6456 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
6457 PRINT_ADDR(cp
->cmd
, "newcmd[%d] %x %x %x %x.\n",
6458 (int) (newcmd
- cp
->patch
),
6459 (unsigned)scr_to_cpu(newcmd
[0]),
6460 (unsigned)scr_to_cpu(newcmd
[1]),
6461 (unsigned)scr_to_cpu(newcmd
[2]),
6462 (unsigned)scr_to_cpu(newcmd
[3]));
6465 ** fake the return address (to the patch).
6466 ** and restart script processor at dispatcher.
6468 OUTL (nc_temp
, newtmp
);
6469 OUTL_DSP (NCB_SCRIPT_PHYS (np
, dispatch
));
6473 ** Unexpected phase changes that occurs when the current phase
6474 ** is not a DATA IN or DATA OUT phase are due to error conditions.
6475 ** Such event may only happen when the SCRIPTS is using a
6476 ** multibyte SCSI MOVE.
6478 ** Phase change Some possible cause
6480 ** COMMAND --> MSG IN SCSI parity error detected by target.
6481 ** COMMAND --> STATUS Bad command or refused by target.
6482 ** MSG OUT --> MSG IN Message rejected by target.
6483 ** MSG OUT --> COMMAND Bogus target that discards extended
6484 ** negotiation messages.
6486 ** The code below does not care of the new phase and so
6487 ** trusts the target. Why to annoy it ?
6488 ** If the interrupted phase is COMMAND phase, we restart at
6490 ** If a target does not get all the messages after selection,
6491 ** the code assumes blindly that the target discards extended
6492 ** messages and clears the negotiation status.
6493 ** If the target does not want all our response to negotiation,
6494 ** we force a SIR_NEGO_PROTO interrupt (it is a hack that avoids
6495 ** bloat for such a should_not_happen situation).
6496 ** In all other situation, we reset the BUS.
6497 ** Are these assumptions reasonnable ? (Wait and see ...)
6504 case 2: /* COMMAND phase */
6505 nxtdsp
= NCB_SCRIPT_PHYS (np
, dispatch
);
6508 case 3: /* STATUS phase */
6509 nxtdsp
= NCB_SCRIPT_PHYS (np
, dispatch
);
6512 case 6: /* MSG OUT phase */
6513 np
->scripth
->nxtdsp_go_on
[0] = cpu_to_scr(dsp
+ 8);
6514 if (dsp
== NCB_SCRIPT_PHYS (np
, send_ident
)) {
6515 cp
->host_status
= HS_BUSY
;
6516 nxtdsp
= NCB_SCRIPTH_PHYS (np
, clratn_go_on
);
6518 else if (dsp
== NCB_SCRIPTH_PHYS (np
, send_wdtr
) ||
6519 dsp
== NCB_SCRIPTH_PHYS (np
, send_sdtr
)) {
6520 nxtdsp
= NCB_SCRIPTH_PHYS (np
, nego_bad_phase
);
6524 case 7: /* MSG IN phase */
6525 nxtdsp
= NCB_SCRIPT_PHYS (np
, clrack
);
6536 ncr_start_reset(np
);
6540 static void ncr_sir_to_redo(struct ncb
*np
, int num
, struct ccb
*cp
)
6542 struct scsi_cmnd
*cmd
= cp
->cmd
;
6543 struct tcb
*tp
= &np
->target
[cmd
->device
->id
];
6544 struct lcb
*lp
= tp
->lp
[cmd
->device
->lun
];
6545 struct list_head
*qp
;
6550 u_char s_status
= INB (SS_PRT
);
6553 ** Let the SCRIPTS processor skip all not yet started CCBs,
6554 ** and count disconnected CCBs. Since the busy queue is in
6555 ** the same order as the chip start queue, disconnected CCBs
6556 ** are before cp and busy ones after.
6559 qp
= lp
->busy_ccbq
.prev
;
6560 while (qp
!= &lp
->busy_ccbq
) {
6561 cp2
= list_entry(qp
, struct ccb
, link_ccbq
);
6566 cp2
->start
.schedule
.l_paddr
=
6567 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, skip
));
6569 lp
->held_ccb
= cp
; /* Requeue when this one completes */
6570 disc_cnt
= lp
->queuedccbs
- busy_cnt
;
6574 default: /* Just for safety, should never happen */
6577 ** Decrease number of tags to the number of
6578 ** disconnected commands.
6582 if (bootverbose
>= 1) {
6583 PRINT_ADDR(cmd
, "QUEUE FULL! %d busy, %d disconnected "
6584 "CCBs\n", busy_cnt
, disc_cnt
);
6586 if (disc_cnt
< lp
->numtags
) {
6587 lp
->numtags
= disc_cnt
> 2 ? disc_cnt
: 2;
6589 ncr_setup_tags (np
, cmd
->device
);
6592 ** Requeue the command to the start queue.
6593 ** If any disconnected commands,
6595 ** Jump to reselect.
6597 cp
->phys
.header
.savep
= cp
->startp
;
6598 cp
->host_status
= HS_BUSY
;
6599 cp
->scsi_status
= S_ILLEGAL
;
6601 ncr_put_start_queue(np
, cp
);
6603 INB (nc_ctest2
); /* Clear SIGP */
6604 OUTL_DSP (NCB_SCRIPT_PHYS (np
, reselect
));
6609 ** If we were requesting sense, give up.
6615 ** Device returned CHECK CONDITION status.
6616 ** Prepare all needed data strutures for getting
6621 cp
->scsi_smsg2
[0] = IDENTIFY(0, cmd
->device
->lun
);
6622 cp
->phys
.smsg
.addr
= cpu_to_scr(CCB_PHYS (cp
, scsi_smsg2
));
6623 cp
->phys
.smsg
.size
= cpu_to_scr(1);
6628 cp
->phys
.cmd
.addr
= cpu_to_scr(CCB_PHYS (cp
, sensecmd
));
6629 cp
->phys
.cmd
.size
= cpu_to_scr(6);
6632 ** patch requested size into sense command
6634 cp
->sensecmd
[0] = 0x03;
6635 cp
->sensecmd
[1] = cmd
->device
->lun
<< 5;
6636 cp
->sensecmd
[4] = sizeof(cp
->sense_buf
);
6641 memset(cp
->sense_buf
, 0, sizeof(cp
->sense_buf
));
6642 cp
->phys
.sense
.addr
= cpu_to_scr(CCB_PHYS(cp
,sense_buf
[0]));
6643 cp
->phys
.sense
.size
= cpu_to_scr(sizeof(cp
->sense_buf
));
6646 ** requeue the command.
6648 startp
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, sdata_in
));
6650 cp
->phys
.header
.savep
= startp
;
6651 cp
->phys
.header
.goalp
= startp
+ 24;
6652 cp
->phys
.header
.lastp
= startp
;
6653 cp
->phys
.header
.wgoalp
= startp
+ 24;
6654 cp
->phys
.header
.wlastp
= startp
;
6656 cp
->host_status
= HS_BUSY
;
6657 cp
->scsi_status
= S_ILLEGAL
;
6658 cp
->auto_sense
= s_status
;
6660 cp
->start
.schedule
.l_paddr
=
6661 cpu_to_scr(NCB_SCRIPT_PHYS (np
, select
));
6664 ** Select without ATN for quirky devices.
6666 if (cmd
->device
->select_no_atn
)
6667 cp
->start
.schedule
.l_paddr
=
6668 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, select_no_atn
));
6670 ncr_put_start_queue(np
, cp
);
6672 OUTL_DSP (NCB_SCRIPT_PHYS (np
, start
));
6682 /*==========================================================
6685 ** ncr chip exception handler for programmed interrupts.
6688 **==========================================================
6691 void ncr_int_sir (struct ncb
*np
)
6694 u_char chg
, ofs
, per
, fak
, wide
;
6695 u_char num
= INB (nc_dsps
);
6696 struct ccb
*cp
=NULL
;
6697 u_long dsa
= INL (nc_dsa
);
6698 u_char target
= INB (nc_sdid
) & 0x0f;
6699 struct tcb
*tp
= &np
->target
[target
];
6700 struct scsi_target
*starget
= tp
->starget
;
6702 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("I#%d", num
);
6707 ** This is used for HP Zalon/53c720 where INTFLY
6708 ** operation is currently broken.
6710 ncr_wakeup_done(np
);
6711 #ifdef SCSI_NCR_CCB_DONE_SUPPORT
6712 OUTL(nc_dsp
, NCB_SCRIPT_PHYS (np
, done_end
) + 8);
6714 OUTL(nc_dsp
, NCB_SCRIPT_PHYS (np
, start
));
6717 case SIR_RESEL_NO_MSG_IN
:
6718 case SIR_RESEL_NO_IDENTIFY
:
6720 ** If devices reselecting without sending an IDENTIFY
6721 ** message still exist, this should help.
6722 ** We just assume lun=0, 1 CCB, no tag.
6725 OUTL_DSP (scr_to_cpu(tp
->lp
[0]->jump_ccb
[0]));
6728 case SIR_RESEL_BAD_TARGET
: /* Will send a TARGET RESET message */
6729 case SIR_RESEL_BAD_LUN
: /* Will send a TARGET RESET message */
6730 case SIR_RESEL_BAD_I_T_L_Q
: /* Will send an ABORT TAG message */
6731 case SIR_RESEL_BAD_I_T_L
: /* Will send an ABORT message */
6732 printk ("%s:%d: SIR %d, "
6733 "incorrect nexus identification on reselection\n",
6734 ncr_name (np
), target
, num
);
6736 case SIR_DONE_OVERFLOW
:
6737 printk ("%s:%d: SIR %d, "
6738 "CCB done queue overflow\n",
6739 ncr_name (np
), target
, num
);
6741 case SIR_BAD_STATUS
:
6743 if (!cp
|| CCB_PHYS (cp
, phys
) != dsa
)
6745 ncr_sir_to_redo(np
, num
, cp
);
6752 while (cp
&& (CCB_PHYS (cp
, phys
) != dsa
))
6756 BUG_ON(cp
!= np
->header
.cp
);
6758 if (!cp
|| cp
!= np
->header
.cp
)
6763 /*-----------------------------------------------------------------------------
6765 ** Was Sie schon immer ueber transfermode negotiation wissen wollten ...
6766 ** ("Everything you've always wanted to know about transfer mode
6769 ** We try to negotiate sync and wide transfer only after
6770 ** a successful inquire command. We look at byte 7 of the
6771 ** inquire data to determine the capabilities of the target.
6773 ** When we try to negotiate, we append the negotiation message
6774 ** to the identify and (maybe) simple tag message.
6775 ** The host status field is set to HS_NEGOTIATE to mark this
6778 ** If the target doesn't answer this message immediately
6779 ** (as required by the standard), the SIR_NEGO_FAIL interrupt
6780 ** will be raised eventually.
6781 ** The handler removes the HS_NEGOTIATE status, and sets the
6782 ** negotiated value to the default (async / nowide).
6784 ** If we receive a matching answer immediately, we check it
6785 ** for validity, and set the values.
6787 ** If we receive a Reject message immediately, we assume the
6788 ** negotiation has failed, and fall back to standard values.
6790 ** If we receive a negotiation message while not in HS_NEGOTIATE
6791 ** state, it's a target initiated negotiation. We prepare a
6792 ** (hopefully) valid answer, set our parameters, and send back
6793 ** this answer to the target.
6795 ** If the target doesn't fetch the answer (no message out phase),
6796 ** we assume the negotiation has failed, and fall back to default
6799 ** When we set the values, we adjust them in all ccbs belonging
6800 ** to this target, in the controller's register, and in the "phys"
6801 ** field of the controller's struct ncb.
6803 ** Possible cases: hs sir msg_in value send goto
6804 ** We try to negotiate:
6805 ** -> target doesn't msgin NEG FAIL noop defa. - dispatch
6806 ** -> target rejected our msg NEG FAIL reject defa. - dispatch
6807 ** -> target answered (ok) NEG SYNC sdtr set - clrack
6808 ** -> target answered (!ok) NEG SYNC sdtr defa. REJ--->msg_bad
6809 ** -> target answered (ok) NEG WIDE wdtr set - clrack
6810 ** -> target answered (!ok) NEG WIDE wdtr defa. REJ--->msg_bad
6811 ** -> any other msgin NEG FAIL noop defa. - dispatch
6813 ** Target tries to negotiate:
6814 ** -> incoming message --- SYNC sdtr set SDTR -
6815 ** -> incoming message --- WIDE wdtr set WDTR -
6816 ** We sent our answer:
6817 ** -> target doesn't msgout --- PROTO ? defa. - dispatch
6819 **-----------------------------------------------------------------------------
6822 case SIR_NEGO_FAILED
:
6823 /*-------------------------------------------------------
6825 ** Negotiation failed.
6826 ** Target doesn't send an answer message,
6827 ** or target rejected our message.
6829 ** Remove negotiation request.
6831 **-------------------------------------------------------
6833 OUTB (HS_PRT
, HS_BUSY
);
6837 case SIR_NEGO_PROTO
:
6838 /*-------------------------------------------------------
6840 ** Negotiation failed.
6841 ** Target doesn't fetch the answer message.
6843 **-------------------------------------------------------
6846 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6847 PRINT_ADDR(cp
->cmd
, "negotiation failed sir=%x "
6848 "status=%x.\n", num
, cp
->nego_status
);
6852 ** any error in negotiation:
6853 ** fall back to default mode.
6855 switch (cp
->nego_status
) {
6858 spi_period(starget
) = 0;
6859 spi_offset(starget
) = 0;
6860 ncr_setsync (np
, cp
, 0, 0xe0);
6864 spi_width(starget
) = 0;
6865 ncr_setwide (np
, cp
, 0, 0);
6869 np
->msgin
[0] = NOP
;
6870 np
->msgout
[0] = NOP
;
6871 cp
->nego_status
= 0;
6875 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6876 ncr_print_msg(cp
, "sync msgin", np
->msgin
);
6882 if (ofs
==0) per
=255;
6885 ** if target sends SDTR message,
6886 ** it CAN transfer synch.
6890 spi_support_sync(starget
) = 1;
6893 ** check values against driver limits.
6896 if (per
< np
->minsync
)
6897 {chg
= 1; per
= np
->minsync
;}
6898 if (per
< tp
->minsync
)
6899 {chg
= 1; per
= tp
->minsync
;}
6900 if (ofs
> tp
->maxoffs
)
6901 {chg
= 1; ofs
= tp
->maxoffs
;}
6904 ** Check against controller limits.
6909 ncr_getsync(np
, per
, &fak
, &scntl3
);
6922 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6923 PRINT_ADDR(cp
->cmd
, "sync: per=%d scntl3=0x%x ofs=%d "
6924 "fak=%d chg=%d.\n", per
, scntl3
, ofs
, fak
, chg
);
6927 if (INB (HS_PRT
) == HS_NEGOTIATE
) {
6928 OUTB (HS_PRT
, HS_BUSY
);
6929 switch (cp
->nego_status
) {
6932 /* This was an answer message */
6934 /* Answer wasn't acceptable. */
6935 spi_period(starget
) = 0;
6936 spi_offset(starget
) = 0;
6937 ncr_setsync(np
, cp
, 0, 0xe0);
6938 OUTL_DSP(NCB_SCRIPT_PHYS (np
, msg_bad
));
6941 spi_period(starget
) = per
;
6942 spi_offset(starget
) = ofs
;
6943 ncr_setsync(np
, cp
, scntl3
, (fak
<<5)|ofs
);
6944 OUTL_DSP(NCB_SCRIPT_PHYS (np
, clrack
));
6949 spi_width(starget
) = 0;
6950 ncr_setwide(np
, cp
, 0, 0);
6956 ** It was a request. Set value and
6957 ** prepare an answer message
6960 spi_period(starget
) = per
;
6961 spi_offset(starget
) = ofs
;
6962 ncr_setsync(np
, cp
, scntl3
, (fak
<<5)|ofs
);
6964 spi_populate_sync_msg(np
->msgout
, per
, ofs
);
6965 cp
->nego_status
= NS_SYNC
;
6967 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6968 ncr_print_msg(cp
, "sync msgout", np
->msgout
);
6972 OUTL_DSP (NCB_SCRIPT_PHYS (np
, msg_bad
));
6975 np
->msgin
[0] = NOP
;
6981 ** Wide request message received.
6983 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
6984 ncr_print_msg(cp
, "wide msgin", np
->msgin
);
6988 ** get requested values.
6992 wide
= np
->msgin
[3];
6995 ** if target sends WDTR message,
6996 ** it CAN transfer wide.
6999 if (wide
&& starget
)
7000 spi_support_wide(starget
) = 1;
7003 ** check values against driver limits.
7006 if (wide
> tp
->usrwide
)
7007 {chg
= 1; wide
= tp
->usrwide
;}
7009 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
7010 PRINT_ADDR(cp
->cmd
, "wide: wide=%d chg=%d.\n", wide
,
7014 if (INB (HS_PRT
) == HS_NEGOTIATE
) {
7015 OUTB (HS_PRT
, HS_BUSY
);
7016 switch (cp
->nego_status
) {
7020 ** This was an answer message
7023 /* Answer wasn't acceptable. */
7024 spi_width(starget
) = 0;
7025 ncr_setwide(np
, cp
, 0, 1);
7026 OUTL_DSP (NCB_SCRIPT_PHYS (np
, msg_bad
));
7029 spi_width(starget
) = wide
;
7030 ncr_setwide(np
, cp
, wide
, 1);
7031 OUTL_DSP (NCB_SCRIPT_PHYS (np
, clrack
));
7036 spi_period(starget
) = 0;
7037 spi_offset(starget
) = 0;
7038 ncr_setsync(np
, cp
, 0, 0xe0);
7044 ** It was a request, set value and
7045 ** prepare an answer message
7048 spi_width(starget
) = wide
;
7049 ncr_setwide(np
, cp
, wide
, 1);
7050 spi_populate_width_msg(np
->msgout
, wide
);
7052 np
->msgin
[0] = NOP
;
7054 cp
->nego_status
= NS_WIDE
;
7056 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
7057 ncr_print_msg(cp
, "wide msgout", np
->msgin
);
7061 /*--------------------------------------------------------------------
7063 ** Processing of special messages
7065 **--------------------------------------------------------------------
7068 case SIR_REJECT_RECEIVED
:
7069 /*-----------------------------------------------
7071 ** We received a MESSAGE_REJECT.
7073 **-----------------------------------------------
7076 PRINT_ADDR(cp
->cmd
, "MESSAGE_REJECT received (%x:%x).\n",
7077 (unsigned)scr_to_cpu(np
->lastmsg
), np
->msgout
[0]);
7080 case SIR_REJECT_SENT
:
7081 /*-----------------------------------------------
7083 ** We received an unknown message
7085 **-----------------------------------------------
7088 ncr_print_msg(cp
, "MESSAGE_REJECT sent for", np
->msgin
);
7091 /*--------------------------------------------------------------------
7093 ** Processing of special messages
7095 **--------------------------------------------------------------------
7098 case SIR_IGN_RESIDUE
:
7099 /*-----------------------------------------------
7101 ** We received an IGNORE RESIDUE message,
7102 ** which couldn't be handled by the script.
7104 **-----------------------------------------------
7107 PRINT_ADDR(cp
->cmd
, "IGNORE_WIDE_RESIDUE received, but not yet "
7111 case SIR_MISSING_SAVE
:
7112 /*-----------------------------------------------
7114 ** We received an DISCONNECT message,
7115 ** but the datapointer wasn't saved before.
7117 **-----------------------------------------------
7120 PRINT_ADDR(cp
->cmd
, "DISCONNECT received, but datapointer "
7121 "not saved: data=%x save=%x goal=%x.\n",
7122 (unsigned) INL (nc_temp
),
7123 (unsigned) scr_to_cpu(np
->header
.savep
),
7124 (unsigned) scr_to_cpu(np
->header
.goalp
));
7133 /*==========================================================
7136 ** Acquire a control block
7139 **==========================================================
7142 static struct ccb
*ncr_get_ccb(struct ncb
*np
, struct scsi_cmnd
*cmd
)
7144 u_char tn
= cmd
->device
->id
;
7145 u_char ln
= cmd
->device
->lun
;
7146 struct tcb
*tp
= &np
->target
[tn
];
7147 struct lcb
*lp
= tp
->lp
[ln
];
7148 u_char tag
= NO_TAG
;
7149 struct ccb
*cp
= NULL
;
7152 ** Lun structure available ?
7155 struct list_head
*qp
;
7157 ** Keep from using more tags than we can handle.
7159 if (lp
->usetags
&& lp
->busyccbs
>= lp
->maxnxs
)
7163 ** Allocate a new CCB if needed.
7165 if (list_empty(&lp
->free_ccbq
))
7166 ncr_alloc_ccb(np
, tn
, ln
);
7169 ** Look for free CCB
7171 qp
= ncr_list_pop(&lp
->free_ccbq
);
7173 cp
= list_entry(qp
, struct ccb
, link_ccbq
);
7175 PRINT_ADDR(cmd
, "ccb free list corrupted "
7179 list_add_tail(qp
, &lp
->wait_ccbq
);
7185 ** If a CCB is available,
7186 ** Get a tag for this nexus if required.
7190 tag
= lp
->cb_tags
[lp
->ia_tag
];
7192 else if (lp
->actccbs
> 0)
7197 ** if nothing available, take the default.
7203 ** Wait until available.
7207 if (flags
& SCSI_NOSLEEP
) break;
7208 if (tsleep ((caddr_t
)cp
, PRIBIO
|PCATCH
, "ncr", 0))
7219 ** Move to next available tag if tag used.
7222 if (tag
!= NO_TAG
) {
7224 if (lp
->ia_tag
== MAX_TAGS
)
7226 lp
->tags_umap
|= (((tagmap_t
) 1) << tag
);
7231 ** Remember all informations needed to free this CCB.
7237 if (DEBUG_FLAGS
& DEBUG_TAGS
) {
7238 PRINT_ADDR(cmd
, "ccb @%p using tag %d.\n", cp
, tag
);
7244 /*==========================================================
7247 ** Release one control block
7250 **==========================================================
7253 static void ncr_free_ccb (struct ncb
*np
, struct ccb
*cp
)
7255 struct tcb
*tp
= &np
->target
[cp
->target
];
7256 struct lcb
*lp
= tp
->lp
[cp
->lun
];
7258 if (DEBUG_FLAGS
& DEBUG_TAGS
) {
7259 PRINT_ADDR(cp
->cmd
, "ccb @%p freeing tag %d.\n", cp
, cp
->tag
);
7263 ** If lun control block available,
7264 ** decrement active commands and increment credit,
7265 ** free the tag if any and remove the JUMP for reselect.
7268 if (cp
->tag
!= NO_TAG
) {
7269 lp
->cb_tags
[lp
->if_tag
++] = cp
->tag
;
7270 if (lp
->if_tag
== MAX_TAGS
)
7272 lp
->tags_umap
&= ~(((tagmap_t
) 1) << cp
->tag
);
7273 lp
->tags_smap
&= lp
->tags_umap
;
7274 lp
->jump_ccb
[cp
->tag
] =
7275 cpu_to_scr(NCB_SCRIPTH_PHYS(np
, bad_i_t_l_q
));
7278 cpu_to_scr(NCB_SCRIPTH_PHYS(np
, bad_i_t_l
));
7283 ** Make this CCB available.
7288 list_move(&cp
->link_ccbq
, &lp
->free_ccbq
);
7294 cp
-> host_status
= HS_IDLE
;
7303 wakeup ((caddr_t
) cp
);
7308 #define ncr_reg_bus_addr(r) (np->paddr + offsetof (struct ncr_reg, r))
7310 /*------------------------------------------------------------------------
7311 ** Initialize the fixed part of a CCB structure.
7312 **------------------------------------------------------------------------
7313 **------------------------------------------------------------------------
7315 static void ncr_init_ccb(struct ncb
*np
, struct ccb
*cp
)
7317 ncrcmd copy_4
= np
->features
& FE_PFEN
? SCR_COPY(4) : SCR_COPY_F(4);
7320 ** Remember virtual and bus address of this ccb.
7322 cp
->p_ccb
= vtobus(cp
);
7323 cp
->phys
.header
.cp
= cp
;
7326 ** This allows list_del to work for the default ccb.
7328 INIT_LIST_HEAD(&cp
->link_ccbq
);
7331 ** Initialyze the start and restart launch script.
7333 ** COPY(4) @(...p_phys), @(dsa)
7334 ** JUMP @(sched_point)
7336 cp
->start
.setup_dsa
[0] = cpu_to_scr(copy_4
);
7337 cp
->start
.setup_dsa
[1] = cpu_to_scr(CCB_PHYS(cp
, start
.p_phys
));
7338 cp
->start
.setup_dsa
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_dsa
));
7339 cp
->start
.schedule
.l_cmd
= cpu_to_scr(SCR_JUMP
);
7340 cp
->start
.p_phys
= cpu_to_scr(CCB_PHYS(cp
, phys
));
7342 memcpy(&cp
->restart
, &cp
->start
, sizeof(cp
->restart
));
7344 cp
->start
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, idle
));
7345 cp
->restart
.schedule
.l_paddr
= cpu_to_scr(NCB_SCRIPTH_PHYS (np
, abort
));
7349 /*------------------------------------------------------------------------
7350 ** Allocate a CCB and initialize its fixed part.
7351 **------------------------------------------------------------------------
7352 **------------------------------------------------------------------------
7354 static void ncr_alloc_ccb(struct ncb
*np
, u_char tn
, u_char ln
)
7356 struct tcb
*tp
= &np
->target
[tn
];
7357 struct lcb
*lp
= tp
->lp
[ln
];
7358 struct ccb
*cp
= NULL
;
7361 ** Allocate memory for this CCB.
7363 cp
= m_calloc_dma(sizeof(struct ccb
), "CCB");
7368 ** Count it and initialyze it.
7372 memset(cp
, 0, sizeof (*cp
));
7373 ncr_init_ccb(np
, cp
);
7376 ** Chain into wakeup list and free ccb queue and take it
7377 ** into account for tagged commands.
7379 cp
->link_ccb
= np
->ccb
->link_ccb
;
7380 np
->ccb
->link_ccb
= cp
;
7382 list_add(&cp
->link_ccbq
, &lp
->free_ccbq
);
7385 /*==========================================================
7388 ** Allocation of resources for Targets/Luns/Tags.
7391 **==========================================================
7395 /*------------------------------------------------------------------------
7396 ** Target control block initialisation.
7397 **------------------------------------------------------------------------
7398 ** This data structure is fully initialized after a SCSI command
7399 ** has been successfully completed for this target.
7400 ** It contains a SCRIPT that is called on target reselection.
7401 **------------------------------------------------------------------------
7403 static void ncr_init_tcb (struct ncb
*np
, u_char tn
)
7405 struct tcb
*tp
= &np
->target
[tn
];
7406 ncrcmd copy_1
= np
->features
& FE_PFEN
? SCR_COPY(1) : SCR_COPY_F(1);
7411 ** Jump to next tcb if SFBR does not match this target.
7412 ** JUMP IF (SFBR != #target#), @(next tcb)
7414 tp
->jump_tcb
.l_cmd
=
7415 cpu_to_scr((SCR_JUMP
^ IFFALSE (DATA (0x80 + tn
))));
7416 tp
->jump_tcb
.l_paddr
= np
->jump_tcb
[th
].l_paddr
;
7419 ** Load the synchronous transfer register.
7420 ** COPY @(tp->sval), @(sxfer)
7422 tp
->getscr
[0] = cpu_to_scr(copy_1
);
7423 tp
->getscr
[1] = cpu_to_scr(vtobus (&tp
->sval
));
7424 #ifdef SCSI_NCR_BIG_ENDIAN
7425 tp
->getscr
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_sxfer
) ^ 3);
7427 tp
->getscr
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_sxfer
));
7431 ** Load the timing register.
7432 ** COPY @(tp->wval), @(scntl3)
7434 tp
->getscr
[3] = cpu_to_scr(copy_1
);
7435 tp
->getscr
[4] = cpu_to_scr(vtobus (&tp
->wval
));
7436 #ifdef SCSI_NCR_BIG_ENDIAN
7437 tp
->getscr
[5] = cpu_to_scr(ncr_reg_bus_addr(nc_scntl3
) ^ 3);
7439 tp
->getscr
[5] = cpu_to_scr(ncr_reg_bus_addr(nc_scntl3
));
7443 ** Get the IDENTIFY message and the lun.
7444 ** CALL @script(resel_lun)
7446 tp
->call_lun
.l_cmd
= cpu_to_scr(SCR_CALL
);
7447 tp
->call_lun
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, resel_lun
));
7450 ** Look for the lun control block of this nexus.
7452 ** JUMP ^ IFTRUE (MASK (i, 3)), @(next_lcb)
7454 for (i
= 0 ; i
< 4 ; i
++) {
7455 tp
->jump_lcb
[i
].l_cmd
=
7456 cpu_to_scr((SCR_JUMP
^ IFTRUE (MASK (i
, 3))));
7457 tp
->jump_lcb
[i
].l_paddr
=
7458 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_identify
));
7462 ** Link this target control block to the JUMP chain.
7464 np
->jump_tcb
[th
].l_paddr
= cpu_to_scr(vtobus (&tp
->jump_tcb
));
7467 ** These assert's should be moved at driver initialisations.
7469 #ifdef SCSI_NCR_BIG_ENDIAN
7470 BUG_ON(((offsetof(struct ncr_reg
, nc_sxfer
) ^
7471 offsetof(struct tcb
, sval
)) &3) != 3);
7472 BUG_ON(((offsetof(struct ncr_reg
, nc_scntl3
) ^
7473 offsetof(struct tcb
, wval
)) &3) != 3);
7475 BUG_ON(((offsetof(struct ncr_reg
, nc_sxfer
) ^
7476 offsetof(struct tcb
, sval
)) &3) != 0);
7477 BUG_ON(((offsetof(struct ncr_reg
, nc_scntl3
) ^
7478 offsetof(struct tcb
, wval
)) &3) != 0);
7483 /*------------------------------------------------------------------------
7484 ** Lun control block allocation and initialization.
7485 **------------------------------------------------------------------------
7486 ** This data structure is allocated and initialized after a SCSI
7487 ** command has been successfully completed for this target/lun.
7488 **------------------------------------------------------------------------
7490 static struct lcb
*ncr_alloc_lcb (struct ncb
*np
, u_char tn
, u_char ln
)
7492 struct tcb
*tp
= &np
->target
[tn
];
7493 struct lcb
*lp
= tp
->lp
[ln
];
7494 ncrcmd copy_4
= np
->features
& FE_PFEN
? SCR_COPY(4) : SCR_COPY_F(4);
7498 ** Already done, return.
7504 ** Allocate the lcb.
7506 lp
= m_calloc_dma(sizeof(struct lcb
), "LCB");
7509 memset(lp
, 0, sizeof(*lp
));
7513 ** Initialize the target control block if not yet.
7515 if (!tp
->jump_tcb
.l_cmd
)
7516 ncr_init_tcb(np
, tn
);
7519 ** Initialize the CCB queue headers.
7521 INIT_LIST_HEAD(&lp
->free_ccbq
);
7522 INIT_LIST_HEAD(&lp
->busy_ccbq
);
7523 INIT_LIST_HEAD(&lp
->wait_ccbq
);
7524 INIT_LIST_HEAD(&lp
->skip_ccbq
);
7527 ** Set max CCBs to 1 and use the default 1 entry
7528 ** jump table by default.
7531 lp
->jump_ccb
= &lp
->jump_ccb_0
;
7532 lp
->p_jump_ccb
= cpu_to_scr(vtobus(lp
->jump_ccb
));
7535 ** Initilialyze the reselect script:
7537 ** Jump to next lcb if SFBR does not match this lun.
7538 ** Load TEMP with the CCB direct jump table bus address.
7539 ** Get the SIMPLE TAG message and the tag.
7541 ** JUMP IF (SFBR != #lun#), @(next lcb)
7542 ** COPY @(lp->p_jump_ccb), @(temp)
7543 ** JUMP @script(resel_notag)
7545 lp
->jump_lcb
.l_cmd
=
7546 cpu_to_scr((SCR_JUMP
^ IFFALSE (MASK (0x80+ln
, 0xff))));
7547 lp
->jump_lcb
.l_paddr
= tp
->jump_lcb
[lh
].l_paddr
;
7549 lp
->load_jump_ccb
[0] = cpu_to_scr(copy_4
);
7550 lp
->load_jump_ccb
[1] = cpu_to_scr(vtobus (&lp
->p_jump_ccb
));
7551 lp
->load_jump_ccb
[2] = cpu_to_scr(ncr_reg_bus_addr(nc_temp
));
7553 lp
->jump_tag
.l_cmd
= cpu_to_scr(SCR_JUMP
);
7554 lp
->jump_tag
.l_paddr
= cpu_to_scr(NCB_SCRIPT_PHYS (np
, resel_notag
));
7557 ** Link this lun control block to the JUMP chain.
7559 tp
->jump_lcb
[lh
].l_paddr
= cpu_to_scr(vtobus (&lp
->jump_lcb
));
7562 ** Initialize command queuing control.
7572 /*------------------------------------------------------------------------
7573 ** Lun control block setup on INQUIRY data received.
7574 **------------------------------------------------------------------------
7575 ** We only support WIDE, SYNC for targets and CMDQ for logical units.
7576 ** This setup is done on each INQUIRY since we are expecting user
7577 ** will play with CHANGE DEFINITION commands. :-)
7578 **------------------------------------------------------------------------
7580 static struct lcb
*ncr_setup_lcb (struct ncb
*np
, struct scsi_device
*sdev
)
7582 unsigned char tn
= sdev
->id
, ln
= sdev
->lun
;
7583 struct tcb
*tp
= &np
->target
[tn
];
7584 struct lcb
*lp
= tp
->lp
[ln
];
7586 /* If no lcb, try to allocate it. */
7587 if (!lp
&& !(lp
= ncr_alloc_lcb(np
, tn
, ln
)))
7591 ** If unit supports tagged commands, allocate the
7592 ** CCB JUMP table if not yet.
7594 if (sdev
->tagged_supported
&& lp
->jump_ccb
== &lp
->jump_ccb_0
) {
7596 lp
->jump_ccb
= m_calloc_dma(256, "JUMP_CCB");
7597 if (!lp
->jump_ccb
) {
7598 lp
->jump_ccb
= &lp
->jump_ccb_0
;
7601 lp
->p_jump_ccb
= cpu_to_scr(vtobus(lp
->jump_ccb
));
7602 for (i
= 0 ; i
< 64 ; i
++)
7604 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_i_t_l_q
));
7605 for (i
= 0 ; i
< MAX_TAGS
; i
++)
7607 lp
->maxnxs
= MAX_TAGS
;
7608 lp
->tags_stime
= jiffies
+ 3*HZ
;
7609 ncr_setup_tags (np
, sdev
);
7617 /*==========================================================
7620 ** Build Scatter Gather Block
7623 **==========================================================
7625 ** The transfer area may be scattered among
7626 ** several non adjacent physical pages.
7628 ** We may use MAX_SCATTER blocks.
7630 **----------------------------------------------------------
7634 ** We try to reduce the number of interrupts caused
7635 ** by unexpected phase changes due to disconnects.
7636 ** A typical harddisk may disconnect before ANY block.
7637 ** If we wanted to avoid unexpected phase changes at all
7638 ** we had to use a break point every 512 bytes.
7639 ** Of course the number of scatter/gather blocks is
7641 ** Under Linux, the scatter/gatter blocks are provided by
7642 ** the generic driver. We just have to copy addresses and
7643 ** sizes to the data segment array.
7646 static int ncr_scatter(struct ncb
*np
, struct ccb
*cp
, struct scsi_cmnd
*cmd
)
7649 int use_sg
= scsi_sg_count(cmd
);
7653 use_sg
= map_scsi_sg_data(np
, cmd
);
7655 struct scatterlist
*sg
;
7656 struct scr_tblmove
*data
;
7658 if (use_sg
> MAX_SCATTER
) {
7659 unmap_scsi_data(np
, cmd
);
7663 data
= &cp
->phys
.data
[MAX_SCATTER
- use_sg
];
7665 scsi_for_each_sg(cmd
, sg
, use_sg
, segment
) {
7666 dma_addr_t baddr
= sg_dma_address(sg
);
7667 unsigned int len
= sg_dma_len(sg
);
7669 ncr_build_sge(np
, &data
[segment
], baddr
, len
);
7670 cp
->data_len
+= len
;
7678 /*==========================================================
7681 ** Test the bus snoop logic :-(
7683 ** Has to be called with interrupts disabled.
7686 **==========================================================
7689 static int __init
ncr_regtest (struct ncb
* np
)
7691 register volatile u32 data
;
7693 ** ncr registers may NOT be cached.
7694 ** write 0xffffffff to a read only register area,
7695 ** and try to read it back.
7698 OUTL_OFF(offsetof(struct ncr_reg
, nc_dstat
), data
);
7699 data
= INL_OFF(offsetof(struct ncr_reg
, nc_dstat
));
7701 if (data
== 0xffffffff) {
7703 if ((data
& 0xe2f0fffd) != 0x02000080) {
7705 printk ("CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
7712 static int __init
ncr_snooptest (struct ncb
* np
)
7714 u32 ncr_rd
, ncr_wr
, ncr_bk
, host_rd
, host_wr
, pc
;
7717 err
|= ncr_regtest (np
);
7723 pc
= NCB_SCRIPTH_PHYS (np
, snooptest
);
7727 ** Set memory and register.
7729 np
->ncr_cache
= cpu_to_scr(host_wr
);
7730 OUTL (nc_temp
, ncr_wr
);
7732 ** Start script (exchange values)
7736 ** Wait 'til done (with timeout)
7738 for (i
=0; i
<NCR_SNOOP_TIMEOUT
; i
++)
7739 if (INB(nc_istat
) & (INTF
|SIP
|DIP
))
7742 ** Save termination position.
7746 ** Read memory and register.
7748 host_rd
= scr_to_cpu(np
->ncr_cache
);
7749 ncr_rd
= INL (nc_scratcha
);
7750 ncr_bk
= INL (nc_temp
);
7754 ncr_chip_reset(np
, 100);
7756 ** check for timeout
7758 if (i
>=NCR_SNOOP_TIMEOUT
) {
7759 printk ("CACHE TEST FAILED: timeout.\n");
7763 ** Check termination position.
7765 if (pc
!= NCB_SCRIPTH_PHYS (np
, snoopend
)+8) {
7766 printk ("CACHE TEST FAILED: script execution failed.\n");
7767 printk ("start=%08lx, pc=%08lx, end=%08lx\n",
7768 (u_long
) NCB_SCRIPTH_PHYS (np
, snooptest
), (u_long
) pc
,
7769 (u_long
) NCB_SCRIPTH_PHYS (np
, snoopend
) +8);
7775 if (host_wr
!= ncr_rd
) {
7776 printk ("CACHE TEST FAILED: host wrote %d, ncr read %d.\n",
7777 (int) host_wr
, (int) ncr_rd
);
7780 if (host_rd
!= ncr_wr
) {
7781 printk ("CACHE TEST FAILED: ncr wrote %d, host read %d.\n",
7782 (int) ncr_wr
, (int) host_rd
);
7785 if (ncr_bk
!= ncr_wr
) {
7786 printk ("CACHE TEST FAILED: ncr wrote %d, read back %d.\n",
7787 (int) ncr_wr
, (int) ncr_bk
);
7793 /*==========================================================
7795 ** Determine the ncr's clock frequency.
7796 ** This is essential for the negotiation
7797 ** of the synchronous transfer rate.
7799 **==========================================================
7801 ** Note: we have to return the correct value.
7802 ** THERE IS NO SAFE DEFAULT VALUE.
7804 ** Most NCR/SYMBIOS boards are delivered with a 40 Mhz clock.
7805 ** 53C860 and 53C875 rev. 1 support fast20 transfers but
7806 ** do not have a clock doubler and so are provided with a
7807 ** 80 MHz clock. All other fast20 boards incorporate a doubler
7808 ** and so should be delivered with a 40 MHz clock.
7809 ** The future fast40 chips (895/895) use a 40 Mhz base clock
7810 ** and provide a clock quadrupler (160 Mhz). The code below
7811 ** tries to deal as cleverly as possible with all this stuff.
7813 **----------------------------------------------------------
7817 * Select NCR SCSI clock frequency
7819 static void ncr_selectclock(struct ncb
*np
, u_char scntl3
)
7821 if (np
->multiplier
< 2) {
7822 OUTB(nc_scntl3
, scntl3
);
7826 if (bootverbose
>= 2)
7827 printk ("%s: enabling clock multiplier\n", ncr_name(np
));
7829 OUTB(nc_stest1
, DBLEN
); /* Enable clock multiplier */
7830 if (np
->multiplier
> 2) { /* Poll bit 5 of stest4 for quadrupler */
7832 while (!(INB(nc_stest4
) & LCKFRQ
) && --i
> 0)
7835 printk("%s: the chip cannot lock the frequency\n", ncr_name(np
));
7836 } else /* Wait 20 micro-seconds for doubler */
7838 OUTB(nc_stest3
, HSC
); /* Halt the scsi clock */
7839 OUTB(nc_scntl3
, scntl3
);
7840 OUTB(nc_stest1
, (DBLEN
|DBLSEL
));/* Select clock multiplier */
7841 OUTB(nc_stest3
, 0x00); /* Restart scsi clock */
7846 * calculate NCR SCSI clock frequency (in KHz)
7848 static unsigned __init
ncrgetfreq (struct ncb
*np
, int gen
)
7854 * Measure GEN timer delay in order
7855 * to calculate SCSI clock frequency
7857 * This code will never execute too
7858 * many loop iterations (if DELAY is
7859 * reasonably correct). It could get
7860 * too low a delay (too high a freq.)
7861 * if the CPU is slow executing the
7862 * loop for some reason (an NMI, for
7863 * example). For this reason we will
7864 * if multiple measurements are to be
7865 * performed trust the higher delay
7866 * (lower frequency returned).
7868 OUTB (nc_stest1
, 0); /* make sure clock doubler is OFF */
7869 OUTW (nc_sien
, 0); /* mask all scsi interrupts */
7870 (void) INW (nc_sist
); /* clear pending scsi interrupt */
7871 OUTB (nc_dien
, 0); /* mask all dma interrupts */
7872 (void) INW (nc_sist
); /* another one, just to be sure :) */
7873 OUTB (nc_scntl3
, 4); /* set pre-scaler to divide by 3 */
7874 OUTB (nc_stime1
, 0); /* disable general purpose timer */
7875 OUTB (nc_stime1
, gen
); /* set to nominal delay of 1<<gen * 125us */
7876 while (!(INW(nc_sist
) & GEN
) && ms
++ < 100000) {
7877 for (count
= 0; count
< 10; count
++)
7878 udelay(100); /* count ms */
7880 OUTB (nc_stime1
, 0); /* disable general purpose timer */
7882 * set prescaler to divide by whatever 0 means
7883 * 0 ought to choose divide by 2, but appears
7884 * to set divide by 3.5 mode in my 53c810 ...
7886 OUTB (nc_scntl3
, 0);
7888 if (bootverbose
>= 2)
7889 printk ("%s: Delay (GEN=%d): %u msec\n", ncr_name(np
), gen
, ms
);
7891 * adjust for prescaler, and convert into KHz
7893 return ms
? ((1 << gen
) * 4340) / ms
: 0;
7897 * Get/probe NCR SCSI clock frequency
7899 static void __init
ncr_getclock (struct ncb
*np
, int mult
)
7901 unsigned char scntl3
= INB(nc_scntl3
);
7902 unsigned char stest1
= INB(nc_stest1
);
7909 ** True with 875 or 895 with clock multiplier selected
7911 if (mult
> 1 && (stest1
& (DBLEN
+DBLSEL
)) == DBLEN
+DBLSEL
) {
7912 if (bootverbose
>= 2)
7913 printk ("%s: clock multiplier found\n", ncr_name(np
));
7914 np
->multiplier
= mult
;
7918 ** If multiplier not found or scntl3 not 7,5,3,
7919 ** reset chip and get frequency from general purpose timer.
7920 ** Otherwise trust scntl3 BIOS setting.
7922 if (np
->multiplier
!= mult
|| (scntl3
& 7) < 3 || !(scntl3
& 1)) {
7925 ncr_chip_reset(np
, 5);
7927 (void) ncrgetfreq (np
, 11); /* throw away first result */
7928 f1
= ncrgetfreq (np
, 11);
7929 f2
= ncrgetfreq (np
, 11);
7932 printk ("%s: NCR clock is %uKHz, %uKHz\n", ncr_name(np
), f1
, f2
);
7934 if (f1
> f2
) f1
= f2
; /* trust lower result */
7936 if (f1
< 45000) f1
= 40000;
7937 else if (f1
< 55000) f1
= 50000;
7940 if (f1
< 80000 && mult
> 1) {
7941 if (bootverbose
>= 2)
7942 printk ("%s: clock multiplier assumed\n", ncr_name(np
));
7943 np
->multiplier
= mult
;
7946 if ((scntl3
& 7) == 3) f1
= 40000;
7947 else if ((scntl3
& 7) == 5) f1
= 80000;
7950 f1
/= np
->multiplier
;
7954 ** Compute controller synchronous parameters.
7956 f1
*= np
->multiplier
;
7960 /*===================== LINUX ENTRY POINTS SECTION ==========================*/
7962 static int ncr53c8xx_slave_alloc(struct scsi_device
*device
)
7964 struct Scsi_Host
*host
= device
->host
;
7965 struct ncb
*np
= ((struct host_data
*) host
->hostdata
)->ncb
;
7966 struct tcb
*tp
= &np
->target
[device
->id
];
7967 tp
->starget
= device
->sdev_target
;
7972 static int ncr53c8xx_slave_configure(struct scsi_device
*device
)
7974 struct Scsi_Host
*host
= device
->host
;
7975 struct ncb
*np
= ((struct host_data
*) host
->hostdata
)->ncb
;
7976 struct tcb
*tp
= &np
->target
[device
->id
];
7977 struct lcb
*lp
= tp
->lp
[device
->lun
];
7978 int numtags
, depth_to_use
;
7980 ncr_setup_lcb(np
, device
);
7983 ** Select queue depth from driver setup.
7984 ** Donnot use more than configured by user.
7986 ** Donnot use more than our maximum.
7988 numtags
= device_queue_depth(np
->unit
, device
->id
, device
->lun
);
7989 if (numtags
> tp
->usrtags
)
7990 numtags
= tp
->usrtags
;
7991 if (!device
->tagged_supported
)
7993 depth_to_use
= numtags
;
7994 if (depth_to_use
< 2)
7996 if (depth_to_use
> MAX_TAGS
)
7997 depth_to_use
= MAX_TAGS
;
7999 scsi_adjust_queue_depth(device
,
8000 (device
->tagged_supported
?
8001 MSG_SIMPLE_TAG
: 0),
8005 ** Since the queue depth is not tunable under Linux,
8006 ** we need to know this value in order not to
8007 ** announce stupid things to user.
8009 ** XXX(hch): As of Linux 2.6 it certainly _is_ tunable..
8010 ** In fact we just tuned it, or did I miss
8011 ** something important? :)
8014 lp
->numtags
= lp
->maxtags
= numtags
;
8015 lp
->scdev_depth
= depth_to_use
;
8017 ncr_setup_tags (np
, device
);
8019 #ifdef DEBUG_NCR53C8XX
8020 printk("ncr53c8xx_select_queue_depth: host=%d, id=%d, lun=%d, depth=%d\n",
8021 np
->unit
, device
->id
, device
->lun
, depth_to_use
);
8024 if (spi_support_sync(device
->sdev_target
) &&
8025 !spi_initial_dv(device
->sdev_target
))
8026 spi_dv_device(device
);
8030 static int ncr53c8xx_queue_command (struct scsi_cmnd
*cmd
, void (* done
)(struct scsi_cmnd
*))
8032 struct ncb
*np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
8033 unsigned long flags
;
8036 #ifdef DEBUG_NCR53C8XX
8037 printk("ncr53c8xx_queue_command\n");
8040 cmd
->scsi_done
= done
;
8041 cmd
->host_scribble
= NULL
;
8042 cmd
->__data_mapped
= 0;
8043 cmd
->__data_mapping
= 0;
8045 spin_lock_irqsave(&np
->smp_lock
, flags
);
8047 if ((sts
= ncr_queue_command(np
, cmd
)) != DID_OK
) {
8048 cmd
->result
= ScsiResult(sts
, 0);
8049 #ifdef DEBUG_NCR53C8XX
8050 printk("ncr53c8xx : command not queued - result=%d\n", sts
);
8053 #ifdef DEBUG_NCR53C8XX
8055 printk("ncr53c8xx : command successfully queued\n");
8058 spin_unlock_irqrestore(&np
->smp_lock
, flags
);
8060 if (sts
!= DID_OK
) {
8061 unmap_scsi_data(np
, cmd
);
8069 irqreturn_t
ncr53c8xx_intr(int irq
, void *dev_id
)
8071 unsigned long flags
;
8072 struct Scsi_Host
*shost
= (struct Scsi_Host
*)dev_id
;
8073 struct host_data
*host_data
= (struct host_data
*)shost
->hostdata
;
8074 struct ncb
*np
= host_data
->ncb
;
8075 struct scsi_cmnd
*done_list
;
8077 #ifdef DEBUG_NCR53C8XX
8078 printk("ncr53c8xx : interrupt received\n");
8081 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("[");
8083 spin_lock_irqsave(&np
->smp_lock
, flags
);
8085 done_list
= np
->done_list
;
8086 np
->done_list
= NULL
;
8087 spin_unlock_irqrestore(&np
->smp_lock
, flags
);
8089 if (DEBUG_FLAGS
& DEBUG_TINY
) printk ("]\n");
8092 ncr_flush_done_cmds(done_list
);
8096 static void ncr53c8xx_timeout(unsigned long npref
)
8098 struct ncb
*np
= (struct ncb
*) npref
;
8099 unsigned long flags
;
8100 struct scsi_cmnd
*done_list
;
8102 spin_lock_irqsave(&np
->smp_lock
, flags
);
8104 done_list
= np
->done_list
;
8105 np
->done_list
= NULL
;
8106 spin_unlock_irqrestore(&np
->smp_lock
, flags
);
8109 ncr_flush_done_cmds(done_list
);
8112 static int ncr53c8xx_bus_reset(struct scsi_cmnd
*cmd
)
8114 struct ncb
*np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
8116 unsigned long flags
;
8117 struct scsi_cmnd
*done_list
;
8120 * If the mid-level driver told us reset is synchronous, it seems
8121 * that we must call the done() callback for the involved command,
8122 * even if this command was not queued to the low-level driver,
8123 * before returning SUCCESS.
8126 spin_lock_irqsave(&np
->smp_lock
, flags
);
8127 sts
= ncr_reset_bus(np
, cmd
, 1);
8129 done_list
= np
->done_list
;
8130 np
->done_list
= NULL
;
8131 spin_unlock_irqrestore(&np
->smp_lock
, flags
);
8133 ncr_flush_done_cmds(done_list
);
8138 #if 0 /* unused and broken */
8139 static int ncr53c8xx_abort(struct scsi_cmnd
*cmd
)
8141 struct ncb
*np
= ((struct host_data
*) cmd
->device
->host
->hostdata
)->ncb
;
8143 unsigned long flags
;
8144 struct scsi_cmnd
*done_list
;
8146 printk("ncr53c8xx_abort: command pid %lu\n", cmd
->serial_number
);
8148 NCR_LOCK_NCB(np
, flags
);
8150 sts
= ncr_abort_command(np
, cmd
);
8152 done_list
= np
->done_list
;
8153 np
->done_list
= NULL
;
8154 NCR_UNLOCK_NCB(np
, flags
);
8156 ncr_flush_done_cmds(done_list
);
8164 ** Scsi command waiting list management.
8166 ** It may happen that we cannot insert a scsi command into the start queue,
8167 ** in the following circumstances.
8168 ** Too few preallocated ccb(s),
8169 ** maxtags < cmd_per_lun of the Linux host control block,
8171 ** Such scsi commands are inserted into a waiting list.
8172 ** When a scsi command complete, we try to requeue the commands of the
8176 #define next_wcmd host_scribble
8178 static void insert_into_waiting_list(struct ncb
*np
, struct scsi_cmnd
*cmd
)
8180 struct scsi_cmnd
*wcmd
;
8182 #ifdef DEBUG_WAITING_LIST
8183 printk("%s: cmd %lx inserted into waiting list\n", ncr_name(np
), (u_long
) cmd
);
8185 cmd
->next_wcmd
= NULL
;
8186 if (!(wcmd
= np
->waiting_list
)) np
->waiting_list
= cmd
;
8188 while ((wcmd
->next_wcmd
) != 0)
8189 wcmd
= (struct scsi_cmnd
*) wcmd
->next_wcmd
;
8190 wcmd
->next_wcmd
= (char *) cmd
;
8194 static struct scsi_cmnd
*retrieve_from_waiting_list(int to_remove
, struct ncb
*np
, struct scsi_cmnd
*cmd
)
8196 struct scsi_cmnd
**pcmd
= &np
->waiting_list
;
8201 *pcmd
= (struct scsi_cmnd
*) cmd
->next_wcmd
;
8202 cmd
->next_wcmd
= NULL
;
8204 #ifdef DEBUG_WAITING_LIST
8205 printk("%s: cmd %lx retrieved from waiting list\n", ncr_name(np
), (u_long
) cmd
);
8209 pcmd
= (struct scsi_cmnd
**) &(*pcmd
)->next_wcmd
;
8214 static void process_waiting_list(struct ncb
*np
, int sts
)
8216 struct scsi_cmnd
*waiting_list
, *wcmd
;
8218 waiting_list
= np
->waiting_list
;
8219 np
->waiting_list
= NULL
;
8221 #ifdef DEBUG_WAITING_LIST
8222 if (waiting_list
) printk("%s: waiting_list=%lx processing sts=%d\n", ncr_name(np
), (u_long
) waiting_list
, sts
);
8224 while ((wcmd
= waiting_list
) != 0) {
8225 waiting_list
= (struct scsi_cmnd
*) wcmd
->next_wcmd
;
8226 wcmd
->next_wcmd
= NULL
;
8227 if (sts
== DID_OK
) {
8228 #ifdef DEBUG_WAITING_LIST
8229 printk("%s: cmd %lx trying to requeue\n", ncr_name(np
), (u_long
) wcmd
);
8231 sts
= ncr_queue_command(np
, wcmd
);
8233 if (sts
!= DID_OK
) {
8234 #ifdef DEBUG_WAITING_LIST
8235 printk("%s: cmd %lx done forced sts=%d\n", ncr_name(np
), (u_long
) wcmd
, sts
);
8237 wcmd
->result
= ScsiResult(sts
, 0);
8238 ncr_queue_done_cmd(np
, wcmd
);
8245 static ssize_t
show_ncr53c8xx_revision(struct class_device
*dev
, char *buf
)
8247 struct Scsi_Host
*host
= class_to_shost(dev
);
8248 struct host_data
*host_data
= (struct host_data
*)host
->hostdata
;
8250 return snprintf(buf
, 20, "0x%x\n", host_data
->ncb
->revision_id
);
8253 static struct class_device_attribute ncr53c8xx_revision_attr
= {
8254 .attr
= { .name
= "revision", .mode
= S_IRUGO
, },
8255 .show
= show_ncr53c8xx_revision
,
8258 static struct class_device_attribute
*ncr53c8xx_host_attrs
[] = {
8259 &ncr53c8xx_revision_attr
,
8263 /*==========================================================
8265 ** Boot command line.
8267 **==========================================================
8270 char *ncr53c8xx
; /* command line passed by insmod */
8271 module_param(ncr53c8xx
, charp
, 0);
8275 static int __init
ncr53c8xx_setup(char *str
)
8277 return sym53c8xx__setup(str
);
8280 __setup("ncr53c8xx=", ncr53c8xx_setup
);
8285 * Host attach and initialisations.
8287 * Allocate host data and ncb structure.
8288 * Request IO region and remap MMIO region.
8289 * Do chip initialization.
8290 * If all is OK, install interrupt handling and
8291 * start the timer daemon.
8293 struct Scsi_Host
* __init
ncr_attach(struct scsi_host_template
*tpnt
,
8294 int unit
, struct ncr_device
*device
)
8296 struct host_data
*host_data
;
8297 struct ncb
*np
= NULL
;
8298 struct Scsi_Host
*instance
= NULL
;
8303 tpnt
->name
= SCSI_NCR_DRIVER_NAME
;
8304 if (!tpnt
->shost_attrs
)
8305 tpnt
->shost_attrs
= ncr53c8xx_host_attrs
;
8307 tpnt
->queuecommand
= ncr53c8xx_queue_command
;
8308 tpnt
->slave_configure
= ncr53c8xx_slave_configure
;
8309 tpnt
->slave_alloc
= ncr53c8xx_slave_alloc
;
8310 tpnt
->eh_bus_reset_handler
= ncr53c8xx_bus_reset
;
8311 tpnt
->can_queue
= SCSI_NCR_CAN_QUEUE
;
8313 tpnt
->sg_tablesize
= SCSI_NCR_SG_TABLESIZE
;
8314 tpnt
->cmd_per_lun
= SCSI_NCR_CMD_PER_LUN
;
8315 tpnt
->use_clustering
= ENABLE_CLUSTERING
;
8317 if (device
->differential
)
8318 driver_setup
.diff_support
= device
->differential
;
8320 printk(KERN_INFO
"ncr53c720-%d: rev 0x%x irq %d\n",
8321 unit
, device
->chip
.revision_id
, device
->slot
.irq
);
8323 instance
= scsi_host_alloc(tpnt
, sizeof(*host_data
));
8326 host_data
= (struct host_data
*) instance
->hostdata
;
8328 np
= __m_calloc_dma(device
->dev
, sizeof(struct ncb
), "NCB");
8331 spin_lock_init(&np
->smp_lock
);
8332 np
->dev
= device
->dev
;
8333 np
->p_ncb
= vtobus(np
);
8334 host_data
->ncb
= np
;
8336 np
->ccb
= m_calloc_dma(sizeof(struct ccb
), "CCB");
8340 /* Store input information in the host data structure. */
8342 np
->verbose
= driver_setup
.verbose
;
8343 sprintf(np
->inst_name
, "ncr53c720-%d", np
->unit
);
8344 np
->revision_id
= device
->chip
.revision_id
;
8345 np
->features
= device
->chip
.features
;
8346 np
->clock_divn
= device
->chip
.nr_divisor
;
8347 np
->maxoffs
= device
->chip
.offset_max
;
8348 np
->maxburst
= device
->chip
.burst_max
;
8349 np
->myaddr
= device
->host_id
;
8351 /* Allocate SCRIPTS areas. */
8352 np
->script0
= m_calloc_dma(sizeof(struct script
), "SCRIPT");
8355 np
->scripth0
= m_calloc_dma(sizeof(struct scripth
), "SCRIPTH");
8359 init_timer(&np
->timer
);
8360 np
->timer
.data
= (unsigned long) np
;
8361 np
->timer
.function
= ncr53c8xx_timeout
;
8363 /* Try to map the controller chip to virtual and physical memory. */
8365 np
->paddr
= device
->slot
.base
;
8366 np
->paddr2
= (np
->features
& FE_RAM
) ? device
->slot
.base_2
: 0;
8368 if (device
->slot
.base_v
)
8369 np
->vaddr
= device
->slot
.base_v
;
8371 np
->vaddr
= ioremap(device
->slot
.base_c
, 128);
8375 "%s: can't map memory mapped IO region\n",ncr_name(np
));
8378 if (bootverbose
> 1)
8380 "%s: using memory mapped IO at virtual address 0x%lx\n", ncr_name(np
), (u_long
) np
->vaddr
);
8383 /* Make the controller's registers available. Now the INB INW INL
8384 * OUTB OUTW OUTL macros can be used safely.
8387 np
->reg
= (struct ncr_reg __iomem
*)np
->vaddr
;
8389 /* Do chip dependent initialization. */
8390 ncr_prepare_setting(np
);
8392 if (np
->paddr2
&& sizeof(struct script
) > 4096) {
8394 printk(KERN_WARNING
"%s: script too large, NOT using on chip RAM.\n",
8398 instance
->max_channel
= 0;
8399 instance
->this_id
= np
->myaddr
;
8400 instance
->max_id
= np
->maxwide
? 16 : 8;
8401 instance
->max_lun
= SCSI_NCR_MAX_LUN
;
8402 instance
->base
= (unsigned long) np
->reg
;
8403 instance
->irq
= device
->slot
.irq
;
8404 instance
->unique_id
= device
->slot
.base
;
8405 instance
->dma_channel
= 0;
8406 instance
->cmd_per_lun
= MAX_TAGS
;
8407 instance
->can_queue
= (MAX_START
-4);
8408 /* This can happen if you forget to call ncr53c8xx_init from
8409 * your module_init */
8410 BUG_ON(!ncr53c8xx_transport_template
);
8411 instance
->transportt
= ncr53c8xx_transport_template
;
8413 /* Patch script to physical addresses */
8414 ncr_script_fill(&script0
, &scripth0
);
8416 np
->scripth
= np
->scripth0
;
8417 np
->p_scripth
= vtobus(np
->scripth
);
8418 np
->p_script
= (np
->paddr2
) ? np
->paddr2
: vtobus(np
->script0
);
8420 ncr_script_copy_and_bind(np
, (ncrcmd
*) &script0
,
8421 (ncrcmd
*) np
->script0
, sizeof(struct script
));
8422 ncr_script_copy_and_bind(np
, (ncrcmd
*) &scripth0
,
8423 (ncrcmd
*) np
->scripth0
, sizeof(struct scripth
));
8424 np
->ccb
->p_ccb
= vtobus (np
->ccb
);
8426 /* Patch the script for LED support. */
8428 if (np
->features
& FE_LED0
) {
8429 np
->script0
->idle
[0] =
8430 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_OR
, 0x01));
8431 np
->script0
->reselected
[0] =
8432 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_AND
, 0xfe));
8433 np
->script0
->start
[0] =
8434 cpu_to_scr(SCR_REG_REG(gpreg
, SCR_AND
, 0xfe));
8438 * Look for the target control block of this nexus.
8440 * JUMP ^ IFTRUE (MASK (i, 3)), @(next_lcb)
8442 for (i
= 0 ; i
< 4 ; i
++) {
8443 np
->jump_tcb
[i
].l_cmd
=
8444 cpu_to_scr((SCR_JUMP
^ IFTRUE (MASK (i
, 3))));
8445 np
->jump_tcb
[i
].l_paddr
=
8446 cpu_to_scr(NCB_SCRIPTH_PHYS (np
, bad_target
));
8449 ncr_chip_reset(np
, 100);
8451 /* Now check the cache handling of the chipset. */
8453 if (ncr_snooptest(np
)) {
8454 printk(KERN_ERR
"CACHE INCORRECTLY CONFIGURED.\n");
8458 /* Install the interrupt handler. */
8459 np
->irq
= device
->slot
.irq
;
8461 /* Initialize the fixed part of the default ccb. */
8462 ncr_init_ccb(np
, np
->ccb
);
8465 * After SCSI devices have been opened, we cannot reset the bus
8466 * safely, so we do it here. Interrupt handler does the real work.
8467 * Process the reset exception if interrupts are not enabled yet.
8468 * Then enable disconnects.
8470 spin_lock_irqsave(&np
->smp_lock
, flags
);
8471 if (ncr_reset_scsi_bus(np
, 0, driver_setup
.settle_delay
) != 0) {
8472 printk(KERN_ERR
"%s: FATAL ERROR: CHECK SCSI BUS - CABLES, TERMINATION, DEVICE POWER etc.!\n", ncr_name(np
));
8474 spin_unlock_irqrestore(&np
->smp_lock
, flags
);
8482 * The middle-level SCSI driver does not wait for devices to settle.
8483 * Wait synchronously if more than 2 seconds.
8485 if (driver_setup
.settle_delay
> 2) {
8486 printk(KERN_INFO
"%s: waiting %d seconds for scsi devices to settle...\n",
8487 ncr_name(np
), driver_setup
.settle_delay
);
8488 mdelay(1000 * driver_setup
.settle_delay
);
8491 /* start the timeout daemon */
8495 /* use SIMPLE TAG messages by default */
8496 #ifdef SCSI_NCR_ALWAYS_SIMPLE_TAG
8497 np
->order
= SIMPLE_QUEUE_TAG
;
8500 spin_unlock_irqrestore(&np
->smp_lock
, flags
);
8507 printk(KERN_INFO
"%s: detaching...\n", ncr_name(np
));
8511 m_free_dma(np
->scripth0
, sizeof(struct scripth
), "SCRIPTH");
8513 m_free_dma(np
->script0
, sizeof(struct script
), "SCRIPT");
8515 m_free_dma(np
->ccb
, sizeof(struct ccb
), "CCB");
8516 m_free_dma(np
, sizeof(struct ncb
), "NCB");
8517 host_data
->ncb
= NULL
;
8520 scsi_host_put(instance
);
8526 void ncr53c8xx_release(struct Scsi_Host
*host
)
8528 struct host_data
*host_data
= shost_priv(host
);
8529 #ifdef DEBUG_NCR53C8XX
8530 printk("ncr53c8xx: release\n");
8533 ncr_detach(host_data
->ncb
);
8534 scsi_host_put(host
);
8537 static void ncr53c8xx_set_period(struct scsi_target
*starget
, int period
)
8539 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
8540 struct ncb
*np
= ((struct host_data
*)shost
->hostdata
)->ncb
;
8541 struct tcb
*tp
= &np
->target
[starget
->id
];
8543 if (period
> np
->maxsync
)
8544 period
= np
->maxsync
;
8545 else if (period
< np
->minsync
)
8546 period
= np
->minsync
;
8548 tp
->usrsync
= period
;
8550 ncr_negotiate(np
, tp
);
8553 static void ncr53c8xx_set_offset(struct scsi_target
*starget
, int offset
)
8555 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
8556 struct ncb
*np
= ((struct host_data
*)shost
->hostdata
)->ncb
;
8557 struct tcb
*tp
= &np
->target
[starget
->id
];
8559 if (offset
> np
->maxoffs
)
8560 offset
= np
->maxoffs
;
8561 else if (offset
< 0)
8564 tp
->maxoffs
= offset
;
8566 ncr_negotiate(np
, tp
);
8569 static void ncr53c8xx_set_width(struct scsi_target
*starget
, int width
)
8571 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
8572 struct ncb
*np
= ((struct host_data
*)shost
->hostdata
)->ncb
;
8573 struct tcb
*tp
= &np
->target
[starget
->id
];
8575 if (width
> np
->maxwide
)
8576 width
= np
->maxwide
;
8580 tp
->usrwide
= width
;
8582 ncr_negotiate(np
, tp
);
8585 static void ncr53c8xx_get_signalling(struct Scsi_Host
*shost
)
8587 struct ncb
*np
= ((struct host_data
*)shost
->hostdata
)->ncb
;
8588 enum spi_signal_type type
;
8590 switch (np
->scsi_mode
) {
8592 type
= SPI_SIGNAL_SE
;
8595 type
= SPI_SIGNAL_HVD
;
8598 type
= SPI_SIGNAL_UNKNOWN
;
8601 spi_signalling(shost
) = type
;
8604 static struct spi_function_template ncr53c8xx_transport_functions
= {
8605 .set_period
= ncr53c8xx_set_period
,
8607 .set_offset
= ncr53c8xx_set_offset
,
8609 .set_width
= ncr53c8xx_set_width
,
8611 .get_signalling
= ncr53c8xx_get_signalling
,
8614 int __init
ncr53c8xx_init(void)
8616 ncr53c8xx_transport_template
= spi_attach_transport(&ncr53c8xx_transport_functions
);
8617 if (!ncr53c8xx_transport_template
)
8622 void ncr53c8xx_exit(void)
8624 spi_release_transport(ncr53c8xx_transport_template
);